tbx  0.7.3
iconpainter.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #ifndef ICONPAINTER_H_
26 #define ICONPAINTER_H_
27 
28 #include "redrawlistener.h"
29 #include <string>
30 
31 namespace tbx {
32 
33 class SpriteArea;
34 
44 {
45 private:
46  unsigned int _flags;
47  BBox _bounds;
48  std::string _text;
49  std::string _validation;
50  SpriteArea *_sprite_area;
51 
52 public:
53  IconPainter();
54  virtual ~IconPainter();
55 
61  BBox &bounds() {return _bounds;}
62 
66  const BBox &bounds() const {return _bounds;}
67 
68  IconPainter &text(std::string text);
69  IconPainter &validation(std::string val);
70  IconPainter &sprite(std::string sprite);
74 
80  IconPainter &text_icon(bool t) {if (t) _flags |= 1; else _flags &=~1; return *this;}
81 
85  bool text_icon() const {return (_flags & 1)!=0;}
86 
90  IconPainter &sprite_icon(bool s) {if (s) _flags |= 2; else _flags &=~2; return *this;}
94  bool sprite_icon() const {return (_flags & 2)!=0;}
95 
99  IconPainter &border(bool f) {if (f) _flags |= 4; else _flags &=~4; return *this;}
105  IconPainter &hcentred(bool f) {if (f) _flags |= 8; else _flags &=~8; return *this;}
111  IconPainter &vcentred(bool f) {if (f) _flags |= (1<<4); else _flags &=~(1<<4); return *this;}
117  IconPainter &filled(bool f) {if (f) _flags |= (1<<5); else _flags &=~(1<<5); return *this;}
123  IconPainter &rjust(bool f) {if (f) _flags |= (1<<9); else _flags &=~(1<<9); return *this;}
129  IconPainter &half_sprite(bool f) {if (f) _flags |= (1<<11); else _flags &=~(1<<11); return *this;}
135  IconPainter &inverted(bool f) {if (f) _flags |= (1<<21); else _flags &=~(1<<21); return *this;}
141  IconPainter &shaded(bool f) {if (f) _flags |= (1<<22); else _flags &=~(1<<28); return *this;}
147  IconPainter &foreground(unsigned int col) {_flags = (_flags & ~0x0F000000) | (col << 24); return *this;}
153  IconPainter &background(unsigned int col) {_flags = (_flags & ~0xF0000000) | (col << 28); return *this;}
154 
160 
166 
172 
193 
199 
200  virtual void redraw(const RedrawEvent &event);
201 };
202 
203 }
204 
205 #endif /* ICONPAINTER_H_ */
IconPainter & shaded(bool f)
Set shaded flag.
Definition: iconpainter.h:141
IconPainter & text_and_sprite_right()
Text and sprite right justified, text at bottom, sprite at top for text and sprite icons...
Definition: iconpainter.h:165
IconPainter & text(std::string text)
Set the text for the icon painter.
Definition: iconpainter.cc:54
IconPainter & use_client_sprite_area()
Use application client area for the sprite.
Definition: iconpainter.cc:122
IconPainter & validation(std::string val)
Set the validation string for the icon.
Definition: iconpainter.cc:68
Class to represent a two dimensional bounding box.
Definition: bbox.h:37
Class to draw an icon in a redraw listener.
Definition: iconpainter.h:43
IconPainter & filled(bool f)
Set filled flag.
Definition: iconpainter.h:117
virtual void redraw(const RedrawEvent &event)
Redraw the icon.
Definition: iconpainter.cc:134
IconPainter & use_wimp_sprite_area()
Use sprite from WIMP sprite pool.
Definition: iconpainter.cc:109
IconPainter & on_top_text_and_sprite_centred()
text and sprite centred (text on top) text and sprite centred for text and sprite icons...
Definition: iconpainter.h:192
bool text_icon() const
Check if this is a text icon.
Definition: iconpainter.h:85
IconPainter & text_icon(bool t)
Set icon as a text icon.
Definition: iconpainter.h:80
IconPainter & border(bool f)
Add a border to the icon.
Definition: iconpainter.h:99
IconPainter & background(unsigned int col)
Set background colour of sprite.
Definition: iconpainter.h:153
IconPainter()
Construct an icon painter.
Definition: iconpainter.cc:39
IconPainter & hcentred(bool f)
Set horizontally centred flag.
Definition: iconpainter.h:105
const BBox & bounds() const
return the bounds of the icon in work area coordinates
Definition: iconpainter.h:66
IconPainter & sprite(std::string sprite)
Set the sprite for the icon.
Definition: iconpainter.cc:80
virtual ~IconPainter()
Icon painter destructor.
Definition: iconpainter.cc:46
IconPainter & top_text_and_sprite_centred()
text and sprite centred text at top, sprite at bottom for text and sprite icons.
Definition: iconpainter.h:187
Event passed to redraw listener to give details on the area that needs a redraw.
Definition: redrawlistener.h:43
IconPainter & half_sprite(bool f)
Set show sprite at half size flag.
Definition: iconpainter.h:129
IconPainter & vcentred(bool f)
Set vertically centred flag.
Definition: iconpainter.h:111
IconPainter & inverted(bool f)
Set inverted flag.
Definition: iconpainter.h:135
IconPainter & sprite_icon(bool s)
Set icon as a sprite icon.
Definition: iconpainter.h:90
IconPainter & text_12_sprite_left()
Sprite at left, text +12 units right of it, text and sprite vertically centred for text and sprite ic...
Definition: iconpainter.h:171
IconPainter & text_and_sprite_centred()
text and sprite centred, text at bottom, sprite at top for text and sprite icons. ...
Definition: iconpainter.h:182
Redraw event listener.
Definition: redrawlistener.h:75
IconPainter & text_left_sprite_right()
text at left, sprite at right, text and sprite vertically centred for text and sprite icons...
Definition: iconpainter.h:177
bool sprite_icon() const
Check if this is a sprite icon.
Definition: iconpainter.h:94
IconPainter & text_and_sprite_left()
Text and sprite left justified, text at bottom, sprite at top for text and sprite icons...
Definition: iconpainter.h:159
IconPainter & text_right_sprite_left()
text at right, sprite at left text and sprite centred for text and sprite icons.
Definition: iconpainter.h:198
IconPainter & rjust(bool f)
Set right justified flag.
Definition: iconpainter.h:123
A SpriteArea holds zero or more user sprites.
Definition: sprite.h:231
IconPainter & foreground(unsigned int col)
Set foreground colour of sprite.
Definition: iconpainter.h:147
BBox & bounds()
Reference to the bounds of the icon.
Definition: iconpainter.h:61
IconPainter & sprite_area(SpriteArea *sprite_area)
Set the sprite area to use for the icon.
Definition: iconpainter.cc:96