1 /*
2  *
3  *  Iter Vehemens ad Necem (IVAN)
4  *  Copyright (C) Timo Kiviluoto
5  *  Released under the GNU General
6  *  Public License
7  *
8  *  See LICENSING which should be included
9  *  along with this file for more details
10  *
11  */
12 
13 #ifndef __GRAPHICS_H__
14 #define __GRAPHICS_H__
15 
16 #include <vector>
17 
18 #ifdef USE_SDL
19 #include "SDL.h"
20 #endif
21 
22 #include "v2.h"
23 
24 #define DOUBLE_BUFFER graphics::GetDoubleBuffer()
25 #define RES graphics::GetRes()
26 #define FONT graphics::GetDefaultFont()
27 
28 class bitmap;
29 class rawbitmap;
30 class festring;
31 
32 typedef void (*drawabove)(bitmap*);
33 
34 class graphics
35 {
36  public:
37   friend class bitmap;
38   static void Init();
39   static void DeInit();
40   static void SetAllowMouseInFullScreen(bool b);
GetScale()41   static int GetScale(){return Scale;}
42 
43 #ifdef USE_SDL
44   static void SetScale(int);
45   static void SwitchMode();
46   static void SetMode(cchar*, cchar*, v2, int, int, truth);
47 #endif
48 
49 #ifdef __DJGPP__
SwitchMode()50   static void SwitchMode() { }
51   static void SetMode(cchar*, cchar*, v2, truth);
52 #endif
53 
54   static void Stretch(bool, bitmap*, blitdata&, bool);
55   static void DrawRectangleOutlineAround(bitmap* bmpAt, v2 v2TopLeft, v2 v2Border, col16 color, bool wide);
56   static void BlitDBToScreen();
57 
58   static void DrawAboveAll(bitmap* bmpBuffer);
59   static void AddDrawAboveAll(drawabove da, int iPriority, const char* desc);
60 
GetRes()61   static v2 GetRes() { return Res; }
GetDoubleBuffer()62   static bitmap* GetDoubleBuffer() { return DoubleBuffer; }
63   static void LoadDefaultFont(cfestring&);
GetDefaultFont()64   static rawbitmap* GetDefaultFont() { return DefaultFont; }
SetSwitchModeHandler(void (* What)())65   static void SetSwitchModeHandler(void (*What)()){ SwitchModeHandler = What; }
66 
67   static int AddStretchRegion(blitdata B,const char* strId);
68   static int GetTotSRegions();
SetSpecialListItemAltPos(bool b)69   static void SetSpecialListItemAltPos(bool b){bSpecialListItemAltPos=b;}
SetAllowStretchedBlit()70   static void SetAllowStretchedBlit(){bAllowStretchedRegionsBlit=true;} //as the dungeon shows most of the time,
SetDenyStretchedBlit()71   static void SetDenyStretchedBlit(){bAllowStretchedRegionsBlit=false;} //it should be denied only during a few moments.
72   static bool isStretchedRegionsAllowed();
73   static void PrepareBeforeDrawingFelist();
74   static void DrawAtDoubleBufferBeforeFelistPage();
75   static bitmap* PrepareBuffer();
76 
77   //TODO utility class for sregion?
78   static bool IsSRegionEnabled(int iIndex);
79   static void SetSRegionEnabled(int iIndex, bool b);
80   static void SetSRegionUseXBRZ(int iIndex, bool b);
81   static void SetSRegionDrawAfterFelist(int iIndex, bool b);
82   static void SetSRegionDrawAlways(int iIndex, bool b);
83   static void SetSRegionDrawBeforeFelistPage(int iIndex, bool, bool);
84   static void SetSRegionDrawRectangleOutline(int iIndex, bool b);
85   static void SetSRegionSrcBitmapOverride(int iIndex, bitmap* bmp, int iStretch, v2 v2Dest);
86   static void SetSRegionListItem(int iIndex);
87   static int  SetSRegionBlitdata(int iIndex, blitdata B);
88   static void SetSRegionClearSquaresAt(int iIndex, v2 v2Size, std::vector<v2> vv2);
89 
90 #ifdef USE_SDL
91   #if SDL_MAJOR_VERSION == 1
92     static SDL_Surface* Screen;
93     #if SDL_BYTEORDER == SDL_BIG_ENDIAN
94       static SDL_Surface* TempSurface;
95     #endif
96   #else
97     public:
GetWindow()98       static SDL_Window* GetWindow(){return Window;};
99     private:
100       static SDL_Window* Window;
101       static SDL_Renderer *Renderer;
102       static SDL_Texture *Texture;
103   #endif
104 #endif
105 
106  private:
107   static void (*SwitchModeHandler)();
108 #ifdef __DJGPP__
109   static ulong BufferSize;
110   static ushort ScreenSelector;
111   static struct vesainfo
112   {
113     void Retrieve();
114     ulong Signature NO_ALIGNMENT;
115     ushort Version NO_ALIGNMENT;
116     ulong OEMString NO_ALIGNMENT;
117     ulong Capabilities NO_ALIGNMENT;
118     ulong ModeList NO_ALIGNMENT;
119     ushort Memory NO_ALIGNMENT;
120     uchar Shit[493] NO_ALIGNMENT;
121   } VesaInfo;
122   static struct modeinfo
123   {
124     void Retrieve(ushort);
125     ushort Attribs1 NO_ALIGNMENT;
126     uchar AWindowAttribs NO_ALIGNMENT;
127     uchar BWindowAttribs NO_ALIGNMENT;
128     ushort Granularity NO_ALIGNMENT;
129     ushort WindowSize NO_ALIGNMENT;
130     ushort WindowASegment NO_ALIGNMENT;
131     ushort WindowBSegment NO_ALIGNMENT;
132     ulong WindowMoveFunction NO_ALIGNMENT;
133     ushort BytesPerLine NO_ALIGNMENT;
134     ushort Width NO_ALIGNMENT;
135     ushort Height NO_ALIGNMENT;
136     uchar CharWidth NO_ALIGNMENT;
137     uchar CharHeight NO_ALIGNMENT;
138     uchar Planes NO_ALIGNMENT;
139     uchar BitsPerPixel NO_ALIGNMENT;
140     uchar Banks NO_ALIGNMENT;
141     uchar MemoryModel NO_ALIGNMENT;
142     uchar BankSize NO_ALIGNMENT;
143     uchar ImagePages NO_ALIGNMENT;
144     uchar Reserved1 NO_ALIGNMENT;
145     uchar RedBits NO_ALIGNMENT;
146     uchar RedShift NO_ALIGNMENT;
147     uchar GreenBits NO_ALIGNMENT;
148     uchar GreenShift NO_ALIGNMENT;
149     uchar BlueBits NO_ALIGNMENT;
150     uchar BlueShift NO_ALIGNMENT;
151     uchar ResBits NO_ALIGNMENT;
152     uchar ResShift NO_ALIGNMENT;
153     uchar Attribs2 NO_ALIGNMENT;
154     ulong PhysicalLFBAddress NO_ALIGNMENT;
155     ulong OffScreenMem NO_ALIGNMENT;
156     ushort OffScreenMemSize NO_ALIGNMENT;
157     uchar Reserved2[206] NO_ALIGNMENT;
158   } ModeInfo;
159 #endif
160   static bitmap* DoubleBuffer;
161   static bitmap* StretchedBuffer;
162   static truth bAllowStretchedRegionsBlit;
163   static truth bSpecialListItemAltPos;
164   static v2 Res;
165   static int Scale;
166   static int ColorDepth;
167   static rawbitmap* DefaultFont;
168 };
169 
170 #endif
171