mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r20457) -Codechange: Remove _scrolling_scrollbar and WF_SCROLL_MIDDLE and instead store the widget index of the being scrolled scrollbar in the Window.
This commit is contained in:
parent
66e48dfdce
commit
57c063250f
|
@ -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.
|
* Compute new position of the scrollbar after a click and updates the window flags.
|
||||||
* @param w Window on which a scroll was performed.
|
* @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 mi Minimum coordinate of the scroll bar.
|
||||||
* @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.
|
||||||
*/
|
*/
|
||||||
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;
|
int pos;
|
||||||
Scrollbar *sb;
|
|
||||||
bool rtl = false;
|
bool rtl = false;
|
||||||
|
Scrollbar *sb = nw->GetScrollbar(w);
|
||||||
|
|
||||||
switch (wtp) {
|
switch (nw->type) {
|
||||||
case WWT_SCROLLBAR:
|
case WWT_SCROLLBAR:
|
||||||
/* vertical scroller */
|
/* vertical scroller */
|
||||||
w->flags4 &= ~WF_HSCROLL;
|
w->flags4 &= ~WF_HSCROLL;
|
||||||
w->flags4 &= ~WF_SCROLL2;
|
w->flags4 &= ~WF_SCROLL2;
|
||||||
pos = y;
|
pos = y;
|
||||||
sb = &w->old_vscroll;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WWT_SCROLL2BAR:
|
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_HSCROLL;
|
||||||
w->flags4 |= WF_SCROLL2;
|
w->flags4 |= WF_SCROLL2;
|
||||||
pos = y;
|
pos = y;
|
||||||
sb = &w->old_vscroll2;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WWT_HSCROLLBAR:
|
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_SCROLL2;
|
||||||
w->flags4 |= WF_HSCROLL;
|
w->flags4 |= WF_HSCROLL;
|
||||||
pos = x;
|
pos = x;
|
||||||
sb = &w->old_hscroll;
|
|
||||||
rtl = _dynlang.text_dir == TD_RTL;
|
rtl = _dynlang.text_dir == TD_RTL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -123,7 +120,7 @@ static void ScrollbarClickPositioning(Window *w, WidgetType wtp, int x, int y, i
|
||||||
}
|
}
|
||||||
_left_button_clicked = false;
|
_left_button_clicked = false;
|
||||||
} else {
|
} else {
|
||||||
Point pt = HandleScrollbarHittest(sb, mi, ma, wtp == WWT_HSCROLLBAR);
|
Point pt = HandleScrollbarHittest(sb, mi, ma, nw->type == WWT_HSCROLLBAR);
|
||||||
|
|
||||||
if (pos < pt.x) {
|
if (pos < pt.x) {
|
||||||
sb->UpdatePosition(rtl ? sb->GetCapacity() : -sb->GetCapacity());
|
sb->UpdatePosition(rtl ? sb->GetCapacity() : -sb->GetCapacity());
|
||||||
|
@ -132,8 +129,7 @@ static void ScrollbarClickPositioning(Window *w, WidgetType wtp, int x, int y, i
|
||||||
} else {
|
} else {
|
||||||
_scrollbar_start_pos = pt.x - mi - 9;
|
_scrollbar_start_pos = pt.x - mi - 9;
|
||||||
_scrollbar_size = ma - mi - 23;
|
_scrollbar_size = ma - mi - 23;
|
||||||
w->flags4 |= WF_SCROLL_MIDDLE;
|
w->scrolling_scrollbar = nw->index;
|
||||||
_scrolling_scrollbar = true;
|
|
||||||
_cursorpos_drag_start = _cursor.pos;
|
_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 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.
|
||||||
*/
|
*/
|
||||||
void ScrollbarClickHandler(Window *w, const NWidgetCore *nw, int x, int y)
|
void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
|
||||||
{
|
{
|
||||||
int mi, ma;
|
int mi, ma;
|
||||||
|
|
||||||
|
@ -174,7 +170,7 @@ void ScrollbarClickHandler(Window *w, const NWidgetCore *nw, int x, int y)
|
||||||
|
|
||||||
default: NOT_REACHED();
|
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) {
|
switch (this->type) {
|
||||||
case WWT_HSCROLLBAR:
|
case WWT_HSCROLLBAR:
|
||||||
DrawHorizontalScrollbar(r, this->colour, (w->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL),
|
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));
|
(w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL), this->GetScrollbar(w));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WWT_SCROLLBAR:
|
case WWT_SCROLLBAR:
|
||||||
assert(this->widget_data == 0);
|
assert(this->widget_data == 0);
|
||||||
DrawVerticalScrollbar(r, this->colour, (w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP,
|
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));
|
(w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN, this->GetScrollbar(w));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WWT_SCROLL2BAR:
|
case WWT_SCROLL2BAR:
|
||||||
assert(this->widget_data == 0);
|
assert(this->widget_data == 0);
|
||||||
DrawVerticalScrollbar(r, this->colour, (w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2),
|
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));
|
(w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2), this->GetScrollbar(w));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,6 @@ int _scrollbar_start_pos;
|
||||||
int _scrollbar_size;
|
int _scrollbar_size;
|
||||||
byte _scroller_click_timeout;
|
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 _scrolling_viewport; ///< A viewport is being scrolled with the mouse.
|
||||||
bool _mouse_hovering; ///< The mouse is hovering over the same point.
|
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)
|
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;
|
WidgetType widget_type = (nw != NULL) ? nw->type : WWT_EMPTY;
|
||||||
|
|
||||||
bool focused_widget_changed = false;
|
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. */
|
/** 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()
|
static EventState HandleScrollbarScrolling()
|
||||||
{
|
{
|
||||||
Window *w;
|
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) {
|
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. */
|
/* Abort if no button is clicked any more. */
|
||||||
if (!_left_button_down) {
|
if (!_left_button_down) {
|
||||||
w->flags4 &= ~WF_SCROLL_MIDDLE;
|
w->scrolling_scrollbar = -1;
|
||||||
w->SetDirty();
|
w->SetDirty();
|
||||||
break;
|
return ES_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
Scrollbar *sb;
|
Scrollbar *sb = w->GetScrollbar(w->scrolling_scrollbar);
|
||||||
bool rtl = false;
|
bool rtl = false;
|
||||||
|
|
||||||
if (w->flags4 & WF_HSCROLL) {
|
if (w->flags4 & WF_HSCROLL) {
|
||||||
sb = &w->old_hscroll;
|
|
||||||
i = _cursor.pos.x - _cursorpos_drag_start.x;
|
i = _cursor.pos.x - _cursorpos_drag_start.x;
|
||||||
rtl = _dynlang.text_dir == TD_RTL;
|
rtl = _dynlang.text_dir == TD_RTL;
|
||||||
} else if (w->flags4 & WF_SCROLL2) {
|
} else if (w->flags4 & WF_SCROLL2) {
|
||||||
sb = &w->old_vscroll2;
|
|
||||||
i = _cursor.pos.y - _cursorpos_drag_start.y;
|
i = _cursor.pos.y - _cursorpos_drag_start.y;
|
||||||
} else {
|
} else {
|
||||||
sb = &w->old_vscroll;
|
|
||||||
i = _cursor.pos.y - _cursorpos_drag_start.y;
|
i = _cursor.pos.y - _cursorpos_drag_start.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1895,8 +1886,7 @@ static EventState HandleScrollbarScrolling()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_scrolling_scrollbar = false;
|
return ES_NOT_HANDLED;
|
||||||
return ES_HANDLED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -398,6 +398,8 @@ public:
|
||||||
NWidgetStacked *shade_select; ///< Selection widget (#NWID_SELECTION) to use for shading the window. If \c NULL, window cannot shade.
|
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).
|
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 *parent; ///< Parent window.
|
||||||
Window *z_front; ///< The window in front of us in z-order.
|
Window *z_front; ///< The window in front of us in z-order.
|
||||||
Window *z_back; ///< The window behind 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_DRAGGING = 1 << 3, ///< Window is being dragged
|
||||||
WF_SCROLL_UP = 1 << 4, ///< Upper scroll button has been pressed, @see ScrollbarClickHandler()
|
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_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_SCROLL2 = 1 << 7,
|
||||||
WF_HSCROLL = 1 << 8,
|
WF_HSCROLL = 1 << 8,
|
||||||
WF_SIZING_RIGHT = 1 << 9, ///< Window is being resized towards the right.
|
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 int _scrollbar_size;
|
||||||
extern byte _scroller_click_timeout;
|
extern byte _scroller_click_timeout;
|
||||||
|
|
||||||
extern bool _scrolling_scrollbar;
|
|
||||||
extern bool _scrolling_viewport;
|
extern bool _scrolling_viewport;
|
||||||
extern bool _mouse_hovering;
|
extern bool _mouse_hovering;
|
||||||
|
|
||||||
|
@ -951,6 +951,6 @@ Window *GetCallbackWnd();
|
||||||
void SetFocusedWindow(Window *w);
|
void SetFocusedWindow(Window *w);
|
||||||
bool EditBoxInGlobalFocus();
|
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 */
|
#endif /* WINDOW_GUI_H */
|
||||||
|
|
Loading…
Reference in New Issue