Pioneer
Loading...
Searching...
No Matches
SDLWrappers.h
Go to the documentation of this file.
1// Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
2// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3
4#ifndef _SDLWRAPPERS_H
5#define _SDLWRAPPERS_H
6
7#include "SmartPtr.h"
8#include <SDL_surface.h>
9#include <string>
10
11namespace FileSystem {
12 class FileSource;
13}
14
15struct SDL_Surface;
16
17class SDLSurfacePtr : public SmartPtrBase<SDLSurfacePtr, SDL_Surface> {
19
20private:
21 explicit SDLSurfacePtr(SDL_Surface *p) :
22 base_type(p) {}
23
24public:
25 static SDLSurfacePtr WrapNew(SDL_Surface *p) { return SDLSurfacePtr(p); }
26 static SDLSurfacePtr WrapCopy(SDL_Surface *p)
27 {
28 if (p) {
29 p->refcount += 1;
30 }
31 return SDLSurfacePtr(p);
32 }
33
36 base_type(b.Get())
37 {
38 if (this->m_ptr) this->m_ptr->refcount += 1;
39 }
40 // ~SDLSurfacePtr() { SDL_FreeSurface(this->Release()); }
41 // workaround for SDL 2.0.6 FreeSurface bug
43 {
44 SDL_Surface *p = this->Release();
45 if (p && --p->refcount <= 0) SDL_FreeSurface(p);
46 }
47
49 {
50 SDLSurfacePtr(b).Swap(*this);
51 return *this;
52 }
53
54 bool Unique() const
55 {
56 assert(this->m_ptr);
57 return (this->m_ptr->refcount == 1);
58 }
59};
60
61SDLSurfacePtr LoadSurfaceFromFile(const std::string &fname, FileSystem::FileSource &source);
62SDLSurfacePtr LoadSurfaceFromFile(const std::string &fname);
63
64#endif
SDLSurfacePtr LoadSurfaceFromFile(const std::string &fname, FileSystem::FileSource &source)
Definition SDLWrappers.cpp:9
Definition FileSystem.h:197
Definition SDLWrappers.h:17
static SDLSurfacePtr WrapNew(SDL_Surface *p)
Definition SDLWrappers.h:25
static SDLSurfacePtr WrapCopy(SDL_Surface *p)
Definition SDLWrappers.h:26
SDLSurfacePtr & operator=(const SDLSurfacePtr &b)
Definition SDLWrappers.h:48
~SDLSurfacePtr()
Definition SDLWrappers.h:42
SDLSurfacePtr()
Definition SDLWrappers.h:34
bool Unique() const
Definition SDLWrappers.h:54
SDLSurfacePtr(const SDLSurfacePtr &b)
Definition SDLWrappers.h:35
Definition SmartPtr.h:18
return p
Definition SmartPtr.h:83
SDL_Surface * Get() const
Definition SmartPtr.h:37
Definition CityOnPlanet.h:27