Fixed fast window scaling behavior

If you move the cursor to fast while scaling a window there is a
chance the mouse will miss the scaler and the scaling operation will
halt. Dragging in itself is quite hard but I implemented the hack I
use for property, window moving and slider for the window scaler and
scaling hopefully now works correctly.
This commit is contained in:
vurtun 2016-08-04 21:07:08 +02:00
parent 2b1c2ca540
commit 204a663de7
1 changed files with 19 additions and 17 deletions

View File

@ -183,6 +183,7 @@ LICENSE:
publish and distribute this file as you see fit. publish and distribute this file as you see fit.
CHANGELOG: CHANGELOG:
- 2016/08/04 (1.044)- Fixed fast window scaling behavior
- 2016/08/04 (1.043)- Fixed window scaling, movement bug which appears if you - 2016/08/04 (1.043)- Fixed window scaling, movement bug which appears if you
move/scale a window and another window is behind it. move/scale a window and another window is behind it.
If you are fast enough then the window behind gets activated If you are fast enough then the window behind gets activated
@ -16349,39 +16350,40 @@ nk_panel_end(struct nk_context *ctx)
if ((layout->flags & NK_WINDOW_SCALABLE) && in && !(layout->flags & NK_WINDOW_MINIMIZED)) if ((layout->flags & NK_WINDOW_SCALABLE) && in && !(layout->flags & NK_WINDOW_MINIMIZED))
{ {
/* calculate scaler bounds */ /* calculate scaler bounds */
const struct nk_style_item *scaler; struct nk_rect scaler;
float scaler_w = NK_MAX(0, scaler_size.x - window_padding.x); const struct nk_style_item *item;
float scaler_h = NK_MAX(0, scaler_size.y - window_padding.y); scaler.w = NK_MAX(0, scaler_size.x - window_padding.x);
float scaler_x = (layout->bounds.x + layout->bounds.w) - (window_padding.x + scaler_w); scaler.h = NK_MAX(0, scaler_size.y - window_padding.y);
float scaler_y; scaler.x = (layout->bounds.x + layout->bounds.w) - (window_padding.x + scaler.w);
if (layout->flags & NK_WINDOW_DYNAMIC) if (layout->flags & NK_WINDOW_DYNAMIC)
scaler_y = footer.y + layout->footer_h - scaler_size.y; scaler.y = footer.y + layout->footer_h - scaler_size.y;
else scaler_y = layout->bounds.y + layout->bounds.h - scaler_size.y; else scaler.y = layout->bounds.y + layout->bounds.h - scaler_size.y;
/* draw scaler */ /* draw scaler */
scaler = &style->window.scaler; item = &style->window.scaler;
if (scaler->type == NK_STYLE_ITEM_IMAGE) { if (item->type == NK_STYLE_ITEM_IMAGE) {
nk_draw_image(out, nk_rect(scaler_x, scaler_y, scaler_w, scaler_h), nk_draw_image(out, scaler, &item->data.image, nk_white);
&scaler->data.image, nk_white);
} else { } else {
nk_fill_triangle(out, scaler_x + scaler_w, scaler_y, scaler_x + scaler_w, nk_fill_triangle(out, scaler.x + scaler.w, scaler.y, scaler.x + scaler.w,
scaler_y + scaler_h, scaler_x, scaler_y + scaler_h, scaler->data.color); scaler.y + scaler.h, scaler.x, scaler.y + scaler.h, item->data.color);
} }
/* do window scaling */ /* do window scaling */
if (!(window->flags & NK_WINDOW_ROM)) { if (!(window->flags & NK_WINDOW_ROM)) {
float prev_x = in->mouse.prev.x;
float prev_y = in->mouse.prev.y;
struct nk_vec2 window_size = style->window.min_size; struct nk_vec2 window_size = style->window.min_size;
int incursor = NK_INBOX(prev_x,prev_y,scaler_x,scaler_y,scaler_w,scaler_h); int left_mouse_down = in->mouse.buttons[NK_BUTTON_LEFT].down;
int left_mouse_click_in_scaler = nk_input_has_mouse_click_down_in_rect(in,
NK_BUTTON_LEFT, scaler, nk_true);
if (nk_input_is_mouse_down(in, NK_BUTTON_LEFT) && incursor) { if (nk_input_is_mouse_down(in, NK_BUTTON_LEFT) && left_mouse_down && left_mouse_click_in_scaler) {
window->bounds.w = NK_MAX(window_size.x, window->bounds.w + in->mouse.delta.x); window->bounds.w = NK_MAX(window_size.x, window->bounds.w + in->mouse.delta.x);
/* dragging in y-direction is only possible if static window */ /* dragging in y-direction is only possible if static window */
if (!(layout->flags & NK_WINDOW_DYNAMIC)) if (!(layout->flags & NK_WINDOW_DYNAMIC))
window->bounds.h = NK_MAX(window_size.y, window->bounds.h + in->mouse.delta.y); window->bounds.h = NK_MAX(window_size.y, window->bounds.h + in->mouse.delta.y);
ctx->style.cursor_active = ctx->style.cursors[NK_CURSOR_RESIZE_TOP_RIGHT_DOWN_LEFT]; ctx->style.cursor_active = ctx->style.cursors[NK_CURSOR_RESIZE_TOP_RIGHT_DOWN_LEFT];
in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.x = scaler.x + in->mouse.delta.x + scaler.w/2.0f;
in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.y = scaler.y + in->mouse.delta.y + scaler.h/2.0f;
} }
} }
} }