Added snap to grid + local/world space UI
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user