]> git.mxchange.org Git - simgear.git/blobdiff - simgear/canvas/elements/CanvasImage.hxx
Canvas: Respect clipping while event handling.
[simgear.git] / simgear / canvas / elements / CanvasImage.hxx
index fccc20f53757036677a9a87e1893860faeb038f1..6d16e8b3d3ff38ecc9455facdec87124f921896b 100644 (file)
 #include "CanvasElement.hxx"
 
 #include <simgear/canvas/canvas_fwd.hxx>
-#include <simgear/math/SGRect.hxx>
+#include <simgear/misc/CSSBorder.hxx>
 #include <osg/Texture2D>
 
 namespace simgear
 {
+namespace HTTP { class Request; }
 namespace canvas
 {
 
@@ -34,6 +35,9 @@ namespace canvas
     public Element
   {
     public:
+      static const std::string TYPE_NAME;
+      static void staticInit();
+
       /**
        * @param node    Property node containing settings for this image:
        *                  rect/[left/right/top/bottom]  Dimensions of source
@@ -43,7 +47,7 @@ namespace canvas
        */
       Image( const CanvasWeakPtr& canvas,
              const SGPropertyNode_ptr& node,
-             const Style& parent_style,
+             const Style& parent_style = Style(),
              Element* parent = 0 );
       virtual ~Image();
 
@@ -81,41 +85,15 @@ namespace canvas
 
       const SGRect<float>& getRegion() const;
 
-      bool handleMouseEvent(MouseEventPtr event);
+      bool handleEvent(EventPtr event);
 
     protected:
 
       enum ImageAttributes
       {
         SRC_RECT       = LAST_ATTRIBUTE << 1, // Source image rectangle
-        DEST_SIZE      = SRC_RECT << 1        // Element size
-      };
-
-      union CSSOffsets
-      {
-        float          val[4];
-        struct { float t, r, b, l; };
-      };
-
-      union CSSOffsetsTypes
-      {
-        bool          rel[4];
-        struct { bool t_rel, r_rel, b_rel, l_rel; };
-      };
-
-      struct CSSBorder
-      {
-        CSSBorder():
-          valid(false)
-        {}
-
-        CSSOffsets getRelOffsets(const SGRect<int>& dim) const;
-        CSSOffsets getAbsOffsets(const SGRect<int>& dim) const;
-
-        CSSOffsets      offsets;
-        CSSOffsetsTypes types;
-        std::string     keyword;
-        bool            valid;
+        DEST_SIZE      = SRC_RECT << 1,       // Element size
+        SRC_CANVAS     = DEST_SIZE << 1
       };
 
       virtual void childChanged(SGPropertyNode * child);
@@ -126,7 +104,7 @@ namespace canvas
       void setQuad(size_t index, const SGVec2f& tl, const SGVec2f& br);
       void setQuadUV(size_t index, const SGVec2f& tl, const SGVec2f& br);
 
-      CSSBorder parseSideOffsets(const std::string& str) const;
+      void handleImageLoadDone(HTTP::Request*);
 
       osg::ref_ptr<osg::Texture2D> _texture;
       // TODO optionally forward events to canvas