Float fields working
This commit is contained in:
@@ -18,4 +18,12 @@ for_expansion :: (static_array: *Static_Array, body: Code, flags: For_Flags) #ex
|
||||
}
|
||||
#insert body;
|
||||
}
|
||||
}
|
||||
|
||||
array_contains :: (static_array: Static_Array, value: static_array.Data_Type) -> bool {
|
||||
for static_array {
|
||||
if it == value return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -186,6 +186,8 @@ editor_ui :: () {
|
||||
euler_rotation *= DEGREES_TO_RADIANS;
|
||||
entity.transform.orientation = euler_to_quaternion(euler_rotation);
|
||||
ui_vector_field("Scale", *entity.transform.scale);
|
||||
|
||||
update_matrix(*entity.transform);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,13 +41,12 @@ calc_tight_light_projection :: (camera: Camera, light_direction: Vector3) -> Mat
|
||||
|
||||
light_projection := orthographic_lh_projection_matrix(final_aabb.min.x, final_aabb.max.x, final_aabb.min.y, final_aabb.max.y, final_aabb.min.z, final_aabb.max.z);
|
||||
|
||||
|
||||
return light_projection * light_view;
|
||||
}
|
||||
|
||||
update_light_buffer :: () {
|
||||
scene := engine.current_scene;
|
||||
camera := scene.camera;
|
||||
camera := ifx engine.mode == .EDITING then engine.editor.camera else scene.camera;
|
||||
|
||||
light_data : Directional_Light_Buffer_Data;
|
||||
light_data.direction = scene.directional_light.direction;
|
||||
|
||||
@@ -1409,6 +1409,8 @@ make_point :: (x: float, y: float, s: float, t: float, color: Vector4) -> Point
|
||||
}
|
||||
|
||||
get_text_size :: (using renderer: *Renderer, text: string, font_handle: Font_Handle) -> Vector2 {
|
||||
if text.count == 0 return .{0,0};
|
||||
|
||||
size : Vector2;
|
||||
|
||||
font := *engine.renderer.fonts[font_handle - 1];
|
||||
|
||||
47
ui/ui.jai
47
ui/ui.jai
@@ -264,8 +264,8 @@ ui_init :: () {
|
||||
init(*ui_state.boxes, 1024);
|
||||
|
||||
ui_state.sampler = create_sampler(engine.renderer);
|
||||
ui_state.fonts.regular = create_font(engine.renderer, "../assets/fonts/roboto/Roboto-Regular.ttf", 12);
|
||||
ui_state.fonts.button = create_font(engine.renderer, "../assets/fonts/roboto/Roboto-Regular.ttf", 12);
|
||||
ui_state.fonts.regular = create_font(engine.renderer, "../assets/fonts/roboto/Roboto-Regular.ttf", 14);
|
||||
ui_state.fonts.button = create_font(engine.renderer, "../assets/fonts/roboto/Roboto-Regular.ttf", 14);
|
||||
|
||||
// ui_rect
|
||||
{
|
||||
@@ -882,30 +882,31 @@ ui_render_text_recursively :: (box: *UI_Box) {
|
||||
|
||||
if box.flags & .DRAW_TEXT {
|
||||
font_handle := ui_state.fonts.regular;
|
||||
if box.text.count > 0 {
|
||||
text_size := get_text_size(engine.renderer, box.text, font_handle);
|
||||
|
||||
text_size := get_text_size(engine.renderer, box.text, font_handle);
|
||||
|
||||
x := box.rect.x + box.padding_left;
|
||||
x := box.rect.x + box.padding_left;
|
||||
|
||||
y := cast(float)engine.renderer.render_target_height - box.rect.y - box.rect.h + box.padding_bottom;
|
||||
if box.alignment_flags & .CENTER_HORIZONTALLY {
|
||||
x += box.rect.w * 0.5 - text_size.x * 0.5;
|
||||
y := cast(float)engine.renderer.render_target_height - box.rect.y - box.rect.h + box.padding_bottom;
|
||||
if box.alignment_flags & .CENTER_HORIZONTALLY {
|
||||
x += box.rect.w * 0.5 - text_size.x * 0.5;
|
||||
}
|
||||
|
||||
if box.alignment_flags & .CENTER_VERTICALLY {
|
||||
y += box.rect.h * 0.5 - text_size.y * 0.5;
|
||||
}
|
||||
|
||||
if box.alignment_flags & .RIGHT_BOTTOM {
|
||||
x += box.rect.w - text_size.x;
|
||||
}
|
||||
|
||||
render_data := bake_text(engine.renderer, x, y, box.text, font_handle, box.style.text_color);
|
||||
font := *engine.renderer.fonts[font_handle - 1];
|
||||
|
||||
push_cmd_set_texture(engine.renderer, 0, font.texture);
|
||||
push_cmd_set_vertex_buffer(engine.renderer, render_data.vb);
|
||||
push_cmd_draw(engine.renderer, render_data.vert_count);
|
||||
}
|
||||
|
||||
if box.alignment_flags & .CENTER_VERTICALLY {
|
||||
y += box.rect.h * 0.5 - text_size.y * 0.5;
|
||||
}
|
||||
|
||||
if box.alignment_flags & .RIGHT_BOTTOM {
|
||||
x += box.rect.w - text_size.x;
|
||||
}
|
||||
|
||||
render_data := bake_text(engine.renderer, x, y, box.text, font_handle, box.style.text_color);
|
||||
font := *engine.renderer.fonts[font_handle - 1];
|
||||
|
||||
push_cmd_set_texture(engine.renderer, 0, font.texture);
|
||||
push_cmd_set_vertex_buffer(engine.renderer, render_data.vb);
|
||||
push_cmd_draw(engine.renderer, render_data.vert_count);
|
||||
}
|
||||
|
||||
child := box.first_child;
|
||||
|
||||
@@ -195,18 +195,69 @@ ui_float_field :: (value: *float, identifier: s64 = 0, loc := #caller_location)
|
||||
|
||||
ui_push_parent(outer, alignment=.LEFT, axis=.HORIZONTAL);
|
||||
{
|
||||
//text.count > 0 {
|
||||
ui_set_next_text(tprint("%", <<value));
|
||||
ui_set_next_text_color(.{1,1,1,1});
|
||||
ui_set_next_text_alignment(.CENTER_VERTICALLY);
|
||||
ui_set_next_text_color(.{1,1,1,1});
|
||||
ui_set_next_size_x(.TEXT_DIM);
|
||||
ui_set_next_size_y(.TEXT_DIM);
|
||||
text_widget := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
|
||||
//}
|
||||
ui_set_next_text_color(.{1,1,1,1});
|
||||
ui_set_next_text_alignment(.CENTER_VERTICALLY);
|
||||
ui_set_next_text_color(.{1,1,1,1});
|
||||
ui_set_next_size_x(.TEXT_DIM);
|
||||
ui_set_next_size_y(.TEXT_DIM);
|
||||
text_widget := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
|
||||
|
||||
if outer.interaction.editing {
|
||||
text_widget.text = alloc_string(text_widget._number_text.count,, allocator=temp);
|
||||
memcpy(text_widget.text.data, text_widget._number_text.data.data, text_widget._number_text.count);
|
||||
|
||||
// Cursor
|
||||
ui_set_next_background_color(.{1.0,1.0,1.0,1.0});
|
||||
ui_set_next_size_x(.PIXELS, 2);
|
||||
ui_set_next_size_y(.PCT, 1);
|
||||
cursor := ui_box_make(.DRAW_BACKGROUND, get_hash(loc, identifier));
|
||||
|
||||
if key_down(.BACKSPACE) && text_widget._number_text.count > 0 {
|
||||
text_widget._number_text.count -= 1;
|
||||
}
|
||||
|
||||
if key_down(.RETURN) {
|
||||
// FORMAT IT BACK!
|
||||
temp_str : string;
|
||||
temp_str.data = text_widget._number_text.data.data;
|
||||
temp_str.count = text_widget._number_text.count;
|
||||
<<value = parse_float(*temp_str);
|
||||
outer.interaction.editing = false;
|
||||
}
|
||||
|
||||
if engine.input.has_char {
|
||||
text_str := alloc_string(1,, allocator=temp);
|
||||
text_str[0] = xx engine.input.current_char;
|
||||
|
||||
if text_str == {
|
||||
case "0";#through;
|
||||
case "1";#through;
|
||||
case "2";#through;
|
||||
case "3";#through;
|
||||
case "4";#through;
|
||||
case "5";#through;
|
||||
case "6";#through;
|
||||
case "7";#through;
|
||||
case "8";#through;
|
||||
case "9";#through;
|
||||
case "."; {
|
||||
if !(text_str == "." && (array_contains(text_widget._number_text, #char ".") || text_widget._number_text.count == 0)) {
|
||||
text_widget._number_text.data[text_widget._number_text.count] = text_str[0];
|
||||
text_widget._number_text.count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Ignore non-numeric characters
|
||||
} else {
|
||||
text_widget.text = copy_temporary_string(tprint("%", formatFloat(<<value, trailing_width=2, zero_removal=.NO)));
|
||||
}
|
||||
|
||||
if outer.interaction.clicked {
|
||||
outer.interaction.editing = true;
|
||||
formatted_text := copy_temporary_string(tprint("%", formatFloat(<<value, trailing_width = 2, zero_removal=.NO)));
|
||||
memcpy(text_widget._number_text.data.data, formatted_text.data, formatted_text.count);
|
||||
text_widget._number_text.count = formatted_text.count;
|
||||
}
|
||||
|
||||
//if outer.interaction.editing {
|
||||
|
||||
@@ -3,6 +3,8 @@ Window :: struct {
|
||||
height: u32;
|
||||
}
|
||||
|
||||
WINDOW_SIZE :: 42000;
|
||||
|
||||
SDL_Window_Type :: struct {
|
||||
using #as window : Window;
|
||||
|
||||
@@ -31,6 +33,14 @@ create_window :: (title: string, width: u32, height: u32, fullscreen: bool) -> *
|
||||
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
}
|
||||
|
||||
if width == WINDOW_SIZE {
|
||||
screen_width = display_mode.w;
|
||||
}
|
||||
|
||||
if height == WINDOW_SIZE {
|
||||
screen_height = display_mode.h;
|
||||
}
|
||||
|
||||
sdl_window := SDL_CreateWindow(to_c_string(title,, temp), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width, screen_height, flags);
|
||||
|
||||
if sdl_window == null {
|
||||
|
||||
Reference in New Issue
Block a user