[Super-tux-commit] supertux/src leveleditor.cpp,1.87,1.88 texture.cpp,1.20,1.21 texture.h,1.21,1.22
Brought to you by:
wkendrick
From: Tobias Gl??er <to...@us...> - 2004-05-05 22:04:58
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30873/src Modified Files: leveleditor.cpp texture.cpp texture.h tile.cpp tile.h Log Message: added draw_stretched capability to surface* and tile* classes and moreover built a minimap upon it for the leveleditor. Unfortunately it only works correctly in OpenGL mode, therefore it is disabled in software mode. Index: tile.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/tile.h,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- tile.h 3 May 2004 20:35:59 -0000 1.16 +++ tile.h 5 May 2004 22:04:48 -0000 1.17 @@ -80,6 +80,7 @@ /** Draw a tile on the screen: */ static void draw(float x, float y, unsigned int c, Uint8 alpha = 255); + static void draw_stretched(float x, float y, int w, int h, unsigned int c, Uint8 alpha = 255); }; struct TileGroup Index: leveleditor.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.cpp,v retrieving revision 1.87 retrieving revision 1.88 diff -u -d -r1.87 -r1.88 --- leveleditor.cpp 5 May 2004 20:05:09 -0000 1.87 +++ leveleditor.cpp 5 May 2004 22:04:47 -0000 1.88 @@ -128,6 +128,7 @@ /* leveleditor internals */ static string_list_type level_subsets; static bool le_level_changed; /* if changes, ask for saving, when quiting*/ +static bool show_minimap; static int pos_x, cursor_x, cursor_y, fire; static int le_level; static LevelEditorWorld le_world; @@ -782,6 +783,41 @@ } } +void le_drawminimap() +{ +if(le_current_level == NULL) +return; + +int mini_tile_width; +if(screen->w - 64 > le_current_level->width * 4) +mini_tile_width = 4; +else if(screen->w - 64 > le_current_level->width * 2) +mini_tile_width = 2; +else +mini_tile_width = 1; +int left_offset = (screen->w - 64 - le_current_level->width*mini_tile_width) / 2; + + for (int y = 0; y < 15; ++y) + for (int x = 0; x < le_current_level->width; ++x) + { + + Tile::draw_stretched(left_offset + mini_tile_width*x, y * 4, mini_tile_width , 4, le_current_level->bg_tiles[y][x]); + + Tile::draw_stretched(left_offset + mini_tile_width*x, y * 4, mini_tile_width , 4, le_current_level->ia_tiles[y][x]); + + Tile::draw_stretched(left_offset + mini_tile_width*x, y * 4, mini_tile_width , 4, le_current_level->fg_tiles[y][x]); + + } + +fillrect(left_offset, 0, le_current_level->width*mini_tile_width, 15*4, 200, 200, 200, 128); + +fillrect(left_offset + (pos_x/32)*mini_tile_width, 0, 19*mini_tile_width, 2, 200, 200, 200, 200); +fillrect(left_offset + (pos_x/32)*mini_tile_width, 0, 2, 15*4, 200, 200, 200, 200); +fillrect(left_offset + (pos_x/32)*mini_tile_width + 19*mini_tile_width - 2, 0, 2, 15*4, 200, 200, 200, 200); +fillrect(left_offset + (pos_x/32)*mini_tile_width, 15*4-2, 19*mini_tile_width, 2, 200, 200, 200, 200); + +} + void le_drawinterface() { int x,y; @@ -798,6 +834,9 @@ fillrect(0, y*32, screen->w - 32, 1, 225, 225, 225,255); } } + + if(show_minimap && use_gl) // use_gl because the minimap isn't shown correctly in software mode. Any idea? FIXME Possible reasons: SDL_SoftStretch is a hack itsself || an alpha blitting issue SDL can't handle in software mode + le_drawminimap(); if(le_selection_mode == CURSOR) if(le_current.IsTile()) @@ -1353,22 +1392,28 @@ } if(!Menu::current()) { + show_minimap = false; + if(le_move_left_bt->get_state() == BUTTON_PRESSED) { pos_x -= 192; + show_minimap = true; } else if(le_move_left_bt->get_state() == BUTTON_HOVER) { pos_x -= 32; + show_minimap = true; } if(le_move_right_bt->get_state() == BUTTON_PRESSED) { pos_x += 192; + show_minimap = true; } else if(le_move_right_bt->get_state() == BUTTON_HOVER) { pos_x += 32; + show_minimap = true; } } Index: tile.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/tile.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- tile.cpp 3 May 2004 20:35:59 -0000 1.18 +++ tile.cpp 5 May 2004 22:04:48 -0000 1.19 @@ -207,5 +207,29 @@ } } +void +Tile::draw_stretched(float x, float y, int w, int h, unsigned int c, Uint8 alpha) +{ + if (c != 0) + { + Tile* ptile = TileManager::instance()->get(c); + if(ptile) + { + if(ptile->images.size() > 1) + { + ptile->images[( ((global_frame_counter*25) / ptile->anim_speed) % (ptile->images.size()))]->draw_stretched(x,y,w,h, alpha); + } + else if (ptile->images.size() == 1) + { + ptile->images[0]->draw_stretched(x,y, w, h, alpha); + } + else + { + //printf("Tile not dravable %u\n", c); + } + } + } +} + // EOF // Index: texture.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/texture.h,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- texture.h 3 May 2004 20:35:58 -0000 1.21 +++ texture.h 5 May 2004 22:04:48 -0000 1.22 @@ -85,7 +85,8 @@ 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_); + void draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update = false); + void resize(int w_, int h_); }; /** Surface implementation, all implementation have to inherit from @@ -107,6 +108,7 @@ 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; + virtual int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update) = 0; int resize(int w_, int h_); SDL_Surface* get_sdl_surface() const; // @evil@ try to avoid this function @@ -123,6 +125,7 @@ int draw(float x, float y, Uint8 alpha, bool update); int draw_bg(Uint8 alpha, bool update); int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update); + int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update); }; #ifndef NOOPENGL @@ -140,6 +143,7 @@ int draw(float x, float y, Uint8 alpha, bool update); int draw_bg(Uint8 alpha, bool update); int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update); + int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update); private: void create_gl(SDL_Surface * surf, GLuint * tex); Index: texture.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/texture.cpp,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- texture.cpp 3 May 2004 20:35:58 -0000 1.20 +++ texture.cpp 5 May 2004 22:04:48 -0000 1.21 @@ -237,6 +237,16 @@ } void +Surface::draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update) +{ + if (impl) + { + if (impl->draw_stretched(x, y, w, h, alpha, update) == -2) + reload(); + } +} + +void Surface::resize(int w_, int h_) { if (impl) @@ -571,6 +581,41 @@ (void) update; // avoid warnings return 0; } + +int +SurfaceOpenGL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, bool update) +{ + float pw = power_of_two(int(this->w)); + float ph = power_of_two(int(this->h)); + + glBindTexture(GL_TEXTURE_2D, gl_texture); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glColor4ub(alpha, alpha, alpha, alpha); + + glEnable(GL_TEXTURE_2D); + + + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2f(x, y); + glTexCoord2f((float)w / pw, 0); + glVertex2f(sw+x, y); + glTexCoord2f((float)w / pw, (float)h / ph); glVertex2f((float)sw+x, (float)sh+y); + glVertex2f(sw +x, sh+y); + glTexCoord2f(0, (float)h / ph); + glVertex2f(x, sh+y); + glEnd(); + + glDisable(GL_TEXTURE_2D); + glDisable(GL_BLEND); + + (void) update; // avoid warnings + return 0; +} + #endif SurfaceSDL::SurfaceSDL(SDL_Surface* surf, int use_alpha) @@ -680,6 +725,27 @@ return ret; } +int +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; + dest.h = (int)sh; + + if(alpha != 255) + SDL_SetAlpha(sdl_surface ,SDL_SRCALPHA,alpha); + + int ret = SDL_SoftStretch(sdl_surface, NULL, screen, &dest); + + if (update == UPDATE) + update_rect(screen, dest.x, dest.y, dest.w, dest.h); + + return ret; +} + SurfaceSDL::~SurfaceSDL() {} |