From 6dd784058ae8e45b306311bd303d09a32113f50e Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Sun, 3 Apr 2016 21:56:12 +0200 Subject: PML. --- src/ui.c | 58 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 16 deletions(-) (limited to 'src/ui.c') diff --git a/src/ui.c b/src/ui.c index 4245603..3f2214a 100644 --- a/src/ui.c +++ b/src/ui.c @@ -24,7 +24,7 @@ struct { typedef struct { phy_sim *sim; - bool dragging, selecting; + bool dragging, dragging_frac, selecting; int xsection_flags; float xsection_frac; bool select_valid; @@ -167,31 +167,54 @@ void ui_event_window(SDL_Event *event, ui_window *uiw) case SDL_MOUSEBUTTONDOWN: if (event->button.y > sv->margin_top && event->button.y < uiw->h - sv->margin_bottom) { - if (event->button.button == SDL_BUTTON_LEFT) + switch (event->button.button) { + case SDL_BUTTON_LEFT: sv->dragging = true; - - if (event->button.button == SDL_BUTTON_RIGHT) + break; + case SDL_BUTTON_RIGHT: + sv->dragging_frac = true; + break; + case SDL_BUTTON_MIDDLE: sv->selecting = true; + break; + } } break; case SDL_MOUSEBUTTONUP: - if (event->button.button == SDL_BUTTON_LEFT) + switch (event->button.button) { + case SDL_BUTTON_LEFT: sv->dragging = false; - else if (event->button.button == SDL_BUTTON_RIGHT) + break; + case SDL_BUTTON_RIGHT: + sv->dragging_frac = false; + break; + case SDL_BUTTON_MIDDLE: sv->selecting = false; - break; + break; + } case SDL_MOUSEMOTION: uiw->mouse[0] = event->motion.x; uiw->mouse[1] = event->motion.y; - if (sv->dragging) { + if (sv->dragging || sv->dragging_frac) { vec2_t delta_v; v2_set(delta_v, event->motion.xrel, event->motion.yrel); v2_div_mst2_nt(delta_v, delta_v, sv->tf_v2s); - v2_add(sv->origin, sv->origin, delta_v); + + if (sv->dragging) + v2_add(sv->origin, sv->origin, delta_v); + + if (sv->dragging_frac) { + sv->xsection_frac += delta_v[1]; + + if (sv->xsection_frac > 1.0f) + sv->xsection_frac = 1.0f; + else if (sv->xsection_frac < 0.0f) + sv->xsection_frac = 0.0f; + } } break; @@ -407,14 +430,17 @@ void ui_draw_simview_selection(ui_window *uiw) char *ui_draw_simview_top_bar_text(ui_simview *sv) { int flags = sv->xsection_flags; + char *rv; + + rv = va("Przekrój %s płaszczyzną %s=%f", + (flags & XSECTION_E ? "E" : + "H"), + (flags & XSECTION_XY ? "Z" : + flags & XSECTION_XZ ? "Y" : + "X"), + sv->xsection_frac); - va("Przekrój %s płaszczyzną %s=%f", - (flags & XSECTION_E ? "E" : - "H"), - (flags & XSECTION_XY ? "Z" : - flags & XSECTION_XZ ? "Y" : - "X"), - sv->xsection_frac); + return rv; } void ui_draw_simview_bars(ui_window *uiw, float dt) -- cgit