Changeset - r13616:40a45ed81e46
[Not reviewed]
master
0 2 0
rubidium - 15 years ago 2009-11-17 18:45:57
rubidium@openttd.org
(svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
2 files changed with 30 insertions and 20 deletions:
0 comments (0 inline, 0 general)
src/widget.cpp
Show inline comments
 
@@ -30,30 +30,35 @@ static const char *DOWNARROW = "\xEE\x8A
 
 * @param sb     Scrollbar list data
 
 * @param top    Top position of the scrollbar (top position of the up-button)
 
 * @param bottom Bottom position of the scrollbar (bottom position of the down-button)
 
 * @param horizontal Whether the scrollbar is horizontal or not
 
 * @return A Point, with x containing the top coordinate of the draggable part, and
 
 *                       y containing the bottom coordinate of the draggable part
 
 */
 
static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom)
 
static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom, bool horizontal)
 
{
 
	Point pt;
 
	int height, count, pos, cap;
 

	
 
	/* Base for reversion */
 
	int rev_base = top + bottom;
 
	top += 10;   // top    points to just below the up-button
 
	bottom -= 9; // bottom points to top of the down-button
 

	
 
	height = (bottom - top);
 

	
 
	pos = sb->GetPosition();
 
	count = sb->GetCount();
 
	cap = sb->GetCapacity();
 
	int height = (bottom - top);
 
	int pos = sb->GetPosition();
 
	int count = sb->GetCount();
 
	int cap = sb->GetCapacity();
 

	
 
	if (count != 0) top += height * pos / count;
 

	
 
	if (cap > count) cap = count;
 
	if (count != 0) bottom -= (count - pos - cap) * height / count;
 

	
 
	pt.x = top;
 
	pt.y = bottom - 1;
 
	Point pt;
 
	if (horizontal && _dynlang.text_dir == TD_RTL) {
 
		pt.x = rev_base - (bottom - 1);
 
		pt.y = rev_base - top;
 
	} else {
 
		pt.x = top;
 
		pt.y = bottom - 1;
 
	}
 
	return pt;
 
}
 

	
 
@@ -70,6 +75,7 @@ static void ScrollbarClickPositioning(Wi
 
{
 
	int pos;
 
	Scrollbar *sb;
 
	bool rtl = false;
 

	
 
	switch (wtp) {
 
		case WWT_SCROLLBAR:
 
@@ -88,12 +94,13 @@ static void ScrollbarClickPositioning(Wi
 
			sb = &w->vscroll2;
 
			break;
 

	
 
		case  WWT_HSCROLLBAR:
 
		case WWT_HSCROLLBAR:
 
			/* horizontal scroller */
 
			w->flags4 &= ~WF_SCROLL2;
 
			w->flags4 |= WF_HSCROLL;
 
			pos = x;
 
			sb = &w->hscroll;
 
			rtl = _dynlang.text_dir == TD_RTL;
 
			break;
 

	
 
		default: NOT_REACHED();
 
@@ -103,7 +110,7 @@ static void ScrollbarClickPositioning(Wi
 
		w->flags4 |= WF_SCROLL_UP;
 
		if (_scroller_click_timeout == 0) {
 
			_scroller_click_timeout = 6;
 
			sb->UpdatePosition(-1);
 
			sb->UpdatePosition(rtl ? 1 : -1);
 
		}
 
		_left_button_clicked = false;
 
	} else if (pos >= ma - 10) {
 
@@ -112,16 +119,16 @@ static void ScrollbarClickPositioning(Wi
 

	
 
		if (_scroller_click_timeout == 0) {
 
			_scroller_click_timeout = 6;
 
			sb->UpdatePosition(1);
 
			sb->UpdatePosition(rtl ? -1 : 1);
 
		}
 
		_left_button_clicked = false;
 
	} else {
 
		Point pt = HandleScrollbarHittest(sb, mi, ma);
 
		Point pt = HandleScrollbarHittest(sb, mi, ma, wtp == WWT_HSCROLLBAR);
 

	
 
		if (pos < pt.x) {
 
			sb->UpdatePosition(-sb->GetCapacity());
 
			sb->UpdatePosition(rtl ? sb->GetCapacity() : -sb->GetCapacity());
 
		} else if (pos > pt.y) {
 
			sb->UpdatePosition(sb->GetCapacity());
 
			sb->UpdatePosition(rtl ? -sb->GetCapacity() : sb->GetCapacity());
 
		} else {
 
			_scrollbar_start_pos = pt.x - mi - 9;
 
			_scrollbar_size = ma - mi - 23;
 
@@ -158,7 +165,7 @@ void ScrollbarClickHandler(Window *w, co
 
			ma = nw->pos_y + nw->current_y;
 
			break;
 

	
 
		case  WWT_HSCROLLBAR:
 
		case WWT_HSCROLLBAR:
 
			/* horizontal scroller */
 
			mi = nw->pos_x;
 
			ma = nw->pos_x + nw->current_x;
 
@@ -357,7 +364,7 @@ static inline void DrawVerticalScrollbar
 
	GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1);
 
	GfxFillRect(r.left + 8, r.top + 10, r.left + 8, r.bottom - 10, c2);
 

	
 
	Point pt = HandleScrollbarHittest(scrollbar, r.top, r.bottom);
 
	Point pt = HandleScrollbarHittest(scrollbar, r.top, r.bottom, false);
 
	DrawFrameRect(r.left, pt.x, r.right, pt.y, colour, bar_dragged ? FR_LOWERED : FR_NONE);
 
}
 

	
 
@@ -392,7 +399,7 @@ static inline void DrawHorizontalScrollb
 
	GfxFillRect(r.left + 10, r.top + 8, r.right - 10, r.top + 8, c2);
 

	
 
	/* draw actual scrollbar */
 
	Point pt = HandleScrollbarHittest(scrollbar, r.left, r.right);
 
	Point pt = HandleScrollbarHittest(scrollbar, r.left, r.right, true);
 
	DrawFrameRect(pt.x, r.top, pt.y, r.bottom, colour, bar_dragged ? FR_LOWERED : FR_NONE);
 
}
 

	
src/window.cpp
Show inline comments
 
@@ -1676,10 +1676,12 @@ static bool HandleScrollbarScrolling()
 

	
 
			int i;
 
			Scrollbar *sb;
 
			bool rtl = false;
 

	
 
			if (w->flags4 & WF_HSCROLL) {
 
				sb = &w->hscroll;
 
				i = _cursor.pos.x - _cursorpos_drag_start.x;
 
				rtl = _dynlang.text_dir == TD_RTL;
 
			} else if (w->flags4 & WF_SCROLL2) {
 
				sb = &w->vscroll2;
 
				i = _cursor.pos.y - _cursorpos_drag_start.y;
 
@@ -1690,6 +1692,7 @@ static bool HandleScrollbarScrolling()
 

	
 
			/* Find the item we want to move to and make sure it's inside bounds. */
 
			int pos = min(max(0, i + _scrollbar_start_pos) * sb->GetCount() / _scrollbar_size, max(0, sb->GetCount() - sb->GetCapacity()));
 
			if (rtl) pos = sb->GetCount() - sb->GetCapacity() - pos;
 
			if (pos != sb->GetPosition()) {
 
				sb->SetPosition(pos);
 
				w->SetDirty();
0 comments (0 inline, 0 general)