Changeset - r16717:227b400c4b5b
[Not reviewed]
master
0 1 0
rubidium - 14 years ago 2010-12-11 10:10:25
rubidium@openttd.org
(svn r21460) -Change [FS#3975]: place the bridge building window under the mouse instead of somewhere randomly on the screen and change the default sort order
1 file changed with 11 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/bridge_gui.cpp
Show inline comments
 
@@ -195,24 +195,34 @@ public:
 
				sprite_dim.height++; // Sprite is rendered one pixel down in the matrix field.
 
				text_dim.height++; // Allowing the bottom row pixels to be rendered on the edge of the matrix field.
 
				resize->height = max(sprite_dim.height, text_dim.height) + 2; // Max of both sizes + account for matrix edges.
 

	
 
				this->bridgetext_offset = WD_MATRIX_LEFT + sprite_dim.width + 1; // Left edge of text, 1 pixel distance from the sprite.
 
				size->width = this->bridgetext_offset + text_dim.width + WD_MATRIX_RIGHT;
 
				size->height = 4 * resize->height; // Smallest bridge gui is 4 entries high in the matrix.
 
				break;
 
			}
 
		}
 
	}
 

	
 
	virtual Point OnInitialPosition(const WindowDesc *desc, int16 sm_width, int16 sm_height, int window_number)
 
	{
 
		/* Position the window so hopefully the first bridge from the list is under the mouse pointer. */
 
		NWidgetBase *list = this->GetWidget<NWidgetBase>(BBSW_BRIDGE_LIST);
 
		Point corner; // point of the top left corner of the window.
 
		corner.y = Clamp(_cursor.pos.y - list->pos_y - 5, GetMainViewTop(), GetMainViewBottom() - sm_height);
 
		corner.x = Clamp(_cursor.pos.x - list->pos_x - 5, 0, _screen.width - sm_width);
 
		return corner;
 
	}
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		switch (widget) {
 
			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++) {
 
					const BridgeSpec *b = this->bridges->Get(i)->spec;
 

	
 
@@ -277,25 +287,25 @@ public:
 
	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->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 */
 
Listing BuildBridgeWindow::last_sorting = {false, 0};
 
Listing BuildBridgeWindow::last_sorting = {true, 2};
 

	
 
/** Available bridge sorting functions. */
 
GUIBridgeList::SortFunction * const BuildBridgeWindow::sorter_funcs[] = {
 
	&BridgeIndexSorter,
 
	&BridgePriceSorter,
 
	&BridgeSpeedSorter
 
};
 

	
 
/** Names of the sorting functions. */
 
const StringID BuildBridgeWindow::sorter_names[] = {
 
	STR_SORT_BY_NUMBER,
 
	STR_SORT_BY_COST,
0 comments (0 inline, 0 general)