Skip to content

Commit d871ce9

Browse files
committed
remove active holding focus stuff from ui code
1 parent 0e939de commit d871ce9

File tree

2 files changed

+69
-68
lines changed

2 files changed

+69
-68
lines changed

Game/source/editor.jai

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,23 +1235,27 @@ do_level_bounds_handles :: () {
12351235
};
12361236

12371237
hovered := is_point_within_frect(Editor.mouse_tile_position, rect);
1238-
focus := update_active_hot_state(hovered, .L | .R);
1238+
update_active_hot_state(hovered, .L | .R);
12391239

1240-
if focus == {
1241-
case .L;
1242-
if mouse.left == .RELEASED {
1243-
Editor.level.bounds.position = snap_to_nearest_unit(Editor.level.bounds.position, 0.5);
1244-
} else {
1240+
if node.flags & .ACTIVE {
1241+
if mouse.left == {
1242+
case .DOWN;
12451243
Editor.level.bounds.position += to_Vec2f(mouse.velocity) / Editor.tile_unit;
1244+
1245+
case .RELEASED;
1246+
Editor.level.bounds.position = snap_to_nearest_unit(Editor.level.bounds.position, 0.5);
12461247
}
12471248

1248-
case .R; // same as above, except that we also adjust size to keep bottom-right in its current position
1249-
if mouse.right == .RELEASED {
1250-
Editor.level.bounds.position = snap_to_nearest_unit(Editor.level.bounds.position, 0.5);
1251-
Editor.level.bounds.size = snap_to_nearest_unit(Editor.level.bounds.size, 0.5);
1252-
} else {
1253-
Editor.level.bounds.position += to_Vec2f(mouse.velocity) / Editor.tile_unit;
1254-
Editor.level.bounds.size -= to_Vec2f(mouse.velocity) / Editor.tile_unit;
1249+
if !mouse.left {
1250+
if mouse.right == {
1251+
case .DOWN;
1252+
Editor.level.bounds.position += to_Vec2f(mouse.velocity) / Editor.tile_unit;
1253+
Editor.level.bounds.size -= to_Vec2f(mouse.velocity) / Editor.tile_unit;
1254+
1255+
case .RELEASED;
1256+
Editor.level.bounds.position = snap_to_nearest_unit(Editor.level.bounds.position, 0.5);
1257+
Editor.level.bounds.size = snap_to_nearest_unit(Editor.level.bounds.size, 0.5);
1258+
}
12551259
}
12561260
}
12571261

@@ -1287,14 +1291,15 @@ do_level_bounds_handles :: () {
12871291
};
12881292

12891293
hovered := is_point_within_frect(Editor.mouse_tile_position, rect);
1290-
focus := update_active_hot_state(hovered, .L | .R);
1294+
update_active_hot_state(hovered, .L | .R);
12911295

1292-
if focus == {
1293-
case .L;
1294-
if mouse.left == .RELEASED {
1295-
Editor.level.bounds.size = snap_to_nearest_unit(Editor.level.bounds.size, 0.5);
1296-
} else {
1296+
if node.flags & .ACTIVE {
1297+
if mouse.left == {
1298+
case .DOWN;
12971299
Editor.level.bounds.size += to_Vec2f(mouse.velocity) / Editor.tile_unit;
1300+
1301+
case .RELEASED;
1302+
Editor.level.bounds.size = snap_to_nearest_unit(Editor.level.bounds.size, 0.5);
12981303
}
12991304
}
13001305

Game/source/editor_ui.jai

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
but then in that case we would already be holding some other active element anyhow
2626
this would simplify some logic and should make multi-selection logic easier to follow
2727
28+
use a simple animator and enumerate the handle clips so that they are easier to reference
2829
2930
3031
*/
@@ -342,7 +343,7 @@ UI_State :: struct {
342343
current_node: *UI_Node;
343344

344345
hot, last_hot, active: *UI_Node;
345-
active_holding_focus: Handle_Focus_Type;
346+
// active_holding_focus: Handle_Focus_Type;
346347
current_walk_index: int;
347348

348349
// TODO: Some state for disambiguating between click on overlapping ui elements
@@ -581,7 +582,8 @@ update_node :: (node: *UI_Node, offset: Vec2f) {
581582
ui_try_set_hot :: (node: *UI_Node) {
582583
node.flags |= .HOVERED;
583584

584-
if !ui_state.active_holding_focus
585+
// if !ui_state.active_holding_focus
586+
if true
585587
&& (ui_state.hot == null || node == ui_state.last_hot || node.walk_index > ui_state.hot.walk_index) {
586588
ui_state.hot = node;
587589
node.flags |= .HOT;
@@ -593,15 +595,15 @@ ui_set_active :: (node: *UI_Node, hold_focus: Handle_Focus_Type) {
593595
ui_state.active = node;
594596
node.flags |= .ACTIVE;
595597

596-
if hold_focus == {
597-
case .L; ui_state.active_holding_focus = .L;
598-
case .R; ui_state.active_holding_focus = .R;
599-
}
598+
// if hold_focus == {
599+
// case .L; ui_state.active_holding_focus = .L;
600+
// case .R; ui_state.active_holding_focus = .R;
601+
// }
600602
}
601603

602604
ui_clear_active :: () {
603605
ui_state.active = null;
604-
ui_state.active_holding_focus = .NONE;
606+
// ui_state.active_holding_focus = .NONE;
605607
}
606608

607609
ui_push :: (id: UI_Node.ID) -> *UI_Node {
@@ -631,7 +633,7 @@ notify_parent_of_active_hot_state :: (node: *UI_Node) {
631633
}
632634

633635
// NOTE: performed on the ui_state.current_node
634-
update_active_hot_state :: (hovered: bool, want_focus_held: Handle_Focus_Type, treat_as_if_active := false) -> Handle_Focus_Type {
636+
update_active_hot_state :: (hovered: bool, want_focus_held: Handle_Focus_Type) {
635637
mouse := get_mouse();
636638
node := ui_state.current_node;
637639

@@ -642,14 +644,15 @@ update_active_hot_state :: (hovered: bool, want_focus_held: Handle_Focus_Type, t
642644
node.flags |= .HOT;
643645
ui_state.flags |= .HOT_VISITED_THIS_FRAME;
644646

645-
if !ui_state.active_holding_focus {
647+
// if !ui_state.active_holding_focus {
648+
// if !(ui_state.flags & .ACTIVE_VISITED_THIS_FRAME) {
646649
if mouse.left == .PRESSED {
647650
ui_set_active(node, want_focus_held & .L);
648651
}
649652
if mouse.right == .PRESSED {
650653
ui_set_active(node, want_focus_held & .R);
651654
}
652-
}
655+
// }
653656
} else {
654657
ui_state.hot == null;
655658
}
@@ -661,31 +664,18 @@ update_active_hot_state :: (hovered: bool, want_focus_held: Handle_Focus_Type, t
661664

662665
notify_parent_of_active_hot_state(node);
663666

664-
focus_held := Handle_Focus_Type.NONE;
665-
if node == ui_state.active || treat_as_if_active {
667+
if node == ui_state.active {
666668
node.flags |= .ACTIVE;
667669
ui_state.flags |= .ACTIVE_VISITED_THIS_FRAME;
668-
669-
if ui_state.active_holding_focus {
670-
if ((mouse.left & (.DOWN | .RELEASED)) && (ui_state.active_holding_focus == .L))
671-
|| ((mouse.right & (.DOWN | .RELEASED)) && (ui_state.active_holding_focus == .R)) {
672-
focus_held = ui_state.active_holding_focus;
673-
}
674-
// use .UP here instead of .RELEASED, since we still want to hold focus on the frame mouse button is released
675-
if ((mouse.left == .UP) && (ui_state.active_holding_focus == .L))
676-
|| ((mouse.right == .UP) && (ui_state.active_holding_focus == .R)) {
677-
ui_state.active_holding_focus = .NONE;
678-
}
679-
}
680670
}
681-
682-
return focus_held;
683671
}
684672

685673

686674
get_render_color :: (node: *UI_Node, base_color: Color4, hot_color: Color4, active_color: Color4) -> Color4 {
687675
color := base_color;
688676

677+
mouse := get_mouse();
678+
689679
if node.flags & .HOT {
690680
color.r += hot_color.r;
691681
color.g += hot_color.g;
@@ -696,7 +686,7 @@ get_render_color :: (node: *UI_Node, base_color: Color4, hot_color: Color4, acti
696686
color = lerp(base_color, active_color, 0.75);
697687
color.a *= 0.8;
698688
} else if node.flags & .ACTIVE {
699-
if ui_state.active_holding_focus {
689+
if mouse && (mouse.left || mouse.right) {
700690
color = active_color;
701691
} else {
702692
color = lerp(base_color, active_color, 0.85);
@@ -734,24 +724,30 @@ ui_tilemap_handle :: (index: int) {
734724
};
735725

736726
hovered := is_point_within_frect(Editor.mouse_tile_position, rect);
737-
focus := update_active_hot_state(hovered, .L | .R);
727+
update_active_hot_state(hovered, .L | .R);
738728

739-
if focus == {
740-
case .L;
741-
if mouse.velocity != Vec2i.{} {
742-
tilemap.root_offset = Editor.mouse_tile_position;
729+
if node.flags & .ACTIVE {
730+
if mouse.left == {
731+
case .DOWN;
732+
tilemap.root_offset += to_Vec2f(mouse.velocity) / Editor.tile_unit;
733+
Editor.should_recalculate_timeline_points = true;
734+
735+
case .RELEASED;
743736
tilemap.root_offset = snap_to_nearest_unit(tilemap.root_offset, 0.5);
744737
Editor.should_recalculate_timeline_points = true;
745738
}
746-
case .R;
747-
if mouse.velocity != Vec2i.{} {
748-
move := to_Vec2f(mouse.velocity) / Editor.tile_unit;
749-
tilemap.anchor_point += move;
750-
tilemap.root_offset += move;
751-
}
752-
if mouse.right == .RELEASED {
753-
tilemap.anchor_point = snap_to_nearest_unit(tilemap.anchor_point, 0.5);
754-
tilemap.root_offset = snap_to_nearest_unit(tilemap.root_offset, 0.5);
739+
740+
if !mouse.left {
741+
if mouse.right == {
742+
case .DOWN;
743+
move := to_Vec2f(mouse.velocity) / Editor.tile_unit;
744+
tilemap.anchor_point += move;
745+
tilemap.root_offset += move;
746+
747+
case .RELEASED;
748+
tilemap.anchor_point = snap_to_nearest_unit(tilemap.anchor_point, 0.5);
749+
tilemap.root_offset = snap_to_nearest_unit(tilemap.root_offset, 0.5);
750+
}
755751
}
756752
}
757753
if hovered {
@@ -793,21 +789,20 @@ ui_entity_handle :: (index: int) {
793789

794790
mouse := get_mouse();
795791

796-
offset_ptr := *entity.init_position;
792+
offset := entity.init_position;
797793
size := get_size(entity);
798794

799795
rect := Rectf.{
800-
position = offset_ptr.* - size / 2,
796+
position = offset - size / 2,
801797
size = size,
802798
};
803799

804800
hovered := is_point_within_frect(Editor.mouse_tile_position, rect);
805801
is_selected := (entity.flags & .SELECTED_IN_EDITOR).(bool);
806802

807-
focus := update_active_hot_state(hovered, .L, is_selected);
803+
update_active_hot_state(hovered, .L);
808804

809-
if focus == {
810-
case .L;
805+
if is_selected || (node.flags & .ACTIVE) {
811806
if mouse.left == {
812807
case .PRESSED;
813808
if hovered {
@@ -823,14 +818,15 @@ ui_entity_handle :: (index: int) {
823818
}
824819

825820
case .DOWN;
826-
offset_ptr.* += to_Vec2f(mouse.velocity) / Editor.tile_unit;
821+
entity.init_position += to_Vec2f(mouse.velocity) / Editor.tile_unit;
827822

828823
case .RELEASED;
829-
offset_ptr.* = snap_to_nearest_unit(offset_ptr.*, 0.5);
824+
entity.init_position = snap_to_nearest_unit(entity.init_position, 0.5);
830825
}
831826
}
832827

833-
update_node(node, offset_ptr.*);
828+
offset = entity.init_position;
829+
update_node(node, offset);
834830

835831
// NOTE: this will only affect visuals, not ui function
836832
if is_selected {

0 commit comments

Comments
 (0)