1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 *
19 */
20
21 #ifndef SDLVIDEODRIVER_H
22 #define SDLVIDEODRIVER_H
23
24 #include "Video.h"
25
26 #include "GUI/EventMgr.h"
27
28 #include "DPadSoftKeyboard.h"
29 #include "SDLSurfaceDrawing.h"
30 #include "SDLSurfaceSprite2D.h"
31
32 #include <vector>
33
34 namespace GemRB {
35
36 #if SDL_VERSION_ATLEAST(1,3,0)
37 #define SDL_SRCCOLORKEY SDL_TRUE
38 #define SDL_SRCALPHA 0
39 #define SDLKey SDL_Keycode
40 #define SDL_JoyAxisEvent SDL_ControllerAxisEvent
41 #define SDL_JoyButtonEvent SDL_ControllerButtonEvent
42 #define SDLK_SCROLLOCK SDLK_SCROLLLOCK
43 #define SDLK_KP1 SDLK_KP_1
44 #define SDLK_KP2 SDLK_KP_2
45 #define SDLK_KP3 SDLK_KP_3
46 #define SDLK_KP4 SDLK_KP_4
47 #define SDLK_KP6 SDLK_KP_6
48 #define SDLK_KP7 SDLK_KP_7
49 #define SDLK_KP8 SDLK_KP_8
50 #define SDLK_KP9 SDLK_KP_9
51 #else
52 using SDL_Keycode = Sint32;
53 #endif
54
GetModState(int modstate)55 inline int GetModState(int modstate)
56 {
57 int value = 0;
58 if (modstate&KMOD_SHIFT) value |= GEM_MOD_SHIFT;
59 if (modstate&KMOD_CTRL) value |= GEM_MOD_CTRL;
60 if (modstate&KMOD_ALT) value |= GEM_MOD_ALT;
61 return value;
62 }
63
64 class SDLVideoDriver : public Video {
65 public:
66 SDLVideoDriver(void);
67 ~SDLVideoDriver(void) override;
68 int Init(void) override;
69
70 Holder<Sprite2D> CreateSprite(const Region& rgn, int bpp, ieDword rMask,
71 ieDword gMask, ieDword bMask, ieDword aMask, void* pixels,
72 bool cK = false, int index = 0) override;
73 Holder<Sprite2D> CreateSprite8(const Region& rgn, void* pixels,
74 PaletteHolder palette, bool cK, int index) override;
75 Holder<Sprite2D> CreatePalettedSprite(const Region& rgn, int bpp, void* pixels,
76 Color* palette, bool cK = false, int index = 0) override;
77
78 void BlitSprite(const Holder<Sprite2D> spr, const Region& src, Region dst,
79 BlitFlags flags, Color tint = Color()) override;
80 void BlitGameSprite(const Holder<Sprite2D> spr, const Point& p, BlitFlags flags, Color tint = Color()) override;
81
82 protected:
83 #if SDL_VERSION_ATLEAST(1,3,0)
84 using vid_buf_t = SDL_Texture;
85 using sprite_t = SDLTextureSprite2D;
86 #else
87 using vid_buf_t =SDL_Surface;
88 using sprite_t = SDLSurfaceSprite2D;
89 using SDL_Point = Point;
90 #endif
91 VideoBufferPtr scratchBuffer; // a buffer that the driver can do with as it pleases for intermediate work
92
93 int CreateDriverDisplay(const char* title) override;
94
95 virtual vid_buf_t* ScratchBuffer() const = 0;
96 virtual inline vid_buf_t* CurrentRenderBuffer() const=0;
97 virtual inline vid_buf_t* CurrentStencilBuffer() const=0;
98 Region CurrentRenderClip() const;
99
100 BlitFlags RenderSpriteVersion(const SDLSurfaceSprite2D* spr, BlitFlags renderflags, const Color* = NULL);
101
102 virtual void BlitSpriteBAMClipped(const Holder<Sprite2D> spr, const Region& src, const Region& dst, BlitFlags flags = BlitFlags::NONE, const Color* tint = NULL)=0;
103 virtual void BlitSpriteNativeClipped(const sprite_t* spr, const SDL_Rect& src, const SDL_Rect& dst, BlitFlags flags = BlitFlags::NONE, const SDL_Color* tint = NULL)=0;
104 void BlitSpriteClipped(const Holder<Sprite2D> spr, Region src, const Region& dst, BlitFlags flags = BlitFlags::NONE, const Color* tint = NULL);
105
106 int PollEvents() override;
107 /* used to process the SDL events dequeued by PollEvents or an arbitraty event from another source.*/
108 virtual int ProcessEvent(const SDL_Event & event);
Wait(unsigned long w)109 void Wait(unsigned long w) override { SDL_Delay(w); }
110
111 private:
112 virtual int CreateSDLDisplay(const char* title) = 0;
113 virtual void DrawSDLPoints(const std::vector<SDL_Point>& points, const SDL_Color& color, BlitFlags flags = BlitFlags::NONE)=0;
114
115 void DrawCircleImp(const Point& origin, unsigned short r, const Color& color, BlitFlags flags) override;
116 void DrawEllipseSegmentImp(const Point& origin, unsigned short xr, unsigned short yr, const Color& color,
117 double anglefrom, double angleto, bool drawlines, BlitFlags flags) override;
118 void DrawEllipseImp(const Point& origin, unsigned short xr, unsigned short yr, const Color& color, BlitFlags flags) override;
119
120 public:
121 // static functions for manipulating surfaces
122 static int SetSurfacePalette(SDL_Surface* surf, const SDL_Color* pal, int numcolors = 256);
123 };
124
125 }
126
127 #endif
128