stratagus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-CVS] stratagus/src include/video.h unit/unittype.c v...


From: Nehal Mistry
Subject: [Stratagus-CVS] stratagus/src include/video.h unit/unittype.c v...
Date: Thu, 20 Nov 2003 01:43:43 -0500

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Nehal Mistry <address@hidden>   03/11/20 01:43:42

Modified files:
        src/include    : video.h 
        src/unit       : unittype.c 
        src/video      : graphic.c sprite.c 

Log message:
        can draw flipped graphics now

Patches:
Index: stratagus/src/include/video.h
diff -u stratagus/src/include/video.h:1.96 stratagus/src/include/video.h:1.97
--- stratagus/src/include/video.h:1.96  Mon Nov 17 14:14:33 2003
+++ stratagus/src/include/video.h       Thu Nov 20 01:43:41 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: video.h,v 1.96 2003/11/17 19:14:33 nehalmistry Exp $
+//     $Id: video.h,v 1.97 2003/11/20 06:43:41 nehalmistry Exp $
 
 #ifndef __VIDEO_H__
 #define __VIDEO_H__
@@ -246,6 +246,9 @@
     /// Load graphic
 extern Graphic* LoadGraphic(const char* file);
 
+    /// Flip graphic and store in graphic->SurfaceFlip
+extern void FlipGraphic(Graphic* graphic);
+
     /// New graphic
 extern Graphic* NewGraphic(unsigned d, int w, int h);
 
@@ -497,11 +500,15 @@
 extern void VideoDrawSubClip(const Graphic*, int ix, int iy, int w, 
     int h, int x, int y);
 
+    ///        Draw a graphic object unclipped and flipped in X direction.
+extern void VideoDrawX(const Graphic*, unsigned frame, int x, int y);
+
+    ///        Draw a graphic object clipped and flipped in X direction.
+extern void VideoDrawClipX(const Graphic*, unsigned frame, int x, int y);
+
 // FIXME FIXME FIXME: need to implement all of this
     ///        Draw a graphic object unclipped.
 //#define VideoDraw(o, f, x, y)        //((o)->Type->Draw)((o), (f), (x), (y))
-    ///        Draw a graphic object unclipped and flipped in X direction.
-#define VideoDrawX(o, f, x, y) //((o)->Type->DrawX)((o), (f), (x), (y))
     ///        Free a graphic object.
 #define VideoFree(o)   //((o)->Type->Free)((o))
     ///        Save (NULL) free a graphic object.
@@ -509,8 +516,6 @@
 //#define VideoDrawSub(a,b,c,d,e,f,g)
     ///        Draw a graphic object clipped to the current clipping.
 //#define VideoDrawSubClip(o, ix, iy, w, h, x, y)
-    ///        Draw a graphic object clipped and flipped in X direction.
-#define VideoDrawClipX(o, f, x, y)     //((o)->Type->DrawClipX)((o), (f), (x), 
(y))
     ///        Draw a shadow graphic object clipped to the current clipping.
 #define VideoDrawShadowClip(o, f, x, y)        
//((o)->Type->DrawShadowClip)((o),(f),(x),(y))
     ///        Draw a shadow graphic object clipped and flipped in X direction.
Index: stratagus/src/unit/unittype.c
diff -u stratagus/src/unit/unittype.c:1.127 stratagus/src/unit/unittype.c:1.128
--- stratagus/src/unit/unittype.c:1.127 Mon Nov 17 14:14:44 2003
+++ stratagus/src/unit/unittype.c       Thu Nov 20 01:43:42 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: unittype.c,v 1.127 2003/11/17 19:14:44 nehalmistry Exp $
+//     $Id: unittype.c,v 1.128 2003/11/20 06:43:42 nehalmistry Exp $
 
 //@{
 
@@ -1197,7 +1197,7 @@
     char** sp;
 
     CLprintf(file, "\n;;; -----------------------------------------\n");
-    CLprintf(file, ";;; MODULE: unittypes $Id: unittype.c,v 1.127 2003/11/17 
19:14:44 nehalmistry Exp $\n\n");
+    CLprintf(file, ";;; MODULE: unittypes $Id: unittype.c,v 1.128 2003/11/20 
06:43:42 nehalmistry Exp $\n\n");
 
     // Original number to internal unit-type name.
 
@@ -1371,6 +1371,7 @@
            ShowLoadProgress("Unit `%s'", file);
            type->ShadowSprite = LoadSprite(file, type->ShadowWidth,
                type->ShadowHeight);
+           FlipGraphic(type->ShadowSprite);
        }
 
        //  Load empty/loaded graphics
@@ -1382,12 +1383,14 @@
                        ShowLoadProgress("Unit `%s'", file);
                        resinfo->SpriteWhenLoaded = LoadSprite(file, 
type->Width,
                            type->Height);
+                       FlipGraphic(resinfo->SpriteWhenLoaded);
                    }
                    if ((file = resinfo->FileWhenEmpty)) {
                        file = strcat(strcpy(buf, "graphics/"), file);
                        ShowLoadProgress("Unit `%s'", file);
                        resinfo->SpriteWhenEmpty = LoadSprite(file, type->Width,
                            type->Height);
+                       FlipGraphic(resinfo->SpriteWhenEmpty);
                    }
                }
            }
@@ -1415,6 +1418,7 @@
            file = strcat(strcpy(buf, "graphics/"), file);
            ShowLoadProgress("Unit `%s'", file);
            type->Sprite = LoadSprite(file, type->Width, type->Height);
+           FlipGraphic(type->Sprite);
        }
     }
 
Index: stratagus/src/video/graphic.c
diff -u stratagus/src/video/graphic.c:1.49 stratagus/src/video/graphic.c:1.50
--- stratagus/src/video/graphic.c:1.49  Mon Nov 17 19:39:40 2003
+++ stratagus/src/video/graphic.c       Thu Nov 20 01:43:42 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: graphic.c,v 1.49 2003/11/18 00:39:40 nehalmistry Exp $
+//     $Id: graphic.c,v 1.50 2003/11/20 06:43:42 nehalmistry Exp $
 
 //@{
 
@@ -541,11 +541,10 @@
 #ifdef USE_SDL_SURFACE
     // FIXME: endian
 
-//    graphic->Surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 
depth, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
     graphic->Surface = SDL_CreateRGBSurfaceFrom(data, width, height, depth, 
width * depth / 8, 
-//     0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
        0, 0, 0, 0);
-//     depth * width);//, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
+
+    graphic->SurfaceFlip = NULL;
 
     graphic->NumFrames = 0;
 #else
@@ -563,6 +562,34 @@
 
     return graphic;
 }
+
+#ifdef USE_SDL_SURFACE
+/**
+**
+**     Flip graphic and store in graphic->SurfaceFlip
+**
+*/
+global void FlipGraphic(Graphic* graphic)
+{
+    int i;
+    int j;
+    SDL_Surface* s;
+
+    s = graphic->SurfaceFlip = SDL_ConvertSurface(graphic->Surface, 
+       graphic->Surface->format, SDL_SWSURFACE);
+
+    SDL_LockSurface(s);
+
+    for (i = 0; i < s->h; ++i) {
+       for (j = 0; j < s->w; ++j) {
+           ((char*)s->pixels)[j + i * s->w] = 
+               ((char*)graphic->Surface->pixels)[s->w - j + i * s->w];
+       }
+    }
+
+    SDL_UnlockSurface(s);
+}
+#endif
 
 /**
 **     Make a new graphic object.
Index: stratagus/src/video/sprite.c
diff -u stratagus/src/video/sprite.c:1.40 stratagus/src/video/sprite.c:1.41
--- stratagus/src/video/sprite.c:1.40   Mon Nov 17 15:39:10 2003
+++ stratagus/src/video/sprite.c        Thu Nov 20 01:43:42 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: sprite.c,v 1.40 2003/11/17 20:39:10 nehalmistry Exp $
+//     $Id: sprite.c,v 1.41 2003/11/20 06:43:42 nehalmistry Exp $
 
 //@{
 
@@ -244,18 +244,29 @@
 #endif
 
 #ifdef USE_SDL_SURFACE
-local void VideoDrawXFlip(const Graphic* sprite, unsigned frame, int x, int y)
+local void VideoDrawX(const Graphic* sprite, unsigned frame, int x, int y)
 {
+    SDL_Rect srect;
+    SDL_Rect drect;
 
-    int sbpp;
-    int dbpp;
+    DebugCheck(!sprite->SurfaceFlip);
 
-    sbpp = sprite->Surface->format->BytesPerPixel;
-    dbpp = TheScreen->format->BytesPerPixel;
+    srect.x = (sprite->SurfaceFlip->w - (frame % (sprite->SurfaceFlip->w / 
+           sprite->Width)) * sprite->Width) - sprite->Width;
+    srect.y = (frame / (sprite->SurfaceFlip->w / sprite->Width)) * 
sprite->Height;
+    srect.w = sprite->Width;
+    srect.h = sprite->Height;
 
+    drect.x = x;
+    drect.y = y;
+
+    SDL_BlitSurface(sprite->SurfaceFlip, &srect, TheScreen, &drect);
+}
 
-    // FIXME: todo
-//    SDL_BlitSurface(, &srect, temp, &drect);
+local void VideoDrawClipX(const Graphic* sprite, unsigned frame, int x, int y)
+{
+    // FIXME?
+    VideoDrawX(sprite, frame, x, y);
 }
 #else
 /**




reply via email to

[Prev in Thread] Current Thread [Next in Thread]