FifeGUI 0.2.0
A C++ GUI library designed for games.
backends/sdl2/image.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#ifndef INCLUDE_FIFECHAN_BACKENDS_SDL_SDLIMAGE_HPP_
6#define INCLUDE_FIFECHAN_BACKENDS_SDL_SDLIMAGE_HPP_
7
8#include <SDL2/SDL.h>
9
10#include <string>
11
12#include "fifechan/color.hpp"
13#include "fifechan/image.hpp"
14#include "fifechan/platform.hpp"
15
16namespace fcn::sdl2
17{
23 class FIFEGUI_EXT_API Image : public fcn::Image
24 {
25 public:
36 Image(SDL_Surface* surface, bool autoFree, SDL_Renderer* renderer = nullptr);
37
38 ~Image() override;
39
40 Image(Image const &) = delete;
41 Image& operator=(Image const &) = delete;
42 Image(Image&&) = delete;
43 Image& operator=(Image&&) = delete;
44
51 virtual SDL_Surface* getSurface() const;
52
58 virtual SDL_Texture* getTexture() const;
59
60 // Inherited from Image
61
62 void free() override;
63
64 int getWidth() const override;
65
66 int getHeight() const override;
67
68 Color getPixel(int x, int y) override;
69
70 void putPixel(int x, int y, Color const & color) override;
71
72 void convertToDisplayFormat() override;
73
74 protected:
76 SDL_Texture* mTexture = nullptr;
77
79 SDL_Renderer* mRenderer = nullptr;
80
82 SDL_Surface* mTransientSurface = nullptr;
83
86 };
87} // namespace fcn::sdl2
88
89#endif // INCLUDE_FIFECHAN_BACKENDS_SDL_SDLIMAGE_HPP_
Color.
Definition color.hpp:56
Abstract holder for image data.
Definition image.hpp:32
SDL_Surface * mTransientSurface
Transient surface for pixel operations (getPixel/putPixel).
void putPixel(int x, int y, Color const &color) override
Puts a pixel with a certain color at coordinate (x, y).
Image(SDL_Surface *surface, bool autoFree, SDL_Renderer *renderer=nullptr)
Constructor.
virtual SDL_Texture * getTexture() const
Gets the SDL texture for the image.
bool mAutoFree
Whether the transient surface should be freed on destruction.
int getWidth() const override
Gets the width of the image.
void free() override
Frees an image.
SDL_Texture * mTexture
SDL texture for accelerated rendering (primary storage).
void convertToDisplayFormat() override
Converts the image, if possible, to display format.
int getHeight() const override
Gets the height of the image.
virtual SDL_Surface * getSurface() const
Gets the SDL surface for the image.
Color getPixel(int x, int y) override
Gets the color of a pixel at coordinate (x, y) in the image.
SDL_Renderer * mRenderer
SDL renderer associated with the texture.
Unified header for the SDL backend.