diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-06-04 18:36:00 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-06-04 18:37:42 +0200 |
commit | 3e747d769f63fde60f6095bd1ae7c651d4237f39 (patch) | |
tree | 92a5955413dac91972edf32b1824739038704720 /plugingui/colour.cc | |
parent | 538abc6cd8f4a5996640ec9800815fbac5c34b26 (diff) |
Make Colour movabl;e and make Image contain a vector of Colour instead of raw char data.
Diffstat (limited to 'plugingui/colour.cc')
-rw-r--r-- | plugingui/colour.cc | 70 |
1 files changed, 63 insertions, 7 deletions
diff --git a/plugingui/colour.cc b/plugingui/colour.cc index 88bd75a..d8cd8e9 100644 --- a/plugingui/colour.cc +++ b/plugingui/colour.cc @@ -26,25 +26,81 @@ */ #include "colour.h" +#include <cstring> + namespace GUI { Colour::Colour() { - red = blue = green = alpha = 1.0; + data = new float[4]; + data[0] = data[1] = data[2] = data[3] = 1.0f; } Colour::Colour(float grey, float a) { - red = green = blue = grey; - alpha = a; + data = new float[4]; + + data[0] = data[1] = data[2] = grey; + data[3] = a; } Colour::Colour(float r, float g, float b, float a) { - red = r; - green = g; - blue = b; - alpha = a; + data = new float[4]; + + data[0] = r; + data[1] = g; + data[2] = b; + data[3] = a; +} + +Colour::Colour(Colour&& other) +{ + if(data) + { + delete[] data; + } + + data = other.data; + other.data = nullptr; +} + +Colour::Colour(const Colour& other) +{ + if(data) + { + delete[] data; + } + + data = new float[4]; + + std::memcpy(data, other.data, 4 * sizeof(float)); +} + +Colour::~Colour() +{ + if(data) + { + delete[] data; + } +} + +Colour& Colour::operator=(const Colour& other) +{ + std::memcpy(data, other.data, 4 * sizeof(float)); + return *this; +} + +Colour& Colour::operator=(Colour&& other) +{ + if(data) + { + delete[] data; + } + + data = other.data; + other.data = nullptr; + return *this; } } // GUI:: |