Added working text input box
This commit is contained in:
parent
15e5ad3454
commit
8da1321bdd
4 changed files with 56 additions and 20 deletions
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
|
@ -3,5 +3,5 @@
|
||||||
"activityBar.background": "#322C2D",
|
"activityBar.background": "#322C2D",
|
||||||
"titleBar.activeBackground": "#463E3F",
|
"titleBar.activeBackground": "#463E3F",
|
||||||
"titleBar.activeForeground": "#FAFAFA"
|
"titleBar.activeForeground": "#FAFAFA"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -17,42 +17,61 @@ import rl "vendor:raylib"
|
||||||
|
|
||||||
PixelWindowHeight :: 180
|
PixelWindowHeight :: 180
|
||||||
|
|
||||||
GameMemory :: struct {}
|
FILE_DIALOG_SIZE :: 1000
|
||||||
|
GameMemory :: struct {
|
||||||
|
file_dialog_text_buffer: [FILE_DIALOG_SIZE + 1]u8,
|
||||||
|
}
|
||||||
|
|
||||||
g_mem: ^GameMemory
|
g_mem: ^GameMemory
|
||||||
|
|
||||||
|
w, h: f32
|
||||||
|
|
||||||
game_camera :: proc() -> rl.Camera2D {
|
game_camera :: proc() -> rl.Camera2D {
|
||||||
w := f32(rl.GetScreenWidth())
|
w = f32(rl.GetScreenWidth())
|
||||||
h := f32(rl.GetScreenHeight())
|
h = f32(rl.GetScreenHeight())
|
||||||
|
|
||||||
return {zoom = h / PixelWindowHeight, target = {}, offset = {w / 2, h / 2}}
|
return {zoom = h / PixelWindowHeight, target = {}, offset = {w / 2, h / 2}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scaling: f32 = 2
|
||||||
ui_camera :: proc() -> rl.Camera2D {
|
ui_camera :: proc() -> rl.Camera2D {
|
||||||
return {zoom = f32(rl.GetScreenHeight()) / PixelWindowHeight}
|
// return {zoom = f32(rl.GetScreenHeight()) / PixelWindowHeight}
|
||||||
|
return {zoom = scaling}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input_box_loc: rl.Vector2 = {}
|
||||||
|
moving_input_box: bool
|
||||||
update :: proc() {
|
update :: proc() {
|
||||||
|
// Update the width/height
|
||||||
|
w = f32(rl.GetScreenWidth())
|
||||||
|
h = f32(rl.GetScreenHeight())
|
||||||
|
rl.SetMouseScale(1 / scaling, 1 / scaling)
|
||||||
|
|
||||||
|
if rl.IsMouseButtonDown(.RIGHT) {
|
||||||
|
input_box_loc = rl.GetMousePosition()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
draw :: proc() {
|
draw :: proc() {
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
defer rl.EndDrawing()
|
||||||
|
|
||||||
rl.ClearBackground(rl.BLACK)
|
rl.ClearBackground(rl.BLACK)
|
||||||
|
|
||||||
rl.BeginMode2D(game_camera())
|
|
||||||
// rl.DrawRectangleV(g_mem.player_pos, {4, 8}, rl.WHITE)
|
|
||||||
rl.DrawRectangleV({20, 20}, {10, 20}, rl.RED)
|
|
||||||
rl.EndMode2D()
|
|
||||||
|
|
||||||
rl.BeginMode2D(ui_camera())
|
rl.BeginMode2D(ui_camera())
|
||||||
// rl.DrawText(
|
rl.GuiTextInputBox(
|
||||||
// fmt.ctprintf("some_number: %v\nplayer_pos: %v", g_mem.some_number, g_mem.player_pos),
|
rl.Rectangle {
|
||||||
// 5,
|
x = input_box_loc.x,
|
||||||
// 5,
|
y = input_box_loc.y,
|
||||||
// 8,
|
width = (w / scaling) / 2,
|
||||||
// rl.WHITE,
|
height = (h / scaling) / 2,
|
||||||
// )
|
},
|
||||||
|
"Files",
|
||||||
|
"File input box",
|
||||||
|
"Button",
|
||||||
|
cstring(rawptr(&g_mem.file_dialog_text_buffer)),
|
||||||
|
FILE_DIALOG_SIZE,
|
||||||
|
nil,
|
||||||
|
)
|
||||||
rl.EndMode2D()
|
rl.EndMode2D()
|
||||||
|
}
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
|
|
|
||||||
15
src/input_box.odin
Normal file
15
src/input_box.odin
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
package game
|
||||||
|
|
||||||
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
|
// Check if any key is pressed
|
||||||
|
// NOTE: We limit keys check to keys between 32 (KEY_SPACE) and 126
|
||||||
|
IsAnyKeyPressed :: proc() -> (keyPressed: bool) {
|
||||||
|
key := rl.GetKeyPressed()
|
||||||
|
|
||||||
|
if (i32(key) >= 32) && (i32(key) <= 126) {
|
||||||
|
keyPressed = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package game
|
package game
|
||||||
|
|
||||||
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
@(export)
|
@(export)
|
||||||
game_update :: proc() -> bool {
|
game_update :: proc() -> bool {
|
||||||
update()
|
update()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue