r167 - trunk/src

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sun Sep 11 11:54:08 EDT 2005


Author: jonas
Date: 2005-09-11 11:54:08 -0400 (Sun, 11 Sep 2005)
New Revision: 167

Modified:
   trunk/src/common.cpp
   trunk/src/common.h
   trunk/src/editor.cpp
   trunk/src/editor.h
   trunk/src/gfxeng.cpp
   trunk/src/gfxeng.h
Log:
move mask and vflags global variables to gfxeng again, added create*Surface functions in gfxeng, added support for a highlight mask surface

Modified: trunk/src/common.cpp
===================================================================
--- trunk/src/common.cpp	2005-09-11 11:22:42 UTC (rev 166)
+++ trunk/src/common.cpp	2005-09-11 15:54:08 UTC (rev 167)
@@ -15,18 +15,6 @@
 Menu* menu=NULL;
 Box* box=NULL;
 Editor* editor=NULL;
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-const Uint32 rmask=0xff000000;
-const Uint32 gmask=0x00ff0000;
-const Uint32 bmask=0x0000ff00;
-const Uint32 amask=0x000000ff;
-#else
-const Uint32 rmask=0x000000ff;
-const Uint32 gmask=0x0000ff00;
-const Uint32 bmask=0x00ff0000;
-const Uint32 amask=0xff000000;
-#endif
-Uint32 vflags=SDL_HWSURFACE|SDL_RESIZABLE|SDL_DOUBLEBUF|SDL_HWACCEL;
 
 string itos(int i) {
     std::stringstream s;

Modified: trunk/src/common.h
===================================================================
--- trunk/src/common.h	2005-09-11 11:22:42 UTC (rev 166)
+++ trunk/src/common.h	2005-09-11 15:54:08 UTC (rev 167)
@@ -255,12 +255,6 @@
 
 //global variables
 //@{
-/// masks
-extern const Uint32 rmask;
-extern const Uint32 gmask;
-extern const Uint32 bmask;
-extern const Uint32 amask;
-extern Uint32 vflags;
 /// Game configuration
 extern Config config;
 /// Image Cache

Modified: trunk/src/editor.cpp
===================================================================
--- trunk/src/editor.cpp	2005-09-11 11:22:42 UTC (rev 166)
+++ trunk/src/editor.cpp	2005-09-11 15:54:08 UTC (rev 167)
@@ -14,12 +14,21 @@
     string place_name="";
     save_name="newmap.cfg";
     box=NULL;
+    mask_surface=NULL;
+    reinit();
 }
 
 Editor::~Editor() {
     closeBox();
 }
 
+void Editor::reinit() {
+    if (mask_surface) SDL_FreeSurface(mask_surface);
+    mask_surface=gfxeng->createRGBAScreenSurface();
+    SDL_FillRect(mask_surface,0,SDL_MapRGBA(mask_surface->format,100,0,0,100));
+    if (box) box->update();
+}
+
 void Editor::updateSelection(Sint16 x, Sint16 y) {
     if (!select_start) return;
     select_rect.w=abs(x-select_start_x);
@@ -219,9 +228,7 @@
     getArea();
 
     if (surface!=NULL) SDL_FreeSurface(surface);
-    SDL_Surface* tmp=SDL_CreateRGBSurface(vflags, area.w, area.h, 32, rmask, gmask, bmask, amask);
-    surface=SDL_DisplayFormatAlpha(tmp);
-    SDL_FreeSurface(tmp);
+    surface=gfxeng->createRGBASurface(area.w, area.h);
 
     SDL_FillRect(surface,0,SDL_MapRGBA(surface->format,200,200,200,180));
     /* create a border */

Modified: trunk/src/editor.h
===================================================================
--- trunk/src/editor.h	2005-09-11 11:22:42 UTC (rev 166)
+++ trunk/src/editor.h	2005-09-11 15:54:08 UTC (rev 167)
@@ -133,6 +133,7 @@
     public:
         Editor();
         ~Editor();
+        void reinit();
         void run_action(Uint32 action, Uint16 x=0, Uint16 y=0);
         Uint32 getActionMPressed(Uint8 button) {
             if (button>=1 && button <6) return action_mouse_pressed[button];
@@ -173,6 +174,7 @@
         SDL_Rect select_rect;
         Sint16 select_start_x;
         Sint16 select_start_y;
+        SDL_Surface* mask_surface;
     private:
         void updateSelection(Sint16 x, Sint16 y);
 };

Modified: trunk/src/gfxeng.cpp
===================================================================
--- trunk/src/gfxeng.cpp	2005-09-11 11:22:42 UTC (rev 166)
+++ trunk/src/gfxeng.cpp	2005-09-11 15:54:08 UTC (rev 167)
@@ -14,12 +14,24 @@
 
 
 GraphicsEngine::GraphicsEngine():
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+  rmask(0xff000000),
+  gmask(0x00ff0000),
+  bmask(0x0000ff00),
+  amask(0x000000ff),
+#else
+  rmask(0x000000ff),
+  gmask(0x0000ff00),
+  bmask(0x00ff0000),
+  amask(0xff000000),
+#endif
   screen(NULL),
   menubg(NULL),
   show_bar(true),
   show_fps(true),
   show_debug(false),
   fullscreen(config.full) {
+    vflags=SDL_HWSURFACE|SDL_RESIZABLE|SDL_DOUBLEBUF|SDL_HWACCEL;
     updatetype=UPDATE_ALL;
     shift.x=0;
     shift.y=0;
@@ -106,6 +118,7 @@
     vis_map.w=screen->w;
     vis_map.h=screen->h-bar.h;
     update(UPDATE_ALL);
+    if (editor && game_mode&GAME_EDIT) editor->reinit();
 }
 
 inline SDL_Rect GraphicsEngine::clipToBG(SDL_Rect dest) const {
@@ -161,6 +174,7 @@
     while (obit!=scenario->pool->objectspool.end()) {
         tmprect=((*obit)->getDrawPos());
         srcpos=(*obit)->getFrame().pos;
+        SDL_BlitSurface((*obit)->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift));
         if (show_debug) {
             debugrect=*(*obit)->getPos();
             drawRectangle(debugrect,1,SDL_MapRGB(screen->format,100,20,0));
@@ -168,11 +182,17 @@
         // TODO: fix this gfxeng mess
         if (editor && game_mode&GAME_EDIT) {
             if (editor->selection.find((*obit)->getName())!=editor->selection.end()) {
-                debugrect=*(*obit)->getPos();
-                drawRectangle(debugrect,3,SDL_MapRGB(screen->format,100,100,0));
+                if (editor->mask_surface) {
+                    debugrect=*(*obit)->getPos();
+                    SDL_Rect area=debugrect;
+                    area.x=area.y=0;
+                    SDL_BlitSurface(editor->mask_surface,&area,screen,shiftMapArea(debugrect,shift));
+                } else {
+                    debugrect=*(*obit)->getPos();
+                    drawRectangle(debugrect,3,SDL_MapRGB(screen->format,100,100,0));
+                }
             }
         }
-        SDL_BlitSurface((*obit)->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift));
         ++obit;
     }
     // TODO: fix this gfxeng mess
@@ -461,3 +481,21 @@
     /* vertical right */
     SDL_FillRect(screen,&rect,color);
 }
+
+SDL_Surface* GraphicsEngine::createRGBSurface(Uint16 width, Uint16 height) {
+    SDL_Surface* tmp_surface=SDL_CreateRGBSurface(vflags, width, height, 32, rmask, gmask, bmask, 0);
+    SDL_Surface* return_surface=SDL_DisplayFormat(tmp_surface);
+    SDL_FreeSurface(tmp_surface);
+    return return_surface;
+}
+
+SDL_Surface* GraphicsEngine::createRGBASurface(Uint16 width, Uint16 height) {
+    SDL_Surface* tmp_surface=SDL_CreateRGBSurface(vflags, width, height, 32, rmask, gmask, bmask, amask);
+    SDL_Surface* return_surface=SDL_DisplayFormatAlpha(tmp_surface);
+    SDL_FreeSurface(tmp_surface);
+    return return_surface;
+}
+
+SDL_Surface* GraphicsEngine::createRGBAScreenSurface() {
+    return createRGBASurface(screen->w, screen->h);
+}

Modified: trunk/src/gfxeng.h
===================================================================
--- trunk/src/gfxeng.h	2005-09-11 11:22:42 UTC (rev 166)
+++ trunk/src/gfxeng.h	2005-09-11 15:54:08 UTC (rev 167)
@@ -42,7 +42,17 @@
             shift.x=shift.y=0;
         }
         void drawRectangle(SDL_Rect rect, Uint8 border=1, Uint32 color=0);
+        SDL_Surface* createRGBSurface(Uint16 width, Uint16 height);
+        SDL_Surface* createRGBASurface(Uint16 width, Uint16 height);
+        SDL_Surface* createRGBAScreenSurface();
     protected:
+        /// masks
+        const Uint32 rmask;
+        const Uint32 gmask;
+        const Uint32 bmask;
+        const Uint32 amask;
+        /// Video flags
+        Uint32 vflags;
         /// main screen
         SDL_Surface* screen;
         /// currently visible part of the map area




More information about the lostpenguins-commits mailing list