Permalink
Browse files

Video: move sprite mirroring logic to base

  • Loading branch information...
1 parent fbb06c2 commit 8267f316ecd1040440e10582c5a1ca1ed7c75961 @bradallred bradallred committed Jun 30, 2013
Showing with 78 additions and 74 deletions.
  1. +75 −0 gemrb/core/Video.cpp
  2. +2 −2 gemrb/core/Video.h
  3. +0 −68 gemrb/plugins/SDLVideo/SDLVideo.cpp
  4. +1 −4 gemrb/plugins/SDLVideo/SDLVideo.h
View
75 gemrb/core/Video.cpp
@@ -68,6 +68,81 @@ void Video::SetEventMgr(EventMgr* evnt)
EvntManager = evnt;
}
+// Flips given sprite vertically (up-down). If MirrorAnchor=true,
+// flips its anchor (i.e. origin//base point) as well
+// returns new sprite
+Sprite2D* Video::MirrorSpriteVertical(const Sprite2D* sprite, bool MirrorAnchor)
+{
+ if (!sprite)
+ return NULL;
+
+ Sprite2D* dest = sprite->copy();
+
+ if (sprite->pixels != dest->pixels) {
+ assert(!sprite->BAM);
+ // if the sprite pixel buffers are not the same we need to manually mirror the pixels
+ for (int x = 0; x < dest->Width; x++) {
+ unsigned char * dst = ( unsigned char * ) dest->pixels + x;
+ unsigned char * src = dst + ( dest->Height - 1 ) * dest->Width;
+ for (int y = 0; y < dest->Height / 2; y++) {
+ unsigned char swp = *dst;
+ *dst = *src;
+ *src = swp;
+ dst += dest->Width;
+ src -= dest->Width;
+ }
+ }
+ } else {
+ // if the pixel buffers are the same then either there are no pixels (NULL)
+ // or the sprites support sharing pixel data and we only need to set a render flag on the copy
+ dest->renderFlags |= RENDER_FLIP_VERTICAL;
+ }
+
+ dest->XPos = sprite->XPos;
+ if (MirrorAnchor)
+ dest->YPos = sprite->Height - sprite->YPos;
+ else
+ dest->YPos = sprite->YPos;
+
+ return dest;
+}
+
+// Flips given sprite horizontally (left-right). If MirrorAnchor=true,
+// flips its anchor (i.e. origin//base point) as well
+Sprite2D* Video::MirrorSpriteHorizontal(const Sprite2D* sprite, bool MirrorAnchor)
+{
+ if (!sprite)
+ return NULL;
+
+ Sprite2D* dest = sprite->copy();
+
+ if (sprite->pixels != dest->pixels) {
+ assert(!sprite->BAM);
+ // if the sprite pixel buffers are not the same we need to manually mirror the pixels
+ for (int y = 0; y < dest->Height; y++) {
+ unsigned char * dst = (unsigned char *) dest->pixels + ( y * dest->Width );
+ unsigned char * src = dst + dest->Width - 1;
+ for (int x = 0; x < dest->Width / 2; x++) {
+ unsigned char swp=*dst;
+ *dst++ = *src;
+ *src-- = swp;
+ }
+ }
+ } else {
+ // if the pixel buffers are the same then either there are no pixels (NULL)
+ // or the sprites support sharing pixel data and we only need to set a render flag on the copy
+ dest->renderFlags |= RENDER_FLIP_HORIZONTAL;
+ }
+
+ if (MirrorAnchor)
+ dest->XPos = sprite->Width - sprite->XPos;
+ else
+ dest->XPos = sprite->XPos;
+ dest->YPos = sprite->YPos;
+
+ return dest;
+}
+
void Video::SetCursor(Sprite2D* cur, enum CursorType curIdx)
{
if (cur) {
View
4 gemrb/core/Video.h
@@ -176,9 +176,9 @@ class GEM_EXPORT Video : public Plugin {
/** Sets Event Manager */
void SetEventMgr(EventMgr* evnt);
/** Flips sprite vertically, returns new sprite */
- virtual Sprite2D *MirrorSpriteVertical(const Sprite2D *sprite, bool MirrorAnchor) = 0;
+ Sprite2D *MirrorSpriteVertical(const Sprite2D *sprite, bool MirrorAnchor);
/** Flips sprite horizontally, returns new sprite */
- virtual Sprite2D *MirrorSpriteHorizontal(const Sprite2D *sprite, bool MirrorAnchor) = 0;
+ Sprite2D *MirrorSpriteHorizontal(const Sprite2D *sprite, bool MirrorAnchor);
/** Duplicates and transforms sprite to have an alpha channel */
Sprite2D* CreateAlpha(const Sprite2D *sprite);
View
68 gemrb/plugins/SDLVideo/SDLVideo.cpp
@@ -1365,74 +1365,6 @@ void SDLVideoDriver::DrawPolyline(Gem_Polygon* poly, const Color& color, bool fi
return;
}
-// Flips given sprite vertically (up-down). If MirrorAnchor=true,
-// flips its anchor (i.e. origin//base point) as well
-// returns new sprite
-
-Sprite2D *SDLVideoDriver::MirrorSpriteVertical(const Sprite2D* sprite, bool MirrorAnchor)
-{
- if (!sprite)
- return NULL;
-
- Sprite2D* dest = sprite->copy();
-
- if (!sprite->BAM) {
- for (int x = 0; x < dest->Width; x++) {
- unsigned char * dst = ( unsigned char * ) dest->pixels + x;
- unsigned char * src = dst + ( dest->Height - 1 ) * dest->Width;
- for (int y = 0; y < dest->Height / 2; y++) {
- unsigned char swp = *dst;
- *dst = *src;
- *src = swp;
- dst += dest->Width;
- src -= dest->Width;
- }
- }
- } else {
- dest->renderFlags |= RENDER_FLIP_VERTICAL;
- }
-
- dest->XPos = sprite->XPos;
- if (MirrorAnchor)
- dest->YPos = sprite->Height - sprite->YPos;
- else
- dest->YPos = sprite->YPos;
-
- return dest;
-}
-
-// Flips given sprite horizontally (left-right). If MirrorAnchor=true,
-// flips its anchor (i.e. origin//base point) as well
-Sprite2D *SDLVideoDriver::MirrorSpriteHorizontal(const Sprite2D* sprite, bool MirrorAnchor)
-{
- if (!sprite)
- return NULL;
-
- Sprite2D* dest = sprite->copy();
-
- if (!sprite->BAM) {
- for (int y = 0; y < dest->Height; y++) {
- unsigned char * dst = (unsigned char *) dest->pixels + ( y * dest->Width );
- unsigned char * src = dst + dest->Width - 1;
- for (int x = 0; x < dest->Width / 2; x++) {
- unsigned char swp=*dst;
- *dst++ = *src;
- *src-- = swp;
- }
- }
- } else {
- dest->renderFlags |= RENDER_FLIP_HORIZONTAL;
- }
-
- if (MirrorAnchor)
- dest->XPos = sprite->Width - sprite->XPos;
- else
- dest->XPos = sprite->XPos;
- dest->YPos = sprite->YPos;
-
- return dest;
-}
-
void SDLVideoDriver::SetFadeColor(int r, int g, int b)
{
if (r>255) r=255;
View
5 gemrb/plugins/SDLVideo/SDLVideo.h
@@ -122,10 +122,7 @@ class SDLVideoDriver : public Video {
void DrawLine(short x1, short y1, short x2, short y2, const Color& color, bool clipped = false);
/** Blits a Sprite filling the Region */
void BlitTiled(Region rgn, const Sprite2D* img, bool anchor = false);
- /** Flips sprite vertically */
- Sprite2D *MirrorSpriteVertical(const Sprite2D *sprite, bool MirrorAnchor);
- /** Flips sprite horizontally */
- Sprite2D *MirrorSpriteHorizontal(const Sprite2D *sprite, bool MirrorAnchor);
+
/** Set Clip Rect */
void SetClipRect(const Region* clip);
/** Get Clip Rect */

0 comments on commit 8267f31

Please sign in to comment.