PageRenderTime 25ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/src/gfx_func.h

https://bitbucket.org/bvrijkorte/openttd-cyclic-timetables
C Header | 219 lines | 112 code | 49 blank | 58 comment | 0 complexity | 4463c1ae7c598e2d9ef61d653cf925dc MD5 | raw file
  1. /* $Id$ */
  2. /*
  3. * This file is part of OpenTTD.
  4. * 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.
  5. * 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.
  6. * 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/>.
  7. */
  8. /** @file gfx_func.h Functions related to the gfx engine. */
  9. /**
  10. * @defgroup dirty Dirty
  11. *
  12. * Handles the repaint of some part of the screen.
  13. *
  14. * Some places in the code are called functions which makes something "dirty".
  15. * This has nothing to do with making a Tile or Window darker or less visible.
  16. * This term comes from memory caching and is used to define an object must
  17. * be repaint. If some data of an object (like a Tile, Window, Vehicle, whatever)
  18. * are changed which are so extensive the object must be repaint its marked
  19. * as "dirty". The video driver repaint this object instead of the whole screen
  20. * (this is btw. also possible if needed). This is used to avoid a
  21. * flickering of the screen by the video driver constantly repainting it.
  22. *
  23. * This whole mechanism is controlled by an rectangle defined in #_invalid_rect. This
  24. * rectangle defines the area on the screen which must be repaint. If a new object
  25. * needs to be repainted this rectangle is extended to 'catch' the object on the
  26. * screen. At some point (which is normally uninteresting for patch writers) this
  27. * rectangle is send to the video drivers method
  28. * VideoDriver::MakeDirty and it is truncated back to an empty rectangle. At some
  29. * later point (which is uninteresting, too) the video driver
  30. * repaints all these saved rectangle instead of the whole screen and drop the
  31. * rectangle informations. Then a new round begins by marking objects "dirty".
  32. *
  33. * @see VideoDriver::MakeDirty
  34. * @see _invalid_rect
  35. * @see _screen
  36. */
  37. #ifndef GFX_FUNC_H
  38. #define GFX_FUNC_H
  39. #include "gfx_type.h"
  40. #include "strings_type.h"
  41. void GameLoop();
  42. void CreateConsole();
  43. extern byte _dirkeys; ///< 1 = left, 2 = up, 4 = right, 8 = down
  44. extern bool _fullscreen;
  45. extern CursorVars _cursor;
  46. extern bool _ctrl_pressed; ///< Is Ctrl pressed?
  47. extern bool _shift_pressed; ///< Is Shift pressed?
  48. extern byte _fast_forward;
  49. extern bool _left_button_down;
  50. extern bool _left_button_clicked;
  51. extern bool _right_button_down;
  52. extern bool _right_button_clicked;
  53. extern DrawPixelInfo _screen;
  54. extern bool _screen_disable_anim; ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
  55. extern int _num_resolutions;
  56. extern Dimension _resolutions[32];
  57. extern Dimension _cur_resolution;
  58. extern Palette _cur_palette; ///< Current palette
  59. void HandleKeypress(uint32 key);
  60. void HandleCtrlChanged();
  61. void HandleMouseEvents();
  62. void CSleep(int milliseconds);
  63. void UpdateWindows();
  64. void DrawMouseCursor();
  65. void ScreenSizeChanged();
  66. void GameSizeChanged();
  67. void UndrawMouseCursor();
  68. /** Size of the buffer used for drawing strings. */
  69. static const int DRAW_STRING_BUFFER = 2048;
  70. void RedrawScreenRect(int left, int top, int right, int bottom);
  71. void GfxScroll(int left, int top, int width, int height, int xo, int yo);
  72. Dimension GetSpriteSize(SpriteID sprid, Point *offset = NULL, ZoomLevel zoom = ZOOM_LVL_GUI);
  73. void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = NULL);
  74. void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = NULL, ZoomLevel zoom = ZOOM_LVL_GUI);
  75. /** How to align the to-be drawn text. */
  76. enum StringAlignment {
  77. SA_LEFT = 0 << 0, ///< Left align the text.
  78. SA_HOR_CENTER = 1 << 0, ///< Horizontally center the text.
  79. SA_RIGHT = 2 << 0, ///< Right align the text (must be a single bit).
  80. SA_HOR_MASK = 3 << 0, ///< Mask for horizontal alignment.
  81. SA_TOP = 0 << 2, ///< Top align the text.
  82. SA_VERT_CENTER = 1 << 2, ///< Vertically center the text.
  83. SA_BOTTOM = 2 << 2, ///< Bottom align the text.
  84. SA_VERT_MASK = 3 << 2, ///< Mask for vertical alignment.
  85. SA_CENTER = SA_HOR_CENTER | SA_VERT_CENTER, ///< Center both horizontally and vertically.
  86. SA_FORCE = 1 << 4, ///< Force the alignment, i.e. don't swap for RTL languages.
  87. SA_STRIP = 1 << 5, ///< Strip the SETX/SETXY commands from the string
  88. };
  89. DECLARE_ENUM_AS_BIT_SET(StringAlignment)
  90. int DrawString(int left, int right, int top, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL);
  91. int DrawString(int left, int right, int top, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL);
  92. int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL);
  93. int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL);
  94. void DrawCharCentered(uint32 c, int x, int y, TextColour colour);
  95. void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode = FILLRECT_OPAQUE);
  96. void GfxDrawLine(int left, int top, int right, int bottom, int colour, int width = 1);
  97. void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3);
  98. Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize = FS_NORMAL);
  99. Dimension GetStringBoundingBox(StringID strid);
  100. uint32 FormatStringLinebreaks(char *str, const char *last, int maxw, FontSize start_fontsize = FS_NORMAL);
  101. int GetStringHeight(StringID str, int maxw);
  102. Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion);
  103. Dimension GetStringMultiLineBoundingBox(const char *str, const Dimension &suggestion);
  104. void LoadStringWidthTable(bool monospace = false);
  105. void DrawDirtyBlocks();
  106. void SetDirtyBlocks(int left, int top, int right, int bottom);
  107. void MarkWholeScreenDirty();
  108. void GfxInitPalettes();
  109. bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height);
  110. /* window.cpp */
  111. void DrawOverlappedWindowForAll(int left, int top, int right, int bottom);
  112. void SetMouseCursor(CursorID cursor, PaletteID pal);
  113. void SetAnimatedMouseCursor(const AnimCursor *table);
  114. void CursorTick();
  115. void UpdateCursorSize();
  116. bool ChangeResInGame(int w, int h);
  117. void SortResolutions(int count);
  118. bool ToggleFullScreen(bool fs);
  119. /* gfx.cpp */
  120. byte GetCharacterWidth(FontSize size, uint32 key);
  121. byte GetDigitWidth(FontSize size = FS_NORMAL);
  122. /**
  123. * Get height of a character for a given font size.
  124. * @param size Font size to get height of
  125. * @return Height of characters in the given font (pixels)
  126. */
  127. static inline byte GetCharacterHeight(FontSize size)
  128. {
  129. assert(size < FS_END);
  130. extern int _font_height[FS_END];
  131. return _font_height[size];
  132. }
  133. /** Height of characters in the small (#FS_SMALL) font. */
  134. #define FONT_HEIGHT_SMALL (GetCharacterHeight(FS_SMALL))
  135. /** Height of characters in the normal (#FS_NORMAL) font. */
  136. #define FONT_HEIGHT_NORMAL (GetCharacterHeight(FS_NORMAL))
  137. /** Height of characters in the large (#FS_LARGE) font. */
  138. #define FONT_HEIGHT_LARGE (GetCharacterHeight(FS_LARGE))
  139. /** Height of characters in the large (#FS_MONO) font. */
  140. #define FONT_HEIGHT_MONO (GetCharacterHeight(FS_MONO))
  141. extern DrawPixelInfo *_cur_dpi;
  142. TextColour GetContrastColour(uint8 background);
  143. /**
  144. * All 16 colour gradients
  145. * 8 colours per gradient from darkest (0) to lightest (7)
  146. */
  147. extern byte _colour_gradient[COLOUR_END][8];
  148. extern bool _palette_remap_grf[];
  149. /**
  150. * Return the colour for a particular greyscale level.
  151. * @param level Intensity, 0 = black, 15 = white
  152. * @return colour
  153. */
  154. #define GREY_SCALE(level) (level)
  155. static const uint8 PC_BLACK = GREY_SCALE(1); ///< Black palette colour.
  156. static const uint8 PC_DARK_GREY = GREY_SCALE(6); ///< Dark grey palette colour.
  157. static const uint8 PC_GREY = GREY_SCALE(10); ///< Grey palette colour.
  158. static const uint8 PC_WHITE = GREY_SCALE(15); ///< White palette colour.
  159. static const uint8 PC_VERY_DARK_RED = 0xB2; ///< Almost-black red palette colour.
  160. static const uint8 PC_DARK_RED = 0xB4; ///< Dark red palette colour.
  161. static const uint8 PC_RED = 0xB8; ///< Red palette colour.
  162. static const uint8 PC_VERY_DARK_BROWN = 0x56; ///< Almost-black brown palette colour.
  163. static const uint8 PC_ORANGE = 0xC2; ///< Orange palette colour.
  164. static const uint8 PC_YELLOW = 0xBF; ///< Yellow palette colour.
  165. static const uint8 PC_LIGHT_YELLOW = 0x44; ///< Light yellow palette colour.
  166. static const uint8 PC_VERY_LIGHT_YELLOW = 0x45; ///< Almost-white yellow palette colour.
  167. static const uint8 PC_GREEN = 0xD0; ///< Green palette colour.
  168. static const uint8 PC_DARK_BLUE = 0x9D; ///< Dark blue palette colour.
  169. static const uint8 PC_LIGHT_BLUE = 0x98; ///< Light blue palette colour.
  170. #endif /* GFX_FUNC_H */