_________ __ __
/ _____// |_____________ _/ |______ ____ __ __ ______
\_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
/ \| | | | \// __ \| | / __ \_/ /_/ > | /\___ \
/_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
\/ \/ \//_____/ \/
______________________ ______________________
T H E W A R B E G I N S
Stratagus - A free fantasy real time strategy game engine
Go to the documentation of this file.
51 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
56 #define RMASK 0x00ff0000
57 #define GMASK 0x0000ff00
58 #define BMASK 0x000000ff
59 #define AMASK 0xff000000
65 #define RMASK 0x0000ff00
66 #define GMASK 0x00ff0000
67 #define BMASK 0xff000000
68 #define AMASK 0x000000ff
71 using pixelModifier = uint32_t(*)(
const uint32_t,
const uint32_t,
const uint32_t);
79 static uint32_t
CopyWithSrcAlphaKey(
const uint32_t srcPixel,
const uint32_t dstPixel,
const uint32_t reqAlpha)
81 uint32_t srcAlpha = (srcPixel >>
ASHIFT) & 0xFF;
83 srcAlpha = (srcAlpha * reqAlpha) >> 8;
84 return (srcPixel - (srcPixel &
AMASK)) + (srcAlpha <<
ASHIFT);
112 void DrawSub(
int gx,
int gy,
int w,
int h,
int x,
int y,
117 const uint32_t param,
131 const uint32_t param,
135 void DrawFrame(
unsigned frame,
int x,
int y,
146 const uint32_t param,
160 static CGraphic *
New(
const std::string &file,
int w = 0,
int h = 0);
166 void Load(
bool grayscale =
false);
230 #ifndef HAVE_STDDEF_H
247 void Draw(
int x,
int y);
273 static Mng *
New(
const std::string &
name) {
return NULL; }
275 bool Load() {
return false; };
277 void Draw(
int x,
int y) {};
280 virtual void *
_getData()
const {
return NULL; };
281 virtual int getWidth()
const {
return 0; };
282 virtual int getHeight()
const {
return 0; };
283 virtual bool isDirty()
const {
return false; };
285 static inline uint32_t
MaxFPS = 15;
333 void DrawVLine(Uint32 color,
int x,
int y,
int height);
334 void DrawTransVLine(Uint32 color,
int x,
int y,
int height,
unsigned char alpha);
338 void DrawHLine(Uint32 color,
int x,
int y,
int width);
339 void DrawTransHLine(Uint32 color,
int x,
int y,
int width,
unsigned char alpha);
343 void DrawLine(Uint32 color,
int sx,
int sy,
int dx,
int dy);
344 void DrawTransLine(Uint32 color,
int sx,
int sy,
int dx,
int dy,
unsigned char alpha);
346 void DrawTransLineClip(Uint32 color,
int sx,
int sy,
int dx,
int dy,
unsigned char alpha);
358 void DrawCircle(Uint32 color,
int x,
int y,
int r);
359 void DrawTransCircle(Uint32 color,
int x,
int y,
int r,
unsigned char alpha);
365 void FillCircle(Uint32 color,
int x,
int y,
int radius);
366 void FillTransCircle(Uint32 color,
int x,
int y,
int radius,
unsigned char alpha);
370 inline Uint32
MapRGB(SDL_PixelFormat *f, Uint8 r, Uint8 g, Uint8 b)
372 return SDL_MapRGB(f, r, g, b);
376 return MapRGB(f, color.
R, color.
G, color.
B);
378 inline Uint32
MapRGBA(SDL_PixelFormat *f, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
380 return SDL_MapRGBA(f, r, g, b, a);
384 return MapRGBA(f, color.
R, color.
G, color.
B, color.
A);
386 inline void GetRGB(Uint32 c, SDL_PixelFormat *f, Uint8 *r, Uint8 *g, Uint8 *b)
388 SDL_GetRGB(c, f, r, g, b);
390 inline void GetRGBA(Uint32 c, SDL_PixelFormat *f, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
392 SDL_GetRGBA(c, f, r, g, b, a);
467 extern void SetClipping(
int left,
int top,
int right,
int bottom);
527 return ColorValues[index];
530 static const char *
ColorNames[] = {
"red",
"yellow",
"green",
"light-gray",
531 "gray",
"dark-gray",
"white",
"orange",
532 "light-blue",
"blue",
"dark-green",
"black", NULL};
564 SDL_Surface *dstSurface,
const SDL_Rect *dstRect,
const bool enableMT =
true);
568 #endif // !__VIDEO_H__
void RealizeVideoMemory()
Realize video memory.
Definition: sdl.cpp:832
void DrawSubCustomMod(int gx, int gy, int w, int h, int x, int y, pixelModifier modifier, const uint32_t param, SDL_Surface *surface=TheScreen) const
Definition: graphic.cpp:118
~CGraphic()
Definition: video.h:106
Uint32 ColorLightGray
Definition: video.cpp:180
void SetPaletteColor(int idx, int r, int g, int b)
Definition: graphic.cpp:1036
bool FullScreen
Definition: video.h:402
double NextFrameTicks
Next frame ticks.
Definition: video.cpp:160
void FillTransRectangle(Uint32 color, int x, int y, int w, int h, unsigned char alpha)
Definition: linedraw.cpp:1022
std::string HashFile
Filename.
Definition: video.h:185
static CGraphic * ForceNew(const std::string &file, int w=0, int h=0)
Definition: graphic.cpp:495
void DrawFrameClipTrans(unsigned frame, int x, int y, int alpha, SDL_Surface *surface=TheScreen) const
Definition: graphic.cpp:284
void SetPlayersPalette()
Definition: player.cpp:1305
int GetColorIndexByName(const char *colorName)
Definition: video.h:534
void(* NetworkEvent)()
Callback for network event.
Definition: video.h:314
virtual int getHeight() const
Definition: video.h:182
void DrawFrame(unsigned frame, int x, int y, SDL_Surface *surface=TheScreen) const
Definition: graphic.cpp:255
unsigned long FrameCounter
Counts frames.
Definition: video.cpp:161
int WindowWidth
Definition: video.h:397
int VideoValidResolution(int w, int h)
Check if a resolution is valid.
Definition: sdl.cpp:514
virtual int getWidth() const
Definition: video.h:251
bool ResizeScreen(int width, int height)
Definition: video.cpp:267
static void Free(CGraphic *g)
Definition: graphic.cpp:748
Uint32 MapRGB(SDL_PixelFormat *f, Uint8 r, Uint8 g, Uint8 b)
Definition: video.h:370
SDL_Window * TheWindow
The SDL screen.
Definition: sdl.cpp:91
Uint32 ColorLightBlue
Definition: video.cpp:176
double VerticalPixelSize
Definition: video.h:399
static CGraphic * Get(const std::string &file)
Definition: graphic.cpp:538
void FillRectangleClip(Uint32 color, int x, int y, int w, int h)
Definition: linedraw.cpp:1026
void PushClipping()
Push current clipping.
Definition: video.cpp:215
void(* ButtonReleased)(unsigned buttons)
Callback for mouse button release.
Definition: video.h:300
void InitImageLoaders()
initialize the image loaders part
Definition: video.cpp:319
static void Free(Mng *mng)
Definition: mng.cpp:240
void DrawSubClip(int gx, int gy, int w, int h, int x, int y, SDL_Surface *surface=TheScreen) const
Definition: graphic.cpp:158
void DrawEllipseClip(Uint32 color, int x, int y, int rx, int ry)
Definition: linedraw.cpp:1052
void UnlockScreen()
Definition: video.cpp:249
void Load(bool grayscale=false)
Definition: graphic.cpp:659
unsigned char G
Red.
Definition: color.h:61
void(* MouseExit)()
Callback for mouse exit of game window.
Definition: video.h:304
void DrawTransHLineClip(Uint32 color, int x, int y, int width, unsigned char alpha)
Definition: linedraw.cpp:979
virtual void * _getData() const
Definition: mng.cpp:302
void DrawCircleClip(Uint32 color, int x, int y, int r)
Definition: linedraw.cpp:1043
SDL_Surface * SurfaceFlip
Surface.
Definition: video.h:187
frame_pos_t * frameFlip_map
Definition: video.h:189
static const char * ColorNames[]
Definition: video.h:530
static CGraphic * New(const std::string &file, int w=0, int h=0)
Definition: graphic.cpp:421
int Height
Definition: video.h:396
void DrawFrameClipTransX(unsigned frame, int x, int y, int alpha, SDL_Surface *surface=TheScreen) const
Definition: graphic.cpp:371
unsigned long GetTicks()
Returns the ticks in ms since start.
Definition: video.cpp:314
void(CCONV *lazyGlBegin)(GLenum)
int Height
Width of a frame.
Definition: video.h:192
Uint32 ColorRed
Definition: video.cpp:183
CPlayerColorGraphic()
Definition: video.h:205
virtual int getWidth() const
Definition: video.h:181
int WindowHeight
Definition: video.h:398
Uint32 ColorDarkGreen
Definition: video.cpp:175
void FillCircleClip(Uint32 color, const PixelPos &screenPos, int radius)
Definition: linedraw.cpp:1065
bool Load()
Definition: mng.cpp:258
void(* MouseMoved)(const PixelPos &screenPos)
Callback for mouse move.
Definition: video.h:302
Uint32 ColorBlue
Definition: video.cpp:177
void DrawLine(Uint32 color, int sx, int sy, int dx, int dy)
Definition: linedraw.cpp:984
void InitVideo()
initialize the video part
Definition: video.cpp:333
void(* KeyPressed)(unsigned keycode, unsigned keychar)
Callback for key press.
Definition: video.h:307
Uint32 MapRGBA(SDL_PixelFormat *f, const CColor &color)
Definition: video.h:382
void DrawCircle(Uint32 color, int x, int y, int r)
Definition: linedraw.cpp:1035
bool TransparentPixel(int x, int y)
Definition: graphic.cpp:1004
SDL_Surface * Surface
Filename used in hash.
Definition: video.h:186
void DrawTransCircle(Uint32 color, int x, int y, int r, unsigned char alpha)
Definition: linedraw.cpp:1039
void ClearAllColorCyclingRange()
Definition: video.cpp:471
#define ASHIFT
Definition: video.h:55
void SaveScreenshotPNG(const char *name)
Save a screenshot to a PNG file.
Definition: png.cpp:57
void SetClipping(int left, int top, int right, int bottom)
Definition: video.cpp:200
void(* ButtonPressed)(unsigned buttons)
Callback for mouse button press.
Definition: video.h:298
SDL_Cursor * blankCursor
Definition: video.h:400
void ToggleFullScreen()
Toggle full screen mode.
Definition: sdl.cpp:938
CGraphic()
Definition: video.h:100
void SetColorCycleAll(bool value)
Definition: video.cpp:494
CPlayerColorGraphic * Clone(bool grayscale=false) const
Definition: graphic.cpp:520
static CPlayerColorGraphic * ForceNew(const std::string &file, int w=0, int h=0)
Definition: graphic.cpp:579
void DrawClip(int x, int y, SDL_Surface *surface=TheScreen) const
Definition: graphic.cpp:71
void Draw(int x, int y)
Definition: mng.cpp:215
unsigned long ticks
Definition: video.h:263
void PopClipping()
Pop current clipping.
Definition: video.cpp:224
bool IsLoaded(bool flipped=false) const
Definition: video.h:177
Uint32 ColorWhite
Definition: video.cpp:179
void DrawVLineClip(Uint32 color, int x, int y, int height)
Definition: linedraw.cpp:958
void DrawSub(int gx, int gy, int w, int h, int x, int y, SDL_Surface *surface=TheScreen) const
Definition: graphic.cpp:93
void DrawFrameTrans(unsigned frame, int x, int y, int alpha, SDL_Surface *surface=TheScreen) const
Definition: graphic.cpp:277
void FillRectangle(Uint32 color, int x, int y, int w, int h)
Definition: linedraw.cpp:1018
void FillTransCircle(Uint32 color, int x, int y, int radius, unsigned char alpha)
Definition: linedraw.cpp:1061
int iteration
Definition: video.h:264
void ToggleGrabMouse(int mode)
Toggle mouse grab mode.
Definition: sdl.cpp:924
static uint32_t CopyWithSrcAlphaKey(const uint32_t srcPixel, const uint32_t dstPixel, const uint32_t reqAlpha)
Definition: video.h:79
EventCallback EditorCallbacks
Game callbacks.
Definition: mainloop.cpp:81
void DrawHLine(Uint32 color, int x, int y, int width)
Definition: linedraw.cpp:967
void FillCircle(Uint32 color, int x, int y, int radius)
Definition: linedraw.cpp:1057
A platform independent color.
Definition: color.h:43
int NumFrames
Height of a frame.
Definition: video.h:193
int GraphicHeight
Original graphic width.
Definition: video.h:195
char VideoForceFullScreen
Fullscreen or windowed set from commandline.
Definition: video.cpp:158
void DeInitVideo()
deinitliaize the video part
Definition: video.cpp:339
void LockScreen()
Definition: video.cpp:241
void DrawFrameClip(unsigned frame, int x, int y, SDL_Surface *surface=TheScreen) const
Definition: graphic.cpp:270
EventCallback GameCallbacks
Definition: mainloop.cpp:80
unsigned char R
Definition: color.h:60
const EventCallback * GetCallbacks()
Get the current callbacks.
Definition: sdl.cpp:717
void DrawTransRectangleClip(Uint32 color, int x, int y, int w, int h, unsigned char alpha)
Definition: linedraw.cpp:1013
int Depth
Definition: video.h:401
Uint32 ColorYellow
Definition: video.cpp:185
void VideoCclRegister()
register lua function
Definition: video.cpp:356
void DrawVLine(Uint32 color, int x, int y, int height)
Definition: linedraw.cpp:950
void DrawSubTrans(int gx, int gy, int w, int h, int x, int y, unsigned char alpha, SDL_Surface *surface=TheScreen) const
Definition: graphic.cpp:186
unsigned char A
Blue.
Definition: color.h:63
void Reset()
Definition: mng.cpp:292
void GetRGB(Uint32 c, SDL_PixelFormat *f, Uint8 *r, Uint8 *g, Uint8 *b)
Definition: video.h:386
void DrawPlayerColorFrameClip(int colorIndex, unsigned frame, int x, int y, SDL_Surface *surface=TheScreen)
Definition: graphic.cpp:309
unsigned char * buffer
Definition: video.h:262
SDL_Surface * TheScreen
Internal screen.
Definition: sdl.cpp:94
void DrawLineClip(Uint32 color, const PixelPos &pos1, const PixelPos &pos2)
Definition: linedraw.cpp:992
void ColorCycle()
Does ColorCycling..
Definition: video.cpp:544
void DrawTransRectangle(Uint32 color, int x, int y, int w, int h, unsigned char alpha)
Definition: linedraw.cpp:1005
void DrawTransCircleClip(Uint32 color, int x, int y, int r, unsigned char alpha)
Definition: linedraw.cpp:1047
virtual void * _getData() const
Definition: video.h:180
void SetVideoSync()
Initializes video synchronization.
Definition: sdl.cpp:125
uint32_t(*)(const uint32_t, const uint32_t, const uint32_t) pixelModifier
Definition: video.h:71
void AddColorCyclingRange(unsigned int begin, unsigned int end)
Definition: video.cpp:476
FILE * fd
Definition: video.h:259
void DeInitImageLoaders()
deinitialize the image loaders
Definition: video.cpp:325
void SetOriginalSize()
Definition: graphic.cpp:967
void GetRGBA(Uint32 c, SDL_PixelFormat *f, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
Definition: video.h:390
int Width
Definition: video.h:191
void DrawTransPixelClip(Uint32 color, int x, int y, unsigned char alpha)
Definition: linedraw.cpp:945
int Refs
Original graphic height.
Definition: video.h:196
void(* KeyReleased)(unsigned keycode, unsigned keychar)
Callback for key release.
Definition: video.h:309
void DrawPlayerColorFrameClipX(int colorIndex, unsigned frame, int x, int y, SDL_Surface *surface=TheScreen)
Definition: graphic.cpp:400
w
Definition: update-images.py:53
void VideoPaletteListAdd(SDL_Surface *surface)
Definition: video.cpp:441
Class for modifiers for custom pixel manipulations.
Definition: video.h:74
mng_handle handle
Definition: video.h:260
CVideo()
Definition: video.h:322
void DrawTransHLine(Uint32 color, int x, int y, int width, unsigned char alpha)
Definition: linedraw.cpp:971
void DrawFrameTransX(unsigned frame, int x, int y, int alpha, SDL_Surface *surface=TheScreen) const
Definition: graphic.cpp:358
void FreeGraphics()
Definition: graphic.cpp:1246
virtual int getHeight() const
Definition: video.h:252
static Mng * New(const std::string &name)
Definition: mng.cpp:227
Uint32 ColorOrange
Definition: video.cpp:178
void SaveMapPNG(const char *name)
Save a screenshot to a PNG file.
Definition: png.cpp:67
void Flip()
Definition: graphic.cpp:776
Uint32 IndexToColor(unsigned int index)
Definition: video.h:522
void DrawSubClipTrans(int gx, int gy, int w, int h, int x, int y, unsigned char alpha, SDL_Surface *surface=TheScreen) const
Definition: graphic.cpp:211
void DrawFrameClipCustomMod(unsigned frame, int x, int y, pixelModifier modifier, const uint32_t param, SDL_Surface *surface=TheScreen) const
Definition: graphic.cpp:291
short int y
Definition: video.h:96
CVideo Video
Do SDL hardware unlock.
Definition: video.cpp:155
void MakeShadow(int xOffset, int yOffset)
Definition: graphic.cpp:1215
void FillTransRectangleClip(Uint32 color, int x, int y, int w, int h, unsigned char alpha)
Definition: linedraw.cpp:1030
void DrawHLineClip(Uint32 color, int x, int y, int width)
Definition: linedraw.cpp:975
void FillTransCircleClip(Uint32 color, int x, int y, int radius, unsigned char alpha)
Definition: linedraw.cpp:1069
static CPlayerColorGraphic * New(const std::string &file, int w=0, int h=0)
Definition: graphic.cpp:458
void InvalidateArea(int x, int y, int w, int h)
Definition: sdl.cpp:527
unsigned char B
Green.
Definition: color.h:62
void OverlayGraphic(CGraphic *other, bool mask=false)
Definition: graphic.cpp:1047
Uint32 ColorDarkGray
Definition: video.cpp:182
void SetCallbacks(const EventCallback *callbacks)
Set the current callbacks.
Definition: sdl.cpp:709
int SkipFrames
0 disable interrupts
Definition: video.cpp:172
std::string File
Definition: video.h:184
void RestoreColorCyclingSurface()
Definition: video.cpp:563
void DrawRectangle(Uint32 color, int x, int y, int w, int h)
Definition: linedraw.cpp:1001
Uint32 MapRGBA(SDL_PixelFormat *f, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Definition: video.h:378
SDL_Texture * TheTexture
Internal screen.
Definition: sdl.cpp:93
bool SdlGetGrabMouse()
Check if the mouse is grabbed.
Definition: sdl.cpp:914
frame_pos_t * frame_map
Flipped surface.
Definition: video.h:188
static CPlayerColorGraphic * Get(const std::string &file)
Definition: graphic.cpp:557
SDL_Surface * surface
Definition: video.h:261
void Resize(int w, int h)
Definition: graphic.cpp:839
void DrawFrameClipX(unsigned frame, int x, int y, SDL_Surface *surface=TheScreen) const
Definition: graphic.cpp:342
std::string name
Definition: video.h:258
void DrawRectangleClip(Uint32 color, int x, int y, int w, int h)
Definition: linedraw.cpp:1009
bool is_dirty
Definition: video.h:257
Uint32 ColorGreen
Definition: video.cpp:184
void BlitSurfaceAlphaBlending_32bpp(const SDL_Surface *srcSurface, const SDL_Rect *srcRect, SDL_Surface *dstSurface, const SDL_Rect *dstRect, const bool enableMT=true)
Blit a surface into another with alpha blending.
Definition: video.cpp:366
const char * SdlKey2Str(int key)
Convert a SDLKey to a string.
Definition: sdl.cpp:884
void InitLineDraw()
Init line draw.
Definition: linedraw.cpp:922
void DrawFrameX(unsigned frame, int x, int y, SDL_Surface *surface=TheScreen) const
Definition: graphic.cpp:325
void DrawTransVLineClip(Uint32 color, int x, int y, int height, unsigned char alpha)
Definition: linedraw.cpp:962
int GraphicWidth
Number of frames.
Definition: video.h:194
short int x
Definition: video.h:95
h
Definition: update-images.py:53
unsigned int SetColorCycleSpeed(unsigned int speed)
Definition: video.cpp:487
static uint32_t MaxFPS
Definition: video.h:255
void DrawTransLineClip(Uint32 color, int sx, int sy, int dx, int dy, unsigned char alpha)
Definition: linedraw.cpp:996
#define AMASK
Definition: video.h:59
bool Resized
Uses of this graphic.
Definition: video.h:197
virtual bool isDirty() const
Definition: video.h:253
void DrawSubClipCustomMod(int gx, int gy, int w, int h, int x, int y, pixelModifier modifier, const uint32_t param, SDL_Surface *surface=TheScreen) const
Definition: graphic.cpp:236
unsigned long SlowFrameCounter
Counts quantity of slow frames.
Definition: video.cpp:162
void GenFramesMap()
Definition: graphic.cpp:599
Uint32 MapRGB(SDL_PixelFormat *f, const CColor &color)
Definition: video.h:374
void DrawTransVLine(Uint32 color, int x, int y, int height, unsigned char alpha)
Definition: linedraw.cpp:954
int VideoSyncSpeed
Definition: video.cpp:171
Uint32 ColorGray
Definition: video.cpp:181
void VideoPaletteListRemove(SDL_Surface *surface)
Definition: video.cpp:461
int Width
Definition: video.h:395
SDL_Renderer * TheRenderer
Internal screen.
Definition: sdl.cpp:92
void WaitEventsOneFrame()
Process all system events. Returns if the time for a frame is over.
Definition: sdl.cpp:732
Uint32 ColorBlack
Editor callbacks.
Definition: video.cpp:174
Font definition.
Definition: font.h:73
void ClearScreen()
Definition: video.cpp:257
void(* KeyRepeated)(unsigned keycode, unsigned keychar)
Callback for key repeated.
Definition: video.h:311
void Invalidate()
Simply invalidates whole window or screen.
Definition: sdl.cpp:541
void DrawPixelClip(Uint32 color, int x, int y)
Definition: linedraw.cpp:941
void DrawTransLine(Uint32 color, int sx, int sy, int dx, int dy, unsigned char alpha)
Definition: linedraw.cpp:988
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.