Changeset - r12873:1aca8aa0fea7
[Not reviewed]
master
0 5 0
rubidium - 15 years ago 2009-09-02 08:58:20
rubidium@openttd.org
(svn r17375) -Codechange: remove last direct usage of scrollbar variables
5 files changed with 20 insertions and 30 deletions:
0 comments (0 inline, 0 general)
src/order_gui.cpp
Show inline comments
 
@@ -1164,13 +1164,13 @@ public:
 
		this->widget[widnum].right = right;
 
	}
 

	
 
	virtual void OnResize(Point delta)
 
	{
 
		/* Update the scroll + matrix */
 
		this->vscroll.UpdateCapacity((this->widget[ORDER_WIDGET_ORDER_LIST].bottom - this->widget[ORDER_WIDGET_ORDER_LIST].top - 1) / ORDER_LIST_LINE_HEIGHT);
 
		this->vscroll.UpdateCapacity(delta.y / ORDER_LIST_LINE_HEIGHT);
 

	
 
		/* Update the button bars. */
 
		if (this->vehicle->owner == _local_company) {
 
			const int arrow_width = 12; // Space needed by the down arrow.
 

	
 
			/* ORDER_WIDGET_ORDER_LIST widget has the same left and right positions as the whole button bars. */
src/widget.cpp
Show inline comments
 
@@ -39,15 +39,15 @@ static Point HandleScrollbarHittest(cons
 

	
 
	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->pos;
 
	count = sb->count;
 
	cap = sb->cap;
 
	pos = sb->GetPosition();
 
	count = sb->GetCount();
 
	cap = sb->GetCapacity();
 

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

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

	
 
@@ -99,31 +99,31 @@ static void ScrollbarClickPositioning(Wi
 
	}
 
	if (pos <= mi + 9) {
 
		/* Pressing the upper button? */
 
		w->flags4 |= WF_SCROLL_UP;
 
		if (_scroller_click_timeout == 0) {
 
			_scroller_click_timeout = 6;
 
			if (sb->pos != 0) sb->pos--;
 
			sb->UpdatePosition(-1);
 
		}
 
		_left_button_clicked = false;
 
	} else if (pos >= ma - 10) {
 
		/* Pressing the lower button? */
 
		w->flags4 |= WF_SCROLL_DOWN;
 

	
 
		if (_scroller_click_timeout == 0) {
 
			_scroller_click_timeout = 6;
 
			if (sb->pos + sb->cap < sb->count) sb->pos++;
 
			sb->UpdatePosition(1);
 
		}
 
		_left_button_clicked = false;
 
	} else {
 
		Point pt = HandleScrollbarHittest(sb, mi, ma);
 

	
 
		if (pos < pt.x) {
 
			sb->pos = max(sb->pos - sb->cap, 0);
 
			sb->UpdatePosition(-sb->GetCapacity());
 
		} else if (pos > pt.y) {
 
			sb->pos = min(sb->pos + sb->cap, max(sb->count - sb->cap, 0));
 
			sb->UpdatePosition(sb->GetCapacity());
 
		} else {
 
			_scrollbar_start_pos = pt.x - mi - 9;
 
			_scrollbar_size = ma - mi - 23;
 
			w->flags4 |= WF_SCROLL_MIDDLE;
 
			_scrolling_scrollbar = true;
 
			_cursorpos_drag_start = _cursor.pos;
src/widgets/dropdown.cpp
Show inline comments
 
@@ -113,13 +113,13 @@ struct DropdownWindow : Window {
 
	bool GetDropDownItem(int &value)
 
	{
 
		if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0) return false;
 

	
 
		int y     = _cursor.pos.y - this->top - 2;
 
		int width = this->widget[0].right - 3;
 
		int pos   = this->vscroll.pos;
 
		int pos   = this->vscroll.GetPosition();
 

	
 
		const DropDownList *list = this->list;
 

	
 
		for (DropDownList::const_iterator it = list->begin(); it != list->end(); ++it) {
 
			/* Skip items that are scrolled up */
 
			if (--pos >= 0) continue;
 
@@ -147,13 +147,13 @@ struct DropdownWindow : Window {
 
		int y = 2;
 

	
 
		int sel    = this->selected_index;
 
		int width  = this->widget[0].right - 2;
 
		int right  = this->widget[0].right;
 
		int bottom = this->widget[0].bottom;
 
		int pos    = this->vscroll.pos;
 
		int pos    = this->vscroll.GetPosition();
 

	
 
		DropDownList *list = this->list;
 

	
 
		for (DropDownList::const_iterator it = list->begin(); it != list->end(); ++it) {
 
			const DropDownListItem *item = *it;
 
			int item_height = item->Height(width);
 
@@ -186,20 +186,13 @@ struct DropdownWindow : Window {
 
			this->SetDirty();
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	{
 
		if (this->scrolling == -1) {
 
			this->vscroll.pos = max(0, this->vscroll.pos - 1);
 
			this->SetDirty();
 
		} else if (this->scrolling == 1) {
 
			this->vscroll.pos = min(this->vscroll.count - this->vscroll.cap, this->vscroll.pos + 1);
 
			this->SetDirty();
 
		}
 
		this->scrolling = 0;
 
		this->vscroll.UpdatePosition(this->scrolling);
 
	}
 

	
 
	virtual void OnMouseLoop()
 
	{
 
		Window *w2 = FindWindowById(this->parent_wnd_class, this->parent_wnd_num);
 
		if (w2 == NULL) {
 
@@ -351,14 +344,14 @@ void ShowDropDownList(Window *w, DropDow
 
		dw->widget[1].right  = dw->widget[0].right;
 
		dw->widget[1].left   = dw->widget[1].right - 11;
 
		dw->widget[1].bottom = dw->widget[0].bottom;
 
		dw->widget[0].right -= 12;
 

	
 
		/* Capacity is the average number of items visible */
 
		dw->vscroll.cap   = height * (uint16)list->size() / list_height;
 
		dw->vscroll.count = (uint16)list->size();
 
		dw->vscroll.SetCapacity(height * (uint16)list->size() / list_height);
 
		dw->vscroll.SetCount((uint16)list->size());
 
	}
 

	
 
	dw->desc_flags = WDF_DEF_WIDGET;
 
	dw->flags4 &= ~WF_WHITE_BORDER_MASK;
 

	
 
	dw->parent_wnd_class = w->window_class;
src/window.cpp
Show inline comments
 
@@ -449,18 +449,15 @@ static void DispatchMouseWheelEvent(Wind
 
			sb = &w->vscroll2;
 
		}
 
	}
 

	
 
	if (w->nested_array != NULL && (uint)widget < w->nested_array_size) sb = w->nested_array[widget]->FindScrollbar(w);
 

	
 
	if (sb != NULL && sb->count > sb->cap) {
 
		int pos = Clamp(sb->pos + wheel, 0, sb->count - sb->cap);
 
		if (pos != sb->pos) {
 
			sb->pos = pos;
 
			w->SetDirty();
 
		}
 
	if (sb != NULL && sb->GetCount() > sb->GetCapacity()) {
 
		sb->UpdatePosition(wheel);
 
		w->SetDirty();
 
	}
 
}
 

	
 
/**
 
 * Generate repaint events for the visible part of window w within the rectangle.
 
 *
 
@@ -1883,15 +1880,15 @@ static bool HandleScrollbarScrolling()
 
			} else {
 
				sb = &w->vscroll;
 
				i = _cursor.pos.y - _cursorpos_drag_start.y;
 
			}
 

	
 
			/* 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->count / _scrollbar_size, max(0, sb->count - sb->cap));
 
			if (pos != sb->pos) {
 
				sb->pos = pos;
 
			int pos = min(max(0, i + _scrollbar_start_pos) * sb->GetCount() / _scrollbar_size, max(0, sb->GetCount() - sb->GetCapacity()));
 
			if (pos != sb->GetPosition()) {
 
				sb->SetPosition(pos);
 
				w->SetDirty();
 
			}
 
			return false;
 
		}
 
	}
 

	
src/window_gui.h
Show inline comments
 
@@ -182,13 +182,13 @@ enum WindowDefaultPosition {
 
};
 

	
 
/**
 
 * Scrollbar data structure
 
 */
 
class Scrollbar {
 
public: // To become private
 
private:
 
	uint16 count;  ///< Number of elements in the list
 
	uint16 cap;    ///< Number of visible elements of the scroll bar
 
	uint16 pos;    ///< Index of first visible item of the list
 
public:
 
	/**
 
	 * Gets the number of elements in the list
0 comments (0 inline, 0 general)