Changeset - r16895:a79cc0d003c2
[Not reviewed]
master
0 2 0
rubidium - 14 years ago 2010-12-25 20:02:04
rubidium@openttd.org
(svn r21640) -Change/Feature-ish: allow disabling the shading when drawing text
2 files changed with 3 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/gfx.cpp
Show inline comments
 
@@ -241,99 +241,99 @@ void GfxDrawLineUnscaled(int x, int y, i
 
 * @param dx1 Screen X-length of first edge.
 
 * @param dy1 Screen Y-length of first edge.
 
 * @param dx2 Screen X-length of second edge.
 
 * @param dy2 Screen Y-length of second edge.
 
 * @param dx3 Screen X-length of third edge.
 
 * @param dy3 Screen Y-length of third edge.
 
 */
 
void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3)
 
{
 
	/*           ....
 
	 *         ..    ....
 
	 *       ..          ....
 
	 *     ..                ^
 
	 *   <--__(dx1,dy1)    /(dx2,dy2)
 
	 *   :    --__       /   :
 
	 *   :        --__ /     :
 
	 *   :            *(x,y) :
 
	 *   :            |      :
 
	 *   :            |     ..
 
	 *    ....        |(dx3,dy3)
 
	 *        ....    | ..
 
	 *            ....V.
 
	 */
 

	
 
	static const byte colour = 15;
 

	
 
	GfxDrawLineUnscaled(x, y, x + dx1, y + dy1, colour);
 
	GfxDrawLineUnscaled(x, y, x + dx2, y + dy2, colour);
 
	GfxDrawLineUnscaled(x, y, x + dx3, y + dy3, colour);
 

	
 
	GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx2, y + dy1 + dy2, colour);
 
	GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx3, y + dy1 + dy3, colour);
 
	GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx1, y + dy2 + dy1, colour);
 
	GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx3, y + dy2 + dy3, colour);
 
	GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx1, y + dy3 + dy1, colour);
 
	GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx2, y + dy3 + dy2, colour);
 
}
 

	
 
/**
 
 * Set the colour remap to be for the given colour.
 
 * @param colour the new colour of the remap.
 
 */
 
static void SetColourRemap(TextColour colour)
 
{
 
	if (colour == TC_INVALID) return;
 

	
 
	/* Black strings have no shading ever; the shading is black, so it
 
	 * would be invisible at best, but it actually makes it illegible. */
 
	bool no_shade   = colour == TC_BLACK;
 
	bool no_shade   = colour & TC_NO_SHADE || colour == TC_BLACK;
 
	bool raw_colour = colour & TC_IS_PALETTE_COLOUR;
 
	colour &= ~TC_IS_PALETTE_COLOUR;
 
	colour &= ~(TC_NO_SHADE | TC_IS_PALETTE_COLOUR);
 

	
 
	_string_colourremap[1] = raw_colour ? (byte)colour : _string_colourmap[_use_palette][colour];
 
	_string_colourremap[2] = no_shade ? 0 : (_use_palette == PAL_DOS ? 1 : 215);
 
	_colour_remap_ptr = _string_colourremap;
 
}
 

	
 
#if !defined(WITH_ICU)
 
typedef WChar UChar;
 
static UChar *HandleBiDiAndArabicShapes(UChar *text) { return text; }
 
#else
 
#include <unicode/ubidi.h>
 
#include <unicode/ushape.h>
 

	
 
/**
 
 * Function to be able to handle right-to-left text and Arabic chars properly.
 
 *
 
 * First: right-to-left (RTL) is stored 'logically' in almost all applications
 
 *        and so do we. This means that their text is stored from right to the
 
 *        left in memory and any non-RTL text (like numbers or English) are
 
 *        then stored from left-to-right. When we want to actually draw the
 
 *        text we need to reverse the RTL text in memory, which is what
 
 *        happens in ubidi_writeReordered.
 
 * Second: Arabic characters "differ" based on their context. To draw the
 
 *        correct variant we pass it through u_shapeArabic. This function can
 
 *        add or remove some characters. This is the reason for the lastof
 
 *        so we know till where we can fill the output.
 
 *
 
 * Sadly enough these functions work with a custom character format, UChar,
 
 * which isn't the same size as WChar. Because of that we need to transform
 
 * our text first to UChars and then back to something we can use.
 
 *
 
 * To be able to truncate strings properly you must truncate before passing to
 
 * this function. This way the logical begin of the string remains and the end
 
 * gets chopped of instead of the other way around.
 
 *
 
 * The reshaping of Arabic characters might increase or decrease the width of
 
 * the characters/string. So it might still overflow after truncation, though
 
 * the chance is fairly slim as most characters get shorter instead of longer.
 
 * @param buffer the buffer to read from/to
 
 * @param lastof the end of the buffer
 
 * @return the buffer to draw from
 
 */
 
static UChar *HandleBiDiAndArabicShapes(UChar *buffer)
 
{
 
	static UChar input_output[DRAW_STRING_BUFFER];
 
	UChar intermediate[DRAW_STRING_BUFFER];
 

	
 
	UChar *t = buffer;
src/gfx_type.h
Show inline comments
 
@@ -180,86 +180,87 @@ struct SubSprite {
 
	int left, top, right, bottom;
 
};
 

	
 
enum Colours {
 
	COLOUR_DARK_BLUE,
 
	COLOUR_PALE_GREEN,
 
	COLOUR_PINK,
 
	COLOUR_YELLOW,
 
	COLOUR_RED,
 
	COLOUR_LIGHT_BLUE,
 
	COLOUR_GREEN,
 
	COLOUR_DARK_GREEN,
 
	COLOUR_BLUE,
 
	COLOUR_CREAM,
 
	COLOUR_MAUVE,
 
	COLOUR_PURPLE,
 
	COLOUR_ORANGE,
 
	COLOUR_BROWN,
 
	COLOUR_GREY,
 
	COLOUR_WHITE,
 
	COLOUR_END,
 
	INVALID_COLOUR = 0xFF,
 
};
 
template <> struct EnumPropsT<Colours> : MakeEnumPropsT<Colours, byte, COLOUR_DARK_BLUE, COLOUR_END, INVALID_COLOUR, 4> {};
 

	
 
/** Colour of the strings, see _string_colourmap in table/palettes.h or docs/ottd-colourtext-palette.png */
 
enum TextColour {
 
	TC_FROMSTRING  = 0x00,
 
	TC_BLUE        = 0x00,
 
	TC_SILVER      = 0x01,
 
	TC_GOLD        = 0x02,
 
	TC_RED         = 0x03,
 
	TC_PURPLE      = 0x04,
 
	TC_LIGHT_BROWN = 0x05,
 
	TC_ORANGE      = 0x06,
 
	TC_GREEN       = 0x07,
 
	TC_YELLOW      = 0x08,
 
	TC_DARK_GREEN  = 0x09,
 
	TC_CREAM       = 0x0A,
 
	TC_BROWN       = 0x0B,
 
	TC_WHITE       = 0x0C,
 
	TC_LIGHT_BLUE  = 0x0D,
 
	TC_GREY        = 0x0E,
 
	TC_DARK_BLUE   = 0x0F,
 
	TC_BLACK       = 0x10,
 
	TC_INVALID     = 0xFF,
 

	
 
	TC_IS_PALETTE_COLOUR = 0x100, ///< Colour value is already a real palette colour index, not an index of a StringColour.
 
	TC_NO_SHADE          = 0x200, ///< Do not add shading to this text colour.
 
};
 
DECLARE_ENUM_AS_BIT_SET(TextColour)
 

	
 
/** Defines a few values that are related to animations using palette changes */
 
enum PaletteAnimationSizes {
 
	PALETTE_ANIM_SIZE_WIN   = 28,   ///< number of animated colours in Windows palette
 
	PALETTE_ANIM_SIZE_DOS   = 38,   ///< number of animated colours in DOS palette
 
	PALETTE_ANIM_SIZE_START = 217,  ///< Index in  the _palettes array from which all animations are taking places (table/palettes.h)
 
};
 

	
 
/** Define the operation GfxFillRect performs */
 
enum FillRectMode {
 
	FILLRECT_OPAQUE,  ///< Fill rectangle with a single colour
 
	FILLRECT_CHECKER, ///< Draw only every second pixel, used for greying-out
 
	FILLRECT_RECOLOUR, ///< Apply a recolour sprite to the screen content
 
};
 

	
 
/** Palettes OpenTTD supports. */
 
enum PaletteType {
 
	PAL_DOS,        ///< Use the DOS palette.
 
	PAL_WINDOWS,    ///< Use the Windows palette.
 
	PAL_AUTODETECT, ///< Automatically detect the palette based on the graphics pack.
 
	MAX_PAL = 2,    ///< The number of palettes.
 
};
 

	
 
/** Types of sprites that might be loaded */
 
enum SpriteType {
 
	ST_NORMAL   = 0,      ///< The most basic (normal) sprite
 
	ST_MAPGEN   = 1,      ///< Special sprite for the map generator
 
	ST_FONT     = 2,      ///< A sprite used for fonts
 
	ST_RECOLOUR = 3,      ///< Recolour sprite
 
	ST_INVALID  = 4,      ///< Pseudosprite or other unusable sprite, used only internally
 
};
 

	
 
/** The number of milliseconds per game tick. */
 
static const uint MILLISECONDS_PER_TICK = 30;
 

	
 
#endif /* GFX_TYPE_H */
0 comments (0 inline, 0 general)