2Mode :: enum #specified {
3 TRAD_TREE :: 0;
4 HYPER_TREE :: 1;
5 CELLS :: 2;
6}
8Gui_Feature :: enum_flags {
9 TOOLTIP;
10}
13input :: () {
15 /* ----------- *
16 * Zoom & Drag *
17 * ----------- */
19 if IsKeyDown(.LEFT_SHIFT) {
20 dragging = false;
21 if !selecting then SetMouseCursor(.DEFAULT);
23 if IsMouseButtonPressed(.LEFT) {
24 selecting = true;
25 selection.x = mouse_world.x;
26 selection.y = mouse_world.y;
27 SetMouseCursor(.RESIZE_NESW);
28 }
29 }
31 if IsMouseButtonPressed(.LEFT) {
32 drag_start = mouse_screen;
33 dragging = true;
34 SetMouseCursor(.RESIZE_ALL);
35 }
37 if IsMouseButtonReleased(.LEFT) {
38 dragging = false;
39 SetMouseCursor(.DEFAULT);
41 if selecting {
42 selecting = false;
43 zoom_to_selection();
44 }
45 }
47 if IsMouseButtonPressed(.RIGHT) {
48 if selecting then selecting = false;
49 }
52 if dragging {
53 camera.target.x -= (mouse_screen.x - drag_start.x) / camera.zoom;
54 camera.target.y -= (mouse_screen.y - drag_start.y) / camera.zoom;
55 drag_start = mouse_screen;
56 }
59 wheel := GetMouseWheelMove();
60 if wheel != 0.0 {
61 before := Vector2.{
62 camera.target.x + (mouse_screen.x - camera.offset.x) / camera.zoom,
63 camera.target.y + (mouse_screen.y - camera.offset.y) / camera.zoom
64 };
66 camera.zoom *= (1.0 + wheel * 0.1);
68 // TODO: Maybe lerp?
70 //! t := 1.0 - exp(-8.0 * frame_time);
71 //! camera.zoom *= lerp(thing1, thing2, t);
72 camera.zoom = clamp(camera.zoom, 0.1, 5.0);
74 camera.target.x = before.x - (mouse_screen.x - camera.offset.x) / camera.zoom;
75 camera.target.y = before.y - (mouse_screen.y - camera.offset.y) / camera.zoom;
76 }
79 /* ----- *
80 * Modes *
81 * ----- */
83 if IsKeyPressed(.F1) {
84 if mode == .TRAD_TREE {
85 vtree_fit_zoom();
86 } else {
87 mode = .TRAD_TREE;
88 state_switch(mode);
89 }
90 }
91 else if IsKeyPressed(.F2) {
92 if mode == .HYPER_TREE {
93 htree_fit_zoom();
94 } else {
95 mode = .HYPER_TREE;
96 state_switch(mode);
97 }
98 }
99 else if IsKeyPressed(.F3) {
100 if mode == .CELLS {
101 cells_fit_zoom();
102 } else {
103 mode = .CELLS;
104 state_switch(mode);
105 }
106 }
108 /* ---------------------- *
109 * Context Based Features *
110 * ---------------------- */
112 if mode == {
113 case .CELLS;
114 if IsKeyPressed(.KEY_T) then flag_toggle(.TOOLTIP);
115 }
116}
118input_draw_selection :: () {
119 if !selecting return;
121 using selection;
122 width = mouse_world.x - x;
123 height = mouse_world.y - y;
125 selection_normalized = normalize_selection(selection);
126 DrawRectangleLinesEx(selection_normalized, 2.0, GREEN);
127}
129flag_has :: (flag: Gui_Feature) -> bool {
130 return cast(bool, gui_feature & flag);
131}
133flag_add :: (flag: Gui_Feature) {
134 gui_feature |= flag;
135}
137flag_remove :: (flag: Gui_Feature) {
138 gui_feature &= ~flag;
139}
141flag_toggle :: (flag: Gui_Feature) {
142 gui_feature ^= flag;
143}
146#scope_file
149drag_start: Vector2;
150dragging: bool;
152selection: Rectangle;
153selection_normalized: Rectangle;
154selecting: bool;
157normalize_selection :: (using selection: Rectangle) -> Rectangle {
158 nx := ifx width < 0 then x + width else x;
159 ny := ifx height < 0 then y + height else y;
161 return { nx, ny, abs(width), abs(height) };
162}
164zoom_to_selection :: () {
165 using selection_normalized;
167 center := Vector2.{ x + width / 2.0, y + height / 2.0 };
168 zoom_x := cast(float, GetScreenWidth() / width);
169 zoom_y := cast(float, GetScreenHeight() / height);
171 new_zoom := min(zoom_x, zoom_y) * 0.9;
173 camera.offset = { GetScreenWidth() / 2.0, GetScreenHeight() / 2.0 };
174 camera.target = center;
175 camera.zoom = new_zoom;
176}
index : binary-tree
---