]> 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 127eece6d9f550e13860b80c0bdf5121d8bce6fb..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,11 +47,12 @@ namespace canvas
        */
       Image( const CanvasWeakPtr& canvas,
              const SGPropertyNode_ptr& node,
-             const Style& parent_style,
+             const Style& parent_style = Style(),
              Element* parent = 0 );
       virtual ~Image();
 
       virtual void update(double dt);
+      virtual void valueChanged(SGPropertyNode* child);
 
       void setSrcCanvas(CanvasPtr canvas);
       CanvasWeakPtr getSrcCanvas() const;
@@ -62,6 +67,17 @@ namespace canvas
        */
       void setSlice(const std::string& slice);
 
+      /**
+       * Set image slice width.
+       *
+       * By default the size of the 9-scale grid is the same as specified
+       * with setSlice/"slice". Using this method allows setting values
+       * different to the size in the source image.
+       *
+       * @see http://www.w3.org/TR/css3-background/#border-image-width
+       */
+      void setSliceWidth(const std::string& width);
+
       /**
        * http://www.w3.org/TR/css3-background/#border-image-outset
        */
@@ -69,28 +85,15 @@ namespace canvas
 
       const SGRect<float>& getRegion() const;
 
+      bool handleEvent(EventPtr event);
+
     protected:
 
       enum ImageAttributes
       {
         SRC_RECT       = LAST_ATTRIBUTE << 1, // Source image rectangle
-        DEST_SIZE      = SRC_RECT << 1        // Element size
-      };
-
-      struct CSSOffsets
-      {
-        CSSOffsets():
-          valid(false)
-        {}
-
-        union
-        {
-          float          offsets[4];
-          struct { float t, r, b, l; };
-        };
-
-        std::string keyword;
-        bool        valid;
+        DEST_SIZE      = SRC_RECT << 1,       // Element size
+        SRC_CANVAS     = DEST_SIZE << 1
       };
 
       virtual void childChanged(SGPropertyNode * child);
@@ -101,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);
 
-      CSSOffsets parseSideOffsets(const std::string& str) const;
+      void handleImageLoadDone(HTTP::Request*);
 
       osg::ref_ptr<osg::Texture2D> _texture;
       // TODO optionally forward events to canvas
@@ -117,7 +120,8 @@ namespace canvas
       SGRect<float>   _src_rect,
                       _region;
 
-      CSSOffsets      _slice,
+      CSSBorder       _slice,
+                      _slice_width,
                       _outset;
   };