• Main Page
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

/builddir/build/BUILD/flowcanvas-0.6.0/flowcanvas/Item.hpp

Go to the documentation of this file.
00001 /* This file is part of FlowCanvas.
00002  * Copyright (C) 2007-2009 Dave Robillard <http://drobilla.net>
00003  *
00004  * FlowCanvas is free software; you can redistribute it and/or modify it under the
00005  * terms of the GNU General Public License as published by the Free Software
00006  * Foundation; either version 2 of the License, or (at your option) any later
00007  * version.
00008  *
00009  * FlowCanvas is distributed in the hope that it will be useful, but WITHOUT ANY
00010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for details.
00012  *
00013  * You should have received a copy of the GNU General Public License along
00014  * with this program; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
00016  */
00017 
00018 #ifndef FLOWCANVAS_ITEM_HPP
00019 #define FLOWCANVAS_ITEM_HPP
00020 
00021 #include <string>
00022 #include <map>
00023 #include <algorithm>
00024 #include <boost/shared_ptr.hpp>
00025 #include <boost/enable_shared_from_this.hpp>
00026 #include <libgnomecanvasmm.h>
00027 #include "flowcanvas/Port.hpp"
00028 
00029 namespace FlowCanvas {
00030 
00031 class Canvas;
00032 
00033 
00038 class Item : public Gnome::Canvas::Group
00039            , public boost::enable_shared_from_this<Item>
00040 {
00041 public:
00042     Item(boost::shared_ptr<Canvas> canvas,
00043          const std::string&        name,
00044          double                    x,
00045          double                    y,
00046          uint32_t                  color);
00047 
00048     virtual ~Item() {}
00049 
00050     bool selected() const { return _selected; }
00051     virtual void set_selected(bool s);
00052 
00053     virtual void set_minimum_width(double w) { _minimum_width = w; }
00054 
00055     virtual void select_tick() = 0;
00056 
00057     virtual void move(double dx, double dy) = 0;
00058 
00059     virtual void zoom(double) {}
00060     boost::weak_ptr<Canvas> canvas() const { return _canvas; }
00061 
00062     bool popup_menu(guint button, guint32 activate_time) {
00063         if ( ! _menu)
00064             create_menu();
00065         if (_menu) {
00066             _menu->popup(button, activate_time);
00067             return true;
00068         } else {
00069             return false;
00070         }
00071     }
00072 
00073     virtual void create_menu() {}
00074 
00075     Gtk::Menu* menu() const           { return _menu; }
00076     void       set_menu(Gtk::Menu* m) { delete _menu; _menu = m; }
00077 
00078     double width() const { return _width; }
00079     double height() const { return _height; }
00080 
00081     virtual void resize() = 0;
00082 
00083     virtual void load_location()  {}
00084     virtual void store_location() {}
00085 
00086     bool        is_within(const Gnome::Canvas::Rect& rect) const;
00087     inline bool point_is_within(double x, double y) const;
00088 
00089     const std::string& name() const                   { return _name; }
00090     virtual void       set_name(const std::string& n) { _name = n; }
00091 
00092     uint32_t     base_color() const           { return _color; }
00093     virtual void set_border_color(uint32_t c) { _border_color = c; }
00094     virtual void set_base_color(uint32_t c)   { _color = c; }
00095     virtual void set_default_base_color() = 0;
00096 
00097     sigc::signal<void> signal_pointer_entered;
00098     sigc::signal<void> signal_pointer_exited;
00099     sigc::signal<void> signal_selected;
00100     sigc::signal<void> signal_unselected;
00101 
00102     sigc::signal<void, GdkEventButton*> signal_clicked;
00103     sigc::signal<void, GdkEventButton*> signal_double_clicked;
00104 
00105     sigc::signal<void, double, double> signal_dragged;
00106     sigc::signal<void, double, double> signal_dropped;
00107 
00108 protected:
00109     virtual void on_drag(double dx, double dy);
00110     virtual void on_click(GdkEventButton*);
00111     virtual void on_double_click(GdkEventButton*);
00112 
00113     virtual void set_height(double h) = 0;
00114     virtual void set_width(double w) = 0;
00115 
00116     const boost::weak_ptr<Canvas> _canvas;
00117 
00118     bool on_event(GdkEvent* event);
00119 
00120     std::string _name;
00121     double      _minimum_width;
00122     double      _width;
00123     double      _height;
00124     uint32_t    _border_color;
00125     uint32_t    _color;
00126     bool        _selected;
00127     Gtk::Menu*  _menu;
00128 };
00129 
00130 
00131 typedef std::list<boost::shared_ptr<Item> > ItemList;
00132 
00133 
00136 inline bool
00137 Item::point_is_within(double x, double y) const
00138 {
00139     return (x > property_x() && x < property_x() + _width
00140             && y > property_y() && y < property_y() + _height);
00141 }
00142 
00143 
00144 inline bool
00145 Item::is_within(const Gnome::Canvas::Rect& rect) const
00146 {
00147     const double x1 = rect.property_x1();
00148     const double y1 = rect.property_y1();
00149     const double x2 = rect.property_x2();
00150     const double y2 = rect.property_y2();
00151 
00152     if (x1 < x2 && y1 < y2) {
00153         return (property_x() > x1
00154             && property_y() > y1
00155             && property_x() + width() < x2
00156             && property_y() + height() < y2);
00157     } else if (x2 < x1 && y2 < y1) {
00158         return (property_x() > x2
00159             && property_y() > y2
00160             && property_x() + width() < x1
00161             && property_y() + height() < y1);
00162     } else if (x1 < x2 && y2 < y1) {
00163         return (property_x() > x1
00164             && property_y() > y2
00165             && property_x() + width() < x2
00166             && property_y() + height() < y1);
00167     } else if (x2 < x1 && y1 < y2) {
00168         return (property_x() > x2
00169             && property_y() > y1
00170             && property_x() + width() < x1
00171             && property_y() + height() < y2);
00172     } else {
00173         return false;
00174     }
00175 }
00176 
00177 } // namespace FlowCanvas
00178 
00179 #endif // FLOWCANVAS_ITEM_HPP
00180 

Generated on Wed Feb 9 2011 for FlowCanvas by  doxygen 1.7.1