OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

gfx_func.h
Go to the documentation of this file.
1 /* $Id: gfx_func.h 27829 2017-03-25 23:19:41Z peter1138 $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
42 #ifndef GFX_FUNC_H
43 #define GFX_FUNC_H
44
45 #include "gfx_type.h"
46 #include "strings_type.h"
47 #include "string_type.h"
48
49 void GameLoop();
50
51 void CreateConsole();
52
53 extern byte _dirkeys;
54 extern bool _fullscreen;
55 extern byte _support8bpp;
56 extern CursorVars _cursor;
57 extern bool _ctrl_pressed;
58 extern bool _shift_pressed;
59 extern byte _fast_forward;
60
61 extern bool _left_button_down;
62 extern bool _left_button_clicked;
63 extern bool _right_button_down;
64 extern bool _right_button_clicked;
65
66 extern DrawPixelInfo _screen;
67 extern bool _screen_disable_anim;
68
69 extern int _num_resolutions;
70 extern Dimension _resolutions[32];
71 extern Dimension _cur_resolution;
72 extern Palette _cur_palette;
73
74 void HandleKeypress(uint keycode, WChar key);
75 void HandleTextInput(const char *str, bool marked = false, const char *caret = NULL, const char *insert_location = NULL, const char *replacement_end = NULL);
76 void HandleCtrlChanged();
77 void HandleMouseEvents();
78 void CSleep(int milliseconds);
79 void UpdateWindows();
80
81 void DrawMouseCursor();
82 void ScreenSizeChanged();
83 void GameSizeChanged();
84 void UndrawMouseCursor();
85
87 static const int DRAW_STRING_BUFFER = 2048;
88
89 void RedrawScreenRect(int left, int top, int right, int bottom);
90 void GfxScroll(int left, int top, int width, int height, int xo, int yo);
91
92 Dimension GetSpriteSize(SpriteID sprid, Point *offset = NULL, ZoomLevel zoom = ZOOM_LVL_GUI);
93 void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = NULL);
94 void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = NULL, ZoomLevel zoom = ZOOM_LVL_GUI);
95
97 enum StringAlignment {
98 SA_LEFT = 0 << 0,
99 SA_HOR_CENTER = 1 << 0,
100 SA_RIGHT = 2 << 0,
101 SA_HOR_MASK = 3 << 0,
102
103 SA_TOP = 0 << 2,
104 SA_VERT_CENTER = 1 << 2,
105 SA_BOTTOM = 2 << 2,
106 SA_VERT_MASK = 3 << 2,
107
108 SA_CENTER = SA_HOR_CENTER | SA_VERT_CENTER,
109
110 SA_FORCE = 1 << 4,
111 };
112 DECLARE_ENUM_AS_BIT_SET(StringAlignment)
113
114 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);
115 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);
116 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);
117 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);
118
119 void DrawCharCentered(uint32 c, int x, int y, TextColour colour);
120
121 void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode = FILLRECT_OPAQUE);
122 void GfxDrawLine(int left, int top, int right, int bottom, int colour, int width = 1, int dash = 0);
123 void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3);
124
125 Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize = FS_NORMAL);
126 Dimension GetStringBoundingBox(StringID strid);
127 int GetStringHeight(const char *str, int maxw, FontSize fontsize = FS_NORMAL);
128 int GetStringHeight(StringID str, int maxw);
129 int GetStringLineCount(StringID str, int maxw);
130 Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion);
131 Dimension GetStringMultiLineBoundingBox(const char *str, const Dimension &suggestion);
132 void LoadStringWidthTable(bool monospace = false);
133 Point GetCharPosInString(const char *str, const char *ch, FontSize start_fontsize = FS_NORMAL);
134 const char *GetCharAtPosition(const char *str, int x, FontSize start_fontsize = FS_NORMAL);
135
136 void DrawDirtyBlocks();
137 void SetDirtyBlocks(int left, int top, int right, int bottom);
138 void MarkWholeScreenDirty();
139
140 void GfxInitPalettes();
141 void CheckBlitter();
142
143 bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height);
144
152 static inline int CenterBounds(int min, int max, int size)
153 {
154 return min + (max - min - size + 1) / 2;
155 }
156
157 /* window.cpp */
158 void DrawOverlappedWindowForAll(int left, int top, int right, int bottom);
159
160 void SetMouseCursorBusy(bool busy);
161 void SetMouseCursor(CursorID cursor, PaletteID pal);
162 void SetAnimatedMouseCursor(const AnimCursor *table);
163 void CursorTick();
164 void UpdateCursorSize();
165 bool ChangeResInGame(int w, int h);
166 void SortResolutions(int count);
167 bool ToggleFullScreen(bool fs);
168
169 /* gfx.cpp */
170 byte GetCharacterWidth(FontSize size, uint32 key);
171 byte GetDigitWidth(FontSize size = FS_NORMAL);
172 void GetBroadestDigit(uint *front, uint *next, FontSize size = FS_NORMAL);
173
174 int GetCharacterHeight(FontSize size);
175
177 #define FONT_HEIGHT_SMALL (GetCharacterHeight(FS_SMALL))
178
180 #define FONT_HEIGHT_NORMAL (GetCharacterHeight(FS_NORMAL))
181
183 #define FONT_HEIGHT_LARGE (GetCharacterHeight(FS_LARGE))
184
186 #define FONT_HEIGHT_MONO (GetCharacterHeight(FS_MONO))
187
188 extern DrawPixelInfo *_cur_dpi;
189
190 TextColour GetContrastColour(uint8 background);
191
196 extern byte _colour_gradient[COLOUR_END][8];
197
198 extern bool _palette_remap_grf[];
199
205 #define GREY_SCALE(level) (level)
206
207 static const uint8 PC_BLACK = GREY_SCALE(1);
208 static const uint8 PC_DARK_GREY = GREY_SCALE(6);
209 static const uint8 PC_GREY = GREY_SCALE(10);
210 static const uint8 PC_WHITE = GREY_SCALE(15);
211
212 static const uint8 PC_VERY_DARK_RED = 0xB2;
213 static const uint8 PC_DARK_RED = 0xB4;
214 static const uint8 PC_RED = 0xB8;
215
216 static const uint8 PC_VERY_DARK_BROWN = 0x56;
217
218 static const uint8 PC_ORANGE = 0xC2;
219
220 static const uint8 PC_YELLOW = 0xBF;
221 static const uint8 PC_LIGHT_YELLOW = 0x44;
222 static const uint8 PC_VERY_LIGHT_YELLOW = 0x45;
223
224 static const uint8 PC_GREEN = 0xD0;
225
226 static const uint8 PC_DARK_BLUE = 0x9D;
227 static const uint8 PC_LIGHT_BLUE = 0x98;
228
229 #endif /* GFX_FUNC_H */