ManaPlus
Public Member Functions | Protected Member Functions | Protected Attributes
SDLGraphics Class Reference

#include <sdlgraphics.h>

Inheritance diagram for SDLGraphics:
Graphics

Public Member Functions

 SDLGraphics ()
 
 ~SDLGraphics ()
 
- 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
 
virtual 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)=0
 
bool setFullscreen (const bool fs)
 
virtual bool resizeScreen (const int width, const int height)
 
virtual void restoreContext ()
 
virtual void drawRescaledImage (const Image *const image, int dstX, int dstY, const int desiredWidth, const int desiredHeight)=0
 
virtual void drawPattern (const Image *const image, const int x, const int y, const int w, const int h)=0
 
virtual void drawRescaledPattern (const Image *const image, const int x, const int y, const int w, const int h, const int scaledWidth, const int scaledHeight)=0
 
virtual void drawImageRect (const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
 
virtual void calcPattern (ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const =0
 
virtual void calcPattern (ImageCollection *const vert, const Image *const image, const int x, const int y, const int w, const int h) const =0
 
virtual void calcTileVertexes (ImageVertexes *const vert, const Image *const image, int x, int y) const =0
 
virtual void calcTileSDL (ImageVertexes *const vert, int x, int y) const
 
virtual void drawTileVertexes (const ImageVertexes *const vert)=0
 
virtual void drawTileCollection (const ImageCollection *const vertCol)=0
 
virtual void calcTileCollection (ImageCollection *const vertCol, const Image *const image, int x, int y)=0
 
virtual void calcWindow (ImageCollection *const vertCol, const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
 
virtual void fillRectangle (const Rect &rectangle)=0
 
virtual void updateScreen ()=0
 
void setWindowSize (const int width, const int height)
 
int getWidth () const
 
int getHeight () const
 
int getMemoryUsage () const
 
virtual void drawNet (const int x1, const int y1, const int x2, const int y2, const int width, const int height)
 
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
 
virtual void drawImage (const Image *const image, int dstX, int dstY)=0
 
virtual void copyImage (const Image *const image, int dstX, int dstY)=0
 
virtual void drawImageCached (const Image *const image, int srcX, int srcY)=0
 
virtual void drawPatternCached (const Image *const image, const int x, const int y, const int w, const int h)=0
 
virtual void completeCache ()=0
 
int getScale () const
 
virtual bool isAllowScale () const
 
void setScale (int scale)
 
virtual void pushClipArea (const Rect &area)
 
virtual void popClipArea ()
 
virtual void drawLine (int x1, int y1, int x2, int y2)=0
 
virtual void drawRectangle (const Rect &rectangle)=0
 
virtual void createGLContext (const bool custom)
 
virtual void drawPoint (int x, int y)=0
 
virtual void beginDraw ()
 
virtual void endDraw ()
 
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 Member Functions

int SDL_FakeUpperBlit (const SDL_Surface *const src, SDL_Rect *const srcrect, const SDL_Surface *const dst, SDL_Rect *dstrect) const
 
void drawHLine (int x1, int y, int x2)
 
void drawVLine (int x, int y1, int y2)
 
- 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 ()
 

Protected Attributes

uint32_t mOldPixel
 
unsigned int mOldAlpha
 
- 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
 
- 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 sdlgraphics.h.

Constructor & Destructor Documentation

◆ SDLGraphics()

SDLGraphics::SDLGraphics ( )

Constructor.

Definition at line 52 of file sdlgraphics.cpp.

52  :
53  Graphics(),
54  mOldPixel(0),
55  mOldAlpha(0)
56 {
58  mName = "Software";
59 }
RenderType mOpenGL
Definition: graphics.h:545
std::string mName
Definition: graphics.h:549
uint32_t mOldPixel
Definition: sdlgraphics.h:71
unsigned int mOldAlpha
Definition: sdlgraphics.h:72
@ RENDER_SOFTWARE
Definition: rendertype.h:27

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

◆ ~SDLGraphics()

SDLGraphics::~SDLGraphics ( )

Destructor.

Definition at line 61 of file sdlgraphics.cpp.

62 {
63 }

Member Function Documentation

◆ drawHLine()

void SDLGraphics::drawHLine ( int  x1,
int  y,
int  x2 
)
protected

Definition at line 1182 of file sdlgraphics.cpp.

1183 {
1184  if (mClipStack.empty())
1185  return;
1186 
1187  const ClipRect& top = mClipStack.top();
1188 
1189  const int xOffset = top.xOffset;
1190  x1 += xOffset;
1191  y += top.yOffset;
1192  x2 += xOffset;
1193 
1194  const int topY = top.y;
1195  if (y < topY || y >= topY + top.height)
1196  return;
1197 
1198  if (x1 > x2)
1199  {
1200  x1 ^= x2;
1201  x2 ^= x1;
1202  x1 ^= x2;
1203  }
1204 
1205  const int topX = top.x;
1206  if (topX > x1)
1207  {
1208  if (topX > x2)
1209  return;
1210 
1211  x1 = topX;
1212  }
1213 
1214  const int sumX = topX + top.width;
1215  if (sumX <= x2)
1216  {
1217  if (sumX <= x1)
1218  return;
1219 
1220  x2 = sumX -1;
1221  }
1222 
1223  const int bpp = mWindow->format->BytesPerPixel;
1224 
1225  SDL_LockSurface(mWindow);
1226 
1227  uint8_t *p = static_cast<uint8_t*>(mWindow->pixels)
1228  + CAST_SIZE(y * mWindow->pitch + x1 * bpp);
1229 
1230  const uint32_t pixel = SDL_MapRGB(mWindow->format,
1231  CAST_U8(mColor.r),
1232  CAST_U8(mColor.g),
1233  CAST_U8(mColor.b));
1234  switch (bpp)
1235  {
1236  case 1:
1237  for (; x1 <= x2; ++x1)
1238  *(p++) = CAST_U8(pixel);
1239  break;
1240 
1241  case 2:
1242  {
1243  uint16_t* q = reinterpret_cast<uint16_t*>(p);
1244  const uint16_t pixel1 = CAST_U16(pixel);
1245  for (; x1 <= x2; ++x1)
1246  *(q++) = pixel1;
1247  break;
1248  }
1249 
1250  case 3:
1251  {
1252  const uint8_t b0 = CAST_U8((pixel >> 16) & 0xff);
1253  const uint8_t b1 = CAST_U8((pixel >> 8) & 0xff);
1254  const uint8_t b2 = CAST_U8(pixel & 0xff);
1255 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
1256  for (; x1 <= x2; ++x1)
1257  {
1258  p[0] = b0;
1259  p[1] = b1;
1260  p[2] = b2;
1261  p += 3;
1262  }
1263 #else // SDL_BYTEORDER == SDL_BIG_ENDIAN
1264  for (; x1 <= x2; ++x1)
1265  {
1266  p[0] = b2;
1267  p[1] = b1;
1268  p[2] = b0;
1269  p += 3;
1270  }
1271 #endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
1272  break;
1273  }
1274 
1275  case 4:
1276  {
1277  uint32_t *q = reinterpret_cast<uint32_t*>(p);
1278  if (mAlpha)
1279  {
1280  unsigned char a = CAST_U8(mColor.a);
1281  unsigned char a1 = CAST_U8(255U - a);
1282  const int b0 = (pixel & 0xff) * a;
1283  const int g0 = (pixel & 0xff00) * a;
1284  const int r0 = (pixel & 0xff0000) * a;
1285  for (; x1 <= x2; ++x1)
1286  {
1287  const unsigned int b = (b0 + (*q & 0xff) * a1) >> 8;
1288  const unsigned int g = (g0 + (*q & 0xff00) * a1) >> 8;
1289  const unsigned int r = (r0 + (*q & 0xff0000) * a1) >> 8;
1290  *q = (b & 0xff) | (g & 0xff00) | (r & 0xff0000);
1291 
1292  q++;
1293  }
1294  }
1295  else
1296  {
1297  for (; x1 <= x2; ++x1)
1298  *(q++) = pixel;
1299  }
1300  break;
1301  }
1302  default:
1303  break;
1304  } // end switch
1305 
1306  SDL_UnlockSurface(mWindow);
1307 }
#define CAST_U16
Definition: cast.h:29
#define CAST_SIZE
Definition: cast.h:34
#define CAST_U8
Definition: cast.h:27
unsigned int a
Definition: color.h:251
unsigned int b
Definition: color.h:245
unsigned int r
Definition: color.h:235
unsigned int g
Definition: color.h:240
SDL_Surface * mWindow
Definition: graphics.h:523
Color mColor
Definition: graphics.h:553
MStack< ClipRect > mClipStack
Definition: graphics.h:521
bool mAlpha
Definition: graphics.h:538
const Image *restrict const top
bool empty() const
Definition: mstack.h:88
T & top() const
Definition: mstack.h:73

References CAST_SIZE, CAST_U16, CAST_U8, top, and y.

◆ drawVLine()

void SDLGraphics::drawVLine ( int  x,
int  y1,
int  y2 
)
protected

Definition at line 1309 of file sdlgraphics.cpp.

1310 {
1311  if (mClipStack.empty())
1312  return;
1313 
1314  const ClipRect &restrict top = mClipStack.top();
1315 
1316  const int yOffset = top.yOffset;
1317  x += top.xOffset;
1318  y1 += yOffset;
1319  y2 += yOffset;
1320 
1321  if (x < top.x || x >= top.x + top.width)
1322  return;
1323 
1324  if (y1 > y2)
1325  {
1326  y1 ^= y2;
1327  y2 ^= y1;
1328  y1 ^= y2;
1329  }
1330 
1331  if (top.y > y1)
1332  {
1333  if (top.y > y2)
1334  return;
1335 
1336  y1 = top.y;
1337  }
1338 
1339  const int sumY = top.y + top.height;
1340  if (sumY <= y2)
1341  {
1342  if (sumY <= y1)
1343  return;
1344 
1345  y2 = sumY - 1;
1346  }
1347 
1348  const int bpp = mWindow->format->BytesPerPixel;
1349 
1350  SDL_LockSurface(mWindow);
1351 
1352  uint8_t *p = static_cast<uint8_t*>(mWindow->pixels)
1353  + CAST_SIZE(y1 * mWindow->pitch + x * bpp);
1354 
1355  const uint32_t pixel = SDL_MapRGB(mWindow->format,
1356  CAST_U8(mColor.r),
1357  CAST_U8(mColor.g),
1358  CAST_U8(mColor.b));
1359 
1360  const int pitch = mWindow->pitch;
1361  switch (bpp)
1362  {
1363  case 1:
1364  for (; y1 <= y2; ++y1)
1365  {
1366  *p = CAST_U8(pixel);
1367  p += pitch;
1368  }
1369  break;
1370 
1371  case 2:
1372  for (; y1 <= y2; ++ y1)
1373  {
1374  *reinterpret_cast<uint16_t*>(p)
1375  = CAST_U16(pixel);
1376  p += pitch;
1377  }
1378  break;
1379 
1380  case 3:
1381  {
1382  const uint8_t b0 = CAST_U8((pixel >> 16) & 0xff);
1383  const uint8_t b1 = CAST_U8((pixel >> 8) & 0xff);
1384  const uint8_t b2 = CAST_U8(pixel & 0xff);
1385 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
1386  for (; y1 <= y2; ++y1)
1387  {
1388  p[0] = b0;
1389  p[1] = b1;
1390  p[2] = b2;
1391  p += pitch;
1392  }
1393 #else // SDL_BYTEORDER == SDL_BIG_ENDIAN
1394  for (; y1 <= y2; ++y1)
1395  {
1396  p[0] = b2;
1397  p[1] = b1;
1398  p[2] = b0;
1399  p += pitch;
1400  }
1401 #endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
1402  break;
1403  }
1404 
1405  case 4:
1406  {
1407  if (mAlpha)
1408  {
1409  unsigned char a = CAST_U8(mColor.a);
1410  unsigned char a1 = CAST_U8(255U - a);
1411  const int b0 = (pixel & 0xff) * a;
1412  const int g0 = (pixel & 0xff00) * a;
1413  const int r0 = (pixel & 0xff0000) * a;
1414  for (; y1 <= y2; ++y1)
1415  {
1416  const unsigned int dst = *reinterpret_cast<uint32_t*>(p);
1417  const unsigned int b = (b0 + (dst & 0xff) * a1) >> 8;
1418  const unsigned int g = (g0 + (dst & 0xff00) * a1) >> 8;
1419  const unsigned int r = (r0 + (dst & 0xff0000) * a1) >> 8;
1420  *reinterpret_cast<uint32_t*>(p) =
1421  (b & 0xff) | (g & 0xff00) | (r & 0xff0000);
1422 
1423  p += pitch;
1424  }
1425  }
1426  else
1427  {
1428  for (; y1 <= y2; ++y1)
1429  {
1430  *reinterpret_cast<uint32_t*>(p) = pixel;
1431  p += pitch;
1432  }
1433  }
1434  break;
1435  }
1436 
1437  default:
1438  break;
1439  } // end switch
1440 
1441  SDL_UnlockSurface(mWindow);
1442 }
#define restrict
Definition: localconsts.h:165

References CAST_SIZE, CAST_U16, CAST_U8, restrict, top, and x.

◆ SDL_FakeUpperBlit()

int SDLGraphics::SDL_FakeUpperBlit ( const SDL_Surface *const  src,
SDL_Rect *const  srcrect,
const SDL_Surface *const  dst,
SDL_Rect *  dstrect 
) const
protected

Definition at line 838 of file sdlgraphics.cpp.

842 {
843  int srcx;
844  int srcy;
845  int w;
846  int h;
847 
848  // Make sure the surfaces aren't locked
849  if ((src == nullptr) || (dst == nullptr))
850  return -1;
851 
852  if ((srcrect == nullptr) || (dstrect == nullptr))
853  return -1;
854 
855  srcx = srcrect->x;
856  w = srcrect->w;
857  if (srcx < 0)
858  {
859  w += srcx;
860  dstrect->x -= CAST_S16(srcx);
861  srcx = 0;
862  }
863  int maxw = src->w - srcx;
864  if (maxw < w)
865  w = maxw;
866 
867  srcy = srcrect->y;
868  h = srcrect->h;
869  if (srcy < 0)
870  {
871  h += srcy;
872  dstrect->y -= CAST_S16(srcy);
873  srcy = 0;
874  }
875  int maxh = src->h - srcy;
876  if (maxh < h)
877  h = maxh;
878 
879  const SDL_Rect *const clip = &dst->clip_rect;
880  const int clipX = clip->x;
881  const int clipY = clip->y;
882  int dx = clipX - dstrect->x;
883  if (dx > 0)
884  {
885  w -= dx;
886  dstrect->x += CAST_S16(dx);
887  srcx += dx;
888  }
889  dx = dstrect->x + w - clipX - clip->w;
890  if (dx > 0)
891  w -= dx;
892 
893  int dy = clipY - dstrect->y;
894  if (dy > 0)
895  {
896  h -= dy;
897  dstrect->y += CAST_S16(dy);
898  srcy += dy;
899  }
900  dy = dstrect->y + h - clipY - clip->h;
901  if (dy > 0)
902  h -= dy;
903 
904  if (w > 0 && h > 0)
905  {
906  srcrect->x = CAST_S16(srcx);
907  srcrect->y = CAST_S16(srcy);
908  srcrect->w = CAST_S16(w);
909  srcrect->h = CAST_S16(h);
910  dstrect->w = CAST_S16(w);
911  dstrect->h = CAST_S16(h);
912 
913  return 1;
914 // return SDL_LowerBlit(src, &sr, dst, dstrect);
915  }
916  dstrect->w = dstrect->h = 0;
917  return 0;
918 }
#define CAST_S16
Definition: cast.h:28

References CAST_S16.

Field Documentation

◆ mOldAlpha

unsigned int SDLGraphics::mOldAlpha
protected

Definition at line 72 of file sdlgraphics.h.

◆ mOldPixel

uint32_t SDLGraphics::mOldPixel
protected

Definition at line 71 of file sdlgraphics.h.


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