# gfx_func.h

Go to the documentation of this file.

    00001 /* $Id: gfx_func.h 26217 2014-01-03 08:51:49Z 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
    00042 #ifndef GFX_FUNC_H
    00043 #define GFX_FUNC_H
    00044
    00045 #include "gfx_type.h"
    00046 #include "strings_type.h"
    00047 #include "string_type.h"
    00048
    00049 void GameLoop();
    00050
    00051 void CreateConsole();
    00052
    00053 extern byte _dirkeys;
    00054 extern bool _fullscreen;
    00055 extern CursorVars _cursor;
    00056 extern bool _ctrl_pressed;
    00057 extern bool _shift_pressed;
    00058 extern byte _fast_forward;
    00059
    00060 extern bool _left_button_down;
    00061 extern bool _left_button_clicked;
    00062 extern bool _right_button_down;
    00063 extern bool _right_button_clicked;
    00064
    00065 extern DrawPixelInfo _screen;
    00066 extern bool _screen_disable_anim;
    00067
    00068 extern int _num_resolutions;
    00069 extern Dimension _resolutions[32];
    00070 extern Dimension _cur_resolution;
    00071 extern Palette _cur_palette;
    00072
    00073 void HandleKeypress(uint keycode, WChar key);
    00074 void HandleTextInput(const char *str, bool marked = false, const char *caret = NULL, const char *insert_location = NULL, const char *replacement_end = NULL);
    00075 void HandleCtrlChanged();
    00076 void HandleMouseEvents();
    00077 void CSleep(int milliseconds);
    00078 void UpdateWindows();
    00079
    00080 void DrawMouseCursor();
    00081 void ScreenSizeChanged();
    00082 void GameSizeChanged();
    00083 void UndrawMouseCursor();
    00084
    00086 static const int DRAW_STRING_BUFFER = 2048;
    00087
    00088 void RedrawScreenRect(int left, int top, int right, int bottom);
    00089 void GfxScroll(int left, int top, int width, int height, int xo, int yo);
    00090
    00091 Dimension GetSpriteSize(SpriteID sprid, Point *offset = NULL, ZoomLevel zoom = ZOOM_LVL_GUI);
    00092 void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = NULL);
    00093 void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = NULL, ZoomLevel zoom = ZOOM_LVL_GUI);
    00094
    00096 enum StringAlignment {
    00097   SA_LEFT        = 0 << 0,
    00098   SA_HOR_CENTER  = 1 << 0,
    00099   SA_RIGHT       = 2 << 0,
    00100   SA_HOR_MASK    = 3 << 0,
    00101
    00102   SA_TOP         = 0 << 2,
    00103   SA_VERT_CENTER = 1 << 2,
    00104   SA_BOTTOM      = 2 << 2,
    00105   SA_VERT_MASK   = 3 << 2,
    00106
    00107   SA_CENTER      = SA_HOR_CENTER | SA_VERT_CENTER,
    00108
    00109   SA_FORCE       = 1 << 4,
    00110 };
    00111 DECLARE_ENUM_AS_BIT_SET(StringAlignment)
    00112
    00113 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);
    00114 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);
    00115 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);
    00116 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);
    00117
    00118 void DrawCharCentered(uint32 c, int x, int y, TextColour colour);
    00119
    00120 void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode = FILLRECT_OPAQUE);
    00121 void GfxDrawLine(int left, int top, int right, int bottom, int colour, int width = 1, int dash = 0);
    00122 void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3);
    00123
    00124 Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize = FS_NORMAL);
    00125 Dimension GetStringBoundingBox(StringID strid);
    00126 int GetStringHeight(const char *str, int maxw, FontSize fontsize = FS_NORMAL);
    00127 int GetStringHeight(StringID str, int maxw);
    00128 int GetStringLineCount(StringID str, int maxw);
    00129 Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion);
    00130 Dimension GetStringMultiLineBoundingBox(const char *str, const Dimension &suggestion);
    00131 void LoadStringWidthTable(bool monospace = false);
    00132 Point GetCharPosInString(const char *str, const char *ch, FontSize start_fontsize = FS_NORMAL);
    00133 const char *GetCharAtPosition(const char *str, int x, FontSize start_fontsize = FS_NORMAL);
    00134
    00135 void DrawDirtyBlocks();
    00136 void SetDirtyBlocks(int left, int top, int right, int bottom);
    00137 void MarkWholeScreenDirty();
    00138
    00139 void GfxInitPalettes();
    00140 void CheckBlitter();
    00141
    00142 bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height);
    00143
    00144 /* window.cpp */
    00145 void DrawOverlappedWindowForAll(int left, int top, int right, int bottom);
    00146
    00147 void SetMouseCursor(CursorID cursor, PaletteID pal);
    00148 void SetAnimatedMouseCursor(const AnimCursor *table);
    00149 void CursorTick();
    00150 void UpdateCursorSize();
    00151 bool ChangeResInGame(int w, int h);
    00152 void SortResolutions(int count);
    00153 bool ToggleFullScreen(bool fs);
    00154
    00155 /* gfx.cpp */
    00156 byte GetCharacterWidth(FontSize size, uint32 key);
    00157 byte GetDigitWidth(FontSize size = FS_NORMAL);
    00158 void GetBroadestDigit(uint *front, uint *next, FontSize size = FS_NORMAL);
    00159
    00160 int GetCharacterHeight(FontSize size);
    00161
    00163 #define FONT_HEIGHT_SMALL  (GetCharacterHeight(FS_SMALL))
    00164
    00166 #define FONT_HEIGHT_NORMAL (GetCharacterHeight(FS_NORMAL))
    00167
    00169 #define FONT_HEIGHT_LARGE  (GetCharacterHeight(FS_LARGE))
    00170
    00172 #define FONT_HEIGHT_MONO  (GetCharacterHeight(FS_MONO))
    00173
    00174 extern DrawPixelInfo *_cur_dpi;
    00175
    00176 TextColour GetContrastColour(uint8 background);
    00177
    00182 extern byte _colour_gradient[COLOUR_END][8];
    00183
    00184 extern bool _palette_remap_grf[];
    00185
    00191 #define GREY_SCALE(level) (level)
    00192
    00193 static const uint8 PC_BLACK              = GREY_SCALE(1);
    00194 static const uint8 PC_DARK_GREY          = GREY_SCALE(6);
    00195 static const uint8 PC_GREY               = GREY_SCALE(10);
    00196 static const uint8 PC_WHITE              = GREY_SCALE(15);
    00197
    00198 static const uint8 PC_VERY_DARK_RED      = 0xB2;
    00199 static const uint8 PC_DARK_RED           = 0xB4;
    00200 static const uint8 PC_RED                = 0xB8;
    00201
    00202 static const uint8 PC_VERY_DARK_BROWN    = 0x56;
    00203
    00204 static const uint8 PC_ORANGE             = 0xC2;
    00205
    00206 static const uint8 PC_YELLOW             = 0xBF;
    00207 static const uint8 PC_LIGHT_YELLOW       = 0x44;
    00208 static const uint8 PC_VERY_LIGHT_YELLOW  = 0x45;
    00209
    00210 static const uint8 PC_GREEN              = 0xD0;
    00211
    00212 static const uint8 PC_DARK_BLUE          = 0x9D;
    00213 static const uint8 PC_LIGHT_BLUE         = 0x98;
    00214
    00215 #endif /* GFX_FUNC_H */