# gfx_func.h

Go to the documentation of this file.

    00001 /* $Id$ */
    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
    00048 void GameLoop();
    00049
    00050 void CreateConsole();
    00051
    00052 extern byte _dirkeys;
    00053 extern bool _fullscreen;
    00054 extern CursorVars _cursor;
    00055 extern bool _ctrl_pressed;
    00056 extern bool _shift_pressed;
    00057 extern byte _fast_forward;
    00058
    00059 extern bool _left_button_down;
    00060 extern bool _left_button_clicked;
    00061 extern bool _right_button_down;
    00062 extern bool _right_button_clicked;
    00063
    00064 extern DrawPixelInfo _screen;
    00065 extern bool _screen_disable_anim;
    00066
    00067 extern int _pal_first_dirty;
    00068 extern int _pal_count_dirty;
    00069 extern int _num_resolutions;
    00070 extern Dimension _resolutions[32];
    00071 extern Dimension _cur_resolution;
    00072 extern Colour _cur_palette[256];
    00073
    00074 void HandleKeypress(uint32 key);
    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);
    00092 void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = NULL);
    00093
    00095 enum StringAlignment {
    00096   SA_LEFT        = 0 << 0,
    00097   SA_HOR_CENTER  = 1 << 0,
    00098   SA_RIGHT       = 2 << 0,
    00099   SA_HOR_MASK    = 3 << 0,
    00100
    00101   SA_TOP         = 0 << 2,
    00102   SA_VERT_CENTER = 1 << 2,
    00103   SA_BOTTOM      = 2 << 2,
    00104   SA_VERT_MASK   = 3 << 2,
    00105
    00106   SA_CENTER      = SA_HOR_CENTER | SA_VERT_CENTER,
    00107
    00108   SA_FORCE       = 1 << 4,
    00109   SA_STRIP       = 1 << 5,
    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);
    00114 int DrawString(int left, int right, int top, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false);
    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);
    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);
    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);
    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 uint32 FormatStringLinebreaks(char *str, const char *last, int maxw, FontSize start_fontsize = FS_NORMAL);
    00127 int GetStringHeight(StringID str, int maxw);
    00128 Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion);
    00129 void LoadStringWidthTable();
    00130
    00131 void DrawDirtyBlocks();
    00132 void SetDirtyBlocks(int left, int top, int right, int bottom);
    00133 void MarkWholeScreenDirty();
    00134
    00135 void GfxInitPalettes();
    00136
    00137 bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height);
    00138
    00139 /* window.cpp */
    00140 void DrawOverlappedWindowForAll(int left, int top, int right, int bottom);
    00141
    00142 void SetMouseCursor(CursorID cursor, PaletteID pal);
    00143 void SetAnimatedMouseCursor(const AnimCursor *table);
    00144 void CursorTick();
    00145 void UpdateCursorSize();
    00146 bool ChangeResInGame(int w, int h);
    00147 void SortResolutions(int count);
    00148 bool ToggleFullScreen(bool fs);
    00149
    00150 /* gfx.cpp */
    00151 byte GetCharacterWidth(FontSize size, uint32 key);
    00152 byte GetDigitWidth(FontSize size = FS_NORMAL);
    00153
    00159 static inline byte GetCharacterHeight(FontSize size)
    00160 {
    00161   assert(size < FS_END);
    00162   extern int _font_height[FS_END];
    00163   return _font_height[size];
    00164 }
    00165
    00167 #define FONT_HEIGHT_SMALL  (GetCharacterHeight(FS_SMALL))
    00168
    00170 #define FONT_HEIGHT_NORMAL (GetCharacterHeight(FS_NORMAL))
    00171
    00173 #define FONT_HEIGHT_LARGE  (GetCharacterHeight(FS_LARGE))
    00174
    00175 extern DrawPixelInfo *_cur_dpi;
    00176
    00181 extern byte _colour_gradient[COLOUR_END][8];
    00182
    00183 extern PaletteType _use_palette;
    00184 extern bool _palette_remap_grf[];
    00185 extern const byte *_palette_remap;
    00186 extern const byte *_palette_reverse_remap;
    00187
    00188 #endif /* GFX_FUNC_H */