Skip to content

Commit

Permalink
Updates for v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Ray committed Aug 22, 2024
1 parent 0ed8047 commit 1aac8ab
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 360 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# PixelUI
Adds GUIs to the [Pixel](https://github.com/faiface/pixel) rendering engine by interpreting [imgui-go](https://github.com/inkyblackness/imgui-go) render data into Pixel render calls.
Adds GUIs to the [Pixel](https://github.com/gopxl/pixel) rendering engine by interpreting [imgui-go](https://github.com/inkyblackness/imgui-go) render data into Pixel render calls.

# [Examples](https://github.com/dusk125/pixelui_examples)
The [examples](https://github.com/dusk125/pixelui_examples) repository contains an example demonstrating PixelUI's functionality.
# Example
The [examples](https://github.com/gopxl/pixel-examples/tree/main/ext/pixelui) repository contains an example demonstrating PixelUI's functionality.

To run an example, navigate to it's directory, then go run the test.go file. For example:

```
$ cd pixelui_examples
$ cd example
$ go run test.go
```

## Current Expected state
This is where we are currently...
![Current State](https://github.com/dusk125/pixelui_examples/blob/master/screenshots/current_state.png)
![Current State](https://github.com/gopxl/pixel-examples/blob/main/ext/pixelui/current_state.png)
21 changes: 8 additions & 13 deletions font.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,31 @@ package pixelui

import (
"fmt"
"image"
"image/color"
"log"
"os"
"unsafe"

"github.com/inkyblackness/imgui-go"

"github.com/faiface/pixel"
"github.com/inkyblackness/imgui-go/v4"
)

// loadFont parses the imgui font data and creates a pixel picture from it.
func (ui *UI) loadFont() {
f := ui.fonts.TextureDataAlpha8()
pic := pixel.MakePictureData(pixel.R(0, 0, float64(f.Width), float64(f.Height)))
pic := image.NewRGBA(image.Rect(0, 0, f.Width, f.Height))

for y := 0; y < f.Height; y++ {
for x := 0; x < f.Width; x++ {
i := y*f.Width + x
ptr := (*uint8)(unsafe.Pointer(uintptr(f.Pixels) + uintptr(i)))
pic.Pix[i] = color.RGBA{R: 0, G: 0, B: 0, A: *ptr}
pic.SetRGBA(x, y, color.RGBA{0, 0, 0, *ptr})
}
}

ui.fontAtlas = ui.win.MakePicture(pic)
id := "default-font"
if err := ui.packer.Replace(id, pixel.NewSprite(pic, pic.Bounds())); err != nil {
log.Fatalln(err)
}
ui.fontId = ui.packer.IdOf(id)
ui.fonts.SetTextureID(imgui.TextureID(ui.fontId))
ui.atlas.Clear(ui.group)
ui.font = ui.group.AddImage(pic)
ui.atlas.Pack()
ui.fonts.SetTextureID(imgui.TextureID(ui.font.ID()))
}

// loadDefaultFont loads the imgui default font if the user wants it.
Expand Down
10 changes: 6 additions & 4 deletions geo.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package pixelui

import (
"github.com/faiface/pixel"
"github.com/inkyblackness/imgui-go"
"github.com/gopxl/pixel/v2"
"github.com/inkyblackness/imgui-go/v4"
)

// imguiRectToPixelRect Converts the imgui rect to a Pixel rect
Expand All @@ -26,7 +26,8 @@ func PV(v imgui.Vec2) pixel.Vec {
}

// ProjectVec projects the vector by the UI's matrix (vertical flip)
// and returns that as a imgui vector
//
// and returns that as a imgui vector
func ProjectVec(v pixel.Vec) imgui.Vec2 {
return IVec(CurrentUI.matrix.Project(v))
}
Expand All @@ -37,7 +38,8 @@ func ProjectV(x, y float64) imgui.Vec2 {
}

// UnprojectV unprojects the vector by the UI's matrix (vertical flip)
// and returns that as a pixel vector
//
// and returns that as a pixel vector
func UnprojectV(v imgui.Vec2) pixel.Vec {
return CurrentUI.matrix.Unproject(PV(v))
}
Expand Down
21 changes: 15 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
module github.com/dusk125/pixelui
module github.com/gopxl/pixelui/v2

go 1.16
go 1.21

require (
github.com/dusk125/pixelutils v1.0.0
github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3
github.com/faiface/pixel v0.11.0-beta
github.com/inkyblackness/imgui-go v1.12.0
github.com/gopxl/mainthread/v2 v2.1.1
github.com/gopxl/pixel/v2 v2.2.1-0.20240821160809-8ed417f54c57
github.com/inkyblackness/imgui-go/v4 v4.7.0
)

require (
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect
github.com/go-gl/mathgl v1.1.0 // indirect
github.com/gopxl/glhf/v2 v2.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
golang.org/x/image v0.19.0 // indirect
)
54 changes: 25 additions & 29 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dusk125/pixelutils v1.0.0 h1:oaJW0Bl6I+WQb4DU8gzMKxNW5+ZwBBQXQLriXsiaKEU=
github.com/dusk125/pixelutils v1.0.0/go.mod h1:V17sw4+q2QWactw9hamp1XgGQQqKBJ6MAO1jEu+fPp8=
github.com/faiface/glhf v0.0.0-20181018222622-82a6317ac380 h1:FvZ0mIGh6b3kOITxUnxS3tLZMh7yEoHo75v3/AgUqg0=
github.com/faiface/glhf v0.0.0-20181018222622-82a6317ac380/go.mod h1:zqnPFFIuYFFxl7uH2gYByJwIVKG7fRqlqQCbzAnHs9g=
github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 h1:baVdMKlASEHrj19iqjARrPbaRisD7EuZEVJj6ZMLl1Q=
github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3/go.mod h1:VEPNJUlxl5KdWjDvz6Q1l+rJlxF2i6xqDeGuGAxa87M=
github.com/faiface/pixel v0.10.0/go.mod h1:lU0YYcW77vL0F1CG8oX51GXurymL45MXd57otHNLK7A=
github.com/faiface/pixel v0.11.0-beta h1:fnqbwutoJWgnfGsuGAXeVgSOVz2kOhknbFOIN/nEoOo=
github.com/faiface/pixel v0.11.0-beta/go.mod h1:hVfcuxlgBHDYw32viMEU0RnOAOzrLTBhNjyw5DhUqAk=
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluNRiMjZHalQZrVrvTbPh+qw=
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72 h1:b+9H1GAsx5RsjvDFLoS5zkNBzIQMuVKUYQDmxU3N5XE=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/mathgl v0.0.0-20190416160123-c4601bc793c7 h1:THttjeRn1iiz69E875U6gAik8KTWk/JYAHoSVpUxBBI=
github.com/go-gl/mathgl v0.0.0-20190416160123-c4601bc793c7/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/inkyblackness/imgui-go v1.12.0 h1:uaxSM5SbbqCTGEx5ig7B2J78hM3g3az4f5NC6b4J7lY=
github.com/inkyblackness/imgui-go v1.12.0/go.mod h1:S9wTWrw/HfxYPbOnqsbck9A6mxHRauv+Sy+bz5+BQwc=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71 h1:5BVwOaUSBTlVZowGO6VZGw2H/zl9nrd3eCZfYV+NfQA=
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a h1:vxnBhFDDT+xzxf1jTJKMKZw3H0swfWk9RpWbBbDK5+0=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/mathgl v1.1.0 h1:0lzZ+rntPX3/oGrDzYGdowSLC2ky8Osirvf5uAwfIEA=
github.com/go-gl/mathgl v1.1.0/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ=
github.com/gopxl/glhf/v2 v2.1.0 h1:IUydEPsxFVsfEu7mIWJBc9KSy/B5aXOXW/uHyRKUiAg=
github.com/gopxl/glhf/v2 v2.1.0/go.mod h1:InKwj5OoVdOAkpzsS0ILwpB+RrWBLw1i7aFefiGmrp8=
github.com/gopxl/mainthread/v2 v2.1.1 h1:S7jIvQZth9s2k8qFePOxtEgtZLzW/Yjykum2mscGr0o=
github.com/gopxl/mainthread/v2 v2.1.1/go.mod h1:RLdqSRamocAGPzK9P4HsZf+WXL5bfHHtX78O6GkKaUw=
github.com/gopxl/pixel/v2 v2.2.1-0.20240821160809-8ed417f54c57 h1:abGkun7FoChS6HIj2ft1MLzLJYnFR1WINuJNXjyNLww=
github.com/gopxl/pixel/v2 v2.2.1-0.20240821160809-8ed417f54c57/go.mod h1:4x2fUMpvunt+VFiBqd/5grkXCYTPoNwryqDWKnarFrs=
github.com/inkyblackness/imgui-go/v4 v4.7.0 h1:Gc169uXvSydsr/gjw3p1cmHCI1XIpqX7I3KBmfeMMOo=
github.com/inkyblackness/imgui-go/v4 v4.7.0/go.mod h1:g8SAGtOYUP7rYaOB2AsVKCEHmPMDmJKgt4z6d+flhb0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pzsz/voronoi v0.0.0-20130609164533-4314be88c79f h1:YeUeWAPTrycaikVXiVoAu1dxIR4+tSsn9IbTkNfRsss=
github.com/pzsz/voronoi v0.0.0-20130609164533-4314be88c79f/go.mod h1:T6EcHUIQ7r0Xr1jjOJ7hmpUaqVyqb9WimeNzS9nz4Zo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI=
golang.org/x/image v0.0.0-20190321063152-3fc05d484e9f/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190523035834-f03afa92d3ff/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9 h1:D0iM1dTCbD5Dg1CbuvLC/v/agLc79efSj/L35Q3Vqhs=
golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/image v0.19.0 h1:D9FX4QWkLfkeqaC62SonffIIuYdOk/UE2XKUBgRIBIQ=
golang.org/x/image v0.19.0/go.mod h1:y0zrRqlQRWQ5PXaYCOMLTW2fpsxZ8Qh9I/ohnInJEys=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
17 changes: 1 addition & 16 deletions helpers.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
package pixelui

import "github.com/inkyblackness/imgui-go"

// Image is a helper for imgui.Image that looks up the sprite in the internal packed atlas.
func (ui *UI) Image(alias interface{}, scale float64) {
id := ui.packer.IdOf(alias)
sprite := ui.packer.BoundsOf(alias)
imgui.Image(imgui.TextureID(id), IVec(sprite.Size().Scaled(scale)))
}

// ImageButton is a helper for imgui.ImageButton that looks up the sprite in the internal packed atlas.
func (ui *UI) ImageButton(alias interface{}, scale float64) bool {
id := ui.packer.IdOf(alias)
sprite := ui.packer.BoundsOf(alias)

return imgui.ImageButton(imgui.TextureID(id), IVec(sprite.Size().Scaled(scale)))
}
import "github.com/inkyblackness/imgui-go/v4"

// Color converts the given 8-bit r,g,b components to a imgui.Vec4 for color arguments
func Color(r, g, b uint8) imgui.Vec4 {
Expand Down
Loading

0 comments on commit 1aac8ab

Please sign in to comment.