Changeset - r12870:17e036c83760
[Not reviewed]
master
0 3 0
rubidium - 15 years ago 2009-09-02 08:28:50
rubidium@openttd.org
(svn r17372) -Codechange: make the settings, rail and sign GUIs use the scrollbar wrappers
3 files changed with 32 insertions and 34 deletions:
0 comments (0 inline, 0 general)
src/rail_gui.cpp
Show inline comments
 
@@ -1021,15 +1021,15 @@ public:
 

	
 
		_railstation.newstations = newstation;
 

	
 
		if (newstation) {
 
			_railstation.station_count = GetNumCustomStations(_railstation.station_class);
 

	
 
			this->vscroll.count = _railstation.station_count;
 
			this->vscroll.cap   = GB(this->nested_array[BRSW_NEWST_LIST]->widget_data, MAT_ROW_START, MAT_ROW_BITS);
 
			this->vscroll.pos   = Clamp(_railstation.station_type - 2, 0, this->vscroll.count - this->vscroll.cap);
 
			this->vscroll.SetCount(_railstation.station_count);
 
			this->vscroll.SetCapacity(GB(this->nested_array[BRSW_NEWST_LIST]->widget_data, MAT_ROW_START, MAT_ROW_BITS));
 
			this->vscroll.SetPosition(Clamp(_railstation.station_type - 2, 0, this->vscroll.GetCount() - this->vscroll.GetCapacity()));
 
		} else {
 
			/* New stations are not available, so ensure the default station
 
			 * type is 'selected'. */
 
			_railstation.station_class = STAT_CLASS_DFLT;
 
			_railstation.station_type = 0;
 
		}
 
@@ -1147,13 +1147,13 @@ public:
 
					_cur_dpi = old_dpi;
 
				}
 
				break;
 

	
 
			case BRSW_NEWST_LIST: {
 
				uint y = r.top;
 
				for (uint16 i = this->vscroll.pos; i < _railstation.station_count && i < (uint)(this->vscroll.pos + this->vscroll.cap); i++) {
 
				for (uint16 i = this->vscroll.GetPosition(); i < _railstation.station_count && this->vscroll.IsVisible(i); i++) {
 
					const StationSpec *statspec = GetCustomStationSpec(_railstation.station_class, i);
 

	
 
					StringID str = STR_STATION_CLASS_DFLT;
 
					if (statspec != NULL && statspec->name != 0) {
 
						if (HasBit(statspec->callbackmask, CBM_STATION_AVAIL) && GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) {
 
							GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->line_height - 2, 0, FILLRECT_CHECKER);
 
@@ -1305,14 +1305,14 @@ public:
 
				break;
 

	
 
			case BRSW_NEWST_LIST: {
 
				const StationSpec *statspec;
 
				int y = (pt.y - this->nested_array[BRSW_NEWST_LIST]->pos_y) / this->line_height;
 

	
 
				if (y >= this->vscroll.cap) return;
 
				y += this->vscroll.pos;
 
				if (y >= this->vscroll.GetCapacity()) return;
 
				y += this->vscroll.GetPosition();
 
				if (y >= _railstation.station_count) return;
 

	
 
				/* Check station availability callback */
 
				statspec = GetCustomStationSpec(_railstation.station_class, y);
 
				if (statspec != NULL &&
 
					HasBit(statspec->callbackmask, CBM_STATION_AVAIL) &&
 
@@ -1336,14 +1336,14 @@ public:
 
			_railstation.station_class = (StationClassID)index;
 
			_railstation.station_type  = 0;
 
			_railstation.station_count = GetNumCustomStations(_railstation.station_class);
 

	
 
			this->CheckSelectedSize(GetCustomStationSpec(_railstation.station_class, _railstation.station_type));
 

	
 
			this->vscroll.count = _railstation.station_count;
 
			this->vscroll.pos   = _railstation.station_type;
 
			this->vscroll.SetCount(_railstation.station_count);
 
			this->vscroll.SetPosition(_railstation.station_type);
 
		}
 

	
 
		SndPlayFx(SND_15_BEEP);
 
		this->SetDirty();
 
		DeleteWindowById(WC_SELECT_STATION, 0);
 
	}
 
@@ -1772,30 +1772,30 @@ enum BuildRailWaypointWidgets {
 
};
 

	
 
struct BuildRailWaypointWindow : PickerWindowBase {
 
	BuildRailWaypointWindow(const WindowDesc *desc, Window *parent) : PickerWindowBase(parent)
 
	{
 
		this->InitNested(desc, TRANSPORT_RAIL);
 
		this->hscroll.cap = 5;
 
		this->hscroll.count = _waypoint_count;
 
		this->hscroll.SetCapacity(5);
 
		this->hscroll.SetCount(_waypoint_count);
 
	};
 

	
 
	virtual void OnPaint()
 
	{
 
		for (uint i = 0; i < this->hscroll.cap; i++) {
 
			this->SetWidgetLoweredState(i + BRWW_WAYPOINT_1, (this->hscroll.pos + i) == _cur_waypoint_type);
 
		for (uint i = 0; i < this->hscroll.GetCapacity(); i++) {
 
			this->SetWidgetLoweredState(i + BRWW_WAYPOINT_1, (this->hscroll.GetPosition() + i) == _cur_waypoint_type);
 
		}
 

	
 
		this->DrawWidgets();
 

	
 
		for (uint i = 0; i < this->hscroll.cap; i++) {
 
			if (this->hscroll.pos + i < this->hscroll.count) {
 
				const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, this->hscroll.pos + i);
 
		for (uint i = 0; i < this->hscroll.GetCapacity(); i++) {
 
			if (this->hscroll.GetPosition() + i < this->hscroll.GetCount()) {
 
				const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, this->hscroll.GetPosition() + i);
 

	
 
				int bottom = this->nested_array[BRWW_WAYPOINT_1 + i]->pos_y + this->nested_array[BRWW_WAYPOINT_1 + i]->current_y;
 
				DrawWaypointSprite(this->nested_array[BRWW_WAYPOINT_1 + i]->pos_x + TILE_PIXELS, bottom - TILE_PIXELS, this->hscroll.pos + i, _cur_railtype);
 
				DrawWaypointSprite(this->nested_array[BRWW_WAYPOINT_1 + i]->pos_x + TILE_PIXELS, bottom - TILE_PIXELS, this->hscroll.GetPosition() + i, _cur_railtype);
 

	
 
				if (statspec != NULL &&
 
						HasBit(statspec->callbackmask, CBM_STATION_AVAIL) &&
 
						GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) {
 
					GfxFillRect(4 + i * 68, 18, 67 + i * 68, 75, 0, FILLRECT_CHECKER);
 
				}
 
@@ -1808,13 +1808,13 @@ struct BuildRailWaypointWindow : PickerW
 
		switch (widget) {
 
			case BRWW_WAYPOINT_1:
 
			case BRWW_WAYPOINT_2:
 
			case BRWW_WAYPOINT_3:
 
			case BRWW_WAYPOINT_4:
 
			case BRWW_WAYPOINT_5: {
 
				byte type = widget - BRWW_WAYPOINT_1 + this->hscroll.pos;
 
				byte type = widget - BRWW_WAYPOINT_1 + this->hscroll.GetPosition();
 

	
 
				/* Check station availability callback */
 
				const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, type);
 
				if (statspec != NULL &&
 
						HasBit(statspec->callbackmask, CBM_STATION_AVAIL) &&
 
						GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) return;
src/settings_gui.cpp
Show inline comments
 
@@ -1445,15 +1445,14 @@ struct GameSettingsWindow : Window {
 
		} else {
 
			_settings_main_page.FoldAll(); // Close all sub-pages
 
		}
 

	
 
		this->valuewindow_entry = NULL; // No setting entry for which a entry window is opened
 
		this->clicked_entry = NULL; // No numeric setting buttons are depressed
 
		this->vscroll.pos = 0;
 
		this->vscroll.cap = (this->widget[SETTINGSEL_OPTIONSPANEL].bottom - this->widget[SETTINGSEL_OPTIONSPANEL].top - 8) / SETTING_HEIGHT;
 
		SetVScrollCount(this, _settings_main_page.Length());
 
		this->vscroll.SetCapacity((this->widget[SETTINGSEL_OPTIONSPANEL].bottom - this->widget[SETTINGSEL_OPTIONSPANEL].top - 8) / SETTING_HEIGHT);
 
		this->vscroll.SetCount(_settings_main_page.Length());
 

	
 
		this->resize.step_height = SETTING_HEIGHT;
 
		this->resize.height = this->height;
 
		this->resize.step_width = 1;
 
		this->resize.width = this->width;
 

	
 
@@ -1461,23 +1460,23 @@ struct GameSettingsWindow : Window {
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		this->DrawWidgets();
 
		_settings_main_page.Draw(settings_ptr, SETTINGTREE_LEFT_OFFSET, SETTINGTREE_TOP_OFFSET,
 
				this->width - 13, this->vscroll.pos, this->vscroll.pos + this->vscroll.cap);
 
				this->width - 13, this->vscroll.GetPosition(), this->vscroll.GetPosition() + this->vscroll.GetCapacity());
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		if (widget != SETTINGSEL_OPTIONSPANEL) return;
 

	
 
		int y = pt.y - SETTINGTREE_TOP_OFFSET;  // Shift y coordinate
 
		if (y < 0) return;  // Clicked above first entry
 

	
 
		byte btn = this->vscroll.pos + y / SETTING_HEIGHT;  // Compute which setting is selected
 
		byte btn = this->vscroll.GetPosition() + y / SETTING_HEIGHT;  // Compute which setting is selected
 
		if (y % SETTING_HEIGHT > SETTING_HEIGHT - 2) return;  // Clicked too low at the setting
 

	
 
		uint cur_row = 0;
 
		SettingEntry *pe = _settings_main_page.FindEntry(btn, &cur_row);
 

	
 
		if (pe == NULL) return;  // Clicked below the last setting of the page
 
@@ -1485,13 +1484,13 @@ struct GameSettingsWindow : Window {
 
		int x = pt.x - SETTINGTREE_LEFT_OFFSET - (pe->level + 1) * LEVEL_WIDTH;  // Shift x coordinate
 
		if (x < 0) return;  // Clicked left of the entry
 

	
 
		if ((pe->flags & SEF_KIND_MASK) == SEF_SUBTREE_KIND) {
 
			pe->d.sub.folded = !pe->d.sub.folded; // Flip 'folded'-ness of the sub-page
 

	
 
			SetVScrollCount(this, _settings_main_page.Length());
 
			this->vscroll.SetCount(_settings_main_page.Length());
 
			this->SetDirty();
 
			return;
 
		}
 

	
 
		assert((pe->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
 
		const SettingDesc *sd = pe->d.entry.setting;
 
@@ -1605,14 +1604,13 @@ struct GameSettingsWindow : Window {
 
			this->SetDirty();
 
		}
 
	}
 

	
 
	virtual void OnResize(Point delta)
 
	{
 
		this->vscroll.cap += delta.y / SETTING_HEIGHT;
 
		SetVScrollCount(this, _settings_main_page.Length());
 
		this->vscroll.UpdateCapacity(delta.y / SETTING_HEIGHT);
 
	}
 
};
 

	
 
GameSettings *GameSettingsWindow::settings_ptr = NULL;
 
const int GameSettingsWindow::SETTINGTREE_LEFT_OFFSET = 5;
 
const int GameSettingsWindow::SETTINGTREE_TOP_OFFSET = 19;
src/signs_gui.cpp
Show inline comments
 
@@ -87,13 +87,13 @@ enum SignListWidgets {
 
	SLW_RESIZE,
 
};
 

	
 
struct SignListWindow : Window, SignList {
 
	SignListWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
 
	{
 
		this->vscroll.cap = 12;
 
		this->vscroll.SetCapacity(12);
 
		this->resize.step_height = 10;
 
		this->resize.height = this->height - 10 * 7; // minimum if 5 in the list
 

	
 
		this->signs.ForceRebuild();
 
		this->signs.NeedResort();
 

	
 
@@ -102,26 +102,26 @@ struct SignListWindow : Window, SignList
 

	
 
	virtual void OnPaint()
 
	{
 
		BuildSignsList();
 
		SortSignsList();
 

	
 
		SetVScrollCount(this, this->signs.Length());
 
		this->vscroll.SetCount(this->signs.Length()); // Update the scrollbar
 

	
 
		SetDParam(0, this->vscroll.count);
 
		SetDParam(0, this->vscroll.GetCount());
 
		this->DrawWidgets();
 

	
 
		/* No signs? */
 
		int y = this->widget[SLW_LIST].top + 2; // offset from top of widget
 
		if (this->vscroll.count == 0) {
 
		if (this->vscroll.GetCount() == 0) {
 
			DrawString(this->widget[SLW_LIST].left + 2, this->widget[SLW_LIST].right, y, STR_STATION_LIST_NONE);
 
			return;
 
		}
 

	
 
		/* Start drawing the signs */
 
		for (uint16 i = this->vscroll.pos; i < this->vscroll.cap + this->vscroll.pos && i < this->vscroll.count; i++) {
 
		for (uint16 i = this->vscroll.GetPosition(); this->vscroll.IsVisible(i) && i < this->vscroll.GetCount(); i++) {
 
			const Sign *si = this->signs[i];
 

	
 
			if (si->owner != OWNER_NONE) DrawCompanyIcon(si->owner, this->widget[SLW_LIST].left + 4, y + 1);
 

	
 
			SetDParam(0, si->index);
 
			DrawString(this->widget[SLW_LIST].left + 22, this->widget[SLW_LIST].right, y, STR_SIGN_NAME, TC_YELLOW);
 
@@ -131,24 +131,24 @@ struct SignListWindow : Window, SignList
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		if (widget == SLW_LIST) {
 
			uint32 id_v = (pt.y - this->widget[SLW_LIST].top - 1) / 10;
 

	
 
			if (id_v >= this->vscroll.cap) return;
 
			id_v += this->vscroll.pos;
 
			if (id_v >= this->vscroll.count) return;
 
			if (id_v >= this->vscroll.GetCapacity()) return;
 
			id_v += this->vscroll.GetPosition();
 
			if (id_v >= this->vscroll.GetCount()) return;
 

	
 
			const Sign *si = this->signs[id_v];
 
			ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
 
		}
 
	}
 

	
 
	virtual void OnResize(Point delta)
 
	{
 
		this->vscroll.cap += delta.y / 10;
 
		this->vscroll.UpdateCapacity(delta.y / 10);
 
	}
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		if (data == 0) {
 
			this->signs.ForceRebuild();
0 comments (0 inline, 0 general)