1 #ifndef _IMAGE_BLITTER_ 2 #define _IMAGE_BLITTER_ 3 /* 4 IMAGE_BLITTER.H 5 6 Copyright (C) 2009 by Jeremiah Morris and the Aleph One developers 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 3 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 This license is contained in the file "COPYING", 19 which is included with this source code; it is available online at 20 http://www.gnu.org/licenses/gpl.html 21 22 Implements images for 2D UI 23 */ 24 25 #include "cseries.h" 26 #include "ImageLoader.h" 27 28 #include <vector> 29 #include <set> 30 31 struct Image_Rect 32 { 33 float x = 0, y = 0, w = 0, h = 0; 34 35 Image_Rect() = default; 36 Image_RectImage_Rect37 explicit constexpr Image_Rect(float x, float y, float w, float h) 38 : x(x), y(y), w(w), h(h) {} 39 Image_RectImage_Rect40 /*implicit*/ constexpr Image_Rect(SDL_Rect r) 41 : x(r.x), y(r.y), w(r.w), h(r.h) {} 42 }; 43 44 class Image_Blitter 45 { 46 public: 47 Image_Blitter(); 48 49 bool Load(const ImageDescriptor& image); 50 bool Load(int picture_resource); 51 bool Load(const SDL_Surface& s); 52 bool Load(const SDL_Surface& s, const SDL_Rect& src); 53 virtual void Unload(); 54 bool Loaded(); 55 56 void Rescale(float width, float height); 57 float Width(); 58 float Height(); 59 int UnscaledWidth(); 60 int UnscaledHeight(); 61 Draw(SDL_Surface * dst_surface,const Image_Rect & dst)62 virtual void Draw(SDL_Surface *dst_surface, const Image_Rect& dst) { Draw(dst_surface, dst, crop_rect); } 63 virtual void Draw(SDL_Surface *dst_surface, const Image_Rect& dst, const Image_Rect& src); 64 65 virtual ~Image_Blitter(); 66 67 // tint the output image -- (1, 1, 1, 1) is untinted 68 float tint_color_r, tint_color_g, tint_color_b, tint_color_a; 69 70 // rotate the output image about the center of destination rect 71 // (in degrees clockwise) 72 float rotation; 73 74 // set default cropping rectangle 75 Image_Rect crop_rect; 76 77 protected: 78 79 SDL_Surface *m_surface; 80 SDL_Surface *m_disp_surface; 81 SDL_Surface *m_scaled_surface; 82 Image_Rect m_src, m_scaled_src; 83 }; 84 85 #endif 86