mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-26 04:50:38 +02:00
Implement the standard set of copy and move operations for Surface
This commit is contained in:
parent
614f74a63d
commit
5a281cf661
@ -28,6 +28,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -94,22 +95,44 @@ Surface::Surface(SDL_Surface *raw_, bool freeWhenDone_)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface::Surface(Surface *s) {
|
Surface::Surface(Surface const& other)
|
||||||
raw = SDL_ConvertSurface(s->raw, s->raw->format, SDL_SWSURFACE);
|
: Surface(SDL_ConvertSurface(
|
||||||
|
other.raw, other.raw->format, SDL_SWSURFACE), true)
|
||||||
|
{
|
||||||
// Note: A bug in SDL_ConvertSurface() leaves the per-surface alpha
|
// Note: A bug in SDL_ConvertSurface() leaves the per-surface alpha
|
||||||
// undefined when converting from RGBA to RGBA. This can cause
|
// undefined when converting from RGBA to RGBA. This can cause
|
||||||
// problems if the surface is later converted to a format without
|
// problems if the surface is later converted to a format without
|
||||||
// an alpha channel, such as the display format.
|
// an alpha channel, such as the display format.
|
||||||
raw->format->alpha = s->raw->format->alpha;
|
raw->format->alpha = other.raw->format->alpha;
|
||||||
freeWhenDone = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface::~Surface() {
|
Surface::Surface(Surface&& other)
|
||||||
|
: raw(other.raw)
|
||||||
|
, freeWhenDone(other.freeWhenDone)
|
||||||
|
{
|
||||||
|
other.raw = nullptr;
|
||||||
|
other.freeWhenDone = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Surface::~Surface()
|
||||||
|
{
|
||||||
if (freeWhenDone) {
|
if (freeWhenDone) {
|
||||||
SDL_FreeSurface(raw);
|
SDL_FreeSurface(raw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Surface& Surface::operator=(Surface other)
|
||||||
|
{
|
||||||
|
swap(other);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Surface::swap(Surface& other)
|
||||||
|
{
|
||||||
|
std::swap(raw, other.raw);
|
||||||
|
std::swap(freeWhenDone, other.freeWhenDone);
|
||||||
|
}
|
||||||
|
|
||||||
void Surface::convertToDisplayFormat() {
|
void Surface::convertToDisplayFormat() {
|
||||||
SDL_Surface *newSurface = SDL_DisplayFormat(raw);
|
SDL_Surface *newSurface = SDL_DisplayFormat(raw);
|
||||||
if (newSurface) {
|
if (newSurface) {
|
||||||
|
@ -52,8 +52,14 @@ public:
|
|||||||
static Surface *loadImage(const std::string &img,
|
static Surface *loadImage(const std::string &img,
|
||||||
const std::string &skin="", bool loadAlpha=true);
|
const std::string &skin="", bool loadAlpha=true);
|
||||||
|
|
||||||
Surface(Surface *s);
|
// TODO: Remove this once naked Surface pointers are no longer in use.
|
||||||
|
Surface(Surface *other) : Surface(*other) {}
|
||||||
|
|
||||||
|
Surface(Surface const& other);
|
||||||
|
Surface(Surface&& other);
|
||||||
~Surface();
|
~Surface();
|
||||||
|
Surface& operator=(Surface other);
|
||||||
|
void swap(Surface& other);
|
||||||
|
|
||||||
/** Converts the underlying surface to the same pixel format as the frame
|
/** Converts the underlying surface to the same pixel format as the frame
|
||||||
* buffer, for faster blitting. This removes the alpha channel if the
|
* buffer, for faster blitting. This removes the alpha channel if the
|
||||||
|
Loading…
Reference in New Issue
Block a user