The Gnome Chemistry Utils 0.13.3
|
00001 // -*- C++ -*- 00002 00003 /* 00004 * Gnome Chemistry Utils 00005 * gccv/item.h 00006 * 00007 * Copyright (C) 2008-2010 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 00048 #define GCCV_ITEM_PROP(type,member) \ 00049 public: \ 00050 void Set##member (type val) { \ 00051 m_##member = val; \ 00052 Invalidate (); \ 00053 } \ 00054 type Get##member (void) const {return m_##member;} \ 00055 private: \ 00056 type m_##member; 00057 00074 #define GCCV_ITEM_POS_PROP(type,member) \ 00075 public: \ 00076 void Set##member (type val) { \ 00077 Invalidate (); \ 00078 m_##member = val; \ 00079 BoundsChanged (); \ 00080 Invalidate (); \ 00081 } \ 00082 type Get##member (void) const {return m_##member;} \ 00083 private: \ 00084 type m_##member; 00085 00086 namespace gccv { 00087 00088 class Canvas; 00089 class Group; 00090 class ItemClient; 00091 00100 class Item 00101 { 00102 public: 00108 Item (Canvas *canvas); 00115 Item (Group *parent, ItemClient *client = NULL); 00119 virtual ~Item (); 00120 00129 void GetBounds (double &x0, double &y0, double &x1, double &y1) const; 00134 void Invalidate () const; 00140 void SetVisible (bool visible); 00141 00142 // virtual methods 00155 virtual double Distance (double x, double y, Item **item) const; 00161 virtual void BuildPath (cairo_t *cr) const; 00170 virtual void Draw (cairo_t *cr, bool is_vector) const; 00186 virtual bool Draw (cairo_t *cr, double x0, double y0, double x1, double y1, bool is_vector) const; 00193 virtual void Move (double x, double y); 00197 bool IsTopLevel () const; 00198 00199 protected: 00203 void BoundsChanged (); 00209 virtual void UpdateBounds (); 00214 Canvas const *GetCanvas () const {return m_Canvas;} 00215 00216 protected: 00220 double m_x0; 00224 double m_y0; 00228 double m_x1; 00232 double m_y1; 00233 00234 private: 00235 Canvas *m_Canvas; 00236 bool m_CachedBounds; 00237 bool m_NeedsRedraw; 00238 00247 GCU_POINTER_PROP (ItemClient, Client) 00251 GCU_RO_POINTER_PROP (Group, Parent) 00255 GCU_RO_PROP (bool, Visible) 00264 GCCV_ITEM_PROP (cairo_operator_t, Operator); 00265 }; 00266 00267 } 00268 00269 #endif // GCCV_ITEM_H