added ImageLock RAII class for SDL Surface locking

This commit is contained in:
Bob Polis 2020-10-24 18:02:43 +02:00
parent 582de4df22
commit ec465820e8
2 changed files with 52 additions and 0 deletions

20
ImageLock.cpp Normal file
View File

@ -0,0 +1,20 @@
//
// ImageLock.cpp
// libscgui
//
// Created by Bob Polis at 2020-10-24
// Copyright (c) 2020 SwiftCoder. All rights reserved.
//
#include "ImageLock.hpp"
#include "Image.hpp"
using namespace sc::gui;
ImageLock::ImageLock(const Image& image) : _image {image} {
SDL_LockSurface(image.surface());
}
ImageLock::~ImageLock() {
SDL_UnlockSurface(_image.surface());
}

32
ImageLock.hpp Normal file
View File

@ -0,0 +1,32 @@
//
// ImageLock.hpp
// libscgui
//
// Created by Bob Polis at 2020-10-24
// Copyright (c) 2020 SwiftCoder. All rights reserved.
//
#ifndef _ImageLock_H_
#define _ImageLock_H_
namespace sc {
namespace gui {
class Image;
class ImageLock {
public:
ImageLock(const Image& image);
~ImageLock();
ImageLock(const ImageLock&) = delete;
ImageLock& operator=(const ImageLock&) = delete;
ImageLock(ImageLock&&) = delete;
ImageLock& operator=(ImageLock&&) = delete;
private:
const Image& _image;
};
}
}
#endif // _ImageLock_H_