diff --git a/examples/gui/icons/README.md b/examples/gui/icons/README.md new file mode 100644 index 0000000..8c114f4 --- /dev/null +++ b/examples/gui/icons/README.md @@ -0,0 +1,3 @@ +This example loads a custom .rgi-file and draws the 255th icon. You can use the [rGuiIcons](https://raylibtech.itch.io/rguiicons) tool to view or create icon files. + +![Screenshot](./screenshot.png) diff --git a/examples/gui/icons/default_icons_with_255.rgi b/examples/gui/icons/default_icons_with_255.rgi new file mode 100644 index 0000000..8271617 Binary files /dev/null and b/examples/gui/icons/default_icons_with_255.rgi differ diff --git a/examples/gui/icons/main.go b/examples/gui/icons/main.go new file mode 100644 index 0000000..1b48fd8 --- /dev/null +++ b/examples/gui/icons/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "github.com/gen2brain/raylib-go/raygui" + rl "github.com/gen2brain/raylib-go/raylib" +) + +func main() { + rl.InitWindow(800, 600, "raylib-go - icons example") + defer rl.CloseWindow() + + raygui.LoadIcons("default_icons_with_255.rgi", false) + + for !rl.WindowShouldClose() { + rl.BeginDrawing() + rl.ClearBackground(rl.RayWhite) + raygui.DrawIcon(raygui.ICON_255, 100, 100, 8, rl.Gray) + rl.EndDrawing() + } +} diff --git a/examples/gui/icons/screenshot.png b/examples/gui/icons/screenshot.png new file mode 100644 index 0000000..3e05961 Binary files /dev/null and b/examples/gui/icons/screenshot.png differ diff --git a/raygui/raygui.go b/raygui/raygui.go index 5c643f7..b72e28b 100644 --- a/raygui/raygui.go +++ b/raygui/raygui.go @@ -8,6 +8,7 @@ package raygui import "C" import ( + "image/color" "strings" "unsafe" @@ -1381,3 +1382,15 @@ func GetFont() rl.Font { ptr := unsafe.Pointer(&ret) return *(*rl.Font)(ptr) } + +// LoadIcons - load raygui icons file (.rgi) into internal icons data +func LoadIcons(fileName string, loadIconsName bool) { + cfileName := C.CString(fileName) + defer C.free(unsafe.Pointer(cfileName)) + C.GuiLoadIcons(cfileName, C.bool(loadIconsName)) +} + +// DrawIcon - draw icon using pixel size at specified position +func DrawIcon(iconId, posX, posY, pixelSize int32, col color.RGBA) { + C.GuiDrawIcon(C.int(iconId), C.int(posX), C.int(posY), C.int(pixelSize), *(*C.Color)(unsafe.Pointer(&col))) +}