Added snap to grid + local/world space UI

This commit is contained in:
2024-11-10 23:34:54 +01:00
parent c52163f3b4
commit e8326e4340
3 changed files with 45 additions and 5 deletions

View File

@@ -34,6 +34,9 @@ Transform_Gizmo :: struct {
actual_entity_scale: Vector3; // The actual position of the selected entity. Used for snapping
last_circle_dir: Vector3;
// Settings
snap_to_grid: bool;
clicked: bool;
transform: Transform;
@@ -184,7 +187,12 @@ update_transform_gizmo :: (ray: Ray, mouse_position: Vector2) -> bool {
entity_position := engine.editor.transform_gizmo.actual_entity_position + position_change;
if selected_entity.flags & Entity_Flags.SNAP_TO_GRID {
if engine.editor.transform_gizmo.snap_to_grid {
snap_interval := Vector3.{1,1,1};
entity_position.x -= fmod_cycling(entity_position.x - selected_entity.snap_offset.x, snap_interval.x);// + selected_entity.snap_offset.x;
entity_position.y -= fmod_cycling(entity_position.y - selected_entity.snap_offset.y, snap_interval.y);// + selected_entity.snap_offset.y;
entity_position.z -= fmod_cycling(entity_position.z - selected_entity.snap_offset.z, snap_interval.z);// + selected_entity.snap_offset.z;
} else if selected_entity.flags & Entity_Flags.SNAP_TO_GRID {
entity_position.x -= fmod_cycling(entity_position.x - selected_entity.snap_offset.x, selected_entity.snap_intervals.x);// + selected_entity.snap_offset.x;
entity_position.y -= fmod_cycling(entity_position.y - selected_entity.snap_offset.y, selected_entity.snap_intervals.y);// + selected_entity.snap_offset.y;
entity_position.z -= fmod_cycling(entity_position.z - selected_entity.snap_offset.z, selected_entity.snap_intervals.z);// + selected_entity.snap_offset.z;

View File

@@ -138,10 +138,42 @@ editor_ui :: () {
viewport_layer := ui_box(.NONE);
ui_push_parent(viewport_layer, alignment=.LEFT, axis=.VERTICAL);
{
ui_set_next_size_x(.PCT, 1.0);
ui_tab_title_bar("SCENE");
ui_set_next_size_x(.PCT, 1.0);
ui_set_next_size_y(.PCT, 0.75);
ui_set_next_size_y(.PCT, 0.1);
ui_toolbar();
ui_push_parent(ui_state.last_box, alignment=.LEFT, axis=.HORIZONTAL);
{
if engine.editor.transform_gizmo.snap_to_grid {
if ui_toolbar_button("Snap to grid enabled", .{0.0, 0.4, 0.0, 1.0}) {
engine.editor.transform_gizmo.snap_to_grid = false;
}
} else {
if ui_toolbar_button("Snap to grid disabled", .{0.4, 0.0, 0.0, 1.0}) {
engine.editor.transform_gizmo.snap_to_grid = true;
}
}
if engine.editor.transform_gizmo.space == .LOCAL {
if ui_toolbar_button("LOCAL", .{0.0, 0.3, 0.0, 1.0}) {
engine.editor.transform_gizmo.space = .WORLD;
}
} else {
if ui_toolbar_button("WORLD", .{0.0, 0.0, 0.3, 1.0}) {
engine.editor.transform_gizmo.space = .LOCAL;
}
}
//ui_space(15, 10)
ui_space(20, 0);
}
ui_pop_parent();
ui_set_next_size_x(.PCT, 1.0);
ui_set_next_size_y(.PCT, 0.65);
state := ui_interactable_texture(get_texture_from_pass("UI Blend Pass"));
engine.input.viewport_mouse_position = state.local_mouse_coordinates;

View File

@@ -61,11 +61,11 @@ ui_button_no_border :: (text: string, identifier: s64 = 0, loc := #caller_locati
return box.interaction.clicked, box.interaction;
}
ui_toolbar_button :: (text: string, identifier: s64 = 0, loc := #caller_location) -> clicked: bool, Interaction_State {
ui_toolbar_button :: (text: string, background_color: Color = .{0.1,0.1,0.1,1}, identifier: s64 = 0, loc := #caller_location) -> clicked: bool, Interaction_State {
ui_set_next_text(text);
ui_set_next_border_width(1);
ui_set_next_border_color(.{0.5,0.5,0.5,1});
ui_set_next_background_color(.{0.1,0.1,0.1,1});
ui_set_next_background_color(background_color);
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
@@ -74,7 +74,7 @@ ui_toolbar_button :: (text: string, identifier: s64 = 0, loc := #caller_location
ui_set_next_padding_top(5);
ui_set_next_padding_bottom(5);
//ui_set_next_text_alignment(.CENTER_HORIZONTALLY | .CENTER_VERTICALLY);
box := ui_box_make(.CLICKABLE | .DRAW_BORDER | .DRAW_TEXT | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
box := ui_box_make(.CLICKABLE | .DRAW_BORDER | .DRAW_BACKGROUND | .DRAW_TEXT | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
return box.interaction.clicked, box.interaction;
}