Mana
Loading...
Searching...
No Matches
sdlgraphics.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
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 2 of the License, or
11 * 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 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "graphics.h"
25
26#include <memory>
27
28class VideoSettings;
29
30class SDLGraphics final : public Graphics
31{
32public:
33 static std::unique_ptr<Graphics> create(SDL_Window *window,
34 const VideoSettings &settings);
35
36 SDLGraphics(SDL_Window *window, SDL_Renderer *renderer);
37 ~SDLGraphics() override;
38
39 void setVSync(bool sync) override;
40
41 void updateSize(int windowWidth, int windowHeight, float scale) override;
42
43 bool drawRescaledImage(const Image *image,
44 int srcX, int srcY,
45 int dstX, int dstY,
46 int width, int height,
47 int desiredWidth, int desiredHeight,
48 bool useColor) override;
49
50#if SDL_VERSION_ATLEAST(2, 0, 10)
51 bool drawRescaledImageF(const Image *image,
52 int srcX, int srcY,
53 float dstX, float dstY,
54 int width, int height,
55 float desiredWidth, float desiredHeight,
56 bool useColor) override;
57#endif
58
59 void drawRescaledImagePattern(const Image *image,
60 int srcX, int srcY,
61 int srcW, int srcH,
62 int dstX, int dstY,
63 int dstW, int dstH,
64 int scaledWidth,
65 int scaledHeight) override;
66
67 void updateScreen() override;
68
69 void windowToLogical(int windowX, int windowY,
70 float &logicalX, float &logicalY) const override;
71
72 SDL_Surface *getScreenshot() override;
73
74 void drawPoint(int x, int y) override;
75
76 void drawLine(int x1, int y1, int x2, int y2) override;
77
78 void drawRectangle(const gcn::Rectangle &rectangle) override;
79
80 void fillRectangle(const gcn::Rectangle &rectangle) override;
81
82protected:
83 void updateClipRect() override;
84
85private:
86 void setColorAlphaMod(const Image *image, bool useColor) const;
87
88 SDL_Window *mWindow = nullptr;
89 SDL_Renderer *mRenderer = nullptr;
90};
A central point of control for graphics.
Definition graphics.h:78
virtual bool drawRescaledImageF(const Image *image, int srcX, int srcY, float dstX, float dstY, int width, int height, float desiredWidth, float desiredHeight, bool useColor=false)
Draws a rescaled version of the image.
Definition graphics.cpp:60
Defines a class for loading and storing images.
Definition image.h:45
static std::unique_ptr< Graphics > create(SDL_Window *window, const VideoSettings &settings)
SDL_Surface * getScreenshot() override
Takes a screenshot and returns it as SDL surface.
void updateClipRect() override
void drawRescaledImagePattern(const Image *image, int srcX, int srcY, int srcW, int srcH, int dstX, int dstY, int dstW, int dstH, int scaledWidth, int scaledHeight) override
Draw a pattern based on a rescaled version of the given image.
void drawPoint(int x, int y) override
void updateScreen() override
Updates the screen.
void setVSync(bool sync) override
Sets whether vertical refresh syncing is enabled.
SDL_Renderer * mRenderer
Definition sdlgraphics.h:89
~SDLGraphics() override
SDL_Window * mWindow
Definition sdlgraphics.h:88
void updateSize(int windowWidth, int windowHeight, float scale) override
Called when the window size or scale has changed.
bool drawRescaledImage(const Image *image, int srcX, int srcY, int dstX, int dstY, int width, int height, int desiredWidth, int desiredHeight, bool useColor) override
Draws a rescaled version of the image.
void setColorAlphaMod(const Image *image, bool useColor) const
void windowToLogical(int windowX, int windowY, float &logicalX, float &logicalY) const override
Converts a window coordinate to a logical coordinate.
void drawRectangle(const gcn::Rectangle &rectangle) override
void drawLine(int x1, int y1, int x2, int y2) override
void fillRectangle(const gcn::Rectangle &rectangle) override