Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

imgmap.h

Go to the documentation of this file.
00001 /* gtkmm Image Map
00002    Copyright (C) 2002 Aaron Bentley
00003 
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 2, or (at your option)
00007    any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; if not, write to the Free Software Foundation,
00016    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00020 #ifndef _IMGMAP_H_ 
00021 #define _IMGMAP_H_ //make idempotent
00022 #include <gtk--/main.h>
00023 #include <gtk--/drawingarea.h>
00024 #include <vector>
00025 
00026 class Rectangle
00027 {
00028    public:
00029    float left, top, width, height;
00030    Rectangle(float left, float top, float width, float height);
00031    bool contains(float x, float y) const;
00032 };
00033 
00034 class RecTransform
00035 {
00036    private:
00037    float offx, offy;
00038    float scalex, scaley;
00039    public:
00040    float power;
00041    RecTransform::RecTransform(float aoffx, float aoffy, float ascalex,
00042       float ascaley)
00043       :
00044    offx(aoffx), offy(aoffy), scalex(ascalex), scaley(ascaley), power(1)
00045    {}
00046 
00047    Rectangle operator()(Rectangle &myrect)
00048    {
00049       myrect.left*=(1-power+scalex*power);
00050       myrect.left+=offx*power;
00051       myrect.top*=(1-power+scaley*power);
00052       myrect.top+=offy*power;
00053       myrect.width*=(1-power+scalex*power);
00054       myrect.height*=(1-power+scaley*power);
00055       return myrect;
00056    }
00057 };
00058 
00059 template <typename T>
00060 class RegionWatcher
00061 {
00062    public:
00063    virtual bool region_click(T &region)
00064    {
00065       return false;
00066    }
00067    virtual bool region_hover(T &region)
00068    {
00069       return false;
00070    }
00071    virtual bool region_default(T &region)
00072    {
00073       return false;
00074    }
00075 };
00076 
00080 class MapRegion
00081 {
00082    public:
00088    virtual bool contains(float x, float y)const=0 ;
00089    virtual bool hover()
00090    {
00091       return false;
00092    }
00093 };
00094 
00095 
00100 class EntryRect: public Rectangle, public MapRegion
00101 {
00102    private:
00103    EnTree const *my_EnTree;
00104    public:
00105    RegionWatcher<EntryRect> *my_watcher;
00106    EntryRect(float left, float top, float width, float height, 
00107       EnTree const &arg_EnTree, RegionWatcher<EntryRect> &arg_watcher)
00108       :
00109       Rectangle(left, top, width, height), my_EnTree(&arg_EnTree), 
00110       my_watcher(&arg_watcher)
00111    {
00112       ;
00113    }
00114    EntryRect(EntryRect const &arg);
00118    EnTree const &get_EnTree() const
00119    {
00120       if (my_EnTree==NULL)
00121       {
00122     Exception err;
00123     throw err;
00124       }
00125       return *my_EnTree;
00126    }
00127    void setColor(Gdk_Color &curcolor) const;
00128    bool contains(float x, float y) const
00129    {
00130       return Rectangle::contains(x,y);
00131    }
00132    bool hover();
00133 
00134    static EntryRect seek_failed;
00135 };
00136 
00140 class ImageMap: public Gtk::DrawingArea 
00141 {
00142 private:
00143    Watcher<ImageMap> *my_watch;
00144    gint mouse_x, mouse_y;
00145 
00146 protected:
00147    EntryRect *over_rect;
00148    bool mouse_in;
00149    std::vector<EntryRect> rectangles;
00150 
00151 public:
00152    void seek_over();
00153    void set_watcher(Watcher<ImageMap> &my_watch);
00154    void me_modified()
00155    {
00156       if (my_watch!=NULL) my_watch->modified(*this);
00157    }
00158    gint motion_notify_event_impl(GdkEventMotion *event);
00159    gint button_press_event_impl(GdkEventButton *event);
00160    gint enter_notify_event_impl(GdkEventCrossing *event);
00161    gint leave_notify_event_impl(GdkEventCrossing *event);
00162    virtual bool clicked(EntryRect const *, int button)=0;
00163    virtual void hover(EntryRect const *);
00164    virtual void left();
00165    virtual void entered();
00166 };
00167 
00168 #endif //_IMGMAP_H_

Generated on Mon Apr 7 19:41:45 2003 for DuTree by doxygen1.2.18