-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.go
85 lines (66 loc) · 1.56 KB
/
test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
/*
#include "imgui.h"
struct ImDrawVert {
ImVec2 pos;
ImVec2 uv;
ImU32 col;
};
*/
import (
"fmt"
"log"
"github.com/dusk125/pixelutils"
_ "image/png"
"github.com/dusk125/pixelui"
"github.com/faiface/pixel"
"github.com/faiface/pixel/pixelgl"
"github.com/inkyblackness/imgui-go"
"golang.org/x/image/colornames"
)
func main() {
pixelgl.Run(run)
}
func run() {
cfg := pixelgl.WindowConfig{
Title: "PixelUi Test",
Bounds: pixel.R(0, 0, 1920, 1080),
}
win, err := pixelgl.NewWindow(cfg)
if err != nil {
log.Fatal(err)
}
ui := pixelui.NewUI(win, 0)
defer ui.Destroy()
// Can also add a loaded sprite with 'ui.AddSprite'
spriteId, sprite := ui.AddSpriteFromFile("golang.png")
// spriteId, sprite := ui.AddSpriteFromFile("ship.png")
ui.AddTTFFont("03b04.ttf", 16)
// imgui.StyleColorsLight()
ticker := pixelutils.NewTicker(60)
for !win.Closed() {
ui.NewFrame()
if win.JustReleased(pixelgl.KeyEscape) {
win.SetClosed(true)
}
win.Clear(colornames.Skyblue)
_, framerate := ticker.Tick()
if ui.JustPressed(pixelgl.MouseButtonLeft) {
fmt.Println("Left pressed")
}
if ui.JustReleased(pixelgl.MouseButtonLeft) {
fmt.Println("Left released")
}
imgui.ShowDemoWindow(nil)
imgui.Begin("Image Test")
imgui.Text(fmt.Sprintf("%.2f", framerate))
// Use the pixelui 'Image' helper function
ui.Image("golang", 0.5)
// Use the default imgui 'Image' function
imgui.Image(spriteId, pixelui.IVec(sprite.Picture().Bounds().Size().Scaled(0.25)))
imgui.End()
ui.Draw(win)
win.Update()
ticker.Wait()
}
}