Improve GUI on Android, add OpenAsset function
This commit is contained in:
parent
8fc94a8d3d
commit
56debbf236
7 changed files with 181 additions and 109 deletions
170
raygui/raygui.go
170
raygui/raygui.go
|
@ -5,7 +5,6 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -164,7 +163,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Current GUI style (default light)
|
// Current GUI style (default light)
|
||||||
var style = []int{
|
var style = []int64{
|
||||||
0xf5f5f5ff, // GLOBAL_BASE_COLOR
|
0xf5f5f5ff, // GLOBAL_BASE_COLOR
|
||||||
0xf5f5f5ff, // GLOBAL_BORDER_COLOR
|
0xf5f5f5ff, // GLOBAL_BORDER_COLOR
|
||||||
0xf5f5f5ff, // GLOBAL_TEXT_COLOR
|
0xf5f5f5ff, // GLOBAL_TEXT_COLOR
|
||||||
|
@ -423,7 +422,7 @@ func Button(bounds raylib.Rectangle, text string) bool {
|
||||||
if raylib.CheckCollisionPointRec(mousePoint, bounds) {
|
if raylib.CheckCollisionPointRec(mousePoint, bounds) {
|
||||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
||||||
buttonState = ButtonPressed
|
buttonState = ButtonPressed
|
||||||
} else if raylib.IsMouseButtonReleased(raylib.MouseLeftButton) {
|
} else if raylib.IsMouseButtonReleased(raylib.MouseLeftButton) || raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
||||||
buttonState = ButtonClicked
|
buttonState = ButtonClicked
|
||||||
} else {
|
} else {
|
||||||
buttonState = ButtonHover
|
buttonState = ButtonHover
|
||||||
|
@ -492,7 +491,7 @@ func ToggleButton(bounds raylib.Rectangle, text string, toggle bool) bool {
|
||||||
if raylib.CheckCollisionPointRec(mousePoint, toggleButton) {
|
if raylib.CheckCollisionPointRec(mousePoint, toggleButton) {
|
||||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
||||||
toggleState = TogglePressed
|
toggleState = TogglePressed
|
||||||
} else if raylib.IsMouseButtonReleased(raylib.MouseLeftButton) {
|
} else if raylib.IsMouseButtonReleased(raylib.MouseLeftButton) || raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
||||||
if toggle {
|
if toggle {
|
||||||
toggle = false
|
toggle = false
|
||||||
toggleState = ToggleUnactive
|
toggleState = ToggleUnactive
|
||||||
|
@ -574,7 +573,7 @@ func ComboBox(bounds raylib.Rectangle, comboText []string, comboActive int) int
|
||||||
if raylib.CheckCollisionPointRec(mousePoint, comboBoxButton) || raylib.CheckCollisionPointRec(mousePoint, click) {
|
if raylib.CheckCollisionPointRec(mousePoint, comboBoxButton) || raylib.CheckCollisionPointRec(mousePoint, click) {
|
||||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
||||||
comboBoxState = ComboboxPressed
|
comboBoxState = ComboboxPressed
|
||||||
} else if raylib.IsMouseButtonReleased(raylib.MouseLeftButton) {
|
} else if raylib.IsMouseButtonReleased(raylib.MouseLeftButton) || raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
||||||
comboBoxState = ComboboxActive
|
comboBoxState = ComboboxActive
|
||||||
} else {
|
} else {
|
||||||
comboBoxState = ComboboxHover
|
comboBoxState = ComboboxHover
|
||||||
|
@ -647,7 +646,7 @@ func CheckBox(bounds raylib.Rectangle, text string, checked bool) bool {
|
||||||
if raylib.CheckCollisionPointRec(mousePoint, bounds) {
|
if raylib.CheckCollisionPointRec(mousePoint, bounds) {
|
||||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
||||||
checkBoxState = CheckboxPressed
|
checkBoxState = CheckboxPressed
|
||||||
} else if raylib.IsMouseButtonReleased(raylib.MouseLeftButton) {
|
} else if raylib.IsMouseButtonReleased(raylib.MouseLeftButton) || raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
||||||
checkBoxState = CheckboxStatus
|
checkBoxState = CheckboxStatus
|
||||||
checked = !checked
|
checked = !checked
|
||||||
} else {
|
} else {
|
||||||
|
@ -1069,8 +1068,9 @@ func SaveGuiStyle(fileName string) {
|
||||||
|
|
||||||
// Load GUI style file
|
// Load GUI style file
|
||||||
func LoadGuiStyle(fileName string) {
|
func LoadGuiStyle(fileName string) {
|
||||||
file, err := os.Open(fileName)
|
file, err := raylib.OpenAsset(fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
raylib.TraceLog(raylib.LogWarning, "[%s] GUI style file could not be opened", fileName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
@ -1098,7 +1098,7 @@ func LoadGuiStyle(fileName string) {
|
||||||
|
|
||||||
v, err := strconv.ParseInt(value, 16, 64)
|
v, err := strconv.ParseInt(value, 16, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
style[i] = int(v)
|
style[i] = int64(v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1106,7 +1106,7 @@ func LoadGuiStyle(fileName string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set one style property
|
// Set one style property
|
||||||
func SetStyleProperty(guiProperty Property, value int) {
|
func SetStyleProperty(guiProperty Property, value int64) {
|
||||||
numColorSamples := 10
|
numColorSamples := 10
|
||||||
|
|
||||||
if guiProperty == GlobalBaseColor {
|
if guiProperty == GlobalBaseColor {
|
||||||
|
@ -1118,37 +1118,37 @@ func SetStyleProperty(guiProperty Property, value int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
style[GlobalBaseColor] = value
|
style[GlobalBaseColor] = value
|
||||||
style[GlobalBackgroundColor] = int(raylib.GetHexValue(fadeColor[3]))
|
style[GlobalBackgroundColor] = int64(raylib.GetHexValue(fadeColor[3]))
|
||||||
style[ButtonDefaultInsideColor] = int(raylib.GetHexValue(fadeColor[4]))
|
style[ButtonDefaultInsideColor] = int64(raylib.GetHexValue(fadeColor[4]))
|
||||||
style[ButtonHoverInsideColor] = int(raylib.GetHexValue(fadeColor[4]))
|
style[ButtonHoverInsideColor] = int64(raylib.GetHexValue(fadeColor[4]))
|
||||||
style[ButtonPressedInsideColor] = int(raylib.GetHexValue(fadeColor[5]))
|
style[ButtonPressedInsideColor] = int64(raylib.GetHexValue(fadeColor[5]))
|
||||||
style[ToggleDefaultInsideColor] = int(raylib.GetHexValue(fadeColor[4]))
|
style[ToggleDefaultInsideColor] = int64(raylib.GetHexValue(fadeColor[4]))
|
||||||
style[ToggleHoverInsideColor] = int(raylib.GetHexValue(fadeColor[4]))
|
style[ToggleHoverInsideColor] = int64(raylib.GetHexValue(fadeColor[4]))
|
||||||
style[TogglePressedInsideColor] = int(raylib.GetHexValue(fadeColor[5]))
|
style[TogglePressedInsideColor] = int64(raylib.GetHexValue(fadeColor[5]))
|
||||||
style[ToggleActiveInsideColor] = int(raylib.GetHexValue(fadeColor[8]))
|
style[ToggleActiveInsideColor] = int64(raylib.GetHexValue(fadeColor[8]))
|
||||||
style[SliderInsideColor] = int(raylib.GetHexValue(fadeColor[4]))
|
style[SliderInsideColor] = int64(raylib.GetHexValue(fadeColor[4]))
|
||||||
style[SliderDefaultColor] = int(raylib.GetHexValue(fadeColor[6]))
|
style[SliderDefaultColor] = int64(raylib.GetHexValue(fadeColor[6]))
|
||||||
style[SliderHoverColor] = int(raylib.GetHexValue(fadeColor[7]))
|
style[SliderHoverColor] = int64(raylib.GetHexValue(fadeColor[7]))
|
||||||
style[SliderActiveColor] = int(raylib.GetHexValue(fadeColor[9]))
|
style[SliderActiveColor] = int64(raylib.GetHexValue(fadeColor[9]))
|
||||||
style[SliderbarInsideColor] = int(raylib.GetHexValue(fadeColor[4]))
|
style[SliderbarInsideColor] = int64(raylib.GetHexValue(fadeColor[4]))
|
||||||
style[SliderbarDefaultColor] = int(raylib.GetHexValue(fadeColor[6]))
|
style[SliderbarDefaultColor] = int64(raylib.GetHexValue(fadeColor[6]))
|
||||||
style[SliderbarHoverColor] = int(raylib.GetHexValue(fadeColor[7]))
|
style[SliderbarHoverColor] = int64(raylib.GetHexValue(fadeColor[7]))
|
||||||
style[SliderbarActiveColor] = int(raylib.GetHexValue(fadeColor[9]))
|
style[SliderbarActiveColor] = int64(raylib.GetHexValue(fadeColor[9]))
|
||||||
style[SliderbarZeroLineColor] = int(raylib.GetHexValue(fadeColor[8]))
|
style[SliderbarZeroLineColor] = int64(raylib.GetHexValue(fadeColor[8]))
|
||||||
style[ProgressbarInsideColor] = int(raylib.GetHexValue(fadeColor[4]))
|
style[ProgressbarInsideColor] = int64(raylib.GetHexValue(fadeColor[4]))
|
||||||
style[ProgressbarProgressColor] = int(raylib.GetHexValue(fadeColor[6]))
|
style[ProgressbarProgressColor] = int64(raylib.GetHexValue(fadeColor[6]))
|
||||||
style[SpinnerLabelInsideColor] = int(raylib.GetHexValue(fadeColor[4]))
|
style[SpinnerLabelInsideColor] = int64(raylib.GetHexValue(fadeColor[4]))
|
||||||
style[SpinnerDefaultButtonInsideColor] = int(raylib.GetHexValue(fadeColor[4]))
|
style[SpinnerDefaultButtonInsideColor] = int64(raylib.GetHexValue(fadeColor[4]))
|
||||||
style[SpinnerHoverButtonInsideColor] = int(raylib.GetHexValue(fadeColor[4]))
|
style[SpinnerHoverButtonInsideColor] = int64(raylib.GetHexValue(fadeColor[4]))
|
||||||
style[SpinnerPressedButtonInsideColor] = int(raylib.GetHexValue(fadeColor[5]))
|
style[SpinnerPressedButtonInsideColor] = int64(raylib.GetHexValue(fadeColor[5]))
|
||||||
style[ComboboxDefaultInsideColor] = int(raylib.GetHexValue(fadeColor[4]))
|
style[ComboboxDefaultInsideColor] = int64(raylib.GetHexValue(fadeColor[4]))
|
||||||
style[ComboboxHoverInsideColor] = int(raylib.GetHexValue(fadeColor[4]))
|
style[ComboboxHoverInsideColor] = int64(raylib.GetHexValue(fadeColor[4]))
|
||||||
style[ComboboxPressedInsideColor] = int(raylib.GetHexValue(fadeColor[8]))
|
style[ComboboxPressedInsideColor] = int64(raylib.GetHexValue(fadeColor[8]))
|
||||||
style[ComboboxPressedListInsideColor] = int(raylib.GetHexValue(fadeColor[8]))
|
style[ComboboxPressedListInsideColor] = int64(raylib.GetHexValue(fadeColor[8]))
|
||||||
style[CheckboxDefaultInsideColor] = int(raylib.GetHexValue(fadeColor[4]))
|
style[CheckboxDefaultInsideColor] = int64(raylib.GetHexValue(fadeColor[4]))
|
||||||
style[CheckboxClickInsideColor] = int(raylib.GetHexValue(fadeColor[6]))
|
style[CheckboxClickInsideColor] = int64(raylib.GetHexValue(fadeColor[6]))
|
||||||
style[CheckboxStatusActiveColor] = int(raylib.GetHexValue(fadeColor[8]))
|
style[CheckboxStatusActiveColor] = int64(raylib.GetHexValue(fadeColor[8]))
|
||||||
style[TextboxInsideColor] = int(raylib.GetHexValue(fadeColor[4]))
|
style[TextboxInsideColor] = int64(raylib.GetHexValue(fadeColor[4]))
|
||||||
} else if guiProperty == GlobalBorderColor {
|
} else if guiProperty == GlobalBorderColor {
|
||||||
baseColor := raylib.GetColor(int32(value))
|
baseColor := raylib.GetColor(int32(value))
|
||||||
fadeColor := make([]raylib.Color, numColorSamples)
|
fadeColor := make([]raylib.Color, numColorSamples)
|
||||||
|
@ -1158,28 +1158,28 @@ func SetStyleProperty(guiProperty Property, value int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
style[GlobalBorderColor] = value
|
style[GlobalBorderColor] = value
|
||||||
style[ButtonDefaultBorderColor] = int(raylib.GetHexValue(fadeColor[7]))
|
style[ButtonDefaultBorderColor] = int64(raylib.GetHexValue(fadeColor[7]))
|
||||||
style[ButtonHoverBorderColor] = int(raylib.GetHexValue(fadeColor[8]))
|
style[ButtonHoverBorderColor] = int64(raylib.GetHexValue(fadeColor[8]))
|
||||||
style[ButtonPressedBorderColor] = int(raylib.GetHexValue(fadeColor[9]))
|
style[ButtonPressedBorderColor] = int64(raylib.GetHexValue(fadeColor[9]))
|
||||||
style[ToggleDefaultBorderColor] = int(raylib.GetHexValue(fadeColor[7]))
|
style[ToggleDefaultBorderColor] = int64(raylib.GetHexValue(fadeColor[7]))
|
||||||
style[ToggleHoverBorderColor] = int(raylib.GetHexValue(fadeColor[8]))
|
style[ToggleHoverBorderColor] = int64(raylib.GetHexValue(fadeColor[8]))
|
||||||
style[TogglePressedBorderColor] = int(raylib.GetHexValue(fadeColor[9]))
|
style[TogglePressedBorderColor] = int64(raylib.GetHexValue(fadeColor[9]))
|
||||||
style[ToggleActiveBorderColor] = int(raylib.GetHexValue(fadeColor[9]))
|
style[ToggleActiveBorderColor] = int64(raylib.GetHexValue(fadeColor[9]))
|
||||||
style[SliderBorderColor] = int(raylib.GetHexValue(fadeColor[7]))
|
style[SliderBorderColor] = int64(raylib.GetHexValue(fadeColor[7]))
|
||||||
style[SliderbarBorderColor] = int(raylib.GetHexValue(fadeColor[7]))
|
style[SliderbarBorderColor] = int64(raylib.GetHexValue(fadeColor[7]))
|
||||||
style[ProgressbarBorderColor] = int(raylib.GetHexValue(fadeColor[7]))
|
style[ProgressbarBorderColor] = int64(raylib.GetHexValue(fadeColor[7]))
|
||||||
style[SpinnerLabelBorderColor] = int(raylib.GetHexValue(fadeColor[7]))
|
style[SpinnerLabelBorderColor] = int64(raylib.GetHexValue(fadeColor[7]))
|
||||||
style[SpinnerDefaultButtonBorderColor] = int(raylib.GetHexValue(fadeColor[7]))
|
style[SpinnerDefaultButtonBorderColor] = int64(raylib.GetHexValue(fadeColor[7]))
|
||||||
style[SpinnerHoverButtonBorderColor] = int(raylib.GetHexValue(fadeColor[8]))
|
style[SpinnerHoverButtonBorderColor] = int64(raylib.GetHexValue(fadeColor[8]))
|
||||||
style[SpinnerPressedButtonBorderColor] = int(raylib.GetHexValue(fadeColor[9]))
|
style[SpinnerPressedButtonBorderColor] = int64(raylib.GetHexValue(fadeColor[9]))
|
||||||
style[ComboboxDefaultBorderColor] = int(raylib.GetHexValue(fadeColor[7]))
|
style[ComboboxDefaultBorderColor] = int64(raylib.GetHexValue(fadeColor[7]))
|
||||||
style[ComboboxHoverBorderColor] = int(raylib.GetHexValue(fadeColor[8]))
|
style[ComboboxHoverBorderColor] = int64(raylib.GetHexValue(fadeColor[8]))
|
||||||
style[ComboboxPressedBorderColor] = int(raylib.GetHexValue(fadeColor[9]))
|
style[ComboboxPressedBorderColor] = int64(raylib.GetHexValue(fadeColor[9]))
|
||||||
style[ComboboxPressedListBorderColor] = int(raylib.GetHexValue(fadeColor[9]))
|
style[ComboboxPressedListBorderColor] = int64(raylib.GetHexValue(fadeColor[9]))
|
||||||
style[CheckboxDefaultBorderColor] = int(raylib.GetHexValue(fadeColor[7]))
|
style[CheckboxDefaultBorderColor] = int64(raylib.GetHexValue(fadeColor[7]))
|
||||||
style[CheckboxHoverBorderColor] = int(raylib.GetHexValue(fadeColor[8]))
|
style[CheckboxHoverBorderColor] = int64(raylib.GetHexValue(fadeColor[8]))
|
||||||
style[CheckboxClickBorderColor] = int(raylib.GetHexValue(fadeColor[9]))
|
style[CheckboxClickBorderColor] = int64(raylib.GetHexValue(fadeColor[9]))
|
||||||
style[TextboxBorderColor] = int(raylib.GetHexValue(fadeColor[7]))
|
style[TextboxBorderColor] = int64(raylib.GetHexValue(fadeColor[7]))
|
||||||
} else if guiProperty == GlobalTextColor {
|
} else if guiProperty == GlobalTextColor {
|
||||||
baseColor := raylib.GetColor(int32(value))
|
baseColor := raylib.GetColor(int32(value))
|
||||||
fadeColor := make([]raylib.Color, numColorSamples)
|
fadeColor := make([]raylib.Color, numColorSamples)
|
||||||
|
@ -1189,35 +1189,35 @@ func SetStyleProperty(guiProperty Property, value int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
style[GlobalTextColor] = value
|
style[GlobalTextColor] = value
|
||||||
style[LabelTextColor] = int(raylib.GetHexValue(fadeColor[9]))
|
style[LabelTextColor] = int64(raylib.GetHexValue(fadeColor[9]))
|
||||||
style[ButtonDefaultTextColor] = int(raylib.GetHexValue(fadeColor[9]))
|
style[ButtonDefaultTextColor] = int64(raylib.GetHexValue(fadeColor[9]))
|
||||||
style[ButtonHoverTextColor] = int(raylib.GetHexValue(fadeColor[8]))
|
style[ButtonHoverTextColor] = int64(raylib.GetHexValue(fadeColor[8]))
|
||||||
style[ButtonPressedTextColor] = int(raylib.GetHexValue(fadeColor[5]))
|
style[ButtonPressedTextColor] = int64(raylib.GetHexValue(fadeColor[5]))
|
||||||
style[ToggleDefaultTextColor] = int(raylib.GetHexValue(fadeColor[9]))
|
style[ToggleDefaultTextColor] = int64(raylib.GetHexValue(fadeColor[9]))
|
||||||
style[ToggleHoverTextColor] = int(raylib.GetHexValue(fadeColor[8]))
|
style[ToggleHoverTextColor] = int64(raylib.GetHexValue(fadeColor[8]))
|
||||||
style[TogglePressedTextColor] = int(raylib.GetHexValue(fadeColor[5]))
|
style[TogglePressedTextColor] = int64(raylib.GetHexValue(fadeColor[5]))
|
||||||
style[ToggleActiveTextColor] = int(raylib.GetHexValue(fadeColor[5]))
|
style[ToggleActiveTextColor] = int64(raylib.GetHexValue(fadeColor[5]))
|
||||||
style[SpinnerDefaultSymbolColor] = int(raylib.GetHexValue(fadeColor[9]))
|
style[SpinnerDefaultSymbolColor] = int64(raylib.GetHexValue(fadeColor[9]))
|
||||||
style[SpinnerDefaultTextColor] = int(raylib.GetHexValue(fadeColor[9]))
|
style[SpinnerDefaultTextColor] = int64(raylib.GetHexValue(fadeColor[9]))
|
||||||
style[SpinnerHoverSymbolColor] = int(raylib.GetHexValue(fadeColor[8]))
|
style[SpinnerHoverSymbolColor] = int64(raylib.GetHexValue(fadeColor[8]))
|
||||||
style[SpinnerHoverTextColor] = int(raylib.GetHexValue(fadeColor[8]))
|
style[SpinnerHoverTextColor] = int64(raylib.GetHexValue(fadeColor[8]))
|
||||||
style[SpinnerPressedSymbolColor] = int(raylib.GetHexValue(fadeColor[5]))
|
style[SpinnerPressedSymbolColor] = int64(raylib.GetHexValue(fadeColor[5]))
|
||||||
style[SpinnerPressedTextColor] = int(raylib.GetHexValue(fadeColor[5]))
|
style[SpinnerPressedTextColor] = int64(raylib.GetHexValue(fadeColor[5]))
|
||||||
style[ComboboxDefaultTextColor] = int(raylib.GetHexValue(fadeColor[9]))
|
style[ComboboxDefaultTextColor] = int64(raylib.GetHexValue(fadeColor[9]))
|
||||||
style[ComboboxDefaultListTextColor] = int(raylib.GetHexValue(fadeColor[9]))
|
style[ComboboxDefaultListTextColor] = int64(raylib.GetHexValue(fadeColor[9]))
|
||||||
style[ComboboxHoverTextColor] = int(raylib.GetHexValue(fadeColor[8]))
|
style[ComboboxHoverTextColor] = int64(raylib.GetHexValue(fadeColor[8]))
|
||||||
style[ComboboxHoverListTextColor] = int(raylib.GetHexValue(fadeColor[8]))
|
style[ComboboxHoverListTextColor] = int64(raylib.GetHexValue(fadeColor[8]))
|
||||||
style[ComboboxPressedTextColor] = int(raylib.GetHexValue(fadeColor[4]))
|
style[ComboboxPressedTextColor] = int64(raylib.GetHexValue(fadeColor[4]))
|
||||||
style[ComboboxPressedListTextColor] = int(raylib.GetHexValue(fadeColor[4]))
|
style[ComboboxPressedListTextColor] = int64(raylib.GetHexValue(fadeColor[4]))
|
||||||
style[TextboxTextColor] = int(raylib.GetHexValue(fadeColor[9]))
|
style[TextboxTextColor] = int64(raylib.GetHexValue(fadeColor[9]))
|
||||||
style[TextboxLineColor] = int(raylib.GetHexValue(fadeColor[6]))
|
style[TextboxLineColor] = int64(raylib.GetHexValue(fadeColor[6]))
|
||||||
} else {
|
} else {
|
||||||
style[guiProperty] = value
|
style[guiProperty] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get one style property
|
// Get one style property
|
||||||
func GetStyleProperty(guiProperty Property) int {
|
func GetStyleProperty(guiProperty Property) int64 {
|
||||||
return style[int(guiProperty)]
|
return style[int(guiProperty)]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,3 +5,9 @@
|
||||||
void android_main(struct android_app *app) {
|
void android_main(struct android_app *app) {
|
||||||
androidMain(app);
|
androidMain(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init_asset_manager(void *state) {
|
||||||
|
struct android_app *app;
|
||||||
|
app = (struct android_app *)state;
|
||||||
|
asset_manager = app->activity->assetManager;
|
||||||
|
}
|
||||||
|
|
|
@ -4,12 +4,21 @@ package raylib
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "android_native_app_glue.h"
|
#include <android/asset_manager.h>
|
||||||
|
#include <android_native_app_glue.h>
|
||||||
|
|
||||||
extern void android_main(struct android_app *app);
|
extern void android_main(struct android_app *app);
|
||||||
|
|
||||||
|
AAssetManager* asset_manager;
|
||||||
|
extern void init_asset_manager(void *state);
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import "unsafe"
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
var callbackHolder func(unsafe.Pointer)
|
var callbackHolder func(unsafe.Pointer)
|
||||||
|
|
||||||
|
@ -18,6 +27,7 @@ func InitWindow(width int32, height int32, app unsafe.Pointer) {
|
||||||
cwidth := (C.int)(width)
|
cwidth := (C.int)(width)
|
||||||
cheight := (C.int)(height)
|
cheight := (C.int)(height)
|
||||||
C.InitWindow(cwidth, cheight, app)
|
C.InitWindow(cwidth, cheight, app)
|
||||||
|
C.init_asset_manager(app)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets callback function
|
// Sets callback function
|
||||||
|
@ -31,3 +41,34 @@ func androidMain(app *C.struct_android_app) {
|
||||||
callbackHolder(unsafe.Pointer(app))
|
callbackHolder(unsafe.Pointer(app))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Open asset
|
||||||
|
func OpenAsset(name string) (io.ReadCloser, error) {
|
||||||
|
cname := C.CString(name)
|
||||||
|
defer C.free(unsafe.Pointer(cname))
|
||||||
|
|
||||||
|
a := &asset{C.AAssetManager_open(C.asset_manager, cname, C.AASSET_MODE_UNKNOWN)}
|
||||||
|
|
||||||
|
if a.ptr == nil {
|
||||||
|
return nil, errors.New("asset file could not be opened")
|
||||||
|
}
|
||||||
|
|
||||||
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type asset struct {
|
||||||
|
ptr *C.AAsset
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *asset) Read(p []byte) (n int, err error) {
|
||||||
|
n = int(C.AAsset_read(a.ptr, unsafe.Pointer(&p[0]), C.size_t(len(p))))
|
||||||
|
if n == 0 && len(p) > 0 {
|
||||||
|
return 0, io.EOF
|
||||||
|
}
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *asset) Close() error {
|
||||||
|
C.AAsset_close(a.ptr)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -44,3 +44,12 @@ func EnableCursor() {
|
||||||
func DisableCursor() {
|
func DisableCursor() {
|
||||||
C.DisableCursor()
|
C.DisableCursor()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Open asset
|
||||||
|
func OpenAsset(name string) (io.ReadCloser, error) {
|
||||||
|
f, err := os.Open(name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return f, nil
|
||||||
|
}
|
||||||
|
|
|
@ -7,7 +7,12 @@ package raylib
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import "unsafe"
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
// Initialize Window and OpenGL Graphics
|
// Initialize Window and OpenGL Graphics
|
||||||
func InitWindow(width int32, height int32, title string) {
|
func InitWindow(width int32, height int32, title string) {
|
||||||
|
@ -70,3 +75,12 @@ func GetDroppedFiles(count *int32) []string {
|
||||||
func ClearDroppedFiles() {
|
func ClearDroppedFiles() {
|
||||||
C.ClearDroppedFiles()
|
C.ClearDroppedFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Open asset
|
||||||
|
func OpenAsset(name string) (io.ReadCloser, error) {
|
||||||
|
f, err := os.Open(name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return f, nil
|
||||||
|
}
|
||||||
|
|
|
@ -17,6 +17,11 @@ const (
|
||||||
|
|
||||||
var traceDebugMsgs = false
|
var traceDebugMsgs = false
|
||||||
|
|
||||||
|
// Set debug messages
|
||||||
|
func SetDebug(enabled bool) {
|
||||||
|
traceDebugMsgs = enabled
|
||||||
|
}
|
||||||
|
|
||||||
// Trace log
|
// Trace log
|
||||||
func TraceLog(msgType int, text string, v ...interface{}) {
|
func TraceLog(msgType int, text string, v ...interface{}) {
|
||||||
switch msgType {
|
switch msgType {
|
||||||
|
@ -33,8 +38,3 @@ func TraceLog(msgType int, text string, v ...interface{}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set debug messages
|
|
||||||
func SetDebug(enabled bool) {
|
|
||||||
traceDebugMsgs = enabled
|
|
||||||
}
|
|
||||||
|
|
|
@ -6,26 +6,26 @@ package raylib
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void logInfo(const char *msg) {
|
void log_info(const char *msg) {
|
||||||
__android_log_print(ANDROID_LOG_INFO, "raylib", msg);
|
__android_log_print(ANDROID_LOG_INFO, "raylib", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void logWarn(const char *msg) {
|
void log_warn(const char *msg) {
|
||||||
__android_log_print(ANDROID_LOG_WARN, "raylib", msg);
|
__android_log_print(ANDROID_LOG_WARN, "raylib", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void logError(const char *msg) {
|
void log_error(const char *msg) {
|
||||||
__android_log_print(ANDROID_LOG_ERROR, "raylib", msg);
|
__android_log_print(ANDROID_LOG_ERROR, "raylib", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void logDebug(const char *msg) {
|
void log_debug(const char *msg) {
|
||||||
__android_log_print(ANDROID_LOG_DEBUG, "raylib", msg);
|
__android_log_print(ANDROID_LOG_DEBUG, "raylib", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void logInfo(const char *msg);
|
void log_info(const char *msg);
|
||||||
void logWarn(const char *msg);
|
void log_warn(const char *msg);
|
||||||
void logError(const char *msg);
|
void log_error(const char *msg);
|
||||||
void logDebug(const char *msg);
|
void log_debug(const char *msg);
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
@ -45,30 +45,32 @@ const (
|
||||||
|
|
||||||
var traceDebugMsgs = false
|
var traceDebugMsgs = false
|
||||||
|
|
||||||
|
// Set debug messages
|
||||||
|
func SetDebug(enabled bool) {
|
||||||
|
traceDebugMsgs = enabled
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trace log
|
||||||
func TraceLog(msgType int, text string, v ...interface{}) {
|
func TraceLog(msgType int, text string, v ...interface{}) {
|
||||||
switch msgType {
|
switch msgType {
|
||||||
case LogInfo:
|
case LogInfo:
|
||||||
msg := C.CString(fmt.Sprintf("INFO: "+text, v...))
|
msg := C.CString(fmt.Sprintf("INFO: "+text, v...))
|
||||||
defer C.free(unsafe.Pointer(msg))
|
defer C.free(unsafe.Pointer(msg))
|
||||||
C.logInfo(msg)
|
C.log_info(msg)
|
||||||
case LogError:
|
case LogError:
|
||||||
msg := C.CString(fmt.Sprintf("ERROR: "+text, v...))
|
msg := C.CString(fmt.Sprintf("ERROR: "+text, v...))
|
||||||
defer C.free(unsafe.Pointer(msg))
|
defer C.free(unsafe.Pointer(msg))
|
||||||
C.logError(msg)
|
C.log_error(msg)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
case LogWarning:
|
case LogWarning:
|
||||||
msg := C.CString(fmt.Sprintf("WARNING: "+text, v...))
|
msg := C.CString(fmt.Sprintf("WARNING: "+text, v...))
|
||||||
defer C.free(unsafe.Pointer(msg))
|
defer C.free(unsafe.Pointer(msg))
|
||||||
C.logWarn(msg)
|
C.log_warn(msg)
|
||||||
case LogDebug:
|
case LogDebug:
|
||||||
if traceDebugMsgs {
|
if traceDebugMsgs {
|
||||||
msg := C.CString(fmt.Sprintf("DEBUG: "+text, v...))
|
msg := C.CString(fmt.Sprintf("DEBUG: "+text, v...))
|
||||||
defer C.free(unsafe.Pointer(msg))
|
defer C.free(unsafe.Pointer(msg))
|
||||||
C.logDebug(msg)
|
C.log_debug(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetDebug(enabled bool) {
|
|
||||||
traceDebugMsgs = enabled
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue