better vis mouse focus checking
This commit is contained in:
parent
d84e12d598
commit
2be3381c92
@ -107,3 +107,8 @@ String StringFromButton(Button button)
|
|||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b32 IsMouseButton(Button button)
|
||||||
|
{
|
||||||
|
return button >= Button_M1 && button <= Button_MWheelDown;
|
||||||
|
}
|
||||||
|
|||||||
@ -158,3 +158,4 @@ Struct(ControllerEventsArray)
|
|||||||
//~ Button helpers
|
//~ Button helpers
|
||||||
|
|
||||||
String StringFromButton(Button button);
|
String StringFromButton(Button button);
|
||||||
|
b32 IsMouseButton(Button button);
|
||||||
|
|||||||
@ -611,10 +611,30 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
V_CmdNode *first_cmd_node = 0;
|
V_CmdNode *first_cmd_node = 0;
|
||||||
V_CmdNode *last_cmd_node = 0;
|
V_CmdNode *last_cmd_node = 0;
|
||||||
|
|
||||||
b32 has_focus = window_frame.has_focus && (UI_MatchKey(ui_frame->hovered_box, vis_box) || UI_MatchKey(ui_frame->active_box, vis_box));
|
b32 has_mouse_focus = (UI_MatchKey(ui_frame->hovered_box, vis_box) && UI_IsKeyNil(ui_frame->active_box)) || UI_MatchKey(ui_frame->active_box, vis_box);
|
||||||
if (!has_focus)
|
b32 has_keyboard_focus = 1;
|
||||||
|
if (!window_frame.has_focus)
|
||||||
{
|
{
|
||||||
ZeroStructs(frame->held_buttons, countof(frame->held_buttons));
|
has_mouse_focus = 0;
|
||||||
|
has_keyboard_focus = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Button btn = 0; btn < countof(frame->held_buttons); ++btn)
|
||||||
|
{
|
||||||
|
if (btn == Button_M1 || btn == Button_M2)
|
||||||
|
{
|
||||||
|
if (!has_mouse_focus)
|
||||||
|
{
|
||||||
|
frame->held_buttons[btn] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!has_keyboard_focus)
|
||||||
|
{
|
||||||
|
frame->held_buttons[btn] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (u64 i = 0; i < window_frame.controller_events.count; ++i)
|
for (u64 i = 0; i < window_frame.controller_events.count; ++i)
|
||||||
@ -622,7 +642,27 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
ControllerEvent cev = window_frame.controller_events.events[i];
|
ControllerEvent cev = window_frame.controller_events.events[i];
|
||||||
b32 down = cev.kind == ControllerEventKind_ButtonDown;
|
b32 down = cev.kind == ControllerEventKind_ButtonDown;
|
||||||
b32 up = cev.kind == ControllerEventKind_ButtonUp;
|
b32 up = cev.kind == ControllerEventKind_ButtonUp;
|
||||||
if (up || (down && has_focus))
|
|
||||||
|
b32 ignore = 0;
|
||||||
|
if (down)
|
||||||
|
{
|
||||||
|
if (cev.button == Button_M1 || cev.button == Button_M2)
|
||||||
|
{
|
||||||
|
if (!has_mouse_focus)
|
||||||
|
{
|
||||||
|
ignore = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!has_keyboard_focus)
|
||||||
|
{
|
||||||
|
ignore = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ignore)
|
||||||
{
|
{
|
||||||
V_Hotkey hotkey = Zi;
|
V_Hotkey hotkey = Zi;
|
||||||
hotkey.button = cev.button;
|
hotkey.button = cev.button;
|
||||||
@ -727,7 +767,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
frame->camera_lerp_ratio = 30.0 * frame->dt;
|
frame->camera_lerp_ratio = 40.0 * frame->dt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1152,7 +1192,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
UI_SetNext(AxisSize, UI_PIX(10, 1), .axis = !panel->axis);
|
UI_SetNext(AxisSize, UI_PIX(10, 1), .axis = !panel->axis);
|
||||||
UI_BuildBoxEx(divider_key);
|
UI_BuildBoxEx(divider_key);
|
||||||
|
|
||||||
if (rep.is_hovered || rep.is_m1_held)
|
if (rep.is_hot || rep.is_m1_held)
|
||||||
{
|
{
|
||||||
if (panel->axis == Axis_X)
|
if (panel->axis == Axis_X)
|
||||||
{
|
{
|
||||||
@ -1564,7 +1604,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
{
|
{
|
||||||
if (!frame->is_panning)
|
if (!frame->is_panning)
|
||||||
{
|
{
|
||||||
f32 edit_move_speed = 15.0 * MaxF32(frame->edit_camera_zoom, min_zoom);
|
f32 edit_move_speed = 20.0 * MaxF32(frame->edit_camera_zoom, min_zoom);
|
||||||
frame->edit_camera_pos = AddVec2(frame->edit_camera_pos, MulVec2(move, edit_move_speed * frame->dt));
|
frame->edit_camera_pos = AddVec2(frame->edit_camera_pos, MulVec2(move, edit_move_speed * frame->dt));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1678,6 +1718,8 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
params.selection_mode = frame->selection_mode;
|
params.selection_mode = frame->selection_mode;
|
||||||
params.equipped_tile = frame->equipped_tile;
|
params.equipped_tile = frame->equipped_tile;
|
||||||
|
|
||||||
|
params.has_mouse_focus = has_mouse_focus;
|
||||||
|
params.has_keyboard_focus = has_keyboard_focus;
|
||||||
params.ui_cursor = frame->ui_cursor;
|
params.ui_cursor = frame->ui_cursor;
|
||||||
params.draw_cursor = frame->draw_cursor;
|
params.draw_cursor = frame->draw_cursor;
|
||||||
params.world_cursor = frame->world_cursor;
|
params.world_cursor = frame->world_cursor;
|
||||||
|
|||||||
@ -21,6 +21,8 @@ Struct(V_DParams)
|
|||||||
V_SelectionMode selection_mode;
|
V_SelectionMode selection_mode;
|
||||||
S_TileKind equipped_tile;
|
S_TileKind equipped_tile;
|
||||||
|
|
||||||
|
b32 has_mouse_focus;
|
||||||
|
b32 has_keyboard_focus;
|
||||||
Vec2 ui_cursor;
|
Vec2 ui_cursor;
|
||||||
Vec2 draw_cursor;
|
Vec2 draw_cursor;
|
||||||
Vec2 world_cursor;
|
Vec2 world_cursor;
|
||||||
|
|||||||
@ -236,6 +236,8 @@ PixelShader(V_OverlayPS, V_OverlayPSOutput, V_OverlayPSInput input)
|
|||||||
tile_selection.p0 = S_TilePosFromWorldPos(world_selection.p0);
|
tile_selection.p0 = S_TilePosFromWorldPos(world_selection.p0);
|
||||||
tile_selection.p1 = S_TilePosFromWorldPos(world_selection.p1);
|
tile_selection.p1 = S_TilePosFromWorldPos(world_selection.p1);
|
||||||
|
|
||||||
|
if (params.has_mouse_focus)
|
||||||
|
{
|
||||||
if (params.selection_mode == V_SelectionMode_Tile)
|
if (params.selection_mode == V_SelectionMode_Tile)
|
||||||
{
|
{
|
||||||
f32 dist = 100000000;
|
f32 dist = 100000000;
|
||||||
@ -264,7 +266,7 @@ PixelShader(V_OverlayPS, V_OverlayPSOutput, V_OverlayPSInput input)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
V_OverlayPSOutput output;
|
V_OverlayPSOutput output;
|
||||||
output.sv_target0 = result;
|
output.sv_target0 = result;
|
||||||
|
|||||||
@ -23,6 +23,11 @@ b32 UI_MatchKey(UI_Key a, UI_Key b)
|
|||||||
return a.hash == b.hash;
|
return a.hash == b.hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b32 UI_IsKeyNil(UI_Key key)
|
||||||
|
{
|
||||||
|
return key.hash == 0;
|
||||||
|
}
|
||||||
|
|
||||||
UI_Key UI_KeyFromString(String str)
|
UI_Key UI_KeyFromString(String str)
|
||||||
{
|
{
|
||||||
u64 top_tag = UI_UseTop(Tag);
|
u64 top_tag = UI_UseTop(Tag);
|
||||||
@ -690,13 +695,20 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color)
|
|||||||
|
|
||||||
case ControllerEventKind_ButtonDown:
|
case ControllerEventKind_ButtonDown:
|
||||||
{
|
{
|
||||||
if (cev.button == Button_M1)
|
if (cev.button == Button_M1 || cev.button == Button_M2)
|
||||||
{
|
{
|
||||||
if (hovered_box)
|
if (hovered_box)
|
||||||
{
|
{
|
||||||
++hovered_box->report.m1_downs;
|
++hovered_box->report.m1_downs;
|
||||||
hovered_box->report.is_m1_held = 1;
|
|
||||||
hovered_box->report.last_m1_offset = SubVec2(frame->cursor_pos, hovered_box->rect.p0);
|
hovered_box->report.last_m1_offset = SubVec2(frame->cursor_pos, hovered_box->rect.p0);
|
||||||
|
if (cev.button == Button_M1)
|
||||||
|
{
|
||||||
|
hovered_box->report.is_m1_held = 1;
|
||||||
|
}
|
||||||
|
else if (cev.button == Button_M2)
|
||||||
|
{
|
||||||
|
hovered_box->report.is_m2_held = 1;
|
||||||
|
}
|
||||||
active_box = hovered_box;
|
active_box = hovered_box;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -704,7 +716,7 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color)
|
|||||||
|
|
||||||
case ControllerEventKind_ButtonUp:
|
case ControllerEventKind_ButtonUp:
|
||||||
{
|
{
|
||||||
if (cev.button == Button_M1)
|
if (cev.button == Button_M1 || cev.button == Button_M2)
|
||||||
{
|
{
|
||||||
if (active_box)
|
if (active_box)
|
||||||
{
|
{
|
||||||
@ -713,7 +725,14 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color)
|
|||||||
++active_box->report.m1_presses;
|
++active_box->report.m1_presses;
|
||||||
}
|
}
|
||||||
++active_box->report.m1_ups;
|
++active_box->report.m1_ups;
|
||||||
|
if (cev.button == Button_M1)
|
||||||
|
{
|
||||||
active_box->report.is_m1_held = 0;
|
active_box->report.is_m1_held = 0;
|
||||||
|
}
|
||||||
|
else if (cev.button == Button_M2)
|
||||||
|
{
|
||||||
|
active_box->report.is_m2_held = 0;
|
||||||
|
}
|
||||||
active_box = 0;
|
active_box = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -732,9 +751,10 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color)
|
|||||||
UI_Box *box = last_frame->boxes_pre[pre_index];
|
UI_Box *box = last_frame->boxes_pre[pre_index];
|
||||||
UI_Report *report = &box->report;
|
UI_Report *report = &box->report;
|
||||||
report->is_hovered = box == hovered_box;
|
report->is_hovered = box == hovered_box;
|
||||||
f32 target_hot = box == active_box || (box == hovered_box && (box == active_box || active_box == 0));
|
report->is_hot = box == active_box || (box == hovered_box && (box == active_box || active_box == 0));
|
||||||
|
f32 target_hovered = report->is_hovered;
|
||||||
|
f32 target_hot = report->is_hot;
|
||||||
f32 target_active = box == active_box;
|
f32 target_active = box == active_box;
|
||||||
f32 target_hovered = box == hovered_box;
|
|
||||||
f32 hot_blend_rate = target_hot == 1 ? 1 : (20 * dt);
|
f32 hot_blend_rate = target_hot == 1 ? 1 : (20 * dt);
|
||||||
f32 active_blend_rate = target_active == 1 ? 1 : (20 * dt);
|
f32 active_blend_rate = target_active == 1 ? 1 : (20 * dt);
|
||||||
f32 hovered_blend_rate = target_hovered == 1 ? 1 : (20 * dt);
|
f32 hovered_blend_rate = target_hovered == 1 ? 1 : (20 * dt);
|
||||||
|
|||||||
@ -175,7 +175,9 @@ Struct(UI_Stack)
|
|||||||
Struct(UI_Report)
|
Struct(UI_Report)
|
||||||
{
|
{
|
||||||
b32 is_m1_held;
|
b32 is_m1_held;
|
||||||
|
b32 is_m2_held;
|
||||||
b32 is_hovered;
|
b32 is_hovered;
|
||||||
|
b32 is_hot;
|
||||||
|
|
||||||
f32 hovered;
|
f32 hovered;
|
||||||
f32 hot;
|
f32 hot;
|
||||||
@ -395,6 +397,7 @@ GC_FontKey UI_GetDefaultFont(void);
|
|||||||
//~ Key helpers
|
//~ Key helpers
|
||||||
|
|
||||||
b32 UI_MatchKey(UI_Key a, UI_Key b);
|
b32 UI_MatchKey(UI_Key a, UI_Key b);
|
||||||
|
b32 UI_IsKeyNil(UI_Key key);
|
||||||
UI_Key UI_KeyFromString(String str);
|
UI_Key UI_KeyFromString(String str);
|
||||||
UI_Key UI_KeyF_(String fmt, ...);
|
UI_Key UI_KeyF_(String fmt, ...);
|
||||||
#define UI_KeyF(fmt_cstr, ...) UI_KeyF_(StringFromCstrNoLimit(fmt_cstr), __VA_ARGS__, FmtEnd)
|
#define UI_KeyF(fmt_cstr, ...) UI_KeyF_(StringFromCstrNoLimit(fmt_cstr), __VA_ARGS__, FmtEnd)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user