Update on change
This commit is contained in:
parent
7022e4e5ca
commit
4de20264fa
2 changed files with 68 additions and 26 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import rl "libraries/raylib"
|
import rl "libraries/raylib"
|
||||||
|
import "core:fmt"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Maybe it is possible to have everything 3d be mathed the same way
|
Maybe it is possible to have everything 3d be mathed the same way
|
||||||
|
|
@ -58,6 +59,16 @@ _animation_rectangle_update_last :: proc(animation: ^AnimationInterface, master_
|
||||||
br = (master_matrix * v3{**data.origin.br, 1.0}).xy,
|
br = (master_matrix * v3{**data.origin.br, 1.0}).xy,
|
||||||
bl = (master_matrix * v3{**data.origin.bl, 1.0}).xy,
|
bl = (master_matrix * v3{**data.origin.bl, 1.0}).xy,
|
||||||
}
|
}
|
||||||
|
fmt.println(data.last)
|
||||||
|
fmt.println(data.origin)
|
||||||
|
}
|
||||||
|
|
||||||
|
_animation_rectangle_update :: proc(animation: ^AnimationInterface, current_matrix: mat3, progress: f32) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_animation_rectangle_update_goto_next :: proc(animation: ^AnimationInterface, next_matrix: mat3) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
animation_create_rectangle :: proc(rectangle: ^AnimationData_Rectangle) -> AnimationInterface {
|
animation_create_rectangle :: proc(rectangle: ^AnimationData_Rectangle) -> AnimationInterface {
|
||||||
|
|
|
||||||
83
program.odin
83
program.odin
|
|
@ -34,6 +34,7 @@ UiElementData_Slider :: struct {
|
||||||
UiElementData_FloatInput :: struct {
|
UiElementData_FloatInput :: struct {
|
||||||
value: ^f32,
|
value: ^f32,
|
||||||
value_string: cstring,
|
value_string: cstring,
|
||||||
|
tag: bit_set[enum{UpdateMatrix}],
|
||||||
}
|
}
|
||||||
|
|
||||||
UiElementData_Dropdown :: struct {
|
UiElementData_Dropdown :: struct {
|
||||||
|
|
@ -178,14 +179,15 @@ matrix_pool_max :: proc() -> int {
|
||||||
return len(program.matrix_float_pool) / 9
|
return len(program.matrix_float_pool) / 9
|
||||||
}
|
}
|
||||||
|
|
||||||
matrix_pool_get_mat3 :: proc() -> []InputFloatField {
|
matrix_pool_get_mat3 :: proc() -> (value_strings: []InputFloatField, values: []f32) {
|
||||||
assert(program.matrix_count + 1 < matrix_pool_max(), "Max matrix count exceeded")
|
assert(program.matrix_count + 1 < matrix_pool_max(), "Max matrix count exceeded")
|
||||||
value_strings := program.matrix_value_string_pool[program.matrix_count * 9 : program.matrix_count * 9 + 9]
|
value_strings = program.matrix_value_string_pool[program.matrix_count * 9 : program.matrix_count * 9 + 9]
|
||||||
|
values = program.matrix_float_pool[program.matrix_count * 9 : program.matrix_count * 9 + 9]
|
||||||
for &str in value_strings {
|
for &str in value_strings {
|
||||||
str[0] = '0'
|
str[0] = '0'
|
||||||
}
|
}
|
||||||
program.matrix_count += 1
|
program.matrix_count += 1
|
||||||
return value_strings
|
return value_strings, values
|
||||||
}
|
}
|
||||||
|
|
||||||
program_show_dialog :: proc(program: ^Program, dialog_type: ProgramDialogType) {
|
program_show_dialog :: proc(program: ^Program, dialog_type: ProgramDialogType) {
|
||||||
|
|
@ -233,9 +235,12 @@ program_init :: proc(allocator := context.allocator) {
|
||||||
program_get_master_matrix :: proc() -> mat3 {
|
program_get_master_matrix :: proc() -> mat3 {
|
||||||
matrices := (cast([^]mat3)raw_data(program.matrix_float_pool))[:program.matrix_count]
|
matrices := (cast([^]mat3)raw_data(program.matrix_float_pool))[:program.matrix_count]
|
||||||
master_matrix := linalg.identity_matrix(mat3)
|
master_matrix := linalg.identity_matrix(mat3)
|
||||||
|
fmt.println("master matrix: ", master_matrix)
|
||||||
#reverse for mat in matrices {
|
#reverse for mat in matrices {
|
||||||
|
fmt.println("master matrix: ", master_matrix, mat)
|
||||||
master_matrix *= mat
|
master_matrix *= mat
|
||||||
}
|
}
|
||||||
|
fmt.println("master matrix: ", master_matrix)
|
||||||
return master_matrix
|
return master_matrix
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -269,10 +274,18 @@ program_update :: proc() {
|
||||||
for hotkey, index in matrix_add_hotkeys {
|
for hotkey, index in matrix_add_hotkeys {
|
||||||
if rl.IsKeyPressed(hotkey) {
|
if rl.IsKeyPressed(hotkey) {
|
||||||
switch index {
|
switch index {
|
||||||
case .Identity: program_add_identity_matrix()
|
case .Identity:
|
||||||
case .Translation: program_show_dialog(&program, .CreateTranslationMatrix)
|
program_add_identity_matrix()
|
||||||
case .Scale: program_show_dialog(&program, .CreateScaleMatrix)
|
program.ui_overlay_queue_focus_first = true
|
||||||
case .Rotation: program_show_dialog(&program, .CreateRotationMatrix)
|
case .Translation:
|
||||||
|
program_show_dialog(&program, .CreateTranslationMatrix)
|
||||||
|
program.ui_overlay_queue_focus_first = true
|
||||||
|
case .Scale:
|
||||||
|
program_show_dialog(&program, .CreateScaleMatrix)
|
||||||
|
program.ui_overlay_queue_focus_first = true
|
||||||
|
case .Rotation:
|
||||||
|
program_show_dialog(&program, .CreateRotationMatrix)
|
||||||
|
program.ui_overlay_queue_focus_first = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -289,22 +302,11 @@ program_update :: proc() {
|
||||||
case .CreateScaleMatrix: program_add_scalar_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])
|
case .CreateRotationMatrix: program_add_rotation_matrix(vals[0])
|
||||||
}
|
}
|
||||||
|
program.animation.update_last(&program.animation, program_get_master_matrix())
|
||||||
program.state = .Normal
|
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch program.animation_state {
|
|
||||||
case .Ready:
|
|
||||||
case .Playing:
|
|
||||||
case .Paused:
|
|
||||||
case .Finished:
|
|
||||||
}
|
|
||||||
|
|
||||||
grid := program.grid
|
grid := program.grid
|
||||||
grid_inner_position := rect_get_tl(grid.inner_area)
|
grid_inner_position := rect_get_tl(grid.inner_area)
|
||||||
draw_grid(grid.area, {32.0, 32.0}, rl.GRAY)
|
draw_grid(grid.area, {32.0, 32.0}, rl.GRAY)
|
||||||
|
|
@ -327,36 +329,62 @@ program_update :: proc() {
|
||||||
program.font_style,
|
program.font_style,
|
||||||
ui_overlay_elements)
|
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() {
|
program_add_identity_matrix :: proc() {
|
||||||
value_strings := matrix_pool_get_mat3()
|
value_strings, values := matrix_pool_get_mat3()
|
||||||
value_strings[0][0] = '1'
|
value_strings[0][0] = '1'
|
||||||
|
values[0] = 1.0
|
||||||
value_strings[4][0] = '1'
|
value_strings[4][0] = '1'
|
||||||
|
values[4] = 1.0
|
||||||
value_strings[8][0] = '1'
|
value_strings[8][0] = '1'
|
||||||
|
values[8] = 1.0
|
||||||
}
|
}
|
||||||
|
|
||||||
program_add_translation_matrix :: proc(x, y, z: f32) {
|
program_add_translation_matrix :: proc(x, y, z: f32) {
|
||||||
value_strings := matrix_pool_get_mat3()
|
value_strings, values := matrix_pool_get_mat3()
|
||||||
|
value_strings[0][0] = '1'
|
||||||
|
values[0] = 1.0
|
||||||
|
|
||||||
fmt.bprint(value_strings[2][:], x)
|
fmt.bprint(value_strings[2][:], x)
|
||||||
|
values[2] = x
|
||||||
|
|
||||||
fmt.bprint(value_strings[5][:], y)
|
fmt.bprint(value_strings[5][:], y)
|
||||||
|
value_strings[4][0] = '1'
|
||||||
|
|
||||||
|
values[4] = 1.0
|
||||||
|
values[5] = y
|
||||||
|
|
||||||
fmt.bprint(value_strings[8][:], z)
|
fmt.bprint(value_strings[8][:], z)
|
||||||
|
values[8] = z
|
||||||
}
|
}
|
||||||
|
|
||||||
program_add_scalar_matrix :: proc(x, y, z: f32) {
|
program_add_scalar_matrix :: proc(x, y, z: f32) {
|
||||||
value_strings := matrix_pool_get_mat3()
|
value_strings, values := matrix_pool_get_mat3()
|
||||||
fmt.bprint(value_strings[0][:], x)
|
fmt.bprint(value_strings[0][:], x)
|
||||||
|
values[0] = x
|
||||||
fmt.bprint(value_strings[4][:], y)
|
fmt.bprint(value_strings[4][:], y)
|
||||||
|
values[4] = y
|
||||||
fmt.bprint(value_strings[8][:], z)
|
fmt.bprint(value_strings[8][:], z)
|
||||||
|
values[8] = z
|
||||||
}
|
}
|
||||||
|
|
||||||
program_add_rotation_matrix :: proc(angle: f32) {
|
program_add_rotation_matrix :: proc(angle: f32) {
|
||||||
value_strings := matrix_pool_get_mat3()
|
value_strings, values := matrix_pool_get_mat3()
|
||||||
rotmat := linalg.matrix2_rotate_f32(angle)
|
rotmat := linalg.matrix2_rotate_f32(angle)
|
||||||
fmt.bprint(value_strings[0][:], rotmat[0, 0])
|
fmt.bprint(value_strings[0][:], rotmat[0, 0])
|
||||||
|
values[0] = rotmat[0, 0]
|
||||||
fmt.bprint(value_strings[1][:], rotmat[0, 1])
|
fmt.bprint(value_strings[1][:], rotmat[0, 1])
|
||||||
|
values[1] = rotmat[0, 1]
|
||||||
fmt.bprint(value_strings[3][:], rotmat[1, 0])
|
fmt.bprint(value_strings[3][:], rotmat[1, 0])
|
||||||
|
values[3] = rotmat[1, 0]
|
||||||
fmt.bprint(value_strings[4][:], rotmat[1, 1])
|
fmt.bprint(value_strings[4][:], rotmat[1, 1])
|
||||||
|
values[4] = rotmat[1, 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_labeled_input_float_element :: proc(label: cstring, margin: f32, value: ^f32, value_string: ^InputFloatField, allocator := context.temp_allocator) -> ^ui.Element {
|
ui_labeled_input_float_element :: proc(label: cstring, margin: f32, value: ^f32, value_string: ^InputFloatField, allocator := context.temp_allocator) -> ^ui.Element {
|
||||||
|
|
@ -594,9 +622,8 @@ program_render_ui_and_handle_focus :: proc(ctx: ^ui.Context, focus_element_id: u
|
||||||
case .ResetTransformation:
|
case .ResetTransformation:
|
||||||
// TODO (synthas): Reset to initial transformation values
|
// TODO (synthas): Reset to initial transformation values
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.type in UiButtonRecalculateFinishGroup {
|
if data.type in UiButtonRecalculateFinishGroup {
|
||||||
// TODO (synthas): Recalculate finish
|
program.animation.update_last(&program.animation, program_get_master_matrix())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .Slider:
|
case .Slider:
|
||||||
|
|
@ -604,9 +631,13 @@ program_render_ui_and_handle_focus :: proc(ctx: ^ui.Context, focus_element_id: u
|
||||||
rl.GuiSlider(area, element.label, "", data.value, data.min, data.max)
|
rl.GuiSlider(area, element.label, "", data.value, data.min, data.max)
|
||||||
case .InputFloat:
|
case .InputFloat:
|
||||||
data := cast(^UiElementData_FloatInput)element.data
|
data := cast(^UiElementData_FloatInput)element.data
|
||||||
|
value_previous := data.value^
|
||||||
if rl.GuiValueBoxFloat(area, element.label, data.value_string, data.value, focus_element_id == element.id) == 1 {
|
if rl.GuiValueBoxFloat(area, element.label, data.value_string, data.value, focus_element_id == element.id) == 1 {
|
||||||
focus_element_id = element.id
|
focus_element_id = element.id
|
||||||
}
|
}
|
||||||
|
if value_previous != data.value^ && .UpdateMatrix in data.tag {
|
||||||
|
program.animation.update_last(&program.animation, program_get_master_matrix())
|
||||||
|
}
|
||||||
case .Dropdown:
|
case .Dropdown:
|
||||||
assert(element.data != nil, "Element data cannot be nil when creating a dropdown")
|
assert(element.data != nil, "Element data cannot be nil when creating a dropdown")
|
||||||
data := cast(^UiElementData_Dropdown)element.data
|
data := cast(^UiElementData_Dropdown)element.data
|
||||||
|
|
@ -665,7 +696,7 @@ ui_mat3 :: proc(mat: []f32, value_strings: []InputFloatField, dimensions: ui.Dim
|
||||||
#unroll for j in 0..<3 {
|
#unroll for j in 0..<3 {
|
||||||
data := new(UiElementData_FloatInput, allocator)
|
data := new(UiElementData_FloatInput, allocator)
|
||||||
index := i * 3 + j
|
index := i * 3 + j
|
||||||
data^ = {value = &mat[index], value_string = cstring(&value_strings[index][0])}
|
data^ = {value = &mat[index], value_string = cstring(&value_strings[index][0]), tag = {.UpdateMatrix}}
|
||||||
ui.element(.InputFloat, matrix_input_dimensions, matrix_input_config, data)
|
ui.element(.InputFloat, matrix_input_dimensions, matrix_input_config, data)
|
||||||
ui.same_line()
|
ui.same_line()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue