PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PColor.h
Go to the documentation of this file.
1 //* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: src/objects/PColor.h
4// Purpose: Lightweight class representing color
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2003-2026 Shane T. Mueller <smueller@obereed.net>
7// License: GPL 2
8//
9//
10//
11// This file is part of the PEBL project.
12//
13// PEBL is free software; you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation; either version 2 of the License, or
16// (at your option) any later version.
17//
18// PEBL 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 General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with PEBL; if not, write to the Free Software
25// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27#ifndef __PCOLOR_H__
28#define __PCOLOR_H__
29
30#include "../base/PEBLObject.h"
31#include <iostream>
32#include <string>
33
37{
38public:
39 PColor();
40 PColor(unsigned int color);//{mRed=0;mGreen=0;mBlue=0;mAlpha=0;SetColorByRGBA(color);}; ///Constructor
41 PColor(int red, int green, int blue, int alpha);
42 PColor(const std::string & colorname);
43
44 PColor(const PColor & pcolor);
45 virtual ~PColor();
46
47 //overloaded generic PEBLObjectBase methods
48 virtual bool SetProperty(std::string, Variant v);
49 virtual ObjectValidationError ValidateProperty(std::string name, Variant v)const;
50 virtual ObjectValidationError ValidateProperty(std::string name)const;
51
52
53 //These will return a single color
54 int GetRed () const;
55 int GetGreen() const;
56 int GetBlue () const;
57 int GetAlpha() const;
58
59 //These will set a single color
60 void SetRed (int color);
61 void SetGreen(int color);
62 void SetBlue (int color);
63 void SetAlpha(int color);
64
66 void SetColorByRGBA(unsigned int color);
67
69 void SetColorByRGBA(int red, int green, int blue, int alpha);
70
72 void SetColorByName(const std::string & colorname);
73
75 unsigned int GetColor() const;
76
78 bool HasChanged() const { return mChanged; }
79 void ClearChanged() { mChanged = false; }
80
81protected:
82
83 virtual std::string ObjectName() const;
84 //Used by overloaded << operator in PComplexData.
85 virtual std::ostream & SendToStream(std::ostream& out) const;
86
87private:
88
89 //Private function that ensures colors are between 0 and 255.
90 int To8BitColor(int color);
91
92 void __SetProps__();
93
94
96 unsigned mRed: 8;
97 unsigned mGreen: 8;
98 unsigned mBlue: 8;
99 unsigned mAlpha: 8;
100
102 bool mChanged;
103};
104
105
106#endif
ObjectValidationError
Definition PEBLObject.h:37
void SetRed(int color)
Definition PColor.cpp:197
int GetRed() const
Definition PColor.cpp:226
virtual std::ostream & SendToStream(std::ostream &out) const
This sends the color descriptions to the specified stream.
Definition PColor.cpp:406
virtual ObjectValidationError ValidateProperty(std::string name, Variant v) const
Definition PColor.cpp:167
void SetColorByName(const std::string &colorname)
Sets color as by its name.
Definition PColor.cpp:257
virtual ~PColor()
Copy constructor.
Definition PColor.cpp:138
int GetAlpha() const
Definition PColor.cpp:229
PColor()
Standard constructor of PColor.
Definition PColor.cpp:44
PColor(const std::string &colorname)
Constructor.
virtual bool SetProperty(std::string, Variant v)
Standard Destructor.
Definition PColor.cpp:153
int GetBlue() const
Definition PColor.cpp:228
void ClearChanged()
Definition PColor.h:79
bool HasChanged() const
Change detection for nested property modifications.
Definition PColor.h:78
int GetGreen() const
Definition PColor.cpp:227
virtual std::string ObjectName() const
Definition PColor.cpp:412
unsigned int GetColor() const
Gets 32-bit unsigned int color.
Definition PColor.cpp:395
void SetGreen(int color)
Definition PColor.cpp:204
void SetColorByRGBA(unsigned int color)
Sets color as a 32-bit unsigned int.
Definition PColor.cpp:235
void SetBlue(int color)
Definition PColor.cpp:211
void SetAlpha(int color)
Definition PColor.cpp:218