PageRenderTime 61ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/1.0.0/src/gfx_func.h

https://github.com/bodhi/OpenTTD
C Header | 199 lines | 93 code | 39 blank | 67 comment | 0 complexity | 6d9663c53bc3b89ac6e3210e31045ae3 MD5 | raw file
  1. /* $Id: gfx_func.h 18872 2010-01-21 01:38:13Z rubidium $ */
  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 normaly uninteressted 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 uninteressted, 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 _pal_first_dirty;
  56. extern int _pal_count_dirty;
  57. extern int _num_resolutions;
  58. extern Dimension _resolutions[32];
  59. extern Dimension _cur_resolution;
  60. extern Colour _cur_palette[256]; ///< Current palette. Entry 0 has to be always fully transparent!
  61. void HandleKeypress(uint32 key);
  62. void HandleCtrlChanged();
  63. void HandleMouseEvents();
  64. void CSleep(int milliseconds);
  65. void UpdateWindows();
  66. void DrawMouseCursor();
  67. void ScreenSizeChanged();
  68. void GameSizeChanged();
  69. void UndrawMouseCursor();
  70. enum {
  71. /* Size of the buffer used for drawing strings. */
  72. DRAW_STRING_BUFFER = 2048,
  73. };
  74. void RedrawScreenRect(int left, int top, int right, int bottom);
  75. void GfxScroll(int left, int top, int width, int height, int xo, int yo);
  76. Dimension GetSpriteSize(SpriteID sprid);
  77. void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = NULL);
  78. /** How to align the to-be drawn text. */
  79. enum StringAlignment {
  80. SA_LEFT, ///< Left align the text
  81. SA_CENTER, ///< Center the text
  82. SA_RIGHT, ///< Right align the text
  83. SA_MASK = 3, ///< Mask for base alignment
  84. SA_FORCE = 4, ///< Force the alignment, i.e. don't swap for RTL languages.
  85. SA_STRIP = 8, ///< Strip the SETX/SETXY commands from the string
  86. };
  87. DECLARE_ENUM_AS_BIT_SET(StringAlignment);
  88. int DrawString(int left, int right, int top, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false);
  89. int DrawString(int left, int right, int top, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false);
  90. int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false);
  91. void DrawCharCentered(uint32 c, int x, int y, TextColour colour);
  92. void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode = FILLRECT_OPAQUE);
  93. void GfxDrawLine(int left, int top, int right, int bottom, int colour);
  94. void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3);
  95. Dimension GetStringBoundingBox(const char *str);
  96. Dimension GetStringBoundingBox(StringID strid);
  97. uint32 FormatStringLinebreaks(char *str, const char *last, int maxw);
  98. int GetStringHeight(StringID str, int maxw);
  99. Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion);
  100. void LoadStringWidthTable();
  101. /**
  102. * Let the dirty blocks repainting by the video driver.
  103. *
  104. * @ingroup dirty
  105. */
  106. void DrawDirtyBlocks();
  107. /**
  108. * Set a new dirty block.
  109. *
  110. * @ingroup dirty
  111. */
  112. void SetDirtyBlocks(int left, int top, int right, int bottom);
  113. /**
  114. * Marks the whole screen as dirty.
  115. *
  116. * @ingroup dirty
  117. */
  118. void MarkWholeScreenDirty();
  119. void GfxInitPalettes();
  120. bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height);
  121. /* window.cpp */
  122. void DrawOverlappedWindowForAll(int left, int top, int right, int bottom);
  123. void SetMouseCursor(CursorID cursor, PaletteID pal);
  124. void SetAnimatedMouseCursor(const AnimCursor *table);
  125. void CursorTick();
  126. bool ChangeResInGame(int w, int h);
  127. void SortResolutions(int count);
  128. bool ToggleFullScreen(bool fs);
  129. /* gfx.cpp */
  130. extern FontSize _cur_fontsize; ///< Currently selected font.
  131. byte GetCharacterWidth(FontSize size, uint32 key);
  132. byte GetDigitWidth(FontSize size = FS_NORMAL);
  133. /**
  134. * Get height of a character for a given font size.
  135. * @param size Font size to get height of
  136. * @return Height of characters in the given font (pixels)
  137. */
  138. static inline byte GetCharacterHeight(FontSize size)
  139. {
  140. assert(size < FS_END);
  141. extern int _font_height[FS_END];
  142. return _font_height[size];
  143. }
  144. /** Height of characters in the small (#FS_SMALL) font. */
  145. #define FONT_HEIGHT_SMALL (GetCharacterHeight(FS_SMALL))
  146. /** Height of characters in the normal (#FS_NORMAL) font. */
  147. #define FONT_HEIGHT_NORMAL (GetCharacterHeight(FS_NORMAL))
  148. /** Height of characters in the large (#FS_LARGE) font. */
  149. #define FONT_HEIGHT_LARGE (GetCharacterHeight(FS_LARGE))
  150. extern DrawPixelInfo *_cur_dpi;
  151. /**
  152. * All 16 colour gradients
  153. * 8 colours per gradient from darkest (0) to lightest (7)
  154. */
  155. extern byte _colour_gradient[COLOUR_END][8];
  156. extern PaletteType _use_palette;
  157. extern bool _palette_remap_grf[];
  158. extern const byte *_palette_remap;
  159. extern const byte *_palette_reverse_remap;
  160. #endif /* GFX_FUNC_H */