Detailed Description
A widget that is painted using vector graphics.【 WPaintedWidget的用途是作为一个widget,允许用户使用向量图在其上作画。】
A painted widget is rendered from basic drawing primitives. Rendering is done not on the server but on the browser, using different rendering methods:
【WPaintedWidget渲染自基本的绘图元素,渲染发生在浏览器端,而不是服务器端,可能采用以下渲染方法:】
Browser | Methods | Default method |
Firefox 1.5+ | HtmlCanvas, InlineSVG | HtmlCanvas |
Internet Explorer 6.0+ | InlineVML | InlineVML |
Safari | HtmlCanvas, InlineSVG | HtmlCanvas |
Opera | InlineSVG, HtmlCanvas* | InlineSVG |
other | ? | HtmlCanvas |
* 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.
【不同的渲染方法对应不同的 WPaintDevice 实现,WPaintedWidget 会根据浏览器能力和配置自动选择适合的渲染方法。 】
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().
【如果禁用 JavaScript, 那么基于 JavaScript 的 HtmlCanvas 将不会被采用,而使用 InlineSVG 代替。我们可以使用 setPreferredMethod() 方法改变渲染方法。 】
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.
【InlineSVG 需要 文档作为 XHTML 渲染,这就要求配置文件中必须设置 <send-xhtml-mime-type>
选项,默认情况下,这个选项是被关闭的。 】
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.
【要想使用 WPaintedWidget,你必须定义继承于它的子类,并重新实现 paintEvent(WPaintDevice *paintDevice) 。要想在 WPaintDevice 作画,你需要使用 WPainter 。Repainting 是由 update() 引发的。 】
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. 【 WPaintedWidget 需要被指定尺寸,或指定布局管理器】
-
See also:
- WImage
类别: c++witty 查看评论