ubit
ubackground.hpp
1 /************************************************************************
2  *
3  * ubackground.hpp: Widget background and transparency.
4  * Ubit GUI Toolkit - Version 6
5  * (C) 2009 | Eric Lecolinet | TELECOM ParisTech | http://www.enst.fr/~elc/ubit
6  *
7  * ***********************************************************************
8  * COPYRIGHT NOTICE :
9  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
10  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
11  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
12  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
13  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
14  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
15  * ***********************************************************************/
16 
17 #ifndef ubackground_hpp
18 #define ubackground_hpp 1
19 #include <ubit/uattr.hpp>
20 namespace ubit {
21 
22 
30  class UBackground : public UAttr {
31  public:
32  UCLASS(UBackground)
33 
34  static UBackground none, inherit,
35  metal, velin, white, black, grey, lightgrey, darkgrey, navy, lightblue, blue,
36  red, green, yellow, orange, wheat, teal;
38 
39  ~UBackground();
40 
41  UBackground();
43 
44  UBackground(const UBackground&);
46 
47  UBackground(const UColor&);
49 
50  UBackground(UIma&);
52 
53  UBackground& operator=(const UBackground&);
55 
56  bool operator==(const UBackground&);
58 
59  virtual UBackground& setColor(const UColor& color);
65  virtual UBackground& setRgba(const URgba&);
67 
68  virtual UBackground& setRbgaF(float r, float g, float b, float a = 1.);
70 
71  virtual UBackground& setRbgaI(unsigned int r, unsigned int g, unsigned int b,
72  unsigned int a = 255);
74 
75  virtual UBackground& setNamedColor(const UStr& color_name, float a = 1.);
77 
78  virtual UBackground& setIma(UIma& image, bool tiling = true);
84  UBackground& setTiling(bool);
86 
87  const UColor* getColor() const;
89 
90  const UIma* getIma() const;
92 
93  bool isTiled() const;
95 
96  virtual void update();
97  virtual void putProp(UUpdateContext*, UElem&);
98 
99  // - impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
100 #ifndef NO_DOC
101  UBackground(UColor&, UConst);
102  UBackground(UIma&, UConst);
103  protected:
104  uptr<UColor> pcolor;
105  uptr<UIma> pima;
106  float alpha;
107  bool tiling;
108 #endif
109  };
110 
111  inline UBackground& ubackground() {return *new UBackground();}
113 
114  inline UBackground& ubackground(const UColor& col) {return *new UBackground(col);}
116 
117  inline UBackground& ubackground(UIma& ima) {return *new UBackground(ima);}
119 
120  // ==================================================== Ubit Toolkit =========
125  class UAlpha : public UAttr {
126  public:
127  UCLASS(UAlpha)
128 
129  UAlpha(float = 1.0);
136  operator float() const {return val;}
138 
139  UAlpha& operator=(float v) {return set(v);}
140  UAlpha& operator=(const UFloat& v) {return set(v);}
141  UAlpha& operator=(const UAlpha& v) {return set(v.val);}
142  virtual UAlpha& set(float);
144 
145  bool operator==(float v) const {return val == v;}
146  bool operator==(const UFloat& v) const {return val == v;}
147  bool operator==(const UAlpha& v) const {return val == v.val;}
148 
149  virtual void update();
150  virtual void putProp(UUpdateContext*, UElem&);
151 
152  private:
153  float val;
154  };
155 
156  inline UAlpha& ualpha(float value = 1.0) {return *new UAlpha(value);}
158 
159 }
160 #endif
161 
Base class for attributes.
Definition: uattr.hpp:97
UBackground & setTiling(bool)
sets tiling on or off.
Definition: ubackground.cpp:166
Image.
Definition: uima.hpp:50
Definition: uobject.hpp:282
Widget transparency.
Definition: ubackground.hpp:125
virtual UBackground & setRgba(const URgba &)
changes the background color.
Definition: ubackground.cpp:128
Widget background.
Definition: ubackground.hpp:30
virtual void update()
updates parents graphics.
Definition: ubackground.cpp:174
const UIma * getIma() const
returns the current image if any; null otherwise.
Definition: ubackground.cpp:97
Color attribute of an element or a widget.
Definition: ucolor.hpp:73
const UColor * getColor() const
returns the current color if any; null otherwise.
Definition: ubackground.cpp:96
Specifies a RGBA value for defining UColor(s).
Definition: ucolor.hpp:24
static UBackground teal
predefined background constants.
Definition: ubackground.hpp:34
lightweight general purpose container.
Definition: uelem.hpp:44
virtual UBackground & setIma(UIma &image, bool tiling=true)
changes the background image (WARNING: see details).
Definition: ubackground.cpp:157
Smart Pointer for UObject instances (.
Definition: uobject.hpp:365
virtual void putProp(UUpdateContext *, UElem &)
[impl] changes corresponding value in the UUpdateContext
Definition: ubackground.cpp:178
bool isTiled() const
returns true if the image is tiled.
Definition: ubackground.cpp:98
virtual UBackground & setRbgaI(unsigned int r, unsigned int g, unsigned int b, unsigned int a=255)
changes the background color, arguments are integers in range [0,255].
Definition: ubackground.cpp:139
UBackground()
creates an empty background attribute.
Definition: ubackground.cpp:73
Definition: uupdatecontext.hpp:32
virtual UBackground & setColor(const UColor &color)
changes the background color.
Definition: ubackground.cpp:121
Definition: uhardfont.hpp:31
virtual UBackground & setNamedColor(const UStr &color_name, float a=1.)
changes the background color, arguments are a color name and an alpha value in range [0...
Definition: ubackground.cpp:144
Active Float.
Definition: unumber.hpp:140
virtual UBackground & setRbgaF(float r, float g, float b, float a=1.)
changes the background color, arguments are floats in range [0,1].
Definition: ubackground.cpp:135
Ubit String.
Definition: ustr.hpp:72
bool operator==(const UBackground &)
compares two background attributes.
Definition: ubackground.cpp:100
UBackground & operator=(const UBackground &)
copies a background attribute from another one.
Definition: ubackground.cpp:106