[Super-tux-commit] supertux/src/screen drawing_context.cpp,1.3,1.4 drawing_context.h,1.1,1.2 texture
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-05-31 13:02:47
|
Update of /cvsroot/super-tux/supertux/src/screen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28560/src/screen Modified Files: drawing_context.cpp drawing_context.h texture.cpp texture.h Log Message: Added support for drawing effects again. We really need a include.h file with major includes, or we could just put the includes into the defines.h. Index: drawing_context.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/screen/drawing_context.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- drawing_context.cpp 30 May 2004 15:25:01 -0000 1.3 +++ drawing_context.cpp 31 May 2004 13:02:20 -0000 1.4 @@ -17,7 +17,7 @@ void DrawingContext::draw_surface(const Surface* surface, const Vector& position, - int layer) + int layer, uint32_t drawing_effect) { assert(surface != 0); @@ -27,13 +27,14 @@ request.layer = layer; request.request_data = const_cast<Surface*> (surface); request.pos = transform.apply(position); + request.drawing_effect = drawing_effect; drawingrequests.push_back(request); } void DrawingContext::draw_surface_part(const Surface* surface, const Vector& source, - const Vector& size, const Vector& dest, int layer) + const Vector& size, const Vector& dest, int layer, uint32_t drawing_effect) { assert(surface != 0); @@ -42,6 +43,7 @@ request.type = SURFACE_PART; request.layer = layer; request.pos = transform.apply(dest); + request.drawing_effect = drawing_effect; SurfacePartRequest* surfacepartrequest = new SurfacePartRequest(); surfacepartrequest->size = size; @@ -133,7 +135,8 @@ surfacepartrequest->surface->impl->draw_part( surfacepartrequest->source.x, surfacepartrequest->source.y, request.pos.x, request.pos.y, - surfacepartrequest->size.x, surfacepartrequest->size.y, 255); + surfacepartrequest->size.x, surfacepartrequest->size.y, 255, + request.drawing_effect); delete surfacepartrequest; } @@ -271,7 +274,7 @@ case SURFACE: { const Surface* surface = (const Surface*) i->request_data; - surface->impl->draw(i->pos.x, i->pos.y, 255); + surface->impl->draw(i->pos.x, i->pos.y, 255, i->drawing_effect); break; } case SURFACE_PART: Index: drawing_context.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/screen/drawing_context.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- drawing_context.h 30 May 2004 01:08:50 -0000 1.1 +++ drawing_context.h 31 May 2004 13:02:21 -0000 1.2 @@ -1,9 +1,11 @@ #ifndef __DRAWINGCONTEXT_H__ #define __DRAWINGCONTEXT_H__ +#include <stdint.h> #include <vector> #include <string> #include "vector.h" +#include "screen.h" #include <SDL.h> class Surface; @@ -50,10 +52,12 @@ ~DrawingContext(); /** Adds a drawing request for a surface into the request list */ - void draw_surface(const Surface* surface, const Vector& position, int layer); + void draw_surface(const Surface* surface, const Vector& position, int layer, + uint32_t drawing_effect = NONE_EFFECT); /** Adds a drawing request for part of a surface */ void draw_surface_part(const Surface* surface, const Vector& source, - const Vector& size, const Vector& dest, int layer); + const Vector& size, const Vector& dest, int layer, + uint32_t drawing_effect = NONE_EFFECT); /** draws a text */ void draw_text(Font* font, const std::string& text, const Vector& position, int layer); @@ -126,6 +130,7 @@ struct DrawingRequest { int layer; + uint32_t drawing_effect; RequestType type; Vector pos; Index: texture.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/screen/texture.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- texture.h 30 May 2004 20:42:24 -0000 1.2 +++ texture.h 31 May 2004 13:02:21 -0000 1.3 @@ -27,6 +27,7 @@ #include <SDL_opengl.h> #endif +#include <stdint.h> #include <list> #include "screen.h" #include "vector.h" @@ -38,6 +39,16 @@ class SurfaceOpenGL; class DrawingContext; +/// bitset for drawing effects +enum { + /** Draw the Surface upside down */ + NONE_EFFECT = 0x0000, + /** Draw the Surface upside down */ + VERTICAL_FLIP = 0x0001, + /** Draw the Surface with alpha equal to 128 */ + SEMI_TRANSPARENT = 0x0002 + }; + /** This class holds all the data necessary to construct a surface */ class SurfaceData { @@ -105,8 +116,8 @@ virtual ~SurfaceImpl(); /** Return 0 on success, -2 if surface needs to be reloaded */ - virtual int draw(float x, float y, Uint8 alpha) = 0; - virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha) = 0; + virtual int draw(float x, float y, Uint8 alpha, uint32_t effect = NONE_EFFECT) = 0; + virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, uint32_t effect = NONE_EFFECT) = 0; #if 0 virtual int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update) = 0; #endif @@ -123,8 +134,8 @@ SurfaceSDL(const std::string& file, int x, int y, int w, int h, int use_alpha); virtual ~SurfaceSDL(); - int draw(float x, float y, Uint8 alpha); - int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha); + int draw(float x, float y, Uint8 alpha, uint32_t effect = NONE_EFFECT); + int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, uint32_t effect = NONE_EFFECT); #if 0 int draw_stretched(float x, float y, int w, int h, Uint8 alpha); #endif @@ -142,8 +153,8 @@ SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, int use_alpha); virtual ~SurfaceOpenGL(); - int draw(float x, float y, Uint8 alpha); - int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha); + int draw(float x, float y, Uint8 alpha, uint32_t effect = NONE_EFFECT); + int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, uint32_t effect = NONE_EFFECT); #if 0 int draw_stretched(float x, float y, int w, int h, Uint8 alpha); #endif Index: texture.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/screen/texture.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- texture.cpp 30 May 2004 01:08:50 -0000 1.1 +++ texture.cpp 31 May 2004 13:02:21 -0000 1.2 @@ -448,11 +448,14 @@ } int -SurfaceOpenGL::draw(float x, float y, Uint8 alpha) +SurfaceOpenGL::draw(float x, float y, Uint8 alpha, uint32_t effect) { float pw = power_of_two(w); float ph = power_of_two(h); + if(effect & SEMI_TRANSPARENT) + alpha = 128; + glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -462,13 +465,35 @@ glBindTexture(GL_TEXTURE_2D, gl_texture); glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2f(x, y); - glTexCoord2f((float)w / pw, 0); - glVertex2f((float)w+x, y); - glTexCoord2f((float)w / pw, (float)h / ph); glVertex2f((float)w+x, (float)h+y); - glTexCoord2f(0, (float)h / ph); - glVertex2f(x, (float)h+y); + + if(effect & VERTICAL_FLIP) + { + glTexCoord2f(0, 0); + glVertex2f(x, (float)h+y); + + glTexCoord2f((float)w / pw, 0); + glVertex2f((float)w+x, (float)h+y); + + glTexCoord2f((float)w / pw, (float)h / ph); + glVertex2f((float)w+x, y); + + glTexCoord2f(0, (float)h / ph); + glVertex2f(x, y); + } + else + { + glTexCoord2f(0, 0); + glVertex2f(x, y); + + glTexCoord2f((float)w / pw, 0); + glVertex2f((float)w+x, y); + + glTexCoord2f((float)w / pw, (float)h / ph); + glVertex2f((float)w+x, (float)h+y); + + glTexCoord2f(0, (float)h / ph); + glVertex2f(x, (float)h+y); + } glEnd(); glDisable(GL_TEXTURE_2D); @@ -478,11 +503,14 @@ } int -SurfaceOpenGL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha) +SurfaceOpenGL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, uint32_t effect) { float pw = power_of_two(int(this->w)); float ph = power_of_two(int(this->h)); + if(effect & SEMI_TRANSPARENT) + alpha = 128; + glBindTexture(GL_TEXTURE_2D, gl_texture); glEnable(GL_BLEND); @@ -494,14 +522,36 @@ glBegin(GL_QUADS); - glTexCoord2f(sx / pw, sy / ph); - glVertex2f(x, y); - glTexCoord2f((float)(sx + w) / pw, sy / ph); - glVertex2f(w+x, y); - glTexCoord2f((sx+w) / pw, (sy+h) / ph); - glVertex2f(w +x, h+y); - glTexCoord2f(sx / pw, (float)(sy+h) / ph); - glVertex2f(x, h+y); + + if(effect & VERTICAL_FLIP) + { + glTexCoord2f(sx / pw, sy / ph); + glVertex2f(x, y); + + glTexCoord2f((float)(sx + w) / pw, sy / ph); + glVertex2f(w+x, y); + + glTexCoord2f((sx+w) / pw, (sy+h) / ph); + glVertex2f(w +x, h+y); + + glTexCoord2f(sx / pw, (float)(sy+h) / ph); + glVertex2f(x, h+y); + } + else + { + glTexCoord2f(sx / pw, (float)(sy+h) / ph); + glVertex2f(x, h+y); + + glTexCoord2f((sx+w) / pw, (sy+h) / ph); + glVertex2f(w +x, h+y); + + glTexCoord2f((float)(sx + w) / pw, sy / ph); + glVertex2f(w+x, y); + + glTexCoord2f(sx / pw, sy / ph); + glVertex2f(x, y); + } + glEnd(); glDisable(GL_TEXTURE_2D); @@ -569,7 +619,7 @@ } int -SurfaceSDL::draw(float x, float y, Uint8 alpha) +SurfaceSDL::draw(float x, float y, Uint8 alpha, uint32_t effect) { SDL_Rect dest; @@ -578,6 +628,17 @@ dest.w = w; dest.h = h; + if(effect & SEMI_TRANSPARENT) + alpha = 128; + + if(effect & VERTICAL_FLIP) // FIXME: feel free to replace this hack + { + for(float sy = 0; sy < h; sy++) + if(draw_part(0, sy, x, y+(h-sy), w, 1, alpha, NONE_EFFECT) == -2) + return -2; + return 0; + } + if(alpha != 255) { /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha @@ -610,7 +671,7 @@ } int -SurfaceSDL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha) +SurfaceSDL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, uint32_t effect) { SDL_Rect src, dest; @@ -624,6 +685,17 @@ dest.w = (int)w; dest.h = (int)h; + if(effect & SEMI_TRANSPARENT) + alpha = 128; + + if(effect & VERTICAL_FLIP) // FIXME: feel free to replace this hack + { + for(float sy_ = sy; sy_ < h; sy_++) + if(draw_part(sx, sy_, x, y+(h-sy_), w, 1, alpha, NONE_EFFECT) == -2) + return -2; + return 0; + } + if(alpha != 255) { /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha |