mirror of https://github.com/OpenTTD/OpenTTD
(svn r20460) -Codechange: Remove WF_SCROLL window flags and store the state directly in the scrollbar widget instead.
parent
6e9c9c28d9
commit
b37be47f16
|
@ -65,46 +65,26 @@ 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 nw Scrollbar
|
* @param sb 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, NWidgetScrollbar *nw, 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;
|
||||||
bool rtl = false;
|
bool rtl = false;
|
||||||
Scrollbar *sb = nw;
|
|
||||||
|
|
||||||
switch (nw->type) {
|
if (sb->type == WWT_HSCROLLBAR) {
|
||||||
case WWT_SCROLLBAR:
|
pos = x;
|
||||||
/* vertical scroller */
|
rtl = _dynlang.text_dir == TD_RTL;
|
||||||
w->flags4 &= ~WF_HSCROLL;
|
} else {
|
||||||
w->flags4 &= ~WF_SCROLL2;
|
pos = y;
|
||||||
pos = y;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WWT_SCROLL2BAR:
|
|
||||||
/* 2nd vertical scroller */
|
|
||||||
w->flags4 &= ~WF_HSCROLL;
|
|
||||||
w->flags4 |= WF_SCROLL2;
|
|
||||||
pos = y;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WWT_HSCROLLBAR:
|
|
||||||
/* horizontal scroller */
|
|
||||||
w->flags4 &= ~WF_SCROLL2;
|
|
||||||
w->flags4 |= WF_HSCROLL;
|
|
||||||
pos = x;
|
|
||||||
rtl = _dynlang.text_dir == TD_RTL;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: NOT_REACHED();
|
|
||||||
}
|
}
|
||||||
if (pos <= mi + 9) {
|
if (pos <= mi + 9) {
|
||||||
/* Pressing the upper button? */
|
/* Pressing the upper button? */
|
||||||
w->flags4 |= WF_SCROLL_UP;
|
SetBit(sb->disp_flags, NDB_SCROLLBAR_UP);
|
||||||
if (_scroller_click_timeout == 0) {
|
if (_scroller_click_timeout == 0) {
|
||||||
_scroller_click_timeout = 6;
|
_scroller_click_timeout = 6;
|
||||||
sb->UpdatePosition(rtl ? 1 : -1);
|
sb->UpdatePosition(rtl ? 1 : -1);
|
||||||
|
@ -112,7 +92,7 @@ static void ScrollbarClickPositioning(Window *w, NWidgetScrollbar *nw, int x, in
|
||||||
_left_button_clicked = false;
|
_left_button_clicked = false;
|
||||||
} else if (pos >= ma - 10) {
|
} else if (pos >= ma - 10) {
|
||||||
/* Pressing the lower button? */
|
/* Pressing the lower button? */
|
||||||
w->flags4 |= WF_SCROLL_DOWN;
|
SetBit(sb->disp_flags, NDB_SCROLLBAR_DOWN);
|
||||||
|
|
||||||
if (_scroller_click_timeout == 0) {
|
if (_scroller_click_timeout == 0) {
|
||||||
_scroller_click_timeout = 6;
|
_scroller_click_timeout = 6;
|
||||||
|
@ -120,7 +100,7 @@ static void ScrollbarClickPositioning(Window *w, NWidgetScrollbar *nw, int x, in
|
||||||
}
|
}
|
||||||
_left_button_clicked = false;
|
_left_button_clicked = false;
|
||||||
} else {
|
} else {
|
||||||
Point pt = HandleScrollbarHittest(sb, mi, ma, nw->type == WWT_HSCROLLBAR);
|
Point pt = HandleScrollbarHittest(sb, mi, ma, sb->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());
|
||||||
|
@ -129,7 +109,7 @@ static void ScrollbarClickPositioning(Window *w, NWidgetScrollbar *nw, int x, in
|
||||||
} 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->scrolling_scrollbar = nw->index;
|
w->scrolling_scrollbar = sb->index;
|
||||||
_cursorpos_drag_start = _cursor.pos;
|
_cursorpos_drag_start = _cursor.pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1718,28 +1698,14 @@ void NWidgetScrollbar::Draw(const Window *w)
|
||||||
const DrawPixelInfo *dpi = _cur_dpi;
|
const DrawPixelInfo *dpi = _cur_dpi;
|
||||||
if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top) return;
|
if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top) return;
|
||||||
|
|
||||||
switch (this->type) {
|
bool up_lowered = HasBit(this->disp_flags, NDB_SCROLLBAR_UP);
|
||||||
case WWT_HSCROLLBAR:
|
bool down_lowered = HasBit(this->disp_flags, NDB_SCROLLBAR_DOWN);
|
||||||
DrawHorizontalScrollbar(r, this->colour, (w->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL),
|
bool middle_lowered = (w->scrolling_scrollbar == this->index);
|
||||||
w->scrolling_scrollbar == this->index,
|
|
||||||
(w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL), this);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WWT_SCROLLBAR:
|
if (this->type == WWT_HSCROLLBAR) {
|
||||||
assert(this->widget_data == 0);
|
DrawHorizontalScrollbar(r, this->colour, up_lowered, middle_lowered, down_lowered, this);
|
||||||
DrawVerticalScrollbar(r, this->colour, (w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP,
|
} else {
|
||||||
w->scrolling_scrollbar == this->index,
|
DrawVerticalScrollbar(r, this->colour, up_lowered, middle_lowered, down_lowered, this);
|
||||||
(w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN, this);
|
|
||||||
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->scrolling_scrollbar == this->index,
|
|
||||||
(w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2), this);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: NOT_REACHED();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->IsDisabled()) {
|
if (this->IsDisabled()) {
|
||||||
|
|
|
@ -250,6 +250,9 @@ enum NWidgetDisplay {
|
||||||
NDB_SHADE_DIMMED = 4, ///< Display dimmed colours in the viewport.
|
NDB_SHADE_DIMMED = 4, ///< Display dimmed colours in the viewport.
|
||||||
/* Button dropdown widget. */
|
/* Button dropdown widget. */
|
||||||
NDB_DROPDOWN_ACTIVE = 5, ///< Dropdown menu of the button dropdown widget is active. @see #NWID_BUTTON_DRPDOWN
|
NDB_DROPDOWN_ACTIVE = 5, ///< Dropdown menu of the button dropdown widget is active. @see #NWID_BUTTON_DRPDOWN
|
||||||
|
/* Scrollbar widget. */
|
||||||
|
NDB_SCROLLBAR_UP = 6, ///< Up-button is lowered bit.
|
||||||
|
NDB_SCROLLBAR_DOWN = 7, ///< Down-button is lowered bit.
|
||||||
|
|
||||||
ND_LOWERED = 1 << NDB_LOWERED, ///< Bit value of the lowered flag.
|
ND_LOWERED = 1 << NDB_LOWERED, ///< Bit value of the lowered flag.
|
||||||
ND_DISABLED = 1 << NDB_DISABLED, ///< Bit value of the disabled flag.
|
ND_DISABLED = 1 << NDB_DISABLED, ///< Bit value of the disabled flag.
|
||||||
|
@ -257,6 +260,8 @@ enum NWidgetDisplay {
|
||||||
ND_SHADE_GREY = 1 << NDB_SHADE_GREY, ///< Bit value of the 'shade to grey' flag.
|
ND_SHADE_GREY = 1 << NDB_SHADE_GREY, ///< Bit value of the 'shade to grey' flag.
|
||||||
ND_SHADE_DIMMED = 1 << NDB_SHADE_DIMMED, ///< Bit value of the 'dimmed colours' flag.
|
ND_SHADE_DIMMED = 1 << NDB_SHADE_DIMMED, ///< Bit value of the 'dimmed colours' flag.
|
||||||
ND_DROPDOWN_ACTIVE = 1 << NDB_DROPDOWN_ACTIVE, ///< Bit value of the 'dropdown active' flag.
|
ND_DROPDOWN_ACTIVE = 1 << NDB_DROPDOWN_ACTIVE, ///< Bit value of the 'dropdown active' flag.
|
||||||
|
ND_SCROLLBAR_UP = 1 << NDB_SCROLLBAR_UP, ///< Bit value of the 'scrollbar up' flag.
|
||||||
|
ND_SCROLLBAR_DOWN = 1 << NDB_SCROLLBAR_DOWN, ///< Bit value of the 'scrollbar down' flag.
|
||||||
};
|
};
|
||||||
DECLARE_ENUM_AS_BIT_SET(NWidgetDisplay)
|
DECLARE_ENUM_AS_BIT_SET(NWidgetDisplay)
|
||||||
|
|
||||||
|
|
|
@ -1380,9 +1380,15 @@ static void DecreaseWindowCounters()
|
||||||
Window *w;
|
Window *w;
|
||||||
FOR_ALL_WINDOWS_FROM_FRONT(w) {
|
FOR_ALL_WINDOWS_FROM_FRONT(w) {
|
||||||
/* Unclick scrollbar buttons if they are pressed. */
|
/* Unclick scrollbar buttons if they are pressed. */
|
||||||
if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) {
|
for (uint i = 0; i < w->nested_array_size; i++) {
|
||||||
w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP);
|
NWidgetBase *nwid = w->nested_array[i];
|
||||||
w->SetDirty();
|
if (nwid != NULL && (nwid->type == WWT_HSCROLLBAR || nwid->type == WWT_SCROLLBAR || nwid->type == WWT_SCROLL2BAR)) {
|
||||||
|
NWidgetScrollbar *sb = static_cast<NWidgetScrollbar*>(nwid);
|
||||||
|
if (sb->disp_flags & (ND_SCROLLBAR_UP | ND_SCROLLBAR_DOWN)) {
|
||||||
|
sb->disp_flags &= ~(ND_SCROLLBAR_UP | ND_SCROLLBAR_DOWN);
|
||||||
|
sb->SetDirty(w);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
w->OnMouseLoop();
|
w->OnMouseLoop();
|
||||||
}
|
}
|
||||||
|
@ -1831,14 +1837,12 @@ static EventState HandleScrollbarScrolling()
|
||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
Scrollbar *sb = w->GetScrollbar(w->scrolling_scrollbar);
|
NWidgetScrollbar *sb = w->GetWidget<NWidgetScrollbar>(w->scrolling_scrollbar);
|
||||||
bool rtl = false;
|
bool rtl = false;
|
||||||
|
|
||||||
if (w->flags4 & WF_HSCROLL) {
|
if (sb->type == WWT_HSCROLLBAR) {
|
||||||
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) {
|
|
||||||
i = _cursor.pos.y - _cursorpos_drag_start.y;
|
|
||||||
} else {
|
} else {
|
||||||
i = _cursor.pos.y - _cursorpos_drag_start.y;
|
i = _cursor.pos.y - _cursorpos_drag_start.y;
|
||||||
}
|
}
|
||||||
|
|
|
@ -746,21 +746,17 @@ enum WindowFlags {
|
||||||
WF_TIMEOUT_BEGIN = 7, ///< The initial value for the timeout
|
WF_TIMEOUT_BEGIN = 7, ///< The initial value for the timeout
|
||||||
WF_TIMEOUT_MASK = 7, ///< Window timeout counter bit mask (3 bits)
|
WF_TIMEOUT_MASK = 7, ///< Window timeout counter bit mask (3 bits)
|
||||||
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_SIZING_RIGHT = 1 << 4, ///< Window is being resized towards the right.
|
||||||
WF_SCROLL_DOWN = 1 << 5, ///< Lower scroll button has been pressed, @see ScrollbarClickHandler()
|
WF_SIZING_LEFT = 1 << 5, ///< Window is being resized towards the left.
|
||||||
WF_SCROLL2 = 1 << 7,
|
|
||||||
WF_HSCROLL = 1 << 8,
|
|
||||||
WF_SIZING_RIGHT = 1 << 9, ///< Window is being resized towards the right.
|
|
||||||
WF_SIZING_LEFT = 1 << 10, ///< Window is being resized towards the left.
|
|
||||||
WF_SIZING = WF_SIZING_RIGHT | WF_SIZING_LEFT, ///< Window is being resized.
|
WF_SIZING = WF_SIZING_RIGHT | WF_SIZING_LEFT, ///< Window is being resized.
|
||||||
WF_STICKY = 1 << 11, ///< Window is made sticky by user
|
WF_STICKY = 1 << 6, ///< Window is made sticky by user
|
||||||
|
|
||||||
WF_DISABLE_VP_SCROLL = 1 << 12, ///< Window does not do autoscroll, @see HandleAutoscroll()
|
WF_DISABLE_VP_SCROLL = 1 << 7, ///< Window does not do autoscroll, @see HandleAutoscroll()
|
||||||
|
|
||||||
WF_WHITE_BORDER_ONE = 1 << 13,
|
WF_WHITE_BORDER_ONE = 1 << 8,
|
||||||
WF_WHITE_BORDER_MASK = 1 << 14 | WF_WHITE_BORDER_ONE,
|
WF_WHITE_BORDER_MASK = 1 << 9 | WF_WHITE_BORDER_ONE,
|
||||||
|
|
||||||
WF_CENTERED = 1 << 15, ///< Window is centered and shall stay centered after ReInit
|
WF_CENTERED = 1 << 10, ///< Window is centered and shall stay centered after ReInit
|
||||||
};
|
};
|
||||||
|
|
||||||
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number);
|
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number);
|
||||||
|
|
Loading…
Reference in New Issue