From a773d45885eac803e794c622a4dfae3f03cc5cb1 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 23 Dec 2007 10:56:02 +0000 Subject: (svn r11684) -Codechange: split gfx.h in a type and functional header. --- src/blitter/32bpp_anim.cpp | 5 +- src/blitter/32bpp_base.cpp | 2 +- src/blitter/32bpp_optimized.cpp | 4 +- src/blitter/32bpp_simple.cpp | 4 +- src/blitter/8bpp_base.cpp | 2 +- src/blitter/8bpp_debug.cpp | 3 +- src/blitter/8bpp_optimized.cpp | 4 +- src/blitter/8bpp_simple.cpp | 3 +- src/blitter/base.hpp | 2 +- src/bmp.cpp | 1 - src/bmp.h | 2 + src/bridge.h | 2 + src/cargotype.h | 1 + src/command.cpp | 1 + src/command_type.h | 1 + src/core/math_func.hpp | 6 - src/engine.h | 1 + src/fontcache.cpp | 1 + src/fontcache.h | 2 +- src/functions.h | 1 + src/gfx.cpp | 9 +- src/gfx.h | 378 ---------------------------------------- src/gfx_func.h | 182 +++++++++++++++++++ src/gfx_type.h | 210 ++++++++++++++++++++++ src/gfxinit.cpp | 1 + src/gfxinit.h | 2 + src/gui.h | 2 +- src/heightmap.cpp | 1 + src/main_gui.cpp | 1 + src/misc.cpp | 1 + src/misc/dbg_helpers.cpp | 1 + src/misc_cmd.cpp | 1 + src/misc_gui.cpp | 1 + src/network/network_gui.cpp | 1 - src/newgrf.cpp | 1 + src/newgrf_station.cpp | 2 +- src/oldloader.cpp | 2 +- src/openttd.cpp | 1 + src/openttd.h | 6 - src/os/macosx/splash.cpp | 2 +- src/players.cpp | 2 +- src/rail.h | 3 +- src/saveload.cpp | 1 + src/screenshot.cpp | 1 + src/signs.cpp | 1 + src/smallmap_gui.cpp | 1 + src/sprite.h | 2 + src/spritecache.h | 2 + src/spriteloader/grf.cpp | 2 +- src/spriteloader/png.cpp | 2 +- src/station.cpp | 1 + src/stdafx.h | 6 + src/table/sprites.h | 2 + src/transparency.h | 2 + src/vehicle.cpp | 1 + src/vehicle.h | 7 +- src/video/dedicated_v.cpp | 2 +- src/video/null_v.cpp | 2 +- src/video/sdl_v.cpp | 2 +- src/video/win32_v.cpp | 2 +- src/viewport.cpp | 1 + src/viewport.h | 4 +- src/window.cpp | 1 + src/zoom.hpp | 94 ---------- src/zoom_func.h | 66 +++++++ src/zoom_type.h | 37 ++++ 66 files changed, 578 insertions(+), 522 deletions(-) delete mode 100644 src/gfx.h create mode 100644 src/gfx_func.h create mode 100644 src/gfx_type.h delete mode 100644 src/zoom.hpp create mode 100644 src/zoom_func.h create mode 100644 src/zoom_type.h (limited to 'src') diff --git a/src/blitter/32bpp_anim.cpp b/src/blitter/32bpp_anim.cpp index 0533d9fbb..0b6e86230 100644 --- a/src/blitter/32bpp_anim.cpp +++ b/src/blitter/32bpp_anim.cpp @@ -1,8 +1,9 @@ /* $Id$ */ #include "../stdafx.h" -#include "../zoom.hpp" -#include "../gfx.h" +#include "../helpers.hpp" +#include "../gfx_func.h" +#include "../zoom_func.h" #include "../debug.h" #include "../table/sprites.h" #include "../video/video_driver.hpp" diff --git a/src/blitter/32bpp_base.cpp b/src/blitter/32bpp_base.cpp index ee1b76d1c..0358ae5dc 100644 --- a/src/blitter/32bpp_base.cpp +++ b/src/blitter/32bpp_base.cpp @@ -1,7 +1,7 @@ /* $Id$ */ #include "../stdafx.h" -#include "../gfx.h" +#include "../gfx_func.h" #include "32bpp_base.hpp" void *Blitter_32bppBase::MoveTo(const void *video, int x, int y) diff --git a/src/blitter/32bpp_optimized.cpp b/src/blitter/32bpp_optimized.cpp index 0535dd640..2906158be 100644 --- a/src/blitter/32bpp_optimized.cpp +++ b/src/blitter/32bpp_optimized.cpp @@ -1,8 +1,8 @@ /* $Id$ */ #include "../stdafx.h" -#include "../zoom.hpp" -#include "../gfx.h" +#include "../zoom_func.h" +#include "../gfx_func.h" #include "../debug.h" #include "../table/sprites.h" #include "32bpp_optimized.hpp" diff --git a/src/blitter/32bpp_simple.cpp b/src/blitter/32bpp_simple.cpp index f00789075..f5ecba8ad 100644 --- a/src/blitter/32bpp_simple.cpp +++ b/src/blitter/32bpp_simple.cpp @@ -1,8 +1,8 @@ /* $Id$ */ #include "../stdafx.h" -#include "../zoom.hpp" -#include "../gfx.h" +#include "../gfx_func.h" +#include "../zoom_func.h" #include "../debug.h" #include "../table/sprites.h" #include "32bpp_simple.hpp" diff --git a/src/blitter/8bpp_base.cpp b/src/blitter/8bpp_base.cpp index 541e88176..7b813f6e7 100644 --- a/src/blitter/8bpp_base.cpp +++ b/src/blitter/8bpp_base.cpp @@ -1,7 +1,7 @@ /* $Id$ */ #include "../stdafx.h" -#include "../gfx.h" +#include "../gfx_func.h" #include "8bpp_base.hpp" void Blitter_8bppBase::DrawColorMappingRect(void *dst, int width, int height, int pal) diff --git a/src/blitter/8bpp_debug.cpp b/src/blitter/8bpp_debug.cpp index 3a9b52d2a..da4b7998f 100644 --- a/src/blitter/8bpp_debug.cpp +++ b/src/blitter/8bpp_debug.cpp @@ -3,8 +3,7 @@ /** @file 8bpp_debug.cpp */ #include "../stdafx.h" -#include "../zoom.hpp" -#include "../gfx.h" +#include "../zoom_func.h" #include "../functions.h" #include "8bpp_debug.hpp" diff --git a/src/blitter/8bpp_optimized.cpp b/src/blitter/8bpp_optimized.cpp index f6013fac2..b795e2891 100644 --- a/src/blitter/8bpp_optimized.cpp +++ b/src/blitter/8bpp_optimized.cpp @@ -3,9 +3,9 @@ /** @file 8bpp_optimized.cpp */ #include "../stdafx.h" -#include "../zoom.hpp" -#include "../gfx.h" +#include "../zoom_func.h" #include "../debug.h" +#include "../helpers.hpp" #include "8bpp_optimized.hpp" static FBlitter_8bppOptimized iFBlitter_8bppOptimized; diff --git a/src/blitter/8bpp_simple.cpp b/src/blitter/8bpp_simple.cpp index 010066f8a..77698cb1c 100644 --- a/src/blitter/8bpp_simple.cpp +++ b/src/blitter/8bpp_simple.cpp @@ -3,8 +3,7 @@ /** @file 8bpp_simple.cpp */ #include "../stdafx.h" -#include "../zoom.hpp" -#include "../gfx.h" +#include "../zoom_func.h" #include "8bpp_simple.hpp" static FBlitter_8bppSimple iFBlitter_8bppSimple; diff --git a/src/blitter/base.hpp b/src/blitter/base.hpp index c9db1d9d4..cefaaa29f 100644 --- a/src/blitter/base.hpp +++ b/src/blitter/base.hpp @@ -5,7 +5,7 @@ #include "../spritecache.h" #include "../spriteloader/spriteloader.hpp" -#include "../zoom.hpp" +#include "../zoom_type.h" enum BlitterMode { BM_NORMAL, diff --git a/src/bmp.cpp b/src/bmp.cpp index 59d559877..dc6d11ef7 100644 --- a/src/bmp.cpp +++ b/src/bmp.cpp @@ -4,7 +4,6 @@ #include "stdafx.h" #include "openttd.h" -#include "gfx.h" #include "bmp.h" #include "core/bitmath_func.hpp" diff --git a/src/bmp.h b/src/bmp.h index d508078bc..daf02c28d 100644 --- a/src/bmp.h +++ b/src/bmp.h @@ -5,6 +5,8 @@ #ifndef BMP_H #define BMP_H +#include "gfx_type.h" + struct BmpInfo { uint32 offset; ///< offset of bitmap data from .bmp file begining uint32 width; ///< bitmap width diff --git a/src/bridge.h b/src/bridge.h index bd85356d6..628eb603e 100644 --- a/src/bridge.h +++ b/src/bridge.h @@ -5,6 +5,8 @@ #ifndef BRIDGE_H #define BRIDGE_H +#include "gfx_type.h" + enum { MAX_BRIDGES = 13 }; diff --git a/src/cargotype.h b/src/cargotype.h index 56a974add..fe55d9099 100644 --- a/src/cargotype.h +++ b/src/cargotype.h @@ -6,6 +6,7 @@ #define CARGOTYPE_H #include "cargo_type.h" +#include "gfx_type.h" typedef uint32 CargoLabel; diff --git a/src/command.cpp b/src/command.cpp index 1b9263b37..7cac47d15 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -17,6 +17,7 @@ #include "genworld.h" #include "newgrf_storage.h" #include "strings_func.h" +#include "gfx_func.h" const char *_cmd_text = NULL; diff --git a/src/command_type.h b/src/command_type.h index d2a7571e9..6a2aad3d0 100644 --- a/src/command_type.h +++ b/src/command_type.h @@ -7,6 +7,7 @@ #include "economy_type.h" #include "strings_type.h" +#include "tile_type.h" /** * Common return value for all commands. Wraps the cost and diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp index 242b17b95..c05e7ffeb 100644 --- a/src/core/math_func.hpp +++ b/src/core/math_func.hpp @@ -17,12 +17,6 @@ #undef abs #endif -/** - * The largest value that can be entered in a variable - * @param type the type of the variable - */ -#define MAX_UVALUE(type) ((type)~(type)0) - /** * Returns the maximum of two values. * diff --git a/src/engine.h b/src/engine.h index 6ee3d8376..9e2815740 100644 --- a/src/engine.h +++ b/src/engine.h @@ -10,6 +10,7 @@ #include "cargo_type.h" #include "vehicle_type.h" #include "command_type.h" +#include "gfx_type.h" #include "sound.h" enum RailVehicleTypes { diff --git a/src/fontcache.cpp b/src/fontcache.cpp index 81f68f0d8..e693d0a7d 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -14,6 +14,7 @@ #include "helpers.hpp" #include "spriteloader/spriteloader.hpp" #include "blitter/factory.hpp" +#include "gfx_func.h" #ifdef WITH_FREETYPE diff --git a/src/fontcache.h b/src/fontcache.h index d5f283840..8df195318 100644 --- a/src/fontcache.h +++ b/src/fontcache.h @@ -3,7 +3,7 @@ #ifndef FONTCACHE_H #define FONTCACHE_H -#include "gfx.h" +#include "gfx_type.h" /** Get the SpriteID mapped to the given font size and key */ SpriteID GetUnicodeGlyph(FontSize size, uint32 key); diff --git a/src/functions.h b/src/functions.h index c4b42dc45..a1e136de9 100644 --- a/src/functions.h +++ b/src/functions.h @@ -8,6 +8,7 @@ #include "core/random_func.hpp" #include "command_type.h" #include "window_type.h" +#include "openttd.h" void UpdateTownMaxPass(Town *t); diff --git a/src/gfx.cpp b/src/gfx.cpp index 66043eec4..b84bf63b3 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -5,7 +5,7 @@ #include "stdafx.h" #include "openttd.h" #include "functions.h" -#include "gfx.h" +#include "gfx_func.h" #include "spritecache.h" #include "string.h" #include "table/palettes.h" @@ -15,7 +15,7 @@ #include "fontcache.h" #include "genworld.h" #include "debug.h" -#include "zoom.hpp" +#include "zoom_func.h" #include "texteff.hpp" #include "blitter/factory.hpp" #include "video/video_driver.hpp" @@ -41,6 +41,9 @@ int _pal_count_dirty; Colour _cur_palette[256]; byte _stringwidth_table[FS_END][224]; +DrawPixelInfo *_cur_dpi; +byte _colour_gradient[16][8]; +bool _use_dos_palette; static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub = NULL); @@ -561,7 +564,7 @@ Dimension GetStringBoundingBox(const char *str) * @param x offset from left side of the screen, if negative offset from the right side * @param y offset from top side of the screen, if negative offset from the bottom * @param real_color colour of the string, see _string_colormap in - * table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx.h + * table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h * @return the x-coordinates where the drawing has finished. If nothing is drawn * the originally passed x-coordinate is returned */ int DoDrawString(const char *string, int x, int y, uint16 real_color) diff --git a/src/gfx.h b/src/gfx.h deleted file mode 100644 index a06a00d30..000000000 --- a/src/gfx.h +++ /dev/null @@ -1,378 +0,0 @@ -/* $Id$ */ - -/** @file gfx.h */ - -/** - * @defgroup dirty Dirty - * - * Handles the repaint of some part of the screen. - * - * Some places in the code are called functions which makes something "dirty". - * This has nothing to do with making a Tile or Window darker or less visible. - * This term comes from memory caching and is used to define an object must - * be repaint. If some data of an object (like a Tile, Window, Vehicle, whatever) - * are changed which are so extensive the object must be repaint its marked - * as "dirty". The video driver repaint this object instead of the whole screen - * (this is btw. also possible if needed). This is used to avoid a - * flickering of the screen by the video driver constantly repainting it. - * - * This whole mechanism is controlled by an rectangle defined in #_invalid_rect. This - * rectangle defines the area on the screen which must be repaint. If a new object - * needs to be repainted this rectangle is extended to 'catch' the object on the - * screen. At some point (which is normaly uninteressted for patch writers) this - * rectangle is send to the video drivers method - * VideoDriver::MakeDirty and it is truncated back to an empty rectangle. At some - * later point (which is uninteressted, too) the video driver - * repaints all these saved rectangle instead of the whole screen and drop the - * rectangle informations. Then a new round begins by marking objects "dirty". - * - * @see VideoDriver::MakeDirty - * @see _invalid_rect - * @see _screen - */ - - -#ifndef GFX_H -#define GFX_H - -#include "openttd.h" -#include "core/math_func.hpp" -#include "core/geometry_type.hpp" -#include "core/enum_type.hpp" -#include "zoom.hpp" - -enum WindowKeyCodes { - WKC_SHIFT = 0x8000, - WKC_CTRL = 0x4000, - WKC_ALT = 0x2000, - WKC_META = 0x1000, - - /* Special ones */ - WKC_NONE = 0, - WKC_ESC = 1, - WKC_BACKSPACE = 2, - WKC_INSERT = 3, - WKC_DELETE = 4, - - WKC_PAGEUP = 5, - WKC_PAGEDOWN = 6, - WKC_END = 7, - WKC_HOME = 8, - - /* Arrow keys */ - WKC_LEFT = 9, - WKC_UP = 10, - WKC_RIGHT = 11, - WKC_DOWN = 12, - - /* Return & tab */ - WKC_RETURN = 13, - WKC_TAB = 14, - - /* Space */ - WKC_SPACE = 32, - - /* Function keys */ - WKC_F1 = 33, - WKC_F2 = 34, - WKC_F3 = 35, - WKC_F4 = 36, - WKC_F5 = 37, - WKC_F6 = 38, - WKC_F7 = 39, - WKC_F8 = 40, - WKC_F9 = 41, - WKC_F10 = 42, - WKC_F11 = 43, - WKC_F12 = 44, - - /* Backquote is the key left of "1" - * we only store this key here, no matter what character is really mapped to it - * on a particular keyboard. (US keyboard: ` and ~ ; German keyboard: ^ and °) */ - WKC_BACKQUOTE = 45, - WKC_PAUSE = 46, - - /* 0-9 are mapped to 48-57 - * A-Z are mapped to 65-90 - * a-z are mapped to 97-122 */ - - /* Numerical keyboard */ - WKC_NUM_0 = 128, - WKC_NUM_1 = 129, - WKC_NUM_2 = 130, - WKC_NUM_3 = 131, - WKC_NUM_4 = 132, - WKC_NUM_5 = 133, - WKC_NUM_6 = 134, - WKC_NUM_7 = 135, - WKC_NUM_8 = 136, - WKC_NUM_9 = 137, - WKC_NUM_DIV = 138, - WKC_NUM_MUL = 139, - WKC_NUM_MINUS = 140, - WKC_NUM_PLUS = 141, - WKC_NUM_ENTER = 142, - WKC_NUM_DECIMAL = 143, - - /* Other keys */ - WKC_SLASH = 144, ///< / Forward slash - WKC_SEMICOLON = 145, ///< ; Semicolon - WKC_EQUALS = 146, ///< = Equals - WKC_L_BRACKET = 147, ///< [ Left square bracket - WKC_BACKSLASH = 148, ///< \ Backslash - WKC_R_BRACKET = 149, ///< ] Right square bracket - WKC_SINGLEQUOTE = 150, ///< ' Single quote - WKC_COMMA = 151, ///< , Comma - WKC_PERIOD = 152, ///< . Period - WKC_MINUS = 153, ///< - Minus -}; - -void GameLoop(); - -void CreateConsole(); - -/** A single sprite of a list of animated cursors */ -struct AnimCursor { - static const CursorID LAST = MAX_UVALUE(CursorID); - CursorID sprite; ///< Must be set to LAST_ANIM when it is the last sprite of the loop - byte display_time; ///< Amount of ticks this sprite will be shown -}; - -struct CursorVars { - Point pos, size, offs, delta; ///< position, size, offset from top-left, and movement - Point draw_pos, draw_size; ///< position and size bounding-box for drawing - SpriteID sprite; ///< current image of cursor - SpriteID pal; - - int wheel; ///< mouse wheel movement - - /* We need two different vars to keep track of how far the scrollwheel moved. - * OSX uses this for scrolling around the map. */ - int v_wheel; - int h_wheel; - - const AnimCursor *animate_list; ///< in case of animated cursor, list of frames - const AnimCursor *animate_cur; ///< in case of animated cursor, current frame - uint animate_timeout; ///< in case of animated cursor, number of ticks to show the current cursor - - bool visible; ///< cursor is visible - bool dirty; ///< the rect occupied by the mouse is dirty (redraw) - bool fix_at; ///< mouse is moving, but cursor is not (used for scrolling) - bool in_window; ///< mouse inside this window, determines drawing logic -}; - -struct DrawPixelInfo { - void *dst_ptr; - int left, top, width, height; - int pitch; - ZoomLevel zoom; -}; - -struct Colour { - byte r; - byte g; - byte b; -}; - - - -extern byte _dirkeys; ///< 1 = left, 2 = up, 4 = right, 8 = down -extern bool _fullscreen; -extern CursorVars _cursor; -extern bool _ctrl_pressed; ///< Is Ctrl pressed? -extern bool _shift_pressed; ///< Is Shift pressed? -extern byte _fast_forward; - -extern bool _left_button_down; -extern bool _left_button_clicked; -extern bool _right_button_down; -extern bool _right_button_clicked; - -extern DrawPixelInfo _screen; - -extern int _pal_first_dirty; -extern int _pal_count_dirty; -extern int _num_resolutions; -extern uint16 _resolutions[32][2]; -extern uint16 _cur_resolution[2]; -extern Colour _cur_palette[256]; - -void HandleKeypress(uint32 key); -void HandleMouseEvents(); -void CSleep(int milliseconds); -void UpdateWindows(); - -uint32 InteractiveRandom(); //< Used for random sequences that are not the same on the other end of the multiplayer link -uint InteractiveRandomRange(uint max); -void DrawChatMessage(); -void DrawMouseCursor(); -void ScreenSizeChanged(); -void HandleExitGameRequest(); -void GameSizeChanged(); -void UndrawMouseCursor(); - -enum FontSize { - FS_NORMAL, - FS_SMALL, - FS_LARGE, - FS_END, -}; -DECLARE_POSTFIX_INCREMENT(FontSize); - -void RedrawScreenRect(int left, int top, int right, int bottom); -void GfxScroll(int left, int top, int width, int height, int xo, int yo); - -/** - * Used to only draw a part of the sprite. - * Draw the subsprite in the rect (sprite_x_offset + left, sprite_y_offset + top) to (sprite_x_offset + right, sprite_y_offset + bottom). - * Both corners are included in the drawing area. - */ -struct SubSprite { - int left, top, right, bottom; -}; - -void DrawSprite(SpriteID img, SpriteID pal, int x, int y, const SubSprite *sub = NULL); - -/* XXX doesn't really belong here, but the only - * consumers always use it in conjunction with DoDrawString() */ -#define UPARROW "\xEE\x8A\x80" -#define DOWNARROW "\xEE\x8A\xAA" - - -int DrawStringCentered(int x, int y, StringID str, uint16 color); -int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color); -int DoDrawStringCentered(int x, int y, const char *str, uint16 color); - -int DrawString(int x, int y, StringID str, uint16 color); -int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw); - -int DoDrawString(const char *string, int x, int y, uint16 color); -int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw); - -void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color); -void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color); - -int DrawStringRightAligned(int x, int y, StringID str, uint16 color); -void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw); -void DrawStringRightAlignedUnderline(int x, int y, StringID str, uint16 color); - -void GfxFillRect(int left, int top, int right, int bottom, int color); -void GfxDrawLine(int left, int top, int right, int bottom, int color); -void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3); - -Dimension GetStringBoundingBox(const char *str); -uint32 FormatStringLinebreaks(char *str, int maxw); -void LoadStringWidthTable(); -void DrawStringMultiCenter(int x, int y, StringID str, int maxw); -uint DrawStringMultiLine(int x, int y, StringID str, int maxw, int maxh = -1); - -/** - * Let the dirty blocks repainting by the video driver. - * - * @ingroup dirty - */ -void DrawDirtyBlocks(); - -/** - * Set a new dirty block. - * - * @ingroup dirty - */ -void SetDirtyBlocks(int left, int top, int right, int bottom); - -/** - * Marks the whole screen as dirty. - * - * @ingroup dirty - */ -void MarkWholeScreenDirty(); - -void GfxInitPalettes(); - -bool FillDrawPixelInfo(DrawPixelInfo* n, int left, int top, int width, int height); - -/* window.cpp */ -void DrawOverlappedWindowForAll(int left, int top, int right, int bottom); - -void SetMouseCursor(SpriteID sprite, SpriteID pal); -void SetAnimatedMouseCursor(const AnimCursor *table); -void CursorTick(); -void DrawMouseCursor(); -void ScreenSizeChanged(); -void UndrawMouseCursor(); -bool ChangeResInGame(int w, int h); -void SortResolutions(int count); -void ToggleFullScreen(bool fs); - -/* gfx.cpp */ -#define ASCII_LETTERSTART 32 -extern FontSize _cur_fontsize; - -byte GetCharacterWidth(FontSize size, uint32 key); - -static inline byte GetCharacterHeight(FontSize size) -{ - switch (size) { - default: NOT_REACHED(); - case FS_NORMAL: return 10; - case FS_SMALL: return 6; - case FS_LARGE: return 18; - } -} - -VARDEF DrawPixelInfo *_cur_dpi; - -enum { - 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 of the strings, see _string_colormap 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, -}; - -/** - * All 16 colour gradients - * 8 colours per gradient from darkest (0) to lightest (7) - */ -VARDEF byte _colour_gradient[16][8]; - -VARDEF bool _use_dos_palette; - -enum StringColorFlags { - IS_PALETTE_COLOR = 0x100, ///< color value is already a real palette color index, not an index of a StringColor -}; - -#endif /* GFX_H */ diff --git a/src/gfx_func.h b/src/gfx_func.h new file mode 100644 index 000000000..837be1e0c --- /dev/null +++ b/src/gfx_func.h @@ -0,0 +1,182 @@ +/* $Id$ */ + +/** @file gfx_func.h Functions related to the gfx engine. */ + +/** + * @defgroup dirty Dirty + * + * Handles the repaint of some part of the screen. + * + * Some places in the code are called functions which makes something "dirty". + * This has nothing to do with making a Tile or Window darker or less visible. + * This term comes from memory caching and is used to define an object must + * be repaint. If some data of an object (like a Tile, Window, Vehicle, whatever) + * are changed which are so extensive the object must be repaint its marked + * as "dirty". The video driver repaint this object instead of the whole screen + * (this is btw. also possible if needed). This is used to avoid a + * flickering of the screen by the video driver constantly repainting it. + * + * This whole mechanism is controlled by an rectangle defined in #_invalid_rect. This + * rectangle defines the area on the screen which must be repaint. If a new object + * needs to be repainted this rectangle is extended to 'catch' the object on the + * screen. At some point (which is normaly uninteressted for patch writers) this + * rectangle is send to the video drivers method + * VideoDriver::MakeDirty and it is truncated back to an empty rectangle. At some + * later point (which is uninteressted, too) the video driver + * repaints all these saved rectangle instead of the whole screen and drop the + * rectangle informations. Then a new round begins by marking objects "dirty". + * + * @see VideoDriver::MakeDirty + * @see _invalid_rect + * @see _screen + */ + + +#ifndef GFX_FUNC_H +#define GFX_FUNC_H + +#include "gfx_type.h" +#include "strings_type.h" + +void GameLoop(); + +void CreateConsole(); + +extern byte _dirkeys; ///< 1 = left, 2 = up, 4 = right, 8 = down +extern bool _fullscreen; +extern CursorVars _cursor; +extern bool _ctrl_pressed; ///< Is Ctrl pressed? +extern bool _shift_pressed; ///< Is Shift pressed? +extern byte _fast_forward; + +extern bool _left_button_down; +extern bool _left_button_clicked; +extern bool _right_button_down; +extern bool _right_button_clicked; + +extern DrawPixelInfo _screen; + +extern int _pal_first_dirty; +extern int _pal_count_dirty; +extern int _num_resolutions; +extern uint16 _resolutions[32][2]; +extern uint16 _cur_resolution[2]; +extern Colour _cur_palette[256]; + +void HandleKeypress(uint32 key); +void HandleMouseEvents(); +void CSleep(int milliseconds); +void UpdateWindows(); + +uint32 InteractiveRandom(); //< Used for random sequences that are not the same on the other end of the multiplayer link +uint InteractiveRandomRange(uint max); +void DrawChatMessage(); +void DrawMouseCursor(); +void ScreenSizeChanged(); +void HandleExitGameRequest(); +void GameSizeChanged(); +void UndrawMouseCursor(); + +void RedrawScreenRect(int left, int top, int right, int bottom); +void GfxScroll(int left, int top, int width, int height, int xo, int yo); + +void DrawSprite(SpriteID img, SpriteID pal, int x, int y, const SubSprite *sub = NULL); + +/* XXX doesn't really belong here, but the only + * consumers always use it in conjunction with DoDrawString() */ +#define UPARROW "\xEE\x8A\x80" +#define DOWNARROW "\xEE\x8A\xAA" + + +int DrawStringCentered(int x, int y, StringID str, uint16 color); +int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color); +int DoDrawStringCentered(int x, int y, const char *str, uint16 color); + +int DrawString(int x, int y, StringID str, uint16 color); +int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw); + +int DoDrawString(const char *string, int x, int y, uint16 color); +int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw); + +void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color); +void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color); + +int DrawStringRightAligned(int x, int y, StringID str, uint16 color); +void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw); +void DrawStringRightAlignedUnderline(int x, int y, StringID str, uint16 color); + +void GfxFillRect(int left, int top, int right, int bottom, int color); +void GfxDrawLine(int left, int top, int right, int bottom, int color); +void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3); + +Dimension GetStringBoundingBox(const char *str); +uint32 FormatStringLinebreaks(char *str, int maxw); +void LoadStringWidthTable(); +void DrawStringMultiCenter(int x, int y, StringID str, int maxw); +uint DrawStringMultiLine(int x, int y, StringID str, int maxw, int maxh = -1); + +/** + * Let the dirty blocks repainting by the video driver. + * + * @ingroup dirty + */ +void DrawDirtyBlocks(); + +/** + * Set a new dirty block. + * + * @ingroup dirty + */ +void SetDirtyBlocks(int left, int top, int right, int bottom); + +/** + * Marks the whole screen as dirty. + * + * @ingroup dirty + */ +void MarkWholeScreenDirty(); + +void GfxInitPalettes(); + +bool FillDrawPixelInfo(DrawPixelInfo* n, int left, int top, int width, int height); + +/* window.cpp */ +void DrawOverlappedWindowForAll(int left, int top, int right, int bottom); + +void SetMouseCursor(SpriteID sprite, SpriteID pal); +void SetAnimatedMouseCursor(const AnimCursor *table); +void CursorTick(); +void DrawMouseCursor(); +void ScreenSizeChanged(); +void UndrawMouseCursor(); +bool ChangeResInGame(int w, int h); +void SortResolutions(int count); +void ToggleFullScreen(bool fs); + +/* gfx.cpp */ +#define ASCII_LETTERSTART 32 +extern FontSize _cur_fontsize; + +byte GetCharacterWidth(FontSize size, uint32 key); + +static inline byte GetCharacterHeight(FontSize size) +{ + switch (size) { + default: NOT_REACHED(); + case FS_NORMAL: return 10; + case FS_SMALL: return 6; + case FS_LARGE: return 18; + } +} + +extern DrawPixelInfo *_cur_dpi; + +/** + * All 16 colour gradients + * 8 colours per gradient from darkest (0) to lightest (7) + */ +extern byte _colour_gradient[16][8]; + +extern bool _use_dos_palette; + +#endif /* GFX_FUNC_H */ diff --git a/src/gfx_type.h b/src/gfx_type.h new file mode 100644 index 000000000..4e6cf28ff --- /dev/null +++ b/src/gfx_type.h @@ -0,0 +1,210 @@ +/* $Id$ */ + +/** @file gfx_type.h Types related to the graphics and/or input devices. */ + +#ifndef GFX_TYPE_H +#define GFX_TYPE_H + +#include "core/enum_type.hpp" +#include "core/geometry_type.hpp" +#include "zoom_type.h" + +typedef uint32 SpriteID; ///< The number of a sprite, without mapping bits and colortables +struct PalSpriteID { + SpriteID sprite; + SpriteID pal; +}; +typedef int32 CursorID; + +enum WindowKeyCodes { + WKC_SHIFT = 0x8000, + WKC_CTRL = 0x4000, + WKC_ALT = 0x2000, + WKC_META = 0x1000, + + /* Special ones */ + WKC_NONE = 0, + WKC_ESC = 1, + WKC_BACKSPACE = 2, + WKC_INSERT = 3, + WKC_DELETE = 4, + + WKC_PAGEUP = 5, + WKC_PAGEDOWN = 6, + WKC_END = 7, + WKC_HOME = 8, + + /* Arrow keys */ + WKC_LEFT = 9, + WKC_UP = 10, + WKC_RIGHT = 11, + WKC_DOWN = 12, + + /* Return & tab */ + WKC_RETURN = 13, + WKC_TAB = 14, + + /* Space */ + WKC_SPACE = 32, + + /* Function keys */ + WKC_F1 = 33, + WKC_F2 = 34, + WKC_F3 = 35, + WKC_F4 = 36, + WKC_F5 = 37, + WKC_F6 = 38, + WKC_F7 = 39, + WKC_F8 = 40, + WKC_F9 = 41, + WKC_F10 = 42, + WKC_F11 = 43, + WKC_F12 = 44, + + /* Backquote is the key left of "1" + * we only store this key here, no matter what character is really mapped to it + * on a particular keyboard. (US keyboard: ` and ~ ; German keyboard: ^ and °) */ + WKC_BACKQUOTE = 45, + WKC_PAUSE = 46, + + /* 0-9 are mapped to 48-57 + * A-Z are mapped to 65-90 + * a-z are mapped to 97-122 */ + + /* Numerical keyboard */ + WKC_NUM_0 = 128, + WKC_NUM_1 = 129, + WKC_NUM_2 = 130, + WKC_NUM_3 = 131, + WKC_NUM_4 = 132, + WKC_NUM_5 = 133, + WKC_NUM_6 = 134, + WKC_NUM_7 = 135, + WKC_NUM_8 = 136, + WKC_NUM_9 = 137, + WKC_NUM_DIV = 138, + WKC_NUM_MUL = 139, + WKC_NUM_MINUS = 140, + WKC_NUM_PLUS = 141, + WKC_NUM_ENTER = 142, + WKC_NUM_DECIMAL = 143, + + /* Other keys */ + WKC_SLASH = 144, ///< / Forward slash + WKC_SEMICOLON = 145, ///< ; Semicolon + WKC_EQUALS = 146, ///< = Equals + WKC_L_BRACKET = 147, ///< [ Left square bracket + WKC_BACKSLASH = 148, ///< \ Backslash + WKC_R_BRACKET = 149, ///< ] Right square bracket + WKC_SINGLEQUOTE = 150, ///< ' Single quote + WKC_COMMA = 151, ///< , Comma + WKC_PERIOD = 152, ///< . Period + WKC_MINUS = 153, ///< - Minus +}; + +/** A single sprite of a list of animated cursors */ +struct AnimCursor { + static const CursorID LAST = MAX_UVALUE(CursorID); + CursorID sprite; ///< Must be set to LAST_ANIM when it is the last sprite of the loop + byte display_time; ///< Amount of ticks this sprite will be shown +}; + +struct CursorVars { + Point pos, size, offs, delta; ///< position, size, offset from top-left, and movement + Point draw_pos, draw_size; ///< position and size bounding-box for drawing + SpriteID sprite; ///< current image of cursor + SpriteID pal; + + int wheel; ///< mouse wheel movement + + /* We need two different vars to keep track of how far the scrollwheel moved. + * OSX uses this for scrolling around the map. */ + int v_wheel; + int h_wheel; + + const AnimCursor *animate_list; ///< in case of animated cursor, list of frames + const AnimCursor *animate_cur; ///< in case of animated cursor, current frame + uint animate_timeout; ///< in case of animated cursor, number of ticks to show the current cursor + + bool visible; ///< cursor is visible + bool dirty; ///< the rect occupied by the mouse is dirty (redraw) + bool fix_at; ///< mouse is moving, but cursor is not (used for scrolling) + bool in_window; ///< mouse inside this window, determines drawing logic +}; + +struct DrawPixelInfo { + void *dst_ptr; + int left, top, width, height; + int pitch; + ZoomLevel zoom; +}; + +struct Colour { + byte r; + byte g; + byte b; +}; + +enum FontSize { + FS_NORMAL, + FS_SMALL, + FS_LARGE, + FS_END, +}; +DECLARE_POSTFIX_INCREMENT(FontSize); + +/** + * Used to only draw a part of the sprite. + * Draw the subsprite in the rect (sprite_x_offset + left, sprite_y_offset + top) to (sprite_x_offset + right, sprite_y_offset + bottom). + * Both corners are included in the drawing area. + */ +struct SubSprite { + int left, top, right, bottom; +}; + +enum { + 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 of the strings, see _string_colormap 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, +}; + +enum StringColorFlags { + IS_PALETTE_COLOR = 0x100, ///< color value is already a real palette color index, not an index of a StringColor +}; + +#endif /* GFX_TYPE_H */ diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index a6694dece..b98ea8223 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -16,6 +16,7 @@ #include "md5.h" #include "variables.h" #include "fontcache.h" +#include "gfx_func.h" #include struct MD5File { diff --git a/src/gfxinit.h b/src/gfxinit.h index a59cc6259..2ebeac69f 100644 --- a/src/gfxinit.h +++ b/src/gfxinit.h @@ -5,6 +5,8 @@ #ifndef GFXINIT_H #define GFXINIT_H +#include "gfx_type.h" + void CheckExternalFiles(); void GfxLoadSprites(); void LoadSpritesIndexed(int file_index, uint *sprite_id, const SpriteID *index_tbl); diff --git a/src/gui.h b/src/gui.h index ad02b2ef5..d48e83ee1 100644 --- a/src/gui.h +++ b/src/gui.h @@ -8,7 +8,7 @@ #include "string.h" #include "window_type.h" #include "vehicle_type.h" -#include "gfx.h" +#include "gfx_type.h" /* main_gui.cpp */ void CcPlaySound10(bool success, TileIndex tile, uint32 p1, uint32 p2); diff --git a/src/heightmap.cpp b/src/heightmap.cpp index b6a62edb4..b287748f6 100644 --- a/src/heightmap.cpp +++ b/src/heightmap.cpp @@ -15,6 +15,7 @@ #include "saveload.h" #include "bmp.h" #include "helpers.hpp" +#include "gfx_func.h" /** * Convert RGB colors to Grayscale using 29.9% Red, 58.7% Green, 11.4% Blue diff --git a/src/main_gui.cpp b/src/main_gui.cpp index d511d197c..a5505e2e5 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -50,6 +50,7 @@ #include "industry.h" #include "transparency.h" #include "strings_func.h" +#include "zoom_func.h" static int _rename_id = 1; static int _rename_what = -1; diff --git a/src/misc.cpp b/src/misc.cpp index 3742f971d..1827f17d4 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -25,6 +25,7 @@ #include "group.h" #include "viewport.h" #include "economy_func.h" +#include "zoom_func.h" char _name_array[512][32]; diff --git a/src/misc/dbg_helpers.cpp b/src/misc/dbg_helpers.cpp index 2e95ee1b8..a07c5ce60 100644 --- a/src/misc/dbg_helpers.cpp +++ b/src/misc/dbg_helpers.cpp @@ -2,6 +2,7 @@ /** @file dbg_helpers.cpp */ #include "../stdafx.h" +#include "../openttd.h" #include "../direction_type.h" #include "../rail.h" #include "../rail_map.h" diff --git a/src/misc_cmd.cpp b/src/misc_cmd.cpp index 2128a6f32..e8e0d7630 100644 --- a/src/misc_cmd.cpp +++ b/src/misc_cmd.cpp @@ -19,6 +19,7 @@ #include "player_face.h" #include "strings_func.h" #include "vehicle.h" +#include "gfx_func.h" /** Change the player's face. * @param tile unused diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 94fb1ce25..9861c4d44 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -40,6 +40,7 @@ #include "fileio.h" #include "fios.h" #include "tile_cmd.h" +#include "zoom_func.h" /* Variables to display file lists */ FiosItem *_fios_list; diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 81418592e..20e8f18a9 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -19,7 +19,6 @@ #include "../gui.h" #include "../window_gui.h" #include "../textbuf_gui.h" -#include "../gfx.h" #include "../variables.h" #include "network_server.h" #include "network_udp.h" diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 2520e6c01..8ad70d175 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -47,6 +47,7 @@ #include "fios.h" #include "rail.h" #include "strings_func.h" +#include "gfx_func.h" /* TTDPatch extended GRF format codec * (c) Petr Baudis 2004 (GPL'd) diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index d0167c71b..788a07207 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -23,7 +23,7 @@ #include "cargotype.h" #include "town_map.h" #include "newgrf_town.h" -#include "gfx.h" +#include "gfx_func.h" static StationClass station_classes[STAT_CLASS_MAX]; diff --git a/src/oldloader.cpp b/src/oldloader.cpp index ba0ab6112..91711f3a1 100644 --- a/src/oldloader.cpp +++ b/src/oldloader.cpp @@ -24,7 +24,7 @@ #include "newgrf_config.h" #include "ai/ai.h" #include "date.h" -#include "zoom.hpp" +#include "zoom_func.h" enum { HEADER_SIZE = 49, diff --git a/src/openttd.cpp b/src/openttd.cpp index cac5b908b..d1e85eb15 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -64,6 +64,7 @@ #include "music/music_driver.hpp" #include "video/video_driver.hpp" #include "strings_func.h" +#include "zoom_func.h" #include "bridge_map.h" #include "clear_map.h" diff --git a/src/openttd.h b/src/openttd.h index 7ad6de5b9..3df5e7403 100644 --- a/src/openttd.h +++ b/src/openttd.h @@ -26,12 +26,6 @@ struct DrawPixelInfo; struct Group; typedef byte VehicleOrderID; ///< The index of an order within its current vehicle (not pool related) typedef byte LandscapeID; -typedef uint32 SpriteID; ///< The number of a sprite, without mapping bits and colortables -struct PalSpriteID { - SpriteID sprite; - SpriteID pal; -}; -typedef int32 CursorID; typedef uint16 EngineID; typedef uint16 UnitID; diff --git a/src/os/macosx/splash.cpp b/src/os/macosx/splash.cpp index f342f32d5..747ea59b9 100644 --- a/src/os/macosx/splash.cpp +++ b/src/os/macosx/splash.cpp @@ -5,7 +5,7 @@ #include "../../variables.h" #include "../../debug.h" #include "../../functions.h" -#include "../../gfx.h" +#include "../../gfx_func.h" #include "../../fileio.h" #include "../../blitter/factory.hpp" diff --git a/src/players.cpp b/src/players.cpp index b54ef6a6c..320e8f0f0 100644 --- a/src/players.cpp +++ b/src/players.cpp @@ -29,7 +29,7 @@ #include "window_func.h" #include "tile_map.h" #include "strings_func.h" -#include "gfx.h" +#include "gfx_func.h" /** * Sets the local player and updates the patch settings that are set on a diff --git a/src/rail.h b/src/rail.h index bffda08e7..9975507fc 100644 --- a/src/rail.h +++ b/src/rail.h @@ -8,9 +8,10 @@ #include "rail_type.h" #include "track_type.h" #include "vehicle_type.h" +#include "gfx_type.h" #include "core/bitmath_func.hpp" -#include "variables.h" #include "economy_func.h" +#include "variables.h" /** This struct contains all the info that is needed to draw and construct tracks. */ diff --git a/src/saveload.cpp b/src/saveload.cpp index 73e688701..22cb8588d 100644 --- a/src/saveload.cpp +++ b/src/saveload.cpp @@ -28,6 +28,7 @@ #include "table/strings.h" #include "window_func.h" #include "strings_func.h" +#include "gfx_func.h" #include extern const uint16 SAVEGAME_VERSION = 83; diff --git a/src/screenshot.cpp b/src/screenshot.cpp index f88c3b528..c77dce722 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -16,6 +16,7 @@ #include "blitter/factory.hpp" #include "fileio.h" #include "strings_func.h" +#include "zoom_func.h" char _screenshot_format_name[8]; uint _num_screenshot_formats; diff --git a/src/signs.cpp b/src/signs.cpp index 4ea465fb4..ba9e80786 100644 --- a/src/signs.cpp +++ b/src/signs.cpp @@ -16,6 +16,7 @@ #include "misc/autoptr.hpp" #include "strings_func.h" #include "viewport.h" +#include "zoom_func.h" SignID _new_sign_id; uint _total_signs; diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index a5ba7d205..0e6b340af 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -27,6 +27,7 @@ #include "blitter/factory.hpp" #include "tunnelbridge_map.h" #include "strings_func.h" +#include "zoom_func.h" static const Widget _smallmap_widgets[] = { diff --git a/src/sprite.h b/src/sprite.h index 00ceed3ee..686db5e75 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -5,6 +5,8 @@ #ifndef SPRITE_H #define SPRITE_H +#include "gfx_type.h" + #define GENERAL_SPRITE_COLOR(color) ((color) + PALETTE_RECOLOR_START) #define PLAYER_SPRITE_COLOR(owner) (GENERAL_SPRITE_COLOR(_player_colors[owner])) diff --git a/src/spritecache.h b/src/spritecache.h index d264ae210..371fc5601 100644 --- a/src/spritecache.h +++ b/src/spritecache.h @@ -5,6 +5,8 @@ #ifndef SPRITECACHE_H #define SPRITECACHE_H +#include "gfx_type.h" + struct Sprite { byte height; uint16 width; diff --git a/src/spriteloader/grf.cpp b/src/spriteloader/grf.cpp index e41732b50..e225ea52d 100644 --- a/src/spriteloader/grf.cpp +++ b/src/spriteloader/grf.cpp @@ -3,7 +3,7 @@ /** @file grf.cpp */ #include "../stdafx.h" -#include "../gfx.h" +#include "../gfx_func.h" #include "../fileio.h" #include "../debug.h" #include "grf.hpp" diff --git a/src/spriteloader/png.cpp b/src/spriteloader/png.cpp index 7429dda68..0a626d5fe 100644 --- a/src/spriteloader/png.cpp +++ b/src/spriteloader/png.cpp @@ -5,7 +5,7 @@ #ifdef WITH_PNG #include "../stdafx.h" -#include "../gfx.h" +#include "../gfx_func.h" #include "../fileio.h" #include "../variables.h" #include "../debug.h" diff --git a/src/station.cpp b/src/station.cpp index f9c56b7dd..e713ceee8 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -32,6 +32,7 @@ #include "cargotype.h" #include "roadveh.h" #include "station_gui.h" +#include "zoom_func.h" Station::Station(TileIndex tile) { diff --git a/src/stdafx.h b/src/stdafx.h index f3a277d5e..90bd721cd 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -374,4 +374,10 @@ assert_compile(sizeof(uint8) == 1); #define MAX_PATH 260 #endif +/** + * The largest value that can be entered in a variable + * @param type the type of the variable + */ +#define MAX_UVALUE(type) ((type)~(type)0) + #endif /* STDAFX_H */ diff --git a/src/table/sprites.h b/src/table/sprites.h index 2d352ebd2..02d931df3 100644 --- a/src/table/sprites.h +++ b/src/table/sprites.h @@ -32,6 +32,8 @@ * @todo Split the "Sprites" enum into smaller chunks and document them */ +#include "../gfx_type.h" + enum Sprites { SPR_SELECT_TILE = 752, SPR_DOT = 774, // corner marker for lower/raise land diff --git a/src/transparency.h b/src/transparency.h index fff77d70d..344946769 100644 --- a/src/transparency.h +++ b/src/transparency.h @@ -5,6 +5,8 @@ #ifndef TRANSPARENCY_H #define TRANSPARENCY_H +#include "gfx_func.h" + /** * Transparency option bits: which position in _transparency_opt stands for which transparency. * If you change the order, change the order of the ShowTransparencyToolbar() stuff in transparency_gui.cpp too. diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 8cd999bf9..79138d85c 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -42,6 +42,7 @@ #include "group.h" #include "order.h" #include "strings_func.h" +#include "zoom_func.h" #define INVALID_COORD (0x7fffffff) #define GEN_HASH(x, y) ((GB((y), 6, 6) << 6) + GB((x), 7, 6)) diff --git a/src/vehicle.h b/src/vehicle.h index 0b7f35d67..b5ba98a49 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -6,16 +6,17 @@ #define VEHICLE_H #include "vehicle_type.h" -#include "oldpool.h" -#include "order.h" #include "track_type.h" #include "rail_type.h" #include "road_type.h" #include "cargo_type.h" #include "window_type.h" +#include "gfx_type.h" +#include "command_type.h" +#include "oldpool.h" +#include "order.h" #include "cargopacket.h" #include "texteff.hpp" -#include "command_type.h" /** Road vehicle states */ enum RoadVehicleStates { diff --git a/src/video/dedicated_v.cpp b/src/video/dedicated_v.cpp index f2d2aecab..70732bb73 100644 --- a/src/video/dedicated_v.cpp +++ b/src/video/dedicated_v.cpp @@ -7,7 +7,7 @@ #include "../openttd.h" #include "../debug.h" #include "../functions.h" -#include "../gfx.h" +#include "../gfx_func.h" #include "../network/network.h" #include "../console.h" #include "../variables.h" diff --git a/src/video/null_v.cpp b/src/video/null_v.cpp index 2250cbaf0..7d2fa512d 100644 --- a/src/video/null_v.cpp +++ b/src/video/null_v.cpp @@ -2,7 +2,7 @@ #include "../stdafx.h" #include "../openttd.h" -#include "../gfx.h" +#include "../gfx_func.h" #include "../variables.h" #include "../debug.h" #include "../blitter/factory.hpp" diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp index 9d4a7986a..05fb771b7 100644 --- a/src/video/sdl_v.cpp +++ b/src/video/sdl_v.cpp @@ -7,7 +7,7 @@ #include "../openttd.h" #include "../debug.h" #include "../functions.h" -#include "../gfx.h" +#include "../gfx_func.h" #include "../sdl.h" #include "../variables.h" #include "../blitter/factory.hpp" diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index 1fc344fac..d3d80daee 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -3,7 +3,7 @@ #include "../stdafx.h" #include "../openttd.h" #include "../functions.h" -#include "../gfx.h" +#include "../gfx_func.h" #include "../variables.h" #include "../win32.h" #include "../blitter/factory.hpp" diff --git a/src/viewport.cpp b/src/viewport.cpp index b3a7e7d20..78b7f03a9 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -25,6 +25,7 @@ #include "blitter/factory.hpp" #include "transparency.h" #include "strings_func.h" +#include "zoom_func.h" #define VIEWPORT_DRAW_MEM (65536 * 2) diff --git a/src/viewport.h b/src/viewport.h index 451c0a42d..32b0c50be 100644 --- a/src/viewport.h +++ b/src/viewport.h @@ -5,10 +5,10 @@ #ifndef VIEWPORT_H #define VIEWPORT_H -#include "zoom.hpp" +#include "zoom_type.h" #include "window_type.h" #include "vehicle_type.h" -#include "gfx.h" +#include "gfx_func.h" struct ViewPort { int left,top; // screen coordinates for the viewport diff --git a/src/window.cpp b/src/window.cpp index 6df6609c4..4a9a4e600 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -17,6 +17,7 @@ #include "helpers.hpp" #include "blitter/factory.hpp" #include "window_gui.h" +#include "zoom_func.h" /* delta between mouse cursor and upper left corner of dragged window */ static Point _drag_delta; diff --git a/src/zoom.hpp b/src/zoom.hpp deleted file mode 100644 index 56e3c6099..000000000 --- a/src/zoom.hpp +++ /dev/null @@ -1,94 +0,0 @@ -/* $Id$ */ - -/** @file zoom.hpp */ - -#ifndef ZOOM_HPP -#define ZOOM_HPP - -#include "core/enum_type.hpp" - -enum ZoomLevel { - /* Our possible zoom-levels */ - ZOOM_LVL_BEGIN = 0, - ZOOM_LVL_NORMAL = 0, - ZOOM_LVL_OUT_2X, - ZOOM_LVL_OUT_4X, - ZOOM_LVL_OUT_8X, - ZOOM_LVL_END, - - /* Here we define in which zoom viewports are */ - ZOOM_LVL_VIEWPORT = ZOOM_LVL_NORMAL, - ZOOM_LVL_NEWS = ZOOM_LVL_NORMAL, - ZOOM_LVL_INDUSTRY = ZOOM_LVL_OUT_2X, - ZOOM_LVL_TOWN = ZOOM_LVL_OUT_2X, - ZOOM_LVL_AIRCRAFT = ZOOM_LVL_NORMAL, - ZOOM_LVL_SHIP = ZOOM_LVL_NORMAL, - ZOOM_LVL_TRAIN = ZOOM_LVL_NORMAL, - ZOOM_LVL_ROADVEH = ZOOM_LVL_NORMAL, - ZOOM_LVL_WORLD_SCREENSHOT = ZOOM_LVL_NORMAL, - - ZOOM_LVL_DETAIL = ZOOM_LVL_OUT_2X, ///< All zoomlevels below or equal to this, will result in details on the screen, like road-work, ... - - ZOOM_LVL_MIN = ZOOM_LVL_NORMAL, - ZOOM_LVL_MAX = ZOOM_LVL_OUT_8X, -}; - -extern ZoomLevel _saved_scrollpos_zoom; - -DECLARE_POSTFIX_INCREMENT(ZoomLevel) - -/** - * Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) - * When shifting right, value is rounded up - * @param value value to shift - * @param zoom zoom level to shift to - * @return shifted value - */ -static inline int ScaleByZoom(int value, ZoomLevel zoom) -{ - if (zoom == ZOOM_LVL_NORMAL) return value; - int izoom = zoom - ZOOM_LVL_NORMAL; - return (zoom > ZOOM_LVL_NORMAL) ? value << izoom : (value + (1 << -izoom) - 1) >> -izoom; -} - -/** - * Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL) - * When shifting right, value is rounded up - * @param value value to shift - * @param zoom zoom level to shift to - * @return shifted value - */ -static inline int UnScaleByZoom(int value, ZoomLevel zoom) -{ - if (zoom == ZOOM_LVL_NORMAL) return value; - int izoom = zoom - ZOOM_LVL_NORMAL; - return (zoom > ZOOM_LVL_NORMAL) ? (value + (1 << izoom) - 1) >> izoom : value << -izoom; -} - -/** - * Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) - * @param value value to shift - * @param zoom zoom level to shift to - * @return shifted value - */ -static inline int ScaleByZoomLower(int value, ZoomLevel zoom) -{ - if (zoom == ZOOM_LVL_NORMAL) return value; - int izoom = zoom - ZOOM_LVL_NORMAL; - return (zoom > ZOOM_LVL_NORMAL) ? value << izoom : value >> -izoom; -} - -/** - * Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL) - * @param value value to shift - * @param zoom zoom level to shift to - * @return shifted value - */ -static inline int UnScaleByZoomLower(int value, ZoomLevel zoom) -{ - if (zoom == ZOOM_LVL_NORMAL) return value; - int izoom = zoom - ZOOM_LVL_NORMAL; - return (zoom > ZOOM_LVL_NORMAL) ? value >> izoom : value << -izoom; -} - -#endif /* ZOOM_HPP */ diff --git a/src/zoom_func.h b/src/zoom_func.h new file mode 100644 index 000000000..4a4fe83ff --- /dev/null +++ b/src/zoom_func.h @@ -0,0 +1,66 @@ +/* $Id$ */ + +/** @file zoom.hpp */ + +#ifndef ZOOM_FUNC_H +#define ZOOM_FUNC_H + +#include "zoom_type.h" + +extern ZoomLevel _saved_scrollpos_zoom; + +/** + * Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) + * When shifting right, value is rounded up + * @param value value to shift + * @param zoom zoom level to shift to + * @return shifted value + */ +static inline int ScaleByZoom(int value, ZoomLevel zoom) +{ + if (zoom == ZOOM_LVL_NORMAL) return value; + int izoom = zoom - ZOOM_LVL_NORMAL; + return (zoom > ZOOM_LVL_NORMAL) ? value << izoom : (value + (1 << -izoom) - 1) >> -izoom; +} + +/** + * Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL) + * When shifting right, value is rounded up + * @param value value to shift + * @param zoom zoom level to shift to + * @return shifted value + */ +static inline int UnScaleByZoom(int value, ZoomLevel zoom) +{ + if (zoom == ZOOM_LVL_NORMAL) return value; + int izoom = zoom - ZOOM_LVL_NORMAL; + return (zoom > ZOOM_LVL_NORMAL) ? (value + (1 << izoom) - 1) >> izoom : value << -izoom; +} + +/** + * Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) + * @param value value to shift + * @param zoom zoom level to shift to + * @return shifted value + */ +static inline int ScaleByZoomLower(int value, ZoomLevel zoom) +{ + if (zoom == ZOOM_LVL_NORMAL) return value; + int izoom = zoom - ZOOM_LVL_NORMAL; + return (zoom > ZOOM_LVL_NORMAL) ? value << izoom : value >> -izoom; +} + +/** + * Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL) + * @param value value to shift + * @param zoom zoom level to shift to + * @return shifted value + */ +static inline int UnScaleByZoomLower(int value, ZoomLevel zoom) +{ + if (zoom == ZOOM_LVL_NORMAL) return value; + int izoom = zoom - ZOOM_LVL_NORMAL; + return (zoom > ZOOM_LVL_NORMAL) ? value >> izoom : value << -izoom; +} + +#endif /* ZOOM_FUNC_H */ diff --git a/src/zoom_type.h b/src/zoom_type.h new file mode 100644 index 000000000..2929e7309 --- /dev/null +++ b/src/zoom_type.h @@ -0,0 +1,37 @@ +/* $Id$ */ + +/** @file zoom_type.h Types related to zooming in and out. */ + +#ifndef ZOOM_TYPE_H +#define ZOOM_TYPE_H + +#include "core/enum_type.hpp" + +enum ZoomLevel { + /* Our possible zoom-levels */ + ZOOM_LVL_BEGIN = 0, + ZOOM_LVL_NORMAL = 0, + ZOOM_LVL_OUT_2X, + ZOOM_LVL_OUT_4X, + ZOOM_LVL_OUT_8X, + ZOOM_LVL_END, + + /* Here we define in which zoom viewports are */ + ZOOM_LVL_VIEWPORT = ZOOM_LVL_NORMAL, + ZOOM_LVL_NEWS = ZOOM_LVL_NORMAL, + ZOOM_LVL_INDUSTRY = ZOOM_LVL_OUT_2X, + ZOOM_LVL_TOWN = ZOOM_LVL_OUT_2X, + ZOOM_LVL_AIRCRAFT = ZOOM_LVL_NORMAL, + ZOOM_LVL_SHIP = ZOOM_LVL_NORMAL, + ZOOM_LVL_TRAIN = ZOOM_LVL_NORMAL, + ZOOM_LVL_ROADVEH = ZOOM_LVL_NORMAL, + ZOOM_LVL_WORLD_SCREENSHOT = ZOOM_LVL_NORMAL, + + ZOOM_LVL_DETAIL = ZOOM_LVL_OUT_2X, ///< All zoomlevels below or equal to this, will result in details on the screen, like road-work, ... + + ZOOM_LVL_MIN = ZOOM_LVL_NORMAL, + ZOOM_LVL_MAX = ZOOM_LVL_OUT_8X, +}; +DECLARE_POSTFIX_INCREMENT(ZoomLevel) + +#endif /* ZOOM_TYPE_H */ -- cgit v1.2.3-54-g00ecf