The Gnome Chemistry Utils  0.14.0
item.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 /*
4  * Gnome Chemistry Utils
5  * gccv/item.h
6  *
7  * Copyright (C) 2008-2010 Jean Bréfort <jean.brefort@normalesup.org>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 3 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22  * USA
23  */
24 
25 #ifndef GCCV_ITEM_H
26 #define GCCV_ITEM_H
27 
28 #include <gcu/macros.h>
29 #include <cairo.h>
30 
48 #define GCCV_ITEM_PROP(type,member) \
49 public: \
50  void Set##member (type val) { \
51  m_##member = val; \
52  Invalidate (); \
53  } \
54  type Get##member (void) const {return m_##member;} \
55 private: \
56  type m_##member;
57 
74 #define GCCV_ITEM_POS_PROP(type,member) \
75 public: \
76  void Set##member (type val) { \
77  Invalidate (); \
78  m_##member = val; \
79  BoundsChanged (); \
80  Invalidate (); \
81  } \
82  type Get##member (void) const {return m_##member;} \
83 private: \
84  type m_##member;
85 
86 namespace gccv {
87 
88 class Canvas;
89 class Group;
90 class ItemClient;
91 
100 class Item
101 {
102 public:
108  Item (Canvas *canvas);
115  Item (Group *parent, ItemClient *client = NULL);
119  virtual ~Item ();
120 
129  void GetBounds (double &x0, double &y0, double &x1, double &y1) const;
134  void Invalidate () const;
140  void SetVisible (bool visible);
141 
142  // virtual methods
155  virtual double Distance (double x, double y, Item **item) const;
161  virtual void BuildPath (cairo_t *cr) const;
170  virtual void Draw (cairo_t *cr, bool is_vector) const;
186  virtual bool Draw (cairo_t *cr, double x0, double y0, double x1, double y1, bool is_vector) const;
193  virtual void Move (double x, double y);
197  bool IsTopLevel () const;
198 
199 protected:
203  void BoundsChanged ();
209  virtual void UpdateBounds ();
214  Canvas const *GetCanvas () const {return m_Canvas;}
215 
216 protected:
220  double m_x0;
224  double m_y0;
228  double m_x1;
232  double m_y1;
233 
234 private:
235  Canvas *m_Canvas;
236  bool m_CachedBounds;
237  bool m_NeedsRedraw;
238 
255 GCU_RO_PROP (bool, Visible)
264 GCCV_ITEM_PROP (cairo_operator_t, Operator);
265 };
266 
267 }
268 
269 #endif // GCCV_ITEM_H