Changeset - r13604:27524d0bf66e
[Not reviewed]
master
0 2 0
peter1138 - 15 years ago 2009-11-17 13:04:05
peter1138@openttd.org
(svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
2 files changed with 50 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/widget.cpp
Show inline comments
 
@@ -757,6 +757,17 @@ void NWidgetResizeBase::SetMinimalSize(u
 
}
 

	
 
/**
 
 * Set minimal text lines for the widget.
 
 * @param min_lines Number of text lines of the widget.
 
 * @param spacing   Extra spacing (eg WD_FRAMERECT_TOP + _BOTTOM) of the widget.
 
 * @param size      Font size of text.
 
 */
 
void NWidgetResizeBase::SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size)
 
{
 
	this->min_y = min_lines * GetCharacterHeight(size) + spacing;
 
}
 

	
 
/**
 
 * Set the filling of the widget from initial size.
 
 * @param fill_x Allow horizontal filling from initial size.
 
 * @param fill_y Allow vertical filling from initial size.
 
@@ -2088,6 +2099,15 @@ static int MakeNWidget(const NWidgetPart
 
				break;
 
			}
 

	
 
			case WPT_MINTEXTLINES: {
 
				NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
 
				if (nwrb != NULL) {
 
					assert(parts->u.text_lines.size >= FS_BEGIN && parts->u.text_lines.size < FS_END);
 
					nwrb->SetMinimalTextLines(parts->u.text_lines.lines, parts->u.text_lines.spacing, parts->u.text_lines.size);
 
				}
 
				break;
 
			}
 

	
 
			case WPT_FILL: {
 
				NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
 
				if (nwrb != NULL) nwrb->SetFill(parts->u.xy.x != 0, parts->u.xy.y != 0);
src/widget_type.h
Show inline comments
 
@@ -125,6 +125,7 @@ enum WidgetType {
 
	/* Nested widget part types. */
 
	WPT_RESIZE,       ///< Widget part for specifying resizing.
 
	WPT_MINSIZE,      ///< Widget part for specifying minimal size.
 
	WPT_MINTEXTLINES, ///< Widget part for specifying minimal number of lines of text.
 
	WPT_FILL,         ///< Widget part for specifying fill.
 
	WPT_DATATIP,      ///< Widget part for specifying data and tooltip.
 
	WPT_PADDING,      ///< Widget part for specifying a padding.
 
@@ -248,6 +249,7 @@ public:
 
	NWidgetResizeBase(WidgetType tp, bool fill_x, bool fill_y);
 

	
 
	void SetMinimalSize(uint min_x, uint min_y);
 
	void SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size);
 
	void SetFill(bool fill_x, bool fill_y);
 
	void SetResize(uint resize_x, uint resize_y);
 

	
 
@@ -590,6 +592,14 @@ struct NWidgetPartPIP {
 
	uint8 pre, inter, post; ///< Amount of space before/between/after child widgets.
 
};
 

	
 
/** Widget part for storing minimal text line data.
 
 * @ingroup NestedWidgetParts */
 
struct NWidgetPartTextLines {
 
	uint8 lines;   ///< Number of text lines.
 
	uint8 spacing; ///< Extra spacing around lines.
 
	FontSize size; ///< Font size of text lines.
 
};
 

	
 
/** Pointer to function returning a nested widget.
 
 * @param biggest_index Pointer to storage for collecting the biggest index used in the nested widget.
 
 * @return Nested widget (tree).
 
@@ -607,6 +617,7 @@ struct NWidgetPart {
 
		NWidgetPartWidget widget;        ///< Part with a start of a widget.
 
		NWidgetPartPaddings padding;     ///< Part with paddings.
 
		NWidgetPartPIP pip;              ///< Part with pre/inter/post spaces.
 
		NWidgetPartTextLines text_lines; ///< Part with text line data.
 
		NWidgetFunctionType *func_ptr;   ///< Part with a function call.
 
		NWidContainerFlags cont_flags;   ///< Part with container flags.
 
	} u;
 
@@ -647,6 +658,25 @@ static inline NWidgetPart SetMinimalSize
 
}
 

	
 
/**
 
 * Widget part function for setting the minimal text lines.
 
 * @param lines   Number of text lines.
 
 * @param spacing Extra spacing required.
 
 * @param size    Font size of text.
 
 * @ingroup NestedWidgetParts
 
 */
 
static inline NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSize size = FS_NORMAL)
 
{
 
	NWidgetPart part;
 

	
 
	part.type = WPT_MINTEXTLINES;
 
	part.u.text_lines.lines = lines;
 
	part.u.text_lines.spacing = spacing;
 
	part.u.text_lines.size = size;
 

	
 
	return part;
 
}
 

	
 
/**
 
 * Widget part function for setting filling.
 
 * @param x_fill Allow horizontal filling from minimal size.
 
 * @param y_fill Allow vertical filling from minimal size.
0 comments (0 inline, 0 general)