no-titlebars: fixed dragon droppings

This commit is contained in:
pelya
2017-03-31 04:16:47 +03:00
parent 7aef2e6897
commit a13b40e0c8
3 changed files with 20 additions and 13 deletions

View File

@@ -86,14 +86,12 @@ static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom, bo
* @param ma Maximum coordinate of the scroll bar. * @param ma Maximum coordinate of the scroll bar.
* @param x The X coordinate of the mouse click. * @param x The X coordinate of the mouse click.
* @param y The Y coordinate of the mouse click. * @param y The Y coordinate of the mouse click.
* @return true if scrollbar slider is pressed
*/ */
static bool ScrollbarClickPositioning(Window *w, NWidgetScrollbar *sb, int x, int y, int mi, int ma) static void ScrollbarClickPositioning(Window *w, NWidgetScrollbar *sb, int x, int y, int mi, int ma)
{ {
int pos; int pos;
int button_size; int button_size;
bool rtl = false; bool rtl = false;
bool sliderPressed = false;
if (sb->type == NWID_HSCROLLBAR) { if (sb->type == NWID_HSCROLLBAR) {
pos = x; pos = x;
@@ -134,12 +132,10 @@ static bool ScrollbarClickPositioning(Window *w, NWidgetScrollbar *sb, int x, in
_scrollbar_size -= button_size; _scrollbar_size -= button_size;
w->scrolling_scrollbar = sb->index; w->scrolling_scrollbar = sb->index;
_cursorpos_drag_start = _cursor.pos; _cursorpos_drag_start = _cursor.pos;
sliderPressed = true;
} }
} }
w->SetDirty(); w->SetDirty();
return sliderPressed;
} }
/** /**
@@ -149,9 +145,8 @@ static bool ScrollbarClickPositioning(Window *w, NWidgetScrollbar *sb, int x, in
* @param nw Pointer to the scrollbar widget. * @param nw Pointer to the scrollbar widget.
* @param x The X coordinate of the mouse click. * @param x The X coordinate of the mouse click.
* @param y The Y coordinate of the mouse click. * @param y The Y coordinate of the mouse click.
* @return true if scrollbar slider is pressed
*/ */
bool ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y) void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
{ {
int mi, ma; int mi, ma;
@@ -164,7 +159,7 @@ bool ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
} }
NWidgetScrollbar *scrollbar = dynamic_cast<NWidgetScrollbar*>(nw); NWidgetScrollbar *scrollbar = dynamic_cast<NWidgetScrollbar*>(nw);
assert(scrollbar != NULL); assert(scrollbar != NULL);
return ScrollbarClickPositioning(w, scrollbar, x, y, mi, ma); ScrollbarClickPositioning(w, scrollbar, x, y, mi, ma);
} }
/** /**

View File

@@ -808,7 +808,8 @@ static void ChangeFocusedWindow(Window *w, int x, int y)
switch (widget_type) { switch (widget_type) {
case NWID_VSCROLLBAR: case NWID_VSCROLLBAR:
case NWID_HSCROLLBAR: case NWID_HSCROLLBAR:
if (ScrollbarClickHandler(w, nw, x, y)) _dragging_widget = true; ScrollbarClickHandler(w, nw, x, y);
_dragging_widget = true;
break; break;
case WWT_RESIZEBOX: case WWT_RESIZEBOX:
@@ -2213,7 +2214,14 @@ static EventState HandleMouseDragDrop()
{ {
if (_special_mouse_mode != WSM_DRAGDROP) return ES_NOT_HANDLED; if (_special_mouse_mode != WSM_DRAGDROP) return ES_NOT_HANDLED;
if (_left_button_down && _cursor.delta.x == 0 && _cursor.delta.y == 0) return ES_HANDLED; // Dragging, but the mouse did not move. bool button = _left_button_down;
static bool button_second_click = false;
if (!_settings_client.gui.windows_titlebars) {
if (_left_button_down) button_second_click = true;
button = _left_button_down || !button_second_click;
}
if (button && _cursor.delta.x == 0 && _cursor.delta.y == 0) return ES_HANDLED; // Dragging, but the mouse did not move.
Window *w = _thd.GetCallbackWnd(); Window *w = _thd.GetCallbackWnd();
if (w != NULL) { if (w != NULL) {
@@ -2221,14 +2229,18 @@ static EventState HandleMouseDragDrop()
Point pt; Point pt;
pt.x = _cursor.pos.x - w->left; pt.x = _cursor.pos.x - w->left;
pt.y = _cursor.pos.y - w->top; pt.y = _cursor.pos.y - w->top;
if (_left_button_down) { if (button) {
w->OnMouseDrag(pt, GetWidgetFromPos(w, pt.x, pt.y)); w->OnMouseDrag(pt, GetWidgetFromPos(w, pt.x, pt.y));
} else { } else {
w->OnDragDrop(pt, GetWidgetFromPos(w, pt.x, pt.y)); w->OnDragDrop(pt, GetWidgetFromPos(w, pt.x, pt.y));
} }
} }
if (!_left_button_down) ResetObjectToPlace(); // Button released, finished dragging. if (!button) {
ResetObjectToPlace(); // Button released, finished dragging.
button_second_click = false;
}
return ES_HANDLED; return ES_HANDLED;
} }

View File

@@ -912,6 +912,6 @@ extern SpecialMouseMode _special_mouse_mode;
void SetFocusedWindow(Window *w); void SetFocusedWindow(Window *w);
bool ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y); void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y);
#endif /* WINDOW_GUI_H */ #endif /* WINDOW_GUI_H */