tbx  0.7.3
itemrenderer.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 /*
26  * itemrenderer.h
27  *
28  * Created on: 24 Mar 2010
29  * Author: alanb
30  */
31 
32 #ifndef ITEMRENDERER_H_
33 #define ITEMRENDERER_H_
34 
35 #include <string>
36 #include "../bbox.h"
37 #include "../redrawlistener.h"
38 #include "viewvalue.h"
39 
40 namespace tbx
41 {
42  class Sprite;
43 };
44 
45 namespace tbx {
46 
47 namespace view {
48 
54 {
55 public:
56  ItemRenderer() {};
57  virtual ~ItemRenderer() {};
58 
59 public:
63  struct Info
64  {
69 
74 
79 
83  unsigned int index;
84 
88  bool selected;
89 
95  Info(const tbx::RedrawEvent &r) : redraw(r) {};
96  };
97 
108  virtual void render(const ItemRenderer::Info &info) = 0;
109 
113  virtual unsigned int width(unsigned int index) const = 0;
114 
118  virtual unsigned int height(unsigned int index) const = 0;
119 
125  virtual Size size(unsigned int index) const = 0;
126 
138  virtual bool hit_test(unsigned int index, const Size &size, const Point &pos) const {return true;}
139 
151  virtual bool intersects(unsigned int index, const Size &size, const BBox &box) const {return true;}
152 
153 };
154 
159 template<class T> class TypedItemRenderer : public ItemRenderer
160 {
161 protected:
163 public:
170 };
171 
178 class WimpFontItemRenderer : public TypedItemRenderer<std::string>
179 {
180 public:
187  : TypedItemRenderer<std::string>(vv)
188  {
189  }
190 
191  virtual ~WimpFontItemRenderer() {};
192 
198  virtual void render(const ItemRenderer::Info &info);
199 
200 
206  virtual unsigned int width(unsigned int index) const;
207 
213  virtual unsigned int height(unsigned int index) const {return 40;}
214 
220  virtual Size size(unsigned int index) const;
221 
222 };
223 
230 class SpriteItemRenderer : public TypedItemRenderer<tbx::Sprite *>
231 {
232 public:
239  TypedItemRenderer<tbx::Sprite *>(vv) {};
240 
241  virtual ~SpriteItemRenderer() {};
242 
246  virtual void render(const ItemRenderer::Info &info);
247 
251  virtual unsigned int width(unsigned int index) const;
252 
256  virtual unsigned int height(unsigned int index) const;
257 
261  virtual Size size(unsigned int index) const;
262 };
263 
264 }
265 
266 }
267 
268 #endif /* ITEMRENDERER_H_ */
Item renderer to render a sprite in a cell.
Definition: itemrenderer.h:230
Class to represent a two-dimensional size.
Definition: size.h:34
const tbx::RedrawEvent & redraw
Redraw event object from FixedCellView.
Definition: itemrenderer.h:68
virtual Size size(unsigned int index) const
Called to get the size of the cell.
Definition: itemrenderer.cc:76
virtual void render(const ItemRenderer::Info &info)
Render text in black using current wimp font.
Definition: itemrenderer.cc:43
virtual unsigned int width(unsigned int index) const =0
Used to measure the width of a column.
virtual unsigned int width(unsigned int index) const
Used to measure the width of a column.
Definition: itemrenderer.cc:64
virtual unsigned int width(unsigned int index) const
Used to measure the width of a column.
Definition: itemrenderer.cc:93
Class to represent a two dimensional bounding box.
Definition: bbox.h:37
tbx::Point screen
Bottom left of items bounding box in screen coordinates.
Definition: itemrenderer.h:78
Base class to provide a value of a given type for an item view.
Definition: viewvalue.h:39
TypedItemRenderer(ItemViewValue< T > *vp)
Construct the item view renderer.
Definition: itemrenderer.h:169
virtual void render(const ItemRenderer::Info &info)=0
Called to render each item that needs drawing.
bool selected
Is the item selected.
Definition: itemrenderer.h:88
unsigned int index
zero based index of item to redraw
Definition: itemrenderer.h:83
Base class to render an indexed item.
Definition: itemrenderer.h:53
Common base class for the UserSprite and WimpSprite classes.
Definition: sprite.h:299
Base class for item renderer that work on a specific type and use an ItemViewValue object to return t...
Definition: itemrenderer.h:159
Class to represent a position in two dimensional space.
Definition: point.h:36
virtual Size size(unsigned int index) const
Called to get the size of the cell.
Definition: itemrenderer.cc:111
Event passed to redraw listener to give details on the area that needs a redraw.
Definition: redrawlistener.h:43
tbx::BBox bounds
Bounding box of cell to redraw in work area coordinates.
Definition: itemrenderer.h:73
WimpFontItemRenderer(ItemViewValue< std::string > *vv)
Construct with object to give value to render.
Definition: itemrenderer.h:186
virtual bool hit_test(unsigned int index, const Size &size, const Point &pos) const
Check if the point given hits content of the cell rather then a margin or background.
Definition: itemrenderer.h:138
virtual unsigned int height(unsigned int index) const
Used to measure the height.
Definition: itemrenderer.cc:102
virtual Size size(unsigned int index) const =0
Called to get the size of the item.
SpriteItemRenderer(ItemViewValue< tbx::Sprite * > *vv)
Construct with object to give value to render.
Definition: itemrenderer.h:238
Information on what needs to be redrawn.
Definition: itemrenderer.h:63
virtual unsigned int height(unsigned int index) const =0
Used to measure the height of column.
ItemViewValue< T > * _value_provider
Object to retrieve the value for a rendered.
Definition: itemrenderer.h:162
virtual unsigned int height(unsigned int index) const
Wimp font height is always 40.
Definition: itemrenderer.h:213
virtual bool intersects(unsigned int index, const Size &size, const BBox &box) const
Check if the given rectangle intersects the content of the cell rather than a margin or background...
Definition: itemrenderer.h:151
Renderer base class to put text in a cell using the current wimp font.
Definition: itemrenderer.h:178
Info(const tbx::RedrawEvent &r)
Construct from Redraw event.
Definition: itemrenderer.h:95
virtual void render(const ItemRenderer::Info &info)
Render the sprite to the screen.
Definition: itemrenderer.cc:84