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

hotspot.cpp

Go to the documentation of this file.
00001 #include "hotspot.h"
00002 #include <vector>
00003 #include <algorithm>
00004 
00005 namespace wit {
00006 
00025 static std::vector<Hotspot*> wit_hotspot_list;
00026 
00027 struct HotspotPrivate {
00028     EventHandler* handler;
00029     Polygon poly;
00030     bool isRect, enabled;
00031     int zorder;
00032 };
00033 
00037 Hotspot::Hotspot() : d(new HotspotPrivate)
00038 {
00039     d->handler = 0;
00040     d->isRect = true;
00041     d->enabled = true;
00042     d->zorder = 0;
00043     wit_hotspot_list.push_back(this);
00044 }
00045 
00049 Hotspot::~Hotspot()
00050 {
00051     wit_hotspot_list.erase(std::find(wit_hotspot_list.begin(), wit_hotspot_list.end(), this));
00052     delete d;
00053 }
00054 
00059 bool Hotspot::isEnabled() const
00060 {
00061     return d->enabled;
00062 }
00063 
00072 void Hotspot::setEnabled(bool on)
00073 {
00074     d->enabled = on;
00075 }
00076 
00083 Rect Hotspot::boundingBox() const
00084 {
00085     return d->poly.boundingBox();
00086 }
00087 
00093 Polygon Hotspot::region() const
00094 {
00095     return d->poly;    
00096 }
00097 
00106 void Hotspot::setRegion(const Rect& rect)
00107 {
00108     d->isRect = true;
00109     Polygon poly;
00110     poly.addPoint(rect.x1, rect.y1);
00111     poly.addPoint(rect.x1, rect.y2);
00112     poly.addPoint(rect.x2, rect.y2);
00113     poly.addPoint(rect.x2, rect.y1);
00114     d->poly = poly;
00115 }
00116 
00120 void Hotspot::setRegion(const Polygon& polygon)
00121 {
00122     d->isRect = false;
00123     d->poly = polygon;
00124 }
00125 
00135 bool Hotspot::boundingBoxContains(float x, float y)
00136 {
00137     return boundingBox().contains(x, y);
00138 }
00139 
00146 bool Hotspot::contains(float x, float y)
00147 {
00148     bool bb = boundingBox().contains(x, y);
00149     if(!bb || d->isRect)
00150         return bb;
00151     return d->poly.contains(x, y);
00152 }
00153 
00160 void Hotspot::setEventHandler(EventHandler* handler)
00161 {
00162     d->handler = handler;
00163 }
00164 
00171 EventHandler* Hotspot::eventHandler() const
00172 {
00173     return d->handler;
00174 }
00175 
00181 int Hotspot::zIndex() const
00182 {
00183     return d->zorder;
00184 }
00185 
00196 void Hotspot::setZIndex(int z)
00197 {
00198     d->zorder = z;
00199 }
00200 
00204 std::auto_ptr<HotspotList> Hotspot::findAtPoint(float x, float y)
00205 {
00206     std::auto_ptr<HotspotList> rv(new HotspotList);
00207     if(!wit_hotspot_list.size()) return rv;
00208 
00209     Hotspot** end = &wit_hotspot_list.back();
00210     Hotspot* hs;
00211     for(Hotspot** iter = &wit_hotspot_list.front(); iter <= end; iter++) {
00212         if(!iter) continue;
00213         hs = *iter;
00214         if(!hs->isEnabled())
00215             continue;
00216         if(hs->contains(x, y))
00217             rv->push_back(hs);
00218     }
00219     return rv;
00220 }
00221 
00222 }

Generated on Sat Sep 3 2011 10:25:00 for wit by  doxygen 1.7.2