libSDL2pp
C++ bindings/wrapper for SDL2
Loading...
Searching...
No Matches
Surface.hh
1/*
2 libSDL2pp - C++ bindings/wrapper for SDL2
3 Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#ifndef SDL2PP_SURFACE_HH
23#define SDL2PP_SURFACE_HH
24
25#include <SDL_stdinc.h>
26#include <SDL_blendmode.h>
27
28#include <SDL2pp/Config.hh>
29#include <SDL2pp/Optional.hh>
30#include <SDL2pp/Rect.hh>
31#include <SDL2pp/Point.hh>
32#include <SDL2pp/Export.hh>
33#include <SDL2pp/Color.hh>
34
35struct SDL_Surface;
36struct SDL_PixelFormat;
37
38namespace SDL2pp {
39
40class RWops;
41
53class SDL2PP_EXPORT Surface {
54private:
55 SDL_Surface* surface_;
56
57public:
70 class LockHandle {
71 friend class Surface;
72 private:
73 Surface* surface_;
74
75 private:
84 explicit LockHandle(Surface* surface);
85
86 public:
94 LockHandle();
95
104 ~LockHandle();
105
112 LockHandle(LockHandle&& other) noexcept;
113
122 LockHandle& operator=(LockHandle&& other) noexcept;
123
130 LockHandle(const LockHandle& other) = delete;
131
138 LockHandle& operator=(const LockHandle& other) = delete;
139
146 void* GetPixels() const;
147
155 int GetPitch() const;
156
163 const SDL_PixelFormat& GetFormat() const;
164 };
165
166public:
173 explicit Surface(SDL_Surface* surface);
174
192 Surface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
193
212 Surface(void* pixels, int width, int height, int depth, int pitch, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
213
214#ifdef SDL2PP_WITH_IMAGE
223 explicit Surface(RWops& rwops);
224
233 explicit Surface(const std::string& filename);
234#endif
235
242 virtual ~Surface();
243
250 Surface(Surface&& other) noexcept;
251
260 Surface& operator=(Surface&& other) noexcept;
261
268 Surface(const Surface&) = delete;
269
276 Surface& operator=(const Surface&) = delete;
277
284 SDL_Surface* Get() const;
285
297 Surface Convert(const SDL_PixelFormat& format);
298
310 Surface Convert(Uint32 pixel_format);
311
324 void Blit(const Optional<Rect>& srcrect, Surface& dst, const Rect& dstrect);
325
338 void BlitScaled(const Optional<Rect>& srcrect, Surface& dst, const Optional<Rect>& dstrect);
339
350 LockHandle Lock();
351
360 Rect GetClipRect() const;
361
372 Uint32 GetColorKey() const;
373
384 Uint8 GetAlphaMod() const;
385
396 SDL_BlendMode GetBlendMode() const;
397
409 Color GetColorAndAlphaMod() const;
410
423 void GetColorMod(Uint8& r, Uint8& g, Uint8& b) const;
424
437 Surface& SetClipRect(const Optional<Rect>& rect = NullOpt);
438
452 Surface& SetColorKey(bool flag, Uint32 key);
453
466 Surface& SetAlphaMod(Uint8 alpha = 255);
467
480 Surface& SetBlendMode(SDL_BlendMode blendMode);
481
496 Surface& SetColorMod(Uint8 r = 255, Uint8 g = 255, Uint8 b = 255);
497
511 Surface& SetColorAndAlphaMod(const Color& color);
512
525 Surface& SetRLE(bool flag);
526
538 Surface& FillRect(const Optional<Rect>& rect, Uint32 color);
539
552 Surface& FillRects(const Rect* rects, int count, Uint32 color);
553
560 int GetWidth() const;
561
568 int GetHeight() const;
569
576 Point GetSize() const;
577
587 Uint32 GetFormat() const;
588};
589
590}
591
592#endif
RGB color with Alpha.
Definition: Color.hh:48
2D point
Definition: Point.hh:51
I/O abstraction.
Definition: RWops.hh:156
2D rectangle
Definition: Rect.hh:50
SDL2pp::Surface lock.
Definition: Surface.hh:70
LockHandle(const LockHandle &other)=delete
Deleted copy constructor.
LockHandle & operator=(const LockHandle &other)=delete
Deleted assignment operator.
Image stored in system memory with direct access to pixel data.
Definition: Surface.hh:53
Surface & operator=(const Surface &)=delete
Deleted assignment operator.
Surface(const Surface &)=delete
Deleted copy constructor.