Changeset - r20541:b3cc03065e98
[Not reviewed]
master
0 3 0
frosch - 11 years ago 2013-07-06 18:54:26
frosch@openttd.org
(svn r25567) -Codechange: Revive dead DrawStringParams as FontState.
3 files changed with 45 insertions and 45 deletions:
0 comments (0 inline, 0 general)
src/gfx.cpp
Show inline comments
 
@@ -51,43 +51,6 @@ byte _colour_gradient[COLOUR_END][8];
 
static void GfxMainBlitterViewport(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub = NULL, SpriteID sprite_id = SPR_CURSOR_MOUSE);
 
static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub = NULL, SpriteID sprite_id = SPR_CURSOR_MOUSE, ZoomLevel zoom = ZOOM_LVL_NORMAL);
 

	
 
/**
 
 * Text drawing parameters, which can change while drawing a line, but are kept between multiple parts
 
 * of the same text, e.g. on line breaks.
 
 */
 
struct DrawStringParams {
 
	FontSize fontsize;
 
	TextColour cur_colour, prev_colour;
 

	
 
	DrawStringParams(TextColour colour, FontSize fontsize) : fontsize(fontsize), cur_colour(colour), prev_colour(colour) {}
 

	
 
	/**
 
	 * Switch to new colour \a c.
 
	 * @param c New colour to use.
 
	 */
 
	inline void SetColour(TextColour c)
 
	{
 
		assert(c >=  TC_BLUE && c <= TC_BLACK);
 
		this->prev_colour = this->cur_colour;
 
		this->cur_colour = c;
 
	}
 

	
 
	/** Switch to previous colour. */
 
	inline void SetPreviousColour()
 
	{
 
		Swap(this->cur_colour, this->prev_colour);
 
	}
 

	
 
	/**
 
	 * Switch to using a new font \a f.
 
	 * @param f New font to use.
 
	 */
 
	inline void SetFontSize(FontSize f)
 
	{
 
		this->fontsize = f;
 
	}
 
};
 

	
 
static ReusableBuffer<uint8> _cursor_backup;
 

	
 
/**
src/gfx_layout.cpp
Show inline comments
 
@@ -410,11 +410,11 @@ Layouter::Layouter(const char *str, int 
 
	const CharType *buffer_last = lastof(this->buffer);
 
	CharType *buff = this->buffer;
 

	
 
	TextColour cur_colour = colour, prev_colour = colour;
 
	FontState state(colour, fontsize);
 
	WChar c = 0;
 

	
 
	do {
 
		Font *f = new Font(fontsize, cur_colour);
 
		Font *f = new Font(state.fontsize, state.cur_colour);
 
		CharType *buff_begin = buff;
 
		FontMap fontMapping;
 

	
 
@@ -428,14 +428,13 @@ Layouter::Layouter(const char *str, int 
 
			if (c == '\0' || c == '\n') {
 
				break;
 
			} else if (c >= SCC_BLUE && c <= SCC_BLACK) {
 
				prev_colour = cur_colour;
 
				cur_colour = (TextColour)(c - SCC_BLUE);
 
				state.SetColour((TextColour)(c - SCC_BLUE));
 
			} else if (c == SCC_PREVIOUS_COLOUR) { // Revert to the previous colour.
 
				Swap(prev_colour, cur_colour);
 
				state.SetPreviousColour();
 
			} else if (c == SCC_TINYFONT) {
 
				fontsize = FS_SMALL;
 
				state.SetFontSize(FS_SMALL);
 
			} else if (c == SCC_BIGFONT) {
 
				fontsize = FS_LARGE;
 
				state.SetFontSize(FS_LARGE);
 
			} else {
 
				buff += AppendToBuffer(buff, buffer_last, c);
 
				continue;
 
@@ -447,7 +446,7 @@ Layouter::Layouter(const char *str, int 
 
			} else {
 
				delete f;
 
			}
 
			f = new Font(fontsize, cur_colour);
 
			f = new Font(state.fontsize, state.cur_colour);
 
		}
 

	
 
		/* Better safe than sorry. */
src/gfx_layout.h
Show inline comments
 
@@ -24,6 +24,44 @@
 
#endif /* WITH_ICU */
 

	
 
/**
 
 * Text drawing parameters, which can change while drawing a line, but are kept between multiple parts
 
 * of the same text, e.g. on line breaks.
 
 */
 
struct FontState {
 
	FontSize fontsize;       ///< Current font size.
 
	TextColour cur_colour;   ///< Current text colour.
 
	TextColour prev_colour;  ///< Text colour from before the last colour switch.
 

	
 
	FontState(TextColour colour, FontSize fontsize) : fontsize(fontsize), cur_colour(colour), prev_colour(colour) {}
 

	
 
	/**
 
	 * Switch to new colour \a c.
 
	 * @param c New colour to use.
 
	 */
 
	inline void SetColour(TextColour c)
 
	{
 
		assert(c >= TC_BLUE && c <= TC_BLACK);
 
		this->prev_colour = this->cur_colour;
 
		this->cur_colour = c;
 
	}
 

	
 
	/** Switch to previous colour. */
 
	inline void SetPreviousColour()
 
	{
 
		Swap(this->cur_colour, this->prev_colour);
 
	}
 

	
 
	/**
 
	 * Switch to using a new font \a f.
 
	 * @param f New font to use.
 
	 */
 
	inline void SetFontSize(FontSize f)
 
	{
 
		this->fontsize = f;
 
	}
 
};
 

	
 
/**
 
 * Container with information about a font.
 
 */
 
class Font ICU_FONTINSTANCE {
0 comments (0 inline, 0 general)