-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using pixelutils packer to handle images
- Loading branch information
Allen Ray
committed
Jul 30, 2020
1 parent
b9122bd
commit 81a64e6
Showing
4 changed files
with
131 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package pixelui | ||
|
||
import ( | ||
"github.com/faiface/pixel" | ||
"github.com/inkyblackness/imgui-go" | ||
) | ||
|
||
// imguiRectToPixelRect Converts the imgui rect to a Pixel rect | ||
func imguiRectToPixelRect(r imgui.Vec4) pixel.Rect { | ||
return pixel.R(float64(r.X), float64(r.Y), float64(r.Z), float64(r.W)) | ||
} | ||
|
||
// IVec converts a pixel vector to an imgui vector | ||
func IVec(v pixel.Vec) imgui.Vec2 { | ||
return imgui.Vec2{X: float32(v.X), Y: float32(v.Y)} | ||
} | ||
|
||
// IV creates an imgui vector from the given points. | ||
func IV(x, y float64) imgui.Vec2 { | ||
return imgui.Vec2{X: float32(x), Y: float32(y)} | ||
} | ||
|
||
// PV converts an imgui vector to a pixel vector | ||
func PV(v imgui.Vec2) pixel.Vec { | ||
return pixel.V(float64(v.X), float64(v.Y)) | ||
} | ||
|
||
// ProjectVec projects the vector by the UI's matrix (vertical flip) | ||
// and returns that as a imgui vector | ||
func ProjectVec(v pixel.Vec) imgui.Vec2 { | ||
return IVec(currentUI.matrix.Project(v)) | ||
} | ||
|
||
// ProjectV creates a pixel vector and projects it using ProjectVec | ||
func ProjectV(x, y float64) imgui.Vec2 { | ||
return ProjectVec(pixel.V(x, y)) | ||
} | ||
|
||
// UnprojectV unprojects the vector by the UI's matrix (vertical flip) | ||
// and returns that as a pixel vector | ||
func UnprojectV(v imgui.Vec2) pixel.Vec { | ||
return currentUI.matrix.Unproject(PV(v)) | ||
} | ||
|
||
// IZV returns an imgui zero vector | ||
func IZV() imgui.Vec2 { | ||
return imgui.Vec2{X: 0, Y: 0} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package pixelui | ||
|
||
import ( | ||
"unsafe" | ||
|
||
"github.com/dusk125/pixelutils/packer" | ||
"github.com/inkyblackness/imgui-go" | ||
|
||
"github.com/faiface/pixel" | ||
) | ||
|
||
const ( | ||
WrappedNone = iota | ||
WrappedSprite | ||
WrappedBatch | ||
WrappedCanvas | ||
) | ||
|
||
type wrapper struct { | ||
Type int | ||
Value interface{} | ||
} | ||
|
||
func Sprite(sprite *pixel.Sprite) imgui.TextureID { | ||
return imgui.TextureID(unsafe.Pointer(&wrapper{ | ||
Type: WrappedSprite, | ||
Value: sprite, | ||
})) | ||
} | ||
|
||
func (ui *UI) AddSprite(sprite *pixel.Sprite) imgui.TextureID { | ||
id, _ := ui.packer.InsertV(sprite, packer.InsertFlipped) | ||
return imgui.TextureID(id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters