summaryrefslogtreecommitdiffstats
path: root/tests/test-painter.cpp
blob: f932c834dfccdcc616ed1dfc07a1d75bab5daae7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <cairo.h>

#include <tqpainter.h>
#include <tqapplication.h>

#include "tqtcairopainter.h"

int
main (int argc, char *argv[])
{
        cairo_surface_t *surface;
        cairo_t *cr;

        surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 500, 500);
//         cr = cairo_create (surface);

// 	/* Examples are in 1.0 x 1.0 coordinate space */
// 	cairo_scale (cr, 120, 120);
// 
// 	/* Drawing code goes here */
// 	cairo_set_line_width (cr, 0.1);
// 	cairo_set_source_rgb (cr, 0, 0, 0);
// 	cairo_rectangle (cr, 0.25, 0.25, 0.5, 0.5);
// 	cairo_stroke (cr);

	// Initialize TQApplication required data structures
	new TQApplication(argc, argv, TRUE);

	TQt3CairoPaintDevice pd(surface);
	TQPainter p(&pd);

	// Rectangle tests
	{
		p.setPen(TQPen(TQt::red, 1));
		p.drawRect(5, 5, 50, 50);
		TQBrush brush( TQt::yellow, TQBrush::DiagCrossPattern ); // yellow pattern
		p.setBrush( brush );                                     // set the yellow brush
		p.setPen( TQt::NoPen );                                  // do not draw outline
		p.drawRect( 0,0, 25,25 );                                // draw filled rectangle
		TQBrush brush2( TQt::green, TQBrush::SolidPattern );     // green pattern
		p.setBrush( brush2 );                                    // set the yellow brush
		p.setPen( TQt::NoPen );                                  // do not draw outline
		p.drawRect( 40,30, 200,100 );                            // draw filled rectangle
		p.setBrush( TQt::NoBrush );                              // do not fill
		p.setPen( TQt::blue );                                   // set blue pen, 0 pixel width
		p.drawRect( 10,10, 30,20 );                              // draw rectangle outline
		TQBrush brush3( TQColor(255,128,0), TQBrush::SolidPattern );     // green pattern
		p.setBrush( brush3 );                                    // set the yellow brush
		p.setPen( TQColor(255,0,255) );                          // draw outline
		p.drawRect( 50,40, 180,80 );                             // draw filled rectangle
	}

	// Line tests
	{
		p.setPen( TQt::blue );                                   // set blue pen, 0 pixel width
		p.drawLine(140,140, 160,160);
	}

	// Point tests
	{
		p.setPen( TQt::green );                                  // set green pen, 0 pixel width
		p.drawPoint(135,135);
	}

	// Polyline tests
	{
		TQPointArray a;
		int x1 = 250;
		int y1 = 10;

		a.setPoints( 11, x1+0, y1+85, x1+75, y1+75, x1+100, y1+10, x1+125, y1+75, x1+200, y1+85, x1+150, y1+125, x1+160, y1+190, x1+100, y1+150, x1+40, y1+190, x1+50, y1+125, x1+0, y1+85 );
		p.setPen(TQt::red);
		p.drawPolyline(a);
	}

	// Polyfill tests
	{
		TQPointArray a;
		int x1 = 250;
		int y1 = 200;

		a.setPoints( 11, x1+0, y1+85, x1+75, y1+75, x1+100, y1+10, x1+125, y1+75, x1+200, y1+85, x1+150, y1+125, x1+160, y1+190, x1+100, y1+150, x1+40, y1+190, x1+50, y1+125, x1+0, y1+85 );
		p.setPen(TQt::blue);
		p.setBrush(TQt::green);
		p.drawPolygon(a);
	}

	// Rounded rectangle tests
	{
		p.setBrush(TQt::green);
		p.setPen(TQPen(TQt::red, 1));
		p.drawRoundRect(10, 150, 50, 50);
		p.setBrush(TQBrush());
		p.setPen(TQPen(TQt::blue, 1));
		p.drawRoundRect(80, 150, 50, 50);
	}

	// Ellipse tests
	{
		p.setBrush(TQt::green);
		p.setPen(TQPen(TQt::red, 1));
		p.drawEllipse(10, 220, 50, 50);
		p.setBrush(TQBrush());
		p.setPen(TQPen(TQt::blue, 1));
		p.drawEllipse(80, 220, 50, 50);
	}

	// Arc tests
	{
		p.setBrush(TQBrush());
		p.setPen(TQPen(TQt::yellow, 1));
		p.drawArc(10,10, 70,100, 100*16, 160*16); // draws a "(" arc
	}

	// Pie tests
	{
		p.setBrush(TQBrush());
		p.setPen(TQPen(TQt::red, 1));
		p.drawPie(250, 400, 200, 100, 45*16, 90*16);
		p.setBrush(TQt::green);
		p.setPen(TQPen(TQt::blue, 1));
		p.drawPie(250, 450, 200, 100, 45*16, 90*16);
	}

	// Chord tests
	{
		p.setBrush(TQBrush());
		p.setPen(TQPen(TQt::red, 1));
		p.drawChord(100, 400, 200, 100, 45*16, 90*16);
		p.setBrush(TQt::green);
		p.setPen(TQPen(TQt::blue, 1));
		p.drawChord(100, 450, 200, 100, 45*16, 90*16);
	}

	p.end();

	/* Write output and clean up */
        cairo_surface_write_to_png (surface, "stroke.png");
//         cairo_destroy (cr);
        cairo_surface_destroy (surface);

        return 0;
}