Radians/degrees

This commit is contained in:
Synthasmagoria 2026-08-28 10:45:52 +02:00
commit 38b7690223
4 changed files with 29 additions and 39 deletions

View file

@ -1,6 +1,3 @@
- Playback slider
- Icons for saving
- Set bigger font size
- Save grid and animation data to file
- Fix focus on submenu
- Centered justification in UI

BIN
default

Binary file not shown.

View file

@ -63,7 +63,7 @@ ElementType :: enum {
Slider,
InputFloat,
InputText,
Dropdown,
ToggleGroup,
Label,
Divider,
Custom0, Custom1, Custom2, Custom3, Custom4, Custom5, Custom6, Custom7, Custom8, Custom9,

View file

@ -57,7 +57,7 @@ UiElementData_TextInput :: struct {
str: cstring,
}
UiElementData_Dropdown :: struct {
UiElementData_ToggleGroup :: struct {
value: ^i32,
}
@ -223,6 +223,11 @@ MouseDraggable :: union {
MouseDraggable_RectangleData,
}
RotationMode :: enum {
Degrees,
Radians,
}
Program :: struct {
ui_context: ui.Context,
ui_element_focus: ui.ElementId,
@ -241,6 +246,7 @@ Program :: struct {
mouse_current_draggable: MouseDraggable,
mouse_draggable_radius: f32,
project_save_string: [DIALOG_STATE_TEXT_INPUT_FIELD_COUNT]byte,
rotation_mode: RotationMode,
grid: Grid,
grid_zoom_x_only: bool,
grid_zoom_y_only: bool,
@ -458,6 +464,10 @@ program_update :: proc() {
}
case .Dialog:
ui_overlay_elements = program_build_dialog_ui(&program.ui_overlay_context, program.dialog_type)
if program.ui_overlay_queue_focus_first {
program.ui_overlay_queue_focus_first = false
program.ui_overlay_element_focus = ui.focus_next_element({container_index = 0, element_index = 0}, ui_overlay_elements, UI_ALLOWED_FOCUS)
}
if rl.IsKeyPressed(.TAB) {
program.ui_overlay_element_focus = ui.focus_next_element(program.ui_overlay_element_focus, ui_overlay_elements, UI_ALLOWED_FOCUS)
}
@ -555,11 +565,6 @@ program_update :: proc() {
program.font_style,
ui_overlay_elements)
}
if program.ui_overlay_queue_focus_first {
program.ui_overlay_queue_focus_first = false
program.ui_overlay_element_focus = ui.focus_next_element({container_index = 0, element_index = 0}, ui_overlay_elements, UI_ALLOWED_FOCUS)
}
}
program_add_identity_matrix :: proc() {
@ -598,6 +603,11 @@ program_add_scalar_matrix :: proc(x, y, z: f32) {
program_add_rotation_matrix :: proc(angle: f32) {
value_strings, values := matrix_pool_get_mat3()
radians: f32
switch (program.rotation_mode) {
case .Degrees: radians = linalg.RAD_PER_DEG * angle
case .Radians: radians = angle
}
rotmat := linalg.matrix2_rotate_f32(angle)
fmt.bprint(value_strings[0][:], rotmat[0, 0])
values[0] = rotmat[0, 0]
@ -607,6 +617,8 @@ program_add_rotation_matrix :: proc(angle: f32) {
values[3] = rotmat[1, 0]
fmt.bprint(value_strings[4][:], rotmat[1, 1])
values[4] = rotmat[1, 1]
fmt.bprint(value_strings[8][:], 1)
values[8] = 1.0
}
program_build_dialog_ui :: proc(ctx: ^ui.Context, dialog_type: ProgramDialogType) -> []ui.Element {
@ -643,6 +655,12 @@ program_build_dialog_ui :: proc(ctx: ^ui.Context, dialog_type: ProgramDialogType
ui_confirm_and_cancel_buttons(button_type, element_margin)
case .CreateRotationMatrix:
ui_labeled_input_float_element("Angle", 4.0, &dialog_data.input_float_values[0], &dialog_data.input_float_value_strings[0])
toggle_group_dimensions := ui.dimensions_pixels(128.0, 32.0)
toggle_group_options := enum_to_raygui_options_string(RotationMode, context.temp_allocator)
toggle_group_config := ui.ElementConfiguration {label = toggle_group_options, margin = element_margin}
toggle_group_data := new(UiElementData_ToggleGroup)
toggle_group_data^ = {value = cast(^i32)&program.rotation_mode}
ui.element(.ToggleGroup, toggle_group_dimensions, toggle_group_config, toggle_group_data)
ui_confirm_and_cancel_buttons(.AddRotationMatrixConfirm, element_margin)
case .SaveProject:
ui_labeled_input_text_element("Path", 4.0, dialog_data.input_text_buffers[0][:])
@ -929,7 +947,7 @@ program_render_ui_and_handle_focus :: proc(ctx: ^ui.Context, focus_element_id: u
matrix_animation_distance := element_matrix_index - animation_matrix_index
alpha := max(0.0, 1.0 - abs(matrix_animation_distance))
color := rl.Color{128, 255, 128, u8(alpha * 64.0)}
rl.DrawRectangleRec(rect2(ui.get_element_outer_area(element)), color)
rl.DrawRectangleRec(area, color)
matrix_area := ui.rect_grow(ui.rect2(area), element.margin / 2.0)
tl, tr, br, bl := ui.rect_get_corners(matrix_area)
@ -1063,24 +1081,13 @@ program_render_ui_and_handle_focus :: proc(ctx: ^ui.Context, focus_element_id: u
if rl.GuiTextBox(area, data.str, i32(program.font_style.size), focus_element_id == element.id) {
focus_element_id = element.id
}
case .Dropdown:
assert(element.data != nil, "Element data cannot be nil when creating a dropdown")
data := cast(^UiElementData_Dropdown)element.data
if focus_element_id == element.id {
render_above = element
} else {
if rl.GuiDropdownBox(area, element.label, data.value, focus_element_id == element.id) {
if focus_element_id == element.id {
focus_element_id = ui.element_id_invalid()
} else {
focus_element_id = element.id
}
}
}
case .Label:
rl.DrawTextEx(font_style.font, element.label, rect_get_tl(area), font_style.size, font_style.spacing, color)
case .Divider:
rl.DrawRectangleRec(rect2(ui.get_element_outer_area(element)), color)
case .ToggleGroup:
data := cast(^UiElementData_ToggleGroup)element.data
rl.GuiToggleGroup(area, element.label, data.value)
case:
rl.DrawRectangleRec(area, rl.MAGENTA)
}
@ -1091,20 +1098,6 @@ program_render_ui_and_handle_focus :: proc(ctx: ^ui.Context, focus_element_id: u
scissor_container = nil
}
if render_above.id != ui.element_id_invalid() {
#partial switch render_above.type {
case .Dropdown:
data := cast(^UiElementData_Dropdown)render_above.data
if rl.GuiDropdownBox(rl.Rectangle(render_above.area), render_above.label, data.value, program.ui_element_focus == render_above.id) {
if program.ui_element_focus == render_above.id {
program.ui_element_focus = ui.element_id_invalid()
} else {
program.ui_element_focus = render_above.id
}
}
}
}
if len(tooltip_text) > 0 {
position := tooltip_position + program.ui_tooltip_offset
size := measure_text(tooltip_text, program.font_style)