1 /* 2 * Copyright 2014, 2016 Peter Olsson 3 * 4 * This file is part of Brum Brum Rally. 5 * 6 * Brum Brum Rally is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * Brum Brum Rally is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef SCALER_H 21 #define SCALER_H 22 23 #include "Surface.h" 24 #include "StateManager.h" 25 26 class Scaler 27 { 28 public: 29 Scaler(); 30 virtual ~Scaler(); 31 virtual void update(int w, int h); 32 void render(const Surface& surface, SDL_Rect* area); 33 src2dst_x(int x)34 inline int src2dst_x(int x) const { return x * screenArea.w / GAME_WIDTH + screenArea.x; }; src2dst_y(int y)35 inline int src2dst_y(int y) const { return y * screenArea.h / GAME_HEIGHT + screenArea.y; }; dst2src_x(int x)36 inline int dst2src_x(int x) const { return (x - screenArea.x) * GAME_WIDTH / screenArea.w; }; dst2src_y(int y)37 inline int dst2src_y(int y) const { return (y - screenArea.y) * GAME_HEIGHT / screenArea.h; }; 38 39 virtual bool isValidZoom(int zoom) const; 40 virtual bool isValidBpp(int bpp) const; 41 virtual bool needStretchBuffer() const; 42 43 void stretchArea(const SDL_Rect& srcArea, SDL_Rect& dstArea, int x, int y, SDL_Surface* source, SDL_Surface* destination); 44 void expand(SDL_Rect& srcArea, SDL_Rect& dstArea, int pixels); 45 46 protected: 47 virtual void renderStretch(const SDL_Rect& srcArea, SDL_Rect& dstArea, SDL_Surface* source, SDL_Surface* destination) = 0; 48 virtual void renderZoom(const SDL_Rect& srcArea, SDL_Rect& dstArea, SDL_Surface* source, SDL_Surface* destination) = 0; 49 50 SDL_Rect screenArea; 51 int zoom; 52 int xZoom; 53 int yZoom; 54 55 SDL_Surface* buffer; 56 bool stretch; 57 }; 58 59 #endif 60