summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-08-12 09:09:24 +0000
committerfrosch <frosch@openttd.org>2010-08-12 09:09:24 +0000
commit57c063250fb8234f17ceda91fb87c2057d5d212e (patch)
tree170b6f5a5fad0197e91b0d9df979521121803884
parent66e48dfdce40b2fac38ae5931581d24fded4265e (diff)
downloadopenttd-57c063250fb8234f17ceda91fb87c2057d5d212e.tar.xz
(svn r20457) -Codechange: Remove _scrolling_scrollbar and WF_SCROLL_MIDDLE and instead store the widget index of the being scrolled scrollbar in the Window.
-rw-r--r--src/widget.cpp26
-rw-r--r--src/window.cpp24
-rw-r--r--src/window_gui.h6
3 files changed, 21 insertions, 35 deletions
diff --git a/src/widget.cpp b/src/widget.cpp
index 88878e0c8..7c6447d0a 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -65,25 +65,24 @@ static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom, bo
/**
* Compute new position of the scrollbar after a click and updates the window flags.
* @param w Window on which a scroll was performed.
- * @param wtp Scrollbar widget type.
+ * @param nw Scrollbar
* @param mi Minimum coordinate of the scroll bar.
* @param ma Maximum coordinate of the scroll bar.
* @param x The X coordinate of the mouse click.
* @param y The Y coordinate of the mouse click.
*/
-static void ScrollbarClickPositioning(Window *w, WidgetType wtp, int x, int y, int mi, int ma)
+static void ScrollbarClickPositioning(Window *w, NWidgetScrollbar *nw, int x, int y, int mi, int ma)
{
int pos;
- Scrollbar *sb;
bool rtl = false;
+ Scrollbar *sb = nw->GetScrollbar(w);
- switch (wtp) {
+ switch (nw->type) {
case WWT_SCROLLBAR:
/* vertical scroller */
w->flags4 &= ~WF_HSCROLL;
w->flags4 &= ~WF_SCROLL2;
pos = y;
- sb = &w->old_vscroll;
break;
case WWT_SCROLL2BAR:
@@ -91,7 +90,6 @@ static void ScrollbarClickPositioning(Window *w, WidgetType wtp, int x, int y, i
w->flags4 &= ~WF_HSCROLL;
w->flags4 |= WF_SCROLL2;
pos = y;
- sb = &w->old_vscroll2;
break;
case WWT_HSCROLLBAR:
@@ -99,7 +97,6 @@ static void ScrollbarClickPositioning(Window *w, WidgetType wtp, int x, int y, i
w->flags4 &= ~WF_SCROLL2;
w->flags4 |= WF_HSCROLL;
pos = x;
- sb = &w->old_hscroll;
rtl = _dynlang.text_dir == TD_RTL;
break;
@@ -123,7 +120,7 @@ static void ScrollbarClickPositioning(Window *w, WidgetType wtp, int x, int y, i
}
_left_button_clicked = false;
} else {
- Point pt = HandleScrollbarHittest(sb, mi, ma, wtp == WWT_HSCROLLBAR);
+ Point pt = HandleScrollbarHittest(sb, mi, ma, nw->type == WWT_HSCROLLBAR);
if (pos < pt.x) {
sb->UpdatePosition(rtl ? sb->GetCapacity() : -sb->GetCapacity());
@@ -132,8 +129,7 @@ static void ScrollbarClickPositioning(Window *w, WidgetType wtp, int x, int y, i
} else {
_scrollbar_start_pos = pt.x - mi - 9;
_scrollbar_size = ma - mi - 23;
- w->flags4 |= WF_SCROLL_MIDDLE;
- _scrolling_scrollbar = true;
+ w->scrolling_scrollbar = nw->index;
_cursorpos_drag_start = _cursor.pos;
}
}
@@ -149,7 +145,7 @@ static void ScrollbarClickPositioning(Window *w, WidgetType wtp, int x, int y, i
* @param x The X coordinate of the mouse click.
* @param y The Y coordinate of the mouse click.
*/
-void ScrollbarClickHandler(Window *w, const NWidgetCore *nw, int x, int y)
+void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
{
int mi, ma;
@@ -174,7 +170,7 @@ void ScrollbarClickHandler(Window *w, const NWidgetCore *nw, int x, int y)
default: NOT_REACHED();
}
- ScrollbarClickPositioning(w, nw->type, x, y, mi, ma);
+ ScrollbarClickPositioning(w, dynamic_cast<NWidgetScrollbar*>(nw), x, y, mi, ma);
}
/**
@@ -1693,21 +1689,21 @@ void NWidgetScrollbar::Draw(const Window *w)
switch (this->type) {
case WWT_HSCROLLBAR:
DrawHorizontalScrollbar(r, this->colour, (w->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL),
- (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL)) == (WF_SCROLL_MIDDLE | WF_HSCROLL),
+ w->scrolling_scrollbar == this->index,
(w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL), this->GetScrollbar(w));
break;
case WWT_SCROLLBAR:
assert(this->widget_data == 0);
DrawVerticalScrollbar(r, this->colour, (w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP,
- (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_MIDDLE,
+ w->scrolling_scrollbar == this->index,
(w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN, this->GetScrollbar(w));
break;
case WWT_SCROLL2BAR:
assert(this->widget_data == 0);
DrawVerticalScrollbar(r, this->colour, (w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2),
- (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_MIDDLE | WF_SCROLL2),
+ w->scrolling_scrollbar == this->index,
(w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2), this->GetScrollbar(w));
break;
diff --git a/src/window.cpp b/src/window.cpp
index cba0f799e..3919bf674 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -56,7 +56,6 @@ int _scrollbar_start_pos;
int _scrollbar_size;
byte _scroller_click_timeout;
-bool _scrolling_scrollbar; ///< A scrollbar is being scrolled with the mouse.
bool _scrolling_viewport; ///< A viewport is being scrolled with the mouse.
bool _mouse_hovering; ///< The mouse is hovering over the same point.
@@ -312,7 +311,7 @@ static void StartWindowSizing(Window *w, bool to_left);
*/
static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
{
- const NWidgetCore *nw = w->nested_root->GetWidgetFromPos(x, y);
+ NWidgetCore *nw = w->nested_root->GetWidgetFromPos(x, y);
WidgetType widget_type = (nw != NULL) ? nw->type : WWT_EMPTY;
bool focused_widget_changed = false;
@@ -1337,7 +1336,7 @@ void Window::InitNested(const WindowDesc *desc, WindowNumber window_number)
}
/** Empty constructor, initialization has been moved to #InitNested() called from the constructor of the derived class. */
-Window::Window() : old_hscroll(false), old_vscroll(true), old_vscroll2(true)
+Window::Window() : old_hscroll(false), old_vscroll(true), old_vscroll2(true), scrolling_scrollbar(-1)
{
}
@@ -1854,33 +1853,25 @@ static void StartWindowSizing(Window *w, bool to_left)
static EventState HandleScrollbarScrolling()
{
Window *w;
-
- /* Get out quickly if no item is being scrolled */
- if (!_scrolling_scrollbar) return ES_NOT_HANDLED;
-
- /* Find the scrolling window */
FOR_ALL_WINDOWS_FROM_BACK(w) {
- if (w->flags4 & WF_SCROLL_MIDDLE) {
+ if (w->scrolling_scrollbar >= 0) {
/* Abort if no button is clicked any more. */
if (!_left_button_down) {
- w->flags4 &= ~WF_SCROLL_MIDDLE;
+ w->scrolling_scrollbar = -1;
w->SetDirty();
- break;
+ return ES_HANDLED;
}
int i;
- Scrollbar *sb;
+ Scrollbar *sb = w->GetScrollbar(w->scrolling_scrollbar);
bool rtl = false;
if (w->flags4 & WF_HSCROLL) {
- sb = &w->old_hscroll;
i = _cursor.pos.x - _cursorpos_drag_start.x;
rtl = _dynlang.text_dir == TD_RTL;
} else if (w->flags4 & WF_SCROLL2) {
- sb = &w->old_vscroll2;
i = _cursor.pos.y - _cursorpos_drag_start.y;
} else {
- sb = &w->old_vscroll;
i = _cursor.pos.y - _cursorpos_drag_start.y;
}
@@ -1895,8 +1886,7 @@ static EventState HandleScrollbarScrolling()
}
}
- _scrolling_scrollbar = false;
- return ES_HANDLED;
+ return ES_NOT_HANDLED;
}
/**
diff --git a/src/window_gui.h b/src/window_gui.h
index 1f51c3aa5..9c7192399 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -398,6 +398,8 @@ public:
NWidgetStacked *shade_select; ///< Selection widget (#NWID_SELECTION) to use for shading the window. If \c NULL, window cannot shade.
Dimension unshaded_size; ///< Last known unshaded size (only valid while shaded).
+ int scrolling_scrollbar; ///< Widgetindex of just being dragged scrollbar. -1 of none is active.
+
Window *parent; ///< Parent window.
Window *z_front; ///< The window in front of us in z-order.
Window *z_back; ///< The window behind us in z-order.
@@ -875,7 +877,6 @@ enum WindowFlags {
WF_DRAGGING = 1 << 3, ///< Window is being dragged
WF_SCROLL_UP = 1 << 4, ///< Upper scroll button has been pressed, @see ScrollbarClickHandler()
WF_SCROLL_DOWN = 1 << 5, ///< Lower scroll button has been pressed, @see ScrollbarClickHandler()
- WF_SCROLL_MIDDLE = 1 << 6, ///< Scrollbar scrolling, @see ScrollbarClickHandler()
WF_SCROLL2 = 1 << 7,
WF_HSCROLL = 1 << 8,
WF_SIZING_RIGHT = 1 << 9, ///< Window is being resized towards the right.
@@ -933,7 +934,6 @@ extern int _scrollbar_start_pos;
extern int _scrollbar_size;
extern byte _scroller_click_timeout;
-extern bool _scrolling_scrollbar;
extern bool _scrolling_viewport;
extern bool _mouse_hovering;
@@ -951,6 +951,6 @@ Window *GetCallbackWnd();
void SetFocusedWindow(Window *w);
bool EditBoxInGlobalFocus();
-void ScrollbarClickHandler(Window *w, const NWidgetCore *nw, int x, int y);
+void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y);
#endif /* WINDOW_GUI_H */