ui
This commit is contained in:
parent
617d86276a
commit
91b851acd6
8 changed files with 204 additions and 8 deletions
|
|
@ -148,6 +148,31 @@ void suic_draw_cube_wires(float x, float y, float z, float width, float height,
|
||||||
DrawCubeWires((Vector3){x, y, z}, width, height, length, (Color){r, g, b, a});
|
DrawCubeWires((Vector3){x, y, z}, width, height, length, (Color){r, g, b, a});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2D Drawing (UI Framework Utils)
|
||||||
|
void suic_draw_text(const char *text, int x, int y, int font_size, unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
|
||||||
|
DrawText(text, x, y, font_size, (Color){r, g, b, a});
|
||||||
|
}
|
||||||
|
|
||||||
|
void suic_draw_rectangle(int x, int y, int width, int height, unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
|
||||||
|
DrawRectangle(x, y, width, height, (Color){r, g, b, a});
|
||||||
|
}
|
||||||
|
|
||||||
|
void suic_draw_rectangle_lines(int x, int y, int width, int height, unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
|
||||||
|
DrawRectangleLines(x, y, width, height, (Color){r, g, b, a});
|
||||||
|
}
|
||||||
|
|
||||||
|
int suic_measure_text(const char *text, int font_size) {
|
||||||
|
return MeasureText(text, font_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void suic_draw_circle(int center_x, int center_y, float radius, unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
|
||||||
|
DrawCircle(center_x, center_y, radius, (Color){r, g, b, a});
|
||||||
|
}
|
||||||
|
|
||||||
|
void suic_draw_line(int start_x, int start_y, int end_x, int end_y, unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
|
||||||
|
DrawLine(start_x, start_y, end_x, end_y, (Color){r, g, b, a});
|
||||||
|
}
|
||||||
|
|
||||||
// Input - Keyboard
|
// Input - Keyboard
|
||||||
bool suic_is_key_down(int key) { return IsKeyDown(key); }
|
bool suic_is_key_down(int key) { return IsKeyDown(key); }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,14 @@ void suic_end_mode3d(void);
|
||||||
void suic_draw_cube(float x, float y, float z, float width, float height, float length, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
void suic_draw_cube(float x, float y, float z, float width, float height, float length, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
||||||
void suic_draw_cube_wires(float x, float y, float z, float width, float height, float length, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
void suic_draw_cube_wires(float x, float y, float z, float width, float height, float length, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
||||||
|
|
||||||
|
// 2D Drawing (UI Framework Utils)
|
||||||
|
void suic_draw_text(const char *text, int x, int y, int font_size, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
||||||
|
void suic_draw_rectangle(int x, int y, int width, int height, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
||||||
|
void suic_draw_rectangle_lines(int x, int y, int width, int height, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
||||||
|
int suic_measure_text(const char *text, int font_size);
|
||||||
|
void suic_draw_circle(int center_x, int center_y, float radius, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
||||||
|
void suic_draw_line(int start_x, int start_y, int end_x, int end_y, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
||||||
|
|
||||||
// Input - Keyboard
|
// Input - Keyboard
|
||||||
bool suic_is_key_down(int key);
|
bool suic_is_key_down(int key);
|
||||||
bool suic_is_key_pressed(int key);
|
bool suic_is_key_pressed(int key);
|
||||||
|
|
|
||||||
34
soup/main.c
34
soup/main.c
|
|
@ -76,6 +76,8 @@ int suic_main(void) {
|
||||||
float pitch = 0.000000;
|
float pitch = 0.000000;
|
||||||
float mouse_sensitivity = 0.003000;
|
float mouse_sensitivity = 0.003000;
|
||||||
int fps_meter_visible = 1;
|
int fps_meter_visible = 1;
|
||||||
|
char** inventory = suic_alloc_array(NULL, sizeof(char*), 3, (char*[]){suic_alloc_array(NULL, sizeof(char), 6, "Sword"), suic_alloc_array(NULL, sizeof(char), 7, "Shield"), suic_alloc_array(NULL, sizeof(char), 7, "Potion")});
|
||||||
|
bool inventory_open = false;
|
||||||
float cube1_x = 0.000000;
|
float cube1_x = 0.000000;
|
||||||
float cube1_y = 0.000000;
|
float cube1_y = 0.000000;
|
||||||
float cube1_z = 0.000000;
|
float cube1_z = 0.000000;
|
||||||
|
|
@ -168,6 +170,15 @@ int suic_main(void) {
|
||||||
if ((suic_is_key_pressed(KEY_F3) != 0)) {
|
if ((suic_is_key_pressed(KEY_F3) != 0)) {
|
||||||
suic_show_fps_meter((suic_vec2){ .x = 10.000000, .y = 10.000000 });
|
suic_show_fps_meter((suic_vec2){ .x = 10.000000, .y = 10.000000 });
|
||||||
fps_meter_visible = 1;
|
fps_meter_visible = 1;
|
||||||
|
}
|
||||||
|
if ((suic_is_key_pressed(KEY_I) != 0)) {
|
||||||
|
if (inventory_open) {
|
||||||
|
inventory_open = false;
|
||||||
|
suic_disable_cursor();
|
||||||
|
} else {
|
||||||
|
inventory_open = true;
|
||||||
|
suic_enable_cursor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
camera_x = (player_x + (forward_x * 0.500000));
|
camera_x = (player_x + (forward_x * 0.500000));
|
||||||
camera_y = (player_y + 0.900000);
|
camera_y = (player_y + 0.900000);
|
||||||
|
|
@ -194,6 +205,29 @@ int suic_main(void) {
|
||||||
suic_draw_cube_wires(0.000000, 0.000000, 0.000000, 0.800000, 1.600000, 0.800000, 0, 0, 0, 255);
|
suic_draw_cube_wires(0.000000, 0.000000, 0.000000, 0.800000, 1.600000, 0.800000, 0, 0, 0, 255);
|
||||||
suic_rl_pop_matrix();
|
suic_rl_pop_matrix();
|
||||||
suic_end_mode3d();
|
suic_end_mode3d();
|
||||||
|
suic_draw_text(suic_alloc_array(NULL, sizeof(char), 2, "N"), 1260, 20, 20, 255, 255, 255, 255);
|
||||||
|
suic_draw_line(1270, 40, 1270, 60, 255, 255, 255, 255);
|
||||||
|
suic_draw_rectangle(1100, 20, 150, 150, 0, 0, 0, 128);
|
||||||
|
suic_draw_rectangle_lines(1100, 20, 150, 150, 255, 255, 255, 128);
|
||||||
|
int minimap_center_x = 1175;
|
||||||
|
int minimap_center_y = 95;
|
||||||
|
suic_draw_circle(minimap_center_x, minimap_center_y, 3.000000, 255, 255, 0, 128);
|
||||||
|
if (inventory_open) {
|
||||||
|
suic_draw_rectangle(200, 100, 400, 300, 0, 0, 0, 200);
|
||||||
|
suic_draw_text(suic_alloc_array(NULL, sizeof(char), 10, "Inventory"), 220, 120, 24, 255, 255, 255, 255);
|
||||||
|
suic_draw_text(suic_alloc_array(NULL, sizeof(char), 6, "Sword"), 220, 160, 18, 200, 200, 200, 255);
|
||||||
|
suic_draw_text(suic_alloc_array(NULL, sizeof(char), 7, "Shield"), 220, 190, 18, 200, 200, 200, 255);
|
||||||
|
suic_draw_text(suic_alloc_array(NULL, sizeof(char), 7, "Potion"), 220, 220, 18, 200, 200, 200, 255);
|
||||||
|
suic_draw_text(suic_alloc_array(NULL, sizeof(char), 17, "Press I to close"), 220, 350, 16, 150, 150, 150, 255);
|
||||||
|
}
|
||||||
|
suic_draw_rectangle(20, 680, 200, 20, 255, 0, 0, 128);
|
||||||
|
suic_draw_rectangle(20, 680, 150, 20, 0, 255, 0, 128);
|
||||||
|
int screen_width = 1280;
|
||||||
|
int screen_height = 720;
|
||||||
|
int crosshair_x = (screen_width / 2);
|
||||||
|
int crosshair_y = (screen_height / 2);
|
||||||
|
suic_draw_line((crosshair_x - 10), crosshair_y, (crosshair_x + 10), crosshair_y, 255, 255, 255, 255);
|
||||||
|
suic_draw_line(crosshair_x, (crosshair_y - 10), crosshair_x, (crosshair_y + 10), 255, 255, 255, 255);
|
||||||
suic_end_drawing();
|
suic_end_drawing();
|
||||||
}
|
}
|
||||||
suic_ode_geom_destroy(cube3_geom);
|
suic_ode_geom_destroy(cube3_geom);
|
||||||
|
|
|
||||||
BIN
soup/main.o
BIN
soup/main.o
Binary file not shown.
|
|
@ -100,6 +100,10 @@ fn main() -> int do
|
||||||
|
|
||||||
# FPS meter toggle
|
# FPS meter toggle
|
||||||
let mut fps_meter_visible = 1
|
let mut fps_meter_visible = 1
|
||||||
|
|
||||||
|
# Inventory system
|
||||||
|
let mut inventory = ["Sword", "Shield", "Potion"] # Array of item names
|
||||||
|
let mut inventory_open = false # Whether inventory UI is open
|
||||||
|
|
||||||
# Cube position variables
|
# Cube position variables
|
||||||
let mut cube1_x = 0.0
|
let mut cube1_x = 0.0
|
||||||
|
|
@ -235,6 +239,17 @@ fn main() -> int do
|
||||||
fps_meter_visible = 1
|
fps_meter_visible = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Toggle inventory with I key
|
||||||
|
if is_key_pressed(KEY_I) != 0 do
|
||||||
|
if inventory_open do
|
||||||
|
inventory_open = false
|
||||||
|
disable_cursor() # Hide cursor when inventory is closed
|
||||||
|
end else do
|
||||||
|
inventory_open = true
|
||||||
|
enable_cursor() # Show cursor when inventory is open
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Direction vectors are updated above
|
# Direction vectors are updated above
|
||||||
|
|
||||||
# Camera follows player (at eye position, slightly in front)
|
# Camera follows player (at eye position, slightly in front)
|
||||||
|
|
@ -280,7 +295,51 @@ fn main() -> int do
|
||||||
rl_pop_matrix()
|
rl_pop_matrix()
|
||||||
|
|
||||||
end_mode3d()
|
end_mode3d()
|
||||||
|
|
||||||
|
# 2D UI Rendering
|
||||||
|
# Direction indicator (compass)
|
||||||
|
draw_text("N", 1260, 20, 20, 255, 255, 255, 255)
|
||||||
|
draw_line(1270, 40, 1270, 60, 255, 255, 255, 255) # North indicator line
|
||||||
|
|
||||||
|
# Simple minimap (top-right corner)
|
||||||
|
draw_rectangle(1100, 20, 150, 150, 0, 0, 0, 128) # Semi-transparent background
|
||||||
|
draw_rectangle_lines(1100, 20, 150, 150, 255, 255, 255, 128) # Border
|
||||||
|
|
||||||
|
# Player position on minimap (center)
|
||||||
|
let minimap_center_x = 1175
|
||||||
|
let minimap_center_y = 95
|
||||||
|
draw_circle(minimap_center_x, minimap_center_y, 3.0, 255, 255, 0, 128) # Yellow dot for player
|
||||||
|
|
||||||
|
# Inventory UI (when open)
|
||||||
|
if inventory_open do
|
||||||
|
# Semi-transparent background
|
||||||
|
draw_rectangle(200, 100, 400, 300, 0, 0, 0, 200)
|
||||||
|
|
||||||
|
# Title
|
||||||
|
draw_text("Inventory", 220, 120, 24, 255, 255, 255, 255)
|
||||||
|
|
||||||
|
# Inventory items (hardcoded for now)
|
||||||
|
draw_text("Sword", 220, 160, 18, 200, 200, 200, 255)
|
||||||
|
draw_text("Shield", 220, 190, 18, 200, 200, 200, 255)
|
||||||
|
draw_text("Potion", 220, 220, 18, 200, 200, 200, 255)
|
||||||
|
|
||||||
|
# Instructions
|
||||||
|
draw_text("Press I to close", 220, 350, 16, 150, 150, 150, 255)
|
||||||
|
end
|
||||||
|
|
||||||
|
# HUD elements (always visible)
|
||||||
|
# Health bar
|
||||||
|
draw_rectangle(20, 680, 200, 20, 255, 0, 0, 128) # Red background
|
||||||
|
draw_rectangle(20, 680, 150, 20, 0, 255, 0, 128) # Green fill (75% health)
|
||||||
|
|
||||||
|
# Crosshair
|
||||||
|
let screen_width = 1280
|
||||||
|
let screen_height = 720
|
||||||
|
let crosshair_x = screen_width / 2
|
||||||
|
let crosshair_y = screen_height / 2
|
||||||
|
draw_line(crosshair_x - 10, crosshair_y, crosshair_x + 10, crosshair_y, 255, 255, 255, 255)
|
||||||
|
draw_line(crosshair_x, crosshair_y - 10, crosshair_x, crosshair_y + 10, 255, 255, 255, 255)
|
||||||
|
|
||||||
end_drawing()
|
end_drawing()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -637,6 +637,13 @@ impl Transpiler {
|
||||||
"rl_pop_matrix" => "suic_rl_pop_matrix",
|
"rl_pop_matrix" => "suic_rl_pop_matrix",
|
||||||
"rl_translate_f" => "suic_rl_translate_f",
|
"rl_translate_f" => "suic_rl_translate_f",
|
||||||
"rl_rotate_f" => "suic_rl_rotate_f",
|
"rl_rotate_f" => "suic_rl_rotate_f",
|
||||||
|
// UI Framework Utils
|
||||||
|
"draw_text" => "suic_draw_text",
|
||||||
|
"draw_rectangle" => "suic_draw_rectangle",
|
||||||
|
"draw_rectangle_lines" => "suic_draw_rectangle_lines",
|
||||||
|
"measure_text" => "suic_measure_text",
|
||||||
|
"draw_circle" => "suic_draw_circle",
|
||||||
|
"draw_line" => "suic_draw_line",
|
||||||
// Player controller functions
|
// Player controller functions
|
||||||
"player_controller_create" => "suic_player_controller_create",
|
"player_controller_create" => "suic_player_controller_create",
|
||||||
"player_controller_destroy" => "suic_player_controller_destroy",
|
"player_controller_destroy" => "suic_player_controller_destroy",
|
||||||
|
|
@ -779,13 +786,25 @@ impl Transpiler {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|expr| self.generate_expr(expr))
|
.map(|expr| self.generate_expr(expr))
|
||||||
.collect();
|
.collect();
|
||||||
// Generate heap-allocated array using helper function
|
|
||||||
// Use NULL for TypeInfo since arrays of primitives don't contain pointers
|
// Check if this is a string array (all elements are string allocations)
|
||||||
format!(
|
let is_string_array = vec.iter().all(|elem| elem.starts_with("suic_alloc_array(NULL, sizeof(char), "));
|
||||||
"suic_alloc_array(NULL, sizeof(int), {}, (int[]){{{}}})",
|
|
||||||
vec.len(),
|
if is_string_array {
|
||||||
vec.join(", ")
|
// String array: use char* elements
|
||||||
)
|
format!(
|
||||||
|
"suic_alloc_array(NULL, sizeof(char*), {}, (char*[]){{{}}})",
|
||||||
|
vec.len(),
|
||||||
|
vec.join(", ")
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
// Regular primitive array
|
||||||
|
format!(
|
||||||
|
"suic_alloc_array(NULL, sizeof(int), {}, (int[]){{{}}})",
|
||||||
|
vec.len(),
|
||||||
|
vec.join(", ")
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CExpr::Assign(lhs, rhs) => {
|
CExpr::Assign(lhs, rhs) => {
|
||||||
|
|
|
||||||
|
|
@ -743,6 +743,7 @@ impl TypeChecker {
|
||||||
"KEY_A",
|
"KEY_A",
|
||||||
"KEY_S",
|
"KEY_S",
|
||||||
"KEY_D",
|
"KEY_D",
|
||||||
|
"KEY_I",
|
||||||
"KEY_SPACE",
|
"KEY_SPACE",
|
||||||
"KEY_LEFT_SHIFT",
|
"KEY_LEFT_SHIFT",
|
||||||
"KEY_EQUAL",
|
"KEY_EQUAL",
|
||||||
|
|
@ -1210,6 +1211,56 @@ impl TypeChecker {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// ===== UI FRAMEWORK UTILS =====
|
||||||
|
self.env.functions.insert(
|
||||||
|
"draw_text".to_string(),
|
||||||
|
FunctionType {
|
||||||
|
type_params: vec![],
|
||||||
|
params: vec![Type::String, Type::Int, Type::Int, Type::Int, Type::Int, Type::Int, Type::Int, Type::Int], // text, x, y, font_size, r, g, b, a
|
||||||
|
return_type: Type::Unit,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
self.env.functions.insert(
|
||||||
|
"draw_rectangle".to_string(),
|
||||||
|
FunctionType {
|
||||||
|
type_params: vec![],
|
||||||
|
params: vec![Type::Int, Type::Int, Type::Int, Type::Int, Type::Int, Type::Int, Type::Int, Type::Int], // x, y, width, height, r, g, b, a
|
||||||
|
return_type: Type::Unit,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
self.env.functions.insert(
|
||||||
|
"draw_rectangle_lines".to_string(),
|
||||||
|
FunctionType {
|
||||||
|
type_params: vec![],
|
||||||
|
params: vec![Type::Int, Type::Int, Type::Int, Type::Int, Type::Int, Type::Int, Type::Int, Type::Int], // x, y, width, height, r, g, b, a
|
||||||
|
return_type: Type::Unit,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
self.env.functions.insert(
|
||||||
|
"measure_text".to_string(),
|
||||||
|
FunctionType {
|
||||||
|
type_params: vec![],
|
||||||
|
params: vec![Type::String, Type::Int], // text, font_size
|
||||||
|
return_type: Type::Int,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
self.env.functions.insert(
|
||||||
|
"draw_circle".to_string(),
|
||||||
|
FunctionType {
|
||||||
|
type_params: vec![],
|
||||||
|
params: vec![Type::Int, Type::Int, Type::Float, Type::Int, Type::Int, Type::Int, Type::Int], // center_x, center_y, radius, r, g, b, a
|
||||||
|
return_type: Type::Unit,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
self.env.functions.insert(
|
||||||
|
"draw_line".to_string(),
|
||||||
|
FunctionType {
|
||||||
|
type_params: vec![],
|
||||||
|
params: vec![Type::Int, Type::Int, Type::Int, Type::Int, Type::Int, Type::Int, Type::Int, Type::Int], // start_x, start_y, end_x, end_y, r, g, b, a
|
||||||
|
return_type: Type::Unit,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// ===== UUID GENERATION API =====
|
// ===== UUID GENERATION API =====
|
||||||
self.env.functions.insert(
|
self.env.functions.insert(
|
||||||
"uuid_generate_v4".to_string(),
|
"uuid_generate_v4".to_string(),
|
||||||
|
|
|
||||||
BIN
tests/fps_game.o
Executable file
BIN
tests/fps_game.o
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue