move text with the mouse in perf_text example

This commit is contained in:
martinfouilleul 2023-02-09 09:50:53 +01:00
parent 21c604104f
commit 833767d6e2
3 changed files with 41 additions and 6 deletions

View File

@ -112,6 +112,11 @@ int main()
f64 frameTime = 0;
bool tracked = false;
vec2 trackPoint = {0};
f32 startX = 10;
f32 startY = contentRect.h - lineHeight - 10;
while(!mp_should_quit())
{
f64 startFrameTime = mp_get_time(MP_CLOCK_MONOTONIC);
@ -127,13 +132,39 @@ int main()
mp_request_quit();
} 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:
break;
}
}
f32 textX = 10;
f32 textY = contentRect.h - lineHeight - 10;
if(tracked)
{
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_set_color_rgba(1, 1, 1, 1);

View File

@ -224,8 +224,8 @@ static void process_mouse_event(mp_window_data* window, mp_key_action action, mp
mp_event event = {0};
event.window = mp_window_handle_from_ptr(window);
event.type = MP_EVENT_MOUSE_BUTTON;
event.key.action = MP_KEY_PRESS;
event.key.code = MP_MOUSE_LEFT;
event.key.action = action;
event.key.code = button;
event.key.mods = mp_get_mod_keys();
mp_queue_event(&event);
@ -378,11 +378,14 @@ LRESULT WinProc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM lParam)
RECT rect;
GetClientRect(mpWindow->win32.hWnd, &rect);
u32 dpi = GetDpiForWindow(mpWindow->win32.hWnd);
f32 scaling = (f32)dpi/96.;
mp_event event = {0};
event.window = mp_window_handle_from_ptr(mpWindow);
event.type = MP_EVENT_MOUSE_MOVE;
event.move.x = LOWORD(lParam);
event.move.y = rect.bottom - HIWORD(lParam);
event.move.x = LOWORD(lParam) / scaling;
event.move.y = (rect.bottom - HIWORD(lParam)) / scaling;
if(__mpApp.inputState.mouse.posValid)
{

View File

@ -1,6 +1,7 @@
Overview
--------
[ ] Pan/Zoom on text example
[ ] Clean+Fixes of canvas code and examples
[ ] Make backend selection easier
[ ] Investigate and fix artifact when seam is aligned to tile boundary?