FifeGUI 0.2.0
A C++ GUI library designed for games.
backends/sdl3/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// Standard library includes
9#include <string>
10
11// Platform config include
12#include "fifechan/platform.hpp"
13
14// Third-party library includes
15#include <SDL3/SDL.h>
16
17// Project headers (subdirs before local)
18#include "fifechan/color.hpp"
19#include "fifechan/image.hpp"
20
21namespace fcn::sdl3
22{
28 class FIFEGUI_EXT_API Image : public fcn::Image
29 {
30 public:
42 Image(SDL_Surface* surface, bool autoFree, SDL_Renderer* renderer = nullptr);
43
44 ~Image() override;
45
52 virtual SDL_Surface* getSurface() const;
53
59 virtual SDL_Texture* getTexture() const;
60
61 // Inherited from Image
62
63 void free() override;
64
65 int getWidth() const override;
66
67 int getHeight() const override;
68
69 Color getPixel(int x, int y) override;
70
71 void putPixel(int x, int y, Color const & color) override;
72
73 void convertToDisplayFormat() override;
74
75 protected:
77 SDL_Texture* mTexture = nullptr;
78
80 SDL_Renderer* mRenderer = nullptr;
81
83 SDL_Surface* mTransientSurface = nullptr;
84
87 };
88} // namespace fcn::sdl3
89
90#endif // INCLUDE_FIFECHAN_BACKENDS_SDL_SDLIMAGE_HPP_
Color.
Definition color.hpp:58
Abstract holder for image data.
Definition image.hpp:34
void convertToDisplayFormat() override
Converts the image, if possible, to display format.
Color getPixel(int x, int y) override
Gets the color of a pixel at coordinate (x, y) in the image.
virtual SDL_Surface * getSurface() const
Gets the SDL surface for the image.
Image(SDL_Surface *surface, bool autoFree, SDL_Renderer *renderer=nullptr)
Constructor.
int getWidth() const override
Gets the width of the image.
SDL_Texture * mTexture
SDL texture for accelerated rendering (primary storage).
int getHeight() const override
Gets the height of the image.
bool mAutoFree
Whether the transient surface should be freed on destruction.
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).
void free() override
Frees an image.
virtual SDL_Texture * getTexture() const
Gets the SDL texture for the image.
SDL_Renderer * mRenderer
SDL renderer associated with the texture.