Work on adding matrices
This commit is contained in:
parent
3920dfd39a
commit
bf4560fdbd
1 changed files with 79 additions and 17 deletions
96
program.odin
96
program.odin
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import rl "libraries/raylib"
|
import rl "libraries/raylib"
|
||||||
import ui "libraries/snths_ui"
|
import ui "libraries/snths_ui"
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
|
import "core:math/linalg"
|
||||||
|
|
||||||
UiContainerType :: enum {
|
UiContainerType :: enum {
|
||||||
Normal,
|
Normal,
|
||||||
|
|
@ -40,6 +41,8 @@ UiElementData_Button :: struct {
|
||||||
options: cstring,
|
options: cstring,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UI_ALLOWED_FOCUS :: bit_set[ui.ElementType]{.InputFloat}
|
||||||
|
|
||||||
MatrixTypes :: enum {
|
MatrixTypes :: enum {
|
||||||
Identity,
|
Identity,
|
||||||
Translation,
|
Translation,
|
||||||
|
|
@ -54,6 +57,18 @@ MatrixTypes :: enum {
|
||||||
.Rotation = rl.KeyboardKey.R,
|
.Rotation = rl.KeyboardKey.R,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
matrix_add_hotkey_proc_identity :: proc() {program_add_identity_matrix()}
|
||||||
|
matrix_add_hotkey_proc_translation :: proc() {program_show_dialog(&program, .CreateTranslationMatrix)}
|
||||||
|
matrix_add_hotkey_proc_scale :: proc() {program_show_dialog(&program, .CreateScaleMatrix)}
|
||||||
|
matrix_add_hotkey_proc_rotation :: proc() {program_show_dialog(&program, .CreateRotationMatrix)}
|
||||||
|
|
||||||
|
@rodata matrix_add_procs := [MatrixTypes](proc()) {
|
||||||
|
.Identity = matrix_add_hotkey_proc_identity,
|
||||||
|
.Translation = matrix_add_hotkey_proc_translation,
|
||||||
|
.Scale = matrix_add_hotkey_proc_scale,
|
||||||
|
.Rotation = matrix_add_hotkey_proc_rotation,
|
||||||
|
}
|
||||||
|
|
||||||
FontStyle :: struct {
|
FontStyle :: struct {
|
||||||
font: rl.Font,
|
font: rl.Font,
|
||||||
size, spacing: f32
|
size, spacing: f32
|
||||||
|
|
@ -102,18 +117,12 @@ ProgramData_DialogState :: struct {
|
||||||
input_values: [DIALOG_STATE_INPUT_FIELD_COUNT]f32,
|
input_values: [DIALOG_STATE_INPUT_FIELD_COUNT]f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
program_data_dialog_state_data_reset :: proc(data: ^ProgramData_DialogState) {
|
|
||||||
data^ = {}
|
|
||||||
for i in 0..<DIALOG_STATE_INPUT_FIELD_COUNT {
|
|
||||||
data.input_value_strings[i][0] = '0'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Program :: struct {
|
Program :: struct {
|
||||||
ui_context: ui.Context,
|
ui_context: ui.Context,
|
||||||
ui_element_focus: ui.ElementId,
|
ui_element_focus: ui.ElementId,
|
||||||
ui_overlay_context: ui.Context,
|
ui_overlay_context: ui.Context,
|
||||||
ui_overlay_element_focus: ui.ElementId,
|
ui_overlay_element_focus: ui.ElementId,
|
||||||
|
ui_overlay_queue_focus_first: bool,
|
||||||
matrix_float_pool: []f32,
|
matrix_float_pool: []f32,
|
||||||
matrix_value_string_pool: []InputFloatField,
|
matrix_value_string_pool: []InputFloatField,
|
||||||
matrix_create_dropdown_value: MatrixTypes,
|
matrix_create_dropdown_value: MatrixTypes,
|
||||||
|
|
@ -147,7 +156,8 @@ matrix_pool_get_mat3 :: proc() -> ^mat3 {
|
||||||
}
|
}
|
||||||
|
|
||||||
program_show_dialog :: proc(program: ^Program, dialog_type: ProgramDialogType) {
|
program_show_dialog :: proc(program: ^Program, dialog_type: ProgramDialogType) {
|
||||||
program_data_dialog_state_data_reset(&program.dialog_data)
|
program.dialog_data = {}
|
||||||
|
program.ui_overlay_queue_focus_first = true
|
||||||
program.state = .Dialog
|
program.state = .Dialog
|
||||||
program.dialog_type = dialog_type
|
program.dialog_type = dialog_type
|
||||||
}
|
}
|
||||||
|
|
@ -179,23 +189,39 @@ program_init :: proc(allocator := context.allocator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
program_update :: proc() {
|
program_update :: proc() {
|
||||||
if rl.IsKeyPressed(.ENTER) {
|
|
||||||
program_show_dialog(&program, .CreateScaleMatrix)
|
|
||||||
}
|
|
||||||
|
|
||||||
ui_elements, matrix_container := program_build_workspace_ui(&program.ui_context)
|
ui_elements, matrix_container := program_build_workspace_ui(&program.ui_context)
|
||||||
ui_overlay_elements: []ui.Element
|
ui_overlay_elements: []ui.Element
|
||||||
|
|
||||||
|
for hotkey, i in matrix_add_hotkeys {
|
||||||
|
if rl.IsKeyPressed(hotkey) {
|
||||||
|
matrix_add_procs[i]()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch program.state {
|
switch program.state {
|
||||||
case .Normal:
|
case .Normal:
|
||||||
program.mouse_state = program_handle_mouse_workspace(program.mouse_state, matrix_container)
|
program.mouse_state = program_handle_mouse_workspace(program.mouse_state, matrix_container)
|
||||||
if rl.IsKeyPressed(.TAB) {
|
if rl.IsKeyPressed(.TAB) {
|
||||||
program.ui_element_focus = ui.focus_next_element(program.ui_element_focus, ui_elements, {.InputFloat})
|
program.ui_element_focus = ui.focus_next_element(program.ui_element_focus, ui_elements, UI_ALLOWED_FOCUS)
|
||||||
}
|
}
|
||||||
case .Message:
|
case .Message:
|
||||||
|
|
||||||
case .Dialog:
|
case .Dialog:
|
||||||
ui_overlay_elements = program_build_dialog_ui(&program.ui_overlay_context)
|
ui_overlay_elements = program_build_dialog_ui(&program.ui_overlay_context)
|
||||||
|
if rl.IsKeyDown(.ENTER) {
|
||||||
|
vals := program.dialog_data.input_values
|
||||||
|
switch program.dialog_type {
|
||||||
|
case .CreateTranslationMatrix: program_add_translation_matrix(vals[0], vals[1], vals[2])
|
||||||
|
case .CreateScaleMatrix: program_add_scalar_matrix(vals[0], vals[1], vals[2])
|
||||||
|
case .CreateRotationMatrix: program_add_rotation_matrix(vals[0])
|
||||||
|
}
|
||||||
|
program.state = .Normal
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
grid := program.grid
|
grid := program.grid
|
||||||
|
|
@ -206,6 +232,43 @@ program_update :: proc() {
|
||||||
program.ui_overlay_element_focus = program_render_ui_and_handle_focus(&program.ui_overlay_context, program.ui_overlay_element_focus, program.font_style, ui_overlay_elements)
|
program.ui_overlay_element_focus = program_render_ui_and_handle_focus(&program.ui_overlay_context, program.ui_overlay_element_focus, program.font_style, ui_overlay_elements)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
program_add_identity_matrix :: proc() {
|
||||||
|
mat := matrix_pool_get_mat3()
|
||||||
|
mat^ = {
|
||||||
|
1, 0, 0,
|
||||||
|
0, 1, 0,
|
||||||
|
0, 0, 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
program_add_translation_matrix :: proc(x, y, z: f32) {
|
||||||
|
mat := matrix_pool_get_mat3()
|
||||||
|
mat^ = {
|
||||||
|
1, 0, x,
|
||||||
|
0, 1, y,
|
||||||
|
0, 0, z,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
program_add_scalar_matrix :: proc(x, y, z: f32) {
|
||||||
|
mat := matrix_pool_get_mat3()
|
||||||
|
mat^ = {
|
||||||
|
x, 0, 0,
|
||||||
|
0, y, 0,
|
||||||
|
0, 0, z,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
program_add_rotation_matrix :: proc(angle: f32) {
|
||||||
|
mat := matrix_pool_get_mat3()
|
||||||
|
rotmat := linalg.matrix2_rotate_f32(angle)
|
||||||
|
mat^ = {
|
||||||
|
rotmat[0, 0], rotmat[0, 1], 0,
|
||||||
|
rotmat[1, 0], rotmat[1, 1], 0,
|
||||||
|
0, 0, 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
program_build_dialog_ui :: proc(ctx: ^ui.Context) -> []ui.Element {
|
program_build_dialog_ui :: proc(ctx: ^ui.Context) -> []ui.Element {
|
||||||
size := v2{WINDOW_WIDTH, WINDOW_HEIGHT}
|
size := v2{WINDOW_WIDTH, WINDOW_HEIGHT}
|
||||||
container_margin := size * 0.33
|
container_margin := size * 0.33
|
||||||
|
|
@ -213,11 +276,10 @@ program_build_dialog_ui :: proc(ctx: ^ui.Context) -> []ui.Element {
|
||||||
dialog_data := &program.dialog_data
|
dialog_data := &program.dialog_data
|
||||||
ui.start(ctx, V2_ZERO, {WINDOW_WIDTH, WINDOW_HEIGHT})
|
ui.start(ctx, V2_ZERO, {WINDOW_WIDTH, WINDOW_HEIGHT})
|
||||||
ui.container_begin(ui.dimensions_auto(), {margin = container_margin, padding = 8.0})
|
ui.container_begin(ui.dimensions_auto(), {margin = container_margin, padding = 8.0})
|
||||||
ui.element(.Label, {}, {label = "Create a scale matrix", color = ui.col(rl.WHITE), margin = element_margin})
|
ui.element(.Label, {}, {label = program_dialog_messages[program.dialog_type], color = ui.col(rl.WHITE), margin = element_margin})
|
||||||
ui_labeled_input_float_element("X", 4.0, &dialog_data.input_values[0], &dialog_data.input_value_strings[0])
|
ui_labeled_input_float_element("X", 4.0, &dialog_data.input_values[0], &dialog_data.input_value_strings[0])
|
||||||
ui_labeled_input_float_element("Y", 4.0, &dialog_data.input_values[0], &dialog_data.input_value_strings[0])
|
ui_labeled_input_float_element("Y", 4.0, &dialog_data.input_values[1], &dialog_data.input_value_strings[1])
|
||||||
ui_labeled_input_float_element("Z", 4.0, &dialog_data.input_values[0], &dialog_data.input_value_strings[0])
|
ui_labeled_input_float_element("Z", 4.0, &dialog_data.input_values[2], &dialog_data.input_value_strings[2])
|
||||||
|
|
||||||
ui.element(.Button, ui.dimensions_pixels({96.0, 32.0}), {label = "Add", margin = element_margin})
|
ui.element(.Button, ui.dimensions_pixels({96.0, 32.0}), {label = "Add", margin = element_margin})
|
||||||
ui.same_line()
|
ui.same_line()
|
||||||
ui.element(.Button, ui.dimensions_pixels({96.0, 32.0}), {label = "Cancel", margin = element_margin})
|
ui.element(.Button, ui.dimensions_pixels({96.0, 32.0}), {label = "Cancel", margin = element_margin})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue