melee / ranged effects
[gemrb.git] / gemrb / core / Video.h
blob3e070bd3f754980bb278ba51610a5d7e34555189
1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
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.
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.
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.
21 /**
22 * @file Video.h
23 * Declares Video, base class for video output plugins.
24 * @author The GemRB Project
27 #ifndef VIDEO_H
28 #define VIDEO_H
30 #include "globals.h"
32 #include "Animation.h"
33 #include "Plugin.h"
34 #include "Polygon.h"
35 #include "ScriptedAnimation.h"
36 #include "GUI/EventMgr.h"
38 class AnimationFactory;
39 class Palette;
40 class SpriteCover;
42 // Note: not all these flags make sense together. Specifically:
43 // NOSHADOW overrides TRANSSHADOW
44 enum SpriteBlitFlags {
45 BLIT_HALFTRANS = IE_VVC_TRANSPARENT, // 2
46 BLIT_BLENDED = IE_VVC_BLENDED, // 8; not implemented in SDLVideo yet
47 BLIT_MIRRORX = IE_VVC_MIRRORX, // 0x10
48 BLIT_MIRRORY = IE_VVC_MIRRORY, // 0x20
49 BLIT_NOSHADOW = 0x1000,
50 BLIT_TRANSSHADOW = 0x2000,
51 BLIT_TINTED = 0x00010000, // IE_VVC_TINT = 0x00030000
52 BLIT_GREY = IE_VVC_GREYSCALE, // 0x80000
53 BLIT_RED = IE_VVC_RED_TINT, // 0x02000000
54 BLIT_DARK = IE_VVC_DARKEN, // 0x00100000; not implemented in SDLVideo yet
55 BLIT_GLOW = IE_VVC_GLOWING // 0x00200000; not implemented in SDLVideo yet
56 // Note: bits 29,30,31 are used by SDLVideo internally
59 //disable mouse flags
60 #define MOUSE_DISABLED 1
61 #define MOUSE_GRAYED 2
63 // !!! Keep this synchronized with GUIDefines.py !!!
64 // used for calculating the tooltip delay limit and the real tooltip delay
65 #define TOOLTIP_DELAY_FACTOR 250
67 /**
68 * @class Video
69 * Base class for video output plugins.
72 class GEM_EXPORT Video : public Plugin {
73 public:
74 static const TypeID ID;
75 public:
76 Video(void);
77 virtual ~Video(void);
78 virtual int Init(void) = 0;
79 virtual int CreateDisplay(int width, int height, int bpp, bool fullscreen) = 0;
80 /** Sets window title of GemRB window */
81 virtual void SetDisplayTitle(char* title, char* icon) = 0;
82 virtual VideoModes GetVideoModes(bool fullscreen = false) = 0;
83 virtual bool TestVideoMode(VideoMode& vm) = 0;
84 /** Toggles GemRB between fullscreen and windowed mode.
85 * 0 = windowed, 1 = fullscreen, -1 (default) = toggle */
86 virtual bool ToggleFullscreenMode(int set_reset=-1) = 0;
87 /** Swaps displayed and back buffers */
88 virtual int SwapBuffers(void) = 0;
89 /** Grabs and releases mouse cursor within GemRB window */
90 virtual bool ToggleGrabInput() = 0;
91 virtual short GetWidth() = 0;
92 virtual short GetHeight() = 0;
94 virtual void InitSpriteCover(SpriteCover* sc, int flags) = 0;
95 virtual void AddPolygonToSpriteCover(SpriteCover* sc, Wall_Polygon* poly) = 0;
96 virtual void DestroySpriteCover(SpriteCover* sc) = 0;
98 virtual Sprite2D* CreateSprite(int w, int h, int bpp, ieDword rMask,
99 ieDword gMask, ieDword bMask, ieDword aMask, void* pixels,
100 bool cK = false, int index = 0) = 0;
101 virtual Sprite2D* CreateSprite8(int w, int h, int bpp, void* pixels,
102 void* palette, bool cK = false, int index = 0) = 0;
103 virtual Sprite2D* CreateSpriteBAM8(int /*w*/, int /*h*/, bool /* RLE */,
104 const unsigned char* /*pixeldata*/,
105 AnimationFactory* /*datasrc*/,
106 Palette* /*palette*/,
107 int /*transindex*/) { return 0; }
108 virtual bool SupportsBAMSprites() { return false; }
109 virtual void FreeSprite(Sprite2D* &spr) = 0;
110 virtual Sprite2D* DuplicateSprite(const Sprite2D* spr) = 0;
111 virtual void BlitTile(const Sprite2D* spr, const Sprite2D* mask, int x, int y, const Region* clip, bool trans) = 0;
112 virtual void BlitSprite(const Sprite2D* spr, int x, int y, bool anchor = false,
113 const Region* clip = NULL) = 0;
115 // Note: BlitSpriteRegion's clip region is shifted by Viewport.x/y if
116 // anchor is false. This is different from the other BlitSprite functions.
117 virtual void BlitSpriteRegion(const Sprite2D* spr, const Region& size, int x, int y,
118 bool anchor = true, const Region* clip = NULL) = 0;
119 // Note: Tint cannot be constified, because it is modified locally
120 // not a pretty interface :)
121 virtual void BlitGameSprite(const Sprite2D* spr, int x, int y,
122 unsigned int flags, Color tint,
123 SpriteCover* cover, Palette *palette = NULL,
124 const Region* clip = NULL, bool anchor = false) = 0;
125 virtual void SetCursor(Sprite2D* up, Sprite2D* down) = 0;
126 /** Sets a temporary cursor when dragging an Item from Inventory.
127 * VideoDriver will call FreeSprite on it.
129 virtual void SetDragCursor(Sprite2D* drag) = 0;
130 /** Return GemRB window screenshot.
131 * It's generated from the momentary back buffer */
132 virtual Sprite2D* GetScreenshot( Region r ) = 0;
133 virtual void ConvertToVideoFormat(Sprite2D* sprite) = 0;
134 /** Sets the palette of a plugin specific sprite */
135 virtual void SetPalette(void* data, Palette* pal) = 0;
136 /** This function Draws the Border of a Rectangle as described by the Region parameter. The Color used to draw the rectangle is passes via the Color parameter. */
137 virtual void DrawRect(const Region& rgn, const Color& color, bool fill = true, bool clipped = false) = 0;
138 /** this function draws a clipped sprite */
139 virtual void DrawRectSprite(const Region& rgn, const Color& color, const Sprite2D* sprite) = 0;
140 virtual void SetPixel(short x, short y, const Color& color, bool clipped = false) = 0;
141 virtual void GetPixel(short x, short y, Color& color) = 0;
142 virtual long GetPixel(void *, unsigned short x, unsigned short y) = 0;
143 virtual void GetPixel(void *, unsigned short x, unsigned short y, Color &color) = 0;
144 /** Draws a circle */
145 virtual void DrawCircle(short cx, short cy, unsigned short r, const Color& color, bool clipped = true) = 0;
146 /** Draws an Ellipse Segment */
147 virtual void DrawEllipseSegment(short cx, short cy, unsigned short xr, unsigned short yr, const Color& color,
148 double anglefrom, double angleto, bool drawlines = true, bool clipped = true) = 0;
149 /** Draws an ellipse */
150 virtual void DrawEllipse(short cx, short cy, unsigned short xr,
151 unsigned short yr, const Color& color, bool clipped = true) = 0;
152 /** Draws a polygon on the screen */
153 virtual void DrawPolyline(Gem_Polygon* poly, const Color& color,
154 bool fill = false) = 0;
155 /** Draws a line segment */
156 virtual void DrawLine(short x1, short y1, short x2, short y2,
157 const Color& color, bool clipped = false) = 0;
158 /** Blits a Sprite filling the Region */
159 void BlitTiled(Region rgn, const Sprite2D* img, bool anchor = false);
160 /** Sets Event Manager */
161 void SetEventMgr(EventMgr* evnt);
162 /** Sends a Quit Signal to the Event Queue */
163 virtual bool Quit(void) = 0;
164 /** Gets the Palette of a surface */
165 virtual Palette* GetPalette(void* surface) = 0;
166 /** Flips sprite vertically, returns new sprite */
167 virtual Sprite2D *MirrorSpriteVertical(const Sprite2D *sprite, bool MirrorAnchor) = 0;
168 /** Flips sprite horizontally, returns new sprite */
169 virtual Sprite2D *MirrorSpriteHorizontal(const Sprite2D *sprite, bool MirrorAnchor) = 0;
170 /** Duplicates and transforms sprite to have an alpha channel */
171 Sprite2D* CreateAlpha(const Sprite2D *sprite);
173 /** Converts a Screen Coordinate to a Game Coordinate */
174 virtual void ConvertToGame(short& x, short& y) = 0;
175 /** Converts a Game Coordinate to a Screen Coordinate */
176 virtual void ConvertToScreen(short& x, short& y) = 0;
177 /** Sets the Fading Color */
178 virtual void SetFadeColor(int r, int g, int b) = 0;
179 /** Sets the Fading to Color Percentage */
180 virtual void SetFadePercent(int percent) = 0;
181 /** Sets Clip Rectangle */
182 virtual void SetClipRect(const Region* clip) = 0;
183 /** Gets Clip Rectangle */
184 virtual void GetClipRect(Region& clip) = 0;
185 /** returns the current mouse coordinates */
186 virtual void GetMousePos(int &x, int &y) = 0;
187 /** clicks the mouse forcibly */
188 virtual void ClickMouse(unsigned int button) = 0;
189 /** moves the mouse forcibly */
190 virtual void MoveMouse(unsigned int x, unsigned int y) = 0;
191 /** initializes the screen for movie */
192 virtual void InitMovieScreen(int &w, int &h, bool yuv=false) = 0;
193 /** sets the font and color of the movie subtitles */
194 virtual void SetMovieFont(Font *stfont, Palette *pal) = 0;
195 /** draws a movie frame */
196 virtual void showFrame(unsigned char* buf, unsigned int bufw,
197 unsigned int bufh, unsigned int sx, unsigned int sy,
198 unsigned int w, unsigned int h, unsigned int dstx,
199 unsigned int dsty, int truecolor, unsigned char *palette,
200 ieDword titleref) = 0;
201 virtual void showYUVFrame(unsigned char** buf, unsigned int *strides,
202 unsigned int bufw, unsigned int bufh,
203 unsigned int w, unsigned int h,
204 unsigned int dstx, unsigned int dsty,
205 ieDword titleref) = 0;
206 virtual void DrawMovieSubtitle(ieStrRef text) = 0;
207 /** handles events during movie */
208 virtual int PollMovieEvents() = 0;
209 virtual void SetGamma(int brightness, int contrast) = 0;
210 public:
211 /** Event Manager Pointer */
213 void SetMouseEnabled(int enabled);
214 void SetMouseGrayed(bool grayed);
215 bool GetFullscreenMode() const;
217 /** Scales down a sprite by a ratio */
218 Sprite2D* SpriteScaleDown( const Sprite2D* sprite, unsigned int ratio );
219 /** Creates an ellipse or circle shaped sprite with various intensity
220 * for projectile light spots */
221 Sprite2D* CreateLight(int radius, int intensity);
223 Color SpriteGetPixelSum (const Sprite2D* sprite, unsigned short xbase, unsigned short ybase, unsigned int ratio);
224 Region GetViewport(void) const;
225 void SetViewport(int x, int y, unsigned int w, unsigned int h);
226 void MoveViewportTo(int x, int y);
227 protected:
228 int DisableMouse;
229 short xCorr, yCorr;
230 EventMgr* Evnt;
231 Region Viewport;
232 int width,height,bpp;
233 bool fullscreen;
235 unsigned char Gamma10toGamma22[256];
236 unsigned char Gamma22toGamma10[256];
239 #endif