/home/koen/project/wt/cvs/wt/examples/painting/PaintExample.C

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
00003  *
00004  * See the LICENSE file for terms of use.
00005  */
00006 
00007 #include <WContainerWidget>
00008 #include <WSlider>
00009 #include <WText>
00010 
00011 #include "PaintExample.h"
00012 #include "ShapesWidget.h"
00013 
00014 using namespace Wt;
00015 
00016 PaintExample::PaintExample(const WEnvironment& env)
00017   : WApplication(env)
00018 {
00019   useStyleSheet("painting.css");
00020 
00021   new WText("<h2>Paint example</h2>"
00022             "<p>A simple example demonstrating cross-browser vector graphics."
00023             "</p>"
00024             "<p>The emweb logo below is painted using the Wt WPainter API, and "
00025             "rendered to the browser using inline SVG, inline VML or the "
00026             "HTML 5 &lt;canvas&gt; element."
00027             "</p>",
00028             root());
00029 
00030   WSlider *scaleSlider = new WSlider(Horizontal, root());
00031   scaleSlider->setMinimum(0);
00032   scaleSlider->setMaximum(20);
00033   scaleSlider->setValue(10);
00034   scaleSlider->setTickInterval(5);
00035   scaleSlider->setTickPosition(WSlider::TicksBothSides);
00036   scaleSlider->resize(300, 50);
00037   scaleSlider->valueChanged.connect(SLOT(this, PaintExample::scaleShape));
00038   scaleSlider->setMargin(WLength(), WWidget::Left | WWidget::Right);
00039 
00040   WSlider *rotateSlider = new WSlider(Vertical, root());
00041   rotateSlider->setMinimum(-30);
00042   rotateSlider->setMaximum(30);
00043   rotateSlider->setValue(0);
00044   rotateSlider->setTickInterval(10);
00045   rotateSlider->setTickPosition(WSlider::TicksBothSides);
00046   rotateSlider->resize(50, 400);
00047   rotateSlider->setFloatSide(WWidget::Left);
00048   rotateSlider->valueChanged.connect(SLOT(this, PaintExample::rotateShape));
00049 
00050   shapes_ = new ShapesWidget(root());
00051   shapes_->setAngle(0.0);
00052   shapes_->setRelativeSize(0.5);
00053   shapes_->setMargin(WLength(), WWidget::Left | WWidget::Right);
00054   // Uncomment below to render using SVG instead of Canvas.
00055   // Make sure that you enable the XHTML1 mime-type in your wt_config.xml
00056   shapes_->setPreferredMethod(WPaintedWidget::InlineSvgVml);
00057 }
00058 
00059 void PaintExample::rotateShape(int v)
00060 {
00061   shapes_->setAngle(v / 2.0);
00062   shapes_->setPreferredMethod(v < 0 ? WPaintedWidget::InlineSvgVml
00063                               : WPaintedWidget::HtmlCanvas);
00064 }
00065 
00066 void PaintExample::scaleShape(int v)
00067 {
00068   shapes_->setRelativeSize(0.1 + 0.9 * (v/20.0));
00069 }
00070 
00071 WApplication *createApplication(const WEnvironment& env)
00072 {
00073   return new PaintExample(env);
00074 }
00075 
00076 int main(int argc, char **argv)
00077 {
00078   return WRun(argc, argv, &createApplication);
00079 }

Generated on Mon Apr 14 15:15:04 2008 for Wt by doxygen 1.5.3