From ec465820e8b5bdaee4d5dbe86b693936143eaae7 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Sat, 24 Oct 2020 18:02:43 +0200 Subject: [PATCH] added ImageLock RAII class for SDL Surface locking --- ImageLock.cpp | 20 ++++++++++++++++++++ ImageLock.hpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 ImageLock.cpp create mode 100644 ImageLock.hpp diff --git a/ImageLock.cpp b/ImageLock.cpp new file mode 100644 index 0000000..fe9c9ee --- /dev/null +++ b/ImageLock.cpp @@ -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()); +} diff --git a/ImageLock.hpp b/ImageLock.hpp new file mode 100644 index 0000000..17d9e1a --- /dev/null +++ b/ImageLock.hpp @@ -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_