// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
-#include <assert.h>
+#include <cassert>
#include <iostream>
#include <algorithm>
+
#include "SDL.h"
#include "SDL_image.h"
+
#include "texture.h"
#include "globals.h"
#include "setup.h"
x(x_), y(y_), w(w_), h(h_)
{}
+SurfaceData::SurfaceData(Color top_gradient_, Color bottom_gradient_, int w_, int h_)
+ : type(GRADIENT), surface(0), use_alpha(false), w(w_), h(h_)
+{
+top_gradient = top_gradient_;
+bottom_gradient = bottom_gradient_;
+}
+
+
SurfaceData::~SurfaceData()
{
SDL_FreeSurface(surface);
return new SurfaceSDL(file, x, y, w, h, use_alpha);
case SURFACE:
return new SurfaceSDL(surface, use_alpha);
+ case GRADIENT:
+ return new SurfaceSDL(top_gradient, bottom_gradient, w, h);
}
assert(0);
}
return new SurfaceOpenGL(file, x, y, w, h, use_alpha);
case SURFACE:
return new SurfaceOpenGL(surface, use_alpha);
+ case GRADIENT:
+ return new SurfaceOpenGL(top_gradient, bottom_gradient, w, h);
}
#endif
assert(0);
surfaces.push_back(this);
}
+Surface::Surface(Color top_background, Color bottom_background, int w, int h)
+ : data(top_background, bottom_background, w, h), w(0), h(0)
+{
+ impl = data.create();
+ if (impl)
+ {
+ w = impl->w;
+ h = impl->h;
+ }
+ surfaces.push_back(this);
+}
+
void
Surface::reload()
{
return sdl_surface;
}
+SDL_Surface*
+sdl_surface_from_gradient(Color top, Color bottom, int w, int h)
+{
+ SDL_Surface* sdl_surface;
+
+ sdl_surface = SDL_CreateRGBSurface(screen->flags, w, h,
+ screen->format->BitsPerPixel, screen->format->Rmask,
+ screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
+
+ if(sdl_surface == NULL)
+ st_abort("Cannot create surface for the gradient", "SURFACE");
+
+ if(top == bottom)
+ {
+ SDL_FillRect(sdl_surface, NULL, SDL_MapRGB(sdl_surface->format,
+ top.red, top.green, top.blue));
+ }
+ else
+ {
+ float redstep = (float(bottom.red)-float(top.red)) / float(h);
+ float greenstep = (float(bottom.green)-float(top.green)) / float(h);
+ float bluestep = (float(bottom.blue) - float(top.blue)) / float(h);
+
+ SDL_Rect rect;
+ rect.x = 0;
+ rect.w = w;
+ rect.h = 1;
+ for(float y = 0; y < h; y++)
+ {
+ rect.y = (int)y;
+ SDL_FillRect(sdl_surface, &rect, SDL_MapRGB(sdl_surface->format,
+ int(float(top.red) + redstep * y),
+ int(float(top.green) + greenstep * y),
+ int(float(top.blue) + bluestep * y)));
+ }
+ }
+
+ return sdl_surface;
+}
+
//---------------------------------------------------------------------------
SurfaceImpl::SurfaceImpl()
h = sdl_surface->h;
}
+SurfaceOpenGL::SurfaceOpenGL(Color top_gradient, Color bottom_gradient, int w, int h)
+{
+ sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient, w, h);
+ create_gl(sdl_surface, &gl_texture);
+
+ w = sdl_surface->w;
+ h = sdl_surface->h;
+}
+
SurfaceOpenGL::~SurfaceOpenGL()
{
glDeleteTextures(1, &gl_texture);
}
int
-SurfaceOpenGL::draw(float x, float y, Uint8 alpha, uint32_t effect)
+SurfaceOpenGL::draw(float x, float y, Uint8 alpha, Uint32 effect)
{
float pw = power_of_two(w);
float ph = power_of_two(h);
}
int
-SurfaceOpenGL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, uint32_t effect)
+SurfaceOpenGL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect)
{
float pw = power_of_two(int(this->w));
float ph = power_of_two(int(this->h));
h = sdl_surface->h;
}
+SurfaceSDL::SurfaceSDL(Color top_gradient, Color bottom_gradient, int w, int h)
+{
+ sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient, w, h);
+ w = sdl_surface->w;
+ h = sdl_surface->h;
+}
+
int
-SurfaceSDL::draw(float x, float y, Uint8 alpha, uint32_t effect)
+SurfaceSDL::draw(float x, float y, Uint8 alpha, Uint32 effect)
{
SDL_Rect dest;
}
int
-SurfaceSDL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, uint32_t effect)
+SurfaceSDL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect)
{
SDL_Rect src, dest;