#include "CanvasElement.hxx"
#include <simgear/canvas/canvas_fwd.hxx>
-#include <simgear/math/Rect.hxx>
+#include <simgear/misc/CSSBorder.hxx>
#include <osg/Texture2D>
namespace simgear
{
+namespace HTTP { class Request; }
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
* [x,y] Position of rectangle
*/
Image( const CanvasWeakPtr& canvas,
- SGPropertyNode_ptr node,
- const Style& parent_style );
+ const SGPropertyNode_ptr& node,
+ 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;
void setImage(osg::Image *img);
void setFill(const std::string& fill);
- const Rect<float>& getRegion() const;
+ /**
+ * Set image slice (aka. 9-scale)
+ *
+ * @see http://www.w3.org/TR/css3-background/#border-image-slice
+ */
+ 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
+ */
+ void setOutset(const std::string& outset);
+
+ 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
+ DEST_SIZE = SRC_RECT << 1, // Element size
+ SRC_CANVAS = DEST_SIZE << 1
};
virtual void childChanged(SGPropertyNode * child);
void setupDefaultDimensions();
- Rect<int> getTextureDimensions() const;
+ SGRect<int> getTextureDimensions() const;
+
+ void setQuad(size_t index, const SGVec2f& tl, const SGVec2f& br);
+ void setQuadUV(size_t index, const SGVec2f& tl, const SGVec2f& br);
+
+ void handleImageLoadDone(HTTP::Request*);
osg::ref_ptr<osg::Texture2D> _texture;
// TODO optionally forward events to canvas
CanvasWeakPtr _src_canvas;
osg::ref_ptr<osg::Geometry> _geom;
+ osg::ref_ptr<osg::DrawArrays>_prim;
osg::ref_ptr<osg::Vec3Array> _vertices;
osg::ref_ptr<osg::Vec2Array> _texCoords;
osg::ref_ptr<osg::Vec4Array> _colors;
SGPropertyNode *_node_src_rect;
- Rect<float> _src_rect,
+ SGRect<float> _src_rect,
_region;
+
+ CSSBorder _slice,
+ _slice_width,
+ _outset;
};
} // namespace canvas