item.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /* 
00004  * Gnome Chemistry Utils
00005  * gccv/item.h 
00006  *
00007  * Copyright (C) 2008 Jean Bréfort <jean.brefort@normalesup.org>
00008  *
00009  * This program is free software; you can redistribute it and/or 
00010  * modify it under the terms of the GNU General Public License as 
00011  * published by the Free Software Foundation; either version 2 of the
00012  * License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00022  * USA
00023  */
00024 
00025 #ifndef GCCV_ITEM_H
00026 #define GCCV_ITEM_H
00027 
00028 #include <gcu/macros.h>
00029 #include <cairo.h>
00030 
00052 #define GCCV_ITEM_PROP(type,member) \
00053 public: \
00054         void Set##member (type val) {   \
00055                 m_##member = val;       \
00056                 Invalidate ();  \
00057         }       \
00058         type Get##member (void) const {return m_##member;}      \
00059         type &GetRef##member (void) {return m_##member;}        \
00060 private:        \
00061         type m_##member;
00062 
00063 #define GCCV_ITEM_POS_PROP(type,member) \
00064 public: \
00065         void Set##member (type val) {   \
00066                 Invalidate ();  \
00067                 m_##member = val;       \
00068                 UpdateBounds ();        \
00069                 Invalidate ();  \
00070         }       \
00071         type Get##member (void) const {return m_##member;}      \
00072         type &GetRef##member (void) {return m_##member;}        \
00073 private:        \
00074         type m_##member;
00075 
00076 namespace gccv {
00077 
00078 class Canvas;
00079 class Group;
00080 class ItemClient;
00081 
00082 class Item
00083 {
00084 public:
00085         Item (Canvas *canvas);
00086         Item (Group *parent, ItemClient *client = NULL);
00087         virtual ~Item ();
00088 
00089         void GetBounds (double &x0, double &y0, double &x1, double &y1) const;
00090         void Invalidate () const;
00091         void SetVisible (bool visible);
00092 
00093         // virtual methods
00094         virtual double Distance (double x, double y, Item **item) const;
00095         virtual void Draw (cairo_t *cr, bool is_vector) const;
00096         virtual bool Draw (cairo_t *cr, double x0, double y0, double x1, double y1, bool is_vector) const;
00097         virtual void Move (double x, double y);
00098 
00099 protected:
00100         void BoundsChanged ();
00101         virtual void UpdateBounds ();
00102         Canvas const *GetCanvas () const {return m_Canvas;}
00103 
00104 protected:
00105         double m_x0, m_y0, m_x1, m_y1;
00106 
00107 private:
00108         Canvas *m_Canvas;
00109         bool m_CachedBounds;
00110         bool m_NeedsRedraw;
00111 
00112 GCU_POINTER_PROP (ItemClient, Client)
00113 GCU_POINTER_PROP (Group, Parent)
00114 GCU_RO_PROP (bool, Visible)
00115 GCCV_ITEM_PROP (cairo_operator_t, Operator);
00116 };
00117 
00118 }
00119 
00120 #endif  //       GCCV_ITEM_H

Generated on Thu Dec 31 11:27:59 2009 for The Gnome Chemistry Utils by  doxygen 1.6.1