Changeset - r15769:4a935f419828
[Not reviewed]
master
0 28 0
frosch - 14 years ago 2010-08-12 08:37:01
frosch@openttd.org
(svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
Note: All windows get individual members with the same names, which are initialised via Window::GetScrollbar(). This caching is not required at all, but simplifies conversion.
28 files changed with 466 insertions and 340 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_gui.cpp
Show inline comments
 
@@ -49,21 +49,24 @@ enum AIListWindowWidgets {
 
 */
 
struct AIListWindow : public Window {
 
	const AIInfoList *ai_info_list;
 
	int selected;
 
	CompanyID slot;
 
	int line_height; // Height of a row in the matrix widget.
 
	Scrollbar *vscroll;
 

	
 
	AIListWindow(const WindowDesc *desc, CompanyID slot) : Window(),
 
		slot(slot)
 
	{
 
		this->ai_info_list = AI::GetUniqueInfoList();
 

	
 
		this->InitNested(desc); // Initializes 'this->line_height' as side effect.
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(AIL_WIDGET_SCROLLBAR);
 
		this->FinishInitNested(desc); // Initializes 'this->line_height' as side effect.
 

	
 
		this->vscroll.SetCount((int)this->ai_info_list->size() + 1);
 
		this->vscroll->SetCount((int)this->ai_info_list->size() + 1);
 

	
 
		/* Try if we can find the currently selected AI */
 
		this->selected = -1;
 
		if (AIConfig::GetConfig(slot)->HasAI()) {
 
			AIInfo *info = AIConfig::GetConfig(slot)->GetInfo();
 
			int i = 0;
 
@@ -96,19 +99,19 @@ struct AIListWindow : public Window {
 
	{
 
		switch (widget) {
 
			case AIL_WIDGET_LIST: {
 
				/* Draw a list of all available AIs. */
 
				int y = this->GetWidget<NWidgetBase>(AIL_WIDGET_LIST)->pos_y;
 
				/* First AI in the list is hardcoded to random */
 
				if (this->vscroll.IsVisible(0)) {
 
				if (this->vscroll->IsVisible(0)) {
 
					DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_LEFT, y + WD_MATRIX_TOP, STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TC_WHITE : TC_BLACK);
 
					y += this->line_height;
 
				}
 
				AIInfoList::const_iterator it = this->ai_info_list->begin();
 
				for (int i = 1; it != this->ai_info_list->end(); i++, it++) {
 
					if (this->vscroll.IsVisible(i)) {
 
					if (this->vscroll->IsVisible(i)) {
 
						DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, (*it).second->GetName(), (this->selected == i - 1) ? TC_WHITE : TC_BLACK);
 
						y += this->line_height;
 
					}
 
				}
 
				break;
 
			}
 
@@ -153,13 +156,13 @@ struct AIListWindow : public Window {
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		switch (widget) {
 
			case AIL_WIDGET_LIST: { // Select one of the AIs
 
				int sel = this->vscroll.GetScrolledRowFromWidget(pt.y, this, AIL_WIDGET_LIST, 0, this->line_height) - 1;
 
				int sel = this->vscroll->GetScrolledRowFromWidget(pt.y, this, AIL_WIDGET_LIST, 0, this->line_height) - 1;
 
				if (sel < (int)this->ai_info_list->size()) {
 
					this->selected = sel;
 
					this->SetDirty();
 
					if (click_count > 1) {
 
						this->ChangeAI();
 
						delete this;
 
@@ -180,14 +183,14 @@ struct AIListWindow : public Window {
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(AIL_WIDGET_LIST);
 
		this->vscroll.SetCapacity(nwi->current_y / this->line_height);
 
		nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		this->vscroll->SetCapacity(nwi->current_y / this->line_height);
 
		nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 
};
 

	
 
/** Widgets for the AI list window. */
 
static const NWidgetPart _nested_ai_list_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
@@ -243,25 +246,28 @@ struct AISettingsWindow : public Window 
 
	AIConfig *ai_config;
 
	int clicked_button;
 
	bool clicked_increase;
 
	int timeout;
 
	int clicked_row;
 
	int line_height; // Height of a row in the matrix widget.
 
	Scrollbar *vscroll;
 

	
 
	AISettingsWindow(const WindowDesc *desc, CompanyID slot) : Window(),
 
		slot(slot),
 
		clicked_button(-1),
 
		timeout(0)
 
	{
 
		this->ai_config = AIConfig::GetConfig(slot);
 

	
 
		this->InitNested(desc, slot);  // Initializes 'this->line_height' as side effect.
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(AIS_WIDGET_SCROLLBAR);
 
		this->FinishInitNested(desc, slot);  // Initializes 'this->line_height' as side effect.
 

	
 
		this->SetWidgetDisabledState(AIS_WIDGET_RESET, _game_mode != GM_MENU);
 

	
 
		this->vscroll.SetCount((int)this->ai_config->GetConfigList()->size());
 
		this->vscroll->SetCount((int)this->ai_config->GetConfigList()->size());
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		if (widget == AIS_WIDGET_BACKGROUND) {
 
			this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
 
@@ -281,24 +287,24 @@ struct AISettingsWindow : public Window 
 
	{
 
		if (widget != AIS_WIDGET_BACKGROUND) return;
 

	
 
		AIConfig *config = this->ai_config;
 
		AIConfigItemList::const_iterator it = config->GetConfigList()->begin();
 
		int i = 0;
 
		for (; !this->vscroll.IsVisible(i); i++) it++;
 
		for (; !this->vscroll->IsVisible(i); i++) it++;
 

	
 
		bool rtl = _dynlang.text_dir == TD_RTL;
 
		uint buttons_left = rtl ? r.right - 23 : r.left + 4;
 
		uint value_left   = r.left + (rtl ? WD_FRAMERECT_LEFT : 28);
 
		uint value_right  = r.right - (rtl ? 28 : WD_FRAMERECT_RIGHT);
 
		uint text_left    = r.left + (rtl ? WD_FRAMERECT_LEFT : 54);
 
		uint text_right   = r.right - (rtl ? 54 : WD_FRAMERECT_RIGHT);
 

	
 

	
 
		int y = r.top;
 
		for (; this->vscroll.IsVisible(i) && it != config->GetConfigList()->end(); i++, it++) {
 
		for (; this->vscroll->IsVisible(i) && it != config->GetConfigList()->end(); i++, it++) {
 
			int current_value = config->GetSetting((*it).name);
 
			bool editable = (_game_mode == GM_MENU) || ((it->flags & AICONFIG_INGAME) != 0);
 

	
 
			uint x = rtl ? r.right : r.left;
 
			if (((*it).flags & AICONFIG_BOOLEAN) != 0) {
 
				DrawFrameRect(buttons_left, y  + 2, buttons_left + 19, y + 10, (current_value != 0) ? COLOUR_GREEN : COLOUR_RED, (current_value != 0) ? FR_LOWERED : FR_NONE);
 
@@ -331,13 +337,13 @@ struct AISettingsWindow : public Window 
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		switch (widget) {
 
			case AIS_WIDGET_BACKGROUND: {
 
				const NWidgetBase *wid = this->GetWidget<NWidgetBase>(AIS_WIDGET_BACKGROUND);
 
				int num = (pt.y - wid->pos_y) / this->line_height + this->vscroll.GetPosition();
 
				int num = (pt.y - wid->pos_y) / this->line_height + this->vscroll->GetPosition();
 
				if (num >= (int)this->ai_config->GetConfigList()->size()) break;
 

	
 
				AIConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
 
				for (int i = 0; i < num; i++) it++;
 
				AIConfigItem config_item = *it;
 
				if (_game_mode != GM_MENU && (config_item.flags & AICONFIG_INGAME) == 0) return;
 
@@ -402,14 +408,14 @@ struct AISettingsWindow : public Window 
 
		this->SetDirty();
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(AIS_WIDGET_BACKGROUND);
 
		this->vscroll.SetCapacity(nwi->current_y / this->line_height);
 
		nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		this->vscroll->SetCapacity(nwi->current_y / this->line_height);
 
		nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 

	
 
	virtual void OnTick()
 
	{
 
		if (--this->timeout == 0) {
 
			this->clicked_button = -1;
 
@@ -516,21 +522,23 @@ static const WindowDesc _ai_config_desc(
 
/**
 
 * Window to configure which AIs will start.
 
 */
 
struct AIConfigWindow : public Window {
 
	CompanyID selected_slot; ///< The currently selected AI slot or \c INVALID_COMPANY.
 
	int line_height;         ///< Height of a single AI-name line.
 
	Scrollbar *vscroll;
 

	
 
	AIConfigWindow() : Window()
 
	{
 
		this->InitNested(&_ai_config_desc); // Initializes 'this->line_height' as a side effect.
 
		this->vscroll = this->GetScrollbar(AIC_WIDGET_SCROLLBAR);
 
		this->selected_slot = INVALID_COMPANY;
 
		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(AIC_WIDGET_LIST);
 
		this->vscroll.SetCapacity(nwi->current_y / this->line_height);
 
		this->vscroll.SetCount(MAX_COMPANIES);
 
		nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		this->vscroll->SetCapacity(nwi->current_y / this->line_height);
 
		this->vscroll->SetCount(MAX_COMPANIES);
 
		nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		this->OnInvalidateData(0);
 
	}
 

	
 
	~AIConfigWindow()
 
	{
 
		DeleteWindowByClass(WC_AI_LIST);
 
@@ -563,13 +571,13 @@ struct AIConfigWindow : public Window {
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		switch (widget) {
 
			case AIC_WIDGET_LIST: {
 
				int y = r.top;
 
				for (int i = this->vscroll.GetPosition(); this->vscroll.IsVisible(i) && i < MAX_COMPANIES; i++) {
 
				for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) {
 
					StringID text;
 

	
 
					if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != NULL) {
 
						SetDParamStr(0, AIConfig::GetConfig((CompanyID)i)->GetInfo()->GetName());
 
						text = STR_JUST_RAW_STRING;
 
					} else if (i == 0) {
 
@@ -600,32 +608,32 @@ struct AIConfigWindow : public Window {
 
				IConsoleSetSetting("difficulty.max_no_competitors", new_value);
 
				this->InvalidateData();
 
				break;
 
			}
 

	
 
			case AIC_WIDGET_LIST: { // Select a slot
 
				this->selected_slot = (CompanyID)this->vscroll.GetScrolledRowFromWidget(pt.y, this, widget, 0, this->line_height);
 
				this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget, 0, this->line_height);
 
				this->InvalidateData();
 
				if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowAIListWindow((CompanyID)this->selected_slot);
 
				break;
 
			}
 

	
 
			case AIC_WIDGET_MOVE_UP:
 
				if (this->selected_slot > 1) {
 
					Swap(_settings_newgame.ai_config[this->selected_slot], _settings_newgame.ai_config[this->selected_slot - 1]);
 
					this->selected_slot--;
 
					this->vscroll.ScrollTowards(this->selected_slot);
 
					this->vscroll->ScrollTowards(this->selected_slot);
 
					this->InvalidateData();
 
				}
 
				break;
 

	
 
			case AIC_WIDGET_MOVE_DOWN:
 
				if (this->selected_slot < _settings_newgame.difficulty.max_no_competitors) {
 
					Swap(_settings_newgame.ai_config[this->selected_slot], _settings_newgame.ai_config[this->selected_slot + 1]);
 
					this->selected_slot++;
 
					this->vscroll.ScrollTowards(this->selected_slot);
 
					this->vscroll->ScrollTowards(this->selected_slot);
 
					this->InvalidateData();
 
				}
 
				break;
 

	
 
			case AIC_WIDGET_CHANGE:  // choose other AI
 
				ShowAIListWindow((CompanyID)this->selected_slot);
 
@@ -705,16 +713,18 @@ struct AIDebugWindow : public QueryStrin
 
	bool autoscroll;
 
	bool show_break_box;
 
	static bool break_check_enabled;                       ///< Stop an AI when it prints a matching string
 
	static char break_string[MAX_BREAK_STR_STRING_LENGTH]; ///< The string to match to the AI output
 
	static bool case_sensitive_break_check;                ///< Is the matching done case-sensitive
 
	int highlight_row;                                     ///< The output row that matches the given string, or -1
 
	Scrollbar *vscroll;
 

	
 
	AIDebugWindow(const WindowDesc *desc, WindowNumber number) : QueryStringBaseWindow(MAX_BREAK_STR_STRING_LENGTH)
 
	{
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(AID_WIDGET_SCROLLBAR);
 
		this->show_break_box = _settings_client.gui.ai_developer_tools;
 
		this->GetWidget<NWidgetStacked>(AID_BREAK_STRING_WIDGETS)->SetDisplayedPlane(this->show_break_box ? 0 : SZSP_HORIZONTAL);
 
		this->FinishInitNested(desc, number);
 

	
 
		if (!this->show_break_box) break_check_enabled = false;
 
		/* Disable the companies who are not active or not an AI */
 
@@ -821,37 +831,37 @@ struct AIDebugWindow : public QueryStrin
 

	
 
		Backup<CompanyByte> cur_company(_current_company, ai_debug_company, FILE_LINE);
 
		AILog::LogData *log = (AILog::LogData *)AIObject::GetLogPointer();
 
		cur_company.Restore();
 

	
 
		int scroll_count = (log == NULL) ? 0 : log->used;
 
		if (this->vscroll.GetCount() != scroll_count) {
 
			this->vscroll.SetCount(scroll_count);
 
		if (this->vscroll->GetCount() != scroll_count) {
 
			this->vscroll->SetCount(scroll_count);
 

	
 
			/* We need a repaint */
 
			this->SetWidgetDirty(AID_WIDGET_SCROLLBAR);
 
		}
 

	
 
		if (log == NULL) return;
 

	
 
		/* Detect when the user scrolls the window. Enable autoscroll when the
 
		 * bottom-most line becomes visible. */
 
		if (this->last_vscroll_pos != this->vscroll.GetPosition()) {
 
			this->autoscroll = this->vscroll.GetPosition() >= log->used - this->vscroll.GetCapacity();
 
		if (this->last_vscroll_pos != this->vscroll->GetPosition()) {
 
			this->autoscroll = this->vscroll->GetPosition() >= log->used - this->vscroll->GetCapacity();
 
		}
 
		if (this->autoscroll) {
 
			int scroll_pos = max(0, log->used - this->vscroll.GetCapacity());
 
			if (scroll_pos != this->vscroll.GetPosition()) {
 
				this->vscroll.SetPosition(scroll_pos);
 
			int scroll_pos = max(0, log->used - this->vscroll->GetCapacity());
 
			if (scroll_pos != this->vscroll->GetPosition()) {
 
				this->vscroll->SetPosition(scroll_pos);
 

	
 
				/* We need a repaint */
 
				this->SetWidgetDirty(AID_WIDGET_SCROLLBAR);
 
				this->SetWidgetDirty(AID_WIDGET_LOG_PANEL);
 
			}
 
		}
 
		this->last_vscroll_pos = this->vscroll.GetPosition();
 
		this->last_vscroll_pos = this->vscroll->GetPosition();
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		switch (widget) {
 
			case AID_WIDGET_NAME_TEXT:
 
@@ -877,13 +887,13 @@ struct AIDebugWindow : public QueryStrin
 
				Backup<CompanyByte> cur_company(_current_company, ai_debug_company, FILE_LINE);
 
				AILog::LogData *log = (AILog::LogData *)AIObject::GetLogPointer();
 
				cur_company.Restore();
 
				if (log == NULL) return;
 

	
 
				int y = this->top_offset;
 
				for (int i = this->vscroll.GetPosition(); this->vscroll.IsVisible(i) && i < log->used; i++) {
 
				for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < log->used; i++) {
 
					int pos = (i + log->pos + 1 - log->used + log->count) % log->count;
 
					if (log->lines[pos] == NULL) break;
 

	
 
					TextColour colour;
 
					switch (log->type[pos]) {
 
						case AILog::LOG_SQ_INFO:  colour = TC_BLACK;  break;
 
@@ -913,17 +923,17 @@ struct AIDebugWindow : public QueryStrin
 
		this->RaiseWidget(ai_debug_company + AID_WIDGET_COMPANY_BUTTON_START);
 
		ai_debug_company = show_ai;
 

	
 
		Backup<CompanyByte> cur_company(_current_company, ai_debug_company, FILE_LINE);
 
		AILog::LogData *log = (AILog::LogData *)AIObject::GetLogPointer();
 
		cur_company.Restore();
 
		this->vscroll.SetCount((log == NULL) ? 0 : log->used);
 
		this->vscroll->SetCount((log == NULL) ? 0 : log->used);
 

	
 
		this->LowerWidget(ai_debug_company + AID_WIDGET_COMPANY_BUTTON_START);
 
		this->autoscroll = true;
 
		this->last_vscroll_pos = this->vscroll.GetPosition();
 
		this->last_vscroll_pos = this->vscroll->GetPosition();
 
		this->SetDirty();
 
		/* Close AI settings window to prevent confusion */
 
		DeleteWindowByClass(WC_AI_SETTINGS);
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
@@ -1031,13 +1041,13 @@ struct AIDebugWindow : public QueryStrin
 
			cur_company.Restore();
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, AID_WIDGET_LOG_PANEL);
 
		this->vscroll->SetCapacityFromWidget(this, AID_WIDGET_LOG_PANEL);
 
	}
 
};
 

	
 
const int AIDebugWindow::top_offset = WD_FRAMERECT_TOP + 2;
 
const int AIDebugWindow::bottom_offset = WD_FRAMERECT_BOTTOM;
 
CompanyID AIDebugWindow::ai_debug_company = INVALID_COMPANY;
src/airport_gui.cpp
Show inline comments
 
@@ -213,12 +213,13 @@ enum AirportPickerWidgets {
 
	BAIRW_BTN_DOHILIGHT,
 
};
 

	
 
class BuildAirportWindow : public PickerWindowBase {
 
	SpriteID preview_sprite; ///< Cached airport preview sprite.
 
	int line_height;
 
	Scrollbar *vscroll;
 

	
 
	/** Build a dropdown list of available airport classes */
 
	static DropDownList *BuildAirportClassDropDown()
 
	{
 
		DropDownList *list = new DropDownList();
 

	
 
@@ -229,21 +230,25 @@ class BuildAirportWindow : public Picker
 
		return list;
 
	}
 

	
 
public:
 
	BuildAirportWindow(const WindowDesc *desc, Window *parent) : PickerWindowBase(parent)
 
	{
 
		this->vscroll.SetCapacity(5);
 
		this->vscroll.SetPosition(0);
 
		this->InitNested(desc, TRANSPORT_AIR);
 
		this->CreateNestedTree(desc);
 

	
 
		this->vscroll = this->GetScrollbar(BAIRW_SCROLLBAR);
 
		this->vscroll->SetCapacity(5);
 
		this->vscroll->SetPosition(0);
 

	
 
		this->FinishInitNested(desc, TRANSPORT_AIR);
 

	
 
		this->SetWidgetLoweredState(BAIRW_BTN_DONTHILIGHT, !_settings_client.gui.station_show_coverage);
 
		this->SetWidgetLoweredState(BAIRW_BTN_DOHILIGHT, _settings_client.gui.station_show_coverage);
 
		this->OnInvalidateData();
 

	
 
		this->vscroll.SetCount(AirportClass::GetCount(_selected_airport_class));
 
		this->vscroll->SetCount(AirportClass::GetCount(_selected_airport_class));
 
		this->SelectFirstAvailableAirport(true);
 
	}
 

	
 
	virtual ~BuildAirportWindow()
 
	{
 
		DeleteWindowById(WC_SELECT_STATION, 0);
 
@@ -295,13 +300,13 @@ public:
 
					if (!as->enabled) continue;
 

	
 
					size->width = max(size->width, GetStringBoundingBox(as->name).width);
 
				}
 

	
 
				this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
 
				size->height = this->vscroll.GetCapacity() * this->line_height;
 
				size->height = this->vscroll->GetCapacity() * this->line_height;
 
				break;
 
			}
 

	
 
			case BAIRW_AIRPORT_SPRITE:
 
				for (int i = 0; i < NUM_AIRPORTS; i++) {
 
					const AirportSpec *as = AirportSpec::Get(i);
 
@@ -340,13 +345,13 @@ public:
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		switch (widget) {
 
			case BAIRW_AIRPORT_LIST: {
 
				int y = r.top;
 
				for (uint i = this->vscroll.GetPosition(); this->vscroll.IsVisible(i) && i < AirportClass::GetCount(_selected_airport_class); i++) {
 
				for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < AirportClass::GetCount(_selected_airport_class); i++) {
 
					const AirportSpec *as = AirportClass::Get(_selected_airport_class, i);
 
					if (!as->IsAvailable()) {
 
						GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->line_height - 2, 0, FILLRECT_CHECKER);
 
					}
 
					DrawString(r.left + WD_MATRIX_LEFT, r.right + WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, as->name, ((int)i == _selected_airport_index) ? TC_WHITE : TC_BLACK);
 
					y += this->line_height;
 
@@ -448,14 +453,14 @@ public:
 
		switch (widget) {
 
			case BAIRW_CLASS_DROPDOWN:
 
				ShowDropDownList(this, BuildAirportClassDropDown(), _selected_airport_class, BAIRW_CLASS_DROPDOWN);
 
				break;
 

	
 
			case BAIRW_AIRPORT_LIST: {
 
				int num_clicked = this->vscroll.GetPosition() + (pt.y - this->nested_array[widget]->pos_y) / this->line_height;
 
				if (num_clicked >= this->vscroll.GetCount()) break;
 
				int num_clicked = this->vscroll->GetPosition() + (pt.y - this->nested_array[widget]->pos_y) / this->line_height;
 
				if (num_clicked >= this->vscroll->GetCount()) break;
 
				const AirportSpec *as = AirportClass::Get(_selected_airport_class, num_clicked);
 
				if (as->IsAvailable()) this->SelectOtherAirport(num_clicked);
 
				break;
 
			}
 

	
 
			case BAIRW_BTN_DONTHILIGHT: case BAIRW_BTN_DOHILIGHT:
 
@@ -515,13 +520,13 @@ public:
 
	}
 

	
 
	virtual void OnDropdownSelect(int widget, int index)
 
	{
 
		assert(widget == BAIRW_CLASS_DROPDOWN);
 
		_selected_airport_class = (AirportClassID)index;
 
		this->vscroll.SetCount(AirportClass::GetCount(_selected_airport_class));
 
		this->vscroll->SetCount(AirportClass::GetCount(_selected_airport_class));
 
		this->SelectFirstAvailableAirport(false);
 
	}
 

	
 
	virtual void OnTick()
 
	{
 
		CheckRedrawStationCoverage(this);
src/autoreplace_gui.cpp
Show inline comments
 
@@ -103,12 +103,14 @@ class ReplaceVehicleWindow : public Wind
 
	GUIEngineList engines[2];     ///< Left and right list of engines.
 
	bool replace_engines;         ///< If \c true, engines are replaced, if \c false, wagons are replaced (only for trains).
 
	bool reset_sel_engine;        ///< Also reset #sel_engine while updating left and/or right (#update_left and/or #update_right) and no valid engine selected.
 
	GroupID sel_group;            ///< Group selected to replace.
 
	int details_height;           ///< Minimal needed height of the details panels (found so far).
 
	RailType sel_railtype;        ///< Type of rail tracks selected.
 
	Scrollbar *vscroll;
 
	Scrollbar *vscroll2;
 

	
 
	/**
 
	 * Figure out if an engine should be added to a list.
 
	 * @param e            The EngineID.
 
	 * @param draw_left    If \c true, the left list is drawn (the engines specific to the railtype you selected).
 
	 * @param show_engines If \c true, the locomotives are drawn, else the wagons are drawn (never both).
 
@@ -168,13 +170,13 @@ class ReplaceVehicleWindow : public Wind
 
	{
 
		EngineID e = this->sel_engine[0];
 

	
 
		if (this->engines[0].NeedRebuild()) {
 
			/* We need to rebuild the left engines list */
 
			this->GenerateReplaceVehList(true);
 
			this->vscroll.SetCount(this->engines[0].Length());
 
			this->vscroll->SetCount(this->engines[0].Length());
 
			if (this->reset_sel_engine && this->sel_engine[0] == INVALID_ENGINE && this->engines[0].Length() != 0) {
 
				this->sel_engine[0] = this->engines[0][0];
 
			}
 
		}
 

	
 
		if (this->engines[1].NeedRebuild() || e != this->sel_engine[0]) {
 
@@ -182,13 +184,13 @@ class ReplaceVehicleWindow : public Wind
 
			if (this->sel_engine[0] == INVALID_ENGINE) {
 
				/* Always empty the right engines list when nothing is selected in the left engines list */
 
				this->engines[1].Clear();
 
				this->sel_engine[1] = INVALID_ENGINE;
 
			} else {
 
				this->GenerateReplaceVehList(false);
 
				this->vscroll2.SetCount(this->engines[1].Length());
 
				this->vscroll2->SetCount(this->engines[1].Length());
 
				if (this->reset_sel_engine && this->sel_engine[1] == INVALID_ENGINE && this->engines[1].Length() != 0) {
 
					this->sel_engine[1] = this->engines[1][0];
 
				}
 
			}
 
		}
 
		/* Reset the flags about needed updates */
 
@@ -223,13 +225,16 @@ public:
 
		this->engines[1].ForceRebuild();
 
		this->reset_sel_engine = true;
 
		this->details_height   = ((vehicletype == VEH_TRAIN) ? 10 : 9) * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
 
		this->sel_engine[0] = INVALID_ENGINE;
 
		this->sel_engine[1] = INVALID_ENGINE;
 

	
 
		this->InitNested(desc, vehicletype);
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(RVW_WIDGET_LEFT_SCROLLBAR);
 
		this->vscroll2 = this->GetScrollbar(RVW_WIDGET_RIGHT_SCROLLBAR);
 
		this->FinishInitNested(desc, vehicletype);
 

	
 
		this->owner = _local_company;
 
		this->sel_group = id_g;
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
@@ -336,14 +341,14 @@ public:
 
				break;
 
			}
 

	
 
			case RVW_WIDGET_LEFT_MATRIX:
 
			case RVW_WIDGET_RIGHT_MATRIX: {
 
				int side = (widget == RVW_WIDGET_LEFT_MATRIX) ? 0 : 1;
 
				EngineID start  = side == 0 ? this->vscroll.GetPosition() : this->vscroll2.GetPosition(); // what is the offset for the start (scrolling)
 
				EngineID end    = min((side == 0 ? this->vscroll.GetCapacity() : this->vscroll2.GetCapacity()) + start, this->engines[side].Length());
 
				EngineID start  = side == 0 ? this->vscroll->GetPosition() : this->vscroll2->GetPosition(); // what is the offset for the start (scrolling)
 
				EngineID end    = min((side == 0 ? this->vscroll->GetCapacity() : this->vscroll2->GetCapacity()) + start, this->engines[side].Length());
 

	
 
				/* Do the actual drawing */
 
				DrawEngineList((VehicleType)this->window_number, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP,
 
						&this->engines[side], start, end, this->sel_engine[side], side == 0, this->sel_group);
 
				break;
 
			}
 
@@ -450,16 +455,16 @@ public:
 

	
 
			case RVW_WIDGET_LEFT_MATRIX:
 
			case RVW_WIDGET_RIGHT_MATRIX: {
 
				uint i;
 
				byte click_side;
 
				if (widget == RVW_WIDGET_LEFT_MATRIX) {
 
					i = this->vscroll.GetScrolledRowFromWidget(pt.y, this, RVW_WIDGET_LEFT_MATRIX);
 
					i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, RVW_WIDGET_LEFT_MATRIX);
 
					click_side = 0;
 
				} else {
 
					i = this->vscroll2.GetScrolledRowFromWidget(pt.y, this, RVW_WIDGET_RIGHT_MATRIX);
 
					i = this->vscroll2->GetScrolledRowFromWidget(pt.y, this, RVW_WIDGET_RIGHT_MATRIX);
 
					click_side = 1;
 
				}
 
				size_t engine_count = this->engines[click_side].Length();
 

	
 
				EngineID e = engine_count > i ? this->engines[click_side][i] : INVALID_ENGINE;
 
				if (e == this->sel_engine[click_side]) break; // we clicked the one we already selected
 
@@ -477,28 +482,28 @@ public:
 
	virtual void OnDropdownSelect(int widget, int index)
 
	{
 
		RailType temp = (RailType)index;
 
		if (temp == sel_railtype) return; // we didn't select a new one. No need to change anything
 
		sel_railtype = temp;
 
		/* Reset scrollbar positions */
 
		this->vscroll.SetPosition(0);
 
		this->vscroll2.SetPosition(0);
 
		this->vscroll->SetPosition(0);
 
		this->vscroll2->SetPosition(0);
 
		/* Rebuild the lists */
 
		this->engines[0].ForceRebuild();
 
		this->engines[1].ForceRebuild();
 
		this->reset_sel_engine = true;
 
		this->SetDirty();
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, RVW_WIDGET_LEFT_MATRIX);
 
		this->vscroll2.SetCapacityFromWidget(this, RVW_WIDGET_RIGHT_MATRIX);
 
		this->vscroll->SetCapacityFromWidget(this, RVW_WIDGET_LEFT_MATRIX);
 
		this->vscroll2->SetCapacityFromWidget(this, RVW_WIDGET_RIGHT_MATRIX);
 

	
 
		this->GetWidget<NWidgetCore>(RVW_WIDGET_LEFT_MATRIX)->widget_data =
 
				this->GetWidget<NWidgetCore>(RVW_WIDGET_RIGHT_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
				this->GetWidget<NWidgetCore>(RVW_WIDGET_RIGHT_MATRIX)->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		if (data != 0) {
 
			this->engines[0].ForceRebuild();
src/bridge_gui.cpp
Show inline comments
 
@@ -77,12 +77,13 @@ private:
 
	/* Internal variables */
 
	TileIndex start_tile;
 
	TileIndex end_tile;
 
	uint32 type;
 
	GUIBridgeList *bridges;
 
	int bridgetext_offset; ///< Horizontal offset of the text describing the bridge properties in #BBSW_BRIDGE_LIST relative to the left edge.
 
	Scrollbar *vscroll;
 

	
 
	/** Sort the bridges by their index */
 
	static int CDECL BridgeIndexSorter(const BuildBridgeData *a, const BuildBridgeData *b)
 
	{
 
		return a->index - b->index;
 
	}
 
@@ -128,30 +129,31 @@ public:
 
		start_tile(start),
 
		end_tile(end),
 
		type(br_type),
 
		bridges(bl)
 
	{
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(BBSW_SCROLLBAR);
 
		/* Change the data, or the caption of the gui. Set it to road or rail, accordingly. */
 
		this->GetWidget<NWidgetCore>(BBSW_CAPTION)->widget_data = (GB(this->type, 15, 2) == TRANSPORT_ROAD) ? STR_SELECT_ROAD_BRIDGE_CAPTION : STR_SELECT_RAIL_BRIDGE_CAPTION;
 
		this->FinishInitNested(desc, GB(br_type, 15, 2)); // Initializes 'this->bridgetext_offset'.
 

	
 
		this->parent = FindWindowById(WC_BUILD_TOOLBAR, GB(this->type, 15, 2));
 
		this->bridges->SetListing(this->last_sorting);
 
		this->bridges->SetSortFuncs(this->sorter_funcs);
 
		this->bridges->NeedResort();
 
		this->SortBridgeList();
 

	
 
		this->vscroll.SetCount(bl->Length());
 
		if (this->last_size < this->vscroll.GetCapacity()) this->last_size = this->vscroll.GetCapacity();
 
		if (this->last_size > this->vscroll.GetCount()) this->last_size = this->vscroll.GetCount();
 
		this->vscroll->SetCount(bl->Length());
 
		if (this->last_size < this->vscroll->GetCapacity()) this->last_size = this->vscroll->GetCapacity();
 
		if (this->last_size > this->vscroll->GetCount()) this->last_size = this->vscroll->GetCount();
 
		/* Resize the bridge selection window if we used a bigger one the last time. */
 
		if (this->last_size > this->vscroll.GetCapacity()) {
 
			ResizeWindow(this, 0, (this->last_size - this->vscroll.GetCapacity()) * this->resize.step_height);
 
		if (this->last_size > this->vscroll->GetCapacity()) {
 
			ResizeWindow(this, 0, (this->last_size - this->vscroll->GetCapacity()) * this->resize.step_height);
 
		}
 
		this->GetWidget<NWidgetCore>(BBSW_BRIDGE_LIST)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		this->GetWidget<NWidgetCore>(BBSW_BRIDGE_LIST)->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 

	
 
	~BuildBridgeWindow()
 
	{
 
		this->last_sorting = this->bridges->GetListing();
 

	
 
@@ -213,13 +215,13 @@ public:
 
			case BBSW_DROPDOWN_ORDER:
 
				this->DrawSortButtonState(widget, this->bridges->IsDescSortOrder() ? SBS_DOWN : SBS_UP);
 
				break;
 

	
 
			case BBSW_BRIDGE_LIST: {
 
				uint y = r.top;
 
				for (int i = this->vscroll.GetPosition(); this->vscroll.IsVisible(i) && i < (int)this->bridges->Length(); i++) {
 
				for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < (int)this->bridges->Length(); i++) {
 
					const BridgeSpec *b = this->bridges->Get(i)->spec;
 

	
 
					SetDParam(2, this->bridges->Get(i)->cost);
 
					SetDParam(1, b->speed);
 
					SetDParam(0, b->material);
 

	
 
@@ -246,13 +248,13 @@ public:
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		switch (widget) {
 
			default: break;
 
			case BBSW_BRIDGE_LIST: {
 
				uint i = this->vscroll.GetScrolledRowFromWidget(pt.y, this, BBSW_BRIDGE_LIST);
 
				uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, BBSW_BRIDGE_LIST);
 
				if (i < this->bridges->Length()) {
 
					this->BuildBridge(i);
 
					delete this;
 
				}
 
				break;
 
			}
 
@@ -276,16 +278,16 @@ public:
 
			this->SortBridgeList();
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, BBSW_BRIDGE_LIST);
 
		this->GetWidget<NWidgetCore>(BBSW_BRIDGE_LIST)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		this->vscroll->SetCapacityFromWidget(this, BBSW_BRIDGE_LIST);
 
		this->GetWidget<NWidgetCore>(BBSW_BRIDGE_LIST)->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 

	
 
		this->last_size = max(this->vscroll.GetCapacity(), this->last_size);
 
		this->last_size = max(this->vscroll->GetCapacity(), this->last_size);
 
	}
 
};
 

	
 
/* Set the default size of the Build Bridge Window */
 
uint16 BuildBridgeWindow::last_size = 4;
 
/* Set the default sorting for the bridges */
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -776,12 +776,13 @@ struct BuildVehicleWindow : Window {
 
	EngineID rename_engine;
 
	GUIEngineList eng_list;
 
	CargoID cargo_filter[NUM_CARGO + 2];        ///< Available cargo filters; CargoID or CF_ANY or CF_NONE
 
	StringID cargo_filter_texts[NUM_CARGO + 3]; ///< Texts for filter_cargo, terminated by INVALID_STRING_ID
 
	byte cargo_filter_criteria;                 ///< Selected cargo filter
 
	int details_height;                         ///< Minimal needed height of the details panels (found so far).
 
	Scrollbar *vscroll;
 

	
 
	BuildVehicleWindow(const WindowDesc *desc, TileIndex tile, VehicleType type) : Window()
 
	{
 
		this->vehicle_type = type;
 
		this->window_number = tile == INVALID_TILE ? (int)type : tile;
 

	
 
@@ -803,12 +804,14 @@ struct BuildVehicleWindow : Window {
 
		}
 

	
 
		this->listview_mode = (this->window_number <= VEH_END);
 

	
 
		this->CreateNestedTree(desc);
 

	
 
		this->vscroll = this->GetScrollbar(BUILD_VEHICLE_WIDGET_SCROLLBAR);
 

	
 
		/* If we are just viewing the list of vehicles, we do not need the Build button.
 
		 * So we just hide it, and enlarge the Rename buton by the now vacant place. */
 
		if (this->listview_mode) this->GetWidget<NWidgetStacked>(BUILD_VEHICLE_WIDGET_BUILD_SEL)->SetDisplayedPlane(SZSP_NONE);
 

	
 
		NWidgetCore *widget = this->GetWidget<NWidgetCore>(BUILD_VEHICLE_WIDGET_LIST);
 
		widget->tool_tip = STR_BUY_VEHICLE_TRAIN_LIST_TOOLTIP + type;
 
@@ -1053,13 +1056,13 @@ struct BuildVehicleWindow : Window {
 
				_last_sort_order[this->vehicle_type] = this->descending_sort_order;
 
				this->eng_list.ForceRebuild();
 
				this->SetDirty();
 
				break;
 

	
 
			case BUILD_VEHICLE_WIDGET_LIST: {
 
				uint i = this->vscroll.GetScrolledRowFromWidget(pt.y, this, BUILD_VEHICLE_WIDGET_LIST);
 
				uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, BUILD_VEHICLE_WIDGET_LIST);
 
				size_t num_items = this->eng_list.Length();
 
				this->sel_engine = (i < num_items) ? this->eng_list[i] : INVALID_ENGINE;
 
				this->SetDirty();
 
				if (click_count > 1 && !this->listview_mode) this->OnClick(pt, BUILD_VEHICLE_WIDGET_BUILD, 1);
 
				break;
 
			}
 
@@ -1149,25 +1152,25 @@ struct BuildVehicleWindow : Window {
 
	}
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		switch (widget) {
 
			case BUILD_VEHICLE_WIDGET_LIST:
 
				DrawEngineList(this->vehicle_type, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, &this->eng_list, this->vscroll.GetPosition(), min(this->vscroll.GetPosition() + this->vscroll.GetCapacity(), this->eng_list.Length()), this->sel_engine, false, DEFAULT_GROUP);
 
				DrawEngineList(this->vehicle_type, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, &this->eng_list, this->vscroll->GetPosition(), min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->eng_list.Length()), this->sel_engine, false, DEFAULT_GROUP);
 
				break;
 

	
 
			case BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING:
 
				this->DrawSortButtonState(BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING, this->descending_sort_order ? SBS_DOWN : SBS_UP);
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		this->GenerateBuildList();
 
		this->vscroll.SetCount(this->eng_list.Length());
 
		this->vscroll->SetCount(this->eng_list.Length());
 

	
 
		this->DrawWidgets();
 

	
 
		if (!this->IsShaded()) {
 
			int needed_height = this->details_height;
 
			/* Draw details panels. */
 
@@ -1216,14 +1219,14 @@ struct BuildVehicleWindow : Window {
 
		}
 
		this->SetDirty();
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, BUILD_VEHICLE_WIDGET_LIST);
 
		this->GetWidget<NWidgetCore>(BUILD_VEHICLE_WIDGET_LIST)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		this->vscroll->SetCapacityFromWidget(this, BUILD_VEHICLE_WIDGET_LIST);
 
		this->GetWidget<NWidgetCore>(BUILD_VEHICLE_WIDGET_LIST)->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 
};
 

	
 
static const WindowDesc _build_vehicle_desc(
 
	WDP_AUTO, 240, 268,
 
	WC_BUILD_VEHICLE, WC_NONE,
src/depot_gui.cpp
Show inline comments
 
@@ -219,23 +219,27 @@ struct DepotWindow : Window {
 
	VehicleID sel;
 
	VehicleID vehicle_over; ///< Rail vehicle over which another one is dragged, \c INVALID_VEHICLE if none.
 
	VehicleType type;
 
	bool generate_list;
 
	VehicleList vehicle_list;
 
	VehicleList wagon_list;
 
	Scrollbar *hscroll;     ///< Only for trains.
 
	Scrollbar *vscroll;
 

	
 
	DepotWindow(const WindowDesc *desc, TileIndex tile, VehicleType type) : Window()
 
	{
 
		assert(IsCompanyBuildableVehicleType(type)); // ensure that we make the call with a valid type
 

	
 
		this->sel = INVALID_VEHICLE;
 
		this->vehicle_over = INVALID_VEHICLE;
 
		this->generate_list = true;
 
		this->type = type;
 

	
 
		this->CreateNestedTree(desc);
 
		this->hscroll = (this->type == VEH_TRAIN ? this->GetScrollbar(DEPOT_WIDGET_H_SCROLL) : NULL);
 
		this->vscroll = this->GetScrollbar(DEPOT_WIDGET_V_SCROLL);
 
		/* Don't show 'rename button' of aircraft hangar */
 
		this->GetWidget<NWidgetStacked>(DEPOT_WIDGET_SHOW_RENAME)->SetDisplayedPlane(type == VEH_AIRCRAFT ? SZSP_NONE : 0);
 
		this->SetupWidgetData(type);
 
		this->FinishInitNested(desc, tile);
 

	
 
		this->owner = GetTileOwner(tile);
 
@@ -268,13 +272,13 @@ struct DepotWindow : Window {
 
			case VEH_TRAIN: {
 
				const Train *u = Train::From(v);
 
				free_wagon = u->IsFreeWagon();
 

	
 
				uint x_space = free_wagon ? TRAININFO_DEFAULT_VEHICLE_WIDTH : 0;
 
				DrawTrainImage(u, image_left + (rtl ? 0 : x_space), image_right - (rtl ? x_space : 0), sprite_y - 1,
 
						this->sel, free_wagon ? 0 : this->hscroll.GetPosition(), this->vehicle_over);
 
						this->sel, free_wagon ? 0 : this->hscroll->GetPosition(), this->vehicle_over);
 

	
 
				/* Number of wagons relative to a standard length wagon (rounded up) */
 
				SetDParam(0, CeilDiv(u->tcache.cached_total_length, 8));
 
				DrawString(rtl ? left + WD_FRAMERECT_LEFT : right - this->count_width, rtl ? left + this->count_width : right - WD_FRAMERECT_RIGHT, y + (this->resize.step_height - FONT_HEIGHT_SMALL) / 2, STR_TINY_BLACK_COMA, TC_FROMSTRING, SA_RIGHT); // Draw the counter
 
				break;
 
			}
 
@@ -322,13 +326,13 @@ struct DepotWindow : Window {
 

	
 
		/* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */
 
		uint16 mat_data = this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX)->widget_data;
 
		uint16 rows_in_display   = GB(mat_data, MAT_ROW_START, MAT_ROW_BITS);
 
		uint16 boxes_in_each_row = GB(mat_data, MAT_COL_START, MAT_COL_BITS);
 

	
 
		uint16 num = this->vscroll.GetPosition() * boxes_in_each_row;
 
		uint16 num = this->vscroll->GetPosition() * boxes_in_each_row;
 
		int maxval = min(this->vehicle_list.Length(), num + (rows_in_display * boxes_in_each_row));
 
		int y;
 
		for (y = r.top + 1; num < maxval; y += this->resize.step_height) { // Draw the rows
 
			for (byte i = 0; i < boxes_in_each_row && num < maxval; i++, num++) {
 
				/* Draw all vehicles in the current row */
 
				const Vehicle *v = this->vehicle_list[num];
 
@@ -338,13 +342,13 @@ struct DepotWindow : Window {
 
					int x = r.left + (rtl ? (boxes_in_each_row - i - 1) : i) * this->resize.step_width;
 
					this->DrawVehicleInDepot(v, x, x + this->resize.step_width - 1, y);
 
				}
 
			}
 
		}
 

	
 
		maxval = min(this->vehicle_list.Length() + this->wagon_list.Length(), (this->vscroll.GetPosition() * boxes_in_each_row) + (rows_in_display * boxes_in_each_row));
 
		maxval = min(this->vehicle_list.Length() + this->wagon_list.Length(), (this->vscroll->GetPosition() * boxes_in_each_row) + (rows_in_display * boxes_in_each_row));
 

	
 
		/* draw the train wagons, that do not have an engine in front */
 
		for (; num < maxval; num++, y += this->resize.step_height) {
 
			const Vehicle *v = this->wagon_list[num - this->vehicle_list.Length()];
 
			this->DrawVehicleInDepot(v, r.left, r.right, y);
 
		}
 
@@ -381,21 +385,21 @@ struct DepotWindow : Window {
 
		uint xt = 0, xm = 0, ym = 0;
 
		if (this->type == VEH_TRAIN) {
 
			xm = x;
 
		} else {
 
			xt = x / this->resize.step_width;
 
			xm = x % this->resize.step_width;
 
			if (xt >= this->hscroll.GetCapacity()) return MODE_ERROR;
 
			if (xt >= this->hscroll->GetCapacity()) return MODE_ERROR;
 
		}
 
		ym = y % this->resize.step_height;
 

	
 
		uint row = y / this->resize.step_height;
 
		if (row >= this->vscroll.GetCapacity()) return MODE_ERROR;
 
		if (row >= this->vscroll->GetCapacity()) return MODE_ERROR;
 

	
 
		uint boxes_in_each_row = GB(matrix_widget->widget_data, MAT_COL_START, MAT_COL_BITS);
 
		uint pos = ((row + this->vscroll.GetPosition()) * boxes_in_each_row) + xt;
 
		uint pos = ((row + this->vscroll->GetPosition()) * boxes_in_each_row) + xt;
 

	
 
		if (this->vehicle_list.Length() + this->wagon_list.Length() <= pos) {
 
			/* Clicking on 'line' / 'block' without a vehicle */
 
			if (this->type == VEH_TRAIN) {
 
				/* End the dragging */
 
				d->head  = NULL;
 
@@ -407,13 +411,13 @@ struct DepotWindow : Window {
 
		}
 

	
 
		bool wagon = false;
 
		if (this->vehicle_list.Length() > pos) {
 
			*veh = this->vehicle_list[pos];
 
			/* Skip vehicles that are scrolled off the list */
 
			x += this->hscroll.GetPosition();
 
			x += this->hscroll->GetPosition();
 
		} else {
 
			pos -= this->vehicle_list.Length();
 
			*veh = this->wagon_list[pos];
 
			/* free wagons don't have an initial loco. */
 
			x -= VEHICLEINFO_FULL_VEHICLE_WIDTH;
 
			wagon = true;
 
@@ -690,16 +694,16 @@ struct DepotWindow : Window {
 
				for (const Train *v = Train::From(this->vehicle_list[num]); v != NULL; v = v->Next()) {
 
					width += v->GetDisplayImageWidth();
 
				}
 
				max_width = max(max_width, width);
 
			}
 
			/* Always have 1 empty row, so people can change the setting of the train */
 
			this->vscroll.SetCount(this->vehicle_list.Length() + this->wagon_list.Length() + 1);
 
			this->hscroll.SetCount(max_width);
 
			this->vscroll->SetCount(this->vehicle_list.Length() + this->wagon_list.Length() + 1);
 
			this->hscroll->SetCount(max_width);
 
		} else {
 
			this->vscroll.SetCount(CeilDiv(this->vehicle_list.Length(), this->hscroll.GetCapacity()));
 
			this->vscroll->SetCount(CeilDiv(this->vehicle_list.Length(), this->hscroll->GetCapacity()));
 
		}
 

	
 
		/* Setup disabled buttons. */
 
		TileIndex tile = this->window_number;
 
		this->SetWidgetsDisabledState(!IsTileOwner(tile, _local_company),
 
			DEPOT_WIDGET_STOP_ALL,
 
@@ -1002,19 +1006,19 @@ struct DepotWindow : Window {
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX);
 
		this->vscroll.SetCapacityFromWidget(this, DEPOT_WIDGET_MATRIX);
 
		this->vscroll->SetCapacityFromWidget(this, DEPOT_WIDGET_MATRIX);
 
		if (this->type == VEH_TRAIN) {
 
			this->hscroll.SetCapacity(nwi->current_x - this->header_width - this->count_width);
 
			nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
			this->hscroll->SetCapacity(nwi->current_x - this->header_width - this->count_width);
 
			nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		} else {
 
			this->hscroll.SetCapacityFromWidget(this, DEPOT_WIDGET_MATRIX);
 
			nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (this->hscroll.GetCapacity() << MAT_COL_START);
 
			this->hscroll->SetCapacityFromWidget(this, DEPOT_WIDGET_MATRIX);
 
			nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (this->hscroll->GetCapacity() << MAT_COL_START);
 
		}
 
	}
 

	
 
	virtual EventState OnCTRLStateChange()
 
	{
 
		if (this->sel != INVALID_VEHICLE) {
src/fios_gui.cpp
Show inline comments
 
@@ -237,12 +237,13 @@ static void MakeSortedSaveGameList()
 
}
 

	
 
struct SaveLoadWindow : public QueryStringBaseWindow {
 
private:
 
	FiosItem o_dir;
 
	const FiosItem *selected;
 
	Scrollbar *vscroll;
 
public:
 

	
 
	void GenerateFileName()
 
	{
 
		GenerateDefaultSaveName(this->edit_str_buf, &this->edit_str_buf[this->edit_str_size - 1]);
 
	}
 
@@ -266,15 +267,16 @@ public:
 
			default:                break;
 
		}
 

	
 
		this->afilter = CS_ALPHANUMERAL;
 
		InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 240);
 

	
 
		this->CreateNestedTree(desc);
 
		this->CreateNestedTree(desc, true);
 
		if (mode == SLD_LOAD_GAME) this->GetWidget<NWidgetStacked>(SLWW_CONTENT_DOWNLOAD_SEL)->SetDisplayedPlane(SZSP_HORIZONTAL);
 
		this->GetWidget<NWidgetCore>(SLWW_WINDOWTITLE)->widget_data = saveload_captions[mode];
 
		this->vscroll = this->GetScrollbar(SLWW_SCROLLBAR);
 

	
 
		this->FinishInitNested(desc, 0);
 

	
 
		this->LowerWidget(SLWW_DRIVES_DIRECTORIES_LIST);
 

	
 
		/* pause is only used in single-player, non-editor mode, non-menu mode. It
 
@@ -350,21 +352,21 @@ public:
 
			}
 

	
 
			case SLWW_DRIVES_DIRECTORIES_LIST: {
 
				GfxFillRect(r.left + 1, r.top + 1, r.right, r.bottom, 0xD7);
 

	
 
				uint y = r.top + WD_FRAMERECT_TOP;
 
				for (uint pos = this->vscroll.GetPosition(); pos < _fios_items.Length(); pos++) {
 
				for (uint pos = this->vscroll->GetPosition(); pos < _fios_items.Length(); pos++) {
 
					const FiosItem *item = _fios_items.Get(pos);
 

	
 
					if (item == this->selected) {
 
						GfxFillRect(r.left + 1, y, r.right, y + this->resize.step_height, 156);
 
					}
 
					DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, item->title, _fios_colours[item->type]);
 
					y += this->resize.step_height;
 
					if (y >= this->vscroll.GetCapacity() * this->resize.step_height + r.top + WD_FRAMERECT_TOP) break;
 
					if (y >= this->vscroll->GetCapacity() * this->resize.step_height + r.top + WD_FRAMERECT_TOP) break;
 
				}
 
				break;
 
			}
 

	
 
			case SLWW_DETAILS: {
 
				GfxFillRect(r.left + WD_FRAMERECT_LEFT, r.top + WD_FRAMERECT_TOP,
 
@@ -480,13 +482,13 @@ public:
 
	{
 
		if (_savegame_sort_dirty) {
 
			_savegame_sort_dirty = false;
 
			MakeSortedSaveGameList();
 
		}
 

	
 
		this->vscroll.SetCount(_fios_items.Length());
 
		this->vscroll->SetCount(_fios_items.Length());
 
		this->DrawWidgets();
 

	
 
		if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
 
			this->DrawEditBox(SLWW_SAVE_OSK_TITLE);
 
		}
 
	}
 
@@ -531,13 +533,13 @@ public:
 
				if (_load_check_data.HasNewGrfs()) {
 
					ShowNewGRFSettings(false, false, false, &_load_check_data.grfconfig);
 
				}
 
				break;
 

	
 
			case SLWW_DRIVES_DIRECTORIES_LIST: { // Click the listbox
 
				int y = this->vscroll.GetScrolledRowFromWidget(pt.y, this, SLWW_DRIVES_DIRECTORIES_LIST, WD_FRAMERECT_TOP);
 
				int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, SLWW_DRIVES_DIRECTORIES_LIST, WD_FRAMERECT_TOP);
 
				if (y == INT_MAX) return;
 

	
 
				const FiosItem *file = _fios_items.Get(y);
 

	
 
				const char *name = FiosBrowseTo(file);
 
				if (name != NULL) {
 
@@ -644,13 +646,13 @@ public:
 
			if (_game_mode == GM_EDITOR) StartupEngines();
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, SLWW_DRIVES_DIRECTORIES_LIST);
 
		this->vscroll->SetCapacityFromWidget(this, SLWW_DRIVES_DIRECTORIES_LIST);
 
	}
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		switch (data) {
 
			case 0:
src/group_gui.cpp
Show inline comments
 
@@ -116,12 +116,13 @@ class VehicleGroupWindow : public BaseVe
 
private:
 
	GroupID group_sel;     ///< Selected group
 
	VehicleID vehicle_sel; ///< Selected vehicle
 
	GroupID group_rename;  ///< Group being renamed, INVALID_GROUP if none
 
	GUIGroupList groups;   ///< List of groups
 
	uint tiny_step_height; ///< Step height for the group list
 
	Scrollbar *vscroll2;
 

	
 
	/**
 
	 * (Re)Build the group list.
 
	 *
 
	 * @param owner The owner of the window
 
	 */
 
@@ -167,12 +168,15 @@ private:
 

	
 
public:
 
	VehicleGroupWindow(const WindowDesc *desc, WindowNumber window_number) : BaseVehicleListWindow()
 
	{
 
		this->CreateNestedTree(desc);
 

	
 
		this->vscroll = this->GetScrollbar(GRP_WIDGET_LIST_VEHICLE_SCROLLBAR);
 
		this->vscroll2 = this->GetScrollbar(GRP_WIDGET_LIST_GROUP_SCROLLBAR);
 

	
 
		this->vehicle_type = (VehicleType)GB(window_number, 11, 5);
 
		switch (this->vehicle_type) {
 
			default: NOT_REACHED();
 
			case VEH_TRAIN:    this->sorting = &_sorting.train;    break;
 
			case VEH_ROAD:     this->sorting = &_sorting.roadveh;  break;
 
			case VEH_SHIP:     this->sorting = &_sorting.ship;     break;
 
@@ -302,14 +306,14 @@ public:
 
		this->BuildVehicleList(owner, this->group_sel, IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST);
 
		this->SortVehicleList();
 

	
 
		this->BuildGroupList(owner);
 
		this->groups.Sort(&GroupNameSorter);
 

	
 
		this->vscroll2.SetCount(this->groups.Length());
 
		this->vscroll.SetCount(this->vehicles.Length());
 
		this->vscroll2->SetCount(this->groups.Length());
 
		this->vscroll->SetCount(this->vehicles.Length());
 

	
 
		/* The drop down menu is out, *but* it may not be used, retract it. */
 
		if (this->vehicles.Length() == 0 && this->IsWidgetLowered(GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN)) {
 
			this->RaiseWidget(GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN);
 
			HideDropDownMenu(this);
 
		}
 
@@ -362,14 +366,14 @@ public:
 
				DrawString(r.left + WD_FRAMERECT_LEFT + 8, r.right - WD_FRAMERECT_RIGHT - 8, r.top + WD_FRAMERECT_TOP + 1,
 
						STR_GROUP_DEFAULT_TRAINS + this->vehicle_type, IsDefaultGroupID(this->group_sel) ? TC_WHITE : TC_BLACK);
 
				break;
 

	
 
			case GRP_WIDGET_LIST_GROUP: {
 
				int y1 = r.top + WD_FRAMERECT_TOP + 1;
 
				int max = min(this->vscroll2.GetPosition() + this->vscroll2.GetCapacity(), this->groups.Length());
 
				for (int i = this->vscroll2.GetPosition(); i < max; ++i) {
 
				int max = min(this->vscroll2->GetPosition() + this->vscroll2->GetCapacity(), this->groups.Length());
 
				for (int i = this->vscroll2->GetPosition(); i < max; ++i) {
 
					const Group *g = this->groups[i];
 

	
 
					assert(g->owner == this->owner);
 

	
 
					/* draw the selected group in white, else we draw it in black */
 
					SetDParam(0, g->index);
 
@@ -420,24 +424,24 @@ public:
 
					this->vehicles.ForceRebuild();
 
					this->SetDirty();
 
				}
 
				break;
 

	
 
			case GRP_WIDGET_LIST_GROUP: { // Matrix Group
 
				uint id_g = this->vscroll2.GetScrolledRowFromWidget(pt.y, this, GRP_WIDGET_LIST_GROUP, 0, this->tiny_step_height);
 
				uint id_g = this->vscroll2->GetScrolledRowFromWidget(pt.y, this, GRP_WIDGET_LIST_GROUP, 0, this->tiny_step_height);
 
				if (id_g >= this->groups.Length()) return;
 

	
 
				this->group_sel = this->groups[id_g]->index;
 

	
 
				this->vehicles.ForceRebuild();
 
				this->SetDirty();
 
				break;
 
			}
 

	
 
			case GRP_WIDGET_LIST_VEHICLE: { // Matrix Vehicle
 
				uint id_v = this->vscroll.GetScrolledRowFromWidget(pt.y, this, GRP_WIDGET_LIST_VEHICLE);
 
				uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, GRP_WIDGET_LIST_VEHICLE);
 
				if (id_v >= this->vehicles.Length()) return; // click out of list bound
 

	
 
				const Vehicle *v = this->vehicles[id_v];
 

	
 
				this->vehicle_sel = v->index;
 

	
 
@@ -509,25 +513,25 @@ public:
 

	
 
			case GRP_WIDGET_LIST_GROUP: { // Matrix group
 
				const VehicleID vindex = this->vehicle_sel;
 
				this->vehicle_sel = INVALID_VEHICLE;
 
				this->SetDirty();
 

	
 
				uint id_g = this->vscroll2.GetScrolledRowFromWidget(pt.y, this, GRP_WIDGET_LIST_GROUP, 0, this->tiny_step_height);
 
				uint id_g = this->vscroll2->GetScrolledRowFromWidget(pt.y, this, GRP_WIDGET_LIST_GROUP, 0, this->tiny_step_height);
 
				if (id_g >= this->groups.Length()) return;
 

	
 
				DoCommandP(0, this->groups[id_g]->index, vindex, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE));
 
				break;
 
			}
 

	
 
			case GRP_WIDGET_LIST_VEHICLE: { // Matrix vehicle
 
				const VehicleID vindex = this->vehicle_sel;
 
				this->vehicle_sel = INVALID_VEHICLE;
 
				this->SetDirty();
 

	
 
				uint id_v = this->vscroll.GetScrolledRowFromWidget(pt.y, this, GRP_WIDGET_LIST_VEHICLE);
 
				uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, GRP_WIDGET_LIST_VEHICLE);
 
				if (id_v >= this->vehicles.Length()) return; // click out of list bound
 

	
 
				const Vehicle *v = this->vehicles[id_v];
 
				if (vindex == v->index) {
 
					ShowVehicleViewWindow(v);
 
				}
 
@@ -543,18 +547,18 @@ public:
 
		this->group_rename = INVALID_GROUP;
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(GRP_WIDGET_LIST_GROUP);
 
		this->vscroll2.SetCapacity(nwi->current_y / this->tiny_step_height);
 
		nwi->widget_data = (this->vscroll2.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		this->vscroll2->SetCapacity(nwi->current_y / this->tiny_step_height);
 
		nwi->widget_data = (this->vscroll2->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 

	
 
		nwi = this->GetWidget<NWidgetCore>(GRP_WIDGET_LIST_VEHICLE);
 
		this->vscroll.SetCapacityFromWidget(this, GRP_WIDGET_LIST_VEHICLE);
 
		nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		this->vscroll->SetCapacityFromWidget(this, GRP_WIDGET_LIST_VEHICLE);
 
		nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 

	
 
	virtual void OnDropdownSelect(int widget, int index)
 
	{
 
		switch (widget) {
 
			case GRP_WIDGET_SORT_BY_DROPDOWN:
src/industry_gui.cpp
Show inline comments
 
@@ -206,12 +206,13 @@ class BuildIndustryWindow : public Windo
 
	IndustryType selected_type;                 ///< industry corresponding to the above index
 
	uint16 callback_timer;                      ///< timer counter for callback eventual verification
 
	bool timer_enabled;                         ///< timer can be used
 
	uint16 count;                               ///< How many industries are loaded
 
	IndustryType index[NUM_INDUSTRYTYPES + 1];  ///< Type of industry, in the order it was loaded
 
	bool enabled[NUM_INDUSTRYTYPES + 1];        ///< availability state, coming from CBID_INDUSTRY_AVAILABLE (if ever)
 
	Scrollbar *vscroll;
 

	
 
	/** The offset for the text in the matrix. */
 
	static const int MATRIX_TEXT_OFFSET = 17;
 

	
 
	void SetupArrays()
 
	{
 
@@ -256,13 +257,13 @@ class BuildIndustryWindow : public Windo
 
		 * I'll be damned if there are none available ;) */
 
		if (this->selected_index == -1) {
 
			this->selected_index = 0;
 
			this->selected_type = this->index[0];
 
		}
 

	
 
		this->vscroll.SetCount(this->count);
 
		this->vscroll->SetCount(this->count);
 
	}
 

	
 
	/** Update status of the fund and display-chain widgets. */
 
	void SetButtons()
 
	{
 
		this->SetWidgetDisabledState(DPIW_FUND_WIDGET, this->selected_type != INVALID_INDUSTRYTYPE && !this->enabled[this->selected_index]);
 
@@ -276,13 +277,16 @@ public:
 

	
 
		this->selected_index = -1;
 
		this->selected_type = INVALID_INDUSTRYTYPE;
 

	
 
		this->callback_timer = DAY_TICKS;
 

	
 
		this->InitNested(&_build_industry_desc, 0);
 
		this->CreateNestedTree(&_build_industry_desc);
 
		this->vscroll = this->GetScrollbar(DPIW_SCROLLBAR);
 
		this->FinishInitNested(&_build_industry_desc, 0);
 

	
 
		this->SetButtons();
 
	}
 

	
 
	virtual void OnInit()
 
	{
 
		this->SetupArrays();
 
@@ -378,22 +382,22 @@ public:
 
	}
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		switch (widget) {
 
			case DPIW_MATRIX_WIDGET:
 
				for (byte i = 0; i < this->vscroll.GetCapacity() && i + this->vscroll.GetPosition() < this->count; i++) {
 
				for (byte i = 0; i < this->vscroll->GetCapacity() && i + this->vscroll->GetPosition() < this->count; i++) {
 
					int x = r.left + WD_MATRIX_LEFT;
 
					int y = r.top + WD_MATRIX_TOP + i * this->resize.step_height;
 
					bool selected = this->selected_index == i + this->vscroll.GetPosition();
 
					bool selected = this->selected_index == i + this->vscroll->GetPosition();
 

	
 
					if (this->index[i + this->vscroll.GetPosition()] == INVALID_INDUSTRYTYPE) {
 
					if (this->index[i + this->vscroll->GetPosition()] == INVALID_INDUSTRYTYPE) {
 
						DrawString(x + MATRIX_TEXT_OFFSET, r.right - WD_MATRIX_RIGHT, y, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, selected ? TC_WHITE : TC_ORANGE);
 
						continue;
 
					}
 
					const IndustrySpec *indsp = GetIndustrySpec(this->index[i + this->vscroll.GetPosition()]);
 
					const IndustrySpec *indsp = GetIndustrySpec(this->index[i + this->vscroll->GetPosition()]);
 

	
 
					/* Draw the name of the industry in white is selected, otherwise, in orange */
 
					DrawString(x + MATRIX_TEXT_OFFSET, r.right - WD_MATRIX_RIGHT, y, indsp->name, selected ? TC_WHITE : TC_ORANGE);
 
					GfxFillRect(x,     y + 1,  x + 10, y + 7, selected ? 15 : 0);
 
					GfxFillRect(x + 1, y + 2,  x +  9, y + 6, indsp->map_colour);
 
				}
 
@@ -473,13 +477,13 @@ public:
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		switch (widget) {
 
			case DPIW_MATRIX_WIDGET: {
 
				int y = this->vscroll.GetScrolledRowFromWidget(pt.y, this, DPIW_MATRIX_WIDGET);
 
				int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, DPIW_MATRIX_WIDGET);
 
				if (y < this->count) { // Is it within the boundaries of available data?
 
					this->selected_index = y;
 
					this->selected_type = this->index[y];
 
					const IndustrySpec *indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(this->selected_type);
 

	
 
					this->SetDirty();
 
@@ -526,14 +530,14 @@ public:
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		/* Adjust the number of items in the matrix depending of the resize */
 
		this->vscroll.SetCapacityFromWidget(this, DPIW_MATRIX_WIDGET);
 
		this->GetWidget<NWidgetCore>(DPIW_MATRIX_WIDGET)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		this->vscroll->SetCapacityFromWidget(this, DPIW_MATRIX_WIDGET);
 
		this->GetWidget<NWidgetCore>(DPIW_MATRIX_WIDGET)->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 

	
 
	virtual void OnPlaceObject(Point pt, TileIndex tile)
 
	{
 
		bool success = true;
 
		/* We do not need to protect ourselves against "Random Many Industries" in this mode */
 
@@ -974,12 +978,13 @@ protected:
 

	
 
	/* Constants for sorting stations */
 
	static const StringID sorter_names[];
 
	static GUIIndustryList::SortFunction * const sorter_funcs[];
 

	
 
	GUIIndustryList industries;
 
	Scrollbar *vscroll;
 

	
 
	/** (Re)Build industries list */
 
	void BuildSortIndustriesList()
 
	{
 
		if (this->industries.NeedRebuild()) {
 
			this->industries.Clear();
 
@@ -988,13 +993,13 @@ protected:
 
			FOR_ALL_INDUSTRIES(i) {
 
				*this->industries.Append() = i;
 
			}
 

	
 
			this->industries.Compact();
 
			this->industries.RebuildDone();
 
			this->vscroll.SetCount(this->industries.Length()); // Update scrollbar as well.
 
			this->vscroll->SetCount(this->industries.Length()); // Update scrollbar as well.
 
		}
 

	
 
		if (!this->industries.Sort()) return;
 
		IndustryDirectoryWindow::last_industry = NULL; // Reset name sorter sort cache
 
		this->SetWidgetDirty(IDW_INDUSTRY_LIST); // Set the modified widget dirty
 
	}
 
@@ -1114,18 +1119,21 @@ protected:
 
		}
 
	}
 

	
 
public:
 
	IndustryDirectoryWindow(const WindowDesc *desc, WindowNumber number) : Window()
 
	{
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(IDW_SCROLLBAR);
 

	
 
		this->industries.SetListing(this->last_sorting);
 
		this->industries.SetSortFuncs(IndustryDirectoryWindow::sorter_funcs);
 
		this->industries.ForceRebuild();
 
		this->BuildSortIndustriesList();
 

	
 
		this->InitNested(desc, 0);
 
		this->FinishInitNested(desc, 0);
 
	}
 

	
 
	~IndustryDirectoryWindow()
 
	{
 
		this->last_sorting = this->industries.GetListing();
 
	}
 
@@ -1151,17 +1159,17 @@ public:
 
				int n = 0;
 
				int y = r.top + WD_FRAMERECT_TOP;
 
				if (this->industries.Length() == 0) {
 
					DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_DIRECTORY_NONE);
 
					break;
 
				}
 
				for (uint i = this->vscroll.GetPosition(); i < this->industries.Length(); i++) {
 
				for (uint i = this->vscroll->GetPosition(); i < this->industries.Length(); i++) {
 
					DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, this->GetIndustryString(this->industries[i]));
 

	
 
					y += this->resize.step_height;
 
					if (++n == this->vscroll.GetCapacity()) break; // max number of industries in 1 window
 
					if (++n == this->vscroll->GetCapacity()) break; // max number of industries in 1 window
 
				}
 
				break;
 
			}
 
		}
 
	}
 

	
 
@@ -1212,13 +1220,13 @@ public:
 

	
 
			case IDW_DROPDOWN_CRITERIA:
 
				ShowDropDownMenu(this, IndustryDirectoryWindow::sorter_names, this->industries.SortType(), IDW_DROPDOWN_CRITERIA, 0, 0);
 
				break;
 

	
 
			case IDW_INDUSTRY_LIST: {
 
				uint p = this->vscroll.GetScrolledRowFromWidget(pt.y, this, IDW_INDUSTRY_LIST, WD_FRAMERECT_TOP);
 
				uint p = this->vscroll->GetScrolledRowFromWidget(pt.y, this, IDW_INDUSTRY_LIST, WD_FRAMERECT_TOP);
 
				if (p < this->industries.Length()) {
 
					if (_ctrl_pressed) {
 
						ShowExtraViewPortWindow(this->industries[p]->location.tile);
 
					} else {
 
						ScrollMainWindowToTile(this->industries[p]->location.tile);
 
					}
 
@@ -1235,13 +1243,13 @@ public:
 
			this->BuildSortIndustriesList();
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, IDW_INDUSTRY_LIST);
 
		this->vscroll->SetCapacityFromWidget(this, IDW_INDUSTRY_LIST);
 
	}
 

	
 
	virtual void OnHundredthTick()
 
	{
 
		this->industries.ForceResort();
 
		this->BuildSortIndustriesList();
 
@@ -1926,16 +1934,20 @@ struct IndustryCargoesWindow : public Wi
 

	
 
	typedef SmallVector<CargoesRow, 4> Fields;
 

	
 
	Fields fields;  ///< Fields to display in the #ICW_PANEL.
 
	uint ind_cargo; ///< If less than #NUM_INDUSTRYTYPES, an industry type, else a cargo id + NUM_INDUSTRYTYPES.
 

	
 
	Scrollbar *vscroll;
 

	
 
	IndustryCargoesWindow(int id) : Window()
 
	{
 
		this->OnInit();
 
		this->InitNested(&_industry_cargoes_desc, 0);
 
		this->CreateNestedTree(&_industry_cargoes_desc);
 
		this->vscroll = this->GetScrollbar(ICW_SCROLLBAR);
 
		this->FinishInitNested(&_industry_cargoes_desc, 0);
 
		this->OnInvalidateData(id);
 
	}
 

	
 
	virtual void OnInit()
 
	{
 
		/* Initialize static CargoesField size variables. */
 
@@ -2204,13 +2216,13 @@ struct IndustryCargoesWindow : public Wi
 
			cust_count++;
 
		}
 

	
 
		this->ShortenCargoColumn(1, 1, num_indrows);
 
		this->ShortenCargoColumn(3, 1, num_indrows);
 
		const NWidgetBase *nwp = this->GetWidget<NWidgetBase>(ICW_PANEL);
 
		this->vscroll.SetCount(CeilDiv(WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM + CargoesField::small_height + num_indrows * CargoesField::normal_height, nwp->resize_y));
 
		this->vscroll->SetCount(CeilDiv(WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM + CargoesField::small_height + num_indrows * CargoesField::normal_height, nwp->resize_y));
 
		this->SetDirty();
 
		this->NotifySmallmap();
 
	}
 

	
 
	/**
 
	 * Compute what and where to display for cargo id \a cid.
 
@@ -2272,13 +2284,13 @@ struct IndustryCargoesWindow : public Wi
 
			this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, NUM_INDUSTRYTYPES);
 
			cust_count++;
 
		}
 

	
 
		this->ShortenCargoColumn(1, 1, num_indrows);
 
		const NWidgetBase *nwp = this->GetWidget<NWidgetBase>(ICW_PANEL);
 
		this->vscroll.SetCount(CeilDiv(WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM + CargoesField::small_height + num_indrows * CargoesField::normal_height, nwp->resize_y));
 
		this->vscroll->SetCount(CeilDiv(WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM + CargoesField::small_height + num_indrows * CargoesField::normal_height, nwp->resize_y));
 
		this->SetDirty();
 
		this->NotifySmallmap();
 
	}
 

	
 
	/**
 
	 * Notify the window about external events.
 
@@ -2313,13 +2325,13 @@ struct IndustryCargoesWindow : public Wi
 

	
 
		int left_pos = WD_FRAMERECT_LEFT;
 
		if (this->ind_cargo >= NUM_INDUSTRYTYPES) left_pos += (CargoesField::industry_width + CargoesField::CARGO_FIELD_WIDTH) / 2;
 
		int last_column = (this->ind_cargo < NUM_INDUSTRYTYPES) ? 4 : 2;
 

	
 
		const NWidgetBase *nwp = this->GetWidget<NWidgetBase>(ICW_PANEL);
 
		int vpos = -this->vscroll.GetPosition() * nwp->resize_y;
 
		int vpos = -this->vscroll->GetPosition() * nwp->resize_y;
 
		for (uint i = 0; i < this->fields.Length(); i++) {
 
			int row_height = (i == 0) ? CargoesField::small_height : CargoesField::normal_height;
 
			if (vpos + row_height >= 0) {
 
				int xpos = left_pos;
 
				int col, dir;
 
				if (_dynlang.text_dir == TD_RTL) {
 
@@ -2352,13 +2364,13 @@ struct IndustryCargoesWindow : public Wi
 
	bool CalculatePositionInWidget(Point pt, Point *fieldxy, Point *xy)
 
	{
 
		const NWidgetBase *nw = this->GetWidget<NWidgetBase>(ICW_PANEL);
 
		pt.x -= nw->pos_x;
 
		pt.y -= nw->pos_y;
 

	
 
		int vpos = WD_FRAMERECT_TOP + CargoesField::small_height - this->vscroll.GetPosition() * nw->resize_y;
 
		int vpos = WD_FRAMERECT_TOP + CargoesField::small_height - this->vscroll->GetPosition() * nw->resize_y;
 
		if (pt.y < vpos) return false;
 

	
 
		int row = (pt.y - vpos) / CargoesField::normal_height; // row is relative to row 1.
 
		if (row + 1 >= (int)this->fields.Length()) return false;
 
		vpos = pt.y - vpos - row * CargoesField::normal_height; // Position in the row + 1 field
 
		row++; // rebase row to match index of this->fields.
 
@@ -2477,13 +2489,13 @@ struct IndustryCargoesWindow : public Wi
 
	{
 
		this->DrawWidgets();
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, ICW_PANEL);
 
		this->vscroll->SetCapacityFromWidget(this, ICW_PANEL);
 
	}
 
};
 

	
 
const int IndustryCargoesWindow::HOR_TEXT_PADDING  = 5; ///< Horizontal padding around the industry type text.
 
const int IndustryCargoesWindow::VERT_TEXT_PADDING = 5; ///< Vertical padding around the industry type text.
 

	
src/network/network_content_gui.cpp
Show inline comments
 
@@ -236,12 +236,13 @@ class NetworkContentListWindow : public 
 
	static GUIContentList::FilterFunction * const filter_funcs[];
 
	GUIContentList content;      ///< List with content
 

	
 
	const ContentInfo *selected; ///< The selected content info
 
	int list_pos;                ///< Our position in the list
 
	uint filesize_sum;           ///< The sum of all selected file sizes
 
	Scrollbar *vscroll;
 

	
 
	/**
 
	 * (Re)build the network game list as its amount has changed because
 
	 * an item has been added or deleted for example
 
	 */
 
	void BuildContentList()
 
@@ -257,13 +258,13 @@ class NetworkContentListWindow : public 
 

	
 
		this->FilterContentList();
 
		this->content.Compact();
 
		this->content.RebuildDone();
 
		this->SortContentList();
 

	
 
		this->vscroll.SetCount(this->content.Length()); // Update the scrollbar
 
		this->vscroll->SetCount(this->content.Length()); // Update the scrollbar
 
		this->ScrollToSelected();
 
	}
 

	
 
	/** Sort content by name. */
 
	static int CDECL NameSorter(const ContentInfo * const *a, const ContentInfo * const *b)
 
	{
 
@@ -335,26 +336,28 @@ class NetworkContentListWindow : public 
 

	
 
	/** Make sure that the currently selected content info is within the visible part of the matrix */
 
	void ScrollToSelected()
 
	{
 
		if (this->selected == NULL) return;
 

	
 
		this->vscroll.ScrollTowards(this->list_pos);
 
		this->vscroll->ScrollTowards(this->list_pos);
 
	}
 

	
 
public:
 
	/**
 
	 * Create the content list window.
 
	 * @param desc the window description to pass to Window's constructor.
 
	 */
 
	NetworkContentListWindow(const WindowDesc *desc, bool select_all) :
 
			QueryStringBaseWindow(EDITBOX_MAX_SIZE),
 
			selected(NULL),
 
			list_pos(0)
 
	{
 
		this->InitNested(desc, 1);
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(NCLWW_SCROLLBAR);
 
		this->FinishInitNested(desc, 1);
 

	
 
		this->GetWidget<NWidgetStacked>(NCLWW_SEL_ALL_UPDATE)->SetDisplayedPlane(select_all);
 

	
 
		this->afilter = CS_ALPHANUMERAL;
 
		InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, EDITBOX_MAX_LENGTH);
 
		this->SetFocusedWidget(NCLWW_FILTER);
 
@@ -445,13 +448,13 @@ public:
 

	
 

	
 
		/* Fill the matrix with the information */
 
		int sprite_y_offset = WD_MATRIX_TOP + (FONT_HEIGHT_NORMAL - 10) / 2;
 
		uint y = r.top;
 
		int cnt = 0;
 
		for (ConstContentIterator iter = this->content.Get(this->vscroll.GetPosition()); iter != this->content.End() && cnt < this->vscroll.GetCapacity(); iter++, cnt++) {
 
		for (ConstContentIterator iter = this->content.Get(this->vscroll->GetPosition()); iter != this->content.End() && cnt < this->vscroll->GetCapacity(); iter++, cnt++) {
 
			const ContentInfo *ci = *iter;
 

	
 
			if (ci == this->selected) GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->resize.step_height - 1, 10);
 

	
 
			SpriteID sprite;
 
			SpriteID pal = PAL_NONE;
 
@@ -587,13 +590,13 @@ public:
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		switch (widget) {
 
			case NCLWW_MATRIX: {
 
				uint id_v = this->vscroll.GetScrolledRowFromWidget(pt.y, this, NCLWW_MATRIX);
 
				uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, NCLWW_MATRIX);
 
				if (id_v >= this->content.Length()) return; // click out of bounds
 

	
 
				this->selected = *this->content.Get(id_v);
 
				this->list_pos = id_v;
 

	
 
				const NWidgetBase *checkbox = this->GetWidget<NWidgetBase>(NCLWW_CHECKBOX);
 
@@ -661,17 +664,17 @@ public:
 
			case WKC_DOWN:
 
				/* scroll down by one */
 
				if (this->list_pos < (int)this->content.Length() - 1) this->list_pos++;
 
				break;
 
			case WKC_PAGEUP:
 
				/* scroll up a page */
 
				this->list_pos = (this->list_pos < this->vscroll.GetCapacity()) ? 0 : this->list_pos - this->vscroll.GetCapacity();
 
				this->list_pos = (this->list_pos < this->vscroll->GetCapacity()) ? 0 : this->list_pos - this->vscroll->GetCapacity();
 
				break;
 
			case WKC_PAGEDOWN:
 
				/* scroll down a page */
 
				this->list_pos = min(this->list_pos + this->vscroll.GetCapacity(), (int)this->content.Length() - 1);
 
				this->list_pos = min(this->list_pos + this->vscroll->GetCapacity(), (int)this->content.Length() - 1);
 
				break;
 
			case WKC_HOME:
 
				/* jump to beginning */
 
				this->list_pos = 0;
 
				break;
 
			case WKC_END:
 
@@ -720,14 +723,14 @@ public:
 
		this->content.ForceRebuild();
 
		this->InvalidateData();
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, NCLWW_MATRIX);
 
		this->GetWidget<NWidgetCore>(NCLWW_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		this->vscroll->SetCapacityFromWidget(this, NCLWW_MATRIX);
 
		this->GetWidget<NWidgetCore>(NCLWW_MATRIX)->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 

	
 
	virtual void OnReceiveContentInfo(const ContentInfo *rci)
 
	{
 
		this->content.ForceRebuild();
 
		this->InvalidateData();
src/network/network_gui.cpp
Show inline comments
 
@@ -251,12 +251,13 @@ protected:
 

	
 
	byte field;                   ///< selected text-field
 
	NetworkGameList *server;      ///< selected server
 
	NetworkGameList *last_joined; ///< the last joined server
 
	GUIGameServerList servers;    ///< list with game servers.
 
	ServerListPosition list_pos;  ///< position of the selected server
 
	Scrollbar *vscroll;
 

	
 
	/**
 
	 * (Re)build the network game list as its amount has changed because
 
	 * an item has been added or deleted for example
 
	 */
 
	void BuildNetworkGameList()
 
@@ -269,13 +270,13 @@ protected:
 
		for (NetworkGameList *ngl = _network_game_list; ngl != NULL; ngl = ngl->next) {
 
			*this->servers.Append() = ngl;
 
		}
 

	
 
		this->servers.Compact();
 
		this->servers.RebuildDone();
 
		this->vscroll.SetCount(this->servers.Length());
 
		this->vscroll->SetCount(this->servers.Length());
 
	}
 

	
 
	/** Sort servers by name. */
 
	static int CDECL NGameNameSorter(NetworkGameList * const *a, NetworkGameList * const *b)
 
	{
 
		return strcasecmp((*a)->info.server_name, (*b)->info.server_name);
 
@@ -440,19 +441,21 @@ protected:
 
	 * If the server is above the currently displayed servers, it will
 
	 * scroll up so that the server appears at the top.
 
	 */
 
	void ScrollToSelectedServer()
 
	{
 
		if (this->list_pos == SLP_INVALID) return; // no server selected
 
		this->vscroll.ScrollTowards(this->list_pos);
 
		this->vscroll->ScrollTowards(this->list_pos);
 
	}
 

	
 
public:
 
	NetworkGameWindow(const WindowDesc *desc) : QueryStringBaseWindow(NETWORK_CLIENT_NAME_LENGTH)
 
	{
 
		this->InitNested(desc, 0);
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(NGWW_SCROLLBAR);
 
		this->FinishInitNested(desc, 0);
 

	
 
		ttd_strlcpy(this->edit_str_buf, _settings_client.network.client_name, this->edit_str_size);
 
		this->afilter = CS_ALPHANUMERAL;
 
		InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 120);
 
		this->SetFocusedWidget(NGWW_CLIENT);
 

	
 
@@ -536,15 +539,15 @@ public:
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		switch (widget) {
 
			case NGWW_MATRIX: {
 
				uint16 y = r.top + WD_MATRIX_TOP;
 

	
 
				const int max = min(this->vscroll.GetPosition() + this->vscroll.GetCapacity(), (int)this->servers.Length());
 
				const int max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), (int)this->servers.Length());
 

	
 
				for (int i = this->vscroll.GetPosition(); i < max; ++i) {
 
				for (int i = this->vscroll->GetPosition(); i < max; ++i) {
 
					const NetworkGameList *ngl = this->servers[i];
 
					this->DrawServerLine(ngl, y, ngl == this->server);
 
					y += this->resize.step_height;
 
				}
 
				break;
 
			}
 
@@ -693,13 +696,13 @@ public:
 
				}
 
				this->ScrollToSelectedServer();
 
				this->SetDirty();
 
				break;
 

	
 
			case NGWW_MATRIX: { // Matrix to show networkgames
 
				uint id_v = this->vscroll.GetScrolledRowFromWidget(pt.y, this, NGWW_MATRIX);
 
				uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, NGWW_MATRIX);
 
				this->server = (id_v < this->servers.Length()) ? this->servers[id_v] : NULL;
 
				this->list_pos = (server == NULL) ? SLP_INVALID : id_v;
 
				this->SetDirty();
 

	
 
				/* FIXME the disabling should go into some InvalidateData, which is called instead of the SetDirty */
 
				if (click_count > 1 && !this->IsWidgetDisabled(NGWW_JOIN)) this->OnClick(pt, NGWW_JOIN, 1);
 
@@ -840,18 +843,18 @@ public:
 
					if (this->server == NULL) return ES_HANDLED;
 
					if (this->list_pos < this->servers.Length() - 1) this->list_pos++;
 
					break;
 
				case WKC_PAGEUP:
 
					/* scroll up a page */
 
					if (this->server == NULL) return ES_HANDLED;
 
					this->list_pos = (this->list_pos < this->vscroll.GetCapacity()) ? 0 : this->list_pos - this->vscroll.GetCapacity();
 
					this->list_pos = (this->list_pos < this->vscroll->GetCapacity()) ? 0 : this->list_pos - this->vscroll->GetCapacity();
 
					break;
 
				case WKC_PAGEDOWN:
 
					/* scroll down a page */
 
					if (this->server == NULL) return ES_HANDLED;
 
					this->list_pos = min(this->list_pos + this->vscroll.GetCapacity(), (int)this->servers.Length() - 1);
 
					this->list_pos = min(this->list_pos + this->vscroll->GetCapacity(), (int)this->servers.Length() - 1);
 
					break;
 
				case WKC_HOME:
 
					/* jump to beginning */
 
					this->list_pos = 0;
 
					break;
 
				case WKC_END:
 
@@ -897,14 +900,14 @@ public:
 
	{
 
		if (!StrEmpty(str)) NetworkAddServer(str);
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, NGWW_MATRIX);
 
		this->GetWidget<NWidgetCore>(NGWW_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		this->vscroll->SetCapacityFromWidget(this, NGWW_MATRIX);
 
		this->GetWidget<NWidgetCore>(NGWW_MATRIX)->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 
};
 

	
 
Listing NetworkGameWindow::last_sorting = {false, 5};
 
GUIGameServerList::SortFunction * const NetworkGameWindow::sorter_funcs[] = {
 
	&NGameNameSorter,
 
@@ -1052,23 +1055,26 @@ enum NetworkStartServerWidgets {
 
};
 

	
 
struct NetworkStartServerWindow : public QueryStringBaseWindow {
 
	byte field;                  ///< Selected text-field
 
	FiosItem *map;               ///< Selected map
 
	byte widget_id;              ///< The widget that has the pop-up input menu
 
	Scrollbar *vscroll;
 

	
 
	NetworkStartServerWindow(const WindowDesc *desc) : QueryStringBaseWindow(NETWORK_NAME_LENGTH)
 
	{
 
		this->InitNested(desc, 0);
 

	
 
		this->vscroll = this->GetScrollbar(NSSW_SCROLLBAR);
 

	
 
		ttd_strlcpy(this->edit_str_buf, _settings_client.network.server_name, this->edit_str_size);
 

	
 
		_saveload_mode = SLD_NEW_GAME;
 
		BuildFileList();
 
		this->vscroll.SetCapacity(14);
 
		this->vscroll.SetCount(_fios_items.Length() + 1);
 
		this->vscroll->SetCapacity(14);
 
		this->vscroll->SetCount(_fios_items.Length() + 1);
 

	
 
		this->afilter = CS_ALPHANUMERAL;
 
		InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 160);
 
		this->SetFocusedWidget(NSSW_GAMENAME);
 

	
 
		this->field = NSSW_GAMENAME;
 
@@ -1140,26 +1146,26 @@ struct NetworkStartServerWindow : public
 
	void DrawMapSelection(const Rect &r) const
 
	{
 
		int y = r.top + WD_FRAMERECT_TOP;
 
		/* draw list of maps */
 
		GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, 0xD7);  // black background of maps list
 

	
 
		for (uint pos = this->vscroll.GetPosition(); pos < _fios_items.Length() + 1; pos++) {
 
		for (uint pos = this->vscroll->GetPosition(); pos < _fios_items.Length() + 1; pos++) {
 
			const FiosItem *item = (pos == 0) ? NULL : _fios_items.Get(pos - 1);
 
			if (item == this->map) { // this->map == NULL for first item
 
				GfxFillRect(r.left + 1, y, r.right - 1, y + FONT_HEIGHT_NORMAL - 1, 155); // show highlighted item with a different colour
 
			}
 

	
 
			if (pos == 0) {
 
				DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_START_SERVER_SERVER_RANDOM_GAME, TC_DARK_GREEN);
 
			} else {
 
				DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, item->title, _fios_colours[item->type] );
 
			}
 
			y += FONT_HEIGHT_NORMAL;
 

	
 
			if (y >= this->vscroll.GetCapacity() * FONT_HEIGHT_NORMAL + r.top) break;
 
			if (y >= this->vscroll->GetCapacity() * FONT_HEIGHT_NORMAL + r.top) break;
 
		}
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		this->field = widget;
 
@@ -1172,14 +1178,14 @@ struct NetworkStartServerWindow : public
 
				this->widget_id = NSSW_SETPWD;
 
				SetDParamStr(0, _settings_client.network.server_password);
 
				ShowQueryString(STR_JUST_RAW_STRING, STR_NETWORK_START_SERVER_SET_PASSWORD, 20, 250, this, CS_ALPHANUMERAL, QSF_NONE);
 
				break;
 

	
 
			case NSSW_SELMAP: { // Select map
 
				int y = this->vscroll.GetScrolledRowFromWidget(pt.y, this, NSSW_SELMAP, WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL);
 
				if (y >= this->vscroll.GetCount()) return;
 
				int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, NSSW_SELMAP, WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL);
 
				if (y >= this->vscroll->GetCount()) return;
 

	
 
				this->map = (y == 0) ? NULL : _fios_items.Get(y - 1);
 
				this->SetDirty();
 
				break;
 
			}
 

	
 
@@ -1451,17 +1457,20 @@ enum NetworkLobbyWindowWidgets {
 
};
 

	
 
struct NetworkLobbyWindow : public Window {
 
	CompanyID company;       ///< Select company
 
	NetworkGameList *server; ///< Selected server
 
	NetworkCompanyInfo company_info[MAX_COMPANIES];
 
	Scrollbar *vscroll;
 

	
 
	NetworkLobbyWindow(const WindowDesc *desc, NetworkGameList *ngl) :
 
			Window(), company(INVALID_COMPANY), server(ngl)
 
	{
 
		this->InitNested(desc, 0);
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(NLWW_SCROLLBAR);
 
		this->FinishInitNested(desc, 0);
 
		this->OnResize();
 
	}
 

	
 
	CompanyID NetworkLobbyFindCompanyIndex(byte pos) const
 
	{
 
		/* Scroll through all this->company_info and get the 'pos' item that is not empty */
 
@@ -1522,13 +1531,13 @@ struct NetworkLobbyWindow : public Windo
 
		this->SetWidgetDisabledState(NLWW_JOIN, this->company == INVALID_COMPANY || GetLobbyCompanyInfo(this->company)->ai);
 
		/* Cannot start new company if there are too many */
 
		this->SetWidgetDisabledState(NLWW_NEW, gi->companies_on >= gi->companies_max);
 
		/* Cannot spectate if there are too many spectators */
 
		this->SetWidgetDisabledState(NLWW_SPECTATE, gi->spectators_on >= gi->spectators_max);
 

	
 
		this->vscroll.SetCount(gi->companies_on);
 
		this->vscroll->SetCount(gi->companies_on);
 

	
 
		/* Draw window widgets */
 
		this->DrawWidgets();
 
	}
 

	
 
	void DrawMatrix(const Rect &r) const
 
@@ -1541,13 +1550,13 @@ struct NetworkLobbyWindow : public Windo
 
		uint text_right = right - (rtl ? 0 : 20);
 
		uint blob_left  = rtl ? left : right - 10;
 
		uint lock_left  = rtl ? left + 10 : right - 20;
 

	
 
		int y = r.top + WD_MATRIX_TOP;
 
		/* Draw company list */
 
		int pos = this->vscroll.GetPosition();
 
		int pos = this->vscroll->GetPosition();
 
		while (pos < this->server->info.companies_on) {
 
			byte company = NetworkLobbyFindCompanyIndex(pos);
 
			bool income = false;
 
			if (this->company == company) {
 
				GfxFillRect(r.left + 1, y - 2, r.right - 1, y + FONT_HEIGHT_NORMAL, 10); // show highlighted item with a different colour
 
			}
 
@@ -1558,13 +1567,13 @@ struct NetworkLobbyWindow : public Windo
 
			/* If the company's income was positive puts a green dot else a red dot */
 
			if (this->company_info[company].income >= 0) income = true;
 
			DrawSprite(SPR_BLOT, income ? PALETTE_TO_GREEN : PALETTE_TO_RED, blob_left, y + (FONT_HEIGHT_NORMAL - 10) / 2);
 

	
 
			pos++;
 
			y += this->resize.step_height;
 
			if (pos >= this->vscroll.GetPosition() + this->vscroll.GetCapacity()) break;
 
			if (pos >= this->vscroll->GetPosition() + this->vscroll->GetCapacity()) break;
 
		}
 
	}
 

	
 
	void DrawDetails(const Rect &r) const
 
	{
 
		const int detail_height = 12 + FONT_HEIGHT_NORMAL + 12;
 
@@ -1633,13 +1642,13 @@ struct NetworkLobbyWindow : public Windo
 
		switch (widget) {
 
			case NLWW_CANCEL:   // Cancel button
 
				ShowNetworkGameWindow();
 
				break;
 

	
 
			case NLWW_MATRIX: { // Company list
 
				uint id_v = this->vscroll.GetScrolledRowFromWidget(pt.y, this, NLWW_MATRIX);
 
				uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, NLWW_MATRIX);
 
				this->company = (id_v >= this->server->info.companies_on) ? INVALID_COMPANY : NetworkLobbyFindCompanyIndex(id_v);
 
				this->SetDirty();
 

	
 
				/* FIXME the disabling should go into some InvalidateData, which is called instead of the SetDirty */
 
				if (click_count > 1 && !this->IsWidgetDisabled(NLWW_JOIN)) this->OnClick(pt, NLWW_JOIN, 1);
 
				break;
 
@@ -1666,14 +1675,14 @@ struct NetworkLobbyWindow : public Windo
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, NLWW_MATRIX);
 
		this->GetWidget<NWidgetCore>(NLWW_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		this->vscroll->SetCapacityFromWidget(this, NLWW_MATRIX);
 
		this->GetWidget<NWidgetCore>(NLWW_MATRIX)->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 
};
 

	
 
static const NWidgetPart _nested_network_lobby_window_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
src/newgrf_debug_gui.cpp
Show inline comments
 
@@ -248,27 +248,31 @@ struct NewGRFInspectWindow : Window {
 
	/** The value for the variable 60 parameters. */
 
	static byte var60params[GSF_FAKE_END][0x20];
 

	
 
	/** The currently editted parameter, to update the right one. */
 
	byte current_edit_param;
 

	
 
	Scrollbar *vscroll;
 

	
 
	/**
 
	 * Check whether the given variable has a parameter.
 
	 * @param variable the variable to check.
 
	 * @return true iff the variable has a parameter.
 
	 */
 
	static bool HasVariableParameter(uint variable)
 
	{
 
		return IsInsideBS(variable, 0x60, 0x20);
 
	}
 

	
 
	NewGRFInspectWindow(const WindowDesc *desc, WindowNumber wno) : Window()
 
	{
 
		this->InitNested(desc, wno);
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(NIW_SCROLLBAR);
 
		this->FinishInitNested(desc, wno);
 

	
 
		this->vscroll.SetCount(0);
 
		this->vscroll->SetCount(0);
 
		this->SetWidgetDisabledState(NIW_PARENT, GetFeatureHelper(this->window_number)->GetParent(GetFeatureIndex(this->window_number)) == UINT32_MAX);
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		if (widget != NIW_CAPTION) return;
 
@@ -298,14 +302,14 @@ struct NewGRFInspectWindow : Window {
 

	
 
		va_list va;
 
		va_start(va, format);
 
		vsnprintf(buf, lengthof(buf), format, va);
 
		va_end(va);
 

	
 
		offset -= this->vscroll.GetPosition();
 
		if (offset < 0 || offset >= this->vscroll.GetCapacity()) return;
 
		offset -= this->vscroll->GetPosition();
 
		if (offset < 0 || offset >= this->vscroll->GetCapacity()) return;
 

	
 
		::DrawString(r.left + LEFT_OFFSET, r.right + RIGHT_OFFSET, r.top + TOP_OFFSET + (offset * this->resize.step_height), buf, TC_BLACK);
 
	}
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
@@ -398,13 +402,13 @@ struct NewGRFInspectWindow : Window {
 
			}
 
		}
 

	
 
		/* Not nice and certainly a hack, but it beats duplicating
 
		 * this whole function just to count the actual number of
 
		 * elements. Especially because they need to be redrawn. */
 
		const_cast<NewGRFInspectWindow*>(this)->vscroll.SetCount(i);
 
		const_cast<NewGRFInspectWindow*>(this)->vscroll->SetCount(i);
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		this->DrawWidgets();
 
	}
 
@@ -421,13 +425,13 @@ struct NewGRFInspectWindow : Window {
 
			case NIW_MAINPANEL: {
 
				/* Does this feature have variables? */
 
				const NIFeature *nif  = GetFeature(this->window_number);
 
				if (nif->variables == NULL) return;
 

	
 
				/* Get the line, make sure it's within the boundaries. */
 
				int line = this->vscroll.GetScrolledRowFromWidget(pt.y, this, NIW_MAINPANEL, TOP_OFFSET);
 
				int line = this->vscroll->GetScrolledRowFromWidget(pt.y, this, NIW_MAINPANEL, TOP_OFFSET);
 
				if (line == INT_MAX) return;
 

	
 
				/* Find the variable related to the line */
 
				for (const NIVariable *niv = nif->variables; niv->name != NULL; niv++, line--) {
 
					if (line != 1) continue; // 1 because of the "Variables:" line
 

	
 
@@ -447,13 +451,13 @@ struct NewGRFInspectWindow : Window {
 
		NewGRFInspectWindow::var60params[GetFeatureIndex(this->window_number)][this->current_edit_param - 0x60] = strtol(str, NULL, 16);
 
		this->SetDirty();
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, NIW_MAINPANEL, TOP_OFFSET + BOTTOM_OFFSET);
 
		this->vscroll->SetCapacityFromWidget(this, NIW_MAINPANEL, TOP_OFFSET + BOTTOM_OFFSET);
 
	}
 
};
 

	
 
/* static */ byte NewGRFInspectWindow::var60params[GSF_FAKE_END][0x20] = { {0} }; // Use spec to have 0s in whole array
 

	
 
static const NWidgetPart _nested_newgrf_inspect_widgets[] = {
 
@@ -557,16 +561,19 @@ enum SpriteAlignerWidgets {
 
	SAW_SCROLLBAR,///< Scrollbar for sprite list
 
};
 

	
 
/** Window used for aligning sprites. */
 
struct SpriteAlignerWindow : Window {
 
	SpriteID current_sprite; ///< The currently shown sprite
 
	Scrollbar *vscroll;
 

	
 
	SpriteAlignerWindow(const WindowDesc *desc, WindowNumber wno) : Window()
 
	{
 
		this->InitNested(desc, wno);
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(SAW_SCROLLBAR);
 
		this->FinishInitNested(desc, wno);
 

	
 
		/* Oh yes, we assume there is at least one normal sprite! */
 
		while (GetSpriteType(this->current_sprite) != ST_NORMAL) this->current_sprite++;
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
@@ -625,16 +632,16 @@ struct SpriteAlignerWindow : Window {
 

	
 
			case SAW_LIST: {
 
				const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
 
				int step_size = nwid->resize_y;
 

	
 
				SmallVector<SpriteID, 256> &list = _newgrf_debug_sprite_picker.sprites;
 
				int max = min<int>(this->vscroll.GetPosition() + this->vscroll.GetCapacity(), list.Length());
 
				int max = min<int>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), list.Length());
 

	
 
				int y = r.top + WD_FRAMERECT_TOP;
 
				for (int i = this->vscroll.GetPosition(); i < max; i++) {
 
				for (int i = this->vscroll->GetPosition(); i < max; i++) {
 
					SetDParam(0, list[i]);
 
					DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_BLACK_COMMA, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
 
					y += step_size;
 
				}
 
				break;
 
			}
 
@@ -674,13 +681,13 @@ struct SpriteAlignerWindow : Window {
 
				break;
 

	
 
			case SAW_LIST: {
 
				const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
 
				int step_size = nwid->resize_y;
 

	
 
				uint i = this->vscroll.GetPosition() + (pt.y - nwid->pos_y) / step_size;
 
				uint i = this->vscroll->GetPosition() + (pt.y - nwid->pos_y) / step_size;
 
				if (i < _newgrf_debug_sprite_picker.sprites.Length()) {
 
					SpriteID spr = _newgrf_debug_sprite_picker.sprites[i];
 
					if (GetSpriteType(spr) == ST_NORMAL) this->current_sprite = spr;
 
				}
 
				this->SetDirty();
 
				break;
 
@@ -732,20 +739,20 @@ struct SpriteAlignerWindow : Window {
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		if (data == 1) {
 
			/* Sprite picker finished */
 
			this->RaiseWidget(SAW_PICKER);
 
			this->vscroll.SetCount(_newgrf_debug_sprite_picker.sprites.Length());
 
			this->vscroll->SetCount(_newgrf_debug_sprite_picker.sprites.Length());
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, SAW_LIST);
 
		this->GetWidget<NWidgetCore>(SAW_LIST)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		this->vscroll->SetCapacityFromWidget(this, SAW_LIST);
 
		this->GetWidget<NWidgetCore>(SAW_LIST)->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 
};
 

	
 
static const NWidgetPart _nested_sprite_aligner_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
src/newgrf_gui.cpp
Show inline comments
 
@@ -139,22 +139,24 @@ struct NewGRFParametersWindow : public W
 
	GRFConfig *grf_config; ///< Set the parameters of this GRFConfig.
 
	uint clicked_button;   ///< The row in which a button was clicked or UINT_MAX.
 
	bool clicked_increase; ///< True if the increase button was clicked, false for the decrease button.
 
	int timeout;           ///< How long before we unpress the last-pressed button?
 
	uint clicked_row;      ///< The selected parameter
 
	int line_height;       ///< Height of a row in the matrix widget.
 
	Scrollbar *vscroll;
 

	
 
	NewGRFParametersWindow(const WindowDesc *desc, GRFConfig *c) : Window(),
 
		grf_config(c),
 
		clicked_button(UINT_MAX),
 
		timeout(0),
 
		clicked_row(UINT_MAX)
 
	{
 
		this->InitNested(desc);  // Initializes 'this->line_height' as side effect.
 

	
 
		this->vscroll.SetCount(c->num_valid_params);
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(GRFPAR_WIDGET_SCROLLBAR);
 
		this->FinishInitNested(desc);  // Initializes 'this->line_height' as side effect.
 
		this->vscroll->SetCount(c->num_valid_params);
 
	}
 

	
 
	/**
 
	 * Get a dummy parameter-info object with default information.
 
	 * @param nr The param number that should be changed.
 
	 * @return GRFParameterInfo with dummy information about the given parameter.
 
@@ -205,13 +207,13 @@ struct NewGRFParametersWindow : public W
 
		uint value_left   = r.left + (rtl ? WD_FRAMERECT_LEFT : 28);
 
		uint value_right  = r.right - (rtl ? 28 : WD_FRAMERECT_RIGHT);
 
		uint text_left    = r.left + (rtl ? WD_FRAMERECT_LEFT : 54);
 
		uint text_right   = r.right - (rtl ? 54 : WD_FRAMERECT_RIGHT);
 

	
 
		int y = r.top;
 
		for (uint i = this->vscroll.GetPosition(); this->vscroll.IsVisible(i) && i < this->grf_config->num_valid_params; i++) {
 
		for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->grf_config->num_valid_params; i++) {
 
			GRFParameterInfo *par_info = (i < this->grf_config->param_info.Length()) ? this->grf_config->param_info[i] : NULL;
 
			if (par_info == NULL) par_info = GetDummyParameterInfo(i);
 
			uint32 current_value = par_info->GetValue(this->grf_config);
 
			bool selected = (i == this->clicked_row);
 

	
 
			uint x = rtl ? r.right : r.left;
 
@@ -253,13 +255,13 @@ struct NewGRFParametersWindow : public W
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		switch (widget) {
 
			case GRFPAR_WIDGET_BACKGROUND: {
 
				uint num = this->vscroll.GetScrolledRowFromWidget(pt.y, this, GRFPAR_WIDGET_BACKGROUND);
 
				uint num = this->vscroll->GetScrolledRowFromWidget(pt.y, this, GRFPAR_WIDGET_BACKGROUND);
 
				if (num >= this->grf_config->num_valid_params) break;
 
				if (this->clicked_row != num) {
 
					DeleteChildWindows(WC_QUERY_STRING);
 
					this->clicked_row = num;
 
				}
 

	
 
@@ -318,14 +320,14 @@ struct NewGRFParametersWindow : public W
 
		this->SetDirty();
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(GRFPAR_WIDGET_BACKGROUND);
 
		this->vscroll.SetCapacity(nwi->current_y / this->line_height);
 
		nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		this->vscroll->SetCapacity(nwi->current_y / this->line_height);
 
		nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 

	
 
	virtual void OnTick()
 
	{
 
		if (--this->timeout == 0) {
 
			this->clicked_button = UINT_MAX;
 
@@ -435,12 +437,15 @@ struct NewGRFWindow : public QueryString
 
	GRFConfig **orig_list;      ///< List active grfs in the game. Used as initial value, may be updated by the window.
 
	bool editable;              ///< Is the window editable?
 
	bool show_params;           ///< Are the grf-parameters shown in the info-panel?
 
	bool execute;               ///< On pressing 'apply changes' are grf changes applied immediately, or only list is updated.
 
	int preset;                 ///< Selected preset.
 

	
 
	Scrollbar *vscroll;
 
	Scrollbar *vscroll2;
 

	
 
	NewGRFWindow(const WindowDesc *desc, bool editable, bool show_params, bool execute, GRFConfig **orig_list) : QueryStringBaseWindow(EDITBOX_MAX_SIZE)
 
	{
 
		this->avail_sel   = NULL;
 
		this->avail_pos   = -1;
 
		this->active_sel  = NULL;
 
		this->actives     = NULL;
 
@@ -450,13 +455,17 @@ struct NewGRFWindow : public QueryString
 
		this->show_params = show_params;
 
		this->preset      = -1;
 

	
 
		CopyGRFConfigList(&this->actives, *orig_list, false);
 
		GetGRFPresetList(&_grf_preset_list);
 

	
 
		this->InitNested(desc);
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(SNGRFS_SCROLLBAR);
 
		this->vscroll2 = this->GetScrollbar(SNGRFS_SCROLL2BAR);
 
		this->FinishInitNested(desc);
 

	
 
		InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, EDITBOX_MAX_LENGTH);
 
		this->SetFocusedWidget(SNGRFS_FILTER);
 

	
 
		this->avails.SetListing(this->last_sorting);
 
		this->avails.SetFiltering(this->last_filtering);
 
		this->avails.SetSortFuncs(this->sorter_funcs);
 
@@ -527,14 +536,14 @@ struct NewGRFWindow : public QueryString
 
			}
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, SNGRFS_FILE_LIST);
 
		this->vscroll2.SetCapacityFromWidget(this, SNGRFS_AVAIL_LIST);
 
		this->vscroll->SetCapacityFromWidget(this, SNGRFS_FILE_LIST);
 
		this->vscroll2->SetCapacityFromWidget(this, SNGRFS_AVAIL_LIST);
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		switch (widget) {
 
			case SNGRFS_PRESET_LIST:
 
@@ -605,13 +614,13 @@ struct NewGRFWindow : public QueryString
 
				uint text_right   = rtl ? r.right - 25 : r.right - WD_FRAMERECT_RIGHT;
 
				uint square_left  = rtl ? r.right - 15 : r.left + 5;
 
				uint warning_left = rtl ? r.right - 30 : r.left + 20;
 

	
 
				int i = 0;
 
				for (const GRFConfig *c = this->actives; c != NULL; c = c->next, i++) {
 
					if (this->vscroll.IsVisible(i)) {
 
					if (this->vscroll->IsVisible(i)) {
 
						const char *text = c->GetName();
 
						bool h = (this->active_sel == c);
 
						PaletteID pal = this->GetPalette(c);
 

	
 
						if (h) GfxFillRect(r.left + 1, y, r.right - 1, y + step_height - 1, 156);
 
						DrawSprite(SPR_SQUARE, pal, square_left, y + sprite_offset_y);
 
@@ -627,14 +636,14 @@ struct NewGRFWindow : public QueryString
 
			case SNGRFS_AVAIL_LIST: {
 
				GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, 0xD7);
 

	
 
				uint step_height = this->GetWidget<NWidgetBase>(SNGRFS_AVAIL_LIST)->resize_y;
 
				int offset_y = (step_height - FONT_HEIGHT_NORMAL) / 2;
 
				uint y = r.top + WD_FRAMERECT_TOP;
 
				uint min_index = this->vscroll2.GetPosition();
 
				uint max_index = min(min_index + this->vscroll2.GetCapacity(), this->avails.Length());
 
				uint min_index = this->vscroll2->GetPosition();
 
				uint max_index = min(min_index + this->vscroll2->GetCapacity(), this->avails.Length());
 

	
 
				for (uint i = min_index; i < max_index; i++) {
 
					const GRFConfig *c = this->avails[i];
 
					bool h = (c == this->avail_sel);
 
					const char *text = c->GetName();
 

	
 
@@ -706,13 +715,13 @@ struct NewGRFWindow : public QueryString
 
						c->next = this->active_sel->next;
 
						this->active_sel->next = c;
 
						*pc = this->active_sel;
 
						break;
 
					}
 
				}
 
				this->vscroll.ScrollTowards(pos);
 
				this->vscroll->ScrollTowards(pos);
 
				this->preset = -1;
 
				this->InvalidateData();
 
				break;
 
			}
 

	
 
			case SNGRFS_MOVE_DOWN: { // Move GRF down
 
@@ -725,20 +734,20 @@ struct NewGRFWindow : public QueryString
 
						*pc = c->next;
 
						c->next = c->next->next;
 
						(*pc)->next = c;
 
						break;
 
					}
 
				}
 
				this->vscroll.ScrollTowards(pos);
 
				this->vscroll->ScrollTowards(pos);
 
				this->preset = -1;
 
				this->InvalidateData();
 
				break;
 
			}
 

	
 
			case SNGRFS_FILE_LIST: { // Select an active GRF.
 
				uint i = this->vscroll.GetScrolledRowFromWidget(pt.y, this, SNGRFS_FILE_LIST);
 
				uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, SNGRFS_FILE_LIST);
 

	
 
				GRFConfig *c;
 
				for (c = this->actives; c != NULL && i > 0; c = c->next, i--) {}
 

	
 
				if (this->active_sel != c) DeleteWindowByClass(WC_GRF_PARAMETERS);
 
				this->active_sel = c;
 
@@ -776,13 +785,13 @@ struct NewGRFWindow : public QueryString
 
				this->avails.ForceRebuild();
 
				this->InvalidateData(2);
 
				break;
 
			}
 

	
 
			case SNGRFS_AVAIL_LIST: { // Select a non-active GRF.
 
				uint i = this->vscroll2.GetScrolledRowFromWidget(pt.y, this, SNGRFS_AVAIL_LIST);
 
				uint i = this->vscroll2->GetScrolledRowFromWidget(pt.y, this, SNGRFS_AVAIL_LIST);
 
				this->active_sel = NULL;
 
				DeleteWindowByClass(WC_GRF_PARAMETERS);
 
				if (i < this->avails.Length()) {
 
					this->avail_sel = this->avails[i];
 
					this->avail_pos = i;
 
				}
 
@@ -967,17 +976,17 @@ struct NewGRFWindow : public QueryString
 
				this->preset = -1;
 
				/* FALL THROUGH */
 
			case 3: {
 
				int i = 0;
 
				for (const GRFConfig *c = this->actives; c != NULL; c = c->next, i++) {}
 

	
 
				this->vscroll.SetCapacityFromWidget(this, SNGRFS_FILE_LIST);
 
				this->vscroll.SetCount(i);
 
				this->vscroll->SetCapacityFromWidget(this, SNGRFS_FILE_LIST);
 
				this->vscroll->SetCount(i);
 

	
 
				this->vscroll2.SetCapacityFromWidget(this, SNGRFS_AVAIL_LIST);
 
				if (this->avail_pos >= 0) this->vscroll2.ScrollTowards(this->avail_pos);
 
				this->vscroll2->SetCapacityFromWidget(this, SNGRFS_AVAIL_LIST);
 
				if (this->avail_pos >= 0) this->vscroll2->ScrollTowards(this->avail_pos);
 
				break;
 
			}
 
		}
 

	
 
		this->BuildAvailables();
 

	
 
@@ -1041,18 +1050,18 @@ struct NewGRFWindow : public QueryString
 
				/* scroll down by one */
 
				if (this->avail_pos < (int)this->avails.Length() - 1) this->avail_pos++;
 
				break;
 

	
 
			case WKC_PAGEUP:
 
				/* scroll up a page */
 
				this->avail_pos = (this->avail_pos < this->vscroll2.GetCapacity()) ? 0 : this->avail_pos - this->vscroll2.GetCapacity();
 
				this->avail_pos = (this->avail_pos < this->vscroll2->GetCapacity()) ? 0 : this->avail_pos - this->vscroll2->GetCapacity();
 
				break;
 

	
 
			case WKC_PAGEDOWN:
 
				/* scroll down a page */
 
				this->avail_pos = min(this->avail_pos + this->vscroll2.GetCapacity(), (int)this->avails.Length() - 1);
 
				this->avail_pos = min(this->avail_pos + this->vscroll2->GetCapacity(), (int)this->avails.Length() - 1);
 
				break;
 

	
 
			case WKC_HOME:
 
				/* jump to beginning */
 
				this->avail_pos = 0;
 
				break;
 
@@ -1072,13 +1081,13 @@ struct NewGRFWindow : public QueryString
 
			}
 
		}
 

	
 
		if (this->avails.Length() == 0) this->avail_pos = -1;
 
		if (this->avail_pos >= 0) {
 
			this->avail_sel = this->avails[this->avail_pos];
 
			this->vscroll2.ScrollTowards(this->avail_pos);
 
			this->vscroll2->ScrollTowards(this->avail_pos);
 
			this->InvalidateData(0);
 
		}
 

	
 
		return ES_HANDLED;
 
	}
 

	
 
@@ -1146,13 +1155,13 @@ private:
 

	
 
		if (this->avail_sel != NULL) {
 
			this->avail_pos = this->avails.FindIndex(this->avail_sel);
 
			if (this->avail_pos < 0) this->avail_sel = NULL;
 
		}
 

	
 
		this->vscroll2.SetCount(this->avails.Length()); // Update the scrollbar
 
		this->vscroll2->SetCount(this->avails.Length()); // Update the scrollbar
 
	}
 
};
 

	
 
Listing NewGRFWindow::last_sorting     = {false, 0};
 
Filtering NewGRFWindow::last_filtering = {false, 0};
 

	
src/news_gui.cpp
Show inline comments
 
@@ -948,15 +948,19 @@ struct MessageHistoryWindow : Window {
 
	static const int top_spacing;    ///< Additional spacing at the top of the #MHW_BACKGROUND widget.
 
	static const int bottom_spacing; ///< Additional spacing at the bottom of the #MHW_BACKGROUND widget.
 

	
 
	int line_height; /// < Height of a single line in the news histoy window including spacing.
 
	int date_width;  /// < Width needed for the date part.
 

	
 
	Scrollbar *vscroll;
 

	
 
	MessageHistoryWindow(const WindowDesc *desc) : Window()
 
	{
 
		this->InitNested(desc); // Initializes 'this->line_height' and 'this->date_width'.
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(MHW_SCROLLBAR);
 
		this->FinishInitNested(desc); // Initializes 'this->line_height' and 'this->date_width'.
 
		this->OnInvalidateData(0);
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		if (widget == MHW_BACKGROUND) {
 
@@ -980,25 +984,25 @@ struct MessageHistoryWindow : Window {
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		if (widget != MHW_BACKGROUND || _total_news == 0) return;
 

	
 
		/* Find the first news item to display. */
 
		NewsItem *ni = _latest_news;
 
		for (int n = this->vscroll.GetPosition(); n > 0; n--) {
 
		for (int n = this->vscroll->GetPosition(); n > 0; n--) {
 
			ni = ni->prev;
 
			if (ni == NULL) return;
 
		}
 

	
 
		/* Fill the widget with news items. */
 
		int y = r.top + this->top_spacing;
 
		bool rtl = _dynlang.text_dir == TD_RTL;
 
		uint date_left  = rtl ? r.right - WD_FRAMERECT_RIGHT - this->date_width : r.left + WD_FRAMERECT_LEFT;
 
		uint date_right = rtl ? r.right - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT + this->date_width;
 
		uint news_left  = rtl ? r.left + WD_FRAMERECT_LEFT : r.left + WD_FRAMERECT_LEFT + this->date_width + WD_FRAMERECT_RIGHT;
 
		uint news_right = rtl ? r.right - WD_FRAMERECT_RIGHT - this->date_width - WD_FRAMERECT_RIGHT : r.right - WD_FRAMERECT_RIGHT;
 
		for (int n = this->vscroll.GetCapacity(); n > 0; n--) {
 
		for (int n = this->vscroll->GetCapacity(); n > 0; n--) {
 
			SetDParam(0, ni->date);
 
			DrawString(date_left, date_right, y, STR_SHORT_DATE);
 

	
 
			DrawNewsString(news_left, news_right, y, TC_WHITE, ni);
 
			y += this->line_height;
 

	
 
@@ -1006,33 +1010,33 @@ struct MessageHistoryWindow : Window {
 
			if (ni == NULL) return;
 
		}
 
	}
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		this->vscroll.SetCount(_total_news);
 
		this->vscroll->SetCount(_total_news);
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		if (widget == MHW_BACKGROUND) {
 
			NewsItem *ni = _latest_news;
 
			if (ni == NULL) return;
 

	
 
			for (int n = this->vscroll.GetScrolledRowFromWidget(pt.y, this, MHW_BACKGROUND, WD_FRAMERECT_TOP, this->line_height); n > 0; n--) {
 
			for (int n = this->vscroll->GetScrolledRowFromWidget(pt.y, this, MHW_BACKGROUND, WD_FRAMERECT_TOP, this->line_height); n > 0; n--) {
 
				ni = ni->prev;
 
				if (ni == NULL) return;
 
			}
 

	
 
			ShowNewsMessage(ni);
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(MHW_BACKGROUND)->current_y / this->line_height);
 
		this->vscroll->SetCapacity(this->GetWidget<NWidgetBase>(MHW_BACKGROUND)->current_y / this->line_height);
 
	}
 
};
 

	
 
const int MessageHistoryWindow::top_spacing = WD_FRAMERECT_TOP + 4;
 
const int MessageHistoryWindow::bottom_spacing = WD_FRAMERECT_BOTTOM;
 

	
src/order_gui.cpp
Show inline comments
 
@@ -463,12 +463,13 @@ private:
 
	};
 

	
 
	int selected_order;
 
	OrderID order_over;     ///< Order over which another order is dragged, \c INVALID_ORDER if none.
 
	OrderPlaceObjectState goto_type;
 
	const Vehicle *vehicle; ///< Vehicle owning the orders being displayed and manipulated.
 
	Scrollbar *vscroll;
 

	
 
	/**
 
	 * Return the memorised selected order.
 
	 * @return the memorised order if it is a vaild one
 
	 *  else return the number of orders
 
	 */
 
@@ -488,15 +489,15 @@ private:
 
	 */
 
	int GetOrderFromPt(int y)
 
	{
 
		NWidgetBase *nwid = this->GetWidget<NWidgetBase>(ORDER_WIDGET_ORDER_LIST);
 
		int sel = (y - nwid->pos_y - WD_FRAMERECT_TOP) / nwid->resize_y; // Selected line in the ORDER_WIDGET_ORDER_LIST panel.
 

	
 
		if ((uint)sel >= this->vscroll.GetCapacity()) return INVALID_ORDER;
 
		if ((uint)sel >= this->vscroll->GetCapacity()) return INVALID_ORDER;
 

	
 
		sel += this->vscroll.GetPosition();
 
		sel += this->vscroll->GetPosition();
 

	
 
		return (sel <= vehicle->GetNumOrders() && sel >= 0) ? sel : INVALID_ORDER;
 
	}
 

	
 
	bool HandleOrderVehClick(const Vehicle *u)
 
	{
 
@@ -707,13 +708,15 @@ private:
 

	
 
public:
 
	OrdersWindow(const WindowDesc *desc, const Vehicle *v) : Window()
 
	{
 
		this->vehicle = v;
 

	
 
		this->InitNested(desc, v->index);
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(ORDER_WIDGET_SCROLLBAR);
 
		this->FinishInitNested(desc, v->index);
 

	
 
		this->selected_order = -1;
 
		this->order_over = INVALID_ORDER;
 
		this->owner = v->owner;
 

	
 
		if (_settings_client.gui.quick_goto && v->owner == _local_company) {
 
@@ -816,13 +819,13 @@ public:
 
				/* Moving selected order */
 
				this->selected_order = to;
 
				break;
 
			}
 
		}
 

	
 
		this->vscroll.SetCount(this->vehicle->GetNumOrders() + 1);
 
		this->vscroll->SetCount(this->vehicle->GetNumOrders() + 1);
 
		this->UpdateButtonState();
 
	}
 

	
 
	void UpdateButtonState()
 
	{
 
		if (this->vehicle->owner != _local_company) return; // No buttons are displayed with competitor order windows.
 
@@ -965,19 +968,19 @@ public:
 
		int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
 
		int middle = rtl ? r.right - WD_FRAMETEXT_RIGHT - index_column_width : r.left + WD_FRAMETEXT_LEFT + index_column_width;
 

	
 
		int y = r.top + WD_FRAMERECT_TOP;
 
		int line_height = this->GetWidget<NWidgetBase>(ORDER_WIDGET_ORDER_LIST)->resize_y;
 

	
 
		int i = this->vscroll.GetPosition();
 
		int i = this->vscroll->GetPosition();
 
		const Order *order = this->vehicle->GetOrder(i);
 
		/* First draw the highlighting underground if it exists. */
 
		if (this->order_over != INVALID_ORDER) {
 
			while (order != NULL) {
 
				/* Don't draw anything if it extends past the end of the window. */
 
				if (!this->vscroll.IsVisible(i)) break;
 
				if (!this->vscroll->IsVisible(i)) break;
 

	
 
				if (i != this->selected_order && i == this->order_over) {
 
					/* Highlight dragged order destination. */
 
					int top = (this->order_over < this->selected_order ? y : y + line_height) - WD_FRAMERECT_TOP;
 
					int bottom = min(top + 2, r.bottom - WD_FRAMERECT_BOTTOM);
 
					top = max(top - 3, r.top + WD_FRAMERECT_TOP);
 
@@ -989,29 +992,29 @@ public:
 
				i++;
 
				order = order->next;
 
			}
 

	
 
			/* Reset counters for drawing the orders. */
 
			y = r.top + WD_FRAMERECT_TOP;
 
			i = this->vscroll.GetPosition();
 
			i = this->vscroll->GetPosition();
 
			order = this->vehicle->GetOrder(i);
 
		}
 

	
 
		/* Draw the orders. */
 
		while (order != NULL) {
 
			/* Don't draw anything if it extends past the end of the window. */
 
			if (!this->vscroll.IsVisible(i)) break;
 
			if (!this->vscroll->IsVisible(i)) break;
 

	
 
			DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, r.left + WD_FRAMETEXT_LEFT, middle, r.right - WD_FRAMETEXT_RIGHT);
 
			y += line_height;
 

	
 
			i++;
 
			order = order->next;
 
		}
 

	
 
		if (this->vscroll.IsVisible(i)) {
 
		if (this->vscroll->IsVisible(i)) {
 
			StringID str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
 
			DrawString(rtl ? r.left + WD_FRAMETEXT_LEFT : middle, rtl ? middle : r.right - WD_FRAMETEXT_RIGHT, y, str, (i == this->selected_order) ? TC_WHITE : TC_BLACK);
 
		}
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
@@ -1337,13 +1340,13 @@ public:
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		/* Update the scroll bar */
 
		this->vscroll.SetCapacityFromWidget(this, ORDER_WIDGET_ORDER_LIST);
 
		this->vscroll->SetCapacityFromWidget(this, ORDER_WIDGET_ORDER_LIST);
 
	}
 

	
 
	virtual void OnTimeout()
 
	{
 
		static const int raise_widgets[] = {
 
			ORDER_WIDGET_TIMETABLE_VIEW, ORDER_WIDGET_SKIP, ORDER_WIDGET_DELETE, ORDER_WIDGET_REFIT, ORDER_WIDGET_SHARED_ORDER_LIST, WIDGET_LIST_END,
src/rail_gui.cpp
Show inline comments
 
@@ -991,12 +991,13 @@ enum BuildRailStationWidgets {
 
	BRSW_PLATFORM_LEN_BEGIN = BRSW_PLATFORM_LEN_1 - 1,
 
};
 

	
 
struct BuildRailStationWindow : public PickerWindowBase {
 
private:
 
	uint line_height; ///< Height of a single line in the newstation selection matrix (#BRSW_NEWST_LIST widget).
 
	Scrollbar *vscroll;
 

	
 
	/**
 
	 * Verify whether the currently selected station size is allowed after selecting a new station class/type.
 
	 * If not, change the station size variables ( _settings_client.gui.station_numtracks and _settings_client.gui.station_platlength ).
 
	 * @param statspec Specification of the new station class/type
 
	 */
 
@@ -1038,12 +1039,13 @@ private:
 
	}
 

	
 
public:
 
	BuildRailStationWindow(const WindowDesc *desc, Window *parent, bool newstation) : PickerWindowBase(parent)
 
	{
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(BRSW_NEWST_SCROLL);
 
		NWidgetStacked *newst_additions = this->GetWidget<NWidgetStacked>(BRSW_SHOW_NEWST_ADDITIONS);
 
		newst_additions->SetDisplayedPlane(newstation ? 0 : SZSP_NONE);
 
		this->FinishInitNested(desc, TRANSPORT_RAIL);
 

	
 
		this->LowerWidget(_railstation.orientation + BRSW_PLATFORM_DIR_X);
 
		if (_settings_client.gui.station_dragdrop) {
 
@@ -1057,15 +1059,15 @@ public:
 

	
 
		_railstation.newstations = newstation;
 

	
 
		if (newstation) {
 
			_railstation.station_count = StationClass::GetCount(_railstation.station_class);
 

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

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

	
 
					StringID str = STR_STATION_CLASS_DFLT;
 
					if (statspec != NULL && statspec->name != 0) {
 
						if (HasBit(statspec->callback_mask, 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);
 
@@ -1339,13 +1341,13 @@ public:
 

	
 
			case BRSW_NEWST_DROPDOWN:
 
				ShowDropDownList(this, BuildStationClassDropDown(), _railstation.station_class, BRSW_NEWST_DROPDOWN);
 
				break;
 

	
 
			case BRSW_NEWST_LIST: {
 
				int y = this->vscroll.GetScrolledRowFromWidget(pt.y, this, BRSW_NEWST_LIST, 0, this->line_height);
 
				int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, BRSW_NEWST_LIST, 0, this->line_height);
 
				if (y >= _railstation.station_count) return;
 

	
 
				/* Check station availability callback */
 
				const StationSpec *statspec = StationClass::Get(_railstation.station_class, y);
 
				if (statspec != NULL && HasBit(statspec->callback_mask, CBM_STATION_AVAIL) &&
 
						GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) return;
 
@@ -1368,14 +1370,14 @@ public:
 
			_railstation.station_class = (StationClassID)index;
 
			_railstation.station_type  = 0;
 
			_railstation.station_count = StationClass::GetCount(_railstation.station_class);
 

	
 
			this->CheckSelectedSize(StationClass::Get(_railstation.station_class, _railstation.station_type));
 

	
 
			this->vscroll.SetCount(_railstation.station_count);
 
			this->vscroll.SetPosition(_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);
 
	}
 
@@ -1768,34 +1770,37 @@ enum BuildRailWaypointWidgets {
 
	BRWW_WAYPOINT_4,
 
	BRWW_WAYPOINT_5,
 
	BRWW_SCROLL,
 
};
 

	
 
struct BuildRailWaypointWindow : PickerWindowBase {
 
	Scrollbar *hscroll;
 

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

	
 
	virtual void OnPaint()
 
	{
 
		for (uint i = 0; i < this->hscroll.GetCapacity(); i++) {
 
			this->SetWidgetLoweredState(i + BRWW_WAYPOINT_1, (this->hscroll.GetPosition() + 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.GetCapacity(); i++) {
 
			if (this->hscroll.GetPosition() + i < this->hscroll.GetCount()) {
 
				const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP, this->hscroll.GetPosition() + i);
 
		for (uint i = 0; i < this->hscroll->GetCapacity(); i++) {
 
			if (this->hscroll->GetPosition() + i < this->hscroll->GetCount()) {
 
				const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP, this->hscroll->GetPosition() + i);
 
				NWidgetBase *nw = this->GetWidget<NWidgetBase>(BRWW_WAYPOINT_1 + i);
 

	
 
				int bottom = nw->pos_y + nw->current_y;
 
				DrawWaypointSprite(nw->pos_x + TILE_PIXELS, bottom - TILE_PIXELS, this->hscroll.GetPosition() + i, _cur_railtype);
 
				DrawWaypointSprite(nw->pos_x + TILE_PIXELS, bottom - TILE_PIXELS, this->hscroll->GetPosition() + i, _cur_railtype);
 

	
 
				if (statspec != NULL &&
 
						HasBit(statspec->callback_mask, CBM_STATION_AVAIL) &&
 
						GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) {
 
					GfxFillRect(nw->pos_x + 1, nw->pos_y + 1, nw->pos_x + nw->current_x - 2, bottom - 2, 0, FILLRECT_CHECKER);
 
				}
 
@@ -1808,13 +1813,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.GetPosition();
 
				byte type = widget - BRWW_WAYPOINT_1 + this->hscroll->GetPosition();
 

	
 
				/* Check station availability callback */
 
				const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP, type);
 
				if (statspec != NULL &&
 
						HasBit(statspec->callback_mask, 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
 
@@ -1501,12 +1501,14 @@ struct GameSettingsWindow : Window {
 

	
 
	static GameSettings *settings_ptr;  ///< Pointer to the game settings being displayed and modified
 

	
 
	SettingEntry *valuewindow_entry; ///< If non-NULL, pointer to setting for which a value-entering window has been opened
 
	SettingEntry *clicked_entry; ///< If non-NULL, pointer to a clicked numeric setting (with a depressed left or right button)
 

	
 
	Scrollbar *vscroll;
 

	
 
	GameSettingsWindow(const WindowDesc *desc) : Window()
 
	{
 
		static bool first_time = true;
 

	
 
		settings_ptr = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game;
 

	
 
@@ -1518,15 +1520,17 @@ struct GameSettingsWindow : Window {
 
			_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->InitNested(desc, 0);
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(SETTINGSEL_SCROLLBAR);
 
		this->FinishInitNested(desc, 0);
 

	
 
		this->vscroll.SetCount(_settings_main_page.Length());
 
		this->vscroll->SetCount(_settings_main_page.Length());
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		if (widget != SETTINGSEL_OPTIONSPANEL) return;
 

	
 
@@ -1538,25 +1542,25 @@ struct GameSettingsWindow : Window {
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		if (widget != SETTINGSEL_OPTIONSPANEL) return;
 

	
 
		_settings_main_page.Draw(settings_ptr, r.left + SETTINGTREE_LEFT_OFFSET, r.right - SETTINGTREE_RIGHT_OFFSET, r.top + SETTINGTREE_TOP_OFFSET,
 
				this->vscroll.GetPosition(), this->vscroll.GetPosition() + this->vscroll.GetCapacity());
 
				this->vscroll->GetPosition(), this->vscroll->GetPosition() + this->vscroll->GetCapacity());
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		this->DrawWidgets();
 
	}
 

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

	
 
		uint btn = this->vscroll.GetScrolledRowFromWidget(pt.y, this, SETTINGSEL_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET - 1);
 
		uint btn = this->vscroll->GetScrolledRowFromWidget(pt.y, this, SETTINGSEL_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET - 1);
 
		if (btn == INT_MAX) return;
 

	
 
		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
 
@@ -1564,13 +1568,13 @@ struct GameSettingsWindow : Window {
 
		int x = (_dynlang.text_dir == TD_RTL ? this->width - pt.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
 

	
 
			this->vscroll.SetCount(_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;
 
@@ -1692,13 +1696,13 @@ struct GameSettingsWindow : Window {
 
		}
 
		this->SetDirty();
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, SETTINGSEL_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET);
 
		this->vscroll->SetCapacityFromWidget(this, SETTINGSEL_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET);
 
	}
 
};
 

	
 
GameSettings *GameSettingsWindow::settings_ptr = NULL;
 

	
 
static const NWidgetPart _nested_settings_selection_widgets[] = {
src/signs_gui.cpp
Show inline comments
 
@@ -87,23 +87,26 @@ enum SignListWidgets {
 
	SLW_LIST,
 
	SLW_SCROLLBAR,
 
};
 

	
 
struct SignListWindow : Window, SignList {
 
	int text_offset; // Offset of the sign text relative to the left edge of the SLW_LIST widget.
 
	Scrollbar *vscroll;
 

	
 
	SignListWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
 
	{
 
		this->InitNested(desc, window_number);
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(SLW_SCROLLBAR);
 
		this->FinishInitNested(desc, window_number);
 

	
 
		/* Create initial list. */
 
		this->signs.ForceRebuild();
 
		this->signs.ForceResort();
 
		this->BuildSignsList();
 
		this->SortSignsList();
 
		this->vscroll.SetCount(this->signs.Length());
 
		this->vscroll->SetCount(this->signs.Length());
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		this->DrawWidgets();
 
	}
 
@@ -111,25 +114,25 @@ struct SignListWindow : Window, SignList
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		switch (widget) {
 
			case SLW_LIST: {
 
				uint y = r.top + WD_FRAMERECT_TOP; // Offset from top of widget.
 
				/* No signs? */
 
				if (this->vscroll.GetCount() == 0) {
 
				if (this->vscroll->GetCount() == 0) {
 
					DrawString(r.left + WD_FRAMETEXT_LEFT, r.right, y, STR_STATION_LIST_NONE);
 
					return;
 
				}
 

	
 
				bool rtl = _dynlang.text_dir == TD_RTL;
 
				int sprite_offset_y = (FONT_HEIGHT_NORMAL - 10) / 2 + 1;
 
				uint icon_left  = 4 + (rtl ? r.right - this->text_offset : r.left);
 
				uint text_left  = r.left + (rtl ? WD_FRAMERECT_LEFT : this->text_offset);
 
				uint text_right = r.right - (rtl ? this->text_offset : WD_FRAMERECT_RIGHT);
 

	
 
				/* At least one sign available. */
 
				for (uint16 i = this->vscroll.GetPosition(); this->vscroll.IsVisible(i) && i < this->vscroll.GetCount(); 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, icon_left, y + sprite_offset_y);
 

	
 
					SetDParam(0, si->index);
 
					DrawString(text_left, text_right, y, STR_SIGN_NAME, TC_YELLOW);
 
@@ -139,29 +142,29 @@ struct SignListWindow : Window, SignList
 
			}
 
		}
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		if (widget == SLW_CAPTION) SetDParam(0, this->vscroll.GetCount());
 
		if (widget == SLW_CAPTION) SetDParam(0, this->vscroll->GetCount());
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		if (widget == SLW_LIST) {
 
			uint id_v = this->vscroll.GetScrolledRowFromWidget(pt.y, this, SLW_LIST, WD_FRAMERECT_TOP);
 
			uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, SLW_LIST, WD_FRAMERECT_TOP);
 
			if (id_v == INT_MAX) return;
 

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

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, SLW_LIST, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
 
		this->vscroll->SetCapacityFromWidget(this, SLW_LIST, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		switch (widget) {
 
			case SLW_LIST: {
 
@@ -185,13 +188,13 @@ struct SignListWindow : Window, SignList
 
	virtual void OnInvalidateData(int data)
 
	{
 
		if (data == 0) { // New or deleted sign.
 
			this->signs.ForceRebuild();
 
			this->BuildSignsList();
 
			this->SetWidgetDirty(SLW_CAPTION);
 
			this->vscroll.SetCount(this->signs.Length());
 
			this->vscroll->SetCount(this->signs.Length());
 
		} else { // Change of sign contents.
 
			this->signs.ForceResort();
 
		}
 

	
 
		this->SortSignsList();
 
	}
src/station_gui.cpp
Show inline comments
 
@@ -214,13 +214,13 @@ protected:
 

	
 
	/* Constants for sorting stations */
 
	static const StringID sorter_names[];
 
	static GUIStationList::SortFunction * const sorter_funcs[];
 

	
 
	GUIStationList stations;
 

	
 
	Scrollbar *vscroll;
 

	
 
	/**
 
	 * (Re)Build station list
 
	 *
 
	 * @param owner company whose stations are to be in list
 
	 */
 
@@ -254,13 +254,13 @@ protected:
 
			}
 
		}
 

	
 
		this->stations.Compact();
 
		this->stations.RebuildDone();
 

	
 
		this->vscroll.SetCount(this->stations.Length()); // Update the scrollbar
 
		this->vscroll->SetCount(this->stations.Length()); // Update the scrollbar
 
	}
 

	
 
	/** Sort stations by their name */
 
	static int CDECL StationNameSorter(const Station * const *a, const Station * const *b)
 
	{
 
		static char buf_cache[64];
 
@@ -346,13 +346,15 @@ public:
 
		this->stations.SetListing(this->last_sorting);
 
		this->stations.SetSortFuncs(this->sorter_funcs);
 
		this->stations.ForceRebuild();
 
		this->stations.NeedResort();
 
		this->SortStationsList();
 

	
 
		this->InitNested(desc, window_number);
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(SLW_SCROLLBAR);
 
		this->FinishInitNested(desc, window_number);
 
		this->owner = (Owner)this->window_number;
 

	
 
		CargoID cid;
 
		FOR_EACH_SET_CARGO_ID(cid, this->cargo_filter) {
 
			if (CargoSpec::Get(cid)->IsValid()) this->LowerWidget(SLW_CARGOSTART + cid);
 
		}
 
@@ -446,15 +448,15 @@ public:
 
				/* draw arrow pointing up/down for ascending/descending sorting */
 
				this->DrawSortButtonState(SLW_SORTBY, this->stations.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
 
				break;
 

	
 
			case SLW_LIST: {
 
				bool rtl = _dynlang.text_dir == TD_RTL;
 
				int max = min(this->vscroll.GetPosition() + this->vscroll.GetCapacity(), this->stations.Length());
 
				int max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->stations.Length());
 
				int y = r.top + WD_FRAMERECT_TOP;
 
				for (int i = this->vscroll.GetPosition(); i < max; ++i) { // do until max number of stations of owner
 
				for (int i = this->vscroll->GetPosition(); i < max; ++i) { // do until max number of stations of owner
 
					const Station *st = this->stations[i];
 
					assert(st->xy != INVALID_TILE);
 

	
 
					/* Do not do the complex check HasStationInUse here, it may be even false
 
					 * when the order had been removed and the station list hasn't been removed yet */
 
					assert(st->owner == owner || st->owner == OWNER_NONE);
 
@@ -482,13 +484,13 @@ public:
 
							}
 
						}
 
					}
 
					y += FONT_HEIGHT_NORMAL;
 
				}
 

	
 
				if (this->vscroll.GetCount() == 0) { // company has no stations
 
				if (this->vscroll->GetCount() == 0) { // company has no stations
 
					DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_STATION_LIST_NONE);
 
					return;
 
				}
 
				break;
 
			}
 

	
 
@@ -524,21 +526,21 @@ public:
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		if (widget == SLW_CAPTION) {
 
			SetDParam(0, this->window_number);
 
			SetDParam(1, this->vscroll.GetCount());
 
			SetDParam(1, this->vscroll->GetCount());
 
		}
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		switch (widget) {
 
			case SLW_LIST: {
 
				uint id_v = this->vscroll.GetScrolledRowFromWidget(pt.y, this, SLW_LIST, 0, FONT_HEIGHT_NORMAL);
 
				uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, SLW_LIST, 0, FONT_HEIGHT_NORMAL);
 
				if (id_v >= this->stations.Length()) return; // click out of list bound
 

	
 
				const Station *st = this->stations[id_v];
 
				/* do not check HasStationInUse - it is slow and may be invalid */
 
				assert(st->owner == (Owner)this->window_number || st->owner == OWNER_NONE);
 

	
 
@@ -679,13 +681,13 @@ public:
 
		this->RaiseWidget(SLW_SORTBY);
 
		this->SetDirty();
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, SLW_LIST, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
 
		this->vscroll->SetCapacityFromWidget(this, SLW_LIST, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
 
	}
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		if (data == 0) {
 
			this->stations.ForceRebuild();
 
@@ -875,12 +877,13 @@ typedef std::list<CargoData> CargoDataLi
 
struct StationViewWindow : public Window {
 
	uint32 cargo;                 ///< Bitmask of cargo types to expand
 
	uint16 cargo_rows[NUM_CARGO]; ///< Header row for each cargo type
 
	uint expand_shrink_width;     ///< The width allocated to the expand/shrink 'button'
 
	int rating_lines;             ///< Number of lines in the cargo ratings view.
 
	int accepts_lines;            ///< Number of lines in the accepted cargo view.
 
	Scrollbar *vscroll;
 

	
 
	/** Height of the #SVW_ACCEPTLIST widget for different views. */
 
	enum AcceptListHeight {
 
		ALH_RATING  = 13, ///< Height of the cargo ratings view.
 
		ALH_ACCEPTS = 3,  ///< Height of the accepted cargo view.
 
	};
 
@@ -888,12 +891,13 @@ struct StationViewWindow : public Window
 
	StationViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
 
	{
 
		this->rating_lines  = ALH_RATING;
 
		this->accepts_lines = ALH_ACCEPTS;
 

	
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(SVW_SCROLLBAR);
 
		/* Nested widget tree creation is done in two steps to ensure that this->GetWidget<NWidgetCore>(SVW_ACCEPTS) exists in UpdateWidgetSize(). */
 
		this->FinishInitNested(desc, window_number);
 

	
 
		Owner owner = Station::Get(window_number)->owner;
 
		if (owner != OWNER_NONE) this->owner = owner;
 
	}
 
@@ -926,13 +930,13 @@ struct StationViewWindow : public Window
 
	virtual void OnPaint()
 
	{
 
		CargoDataList cargolist;
 
		uint32 transfers = 0;
 
		this->OrderWaitingCargo(&cargolist, &transfers);
 

	
 
		this->vscroll.SetCount((int)cargolist.size() + 1); // update scrollbar
 
		this->vscroll->SetCount((int)cargolist.size() + 1); // update scrollbar
 

	
 
		/* disable some buttons */
 
		const Station *st = Station::Get(this->window_number);
 
		this->SetWidgetDisabledState(SVW_RENAME,   st->owner != _local_company);
 
		this->SetWidgetDisabledState(SVW_TRAINS,   !(st->facilities & FACIL_TRAIN));
 
		this->SetWidgetDisabledState(SVW_ROADVEHS, !(st->facilities & FACIL_TRUCK_STOP) && !(st->facilities & FACIL_BUS_STOP));
 
@@ -1038,13 +1042,13 @@ struct StationViewWindow : public Window
 
	 * @param cargolist Cargo, ordered by type and destination.
 
	 * @param transfers Bitmask for cargoes that are transfered.
 
	 */
 
	void DrawWaitingCargo(const Rect &r, const CargoDataList &cargolist, uint32 transfers) const
 
	{
 
		int y = r.top + WD_FRAMERECT_TOP;
 
		int pos = this->vscroll.GetPosition();
 
		int pos = this->vscroll->GetPosition();
 

	
 
		const Station *st = Station::Get(this->window_number);
 
		if (--pos < 0) {
 
			StringID str = STR_JUST_NOTHING;
 
			for (CargoID i = 0; i < NUM_CARGO; i++) {
 
				if (!st->goods[i].cargo.Empty()) str = STR_EMPTY;
 
@@ -1058,13 +1062,13 @@ struct StationViewWindow : public Window
 
		int text_left    = rtl ? r.left + this->expand_shrink_width : r.left + WD_FRAMERECT_LEFT;
 
		int text_right   = rtl ? r.right - WD_FRAMERECT_LEFT : r.right - this->expand_shrink_width;
 
		int shrink_left  = rtl ? r.left + WD_FRAMERECT_LEFT : r.right - this->expand_shrink_width + WD_FRAMERECT_LEFT;
 
		int shrink_right = rtl ? r.left + this->expand_shrink_width - WD_FRAMERECT_RIGHT : r.right - WD_FRAMERECT_RIGHT;
 

	
 

	
 
		int maxrows = this->vscroll.GetCapacity();
 
		int maxrows = this->vscroll->GetCapacity();
 
		for (CargoDataList::const_iterator it = cargolist.begin(); it != cargolist.end() && pos > -maxrows; ++it) {
 
			if (--pos < 0) {
 
				const CargoData *cd = &(*it);
 
				if (cd->source == INVALID_STATION) {
 
					/* Heading */
 
					DrawCargoIcons(cd->cargo, cd->count, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y);
 
@@ -1149,13 +1153,13 @@ struct StationViewWindow : public Window
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		switch (widget) {
 
			case SVW_WAITING:
 
				this->HandleCargoWaitingClick(this->vscroll.GetScrolledRowFromWidget(pt.y, this, SVW_WAITING, WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL));
 
				this->HandleCargoWaitingClick(this->vscroll->GetScrolledRowFromWidget(pt.y, this, SVW_WAITING, WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL));
 
				break;
 

	
 
			case SVW_LOCATION:
 
				if (_ctrl_pressed) {
 
					ShowExtraViewPortWindow(Station::Get(this->window_number)->xy);
 
				} else {
 
@@ -1199,13 +1203,13 @@ struct StationViewWindow : public Window
 

	
 
		DoCommandP(0, this->window_number, 0, CMD_RENAME_STATION | CMD_MSG(STR_ERROR_CAN_T_RENAME_STATION), NULL, str);
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, SVW_WAITING, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
 
		this->vscroll->SetCapacityFromWidget(this, SVW_WAITING, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
 
	}
 
};
 

	
 

	
 
static const WindowDesc _station_view_desc(
 
	WDP_AUTO, 249, 110,
 
@@ -1351,19 +1355,21 @@ static const NWidgetPart _nested_select_
 
 * @tparam T The type of station to join with
 
 */
 
template <class T>
 
struct SelectStationWindow : Window {
 
	CommandContainer select_station_cmd; ///< Command to build new station
 
	TileArea area; ///< Location of new station
 
	Scrollbar *vscroll;
 

	
 
	SelectStationWindow(const WindowDesc *desc, CommandContainer cmd, TileArea ta) :
 
		Window(),
 
		select_station_cmd(cmd),
 
		area(ta)
 
	{
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(JSW_SCROLLBAR);
 
		this->GetWidget<NWidgetCore>(JSW_WIDGET_CAPTION)->widget_data = T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CAPTION : STR_JOIN_STATION_CAPTION;
 
		this->FinishInitNested(desc, 0);
 
		this->OnInvalidateData(0);
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
@@ -1393,33 +1399,33 @@ struct SelectStationWindow : Window {
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		if (widget != JSW_PANEL) return;
 

	
 
		uint y = r.top + WD_FRAMERECT_TOP;
 
		if (this->vscroll.GetPosition() == 0) {
 
		if (this->vscroll->GetPosition() == 0) {
 
			DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CREATE_SPLITTED_WAYPOINT : STR_JOIN_STATION_CREATE_SPLITTED_STATION);
 
			y += this->resize.step_height;
 
		}
 

	
 
		for (uint i = max<uint>(1, this->vscroll.GetPosition()); i <= _stations_nearby_list.Length(); ++i, y += this->resize.step_height) {
 
		for (uint i = max<uint>(1, this->vscroll->GetPosition()); i <= _stations_nearby_list.Length(); ++i, y += this->resize.step_height) {
 
			/* Don't draw anything if it extends past the end of the window. */
 
			if (i - this->vscroll.GetPosition() >= this->vscroll.GetCapacity()) break;
 
			if (i - this->vscroll->GetPosition() >= this->vscroll->GetCapacity()) break;
 

	
 
			const T *st = T::Get(_stations_nearby_list[i - 1]);
 
			SetDParam(0, st->index);
 
			SetDParam(1, st->facilities);
 
			DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_STATION_LIST_WAYPOINT : STR_STATION_LIST_STATION);
 
		}
 
	}
 

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

	
 
		uint st_index = this->vscroll.GetScrolledRowFromWidget(pt.y, this, JSW_PANEL, WD_FRAMERECT_TOP);
 
		uint st_index = this->vscroll->GetScrolledRowFromWidget(pt.y, this, JSW_PANEL, WD_FRAMERECT_TOP);
 
		bool distant_join = (st_index > 0);
 
		if (distant_join) st_index--;
 

	
 
		if (distant_join && st_index >= _stations_nearby_list.Length()) return;
 

	
 
		/* Insert station to be joined into stored command */
 
@@ -1440,19 +1446,19 @@ struct SelectStationWindow : Window {
 
			this->SetDirty();
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, JSW_PANEL, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
 
		this->vscroll->SetCapacityFromWidget(this, JSW_PANEL, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
 
	}
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		FindStationsNearby<T>(this->area, true);
 
		this->vscroll.SetCount(_stations_nearby_list.Length() + 1);
 
		this->vscroll->SetCount(_stations_nearby_list.Length() + 1);
 
		this->SetDirty();
 
	}
 
};
 

	
 
static const WindowDesc _select_station_desc(
 
	WDP_AUTO, 200, 180,
src/subsidy_gui.cpp
Show inline comments
 
@@ -28,23 +28,27 @@
 
enum SubsidyListWidgets {
 
	SLW_PANEL,
 
	SLW_SCROLLBAR,
 
};
 

	
 
struct SubsidyListWindow : Window {
 
	Scrollbar *vscroll;
 

	
 
	SubsidyListWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
 
	{
 
		this->InitNested(desc, window_number);
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(SLW_SCROLLBAR);
 
		this->FinishInitNested(desc, window_number);
 
		this->OnInvalidateData(0);
 
	}
 

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

	
 
		int y = this->vscroll.GetScrolledRowFromWidget(pt.y, this, SLW_PANEL, WD_FRAMERECT_TOP);
 
		int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, SLW_PANEL, WD_FRAMERECT_TOP);
 
		int num = 0;
 
		const Subsidy *s;
 
		FOR_ALL_SUBSIDIES(s) {
 
			if (!s->IsAwarded()) {
 
				y--;
 
				if (y == 0) {
 
@@ -154,14 +158,14 @@ struct SubsidyListWindow : Window {
 
		ConvertDateToYMD(_date, &ymd);
 

	
 
		int right = r.right - WD_FRAMERECT_RIGHT;
 
		int y = r.top + WD_FRAMERECT_TOP;
 
		int x = r.left + WD_FRAMERECT_LEFT;
 

	
 
		int pos = -this->vscroll.GetPosition();
 
		const int cap = this->vscroll.GetCapacity();
 
		int pos = -this->vscroll->GetPosition();
 
		const int cap = this->vscroll->GetCapacity();
 

	
 
		/* Section for drawing the offered subisidies */
 
		if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_OFFERED_TITLE);
 
		pos++;
 

	
 
		uint num = 0;
 
@@ -210,18 +214,18 @@ struct SubsidyListWindow : Window {
 
			pos++;
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, SLW_PANEL);
 
		this->vscroll->SetCapacityFromWidget(this, SLW_PANEL);
 
	}
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		this->vscroll.SetCount(this->CountLines());
 
		this->vscroll->SetCount(this->CountLines());
 
	}
 
};
 

	
 
static const NWidgetPart _nested_subsidies_list_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
src/timetable_gui.cpp
Show inline comments
 
@@ -169,20 +169,23 @@ static void ChangeTimetableStartCallback
 
struct TimetableWindow : Window {
 
	int sel_index;
 
	const Vehicle *vehicle; ///< Vehicle monitored by the window.
 
	bool show_expected;     ///< Whether we show expected arrival or scheduled
 
	uint deparr_time_width; ///< The width of the departure/arrival time
 
	uint deparr_abbr_width; ///< The width of the departure/arrival abbreviation
 
	Scrollbar *vscroll;
 

	
 
	TimetableWindow(const WindowDesc *desc, WindowNumber window_number) :
 
			Window(),
 
			sel_index(-1),
 
			vehicle(Vehicle::Get(window_number)),
 
			show_expected(true)
 
	{
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(TTV_SCROLLBAR);
 
		// TODO TTV_FAKE_SCROLLBAR
 
		this->UpdateSelectionStates();
 
		this->FinishInitNested(desc, window_number);
 

	
 
		this->owner = this->vehicle->owner;
 
	}
 

	
 
@@ -226,15 +229,15 @@ struct TimetableWindow : Window {
 
	}
 

	
 
	int GetOrderFromTimetableWndPt(int y, const Vehicle *v)
 
	{
 
		int sel = (y - this->GetWidget<NWidgetBase>(TTV_TIMETABLE_PANEL)->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_NORMAL;
 

	
 
		if ((uint)sel >= this->vscroll.GetCapacity()) return INVALID_ORDER;
 
		if ((uint)sel >= this->vscroll->GetCapacity()) return INVALID_ORDER;
 

	
 
		sel += this->vscroll.GetPosition();
 
		sel += this->vscroll->GetPosition();
 

	
 
		return (sel < v->GetNumOrders() * 2 && sel >= 0) ? sel : INVALID_ORDER;
 
	}
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
@@ -305,13 +308,13 @@ struct TimetableWindow : Window {
 

	
 
	virtual void OnPaint()
 
	{
 
		const Vehicle *v = this->vehicle;
 
		int selected = this->sel_index;
 

	
 
		this->vscroll.SetCount(v->GetNumOrders() * 2);
 
		this->vscroll->SetCount(v->GetNumOrders() * 2);
 

	
 
		if (v->owner == _local_company) {
 
			bool disable = true;
 
			if (selected != -1) {
 
				const Order *order = v->GetOrder(((selected + 1) / 2) % v->GetNumOrders());
 
				if (selected % 2 == 1) {
 
@@ -355,25 +358,25 @@ struct TimetableWindow : Window {
 
		const Vehicle *v = this->vehicle;
 
		int selected = this->sel_index;
 

	
 
		switch (widget) {
 
			case TTV_TIMETABLE_PANEL: {
 
				int y = r.top + WD_FRAMERECT_TOP;
 
				int i = this->vscroll.GetPosition();
 
				int i = this->vscroll->GetPosition();
 
				VehicleOrderID order_id = (i + 1) / 2;
 
				bool final_order = false;
 

	
 
				bool rtl = _dynlang.text_dir == TD_RTL;
 
				SetDParam(0, 99);
 
				int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
 
				int middle = rtl ? r.right - WD_FRAMERECT_RIGHT - index_column_width : r.left + WD_FRAMERECT_LEFT + index_column_width;
 

	
 
				const Order *order = v->GetOrder(order_id);
 
				while (order != NULL) {
 
					/* Don't draw anything if it extends past the end of the window. */
 
					if (!this->vscroll.IsVisible(i)) break;
 
					if (!this->vscroll->IsVisible(i)) break;
 

	
 
					if (i % 2 == 0) {
 
						DrawOrderString(v, order, order_id, y, i == selected, true, r.left + WD_FRAMERECT_LEFT, middle, r.right - WD_FRAMERECT_RIGHT);
 

	
 
						order_id++;
 

	
 
@@ -427,15 +430,15 @@ struct TimetableWindow : Window {
 
				bool rtl = _dynlang.text_dir == TD_RTL;
 
				int abbr_left  = rtl ? r.right - WD_FRAMERECT_RIGHT - this->deparr_abbr_width : r.left + WD_FRAMERECT_LEFT;
 
				int abbr_right = rtl ? r.right - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT + this->deparr_abbr_width;
 
				int time_left  = rtl ? r.left + WD_FRAMERECT_LEFT : r.right - WD_FRAMERECT_RIGHT - this->deparr_time_width;
 
				int time_right = rtl ? r.left + WD_FRAMERECT_LEFT + this->deparr_time_width : r.right - WD_FRAMERECT_RIGHT;
 

	
 
				for (int i = this->vscroll.GetPosition(); i / 2 < v->GetNumOrders(); ++i) { // note: i is also incremented in the loop
 
				for (int i = this->vscroll->GetPosition(); i / 2 < v->GetNumOrders(); ++i) { // note: i is also incremented in the loop
 
					/* Don't draw anything if it extends past the end of the window. */
 
					if (!this->vscroll.IsVisible(i)) break;
 
					if (!this->vscroll->IsVisible(i)) break;
 

	
 
					if (i % 2 == 0) {
 
						if (arr_dep[i / 2].arrival != INVALID_TICKS) {
 
							DrawString(abbr_left, abbr_right, y, STR_TIMETABLE_ARRIVAL_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK);
 
							if (this->show_expected && i / 2 == earlyID) {
 
								SetArrivalDepartParams(0, 1, arr_dep[i / 2].arrival);
 
@@ -588,13 +591,13 @@ struct TimetableWindow : Window {
 
		DoCommandP(0, p1, p2, CMD_CHANGE_TIMETABLE | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		/* Update the scroll bar */
 
		this->vscroll.SetCapacityFromWidget(this, TTV_TIMETABLE_PANEL, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
 
		this->vscroll->SetCapacityFromWidget(this, TTV_TIMETABLE_PANEL, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
 
	}
 

	
 
	/**
 
	 * Update the selection state of the arrival/departure data
 
	 */
 
	void UpdateSelectionStates()
src/town_gui.cpp
Show inline comments
 
@@ -71,12 +71,13 @@ static const NWidgetPart _nested_town_au
 

	
 
/** Town authority window. */
 
struct TownAuthorityWindow : Window {
 
private:
 
	Town *town;    ///< Town being displayed.
 
	int sel_index; ///< Currently selected town action, \c 0 to \c TACT_COUNT-1, \c -1 means no action selected.
 
	Scrollbar *vscroll;
 

	
 
	/**
 
	 * Get the position of the Nth set bit.
 
	 *
 
	 * If there is no Nth bit set return -1
 
	 *
 
@@ -98,21 +99,22 @@ private:
 

	
 
public:
 
	TownAuthorityWindow(const WindowDesc *desc, WindowNumber window_number) : Window(), sel_index(-1)
 
	{
 
		this->town = Town::Get(window_number);
 
		this->InitNested(desc, window_number);
 
		this->vscroll.SetCapacity((this->GetWidget<NWidgetBase>(TWA_COMMAND_LIST)->current_y - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM) / FONT_HEIGHT_NORMAL);
 
		this->vscroll = this->GetScrollbar(TWA_SCROLLBAR);
 
		this->vscroll->SetCapacity((this->GetWidget<NWidgetBase>(TWA_COMMAND_LIST)->current_y - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM) / FONT_HEIGHT_NORMAL);
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		int numact;
 
		uint buttons = GetMaskOfTownActions(&numact, _local_company, this->town);
 

	
 
		this->vscroll.SetCount(numact + 1);
 
		this->vscroll->SetCount(numact + 1);
 

	
 
		if (this->sel_index != -1 && !HasBit(buttons, this->sel_index)) {
 
			this->sel_index = -1;
 
		}
 

	
 
		this->SetWidgetDisabledState(TWA_EXECUTE, this->sel_index == -1);
 
@@ -195,13 +197,13 @@ public:
 
				}
 
				break;
 
			case TWA_COMMAND_LIST: {
 
				int numact;
 
				uint buttons = GetMaskOfTownActions(&numact, _local_company, this->town);
 
				int y = r.top + WD_FRAMERECT_TOP;
 
				int pos = this->vscroll.GetPosition();
 
				int pos = this->vscroll->GetPosition();
 

	
 
				if (--pos < 0) {
 
					DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_LOCAL_AUTHORITY_ACTIONS_TITLE);
 
					y += FONT_HEIGHT_NORMAL;
 
				}
 

	
 
@@ -257,13 +259,13 @@ public:
 
	{
 
		switch (widget) {
 
			case TWA_COMMAND_LIST: {
 
				int y = this->GetRowFromWidget(pt.y, TWA_COMMAND_LIST, 1, FONT_HEIGHT_NORMAL);
 
				if (!IsInsideMM(y, 0, 5)) return;
 

	
 
				y = GetNthSetBit(GetMaskOfTownActions(NULL, _local_company, this->town), y + this->vscroll.GetPosition() - 1);
 
				y = GetNthSetBit(GetMaskOfTownActions(NULL, _local_company, this->town), y + this->vscroll->GetPosition() - 1);
 
				if (y >= 0) {
 
					this->sel_index = y;
 
					this->SetDirty();
 
				}
 
				/* FALL THROUGH, when double-clicking. */
 
				if (click_count == 1 || y < 0) break;
 
@@ -651,25 +653,27 @@ private:
 

	
 
	/* Constants for sorting towns */
 
	static GUITownList::SortFunction * const sorter_funcs[];
 

	
 
	GUITownList towns;
 

	
 
	Scrollbar *vscroll;
 

	
 
	void BuildSortTownList()
 
	{
 
		if (this->towns.NeedRebuild()) {
 
			this->towns.Clear();
 

	
 
			const Town *t;
 
			FOR_ALL_TOWNS(t) {
 
				*this->towns.Append() = t;
 
			}
 

	
 
			this->towns.Compact();
 
			this->towns.RebuildDone();
 
			this->vscroll.SetCount(this->towns.Length()); // Update scrollbar as well.
 
			this->vscroll->SetCount(this->towns.Length()); // Update scrollbar as well.
 
		}
 
		/* Always sort the towns. */
 
		this->last_town = NULL;
 
		this->towns.Sort();
 
	}
 

	
 
@@ -702,18 +706,22 @@ private:
 
		return (*a)->population - (*b)->population;
 
	}
 

	
 
public:
 
	TownDirectoryWindow(const WindowDesc *desc) : Window()
 
	{
 
		this->CreateNestedTree(desc);
 

	
 
		this->vscroll = this->GetScrollbar(TDW_SCROLLBAR);
 

	
 
		this->towns.SetListing(this->last_sorting);
 
		this->towns.SetSortFuncs(TownDirectoryWindow::sorter_funcs);
 
		this->towns.ForceRebuild();
 
		this->BuildSortTownList();
 

	
 
		this->InitNested(desc, 0);
 
		this->FinishInitNested(desc, 0);
 
	}
 

	
 
	~TownDirectoryWindow()
 
	{
 
		this->last_sorting = this->towns.GetListing();
 
	}
 
@@ -744,23 +752,23 @@ public:
 
				int y = r.top + WD_FRAMERECT_TOP;
 
				if (this->towns.Length() == 0) { // No towns available.
 
					DrawString(r.left + WD_FRAMERECT_LEFT, r.right, y, STR_TOWN_DIRECTORY_NONE);
 
					break;
 
				}
 
				/* At least one town available. */
 
				for (uint i = this->vscroll.GetPosition(); i < this->towns.Length(); i++) {
 
				for (uint i = this->vscroll->GetPosition(); i < this->towns.Length(); i++) {
 
					const Town *t = this->towns[i];
 

	
 
					assert(t->xy != INVALID_TILE);
 

	
 
					SetDParam(0, t->index);
 
					SetDParam(1, t->population);
 
					DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_TOWN_DIRECTORY_TOWN);
 

	
 
					y += this->resize.step_height;
 
					if (++n == this->vscroll.GetCapacity()) break; // max number of towns in 1 window
 
					if (++n == this->vscroll->GetCapacity()) break; // max number of towns in 1 window
 
				}
 
				break;
 
			}
 
		}
 
	}
 

	
 
@@ -824,13 +832,13 @@ public:
 
				}
 
				this->BuildSortTownList();
 
				this->SetDirty();
 
				break;
 

	
 
			case TDW_CENTERTOWN: { // Click on Town Matrix
 
				uint id_v = this->vscroll.GetScrolledRowFromWidget(pt.y, this, TDW_CENTERTOWN, WD_FRAMERECT_TOP);
 
				uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, TDW_CENTERTOWN, WD_FRAMERECT_TOP);
 
				if (id_v >= this->towns.Length()) return; // click out of town bounds
 

	
 
				const Town *t = this->towns[id_v];
 
				assert(t != NULL);
 
				if (_ctrl_pressed) {
 
					ShowExtraViewPortWindow(t->xy);
 
@@ -847,13 +855,13 @@ public:
 
		this->BuildSortTownList();
 
		this->SetDirty();
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, TDW_CENTERTOWN);
 
		this->vscroll->SetCapacityFromWidget(this, TDW_CENTERTOWN);
 
	}
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		if (data == 0) {
 
			this->towns.ForceRebuild();
src/vehicle_gui.cpp
Show inline comments
 
@@ -126,13 +126,13 @@ void BaseVehicleListWindow::BuildVehicle
 
		this->unitnumber_digits = 3;
 
	} else {
 
		this->unitnumber_digits = 2;
 
	}
 

	
 
	this->vehicles.RebuildDone();
 
	this->vscroll.SetCount(this->vehicles.Length());
 
	this->vscroll->SetCount(this->vehicles.Length());
 
}
 

	
 
/**
 
 * Compute the size for the Action dropdown.
 
 * @param show_autoreplace If true include the autoreplace item.
 
 * @param show_group If true include group-related stuff.
 
@@ -415,54 +415,56 @@ enum VehicleRefitWidgets {
 
/** Refit cargo window. */
 
struct RefitWindow : public Window {
 
	int sel;              ///< Index in refit options, \c -1 if nothing is selected.
 
	RefitOption *cargo;   ///< Refit option selected by \v sel.
 
	RefitList list;       ///< List of cargo types available for refitting.
 
	VehicleOrderID order; ///< If not #INVALID_VEH_ORDER_ID, selection is part of a refit order (rather than execute directly).
 
	Scrollbar *vscroll;
 

	
 
	RefitWindow(const WindowDesc *desc, const Vehicle *v, VehicleOrderID order) : Window()
 
	{
 
		this->CreateNestedTree(desc);
 

	
 
		this->vscroll = this->GetScrollbar(VRW_SCROLLBAR);
 
		this->GetWidget<NWidgetCore>(VRW_SELECTHEADER)->tool_tip = STR_REFIT_TRAIN_LIST_TOOLTIP + v->type;
 
		this->GetWidget<NWidgetCore>(VRW_MATRIX)->tool_tip       = STR_REFIT_TRAIN_LIST_TOOLTIP + v->type;
 
		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(VRW_REFITBUTTON);
 
		nwi->widget_data = STR_REFIT_TRAIN_REFIT_BUTTON + v->type;
 
		nwi->tool_tip    = STR_REFIT_TRAIN_REFIT_TOOLTIP + v->type;
 

	
 
		this->FinishInitNested(desc, v->index);
 
		this->owner = v->owner;
 

	
 
		this->order = order;
 
		this->sel  = -1;
 
		BuildRefitList(v, &this->list);
 
		this->vscroll.SetCount(this->list.Length());
 
		this->vscroll->SetCount(this->list.Length());
 
	}
 

	
 
	virtual void OnInit()
 
	{
 
		if (this->cargo != NULL) {
 
			/* Store the RefitOption currently in use. */
 
			RefitOption current_refit_option = *(this->cargo);
 

	
 
			/* Rebuild the refit list */
 
			BuildRefitList(Vehicle::Get(this->window_number), &this->list);
 
			this->vscroll.SetCount(this->list.Length());
 
			this->vscroll->SetCount(this->list.Length());
 
			this->sel = -1;
 
			this->cargo = NULL;
 
			for (uint i = 0; i < this->list.Length(); i++) {
 
				if (this->list[i] == current_refit_option) {
 
					this->sel = i;
 
					this->cargo = &this->list[i];
 
					this->vscroll.ScrollTowards(i);
 
					this->vscroll->ScrollTowards(i);
 
					break;
 
				}
 
			}
 

	
 
			/* If the selected refit option was not found, scroll the window to the initial position. */
 
			if (this->sel == -1) this->vscroll.ScrollTowards(0);
 
			if (this->sel == -1) this->vscroll->ScrollTowards(0);
 
		} else {
 
			/* Rebuild the refit list */
 
			this->OnInvalidateData(0);
 
		}
 
	}
 

	
 
@@ -487,13 +489,13 @@ struct RefitWindow : public Window {
 
	}
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		switch (widget) {
 
			case VRW_MATRIX:
 
				DrawVehicleRefitWindow(this->list, this->sel, this->vscroll.GetPosition(), this->vscroll.GetCapacity(), this->resize.step_height, r);
 
				DrawVehicleRefitWindow(this->list, this->sel, this->vscroll->GetPosition(), this->vscroll->GetCapacity(), this->resize.step_height, r);
 
				break;
 

	
 
			case VRW_INFOPANEL:
 
				if (this->cargo != NULL) {
 
					Vehicle *v = Vehicle::Get(this->window_number);
 
					CommandCost cost = DoCommand(v->tile, v->index, this->cargo->cargo | this->cargo->subtype << 8, DC_QUERY_COST, GetCmdRefitVeh(v->type));
 
@@ -512,13 +514,13 @@ struct RefitWindow : public Window {
 
	virtual void OnInvalidateData(int data)
 
	{
 
		switch (data) {
 
			case 0: { // The consist lenght of the vehicle has changed; rebuild the entire list.
 
				Vehicle *v = Vehicle::Get(this->window_number);
 
				BuildRefitList(v, &this->list);
 
				this->vscroll.SetCount(this->list.Length());
 
				this->vscroll->SetCount(this->list.Length());
 
				/* FALL THROUGH */
 
			}
 

	
 
			case 1: // A new cargo has been selected.
 
				this->cargo = (this->sel >= 0 && this->sel < (int)this->list.Length()) ? &this->list[this->sel] : NULL;
 
				break;
 
@@ -526,13 +528,13 @@ struct RefitWindow : public Window {
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		switch (widget) {
 
			case VRW_MATRIX: { // listbox
 
				this->sel = this->vscroll.GetScrolledRowFromWidget(pt.y, this, VRW_MATRIX);
 
				this->sel = this->vscroll->GetScrolledRowFromWidget(pt.y, this, VRW_MATRIX);
 
				this->InvalidateData(1);
 

	
 
				if (click_count == 1) break;
 
				/* FALL THROUGH */
 
			}
 

	
 
@@ -549,14 +551,14 @@ struct RefitWindow : public Window {
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, VRW_MATRIX);
 
		this->GetWidget<NWidgetCore>(VRW_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		this->vscroll->SetCapacityFromWidget(this, VRW_MATRIX);
 
		this->GetWidget<NWidgetCore>(VRW_MATRIX)->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 
};
 

	
 
static const NWidgetPart _nested_vehicle_refit_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
@@ -980,14 +982,14 @@ void BaseVehicleListWindow::DrawVehicleL
 
	int image_left  = (rtl && show_orderlist) ? orderlist_right : text_left;
 
	int image_right = (!rtl && show_orderlist) ? orderlist_left : text_right;
 

	
 
	int vehicle_button_x = rtl ? right - 8 : left;
 

	
 
	int y = r.top;
 
	uint max = min(this->vscroll.GetPosition() + this->vscroll.GetCapacity(), this->vehicles.Length());
 
	for (uint i = this->vscroll.GetPosition(); i < max; ++i) {
 
	uint max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->vehicles.Length());
 
	for (uint i = this->vscroll->GetPosition(); i < max; ++i) {
 
		const Vehicle *v = this->vehicles[i];
 
		StringID str;
 

	
 
		SetDParam(0, v->GetDisplayProfitThisYear());
 
		SetDParam(1, v->GetDisplayProfitLastYear());
 

	
 
@@ -1054,20 +1056,22 @@ public:
 
			case VEH_ROAD:     this->sorting = &_sorting.roadveh; break;
 
			case VEH_SHIP:     this->sorting = &_sorting.ship; break;
 
			case VEH_AIRCRAFT: this->sorting = &_sorting.aircraft; break;
 
			default: NOT_REACHED();
 
		}
 

	
 
		this->CreateNestedTree(desc);
 

	
 
		this->vscroll = this->GetScrollbar(VLW_WIDGET_SCROLLBAR);
 

	
 
		this->vehicles.SetListing(*this->sorting);
 
		this->vehicles.ForceRebuild();
 
		this->vehicles.NeedResort();
 
		this->BuildVehicleList(company, GB(window_number, 16, 16), window_type);
 
		this->SortVehicleList();
 

	
 
		this->CreateNestedTree(desc);
 

	
 
		/* Set up the window widgets */
 
		this->GetWidget<NWidgetCore>(VLW_WIDGET_LIST)->tool_tip = STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vehicle_type;
 

	
 
		if (window_type == VLW_SHARED_ORDERS) {
 
			this->GetWidget<NWidgetCore>(VLW_WIDGET_CAPTION)->widget_data = STR_VEHICLE_LIST_SHARED_ORDERS_LIST_CAPTION;
 
		} else {
 
@@ -1127,32 +1131,32 @@ public:
 
					case VLW_SHARED_ORDERS: // Shared Orders
 
						if (this->vehicles.Length() == 0) {
 
							/* We can't open this window without vehicles using this order
 
							* and we should close the window when deleting the order      */
 
							NOT_REACHED();
 
						}
 
						SetDParam(0, this->vscroll.GetCount());
 
						SetDParam(0, this->vscroll->GetCount());
 
						break;
 

	
 
					case VLW_STANDARD: // Company Name
 
						SetDParam(0, STR_COMPANY_NAME);
 
						SetDParam(1, index);
 
						SetDParam(3, this->vscroll.GetCount());
 
						SetDParam(3, this->vscroll->GetCount());
 
						break;
 

	
 
					case VLW_STATION_LIST: // Station/Waypoint Name
 
						SetDParam(0, Station::IsExpected(BaseStation::Get(index)) ? STR_STATION_NAME : STR_WAYPOINT_NAME);
 
						SetDParam(1, index);
 
						SetDParam(3, this->vscroll.GetCount());
 
						SetDParam(3, this->vscroll->GetCount());
 
						break;
 

	
 
					case VLW_DEPOT_LIST:
 
						SetDParam(0, STR_DEPOT_CAPTION);
 
						SetDParam(1, this->vehicle_type);
 
						SetDParam(2, index);
 
						SetDParam(3, this->vscroll.GetCount());
 
						SetDParam(3, this->vscroll->GetCount());
 
						break;
 
					default: NOT_REACHED();
 
				}
 
				break;
 
			}
 
		}
 
@@ -1217,13 +1221,13 @@ public:
 
			case VLW_WIDGET_SORT_BY_PULLDOWN:// Select sorting criteria dropdown menu
 
				ShowDropDownMenu(this, this->vehicle_sorter_names, this->vehicles.SortType(), VLW_WIDGET_SORT_BY_PULLDOWN, 0,
 
						(this->vehicle_type == VEH_TRAIN || this->vehicle_type == VEH_ROAD) ? 0 : (1 << 10));
 
				return;
 

	
 
			case VLW_WIDGET_LIST: { // Matrix to show vehicles
 
				uint id_v = this->vscroll.GetScrolledRowFromWidget(pt.y, this, VLW_WIDGET_LIST);
 
				uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, VLW_WIDGET_LIST);
 
				if (id_v >= this->vehicles.Length()) return; // click out of list bound
 

	
 
				const Vehicle *v = this->vehicles[id_v];
 
				ShowVehicleViewWindow(v);
 
				break;
 
			}
 
@@ -1286,14 +1290,14 @@ public:
 
			this->SetDirty();
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacityFromWidget(this, VLW_WIDGET_LIST);
 
		this->GetWidget<NWidgetCore>(VLW_WIDGET_LIST)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		this->vscroll->SetCapacityFromWidget(this, VLW_WIDGET_LIST);
 
		this->GetWidget<NWidgetCore>(VLW_WIDGET_LIST)->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		if (HasBit(data, 15) && (this->window_number & VLW_MASK) == VLW_SHARED_ORDERS) {
 
			SB(this->window_number, 16, 16, GB(data, 16, 16));
 
@@ -1457,19 +1461,22 @@ extern void DrawRoadVehDetails(const Veh
 
extern void DrawShipDetails(const Vehicle *v, int left, int right, int y);
 
extern void DrawAircraftDetails(const Aircraft *v, int left, int right, int y);
 

	
 
/** Class for managing the vehicle details window. */
 
struct VehicleDetailsWindow : Window {
 
	TrainDetailsWindowTabs tab; ///< For train vehicles: which tab is displayed.
 
	Scrollbar *vscroll;
 

	
 
	/** Initialize a newly created vehicle details window */
 
	VehicleDetailsWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
 
	{
 
		this->InitNested(desc, window_number);
 
		const Vehicle *v = Vehicle::Get(window_number);
 

	
 
		const Vehicle *v = Vehicle::Get(this->window_number);
 
		this->CreateNestedTree(desc);
 
		this->vscroll = (v->type == VEH_TRAIN ? this->GetScrollbar(VLD_WIDGET_SCROLLBAR) : NULL);
 
		this->FinishInitNested(desc, window_number);
 

	
 
		this->GetWidget<NWidgetCore>(VLD_WIDGET_RENAME_VEHICLE)->tool_tip = STR_VEHICLE_DETAILS_TRAIN_RENAME + v->type;
 

	
 
		this->owner = v->owner;
 
		this->tab = TDW_TAB_CARGO;
 
	}
 
@@ -1666,13 +1673,13 @@ struct VehicleDetailsWindow : Window {
 
				DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS);
 
				break;
 
			}
 

	
 
			case VLD_WIDGET_MATRIX:
 
				/* For trains only. */
 
				DrawVehicleDetails(v, r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, r.top + WD_MATRIX_TOP, this->vscroll.GetPosition(), this->vscroll.GetCapacity(), this->tab);
 
				DrawVehicleDetails(v, r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, r.top + WD_MATRIX_TOP, this->vscroll->GetPosition(), this->vscroll->GetCapacity(), this->tab);
 
				break;
 

	
 
			case VLD_WIDGET_MIDDLE_DETAILS: {
 
				/* For other vehicles, at the place of the matrix. */
 
				bool rtl = _dynlang.text_dir == TD_RTL;
 
				uint sprite_width = max<uint>(GetSprite(v->GetImage(rtl ? DIR_E : DIR_W), ST_NORMAL)->width, 70U) + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
 
@@ -1686,13 +1693,13 @@ struct VehicleDetailsWindow : Window {
 
				} else {
 
					uint sprite_left  = rtl ? text_right : r.left;
 
					uint sprite_right = rtl ? r.right : text_left;
 

	
 
					DrawVehicleImage(v, sprite_left + WD_FRAMERECT_LEFT, sprite_right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, INVALID_VEHICLE, 0);
 
				}
 
				DrawVehicleDetails(v, text_left + WD_FRAMERECT_LEFT, text_right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, this->vscroll.GetPosition(), this->vscroll.GetCapacity(), this->tab);
 
				DrawVehicleDetails(v, text_left + WD_FRAMERECT_LEFT, text_right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, this->vscroll->GetPosition(), this->vscroll->GetCapacity(), this->tab);
 
				break;
 
			}
 

	
 
			case VLD_WIDGET_SERVICING_INTERVAL:
 
				/* Draw service interval text */
 
				SetDParam(0, v->service_interval);
 
@@ -1709,13 +1716,13 @@ struct VehicleDetailsWindow : Window {
 
		const Vehicle *v = Vehicle::Get(this->window_number);
 

	
 
		this->SetWidgetDisabledState(VLD_WIDGET_RENAME_VEHICLE, v->owner != _local_company);
 

	
 
		if (v->type == VEH_TRAIN) {
 
			this->DisableWidget(this->tab + VLD_WIDGET_DETAILS_CARGO_CARRIED);
 
			this->vscroll.SetCount(GetTrainDetailsWndVScroll(v->index, this->tab));
 
			this->vscroll->SetCount(GetTrainDetailsWndVScroll(v->index, this->tab));
 
		}
 

	
 
		/* Disable service-scroller when interval is set to disabled */
 
		this->SetWidgetsDisabledState(!IsVehicleServiceIntervalEnabled(v->type, v->owner),
 
			VLD_WIDGET_INCREASE_SERVICING_INTERVAL,
 
			VLD_WIDGET_DECREASE_SERVICING_INTERVAL,
 
@@ -1774,14 +1781,14 @@ struct VehicleDetailsWindow : Window {
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(VLD_WIDGET_MATRIX);
 
		if (nwi != NULL) {
 
			this->vscroll.SetCapacityFromWidget(this, VLD_WIDGET_MATRIX);
 
			nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
			this->vscroll->SetCapacityFromWidget(this, VLD_WIDGET_MATRIX);
 
			nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		}
 
	}
 
};
 

	
 
/** Vehicle details window descriptor. */
 
static const WindowDesc _train_vehicle_details_desc(
src/vehicle_gui_base.h
Show inline comments
 
@@ -20,12 +20,13 @@ typedef GUIList<const Vehicle*> GUIVehic
 

	
 
struct BaseVehicleListWindow : public Window {
 
	GUIVehicleList vehicles;  ///< The list of vehicles
 
	Listing *sorting;         ///< Pointer to the vehicle type related sorting.
 
	VehicleType vehicle_type; ///< The vehicle type that is sorted
 
	byte unitnumber_digits;   ///< The number of digits of the highest unit number
 
	Scrollbar *vscroll;
 

	
 
	enum ActionDropdownItem {
 
		ADI_REPLACE,
 
		ADI_SERVICE,
 
		ADI_DEPOT,
 
		ADI_ADD_SHARED,
src/widget.cpp
Show inline comments
 
@@ -80,29 +80,29 @@ static void ScrollbarClickPositioning(Wi
 
	switch (wtp) {
 
		case WWT_SCROLLBAR:
 
			/* vertical scroller */
 
			w->flags4 &= ~WF_HSCROLL;
 
			w->flags4 &= ~WF_SCROLL2;
 
			pos = y;
 
			sb = &w->vscroll;
 
			sb = &w->old_vscroll;
 
			break;
 

	
 
		case WWT_SCROLL2BAR:
 
			/* 2nd vertical scroller */
 
			w->flags4 &= ~WF_HSCROLL;
 
			w->flags4 |= WF_SCROLL2;
 
			pos = y;
 
			sb = &w->vscroll2;
 
			sb = &w->old_vscroll2;
 
			break;
 

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

	
 
		default: NOT_REACHED();
 
	}
 
	if (pos <= mi + 9) {
 
@@ -1994,32 +1994,32 @@ void NWidgetLeaf::Draw(const Window *w)
 
			break;
 

	
 
		case WWT_SCROLLBAR:
 
			assert(this->widget_data == 0);
 
			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->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN, &w->vscroll);
 
								(w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN, &w->old_vscroll);
 
			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->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_MIDDLE | WF_SCROLL2),
 
								(w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2), &w->vscroll2);
 
								(w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2), &w->old_vscroll2);
 
			break;
 

	
 
		case WWT_CAPTION:
 
			if (this->index >= 0) w->SetStringParameters(this->index);
 
			DrawCaption(r, this->colour, w->owner, this->widget_data);
 
			break;
 

	
 
		case WWT_HSCROLLBAR:
 
			assert(this->widget_data == 0);
 
			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->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL), &w->hscroll);
 
								(w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL), &w->old_hscroll);
 
			break;
 

	
 
		case WWT_SHADEBOX:
 
			assert(this->widget_data == 0);
 
			DrawShadeBox(r, this->colour, w->IsShaded());
 
			break;
src/widgets/dropdown.cpp
Show inline comments
 
@@ -96,12 +96,13 @@ struct DropdownWindow : Window {
 
	int selected_index;           ///< Index of the selected item in the list.
 
	byte click_delay;             ///< Timer to delay selection.
 
	bool drag_mode;
 
	bool instant_close;           ///< Close the window when the mouse button is raised.
 
	int scrolling;                ///< If non-zero, auto-scroll the item list (one time).
 
	Point position;               ///< Position of the topleft corner of the window.
 
	Scrollbar *vscroll;
 

	
 
	/**
 
	 * Create a dropdown menu.
 
	 * @param parent        Parent window.
 
	 * @param list          Dropdown item list.
 
	 * @param selected      Index of the selected item in the list.
 
@@ -116,12 +117,14 @@ struct DropdownWindow : Window {
 
	DropdownWindow(Window *parent, DropDownList *list, int selected, int button, bool instant_close, const Point &position, const Dimension &size, Colours wi_colour, bool scroll) : Window()
 
	{
 
		this->position = position;
 

	
 
		this->CreateNestedTree(&_dropdown_desc);
 

	
 
		this->vscroll = this->GetScrollbar(DDM_SCROLL);
 

	
 
		uint items_width = size.width - (scroll ? WD_VSCROLLBAR_WIDTH : 0);
 
		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(DDM_ITEMS);
 
		nwi->SetMinimalSize(items_width, size.height + 4);
 
		nwi->colour = wi_colour;
 

	
 
		nwi = this->GetWidget<NWidgetCore>(DDM_SCROLL);
 
@@ -139,14 +142,14 @@ struct DropdownWindow : Window {
 
		for (DropDownList::const_iterator it = list->begin(); it != list->end(); ++it) {
 
			DropDownListItem *item = *it;
 
			list_height += item->Height(items_width);
 
		}
 

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

	
 
		this->parent_wnd_class = parent->window_class;
 
		this->parent_wnd_num   = parent->window_number;
 
		this->parent_button    = button;
 
		this->list             = list;
 
		this->selected_index   = selected;
 
@@ -189,13 +192,13 @@ struct DropdownWindow : Window {
 
	{
 
		if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0) return false;
 

	
 
		NWidgetBase *nwi = this->GetWidget<NWidgetBase>(DDM_ITEMS);
 
		int y     = _cursor.pos.y - this->top - nwi->pos_y - 2;
 
		int width = nwi->current_x - 4;
 
		int pos   = this->vscroll.GetPosition();
 
		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;
 
@@ -224,13 +227,13 @@ struct DropdownWindow : Window {
 
	{
 
		if (widget != DDM_ITEMS) return;
 

	
 
		TextColour colour = (TextColour)this->GetWidget<NWidgetCore>(widget)->colour;
 

	
 
		int y = r.top + 2;
 
		int pos = this->vscroll.GetPosition();
 
		int pos = this->vscroll->GetPosition();
 
		for (DropDownList::const_iterator it = this->list->begin(); it != this->list->end(); ++it) {
 
			const DropDownListItem *item = *it;
 
			int item_height = item->Height(r.right - r.left + 1);
 

	
 
			/* Skip items that are scrolled up */
 
			if (--pos >= 0) continue;
 
@@ -260,18 +263,18 @@ struct DropdownWindow : Window {
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	{
 
		if (this->scrolling != 0) {
 
			int pos = this->vscroll.GetPosition();
 
			int pos = this->vscroll->GetPosition();
 

	
 
			this->vscroll.UpdatePosition(this->scrolling);
 
			this->vscroll->UpdatePosition(this->scrolling);
 
			this->scrolling = 0;
 

	
 
			if (pos != this->vscroll.GetPosition()) {
 
			if (pos != this->vscroll->GetPosition()) {
 
				this->SetDirty();
 
			}
 
		}
 
	}
 

	
 
	virtual void OnMouseLoop()
src/window.cpp
Show inline comments
 
@@ -136,15 +136,15 @@ void Scrollbar::SetCapacityFromWidget(Wi
 
 * @return Scrollbar to the widget
 
 */
 
const Scrollbar *Window::GetScrollbar(uint widnum) const
 
{
 
	const NWidgetLeaf *wid = this->GetWidget<NWidgetLeaf>(widnum);
 
	switch (wid->type) {
 
		case WWT_HSCROLLBAR: return &this->hscroll;
 
		case WWT_SCROLLBAR:  return &this->vscroll;
 
		case WWT_SCROLL2BAR: return &this->vscroll2;
 
		case WWT_HSCROLLBAR: return &this->old_hscroll;
 
		case WWT_SCROLLBAR:  return &this->old_vscroll;
 
		case WWT_SCROLL2BAR: return &this->old_vscroll2;
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 
/**
 
 * Return the Scrollbar to a widget index.
 
@@ -152,15 +152,15 @@ const Scrollbar *Window::GetScrollbar(ui
 
 * @return Scrollbar to the widget
 
 */
 
Scrollbar *Window::GetScrollbar(uint widnum)
 
{
 
	NWidgetLeaf *wid = this->GetWidget<NWidgetLeaf>(widnum);
 
	switch (wid->type) {
 
		case WWT_HSCROLLBAR: return &this->hscroll;
 
		case WWT_SCROLLBAR:  return &this->vscroll;
 
		case WWT_SCROLL2BAR: return &this->vscroll2;
 
		case WWT_HSCROLLBAR: return &this->old_hscroll;
 
		case WWT_SCROLLBAR:  return &this->old_vscroll;
 
		case WWT_SCROLL2BAR: return &this->old_vscroll2;
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 

	
 
/**
 
@@ -1346,13 +1346,13 @@ void Window::InitNested(const WindowDesc
 
{
 
	this->CreateNestedTree(desc, false);
 
	this->FinishInitNested(desc, window_number);
 
}
 

	
 
/** Empty constructor, initialization has been moved to #InitNested() called from the constructor of the derived class. */
 
Window::Window() : hscroll(false), vscroll(true), vscroll2(true)
 
Window::Window() : old_hscroll(false), old_vscroll(true), old_vscroll2(true)
 
{
 
}
 

	
 
/**
 
 * Do a search for a window at specific coordinates. For this we start
 
 * at the topmost window, obviously and work our way down to the bottom
 
@@ -1882,20 +1882,20 @@ static EventState HandleScrollbarScrolli
 

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

	
 
			if (w->flags4 & WF_HSCROLL) {
 
				sb = &w->hscroll;
 
				sb = &w->old_hscroll;
 
				i = _cursor.pos.x - _cursorpos_drag_start.x;
 
				rtl = _dynlang.text_dir == TD_RTL;
 
			} else if (w->flags4 & WF_SCROLL2) {
 
				sb = &w->vscroll2;
 
				sb = &w->old_vscroll2;
 
				i = _cursor.pos.y - _cursorpos_drag_start.y;
 
			} else {
 
				sb = &w->vscroll;
 
				sb = &w->old_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->GetCount() / _scrollbar_size, max(0, sb->GetCount() - sb->GetCapacity()));
 
			if (rtl) pos = max(0, sb->GetCount() - sb->GetCapacity() - pos);
src/window_gui.h
Show inline comments
 
@@ -379,15 +379,15 @@ public:
 

	
 
	int left;   ///< x position of left edge of the window
 
	int top;    ///< y position of top edge of the window
 
	int width;  ///< width of the window (number of pixels to the right in x direction)
 
	int height; ///< Height of the window (number of pixels down in y direction)
 

	
 
	Scrollbar hscroll;  ///< Horizontal scroll bar
 
	Scrollbar vscroll;  ///< First vertical scroll bar
 
	Scrollbar vscroll2; ///< Second vertical scroll bar
 
	Scrollbar old_hscroll;  ///< Horizontal scroll bar
 
	Scrollbar old_vscroll;  ///< First vertical scroll bar
 
	Scrollbar old_vscroll2; ///< Second vertical scroll bar
 
	ResizeInfo resize;  ///< Resize information
 

	
 
	Owner owner;        ///< The owner of the content shown in this window. Company colour is acquired from this variable.
 

	
 
	ViewportData *viewport;          ///< Pointer to viewport data, if present.
 
	uint32 desc_flags;               ///< Window/widgets default flags setting. @see WindowDefaultFlag
 
@@ -409,13 +409,13 @@ public:
 

	
 
	const Scrollbar *GetScrollbar(uint widnum) const;
 
	Scrollbar *GetScrollbar(uint widnum);
 

	
 
	void InitNested(const WindowDesc *desc, WindowNumber number = 0);
 
	void CreateNestedTree(const WindowDesc *desc, bool fill_nested = true);
 
	void FinishInitNested(const WindowDesc *desc, WindowNumber window_number);
 
	void FinishInitNested(const WindowDesc *desc, WindowNumber window_number = 0);
 

	
 
	/**
 
	 * Sets the enabled/disabled status of a widget.
 
	 * By default, widgets are enabled.
 
	 * On certain conditions, they have to be disabled.
 
	 * @param widget_index index of this widget in the window
0 comments (0 inline, 0 general)