Ejemplo n.º 1
0
// SetSubImage sets a designated part of an image for this sprite renderer
//  @param  {[string]} this *SpriteRenderer [the base image path]
//  @param  {[image.Rectangle]} this *SpriteRenderer [the rectangular bounds of designated part of image]
//  @return
func (s *SpriteRenderer) SetSubImage(imageLoc string, bounds image.Rectangle) {
	img, err := Image.NewImage(imageLoc)

	if err != nil {
		Logging.Debug("Cannot create image: " + err.Error())
	}

	img, err = img.SubImage(bounds)
	if err != nil {
		Logging.Debug("Cannot create sub image: " + err.Error())
	}

	s.img = &img
}
Ejemplo n.º 2
0
// SpliceSpriteSheetAnimation manually cuts up a row of a sprite sheet based on user defined dimensions and sets it as the current animation
func SpliceSpriteSheetAnimation(imageLoc string,
	frameWidth, frameHeight, noOfFrames, rowNum int) *FrameAnimation {

	fa := newFrameAnimation()

	img, err := Image.NewImage(imageLoc)
	if err != nil {
		Logging.Debug("Cannot create image: " + err.Error())
	}

	// throw warnings for bad input
	numOfRows := float32(img.Bounds().Dy() / frameHeight)
	numOfColumns := float32(img.Bounds().Dx() / frameWidth)
	if float32(noOfFrames) > numOfColumns || numOfColumns < 1 {
		Logging.Debug("WARNING: frames out of bounds")
	}
	if float32(rowNum) > numOfRows || numOfRows < 1 {
		Logging.Debug("WARNING: row desired out of bounds")
	}

	for j := 0; j < img.Bounds().Dy(); j += frameHeight {

		// only use our desired row (if specified)
		if rowNum != 0 && j/frameHeight != rowNum-1 {
			continue
		}

		// splice the row by the amount of intended images
		for i := 0; i < img.Bounds().Dx(); i += frameWidth {

			// only grab our desired number of frames (if specified)
			if noOfFrames != 0 && i/frameWidth >= noOfFrames {
				continue
			}

			// splice image from row, and insert piece into array
			b := image.Rect(i, j, i+frameWidth, j+frameHeight)
			spriteSheetPart, err := img.SubImage(b)

			if err != nil {
				Logging.Debug("Cannot create sub image: " + err.Error())
			}
			fa.animationImages = append(fa.animationImages, &spriteSheetPart)
		}
	}

	return fa
}
Ejemplo n.º 3
0
// Append simply adds an image from the aggregate to the end of our animation
func (f *FrameAnimation) Append(imageLoc string) {
	img, err := Image.NewImage(imageLoc)
	if err != nil {
		Logging.Debug("Cannot create image: " + err.Error())
	}
	f.animationImages = append(f.animationImages, &img)
}
Ejemplo n.º 4
0
func NewWindowedWindow(title string, width, height int) Window {
	// FOR GLFW event handling
	runtime.LockOSThread()

	windowSDL, err := sdl.CreateWindow(title, sdl.WINDOWPOS_UNDEFINED,
		sdl.WINDOWPOS_UNDEFINED,
		width, height, sdl.WINDOW_OPENGL)

	if err != nil {
		panic(err)
	}
	if windowSDL == nil {
		panic(sdl.GetError())
	}

	context, err := sdl.GL_CreateContext(windowSDL)

	sdl.GL_MakeCurrent(windowSDL, context)

	if err != nil {
		panic("Error loading window: " + err.Error())
	}

	w := Window{title: title, Width: width, Height: height, full: false, windowSDL: windowSDL, contextSDL: context, running: false}

	w.init()
	var current sdl.DisplayMode
	if err := sdl.GetCurrentDisplayMode(0, &current); err != nil {
		Logging.Debug("Could not get display mode: " + err.Error())
	}
	Logging.Info("Display #%d: current display mode is %dx%dpx @ %dhz. \n", 0, current.W, current.H, current.RefreshRate)

	return w
}
Ejemplo n.º 5
0
// SetImage puts a designated image from the agregate into our image which will be rendered
func (s *SpriteRenderer) SetImage(imageLoc string) {
	img, err := Image.NewImage(imageLoc)

	if err != nil {
		Logging.Debug("Cannot create image: " + err.Error())
	}

	s.img = &img
}
Ejemplo n.º 6
0
// SetCurrentAnimation takes a animation's name and tries to set that as the current animation
func (a *AnimationManager) SetCurrentAnimation(mappedAnimationName string) {
	animationRetrieved, ok := a.animationsMap[mappedAnimationName]
	if !ok {
		Logging.Debug("couldn't find the animation: " + mappedAnimationName)
	}

	a.currentAnimation = animationRetrieved
	Logging.Info(mappedAnimationName, ":Set current anim to ", a.currentAnimation)
	Logging.Info("Animation Map: ", a.animationsMap)
}
Ejemplo n.º 7
0
// Normalizes normalizes the vector values to be in 0.0 - 1.0 range
func (this vector3) Normalize() vector3 {
	mag := this.Mag()

	if mag > 0 {
		return this.Scalar(1 / mag)
	}

	Logging.Debug("Cannot normalize vector, magnitude 0")
	return ZeroVector3()
}
Ejemplo n.º 8
0
// Remove an item from the animation via 1-based input
func (f *FrameAnimation) Remove(imageIdx int) {
	// convert to zero based
	imageIdx--

	// shift the image to the end, then pop it
	if imageIdx >= 0 && imageIdx < len(f.animationImages) {
		f.animationImages = append(f.animationImages[:imageIdx], f.animationImages[imageIdx+1:]...)
		f.animationImages = f.animationImages[:len(f.animationImages)-1]
	} else {
		Logging.Debug("cant remove from animation, out of bounds...")
	}
}
Ejemplo n.º 9
0
func (this *Node) AddComponent(component Component) {
	if n, ok := component.(Child); ok {

		n.SetParent(this)
	} else {
		Logging.Debug("No parent to set for child component.\n")
	}

	this.components = append(this.components, component)

	component.Initialize()
}
Ejemplo n.º 10
0
func main() {

	// The logger now initializes in the Engine's start. That is where flags get parsed etc.
	GT.EngineStart()

	// TODO: test filtering and simultaneous outputs once implemented and configured
	Logging.Debug("debug")
	Logging.Info("info")

	// Note: this has been tested to work on multiple code call levels
	// so inserting debug logs in SimpleWindow.go as well as Scene.go
	// will place all info into GT/Logging/default.log
}
Ejemplo n.º 11
0
func (this *TextRenderer) SetText(text string) {

	this.text = text

	for _, t := range text {
		img, err := Image.NewFontImage(this.font, t)

		if err != nil {
			Logging.Debug("Cannot create image: " + err.Error())
		}

		this.runeImgs = append(this.runeImgs, &img)

	}

}
Ejemplo n.º 12
0
// Reorder simply swaps the order in which any two images are rendered ()
func (f *FrameAnimation) Reorder(imageOneIdx int, imageTwoIdx int) {

	// convert from one-based input to zero-based logic
	listLength := len(f.animationImages)
	lowerIdx := imageOneIdx - 1
	higherIdx := imageTwoIdx - 1

	// keep track of the higher and lower indexes
	if imageOneIdx > imageTwoIdx {
		lowerIdx = imageTwoIdx
		higherIdx = imageOneIdx
	}

	if imageOneIdx == imageTwoIdx || higherIdx > listLength || lowerIdx < 0 {
		Logging.Debug("invalid input, please ensure you are entering two unique dimensions within the list")
		return
	}

	imgTmp := f.animationImages[lowerIdx]

	f.animationImages[lowerIdx] = f.animationImages[higherIdx]
	f.animationImages[higherIdx] = imgTmp
}
Ejemplo n.º 13
0
// returns image of rendered font
func (this FontInfo) GetImage() image.Image {

	f := truetype.Font(this)

	maxWidth := 0
	curW := 0
	maxHeight := int(f.Bounds(sizeFixed).Max.Sub(f.Bounds(sizeFixed).Min).Y) + insetPadding
	for idx, val := range text {
		if idx > 0 && int(math.Mod(float64(idx), float64(itemsPerRow))) == 0 {
			maxHeight += int(f.Bounds(sizeFixed).Max.Sub(f.Bounds(sizeFixed).Min).Y) + insetPadding
			curW = 0

		}

		i := f.Index(val)
		hmet := f.HMetric(sizeFixed, i)

		curW += int(hmet.AdvanceWidth) + insetPadding

		if curW > maxWidth {
			maxWidth = curW
		}

	}

	Logging.Debug("Font ", this.Name())
	Logging.Debug("Max width: ", maxWidth)
	Logging.Debug("Max height: ", maxHeight)

	// Draw the background and the guidelines.
	fg, bg := image.Black, image.Transparent

	// diffY := int(f.Bounds(sizeFixed).Max.Sub(f.Bounds(sizeFixed).Min).Y)

	// add a constant to the y term because of subtle bleeding between vertical space, probably because of advance height
	rgba := image.NewRGBA(image.Rect(0, 0, maxWidth, maxHeight)) //diffY+5))

	draw.Draw(rgba, rgba.Bounds(), bg, image.ZP, draw.Src)

	// Draw the text.
	h := font.HintingNone
	switch hinting {
	case "full":
		h = font.HintingFull
	}
	d := &font.Drawer{
		Dst: rgba,
		Src: fg,
		Face: truetype.NewFace(&f, &truetype.Options{
			Size:    size,
			DPI:     dpi,
			Hinting: h,
		}),
	}

	// y := int(math.Abs(float64(f.Bounds(sizeFixed).Max.Y))) //10 + int(math.Ceil(*size**dpi/72))
	// dy := int(math.Ceil(size * spacing * dpi / 72))

	tWidth := 0
	tHeight := int(math.Abs(float64(f.Bounds(sizeFixed).Max.Y)))
	for idx, r := range text {
		if idx > 0 && int(math.Mod(float64(idx), float64(itemsPerRow))) == 0 {
			tHeight += int(f.Bounds(sizeFixed).Max.Sub(f.Bounds(sizeFixed).Min).Y) + insetPadding
			tWidth = 0
		}
		i := f.Index(r)
		hmet := f.HMetric(sizeFixed, i)

		d.Dot = fixed.P(tWidth, tHeight)
		tWidth += int(hmet.AdvanceWidth) + insetPadding

		d.DrawString(string(r))

	}

	return rgba
}