move text with the mouse in perf_text example
This commit is contained in:
parent
21c604104f
commit
833767d6e2
|
@ -112,6 +112,11 @@ int main()
|
||||||
|
|
||||||
f64 frameTime = 0;
|
f64 frameTime = 0;
|
||||||
|
|
||||||
|
bool tracked = false;
|
||||||
|
vec2 trackPoint = {0};
|
||||||
|
f32 startX = 10;
|
||||||
|
f32 startY = contentRect.h - lineHeight - 10;
|
||||||
|
|
||||||
while(!mp_should_quit())
|
while(!mp_should_quit())
|
||||||
{
|
{
|
||||||
f64 startFrameTime = mp_get_time(MP_CLOCK_MONOTONIC);
|
f64 startFrameTime = mp_get_time(MP_CLOCK_MONOTONIC);
|
||||||
|
@ -127,13 +132,39 @@ int main()
|
||||||
mp_request_quit();
|
mp_request_quit();
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
case MP_EVENT_MOUSE_BUTTON:
|
||||||
|
{
|
||||||
|
if(event.key.code == MP_MOUSE_LEFT)
|
||||||
|
{
|
||||||
|
if(event.key.action == MP_KEY_PRESS)
|
||||||
|
{
|
||||||
|
tracked = true;
|
||||||
|
vec2 mousePos = mp_input_mouse_position();
|
||||||
|
trackPoint.x = mousePos.x - startX;
|
||||||
|
trackPoint.y = mousePos.y - startY;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tracked = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f32 textX = 10;
|
if(tracked)
|
||||||
f32 textY = contentRect.h - lineHeight - 10;
|
{
|
||||||
|
vec2 mousePos = mp_input_mouse_position();
|
||||||
|
startX = mousePos.x - trackPoint.x;
|
||||||
|
startY = mousePos.y - trackPoint.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
f32 textX = startX;
|
||||||
|
f32 textY = startY;
|
||||||
|
|
||||||
mg_surface_prepare(surface);
|
mg_surface_prepare(surface);
|
||||||
mg_set_color_rgba(1, 1, 1, 1);
|
mg_set_color_rgba(1, 1, 1, 1);
|
||||||
|
|
|
@ -224,8 +224,8 @@ static void process_mouse_event(mp_window_data* window, mp_key_action action, mp
|
||||||
mp_event event = {0};
|
mp_event event = {0};
|
||||||
event.window = mp_window_handle_from_ptr(window);
|
event.window = mp_window_handle_from_ptr(window);
|
||||||
event.type = MP_EVENT_MOUSE_BUTTON;
|
event.type = MP_EVENT_MOUSE_BUTTON;
|
||||||
event.key.action = MP_KEY_PRESS;
|
event.key.action = action;
|
||||||
event.key.code = MP_MOUSE_LEFT;
|
event.key.code = button;
|
||||||
event.key.mods = mp_get_mod_keys();
|
event.key.mods = mp_get_mod_keys();
|
||||||
|
|
||||||
mp_queue_event(&event);
|
mp_queue_event(&event);
|
||||||
|
@ -378,11 +378,14 @@ LRESULT WinProc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
RECT rect;
|
RECT rect;
|
||||||
GetClientRect(mpWindow->win32.hWnd, &rect);
|
GetClientRect(mpWindow->win32.hWnd, &rect);
|
||||||
|
|
||||||
|
u32 dpi = GetDpiForWindow(mpWindow->win32.hWnd);
|
||||||
|
f32 scaling = (f32)dpi/96.;
|
||||||
|
|
||||||
mp_event event = {0};
|
mp_event event = {0};
|
||||||
event.window = mp_window_handle_from_ptr(mpWindow);
|
event.window = mp_window_handle_from_ptr(mpWindow);
|
||||||
event.type = MP_EVENT_MOUSE_MOVE;
|
event.type = MP_EVENT_MOUSE_MOVE;
|
||||||
event.move.x = LOWORD(lParam);
|
event.move.x = LOWORD(lParam) / scaling;
|
||||||
event.move.y = rect.bottom - HIWORD(lParam);
|
event.move.y = (rect.bottom - HIWORD(lParam)) / scaling;
|
||||||
|
|
||||||
if(__mpApp.inputState.mouse.posValid)
|
if(__mpApp.inputState.mouse.posValid)
|
||||||
{
|
{
|
||||||
|
|
1
todo.txt
1
todo.txt
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
Overview
|
Overview
|
||||||
--------
|
--------
|
||||||
|
[ ] Pan/Zoom on text example
|
||||||
[ ] Clean+Fixes of canvas code and examples
|
[ ] Clean+Fixes of canvas code and examples
|
||||||
[ ] Make backend selection easier
|
[ ] Make backend selection easier
|
||||||
[ ] Investigate and fix artifact when seam is aligned to tile boundary?
|
[ ] Investigate and fix artifact when seam is aligned to tile boundary?
|
||||||
|
|
Loading…
Reference in New Issue