Thread: [Super-tux-commit] supertux/src leveleditor.cpp,1.100,1.101 menu.cpp,1.66,1.67 menu.h,1.59,1.60 text
Brought to you by:
wkendrick
From: Tobias Gl??er <to...@us...> - 2004-05-09 18:08:12
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1289/src Modified Files: leveleditor.cpp menu.cpp menu.h texture.cpp texture.h Log Message: Added a static member function to the Surface class for screen capturing. Redesigned the confirm dialog using it. Minor leveleditor improvements. (Asks if you want to save a changed level etc.) Index: menu.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/menu.cpp,v retrieving revision 1.66 retrieving revision 1.67 diff -u -d -r1.66 -r1.67 --- menu.cpp 7 May 2004 00:22:28 -0000 1.66 +++ menu.cpp 9 May 2004 18:08:01 -0000 1.67 @@ -1,5 +1,5 @@ // $Id$ -// +// // SuperTux // Copyright (C) 2004 Tobias Glaesser <tob...@gm...> // @@ -12,7 +12,7 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// [...1008 lines suppressed...] + y = event.motion.y; + if(x > pos_x - get_width()/2 && + x < pos_x + get_width()/2 && + y > pos_y - get_height()/2 && + y < pos_y + get_height()/2) + { + active_item = (y - (pos_y - get_height()/2)) / 24; + mouse_cursor->set_state(MC_LINK); + } + else + { + mouse_cursor->set_state(MC_NORMAL); + } + break; + default: + break; + } } Index: leveleditor.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.cpp,v retrieving revision 1.100 retrieving revision 1.101 diff -u -d -r1.100 -r1.101 --- leveleditor.cpp 9 May 2004 13:55:54 -0000 1.100 +++ leveleditor.cpp 9 May 2004 18:08:01 -0000 1.101 @@ -66,7 +66,7 @@ /* crutial ones (main loop) */ int le_init(); void le_quit(); -int le_load_level(char *filename); +int le_load_level_subset(char *filename); void le_drawlevel(); void le_drawinterface(); void le_checkevents(); @@ -75,7 +75,7 @@ void le_showhelp(); void le_set_defaults(void); void le_activate_bad_guys(void); - +void le_goto_level(int levelnb); void le_highlight_selection(); void apply_level_settings_menu(); @@ -169,7 +169,7 @@ {} if(filename != NULL) - if(le_load_level(filename)) + if(le_load_level_subset(filename)) return 1; while(true) @@ -294,7 +294,7 @@ default: if(i >= 1) { - if(le_load_level(level_subsets.item[i-1])) + if(le_load_level_subset(level_subsets.item[i-1])) return 1; } break; @@ -314,8 +314,7 @@ LevelSubset::create(subset_new_menu->get_item_by_id(MNID_SUBSETNAME).input); le_level_subset->load(subset_new_menu->get_item_by_id(MNID_SUBSETNAME).input); leveleditor_menu->get_item_by_id(MNID_SUBSETSETTINGS).kind = MN_GOTO; - delete le_world; - le_world = new World(le_level_subset->name,1); + le_goto_level(1); subset_new_menu->get_item_by_id(MNID_SUBSETNAME).change_input(""); Menu::set_current(subset_settings_menu); @@ -361,13 +360,12 @@ return done; } -int le_load_level(char *filename) +int le_load_level_subset(char *filename) { le_level_subset->load(filename); leveleditor_menu->get_item_by_id(MNID_SUBSETSETTINGS).kind = MN_GOTO; le_level = 1; - delete le_world; - le_world = new World(filename,le_level); + le_goto_level(1); //GameSession* session = new GameSession(datadir + "/levels/" + le_level_subset->name + "/level1.stl", 0, ST_GL_DEMO_GAME); @@ -666,20 +664,35 @@ le_level_subset->save(); } -void le_goto_level(int levelnb) +void le_unload_level() { + if(le_level_changed) + { + le_drawlevel(); + le_drawinterface(); + char str[1024]; + sprintf(str,"Save changes to level %d of %s?",le_level,le_level_subset->name.c_str()); + if(confirm_dialog(str)) + { + le_world->get_level()->save(le_level_subset->name.c_str(),le_level); + } + } + delete le_world; + le_level_changed = false; +} + +void le_goto_level(int levelnb) +{ + le_unload_level(); le_world = new World(le_level_subset->name, levelnb); } void le_quit(void) { - /*if(level_changed == true) - if(askforsaving() == CANCEL) - return;*/ //FIXME - SDL_EnableKeyRepeat(0, 0); // disables key repeating + le_unload_level(); delete le_selection; delete leveleditor_menu; delete subset_load_menu; @@ -777,19 +790,19 @@ { if(le_current.IsTile()) le_selection->draw( cursor_x - pos_x, cursor_y); - } - else if(le_selection_mode == SQUARE) - { - int w, h; - le_highlight_selection(); - /* draw current selection */ - w = selection.x2 - selection.x1; - h = selection.y2 - selection.y1; - fillrect(selection.x1 - pos_x, selection.y1, w, SELECT_W, SELECT_CLR); - fillrect(selection.x1 - pos_x + w, selection.y1, SELECT_W, h, SELECT_CLR); - fillrect(selection.x1 - pos_x, selection.y1 + h, w, SELECT_W, SELECT_CLR); - fillrect(selection.x1 - pos_x, selection.y1, SELECT_W, h, SELECT_CLR); - } + } + else if(le_selection_mode == SQUARE) + { + int w, h; + le_highlight_selection(); + /* draw current selection */ + w = selection.x2 - selection.x1; + h = selection.y2 - selection.y1; + fillrect(selection.x1 - pos_x, selection.y1, w, SELECT_W, SELECT_CLR); + fillrect(selection.x1 - pos_x + w, selection.y1, SELECT_W, h, SELECT_CLR); + fillrect(selection.x1 - pos_x, selection.y1 + h, w, SELECT_W, SELECT_CLR); + fillrect(selection.x1 - pos_x, selection.y1, SELECT_W, h, SELECT_CLR); + } /* draw button bar */ @@ -961,7 +974,7 @@ { Menu::current()->event(event); if(!le_world && !Menu::current()) - Menu::set_current(leveleditor_menu); + Menu::set_current(leveleditor_menu); } else { @@ -982,7 +995,7 @@ { case SDLK_ESCAPE: Menu::set_current(leveleditor_menu); - break; + break; case SDLK_LEFT: if(fire == DOWN) cursor_x -= KEY_CURSOR_SPEED; @@ -1341,6 +1354,7 @@ { if(le_current.IsObject()) { + le_level_changed = true; std::string type = le_current.obj->type(); if(type == "BadGuy") { @@ -1440,8 +1454,8 @@ int x1, x2, y1, y2; unsigned int i = 0; - /* level_changed = true; */ - + le_level_changed = true; + switch(le_selection_mode) { case CURSOR: Index: menu.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/menu.h,v retrieving revision 1.59 retrieving revision 1.60 diff -u -d -r1.59 -r1.60 --- menu.h 6 May 2004 15:09:47 -0000 1.59 +++ menu.h 9 May 2004 18:08:02 -0000 1.60 @@ -92,7 +92,7 @@ MNID_APPLY }; -bool confirm_dialog(char *text); +bool confirm_dialog(std::string text); /* Kinds of menu items */ enum MenuItemKind { Index: texture.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/texture.h,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- texture.h 5 May 2004 22:04:48 -0000 1.22 +++ texture.h 9 May 2004 18:08:02 -0000 1.23 @@ -30,6 +30,8 @@ #include <list> #include "screen.h" +SDL_Surface* sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, int use_alpha); + class SurfaceImpl; class SurfaceSDL; class SurfaceOpenGL; @@ -79,6 +81,9 @@ Surface(const std::string& file, int x, int y, int w, int h, int use_alpha); ~Surface(); + /** Captures the screen and returns it as Surface*, the user is expected to call the destructor. */ + static Surface* CaptureScreen(); + /** Reload the surface, which is necesarry in case of a mode swich */ void reload(); Index: texture.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/texture.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- texture.cpp 9 May 2004 13:49:14 -0000 1.24 +++ texture.cpp 9 May 2004 18:08:02 -0000 1.25 @@ -251,13 +251,60 @@ { if (impl) { - w = w_; - h = h_; + w = w_; + h = h_; if (impl->resize(w_,h_) == -2) reload(); } } +Surface* Surface::CaptureScreen() +{ + Surface *cap_screen; + + if (!(screen->flags & SDL_OPENGL)) + { + cap_screen = new Surface(SDL_GetVideoSurface(),false); + } + +#ifndef NOOPENGL + if (use_gl) + { + SDL_Surface *temp; + unsigned char *pixels; + int i; + temp = SDL_CreateRGBSurface(SDL_SWSURFACE, screen->w, screen->h, 24, +#if SDL_BYTEORDER == SDL_LIL_ENDIAN + 0x000000FF, 0x0000FF00, 0x00FF0000, 0 +#else + 0x00FF0000, 0x0000FF00, 0x000000FF, 0 +#endif + ); + if (temp == NULL) + st_abort("Error while trying to capture the screen in OpenGL mode",""); + + pixels = (unsigned char*) malloc(3 * screen->w * screen->h); + if (pixels == NULL) + { + SDL_FreeSurface(temp); + st_abort("Error while trying to capture the screen in OpenGL mode",""); + } + + glReadPixels(0, 0, screen->w, screen->h, GL_RGB, GL_UNSIGNED_BYTE, pixels); + + for (i=0; i<screen->h; i++) + memcpy(((char *) temp->pixels) + temp->pitch * i, pixels + 3*screen->w * (screen->h-i-1), screen->w*3); + free(pixels); + + cap_screen = new Surface(temp,false); + SDL_FreeSurface(temp); + + } +#endif + +return cap_screen; +} + SDL_Surface* sdl_surface_part_from_file(const std::string& file, int x, int y, int w, int h, int use_alpha) { @@ -400,7 +447,7 @@ dest.w = w; dest.h = h; int ret = SDL_SoftStretch(sdl_surface, NULL, - sdl_surface, &dest); + sdl_surface, &dest); return ret; } @@ -789,7 +836,7 @@ SurfaceSDL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, bool update) { SDL_Rect dest; - + dest.x = (int)x; dest.y = (int)y; dest.w = (int)sw; @@ -797,15 +844,15 @@ if(alpha != 255) SDL_SetAlpha(sdl_surface ,SDL_SRCALPHA,alpha); - - - SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags, - sw, sh, sdl_surface->format->BitsPerPixel, - sdl_surface->format->Rmask, sdl_surface->format->Gmask, - sdl_surface->format->Bmask, - 0); - SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL); + + SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags, + sw, sh, sdl_surface->format->BitsPerPixel, + sdl_surface->format->Rmask, sdl_surface->format->Gmask, + sdl_surface->format->Bmask, + 0); + + SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL); SDL_SoftStretch(sdl_surface_copy, NULL, sdl_surface_copy, &dest); int ret = SDL_BlitSurface(sdl_surface_copy,NULL,screen,&dest); |