gfx_type.h

Go to the documentation of this file.
00001 /* $Id: gfx_type.h 24111 2012-04-10 20:16:51Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #ifndef GFX_TYPE_H
00013 #define GFX_TYPE_H
00014 
00015 #include "core/endian_type.hpp"
00016 #include "core/geometry_type.hpp"
00017 #include "zoom_type.h"
00018 
00019 typedef uint32 SpriteID;  
00020 typedef uint32 PaletteID; 
00021 typedef uint32 CursorID;  
00022 
00024 struct PalSpriteID {
00025   SpriteID sprite;  
00026   PaletteID pal;    
00027 };
00028 
00029 enum WindowKeyCodes {
00030   WKC_SHIFT = 0x8000,
00031   WKC_CTRL  = 0x4000,
00032   WKC_ALT   = 0x2000,
00033   WKC_META  = 0x1000,
00034 
00035   WKC_GLOBAL_HOTKEY = 0x0800, 
00036 
00037   WKC_SPECIAL_KEYS = WKC_SHIFT | WKC_CTRL | WKC_ALT | WKC_META | WKC_GLOBAL_HOTKEY,
00038 
00039   /* Special ones */
00040   WKC_NONE        =  0,
00041   WKC_ESC         =  1,
00042   WKC_BACKSPACE   =  2,
00043   WKC_INSERT      =  3,
00044   WKC_DELETE      =  4,
00045 
00046   WKC_PAGEUP      =  5,
00047   WKC_PAGEDOWN    =  6,
00048   WKC_END         =  7,
00049   WKC_HOME        =  8,
00050 
00051   /* Arrow keys */
00052   WKC_LEFT        =  9,
00053   WKC_UP          = 10,
00054   WKC_RIGHT       = 11,
00055   WKC_DOWN        = 12,
00056 
00057   /* Return & tab */
00058   WKC_RETURN      = 13,
00059   WKC_TAB         = 14,
00060 
00061   /* Space */
00062   WKC_SPACE       = 32,
00063 
00064   /* Function keys */
00065   WKC_F1          = 33,
00066   WKC_F2          = 34,
00067   WKC_F3          = 35,
00068   WKC_F4          = 36,
00069   WKC_F5          = 37,
00070   WKC_F6          = 38,
00071   WKC_F7          = 39,
00072   WKC_F8          = 40,
00073   WKC_F9          = 41,
00074   WKC_F10         = 42,
00075   WKC_F11         = 43,
00076   WKC_F12         = 44,
00077 
00078   /* Backquote is the key left of "1"
00079    * we only store this key here, no matter what character is really mapped to it
00080    * on a particular keyboard. (US keyboard: ` and ~ ; German keyboard: ^ and °) */
00081   WKC_BACKQUOTE   = 45,
00082   WKC_PAUSE       = 46,
00083 
00084   /* 0-9 are mapped to 48-57
00085    * A-Z are mapped to 65-90
00086    * a-z are mapped to 97-122 */
00087 
00088   /* Numerical keyboard */
00089   WKC_NUM_DIV     = 138,
00090   WKC_NUM_MUL     = 139,
00091   WKC_NUM_MINUS   = 140,
00092   WKC_NUM_PLUS    = 141,
00093   WKC_NUM_ENTER   = 142,
00094   WKC_NUM_DECIMAL = 143,
00095 
00096   /* Other keys */
00097   WKC_SLASH       = 144, 
00098   WKC_SEMICOLON   = 145, 
00099   WKC_EQUALS      = 146, 
00100   WKC_L_BRACKET   = 147, 
00101   WKC_BACKSLASH   = 148, 
00102   WKC_R_BRACKET   = 149, 
00103   WKC_SINGLEQUOTE = 150, 
00104   WKC_COMMA       = 151, 
00105   WKC_PERIOD      = 152, 
00106   WKC_MINUS       = 153, 
00107 };
00108 
00110 struct AnimCursor {
00111   static const CursorID LAST = MAX_UVALUE(CursorID);
00112   CursorID sprite;   
00113   byte display_time; 
00114 };
00115 
00117 struct CursorVars {
00118   Point pos, size, offs, delta; 
00119   Point draw_pos, draw_size;    
00120   int short_vehicle_offset;     
00121   CursorID sprite; 
00122   PaletteID pal;
00123 
00124   int wheel;       
00125 
00126   /* We need two different vars to keep track of how far the scrollwheel moved.
00127    * OSX uses this for scrolling around the map. */
00128   int v_wheel;
00129   int h_wheel;
00130 
00131   const AnimCursor *animate_list; 
00132   const AnimCursor *animate_cur;  
00133   uint animate_timeout;           
00134 
00135   bool visible;    
00136   bool dirty;      
00137   bool fix_at;     
00138   bool in_window;  
00139 
00140   bool vehchain;   
00141 };
00142 
00144 struct DrawPixelInfo {
00145   void *dst_ptr;
00146   int left, top, width, height;
00147   int pitch;
00148   ZoomLevel zoom;
00149 };
00150 
00152 union Colour {
00153   uint32 data; 
00154   struct {
00155 #if TTD_ENDIAN == TTD_BIG_ENDIAN
00156     uint8 a, r, g, b; 
00157 #else
00158     uint8 b, g, r, a; 
00159 #endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
00160   };
00161 
00169   Colour(uint8 r, uint8 g, uint8 b, uint8 a = 0xFF) :
00170 #if TTD_ENDIAN == TTD_BIG_ENDIAN
00171     a(a), r(r), g(g), b(b)
00172 #else
00173     b(b), g(g), r(r), a(a)
00174 #endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
00175   {
00176   }
00177 
00182   Colour(uint data = 0) : data(data)
00183   {
00184   }
00185 };
00186 
00187 assert_compile(sizeof(Colour) == sizeof(uint32));
00188 
00189 
00191 enum FontSize {
00192   FS_NORMAL, 
00193   FS_SMALL,  
00194   FS_LARGE,  
00195   FS_MONO,   
00196   FS_END,
00197 
00198   FS_BEGIN = FS_NORMAL, 
00199 };
00200 DECLARE_POSTFIX_INCREMENT(FontSize)
00201 
00202 
00207 struct SubSprite {
00208   int left, top, right, bottom;
00209 };
00210 
00211 enum Colours {
00212   COLOUR_BEGIN,
00213   COLOUR_DARK_BLUE = COLOUR_BEGIN,
00214   COLOUR_PALE_GREEN,
00215   COLOUR_PINK,
00216   COLOUR_YELLOW,
00217   COLOUR_RED,
00218   COLOUR_LIGHT_BLUE,
00219   COLOUR_GREEN,
00220   COLOUR_DARK_GREEN,
00221   COLOUR_BLUE,
00222   COLOUR_CREAM,
00223   COLOUR_MAUVE,
00224   COLOUR_PURPLE,
00225   COLOUR_ORANGE,
00226   COLOUR_BROWN,
00227   COLOUR_GREY,
00228   COLOUR_WHITE,
00229   COLOUR_END,
00230   INVALID_COLOUR = 0xFF,
00231 };
00232 template <> struct EnumPropsT<Colours> : MakeEnumPropsT<Colours, byte, COLOUR_BEGIN, COLOUR_END, INVALID_COLOUR, 4> {};
00233 
00235 enum TextColour {
00236   TC_BEGIN       = 0x00,
00237   TC_FROMSTRING  = 0x00,
00238   TC_BLUE        = 0x00,
00239   TC_SILVER      = 0x01,
00240   TC_GOLD        = 0x02,
00241   TC_RED         = 0x03,
00242   TC_PURPLE      = 0x04,
00243   TC_LIGHT_BROWN = 0x05,
00244   TC_ORANGE      = 0x06,
00245   TC_GREEN       = 0x07,
00246   TC_YELLOW      = 0x08,
00247   TC_DARK_GREEN  = 0x09,
00248   TC_CREAM       = 0x0A,
00249   TC_BROWN       = 0x0B,
00250   TC_WHITE       = 0x0C,
00251   TC_LIGHT_BLUE  = 0x0D,
00252   TC_GREY        = 0x0E,
00253   TC_DARK_BLUE   = 0x0F,
00254   TC_BLACK       = 0x10,
00255   TC_END,
00256   TC_INVALID     = 0xFF,
00257 
00258   TC_IS_PALETTE_COLOUR = 0x100, 
00259   TC_NO_SHADE          = 0x200, 
00260 };
00261 DECLARE_ENUM_AS_BIT_SET(TextColour)
00262 
00263 
00264 enum PaletteAnimationSizes {
00265   PALETTE_ANIM_SIZE  = 28,   
00266   PALETTE_ANIM_START = 227,  
00267 };
00268 
00270 enum FillRectMode {
00271   FILLRECT_OPAQUE,  
00272   FILLRECT_CHECKER, 
00273   FILLRECT_RECOLOUR, 
00274 };
00275 
00277 enum PaletteType {
00278   PAL_DOS,        
00279   PAL_WINDOWS,    
00280   PAL_AUTODETECT, 
00281   MAX_PAL = 2,    
00282 };
00283 
00285 enum SpriteType {
00286   ST_NORMAL   = 0,      
00287   ST_MAPGEN   = 1,      
00288   ST_FONT     = 2,      
00289   ST_RECOLOUR = 3,      
00290   ST_INVALID  = 4,      
00291 };
00292 
00294 static const uint MILLISECONDS_PER_TICK = 30;
00295 
00297 struct Palette {
00298   Colour palette[256]; 
00299   int first_dirty;     
00300   int count_dirty;     
00301 };
00302 
00303 #endif /* GFX_TYPE_H */