55#include "vector_display_glinc.h"
66#include "vector_display.h"
77#include "vector_font_simplex.h"
8+ #include "vector_shapes.h"
89
910static vector_display_t * display ;
1011static int dwidth ;
1112static int dheight ;
1213
13- static double scale = 1.0 ;
14- static int offsetx ;
15- static int offsety ;
16-
17- static void draw_line (vector_display_t * display , double x0 , double y0 , double x1 , double y1 ) {
18- vector_display_begin_draw (display , x0 , y0 );
19- vector_display_draw_to (display , x1 , y1 );
20- vector_display_end_draw (display );
21- }
22-
23- static void draw_wheel (vector_display_t * display , double angle , double x , double y , double radius ) {
24- double spokeradius = radius - 2.0f ;
25- // draw spokes
26- draw_line (display ,
27- x + spokeradius * sin (angle ),
28- y - spokeradius * cos (angle ),
29- x - spokeradius * sin (angle ),
30- y + spokeradius * cos (angle ));
31- draw_line (display ,
32- x + spokeradius * sin (angle + M_PI / 4.0f ),
33- y - spokeradius * cos (angle + M_PI / 4.0f ),
34- x - spokeradius * sin (angle + M_PI / 4.0f ),
35- y + spokeradius * cos (angle + M_PI / 4.0f ));
36- draw_line (display ,
37- x + spokeradius * sin (angle + M_PI / 2.0f ),
38- y - spokeradius * cos (angle + M_PI / 2.0f ),
39- x - spokeradius * sin (angle + M_PI / 2.0f ),
40- y + spokeradius * cos (angle + M_PI / 2.0f ));
41- draw_line (display ,
42- x + spokeradius * sin (angle + 3.0f * M_PI / 4.0f ),
43- y - spokeradius * cos (angle + 3.0f * M_PI / 4.0f ),
44- x - spokeradius * sin (angle + 3.0f * M_PI / 4.0f ),
45- y + spokeradius * cos (angle + 3.0f * M_PI / 4.0f ));
46-
47- double edgeangle = 0.0f ;
48- double angadjust = 0.0f ;
49-
50- vector_display_begin_draw (display ,
51- x + radius * sin (angle + edgeangle + angadjust ),
52- y - radius * cos (angle + edgeangle + angadjust ));
53- for (edgeangle = 0 ; edgeangle < 2 * M_PI - 0.001 ; edgeangle += M_PI /4.0f ) {
54- vector_display_draw_to (display ,
55- x + radius * sin (angle + edgeangle + M_PI / 4.0f - angadjust ),
56- y - radius * cos (angle + edgeangle + M_PI / 4.0f - angadjust ));
57- }
58- vector_display_end_draw (display );
59- }
60-
61- static void draw_circle (vector_display_t * display , double x , double y , double radius , double steps ) {
62- double edgeangle = 0.0f ;
63- double angadjust = 0.0f ;
64-
65- double step = M_PI * 2 / steps ;
66-
67- vector_display_begin_draw (display ,
68- x + radius * sin (edgeangle + angadjust ),
69- y - radius * cos (edgeangle + angadjust ));
70- for (edgeangle = 0 ; edgeangle < 2 * M_PI - 0.001 ; edgeangle += step ) {
71- vector_display_draw_to (display ,
72- x + radius * sin (edgeangle + step - angadjust ),
73- y - radius * cos (edgeangle + step - angadjust ));
74- }
75- vector_display_end_draw (display );
76- }
77-
78- static void draw_box (vector_display_t * display , double x , double y , double w , double h ) {
79- vector_display_begin_draw (display , x , y );
80- vector_display_draw_to (display , x + w , y );
81- vector_display_draw_to (display , x + w , y + h );
82- vector_display_draw_to (display , x , y + h );
83- vector_display_draw_to (display , x , y );
84- vector_display_end_draw (display );
85- }
86-
87- static int fixx (int x ) {
88- return (int )((double )x * scale ) + offsetx ;
89- }
90- static int fixy (int y ) {
91- return (int )((double )y * scale ) + offsety ;
92- }
93- static double fix (double v ) {
94- return v * scale ;
95- }
96-
9714void
9815VectorTestImpl_Draw ()
9916{
@@ -109,10 +26,10 @@ VectorTestImpl_Draw()
10926 //
11027 //vector_font_simplex_draw(display, 100, 1300, 5.0, "Hello, World!");
11128 vector_display_set_color (display , 0.7f , 0.7f , 1.0f );
112- vector_font_simplex_draw (display , fixx (50 ), fixy (180 ), fix (3.5 ), "ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
113- vector_font_simplex_draw (display , fixx (50 ), fixy (360 ), fix (3.5 ), "abcdefghijklmnopqrstuvwxyz" );
114- vector_font_simplex_draw (display , fixx (50 ), fixy (540 ), fix (3.5 ), buf );
115- vector_font_simplex_draw (display , fixx (50 ), fixy (720 ), fix (3.5 ), "!@#$%^&*()-=<>/?;:'\"{}[]|\\+=-_" );
29+ vector_font_simplex_draw (display , (50 ), (180 ), (3.5 ), "ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
30+ vector_font_simplex_draw (display , (50 ), (360 ), (3.5 ), "abcdefghijklmnopqrstuvwxyz" );
31+ vector_font_simplex_draw (display , (50 ), (540 ), (3.5 ), buf );
32+ vector_font_simplex_draw (display , (50 ), (720 ), (3.5 ), "!@#$%^&*()-=<>/?;:'\"{}[]|\\+=-_" );
11633
11734
11835 //
@@ -121,36 +38,36 @@ VectorTestImpl_Draw()
12138 vector_display_set_color (display , 1.0f , 0.7f , 0.7f );
12239 for (i = 0 ; i < 4 ; i ++ ) {
12340 for (j = 0 ; j < i ; j ++ ) {
124- draw_line (display , fixx (50 ), fixy (750 + 100 * i ), fixx (400 ), fixy (750 + 100 * i ));
41+ vector_shape_draw_line (display , (50 ), (750 + 100 * i ), (400 ), (750 + 100 * i ));
12542 }
12643 }
12744
12845 for (i = 0 ; i < 4 ; i ++ ) {
12946 for (j = 0 ; j <= i ; j ++ ) {
130- draw_line (display , fixx (50 + 100 * i ), fixy (1200 ), fixx (50 + 100 * i ), fixy (1400 ));
47+ vector_shape_draw_line (display , (50 + 100 * i ), (1200 ), (50 + 100 * i ), (1400 ));
13148 }
13249 }
13350
13451 //
13552 // test pattern for shapes
13653 //
13754 vector_display_set_color (display , 0.7f , 0.7f , 1.0f );
138- draw_circle (display , fixx (500 ), fixy (950 ), fix (20 ), 32 );
139- draw_circle (display , fixx (600 ), fixy (950 ), fix (50 ), 32 );
140- draw_circle (display , fixx (800 ), fixy (950 ), fix (100 ), 32 );
141- draw_circle (display , fixx (1075 ), fixy (950 ), fix (150 ), 64 );
55+ vector_shape_draw_circle (display , (500 ), (950 ), (20 ), 32 );
56+ vector_shape_draw_circle (display , (600 ), (950 ), (50 ), 32 );
57+ vector_shape_draw_circle (display , (800 ), (950 ), (100 ), 32 );
58+ vector_shape_draw_circle (display , (1075 ), (950 ), (150 ), 64 );
14259
14360 vector_display_set_color (display , 0.7f , 1.0f , 0.7f );
144- draw_box (display , fixx (500 ), fixy (1200 ), fix (40 ), fix (40 ));
145- draw_box (display , fixx (565 ), fixy (1200 ), fix (100 ), fix (100 ));
146- draw_box (display , fixx (700 ), fixy (1200 ), fix (200 ), fix (200 ));
147- draw_box (display , fixx (950 ), fixy (1200 ), fix (300 ), fix (300 ));
61+ vector_shape_draw_box (display , (500 ), (1200 ), (40 ), (40 ));
62+ vector_shape_draw_box (display , (565 ), (1200 ), (100 ), (100 ));
63+ vector_shape_draw_box (display , (700 ), (1200 ), (200 ), (200 ));
64+ vector_shape_draw_box (display , (950 ), (1200 ), (300 ), (300 ));
14865
14966 vector_display_set_color (display , 1.0f , 0.7f , 1.0f );
150- draw_wheel (display , M_PI , fixx (1425 ), fixy (950 ), fix (150 ));
151- draw_wheel (display , 3 * M_PI / 4 , fixx (1700 ), fixy (950 ), fix (100 ));
152- draw_wheel (display , M_PI / 2 , fixx (1900 ), fixy (950 ), fix (50 ));
153- draw_wheel (display , M_PI / 4 , fixx (2000 ), fixy (950 ), fix (20 ));
67+ vector_shape_draw_wheel (display , M_PI , (1425 ), (950 ), (150 ));
68+ vector_shape_draw_wheel (display , 3 * M_PI / 4 , (1700 ), (950 ), (100 ));
69+ vector_shape_draw_wheel (display , M_PI / 2 , (1900 ), (950 ), (50 ));
70+ vector_shape_draw_wheel (display , M_PI / 4 , (2000 ), (950 ), (20 ));
15471
15572 //
15673 // finish
@@ -171,13 +88,11 @@ static void resize(int w, int h)
17188 dheight = h ;
17289
17390 if (((double )dwidth / (double )dheight ) < (2048.0 /1536.0 )) {
174- scale = (double )dwidth / 2048.0 ;
175- offsetx = 0 ;
176- offsety = (dheight - (int )((double )1536 * scale )) / 2 ;
91+ double scale = (double )dwidth / 2048.0 ;
92+ vector_display_set_transform (display , 0 , (dheight - (int )((double )1536 * scale )) / 2 , scale );
17793 } else {
178- scale = (double )dheight / 1536.0 ;
179- offsetx = (dwidth - (int )((double )2048 * scale )) / 2 ;
180- offsety = 0 ;
94+ double scale = (double )dheight / 1536.0 ;
95+ vector_display_set_transform (display , (dwidth - (int )((double )2048 * scale )) / 2 , 0 , scale );
18196 }
18297}
18398
0 commit comments