zenilib: zenilib/jni/external/zenilib/zeni/Color.cpp Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Color.cpp
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2 * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3 *
4 * zenilib is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * zenilib is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <zeni.h>
19
20 namespace Zeni {
21
22 Color::Color()
23 : r(1.0f),
24 g(1.0f),
25 b(1.0f),
26 a(1.0f)
27 {
28 }
29
30 Color::Color(const float &a_, const float &r_, const float &g_, const float &b_)
31 : r(r_),
32 g(g_),
33 b(b_),
34 a(a_)
35 {
36 }
37
38 Color::Color(const Uint32 &argb)
39 : r(((argb >> 16) & 0xFF) / 256.0f),
40 g(((argb >> 8) & 0xFF) / 256.0f),
41 b((argb & 0xFF) / 256.0f),
42 a(((argb >> 24) & 0xFF) / 256.0f)
43 {
44 }
45
46 Color Color::interpolate_to(const float &rhs_part, const Color &rhs) const {
47 float lhs_part = 1.0f - rhs_part;
48 return Color(lhs_part * a + rhs_part * rhs.a,
49 lhs_part * r + rhs_part * rhs.r,
50 lhs_part * g + rhs_part * rhs.g,
51 lhs_part * b + rhs_part * rhs.b);
52 }
53
54 bool Color::operator<(const Color &rhs) const {
55 return a < rhs.a || (a == rhs.a &&
56 (r < rhs.r || (r == rhs.r &&
57 (g < rhs.g || (g == rhs.g &&
58 b < rhs.b)))));
59 }
60
61 bool Color::operator==(const Color &rhs) const {
62 return a == rhs.a &&
63 r == rhs.r &&
64 g == rhs.g &&
65 b == rhs.b;
66 }
67
68 std::ostream & serialize(std::ostream &os, const Color &value) {
69 return serialize(serialize(serialize(serialize(os, value.a), value.r), value.g), value.b);
70 }
71
72 std::istream & unserialize(std::istream &is, Color &value) {
73 return unserialize(unserialize(unserialize(unserialize(is, value.a), value.r), value.g), value.b);
74 }
75
76 }
g
GLboolean GLboolean g
Definition: glew.h:8736
f
GLclampf f
Definition: glew.h:3390
Zeni::Color::operator<
bool operator<(const Color &rhs) const
To provide an arbitrary total ordering. Do not depend on it remaining the same in the future...
Definition: Color.cpp:54
a
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:8736
Zeni::unserialize
std::istream & unserialize(std::istream &is, Color &value)
Definition: Color.cpp:72
Zeni::serialize
std::ostream & serialize(std::ostream &os, const Color &value)
Definition: Color.cpp:68
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:145
Zeni::Color::a
float a
Definition: Color.h:69
Zeni::Color::interpolate_to
Color interpolate_to(const float &rhs_part, const Color &rhs) const
Get a color that is inbetween this color and another color.
Definition: Color.cpp:46
Zeni::Color::b
float b
Definition: Color.h:68
value
EGLSurface EGLint void ** value
Definition: eglext.h:301
Zeni::Color::Color
Color()
Set the red, green, blue, and alpha channels using the stored type, float.
Definition: Color.cpp:22
Zeni::Color::operator==
bool operator==(const Color &rhs) const
A simple equality test. Close hits are misses.
Definition: Color.cpp:61
r
GLdouble GLdouble GLdouble r
Definition: glew.h:1392
b
GLdouble GLdouble GLdouble b
Definition: glew.h:8383
Zeni::Color::g
float g
Definition: Color.h:67
zeni.h
Zeni::Color::r
float r
Definition: Color.h:66
Zeni::Color
Color.
Definition: Color.h:41