Project

General

Profile

Bug #1803 » png-drawRect.cpp

Koen Deforche, 04/01/2013 10:14 PM

 
1

    
2
#include <Wt/WGlobal>
3
#include <Wt/WApplication>
4
#include <Wt/WPaintedWidget>
5
#include <Wt/WPainter>
6

    
7
using namespace Wt;
8

    
9
class SomePaintedWidget : public WPaintedWidget {
10
public:
11
    SomePaintedWidget(WContainerWidget* p=0)
12
        : WPaintedWidget(p) {
13
            resize(600, 600);
14
            setPreferredMethod(WPaintedWidget::PngImage);
15
        }
16

    
17
protected:
18
    void paintEvent(Wt::WPaintDevice* device) {
19
        WPainter painter(device);
20

    
21
	/* Solution 1: enable anti-aliasing */
22
	painter.setRenderHint(WPainter::Antialiasing);
23

    
24
	/* Solution 2: position line in the middle of a pixel */
25
        painter.drawRect(10.5, 10.5, 400, 200);
26
    }
27
};
28

    
29
class MyApp : public WApplication {
30
public:
31
    MyApp(const WEnvironment& env):
32
        WApplication(env) {
33
        SomePaintedWidget* spw = new SomePaintedWidget(root());
34
    }
35
};
36

    
37
WApplication* createApplication(const WEnvironment& env) {
38
    return new MyApp(env);
39
}
40

    
41
int main(int argc, char** argv) {
42
    return WRun(argc, argv, &createApplication);
43
}
44

    
(2-2/2)