ManaPlus
Public Member Functions | Protected Attributes
SurfaceGraphics Class Reference

#include <surfacegraphics.h>

Inheritance diagram for SurfaceGraphics:
Graphics

Public Member Functions

 SurfaceGraphics ()
 
 ~SurfaceGraphics ()
 
void setTarget (SDL_Surface *const target)
 
SDL_Surface * getTarget () const
 
void beginDraw ()
 
void endDraw ()
 
void pushClipArea (const Rect &rect)
 
void popClipArea ()
 
void drawRescaledImage (const Image *const image, int dstX, int dstY, const int desiredWidth, const int desiredHeight)
 
void drawPattern (const Image *const image, const int x, const int y, const int w, const int h)
 
void drawRescaledPattern (const Image *const image, const int x, const int y, const int w, const int h, const int scaledWidth, const int scaledHeight)
 
void calcPattern (ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const
 
void calcPattern (ImageCollection *const vert, const Image *const image, const int x, const int y, const int w, const int h) const
 
void calcTileVertexes (ImageVertexes *const vert, const Image *const image, int x, int y) const
 
void calcTileSDL (ImageVertexes *const vert, int x, int y) const
 
void calcTileCollection (ImageCollection *const vertCol, const Image *const image, int x, int y)
 
void drawTileVertexes (const ImageVertexes *const vert)
 
void drawTileCollection (const ImageCollection *const vertCol)
 
void updateScreen ()
 
void drawNet (const int x1, const int y1, const int x2, const int y2, const int width, const int height)
 
void calcWindow (ImageCollection *const vertCol, const int x, const int y, const int w, const int h, const ImageRect &imgRect)
 
void setBlitMode (const BlitModeT mode)
 
BlitModeT getBlitMode () const
 
void fillRectangle (const Rect &rect)
 
void drawRectangle (const Rect &rect)
 
void drawPoint (int x, int y)
 
void drawLine (int x1, int y1, int x2, int y2)
 
bool setVideoMode (const int w, const int h, const int scale, const int bpp, const bool fs, const bool hwaccel, const bool resize, const bool noFrame, const bool allowHighDPI)
 
void drawImage (const Image *const image, int dstX, int dstY)
 
void copyImage (const Image *const image, int dstX, int dstY)
 
void drawImageCached (const Image *const image, int x, int y)
 
void drawPatternCached (const Image *const image, const int x, const int y, const int w, const int h)
 
void completeCache ()
 
void drawImageRect (const int x, const int y, const int w, const int h, const ImageRect &imgRect)
 
- Public Member Functions inherited from Graphics
virtual ~Graphics ()
 
void setWindow (SDL_Surface *const window, const int width, const int height)
 
SDL_Surface * getWindow () const
 
void setSync (const bool sync)
 
bool getSync () const
 
bool setFullscreen (const bool fs)
 
virtual bool resizeScreen (const int width, const int height)
 
virtual void restoreContext ()
 
void setWindowSize (const int width, const int height)
 
int getWidth () const
 
int getHeight () const
 
int getMemoryUsage () const
 
ClipRectgetTopClip () const
 
void setRedraw (const bool n)
 
bool getRedraw () const
 
void setSecure (const bool n)
 
bool getSecure () const
 
int getBpp () const
 
bool getFullScreen () const
 
bool getHWAccel () const
 
bool getDoubleBuffer () const
 
RenderType getOpenGL () const
 
void setNoFrame (const bool n)
 
const std::string & getName () const
 
virtual void initArrays (const int vertCount)
 
virtual void setColor (const Color &color)
 
const ColorgetColor () const
 
int getScale () const
 
virtual bool isAllowScale () const
 
void setScale (int scale)
 
virtual void createGLContext (const bool custom)
 
virtual void clearScreen () const
 
virtual void deleteArrays ()
 
virtual void postInit ()
 
virtual void finalize (ImageCollection *const col)
 
virtual void finalize (ImageVertexes *const vert)
 
virtual void testDraw ()
 
virtual void removeArray (const uint32_t sz, uint32_t *const arr)
 
virtual void screenResized ()
 

Protected Attributes

BlitModeT mBlitMode
 
SDL_Surface * mTarget
 
- Protected Attributes inherited from Graphics
MStack< ClipRectmClipStack
 
SDL_Surface * mWindow
 
int mBpp
 
bool mAlpha
 
bool mFullscreen
 
bool mHWAccel
 
bool mRedraw
 
bool mDoubleBuffer
 
SDL_Rect mRect
 
bool mSecure
 
RenderType mOpenGL
 
bool mEnableResize
 
bool mNoFrame
 
bool mAllowHighDPI
 
std::string mName
 
int mStartFreeMem
 
bool mSync
 
int mScale
 
Color mColor
 

Additional Inherited Members

- Public Types inherited from Graphics
enum  Alignment { LEFT = 0 , CENTER , RIGHT }
 
- Static Public Member Functions inherited from Graphics
static void cleanUp ()
 
- Data Fields inherited from Graphics
int mWidth
 
int mHeight
 
int mActualWidth
 
int mActualHeight
 
- Protected Member Functions inherited from Graphics
 Graphics ()
 
void setMainFlags (const int w, const int h, const int scale, const int bpp, const bool fs, const bool hwaccel, const bool resize, const bool noFrame, const bool allowHighDPI)
 
int getOpenGLFlags () const
 
int getSoftwareFlags () const
 
bool setOpenGLMode ()
 
void updateMemoryInfo ()
 
bool videoInfo ()
 
void setOpenGLFlags ()
 
- Static Protected Attributes inherited from Graphics
static void * mGLContext = 0
 

Detailed Description

A central point of control for graphics.

Definition at line 40 of file surfacegraphics.h.

Constructor & Destructor Documentation

◆ SurfaceGraphics()

SurfaceGraphics::SurfaceGraphics ( )

Definition at line 34 of file surfacegraphics.cpp.

34  :
35  Graphics(),
37  mTarget(nullptr)
38 {
40  mName = "Surface";
41 }
RenderType mOpenGL
Definition: graphics.h:545
std::string mName
Definition: graphics.h:549
SDL_Surface * mTarget
@ BLIT_NORMAL
Definition: blitmode.h:31
@ RENDER_SOFTWARE
Definition: rendertype.h:27

References Graphics::mName, Graphics::mOpenGL, and RENDER_SOFTWARE.

◆ ~SurfaceGraphics()

SurfaceGraphics::~SurfaceGraphics ( )

Definition at line 43 of file surfacegraphics.cpp.

44 {
45 }

Member Function Documentation

◆ beginDraw()

void SurfaceGraphics::beginDraw ( )
inlinevirtual

Initializes drawing. Called by the Gui when Gui::draw() is called. It is needed by some implementations of Graphics to perform preparations before drawing. An example of such an implementation is the OpenGLGraphics.

NOTE: You will never need to call this function yourself, unless you use a Graphics object outside of Guichan.

See also
endDraw, Gui::draw

Reimplemented from Graphics.

Definition at line 55 of file surfacegraphics.h.

56  { }

Referenced by CompoundSprite::redraw().

◆ calcPattern() [1/2]

void SurfaceGraphics::calcPattern ( ImageCollection *const  vert,
const Image *const  image,
const int  x,
const int  y,
const int  w,
const int  h 
) const
inlinevirtual

Implements Graphics.

Definition at line 100 of file surfacegraphics.h.

106  { }

◆ calcPattern() [2/2]

void SurfaceGraphics::calcPattern ( ImageVertexes *const  vert,
const Image *const  image,
const int  x,
const int  y,
const int  w,
const int  h 
) const
inlinevirtual

Implements Graphics.

Definition at line 92 of file surfacegraphics.h.

98  { }

◆ calcTileCollection()

void SurfaceGraphics::calcTileCollection ( ImageCollection *const  vertCol,
const Image *const  image,
int  x,
int  y 
)
inlinevirtual

Implements Graphics.

Definition at line 120 of file surfacegraphics.h.

125  { }

◆ calcTileSDL()

void SurfaceGraphics::calcTileSDL ( ImageVertexes *const  vert,
int  x,
int  y 
) const
inlinevirtual

Reimplemented from Graphics.

Definition at line 115 of file surfacegraphics.h.

118  { }

◆ calcTileVertexes()

void SurfaceGraphics::calcTileVertexes ( ImageVertexes *const  vert,
const Image *const  image,
int  x,
int  y 
) const
inlinevirtual

Implements Graphics.

Definition at line 108 of file surfacegraphics.h.

113  { }

◆ calcWindow()

void SurfaceGraphics::calcWindow ( ImageCollection *const  vertCol,
const int  x,
const int  y,
const int  w,
const int  h,
const ImageRect imgRect 
)
inlinevirtual

Implements Graphics.

Definition at line 147 of file surfacegraphics.h.

152  { }

◆ completeCache()

void SurfaceGraphics::completeCache ( )
virtual

Implements Graphics.

Definition at line 155 of file surfacegraphics.cpp.

156 {
157 }

◆ copyImage()

void SurfaceGraphics::copyImage ( const Image *const  image,
int  dstX,
int  dstY 
)
virtual

Implements Graphics.

Definition at line 85 of file surfacegraphics.cpp.

87 {
88  FUNC_BLOCK("Graphics::drawImage", 1)
89  // Check that preconditions for blitting are met.
90  if (mTarget == nullptr ||
91  image == nullptr ||
92  image->mSDLSurface == nullptr)
93  {
94  return;
95  }
96 
97  const SDL_Rect &imageRect = image->mBounds;
98  SDL_Rect dstRect;
99  SDL_Rect srcRect;
100  dstRect.x = CAST_S16(dstX);
101  dstRect.y = CAST_S16(dstY);
102  srcRect.x = CAST_S16(imageRect.x);
103  srcRect.y = CAST_S16(imageRect.y);
104  srcRect.w = CAST_U16(imageRect.w);
105  srcRect.h = CAST_U16(imageRect.h);
106 
107 #ifdef USE_SDL2
108  // probably need change some flags
109  SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
110 #else // USE_SDL2
111 
112  SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
113 #endif // USE_SDL2
114 }
#define CAST_U16
Definition: cast.h:29
#define CAST_S16
Definition: cast.h:28
if(!vert) return
#define FUNC_BLOCK(name, id)
Definition: perfomance.h:81

References CAST_S16, CAST_U16, and FUNC_BLOCK.

◆ drawImage()

void SurfaceGraphics::drawImage ( const Image *const  image,
int  dstX,
int  dstY 
)
virtual

Blits an image onto the screen.

Returns
true if the image was blitted properly false otherwise.

Implements Graphics.

Definition at line 47 of file surfacegraphics.cpp.

49 {
50  FUNC_BLOCK("Graphics::drawImage", 1)
51  // Check that preconditions for blitting are met.
52  if (mTarget == nullptr ||
53  image == nullptr ||
54  image->mSDLSurface == nullptr)
55  {
56  return;
57  }
58 
59  const SDL_Rect &imageRect = image->mBounds;
60  SDL_Rect dstRect;
61  SDL_Rect srcRect;
62  dstRect.x = CAST_S16(dstX);
63  dstRect.y = CAST_S16(dstY);
64  srcRect.x = CAST_S16(imageRect.x);
65  srcRect.y = CAST_S16(imageRect.y);
66  srcRect.w = CAST_U16(imageRect.w);
67  srcRect.h = CAST_U16(imageRect.h);
68 
69 #ifdef USE_SDL2
70  SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
71 #else // USE_SDL2
72 
74  {
75  SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
76  }
77  else
78  {
79  SurfaceImageHelper::combineSurface(image->mSDLSurface,
80  &srcRect, mTarget, &dstRect);
81  }
82 #endif // USE_SDL2
83 }

References BlitMode::BLIT_NORMAL, CAST_S16, CAST_U16, and FUNC_BLOCK.

◆ drawImageCached()

void SurfaceGraphics::drawImageCached ( const Image *const  image,
int  x,
int  y 
)
virtual

Implements Graphics.

Definition at line 116 of file surfacegraphics.cpp.

118 {
119  FUNC_BLOCK("Graphics::drawImageCached", 1)
120  // Check that preconditions for blitting are met.
121  if (mTarget == nullptr ||
122  image == nullptr ||
123  image->mSDLSurface == nullptr)
124  {
125  return;
126  }
127 
128  const SDL_Rect &rect = image->mBounds;
129 
130  SDL_Rect dstRect;
131  SDL_Rect srcRect;
132  dstRect.x = CAST_S16(x);
133  dstRect.y = CAST_S16(y);
134  srcRect.x = CAST_S16(rect.x);
135  srcRect.y = CAST_S16(rect.y);
136  srcRect.w = CAST_U16(rect.w);
137  srcRect.h = CAST_U16(rect.h);
138 
139 #ifdef USE_SDL2
140  SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
141 #else // USE_SDL2
142 
144  {
145  SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
146  }
147  else
148  {
149  SurfaceImageHelper::combineSurface(image->mSDLSurface, &srcRect,
150  mTarget, &dstRect);
151  }
152 #endif // USE_SDL2
153 }

References BlitMode::BLIT_NORMAL, CAST_S16, CAST_U16, FUNC_BLOCK, x, and y.

◆ drawImageRect()

void SurfaceGraphics::drawImageRect ( const int  x,
const int  y,
const int  w,
const int  h,
const ImageRect imgRect 
)
inlinevirtual

Draws a rectangle using images. 4 corner images, 4 side images and 1 image for the inside.

Implements Graphics.

Definition at line 208 of file surfacegraphics.h.

212  { }

◆ drawLine()

void SurfaceGraphics::drawLine ( int  x1,
int  y1,
int  x2,
int  y2 
)
inlinevirtual

Ddraws a line.

Parameters
x1The first x coordinate.
y1The first y coordinate.
x2The second x coordinate.
y2The second y coordinate.

Implements Graphics.

Definition at line 171 of file surfacegraphics.h.

174  { }

◆ drawNet()

void SurfaceGraphics::drawNet ( const int  x1,
const int  y1,
const int  x2,
const int  y2,
const int  width,
const int  height 
)
inlinevirtual

Reimplemented from Graphics.

Definition at line 139 of file surfacegraphics.h.

145  { }

◆ drawPattern()

void SurfaceGraphics::drawPattern ( const Image *const  image,
const int  x,
const int  y,
const int  w,
const int  h 
)
inlinevirtual

Implements Graphics.

Definition at line 75 of file surfacegraphics.h.

80  { }

◆ drawPatternCached()

void SurfaceGraphics::drawPatternCached ( const Image *const  image,
const int  x,
const int  y,
const int  w,
const int  h 
)
inlinevirtual

Implements Graphics.

Definition at line 195 of file surfacegraphics.h.

200  { }

◆ drawPoint()

void SurfaceGraphics::drawPoint ( int  x,
int  y 
)
inlinevirtual

Draws a single point/pixel.

Parameters
xThe x coordinate.
yThe y coordinate.

Implements Graphics.

Definition at line 168 of file surfacegraphics.h.

169  { }

◆ drawRectangle()

void SurfaceGraphics::drawRectangle ( const Rect rectangle)
inlinevirtual

Draws a simple, non-filled, rectangle with a one pixel width.

Parameters
rectangleThe rectangle to draw.

Implements Graphics.

Definition at line 164 of file surfacegraphics.h.

166  { }

◆ drawRescaledImage()

void SurfaceGraphics::drawRescaledImage ( const Image *const  image,
int  dstX,
int  dstY,
const int  desiredWidth,
const int  desiredHeight 
)
inlinevirtual

Draws a resclaled version of the image

Implements Graphics.

Definition at line 68 of file surfacegraphics.h.

73  { }

◆ drawRescaledPattern()

void SurfaceGraphics::drawRescaledPattern ( const Image *const  image,
const int  x,
const int  y,
const int  w,
const int  h,
const int  scaledWidth,
const int  scaledHeight 
)
inlinevirtual

Draw a pattern based on a rescaled version of the given image...

Implements Graphics.

Definition at line 82 of file surfacegraphics.h.

90  { }

◆ drawTileCollection()

void SurfaceGraphics::drawTileCollection ( const ImageCollection *const  vertCol)
inlinevirtual

Implements Graphics.

Definition at line 131 of file surfacegraphics.h.

134  { }

◆ drawTileVertexes()

void SurfaceGraphics::drawTileVertexes ( const ImageVertexes *const  vert)
inlinevirtual

Implements Graphics.

Definition at line 127 of file surfacegraphics.h.

129  { }

◆ endDraw()

void SurfaceGraphics::endDraw ( )
inlinevirtual

Deinitializes drawing. Called by the Gui when a Gui::draw() is done. done. It should reset any state changes made by beginDraw().

NOTE: You will never need to call this function yourself, unless you use a Graphics object outside of Guichan.

See also
beginDraw, Gui::draw

Reimplemented from Graphics.

Definition at line 58 of file surfacegraphics.h.

59  { }

◆ fillRectangle()

void SurfaceGraphics::fillRectangle ( const Rect rect)
inlinevirtual

Implements Graphics.

Definition at line 160 of file surfacegraphics.h.

162  { }

◆ getBlitMode()

BlitModeT SurfaceGraphics::getBlitMode ( ) const
inline

Definition at line 157 of file surfacegraphics.h.

158  { return mBlitMode; }

References mBlitMode.

◆ getTarget()

SDL_Surface* SurfaceGraphics::getTarget ( ) const
inline

Definition at line 52 of file surfacegraphics.h.

53  { return mTarget; }

References mTarget.

◆ popClipArea()

void SurfaceGraphics::popClipArea ( )
inlinevirtual

Removes the top most clip area from the stack.

Exceptions
Exceptionif the stack is empty.

Reimplemented from Graphics.

Definition at line 65 of file surfacegraphics.h.

66  { }

◆ pushClipArea()

void SurfaceGraphics::pushClipArea ( const Rect area)
inlinevirtual

Pushes a clip area onto the stack. The x and y coordinates in the rectangle is relative to the last pushed clip area. If the new area falls outside the current clip area, it will be clipped as necessary.

If a clip area is outside of the top clip area a clip area with zero width and height will be pushed.

Parameters
areaThe clip area to be pushed onto the stack.

Reimplemented from Graphics.

Definition at line 61 of file surfacegraphics.h.

63  { }

◆ setBlitMode()

void SurfaceGraphics::setBlitMode ( const BlitModeT  mode)
inline

Definition at line 154 of file surfacegraphics.h.

155  { mBlitMode = mode; }

References mBlitMode.

Referenced by CompoundSprite::redraw().

◆ setTarget()

void SurfaceGraphics::setTarget ( SDL_Surface *const  target)
inline

Definition at line 49 of file surfacegraphics.h.

50  { mTarget = target; }

References mTarget.

Referenced by CompoundSprite::redraw().

◆ setVideoMode()

bool SurfaceGraphics::setVideoMode ( const int  w,
const int  h,
const int  scale,
const int  bpp,
const bool  fs,
const bool  hwaccel,
const bool  resize,
const bool  noFrame,
const bool  allowHighDPI 
)
inlinevirtual

Try to create a window with the given settings.

Implements Graphics.

Definition at line 176 of file surfacegraphics.h.

184  { return false; }

◆ updateScreen()

void SurfaceGraphics::updateScreen ( )
inlinevirtual

Updates the screen. This is done by either copying the buffer to the screen or swapping pages.

Implements Graphics.

Definition at line 136 of file surfacegraphics.h.

137  { }

Field Documentation

◆ mBlitMode

BlitModeT SurfaceGraphics::mBlitMode
protected

Definition at line 215 of file surfacegraphics.h.

Referenced by getBlitMode(), and setBlitMode().

◆ mTarget

SDL_Surface* SurfaceGraphics::mTarget
protected

Definition at line 216 of file surfacegraphics.h.

Referenced by getTarget(), and setTarget().


The documentation for this class was generated from the following files: