Changeset - r12891:c87cc0039f37
[Not reviewed]
master
0 1 0
alberth - 15 years ago 2009-09-02 20:46:42
alberth@openttd.org
(svn r17393) -Codechange: Fill small window with widgets.
1 file changed with 38 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/news_gui.cpp
Show inline comments
 
@@ -117,14 +117,16 @@ static TileIndex GetReferenceTile(NewsRe
 
}
 

	
 
/** Widget numbers of the news display windows. */
 
enum NewsTypeWidgets {
 
	NTW_HEADLINE, ///< The news headline.
 
	NTW_CLOSEBOX, ///< Close the window.
 
	NTW_CAPTION,  ///< Title bar of the window. Only used in type0-news.
 
	NTW_VIEWPORT, ///< Viewport in window. Only used in type0-news.
 
	NTW_CAPTION,  ///< Title bar of the window. Only used in small news items.
 
	NTW_INSET,    ///< Inset around the viewport in the window. Only used in small news items.
 
	NTW_VIEWPORT, ///< Viewport in the window. Only used in small news items.
 
	NTW_MESSAGE,  ///< Space for displaying the message. Only used in small news items.
 
};
 

	
 
/* Normal news items. */
 
static const NWidgetPart _nested_normal_news_widgets[] = {
 
	NWidget(WWT_PANEL, COLOUR_WHITE, NTW_HEADLINE),
 
		NWidget(NWID_HORIZONTAL),
 
@@ -167,22 +169,16 @@ static NWidgetPart _nested_small_news_wi
 
		NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE, NTW_CLOSEBOX), SetMinimalSize(11, 14), SetDataTip(STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW),
 
		NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, NTW_CAPTION), SetMinimalSize(269, 14), SetDataTip(STR_NEWS_MESSAGE_CAPTION, STR_NULL),
 
	EndContainer(),
 

	
 
	/* Main part */
 
	NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, NTW_HEADLINE),
 
		NWidget(NWID_SPACER), SetMinimalSize(0, 2),
 
		NWidget(NWID_HORIZONTAL),
 
			NWidget(NWID_SPACER), SetMinimalSize(2, 0),
 

	
 
			NWidget(WWT_INSET, COLOUR_LIGHT_BLUE, NTW_VIEWPORT), SetMinimalSize(276, 49),
 
			EndContainer(),
 

	
 
			NWidget(NWID_SPACER), SetMinimalSize(2, 0),
 
		NWidget(WWT_INSET, COLOUR_LIGHT_BLUE, NTW_INSET), SetPadding(2, 2, 2, 2),
 
			NWidget(NWID_VIEWPORT, INVALID_COLOUR, NTW_VIEWPORT), SetPadding(1, 1, 1, 1), SetMinimalSize(274, 47), SetFill(true, false),
 
		EndContainer(),
 
		NWidget(NWID_SPACER), SetMinimalSize(0, 22),
 
		NWidget(WWT_EMPTY, COLOUR_WHITE, NTW_MESSAGE), SetMinimalSize(275, 20), SetFill(true, false),
 
	EndContainer(),
 
};
 

	
 
static WindowDesc _small_news_desc(
 
	WDP_CENTER, 476, 280, 87, 280, 87,
 
	WC_NEWS_WINDOW, WC_NONE,
 
@@ -275,16 +271,17 @@ struct NewsWindow : Window {
 

	
 
			case NM_THIN:
 
				InitializeWindowViewport(this, 2, 58, 426, 70,
 
					ni->reftype1 == NR_VEHICLE ? 0x80000000 | ni->ref1 : GetReferenceTile(ni->reftype1, ni->ref1), ZOOM_LVL_NEWS);
 
				break;
 

	
 
			case NM_SMALL:
 
				InitializeWindowViewport(this, 3, 17, 274, 47,
 
					ni->reftype1 == NR_VEHICLE ? 0x80000000 | ni->ref1 : GetReferenceTile(ni->reftype1, ni->ref1), ZOOM_LVL_NEWS);
 
			case NM_SMALL: {
 
				NWidgetViewport *nvp = (NWidgetViewport *)this->nested_array[NTW_VIEWPORT];
 
				nvp->InitializeViewport(this, ni->reftype1 == NR_VEHICLE ? 0x80000000 | ni->ref1 : GetReferenceTile(ni->reftype1, ni->ref1), ZOOM_LVL_NEWS);
 
				break;
 
			}
 

	
 
			default: NOT_REACHED();
 
		}
 
	}
 

	
 
	void DrawNewsBorder() const
 
@@ -345,21 +342,45 @@ struct NewsWindow : Window {
 
				}
 
				break;
 
			}
 

	
 
			case NM_SMALL:
 
				this->DrawWidgets();
 
				this->DrawViewport();
 
				CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
 
				DrawStringMultiLine(2, this->width - 2, 64, this->height, this->ni->string_id, TC_FROMSTRING, SA_CENTER);
 
				break;
 

	
 
			default: NOT_REACHED();
 
		}
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *resize)
 
	{
 
		switch (widget) {
 
			case NTW_MESSAGE: {
 
				CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
 
				Dimension d = *size;
 
				d.width = (d.width >= padding.width) ? d.width - padding.width : 0;
 
				d.height = (d.height >= padding.height) ? d.height - padding.height : 0;
 
				d = GetStringMultiLineBoundingBox(this->ni->string_id, d);
 
				d.width += padding.width;
 
				d.height += padding.height;
 
				*size = maxdim(*size, d);
 
				break;
 
			}
 
		}
 
	}
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		switch (widget) {
 
			case NTW_MESSAGE:
 
				CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
 
				DrawStringMultiLine(r.left + 2, r.right - 2, r.top, r.bottom, this->ni->string_id, TC_FROMSTRING, SA_CENTER);
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		switch (widget) {
 
			case NTW_CLOSEBOX:
 
				NewsWindow::duration = 0;
 
				delete this;
0 comments (0 inline, 0 general)