From 6a4603ff2786ecf6cc4b0219f85698bcfff3448a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20Gl=C3=A4=C3=9Fer?= Date: Mon, 3 May 2004 20:35:59 +0000 Subject: [PATCH] more leveleditor related improvements SVN-Revision: 959 --- src/button.cpp | 207 +++++++++++++++++++-------------------- src/leveleditor.cpp | 57 ++++++----- src/texture.cpp | 273 ++++++++++++++++++++++++++++------------------------ src/texture.h | 2 + src/tile.cpp | 8 +- src/tile.h | 3 +- 6 files changed, 289 insertions(+), 261 deletions(-) diff --git a/src/button.cpp b/src/button.cpp index 03fa0c932..3fcfc702d 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -1,5 +1,5 @@ // $Id$ -// +// // SuperTux // Copyright (C) 2004 Tobias Glaesser // @@ -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. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA @@ -34,32 +34,21 @@ Button::Button(std::string icon_file, std::string ninfo, SDLKey nshortcut, int x char filename[1024]; if(!icon_file.empty()) - { - snprintf(filename, 1024, "%s/%s", datadir.c_str(), icon_file.c_str()); - if(!faccessible(filename)) - snprintf(filename, 1024, "%s/images/icons/default-icon.png", datadir.c_str()); - } - else - { + { + snprintf(filename, 1024, "%s/%s", datadir.c_str(), icon_file.c_str()); + if(!faccessible(filename)) snprintf(filename, 1024, "%s/images/icons/default-icon.png", datadir.c_str()); - } + } + else + { + snprintf(filename, 1024, "%s/images/icons/default-icon.png", datadir.c_str()); + } if(mw != -1 || mh != -1) - { - icon = new Surface(filename,USE_ALPHA); - if(mw != -1) - icon->w = mw; - if(mh != -1) - icon->h = mh; - - SDL_Rect dest; - dest.x = 0; - dest.y = 0; - dest.w = icon->w; - dest.h = icon->h; - SDL_SoftStretch(icon->impl->get_sdl_surface(), NULL, - icon->impl->get_sdl_surface(), &dest); - } + { + icon = new Surface(filename,USE_ALPHA); + icon->resize(mw,mh); + } else icon = new Surface(filename,USE_ALPHA); @@ -83,15 +72,15 @@ void Button::change_icon(std::string icon_file, int /*mw*/, int /*mh*/) char filename[1024]; if(!icon_file.empty()) - { - snprintf(filename, 1024, "%s/%s", datadir.c_str(), icon_file.c_str()); - if(!faccessible(filename)) - snprintf(filename, 1024, "%s/images/icons/default-icon.png", datadir.c_str()); - } - else - { + { + snprintf(filename, 1024, "%s/%s", datadir.c_str(), icon_file.c_str()); + if(!faccessible(filename)) snprintf(filename, 1024, "%s/images/icons/default-icon.png", datadir.c_str()); - } + } + else + { + snprintf(filename, 1024, "%s/images/icons/default-icon.png", datadir.c_str()); + } delete icon; icon = new Surface(filename,USE_ALPHA); @@ -101,33 +90,33 @@ void Button::draw() { if(state == BUTTON_HOVER) if(!popup_timer.check()) - show_info = true; + show_info = true; fillrect(rect.x,rect.y,rect.w,rect.h,75,75,75,200); fillrect(rect.x+1,rect.y+1,rect.w-2,rect.h-2,175,175,175,200); if(bkgd != NULL) - { - bkgd->draw(rect.x,rect.y); - } + { + bkgd->draw(rect.x,rect.y); + } icon->draw(rect.x,rect.y); if(game_object != NULL) { - game_object->draw(); + game_object->draw(); } - + if(show_info) - { - char str[80]; - int i = -32; + { + char str[80]; + int i = -32; - if(0 > rect.x - (int)strlen(info.c_str()) * white_small_text->w) - i = rect.w + strlen(info.c_str()) * white_small_text->w; + if(0 > rect.x - (int)strlen(info.c_str()) * white_small_text->w) + i = rect.w + strlen(info.c_str()) * white_small_text->w; - if(!info.empty()) - white_small_text->draw(info.c_str(), i + rect.x - strlen(info.c_str()) * white_small_text->w, rect.y, 1); - sprintf(str,"(%s)", SDL_GetKeyName(shortcut)); - white_small_text->draw(str, i + rect.x - strlen(str) * white_small_text->w, rect.y + white_small_text->h+2, 1); - } + if(!info.empty()) + white_small_text->draw(info.c_str(), i + rect.x - strlen(info.c_str()) * white_small_text->w, rect.y, 1); + sprintf(str,"(%s)", SDL_GetKeyName(shortcut)); + white_small_text->draw(str, i + rect.x - strlen(str) * white_small_text->w, rect.y + white_small_text->h+2, 1); + } if(state == BUTTON_PRESSED) fillrect(rect.x,rect.y,rect.w,rect.h,75,75,75,200); else if(state == BUTTON_HOVER) @@ -145,65 +134,65 @@ void Button::event(SDL_Event &event) SDLKey key = event.key.keysym.sym; if(event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP) + { + if(event.button.x < rect.x || event.button.x >= rect.x + rect.w || + event.button.y < rect.y || event.button.y >= rect.y + rect.h) + return; + + if(event.button.button != SDL_BUTTON_LEFT) { - if(event.button.x < rect.x || event.button.x >= rect.x + rect.w || - event.button.y < rect.y || event.button.y >= rect.y + rect.h) - return; - - if(event.button.button != SDL_BUTTON_LEFT) - { - show_info = true; - return; - } - - if(event.type == SDL_MOUSEBUTTONDOWN) - state = BUTTON_PRESSED; - else - state = BUTTON_CLICKED; + show_info = true; + return; } + + if(event.type == SDL_MOUSEBUTTONDOWN) + state = BUTTON_PRESSED; + else + state = BUTTON_CLICKED; + } else if(event.type == SDL_MOUSEMOTION) + { + if(event.motion.x < rect.x || event.motion.x >= rect.x + rect.w || + event.motion.y < rect.y || event.motion.y >= rect.y + rect.h) + state = BUTTON_NONE; + else + state = BUTTON_HOVER; + + popup_timer.start(1500); + if(show_info) { - if(event.motion.x < rect.x || event.motion.x >= rect.x + rect.w || - event.motion.y < rect.y || event.motion.y >= rect.y + rect.h) - state = BUTTON_NONE; - else - state = BUTTON_HOVER; - - popup_timer.start(1500); - if(show_info) - { - show_info = false; - } + show_info = false; } + } else if(event.type == SDL_KEYDOWN) - { - if(key == shortcut) - state = BUTTON_PRESSED; - } + { + if(key == shortcut) + state = BUTTON_PRESSED; + } else if(event.type == SDL_KEYUP) - { - if(state == BUTTON_PRESSED && key == shortcut) - state = BUTTON_CLICKED; - } + { + if(state == BUTTON_PRESSED && key == shortcut) + state = BUTTON_CLICKED; + } } int Button::get_state() { int rstate; if(state == BUTTON_CLICKED) - { - rstate = state; - state = BUTTON_NONE; - return rstate; - } + { + rstate = state; + state = BUTTON_NONE; + return rstate; + } else - { - return state; - } + { + return state; + } } ButtonPanel::ButtonPanel(int x, int y, int w, int h) -{ +{ bw = 32; bh = 32; rect.x = x; @@ -216,27 +205,27 @@ ButtonPanel::ButtonPanel(int x, int y, int w, int h) Button* ButtonPanel::event(SDL_Event& event) { if(!hidden) + { + for(std::vector::iterator it = item.begin(); it != item.end(); ++it) { - for(std::vector::iterator it = item.begin(); it != item.end(); ++it) - { - (*it)->event(event); - if((*it)->state != BUTTON_NONE) - return (*it); - } - return NULL; + (*it)->event(event); + if((*it)->state != BUTTON_NONE) + return (*it); } + return NULL; + } else - { - return NULL; - } + { + return NULL; + } } ButtonPanel::~ButtonPanel() { for(std::vector::iterator it = item.begin(); it != item.end(); ++it) - { - delete (*it); - } + { + delete (*it); + } item.clear(); } @@ -244,13 +233,13 @@ void ButtonPanel::draw() { if(hidden == false) + { + fillrect(rect.x,rect.y,rect.w,rect.h,100,100,100,200); + for(std::vector::iterator it = item.begin(); it != item.end(); ++it) { - fillrect(rect.x,rect.y,rect.w,rect.h,100,100,100,200); - for(std::vector::iterator it = item.begin(); it != item.end(); ++it) - { - (*it)->draw(); - } + (*it)->draw(); } + } } void ButtonPanel::additem(Button* pbutton, int tag) diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index 0b147ceee..314a5f09c 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -367,7 +367,7 @@ int leveleditor(int levelnb) le_current_level->load_gfx(); le_world.activate_bad_guys(); subset_new_menu->get_item_by_id(MNID_SUBSETNAME).change_input(""); - + Menu::set_current(subset_settings_menu); break; } @@ -498,7 +498,18 @@ void le_init_menus() sit != (*it).tiles.end(); ++sit, ++i) { std::string imagefile = "/images/tilesets/" ; - imagefile += TileManager::instance()->get(*sit)->filenames[0]; + if(!TileManager::instance()->get(*sit)->filenames.empty()) + { + imagefile += TileManager::instance()->get(*sit)->filenames[0]; + } + else if(!TileManager::instance()->get(*sit)->editor_filenames.empty()) + { + imagefile += TileManager::instance()->get(*sit)->editor_filenames[0]; + } + else + { + imagefile += "notile.png"; + } Button* button = new Button(imagefile, it->name, SDLKey(SDLK_a + i), 0, 0, 32, 32); tilegroups_map[it->name]->additem(button, *sit); @@ -580,20 +591,20 @@ void update_level_settings_menu() { char str[80]; int i; - + level_settings_menu->get_item_by_id(MNID_NAME).change_input(le_current_level->name.c_str()); level_settings_menu->get_item_by_id(MNID_AUTHOR).change_input(le_current_level->author.c_str()); - + string_list_copy(level_settings_menu->get_item_by_id(MNID_SONG).list, dfiles("music/",NULL, "-fast")); string_list_copy(level_settings_menu->get_item_by_id(MNID_BGIMG).list, dfiles("images/background",NULL, NULL)); string_list_add_item(level_settings_menu->get_item_by_id(MNID_BGIMG).list,""); - + if((i = string_list_find(level_settings_menu->get_item_by_id(MNID_SONG).list,le_current_level->song_title.c_str())) != -1) level_settings_menu->get_item_by_id(MNID_SONG).list->active_item = i; if((i = string_list_find(level_settings_menu->get_item_by_id(MNID_BGIMG).list,le_current_level->bkgd_image.c_str())) != -1) level_settings_menu->get_item_by_id(MNID_BGIMG).list->active_item = i; - - sprintf(str,"%d",le_current_level->width); + + sprintf(str,"%d",le_current_level->width); level_settings_menu->get_item_by_id(MNID_LENGTH).change_input(str); sprintf(str,"%d",le_current_level->time_left); level_settings_menu->get_item_by_id(MNID_TIME).change_input(str); @@ -769,7 +780,7 @@ void le_drawinterface() if(TileManager::instance()->get(le_current.tile)->editor_images.size() > 0) TileManager::instance()->get(le_current.tile)->editor_images[0]->draw( 19 * 32, 14 * 32); } - + //if(le_current.IsObject()) //printf(""); @@ -1013,16 +1024,16 @@ void le_checkevents() x = event.motion.x; y = event.motion.y; - if(le_current.IsTile()) - { - cursor_x = ((int)(pos_x + x) / 32) * 32; - cursor_y = ((int) y / 32) * 32; - } - else - { - cursor_x = x; - cursor_y = y; - } + if(le_current.IsTile()) + { + cursor_x = ((int)(pos_x + x) / 32) * 32; + cursor_y = ((int) y / 32) * 32; + } + else + { + cursor_x = x; + cursor_y = y; + } if(le_mouse_pressed[LEFT]) { @@ -1192,9 +1203,9 @@ void le_checkevents() if(type == "BadGuy") { BadGuy* pbadguy = dynamic_cast(le_current.obj); - + le_world.bad_guys.push_back(BadGuy(cursor_x, cursor_y,pbadguy->kind,false)); - le_current_level->badguy_data.push_back(&le_world.bad_guys.back()); + le_current_level->badguy_data.push_back(&le_world.bad_guys.back()); } } } @@ -1281,10 +1292,10 @@ void le_change(float x, float y, int tm, unsigned int c) /* if there is a bad guy over there, remove it */ for(i = 0; i < le_world.bad_guys.size(); ++i) if(rectcollision(cursor_base,le_world.bad_guys[i].base)) - { + { le_world.bad_guys.erase(le_world.bad_guys.begin() + i); - le_current_level->badguy_data.erase(le_current_level->badguy_data.begin() + i); - } + le_current_level->badguy_data.erase(le_current_level->badguy_data.begin() + i); + } break; case SQUARE: diff --git a/src/texture.cpp b/src/texture.cpp index a62b60f07..3aafe0efa 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -1,5 +1,5 @@ // $Id$ -// +// // SuperTux // Copyright (C) 2004 Tobias Glaesser // @@ -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. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA @@ -30,7 +30,7 @@ Surface::Surfaces Surface::surfaces; SurfaceData::SurfaceData(SDL_Surface* temp, int use_alpha_) - : type(SURFACE), surface(0), use_alpha(use_alpha_) + : type(SURFACE), surface(0), use_alpha(use_alpha_) { // Copy the given surface and make sure that it is not stored in // video memory @@ -48,19 +48,17 @@ SurfaceData::SurfaceData(SDL_Surface* temp, int use_alpha_) } SurfaceData::SurfaceData(const std::string& file_, int use_alpha_) - : type(LOAD), surface(0), file(file_), use_alpha(use_alpha_) -{ -} - + : type(LOAD), surface(0), file(file_), use_alpha(use_alpha_) +{} + SurfaceData::SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, int use_alpha_) - : type(LOAD_PART), surface(0), file(file_), use_alpha(use_alpha_), + : type(LOAD_PART), surface(0), file(file_), use_alpha(use_alpha_), x(x_), y(y_), w(w_), h(h_) -{ -} +{} SurfaceData::~SurfaceData() { - SDL_FreeSurface(surface); + SDL_FreeSurface(surface); } SurfaceImpl* @@ -80,14 +78,14 @@ SurfaceSDL* SurfaceData::create_SurfaceSDL() { switch(type) - { - case LOAD: - return new SurfaceSDL(file, use_alpha); - case LOAD_PART: - return new SurfaceSDL(file, x, y, w, h, use_alpha); - case SURFACE: - return new SurfaceSDL(surface, use_alpha); - } + { + case LOAD: + return new SurfaceSDL(file, use_alpha); + case LOAD_PART: + return new SurfaceSDL(file, x, y, w, h, use_alpha); + case SURFACE: + return new SurfaceSDL(surface, use_alpha); + } assert(0); } @@ -96,14 +94,14 @@ SurfaceData::create_SurfaceOpenGL() { #ifndef NOOPENGL switch(type) - { - case LOAD: - return new SurfaceOpenGL(file, use_alpha); - case LOAD_PART: - return new SurfaceOpenGL(file, x, y, w, h, use_alpha); - case SURFACE: - return new SurfaceOpenGL(surface, use_alpha); - } + { + case LOAD: + return new SurfaceOpenGL(file, use_alpha); + case LOAD_PART: + return new SurfaceOpenGL(file, x, y, w, h, use_alpha); + case SURFACE: + return new SurfaceOpenGL(surface, use_alpha); + } #endif assert(0); } @@ -114,7 +112,8 @@ static int power_of_two(int input) { int value = 1; - while ( value < input ) { + while ( value < input ) + { value <<= 1; } return value; @@ -122,38 +121,38 @@ static int power_of_two(int input) #endif Surface::Surface(SDL_Surface* surf, int use_alpha) - : data(surf, use_alpha), w(0), h(0) + : data(surf, use_alpha), w(0), h(0) { impl = data.create(); - if (impl) - { - w = impl->w; - h = impl->h; - } + if (impl) + { + w = impl->w; + h = impl->h; + } surfaces.push_back(this); } Surface::Surface(const std::string& file, int use_alpha) - : data(file, use_alpha), w(0), h(0) + : data(file, use_alpha), w(0), h(0) { impl = data.create(); - if (impl) - { - w = impl->w; - h = impl->h; - } + if (impl) + { + w = impl->w; + h = impl->h; + } surfaces.push_back(this); } Surface::Surface(const std::string& file, int x, int y, int w, int h, int use_alpha) - : data(file, x, y, w, h, use_alpha), w(0), h(0) + : data(file, x, y, w, h, use_alpha), w(0), h(0) { impl = data.create(); - if (impl) - { - w = impl->w; - h = impl->h; - } + if (impl) + { + w = impl->w; + h = impl->h; + } surfaces.push_back(this); } @@ -162,11 +161,11 @@ Surface::reload() { delete impl; impl = data.create(); - if (impl) - { - w = impl->w; - h = impl->h; - } + if (impl) + { + w = impl->w; + h = impl->h; + } } Surface::~Surface() @@ -174,10 +173,12 @@ Surface::~Surface() #ifdef DEBUG bool found = false; for(std::list::iterator i = surfaces.begin(); i != surfaces.end(); - ++i) { - if(*i == this) { - found = true; break; - } + ++i) + { + if(*i == this) + { + found = true; break; + } } if(!found) printf("Error: Surface freed twice!!!\n"); @@ -190,49 +191,61 @@ void Surface::reload_all() { for(Surfaces::iterator i = surfaces.begin(); i != surfaces.end(); ++i) - { - (*i)->reload(); - } + { + (*i)->reload(); + } } void Surface::debug_check() { for(Surfaces::iterator i = surfaces.begin(); i != surfaces.end(); ++i) - { - printf("Surface not freed: T:%d F:%s.\n", (*i)->data.type, - (*i)->data.file.c_str()); - } + { + printf("Surface not freed: T:%d F:%s.\n", (*i)->data.type, + (*i)->data.file.c_str()); + } } void Surface::draw(float x, float y, Uint8 alpha, bool update) { - if (impl) - { - if (impl->draw(x, y, alpha, update) == -2) - reload(); - } + if (impl) + { + if (impl->draw(x, y, alpha, update) == -2) + reload(); + } } void Surface::draw_bg(Uint8 alpha, bool update) { if (impl) - { - if (impl->draw_bg(alpha, update) == -2) - reload(); - } + { + if (impl->draw_bg(alpha, update) == -2) + reload(); + } } void Surface::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) { if (impl) - { - if (impl->draw_part(sx, sy, x, y, w, h, alpha, update) == -2) - reload(); - } + { + if (impl->draw_part(sx, sy, x, y, w, h, alpha, update) == -2) + reload(); + } +} + +void +Surface::resize(int w_, int h_) +{ + if (impl) + { + w = w_; + h = h_; + if (impl->resize(w_,h_) == -2) + reload(); + } } SDL_Surface* @@ -284,7 +297,7 @@ sdl_surface_part_from_file(const std::string& file, int x, int y, int w, int h, SDL_FreeSurface(temp); SDL_FreeSurface(conv); - + return sdl_surface; } @@ -293,7 +306,7 @@ sdl_surface_from_file(const std::string& file, int use_alpha) { SDL_Surface* sdl_surface; SDL_Surface* temp; - + temp = IMG_Load(file.c_str()); if (temp == NULL) @@ -303,7 +316,7 @@ sdl_surface_from_file(const std::string& file, int use_alpha) sdl_surface = SDL_DisplayFormat(temp); else sdl_surface = SDL_DisplayFormatAlpha(temp); - + if (sdl_surface == NULL) st_abort("Can't covert to display format", file); @@ -315,22 +328,22 @@ sdl_surface_from_file(const std::string& file, int use_alpha) return sdl_surface; } -SDL_Surface* +SDL_Surface* sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, int use_alpha) { SDL_Surface* sdl_surface; Uint32 saved_flags; Uint8 saved_alpha; - + /* Save the alpha blending attributes */ saved_flags = sdl_surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK); saved_alpha = sdl_surf->format->alpha; if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) - { - SDL_SetAlpha(sdl_surf, 0, 0); - } - + { + SDL_SetAlpha(sdl_surf, 0, 0); + } + if(use_alpha == IGNORE_ALPHA && !use_gl) sdl_surface = SDL_DisplayFormat(sdl_surf); else @@ -339,10 +352,10 @@ sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, int use_alpha) /* Restore the alpha blending attributes */ if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) - { - SDL_SetAlpha(sdl_surface, saved_flags, saved_alpha); - } - + { + SDL_SetAlpha(sdl_surface, saved_flags, saved_alpha); + } + if (sdl_surface == NULL) st_abort("Can't covert to display format", "SURFACE"); @@ -355,8 +368,7 @@ sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, int use_alpha) //--------------------------------------------------------------------------- SurfaceImpl::SurfaceImpl() -{ -} +{} SurfaceImpl::~SurfaceImpl() { @@ -368,6 +380,20 @@ SDL_Surface* SurfaceImpl::get_sdl_surface() const return sdl_surface; } +int SurfaceImpl::resize(int w_, int h_) +{ + w = w_; + h = h_; + SDL_Rect dest; + dest.x = 0; + dest.y = 0; + dest.w = w; + dest.h = h; + int ret = SDL_SoftStretch(sdl_surface, NULL, + sdl_surface, &dest); + return ret; +} + #ifndef NOOPENGL SurfaceOpenGL::SurfaceOpenGL(SDL_Surface* surf, int use_alpha) { @@ -378,7 +404,7 @@ SurfaceOpenGL::SurfaceOpenGL(SDL_Surface* surf, int use_alpha) h = sdl_surface->h; } -SurfaceOpenGL::SurfaceOpenGL(const std::string& file, int use_alpha) +SurfaceOpenGL::SurfaceOpenGL(const std::string& file, int use_alpha) { sdl_surface = sdl_surface_from_file(file, use_alpha); create_gl(sdl_surface,&gl_texture); @@ -413,11 +439,11 @@ SurfaceOpenGL::create_gl(SDL_Surface * surf, GLuint * tex) h = power_of_two(surf->h), #if SDL_BYTEORDER == SDL_BIG_ENDIAN - conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel, - 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff); + conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel, + 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff); #else - conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel, - 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); + conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel, + 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); #endif /* Save the alpha blending attributes */ @@ -425,18 +451,18 @@ SurfaceOpenGL::create_gl(SDL_Surface * surf, GLuint * tex) saved_alpha = surf->format->alpha; if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) - { - SDL_SetAlpha(surf, 0, 0); - } + { + SDL_SetAlpha(surf, 0, 0); + } SDL_BlitSurface(surf, 0, conv, 0); /* Restore the alpha blending attributes */ if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) - { - SDL_SetAlpha(surf, saved_flags, saved_alpha); - } + { + SDL_SetAlpha(surf, saved_flags, saved_alpha); + } glGenTextures(1, &*tex); glBindTexture(GL_TEXTURE_2D , *tex); @@ -447,7 +473,7 @@ SurfaceOpenGL::create_gl(SDL_Surface * surf, GLuint * tex) glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10_A2, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - + SDL_FreeSurface(conv); } @@ -474,12 +500,12 @@ SurfaceOpenGL::draw(float x, float y, Uint8 alpha, bool update) glTexCoord2f(0, (float)h / ph); glVertex2f(x, (float)h+y); glEnd(); - + glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); - + (void) update; // avoid compiler warning - + return 0; } @@ -504,7 +530,7 @@ SurfaceOpenGL::draw_bg(Uint8 alpha, bool update) glTexCoord2f(0, (float)h / ph); glVertex2f(0, screen->h); glEnd(); - + glDisable(GL_TEXTURE_2D); (void) update; // avoid compiler warning @@ -577,30 +603,30 @@ SurfaceSDL::draw(float x, float y, Uint8 alpha, bool update) dest.y = (int)y; dest.w = w; dest.h = h; - + if(alpha != 255) - { + { /* Copy the SDL surface, then make it using alpha and use it to blit into the screen */ SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags, - sdl_surface->w, sdl_surface->h, sdl_surface->format->BitsPerPixel, - sdl_surface->format->Rmask, sdl_surface->format->Gmask, sdl_surface->format->Bmask, - sdl_surface->format->Amask); + sdl_surface->w, sdl_surface->h, sdl_surface->format->BitsPerPixel, + sdl_surface->format->Rmask, sdl_surface->format->Gmask, sdl_surface->format->Bmask, + sdl_surface->format->Amask); SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL); - + SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha); int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest); - + if (update == UPDATE) SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h); - + SDL_FreeSurface (sdl_surface_copy) ; return ret; - } - + } + int ret = SDL_BlitSurface(sdl_surface, NULL, screen, &dest); - + if (update == UPDATE) SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h); @@ -611,7 +637,7 @@ int SurfaceSDL::draw_bg(Uint8 alpha, bool update) { SDL_Rect dest; - + dest.x = 0; dest.y = 0; dest.w = screen->w; @@ -619,9 +645,9 @@ SurfaceSDL::draw_bg(Uint8 alpha, bool update) if(alpha != 255) SDL_SetAlpha(sdl_surface ,SDL_SRCALPHA,alpha); - + int ret = SDL_SoftStretch(sdl_surface, NULL, screen, &dest); - + if (update == UPDATE) SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h); @@ -645,17 +671,16 @@ SurfaceSDL::draw_part(float sx, float sy, float x, float y, float w, float h, Ui if(alpha != 255) SDL_SetAlpha(sdl_surface ,SDL_SRCALPHA,alpha); - + int ret = SDL_BlitSurface(sdl_surface, &src, screen, &dest); if (update == UPDATE) update_rect(screen, dest.x, dest.y, dest.w, dest.h); - + return ret; } SurfaceSDL::~SurfaceSDL() -{ -} +{} /* EOF */ diff --git a/src/texture.h b/src/texture.h index e5b5060fa..3cd8c2228 100644 --- a/src/texture.h +++ b/src/texture.h @@ -85,6 +85,7 @@ public: void draw(float x, float y, Uint8 alpha = 255, bool update = false); void draw_bg(Uint8 alpha = 255, bool update = false); void draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha = 255, bool update = false); + void Surface::resize(int w_, int h_); }; /** Surface implementation, all implementation have to inherit from @@ -106,6 +107,7 @@ public: virtual int draw(float x, float y, Uint8 alpha, bool update) = 0; virtual int draw_bg(Uint8 alpha, bool update) = 0; virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) = 0; + int resize(int w_, int h_); SDL_Surface* get_sdl_surface() const; // @evil@ try to avoid this function }; diff --git a/src/tile.cpp b/src/tile.cpp index 90225d6d5..5b0a356ec 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -83,7 +83,7 @@ void TileManager::load_tileset(std::string filename) if (strcmp(lisp_symbol(lisp_car(element)), "tile") == 0) { - std::vector editor_filenames; + Tile* tile = new Tile; tile->id = -1; @@ -111,7 +111,7 @@ void TileManager::load_tileset(std::string filename) reader.read_int("anim-speed", &tile->anim_speed); reader.read_int("next-tile", &tile->next_tile); reader.read_string_vector("images", &tile->filenames); - reader.read_string_vector("editor-images", &editor_filenames); + reader.read_string_vector("editor-images", &tile->editor_filenames); for(std::vector::iterator it = tile-> filenames.begin(); @@ -124,8 +124,8 @@ void TileManager::load_tileset(std::string filename) datadir + "/images/tilesets/" + (*it), USE_ALPHA); } - for(std::vector::iterator it = editor_filenames.begin(); - it != editor_filenames.end(); + for(std::vector::iterator it = tile->editor_filenames.begin(); + it != tile->editor_filenames.end(); ++it) { Surface* cur_image; diff --git a/src/tile.h b/src/tile.h index ee6a0f66b..91cedc55f 100644 --- a/src/tile.h +++ b/src/tile.h @@ -43,7 +43,8 @@ public: std::vector editor_images; std::vector filenames; - + std::vector editor_filenames; + /** solid tile that is indestructable by Tux */ bool solid; -- 2.11.0