Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include <Wt/WContainerWidget>
00008 #include <Wt/WGridLayout>
00009 #include <Wt/WSlider>
00010 #include <Wt/WText>
00011
00012 #include "PaintExample.h"
00013 #include "ShapesWidget.h"
00014
00015 using namespace Wt;
00016
00017 PaintExample::PaintExample(WContainerWidget *root, bool showTitle)
00018 : WContainerWidget(root)
00019 {
00020 std::string text;
00021 if (showTitle)
00022 text += "<h2>Paint example</h2>";
00023
00024 text +=
00025 "<p>A simple example demonstrating cross-browser vector graphics."
00026 "</p>"
00027 "<p>The emweb logo below is painted using the Wt WPainter API from "
00028 "bezier paths, and rendered to the browser using inline SVG, inline VML "
00029 "or the HTML 5 <canvas> element."
00030 "</p>"
00031 "<p>"
00032 "The example also demonstrates the horizontal and vertical "
00033 "<a href=\"http://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WSlider.html\" target=\"_blank\">"
00034 "WSlider</a> widgets (which are rendered using vector graphics). Here, "
00035 "the events of the WSlider widgets are used to scale and rotate the "
00036 "emweb logo."
00037 "</p>"
00038 "<p>"
00039 "In non-IE browsers, a different backend is used for positive or negative "
00040 "angles (SVG or HTML canvas)."
00041 "</p>";
00042
00043 new WText(text, this);
00044
00045 WContainerWidget *emweb = new WContainerWidget(this);
00046 emweb->setMargin(WLength::Auto, Left | Right);
00047
00048 WGridLayout *layout = new WGridLayout();
00049 emweb->setLayout(layout, AlignCenter | AlignTop);
00050
00051 WSlider *scaleSlider = new WSlider(Horizontal);
00052 scaleSlider->setMinimum(0);
00053 scaleSlider->setMaximum(20);
00054 scaleSlider->setValue(10);
00055 scaleSlider->setTickInterval(5);
00056 scaleSlider->setTickPosition(WSlider::TicksBothSides);
00057 scaleSlider->resize(300, 50);
00058 scaleSlider->sliderMoved().connect(SLOT(this, PaintExample::scaleShape));
00059
00060 layout->addWidget(scaleSlider, 0, 1, AlignCenter | AlignMiddle);
00061
00062 WSlider *rotateSlider = new WSlider(Vertical);
00063 rotateSlider->setMinimum(-30);
00064 rotateSlider->setMaximum(30);
00065 rotateSlider->setValue(0);
00066 rotateSlider->setTickInterval(10);
00067 rotateSlider->setTickPosition(WSlider::TicksBothSides);
00068 rotateSlider->resize(50, 400);
00069 rotateSlider->sliderMoved().connect(SLOT(this, PaintExample::rotateShape));
00070
00071 layout->addWidget(rotateSlider, 1, 0, AlignCenter | AlignMiddle);
00072
00073 shapes_ = new ShapesWidget();
00074 shapes_->setAngle(0.0);
00075 shapes_->setRelativeSize(0.5);
00076 shapes_->setPreferredMethod(WPaintedWidget::InlineSvgVml);
00077
00078 layout->addWidget(shapes_, 1, 1, AlignCenter | AlignMiddle);
00079 }
00080
00081 void PaintExample::rotateShape(int v)
00082 {
00083 shapes_->setAngle(v / 2.0);
00084
00085
00086 shapes_->setPreferredMethod(v < 0 ? WPaintedWidget::InlineSvgVml
00087 : WPaintedWidget::HtmlCanvas);
00088 }
00089
00090 void PaintExample::scaleShape(int v)
00091 {
00092 shapes_->setRelativeSize(0.1 + 0.9 * (v/20.0));
00093 }