Wt  3.3.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
Public Types | Public Member Functions | Protected Member Functions
Wt::WPaintedWidget Class Reference

A widget that is painted using vector graphics. More...

#include <Wt/WPaintedWidget>

Inheritance diagram for Wt::WPaintedWidget:
Inheritance graph
[legend]

List of all members.

Public Types

enum  Method { InlineSvgVml, HtmlCanvas, PngImage }
 Enumeration that indicates a rendering method. More...

Public Member Functions

 WPaintedWidget (WContainerWidget *parent=0)
 Create a new painted widget.
 ~WPaintedWidget ()
 Destructor.
void setPreferredMethod (Method method)
 Sets the preferred rendering method.
Method preferredMethod () const
 Returns the preferred rendering method.
void update (WFlags< PaintFlag > flags=0)
 Lets the widget repaint itself.
virtual void resize (const WLength &width, const WLength &height)
 Resizes the widget.
void addArea (WAbstractArea *area)
 Adds an interactive area.
void insertArea (int index, WAbstractArea *area)
 Inserts an interactive area.
void removeArea (WAbstractArea *area)
 Removes an interactive area.
WAbstractAreaarea (int index) const
 Returns the interactive area at the given index.
const std::vector
< WAbstractArea * > 
areas () const
 Returns the interactive areas set for this widget.
JSlotrepaintSlot ()
 A JavaScript slot that repaints the widget when triggered.

Protected Member Functions

WJavaScriptHandle< WTransformcreateJSTransform ()
 Create a WTransform that is accessible from JavaScript, associated with this WPaintedWidget.
WJavaScriptHandle< WBrushcreateJSBrush ()
 Create a WBrush that is accessible from JavaScript, associated with this WPaintedWidget.
WJavaScriptHandle< WPencreateJSPen ()
 Create a WPen that is accessible from JavaScript, associated with this WPaintedWidget.
WJavaScriptHandle< WPainterPathcreateJSPainterPath ()
 Create a WPainterPath that is accessible from JavaScript, associated with this WPaintedWidget.
WJavaScriptHandle< WRectFcreateJSRect ()
 Create a WRectF that is accessible from JavaScript, associated with this WPaintedWidget.
WJavaScriptHandle< WPointFcreateJSPoint ()
 Create a WPointF that is accessible from JavaScript, associated with this WPaintedWidget.
virtual void layoutSizeChanged (int width, int height)
 Virtual method that indicates a size change.
virtual Method getMethod () const
 Returns the actual method used for rendering.
virtual void paintEvent (WPaintDevice *paintDevice)=0
 Paints the widget.
virtual WPaintDevicecreatePaintDevice () const
 Creates a paint device.
virtual void enableAjax ()
 Progresses to an Ajax-enabled widget.
virtual void render (WFlags< RenderFlag > flags)
 Renders the widget.
std::string objJsRef () const
 Returns a JavaScript reference to the client side representation of the WPaintedWidget.

Detailed Description

A widget that is painted using vector graphics.

A painted widget is rendered from basic drawing primitives. Rendering is done not on the server but on the browser, using different rendering methods:

BrowserMethods Default method
Firefox 1.5+HtmlCanvas, InlineSVG, PngImage HtmlCanvas
Internet Explorer 6.0+InlineVML, PngImage InlineVML
Internet Explorer 9+HtmlCanvas, InlineSVG, PngImage HtmlCanvas
SafariHtmlCanvas, InlineSVG, PngImage HtmlCanvas
OperaInlineSVG, HtmlCanvas*, PngImage InlineSVG
other?HtmlCanvas, PngImage

* HtmlCanvas occasionally suffers from rendering artefacts in Opera.

The different rendering methods correspond to different WPaintDevice implementations, from which this widget choses a suitable one depending on the browser capabilities and configuration.

If no JavaScript is available, the JavaScript-based HtmlCanvas will not be used, and InlineSVG will be used instead. The method used may be changed by using setPreferredMethod().

In some browsers, InlineSVG requires that the document is rendered as XHTML. This must be enabled in the configuration file using the <send-xhtml-mime-type> option. By default, this option is off. Firefox 4 and Chrome do support svg in normal html mode.

The PngImage is the most portable rendering method, and may be the fastest if the painting is of high complexity and/or the image is fairly small.

To use a WPaintedWidget, you must derive from it and reimplement paintEvent(WPaintDevice *paintDevice). To paint on a WPaintDevice, you will need to use a WPainter. Repainting is triggered by calling the update() method.

Usage example:

 class MyPaintedWidget : public Wt::WPaintedWidget
 {
 public:
   MyPaintedWidget(Wt::WContainerWidget *parent = 0)
     : Wt::WPaintedWidget(parent),
       foo_(100)
   {
      resize(200, 200); // provide a default size
   }

   void setFoo(int foo) {
      foo_ = foo;
      update(); // trigger a repaint
   }

 protected:
   void paintEvent(Wt::WPaintDevice *paintDevice) {
     Wt::WPainter painter(paintDevice);
     painter.drawLine(20, 20, foo_, foo_);
     ...
   }

 private:
   int foo_;
 };

CSS

Styling through CSS is not applicable.

Note:
A WPaintedWidget requires that it is given a size using resize() or by a layout manager.

Client side interaction and repainting

If the widget is drawn as an HTML canvas element, i.e. the method is HtmlCanvas, a WPaintedWidget can expose certain objects to be modified client side.

See also:
WJavaScriptHandle, WJavaScriptExposableObject
WImage

Member Enumeration Documentation

Enumeration that indicates a rendering method.

Enumerator:
InlineSvgVml 

SVG (Most browsers) or VML (Internet Explorer < 9) embedded in the page.

HtmlCanvas 

The WHATWG HTML 5 canvas element.

PngImage 

Using a PNG image resource.

Reimplemented from Wt::WObject.


Member Function Documentation

Adds an interactive area.

Adds the area which listens to events in a specific region of the widget. Areas are organized in a list, to which the given area is appended. When areas overlap, the area with the lowest index receives the event.

Ownership of the area is transferred to the widget.

Note:
When defining at least one area, no more events will propagate to the widget itself. As a work-around, you can emulate this by listening for events on a WRectArea that corresponds to the whole widget, and which is added as the last area (catching all events that were not caught by preceding areas).
See also:
insertArea(int, WAbstractArea *)
WAbstractArea * Wt::WPaintedWidget::area ( int  index) const

Returns the interactive area at the given index.

Returns 0 if index was invalid.

See also:
insertArea(int, WAbstractArea *)
const std::vector< WAbstractArea * > Wt::WPaintedWidget::areas ( ) const

Returns the interactive areas set for this widget.

See also:
addArea()
WPaintDevice * Wt::WPaintedWidget::createPaintDevice ( ) const [protected, virtual]

Creates a paint device.

Although it's usually not necessary to call this function, you may want to reimplement this function to customize or specialize the device used for painting the widget.

Ownership of the device is transferred to the caller.

void Wt::WPaintedWidget::enableAjax ( ) [protected, virtual]

Progresses to an Ajax-enabled widget.

This method is called when the progressive bootstrap method is used, and support for AJAX has been detected. The default behavior will upgrade the widget's event handling to use AJAX instead of full page reloads, and propagate the call to its children.

You may want to reimplement this method if you want to make changes to widget when AJAX is enabled. You should always call the base implementation.

See also:
WApplication::enableAjax()

Reimplemented from Wt::WWebWidget.

WPaintedWidget::Method Wt::WPaintedWidget::getMethod ( ) const [protected, virtual]

Returns the actual method used for rendering.

The default method considers browser capabilites and the preferred method to make an actual choice for the implementation.

You may want to reimplement this method to override this choice.

void Wt::WPaintedWidget::insertArea ( int  index,
WAbstractArea area 
)

Inserts an interactive area.

Inserts the area which listens to events in the coresponding area of the widget. Areas are organized in a list, and the area is inserted at index index. When areas overlap, the area with the lowest index receives the event.

Ownership of the Area is transferred to the widget.

Note:
When defining at least one area, no more events will propagate to the widget itself. As a work-around, you can emulate this by listening for events on a WRectArea that corresponds to the whole widget, and which is added as the last area (catching all events that were not caught by preceding areas).
See also:
addArea(WAbstractArea *)
void Wt::WPaintedWidget::layoutSizeChanged ( int  width,
int  height 
) [protected, virtual]

Virtual method that indicates a size change.

This method propagates the client-side width and height of the widget when the widget is contained by a layout manager and setLayoutSizeAware(true) was called.

See also:
setLayoutSizeAware()

Reimplemented from Wt::WWidget.

std::string Wt::WPaintedWidget::objJsRef ( ) const [protected]

Returns a JavaScript reference to the client side representation of the WPaintedWidget.

The client side representation exposes the following interface:

 {
   canvas: exposes the underlying HTML canvas element
   repaint: a function that, when called, will repaint the widget without a server roundtrip
 }
Note:
The method should be HtmlCanvas and there has to be at least one WJavaScriptHandle associated with this WPaintedWidget in order for this reference to be valid.
virtual void Wt::WPaintedWidget::paintEvent ( WPaintDevice paintDevice) [protected, pure virtual]

Paints the widget.

You should reimplement this method to paint the contents of the widget, using the given paintDevice.

Implemented in Wt::Chart::WCartesianChart, Wt::Chart::WPieChart, and Wt::Chart::WAxisSliderWidget.

Returns the preferred rendering method.

See also:
setPreferredMethod(Method)

Removes an interactive area.

Removes the area from this widget, returning the ownership.

See also:
addArea(WAbstractArea *)
void Wt::WPaintedWidget::render ( WFlags< RenderFlag flags) [protected, virtual]

Renders the widget.

This function renders the widget (or an update for the widget), after this has been scheduled using scheduleRender().

The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.

Reimplemented from Wt::WWebWidget.

Reimplemented in Wt::Chart::WCartesianChart, and Wt::Chart::WAxisSliderWidget.

A JavaScript slot that repaints the widget when triggered.

This is useful for client-side initiated repaints. You may want to use this if you want to add interaction or animation to your WPaintedWidget.

Note:
This feature is currently only supported if the method is HtmlCanvas. This will not cause a server roundtrip. Instead, the resulting JavaScript of paintEvent() will be re-executed on the client side.
See also:
objJsRef()
void Wt::WPaintedWidget::resize ( const WLength width,
const WLength height 
) [virtual]

Resizes the widget.

Specifies a fixed size for this widget, setting CSS width and height properties. By default a widget has automatic width and height, which sets a size for the widget following CSS rules.

When the widget is not managed by a layout manager, the automatic (natural) size of a widget depends on whether they widget is a block or inline widget:

  • a block widget takes by default the width of the parent, and the height that it needs based on its contents
  • an inline widget takes the width and height that it needs based on its contents (possibly wrapping over multiple lines). The width and height of an inline widget cannot be changed (by the letter of CSS, although most browsers will react to it in varying ways).

When inserted in a layout manager, the size set will be used as a widget's preferred size, but the widget may be given a different size by the layout manager based on available space and stretch factors. The actual size given by a layout manager may be retrieved by making the widget "layout size aware", using setLayoutSizeAware(). If you have defined a "wtResize()" JavaScript method for the widget, then this method will also be called.

The default width and height of a widget is WLength::Auto.

See also:
width(), height()

Reimplemented from Wt::WWebWidget.

Sets the preferred rendering method.

When method is supported by the browser, then it is chosen for rendering.

void Wt::WPaintedWidget::update ( WFlags< PaintFlag flags = 0)

Lets the widget repaint itself.

Repainting is not immediate, but happens after when the event loop is exited.

Unless a Wt::PaintUpdate paint flag is set, the widget is first cleared.

 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator

Generated on Tue Mar 22 2016 for the C++ Web Toolkit (Wt) by doxygen 1.7.6.1