summaryrefslogtreecommitdiff
path: root/plugingui
diff options
context:
space:
mode:
authorAndré Nusser <andre.nusser@googlemail.com>2018-06-09 12:46:09 +0200
committerAndré Nusser <andre.nusser@googlemail.com>2018-06-09 12:51:08 +0200
commitf602f5ffd6959f4da6de0dd61ea1b60025d12294 (patch)
tree7f06de633263c23a87d0278a93825d85fcb9c1f6 /plugingui
parent21554166b294470ac593a1a90c82d1b4fe75c61e (diff)
Refactor Colour.
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/colour.cc58
-rw-r--r--plugingui/colour.h9
2 files changed, 15 insertions, 52 deletions
diff --git a/plugingui/colour.cc b/plugingui/colour.cc
index dff1a82..9abe7eb 100644
--- a/plugingui/colour.cc
+++ b/plugingui/colour.cc
@@ -32,79 +32,41 @@ namespace GUI {
Colour::Colour()
{
- data = new float[4];
- data[0] = data[1] = data[2] = data[3] = 1.0f;
+ data = {1.0f, 1.0f, 1.0f, 1.0f};
}
Colour::Colour(float grey, float a)
{
- data = new float[4];
-
- data[0] = data[1] = data[2] = grey;
- data[3] = a;
+ data = {grey, grey, grey, a};
}
Colour::Colour(float r, float g, float b, float a)
{
- data = new float[4];
-
- data[0] = r;
- data[1] = g;
- data[2] = b;
- data[3] = a;
+ data = {r, g, b, a};
}
Colour::Colour(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a)
: Colour(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f)
{}
-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));
+ data = other.data;
}
-Colour::~Colour()
+Colour& Colour::operator=(const Colour& other)
{
- if(data)
- {
- delete[] data;
- }
+ data = other.data;
}
-Colour& Colour::operator=(const Colour& other)
+bool Colour::operator==(const Colour& other) const
{
- std::memcpy(data, other.data, 4 * sizeof(float));
- return *this;
+ return data == other.data;
}
-Colour& Colour::operator=(Colour&& other)
+bool Colour::operator!=(const Colour& other) const
{
- if(data)
- {
- delete[] data;
- }
-
- data = other.data;
- other.data = nullptr;
- return *this;
+ return !(*this == other);
}
} // GUI::
diff --git a/plugingui/colour.h b/plugingui/colour.h
index 26f424c..3a135fc 100644
--- a/plugingui/colour.h
+++ b/plugingui/colour.h
@@ -26,6 +26,7 @@
*/
#pragma once
+#include <array>
#include <cstdint>
namespace GUI
@@ -37,12 +38,12 @@ public:
Colour(float grey, float alpha = 1.0f);
Colour(float red, float green, float blue, float alpha = 1.0f);
Colour(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a);
- Colour(Colour&& other);
Colour(const Colour& other);
- ~Colour();
Colour& operator=(const Colour& other);
- Colour& operator=(Colour&& other);
+
+ bool operator==(const Colour& other) const;
+ bool operator!=(const Colour& other) const;
inline float red() const { return data[0]; }
inline float green() const { return data[1]; }
@@ -50,7 +51,7 @@ public:
inline float alpha() const { return data[3]; }
private:
- float *data{nullptr};
+ std::array<float, 4> data;
};
} // GUI::