1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /***************************************************************************
3  *            colour.cc
4  *
5  *  Fri Oct 14 09:38:28 CEST 2011
6  *  Copyright 2011 Bent Bisballe Nyeng
7  *  deva@aasimon.org
8  ****************************************************************************/
9 
10 /*
11  *  This file is part of DrumGizmo.
12  *
13  *  DrumGizmo is free software; you can redistribute it and/or modify
14  *  it under the terms of the GNU Lesser General Public License as published by
15  *  the Free Software Foundation; either version 3 of the License, or
16  *  (at your option) any later version.
17  *
18  *  DrumGizmo is distributed in the hope that it will be useful,
19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  *  GNU Lesser General Public License for more details.
22  *
23  *  You should have received a copy of the GNU Lesser General Public License
24  *  along with DrumGizmo; if not, write to the Free Software
25  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
26  */
27 #include "colour.h"
28 
29 #include <cstring>
30 
31 namespace GUI
32 {
33 
Colour()34 Colour::Colour()
35 {
36 }
37 
Colour(float grey,float a)38 Colour::Colour(float grey, float a)
39 	: pixel({{(std::uint8_t)(grey * 255),
40 	          (std::uint8_t)(grey * 255),
41 	          (std::uint8_t)(grey * 255),
42 	          (std::uint8_t)(a * 255)}})
43 {
44 }
45 
Colour(float r,float g,float b,float a)46 Colour::Colour(float r, float g, float b, float a)
47 	: pixel({{(std::uint8_t)(r * 255),
48 	          (std::uint8_t)(g * 255),
49 	          (std::uint8_t)(b * 255),
50 	          (std::uint8_t)(a * 255)}})
51 {
52 }
53 
Colour(std::uint8_t r,std::uint8_t g,std::uint8_t b,std::uint8_t a)54 Colour::Colour(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a)
55 	: pixel({{r, g, b, a}})
56 {
57 }
58 
Colour(const Colour & other)59 Colour::Colour(const Colour& other)
60 	: pixel(other.pixel)
61 {
62 }
63 
operator =(const Colour & other)64 Colour& Colour::operator=(const Colour& other)
65 {
66 	pixel = other.pixel;
67 	return *this;
68 }
69 
operator ==(const Colour & other) const70 bool Colour::operator==(const Colour& other) const
71 {
72 	return pixel[0] == other.pixel[0] &&
73 	       pixel[1] == other.pixel[1] &&
74 	       pixel[2] == other.pixel[2];
75 }
76 
operator !=(const Colour & other) const77 bool Colour::operator!=(const Colour& other) const
78 {
79 	return !(*this == other);
80 }
81 
82 } // GUI::
83