diff --git a/src/sdl/image.cpp b/src/sdl/image.cpp index c7a4b730f022..24b91f70c292 100644 --- a/src/sdl/image.cpp +++ b/src/sdl/image.cpp @@ -28,15 +28,12 @@ namespace sdl { timage::timage(Uint16 w, Uint16 h) : image_(NULL) - , rotation_(0) - , hscale_(1) - , vscale_(1) - , smooth_scaling_(false) - , clip_(create_gpu_rect(0, 0, w, h)) - , color_mod_(create_color(0, 0, 0, 255)) - , hwrap_(GPU_WRAP_NONE) - , vwrap_(GPU_WRAP_NONE) + , rotation_(new float(0)) + , hscale_(new float(1)) + , vscale_(new float(1)) + , clip_(new GPU_Rect) { + *clip_ = create_gpu_rect(0, 0, w, h); image_ = GPU_CreateImage(w, h, GPU_FORMAT_RGBA); if (image_ == NULL) { //TODO: report errorr @@ -47,71 +44,55 @@ timage::timage(Uint16 w, Uint16 h) timage::timage(const std::string &file) : image_(GPU_LoadImage(file.c_str())) - , rotation_(0) - , hscale_(1) - , vscale_(1) - , smooth_scaling_(false) - , clip_() - , color_mod_(create_color(0, 0, 0, 255)) - , hwrap_(GPU_WRAP_NONE) - , vwrap_(GPU_WRAP_NONE) + , rotation_(new float(0)) + , hscale_(new float(1)) + , vscale_(new float(1)) + , clip_(new GPU_Rect) { if (image_ == NULL) { //TODO: report error } else { - clip_ = create_gpu_rect(0, 0, image_->w, image_->h); + *clip_ = create_gpu_rect(0, 0, image_->w, image_->h); image_->refcount = 1; } } timage::timage(const surface &source) : image_(GPU_CopyImageFromSurface(source)) - , rotation_(0) - , hscale_(1) - , vscale_(1) - , smooth_scaling_(false) - , clip_() - , color_mod_(create_color(0, 0, 0, 255)) - , hwrap_(GPU_WRAP_NONE) - , vwrap_(GPU_WRAP_NONE) + , rotation_(new float(0)) + , hscale_(new float(1)) + , vscale_(new float(1)) + , clip_(new GPU_Rect) { if (image_ == NULL) { //TODO: report error } else { - clip_ = create_gpu_rect(0, 0, image_->w, image_->h); + *clip_ = create_gpu_rect(0, 0, image_->w, image_->h); image_->refcount = 1; } } timage::timage(SDL_Surface *source) : image_(GPU_CopyImageFromSurface(source)) - , rotation_(0) - , hscale_(1) - , vscale_(1) - , smooth_scaling_(false) - , clip_() - , color_mod_(create_color(0, 0, 0, 255)) - , hwrap_(GPU_WRAP_NONE) - , vwrap_(GPU_WRAP_NONE) + , rotation_(new float(0)) + , hscale_(new float(1)) + , vscale_(new float(1)) + , clip_(new GPU_Rect) { if (image_ == NULL) { //TODO: report error } else { - clip_ = create_gpu_rect(0, 0, image_->w, image_->h); + *clip_ = create_gpu_rect(0, 0, image_->w, image_->h); image_->refcount = 1; } } timage::timage() : image_(NULL) - , rotation_(0) - , hscale_(1) - , vscale_(1) - , smooth_scaling_(false) - , clip_(create_gpu_rect(0, 0, 0, 0)) - , color_mod_(create_color(0, 0, 0, 255)) - , hwrap_(GPU_WRAP_NONE) - , vwrap_(GPU_WRAP_NONE) + , rotation_(new float(0)) + , hscale_(new float(1)) + , vscale_(new float(1)) + , clip_(new GPU_Rect) { } @@ -121,6 +102,10 @@ sdl::timage::~timage() image_->refcount -= 1; if (image_->refcount == 0) { GPU_FreeImage(image_); + delete clip_; + delete hscale_; + delete vscale_; + delete rotation_; } } } @@ -130,11 +115,7 @@ timage::timage(const timage &texture) , rotation_(texture.rotation_) , hscale_(texture.hscale_) , vscale_(texture.vscale_) - , smooth_scaling_(texture.smooth_scaling_) , clip_(texture.clip_) - , color_mod_(texture.color_mod_) - , hwrap_(texture.hwrap_) - , vwrap_(texture.vwrap_) { if (image_ != NULL) { image_->refcount += 1; @@ -153,70 +134,65 @@ timage &timage::operator =(const timage &texture) void timage::draw(GPU_Target &target, const int x, const int y) { - GPU_SetImageFilter(image_, - smooth_scaling_ - ? GPU_FILTER_LINEAR - : GPU_FILTER_NEAREST); - //GPU_SetColor(image_, &color_mod_); - GPU_SetWrapMode(image_, hwrap_, vwrap_); - GPU_BlitTransform(image_, &clip_, &target, x + width()/2, - y + height()/2, rotation_, hscale_, vscale_); + GPU_BlitTransform(image_, clip_, &target, x + width()/2, + y + height()/2, *rotation_, *hscale_, *vscale_); } void timage::set_rotation(float rotation) { - rotation_ = rotation; + *rotation_ = rotation; } float timage::rotation() const { - return rotation_; + return *rotation_; } void timage::set_hscale(float factor) { - hscale_ = factor; + *hscale_ = factor; } void timage::set_vscale(float factor) { - vscale_ = factor; + *vscale_ = factor; } void timage::set_scale(float hfactor, float vfactor) { - hscale_ = hfactor; - vscale_ = vfactor; + *hscale_ = hfactor; + *vscale_ = vfactor; } float timage::hscale() const { - return hscale_; + return *hscale_; } float timage::vscale() const { - return vscale_; + return *vscale_; } void timage::set_smooth_scaling(bool use_smooth) { - smooth_scaling_ = use_smooth; + GPU_SetImageFilter(image_, + use_smooth ? GPU_FILTER_LINEAR : GPU_FILTER_NEAREST); } bool timage::smooth_scaling() const { - return smooth_scaling_; + return image_->filter_mode == GPU_FILTER_LINEAR; } Uint16 timage::width() const { - return image_->w * hscale_; + return image_->w * *hscale_; } Uint16 timage::height() const { - return image_->h * vscale_; + return image_->h * *vscale_; } Uint16 timage::base_width() const @@ -231,79 +207,79 @@ Uint16 timage::base_height() const void timage::set_clip(const SDL_Rect &rect) { - clip_.x = rect.x; - clip_.y = rect.y; - clip_.w = rect.w; - clip_.h = rect.h; + clip_->x = rect.x; + clip_->y = rect.y; + clip_->w = rect.w; + clip_->h = rect.h; } SDL_Rect timage::clip() const { SDL_Rect result; - result.x = clip_.x; - result.y = clip_.y; - result.w = clip_.w; - result.h = clip_.h; + result.x = clip_->x; + result.y = clip_->y; + result.w = clip_->w; + result.h = clip_->h; return result; } void timage::set_alpha(Uint8 alpha) { - color_mod_.unused = alpha; + const SDL_Color prev = image_->color; + SDL_Color next = create_color(prev.r, prev.g, prev.b, alpha); + GPU_SetColor(image_, &next); } Uint8 timage::alpha() const { - return color_mod_.unused; + return image_->color.unused; } void timage::set_color_mod(Uint8 r, Uint8 g, Uint8 b) { - color_mod_.r = r; - color_mod_.g = g; - color_mod_.b = b; + SDL_Color c = create_color(r, g, b, image_->color.unused); + GPU_SetColor(image_, &c); } Uint8 timage::red_mod() const { - return color_mod_.r; + return image_->color.r; } Uint8 timage::green_mod() const { - return color_mod_.g; + return image_->color.g; } Uint8 timage::blue_mod() const { - return color_mod_.b; + return image_->color.b; } void timage::set_hwrap(GPU_WrapEnum mode) { - hwrap_ = mode; + GPU_SetWrapMode(image_, mode, image_->wrap_mode_y); } void timage::set_vwrap(GPU_WrapEnum mode) { - vwrap_ = mode; + GPU_SetWrapMode(image_, image_->wrap_mode_x, mode); } void timage::set_wrap(GPU_WrapEnum hmode, GPU_WrapEnum vmode) { - hwrap_ = hmode; - vwrap_ = vmode; + GPU_SetWrapMode(image_, hmode, vmode); } GPU_WrapEnum timage::hwrap() const { - return hwrap_; + return image_->wrap_mode_x; } GPU_WrapEnum timage::vwrap() const { - return vwrap_; + return image_->wrap_mode_y; } bool timage::null() const diff --git a/src/sdl/image.hpp b/src/sdl/image.hpp index a9ceb7624a63..d97a0ea5488e 100644 --- a/src/sdl/image.hpp +++ b/src/sdl/image.hpp @@ -248,28 +248,16 @@ class timage GPU_Image *image_; /** How much will it be rotated. */ - float rotation_; + float *rotation_; /** How much will it be scaled horizontally. */ - float hscale_; + float *hscale_; /** How much will it be scaled vertically. */ - float vscale_; - - /** Whether to use bilinear scaling. */ - bool smooth_scaling_; + float *vscale_; /** Which part of the texture should be displayed. */ - GPU_Rect clip_; - - /** Color modulation. */ - SDL_Color color_mod_; - - /** Horizontal wrap policy. */ - GPU_WrapEnum hwrap_; - - /** Vertical wrap policy. */ - GPU_WrapEnum vwrap_; + GPU_Rect *clip_; }; } #endif