1 /**
2  ** sbctest.c ---- test subcontext
3  **
4  ** This is a test/demo file of the GRX graphics library.
5  ** You can use GRX test/demo files as you want.
6  **
7  ** The GRX graphics library is free software; you can redistribute it
8  ** and/or modify it under some conditions; see the "copying.grx" file
9  ** for details.
10  **
11  ** This library is distributed in the hope that it will be useful,
12  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  **
15  **/
16 
17 #include <string.h>
18 #include "test.h"
19 
20 static void drawpf( int border, GrPattern *pat );
21 static void drawp( int border, GrLinePattern *grlp );
22 
TESTFUNC(sbctest)23 TESTFUNC(sbctest)
24 {
25   char bits[] = {0, 76, 50, 0, 0, 76, 60, 0};
26   GrContext *grc, *grsc;
27   GrPattern *pat1, *pat2;
28   GrLineOption grl;
29   GrLinePattern grlp;
30   GrFont *grf;
31   GrTextOption grt;
32 
33   grc = GrCreateContext( 300,300,NULL,NULL );
34   if( grc == NULL ) return;
35   grsc = GrCreateSubContext( 10,10,290,290,grc,NULL );
36   if( grsc == NULL ) return;
37   pat1 = GrBuildPixmapFromBits( bits,8,8,GrWhite(),GrBlack() );
38   if( pat1 == NULL ) return;
39   pat2 = GrBuildPixmapFromBits( bits,8,8,GrBlack(),GrWhite() );
40   if( pat2 == NULL ) return;
41   grf = GrLoadFont( "lucb40.fnt" );
42   if( grf == NULL ){
43     grf = GrLoadFont( "../fonts/lucb40.fnt" );
44     if( grf == NULL ) return;
45     }
46 
47   GrBox( 19,19,320,320,GrWhite() );
48 
49   GrTextXY( 0,0,"White drawing on context       ",GrWhite(),GrBlack() );
50   GrSetContext( grc );
51   GrClearContext( GrBlack() );
52   drawing( 10,10,280,280,GrWhite(),GrNOCOLOR );
53   GrSetContext( NULL );
54   GrBitBlt( NULL,20,20,grc,0,0,299,299,GrWRITE );
55   GrKeyRead();
56 
57   GrTextXY( 0,0,"Black drawing on subcontext    ",GrWhite(),GrBlack() );
58   GrSetContext( grsc );
59   drawing( 0,0,280,280,GrBlack(),GrNOCOLOR );
60   GrSetContext( NULL );
61   GrBitBlt( NULL,20,20,grc,0,0,299,299,GrWRITE );
62   GrKeyRead();
63 
64   GrTextXY( 0,0,"Pattern drawing on context     ",GrWhite(),GrBlack() );
65   GrSetContext( grc );
66   GrClearContext( GrBlack() );
67   drawpf( 10,pat1 );
68   GrSetContext( NULL );
69   GrBitBlt( NULL,20,20,grc,0,0,299,299,GrWRITE );
70   GrKeyRead();
71 
72   GrTextXY( 0,0,"Pattern drawing on subcontext  ",GrWhite(),GrBlack() );
73   GrSetContext( grsc );
74   GrClearContext( GrBlack() );
75   drawpf( 0,pat2 );
76   GrSetContext( NULL );
77   GrBitBlt( NULL,20,20,grc,0,0,299,299,GrXOR );
78   GrKeyRead();
79 
80   grl.lno_color = GrWhite();
81   grl.lno_width = 3;
82   grl.lno_pattlen = 0;
83   grlp.lnp_pattern = pat1;
84   grlp.lnp_option = &grl;
85 
86   GrTextXY( 0,0,"Patterned drawing on context   ",GrWhite(),GrBlack() );
87   GrSetContext( grc );
88   GrClearContext( GrBlack() );
89   grlp.lnp_pattern = pat1;
90   drawp( 10,&grlp );
91   GrSetContext( NULL );
92   GrBitBlt( NULL,20,20,grc,0,0,299,299,GrWRITE );
93   GrKeyRead();
94 
95   GrTextXY( 0,0,"Patterned drawing on subcontext",GrWhite(),GrBlack() );
96   GrSetContext( grsc );
97   GrClearContext( GrBlack() );
98   grlp.lnp_pattern = pat2;
99   drawp( 0,&grlp );
100   GrSetContext( NULL );
101   GrBitBlt( NULL,20,20,grc,0,0,299,299,GrXOR );
102   GrKeyRead();
103 
104   grt.txo_fgcolor.v = GrWhite();
105   grt.txo_bgcolor.v = GrBlack() | GrOR;
106   grt.txo_font = grf;
107   grt.txo_direct = GR_TEXT_RIGHT;
108   grt.txo_xalign = GR_ALIGN_LEFT;
109   grt.txo_yalign = GR_ALIGN_CENTER;
110   grt.txo_chrtype = GR_BYTE_TEXT;
111 
112   GrTextXY( 0,0,"Patterned text on context      ",GrWhite(),GrBlack() );
113   GrSetContext( grc );
114   GrClearContext( GrBlack() );
115   GrPatternDrawString( "Hello all",9,20,60,&grt,pat1 );
116   GrPatternDrawChar( 'G',20,120,&grt,pat1 );
117   GrPatternDrawStringExt( "Hola a todos",12,20,180,&grt,pat1 );
118   GrSetContext( NULL );
119   GrBitBlt( NULL,20,20,grc,0,0,299,299,GrWRITE );
120   GrKeyRead();
121 
122   GrTextXY( 0,0,"Patterned text on subcontext   ",GrWhite(),GrBlack() );
123   GrSetContext( grsc );
124   GrClearContext( GrBlack() );
125   GrPatternDrawString( "Hello all",9,10,50,&grt,pat2 );
126   GrPatternDrawChar( 'G',10,110,&grt,pat2 );
127   GrPatternDrawStringExt( "Hola a todos",12,10,170,&grt,pat2 );
128   GrSetContext( NULL );
129   GrBitBlt( NULL,20,20,grc,0,0,299,299,GrXOR );
130   GrKeyRead();
131 
132   GrUnloadFont( grf );
133   GrDestroyPattern( pat2 );
134   GrDestroyPattern( pat1 );
135   GrDestroyContext( grsc );
136   GrDestroyContext( grc );
137 }
138 
139 /***/
140 
drawpf(int border,GrPattern * pat)141 static void drawpf( int border, GrPattern *pat )
142 {
143   int pt1[4][2] = {{130,200},{140,240},{150,250},{160,180}};
144   int pt2[4][2] = {{230,200},{235,240},{246,250},{258,180}};
145   int ptaux[4][2];
146   int i,j;
147 
148   GrPatternFilledBox( 0+border,0+border,93+border,93+border,pat );
149   GrPatternFilledCircle( 139+border,46+border,45,pat );
150   GrPatternFilledEllipse( 232+border,46+border,45,35,pat );
151   GrPatternFilledCircleArc( 46+border,139+border,45,-300,600,
152                             GR_ARC_STYLE_CLOSE2,pat );
153   GrPatternFilledEllipseArc( 139+border,139+border,45,35,-700,400,
154                              GR_ARC_STYLE_CLOSE2,pat );
155   GrPatternFilledLine( 188+border,139+border,278+border,139+border,pat );
156   GrPatternFilledPlot( 47+border,228+border,pat );
157   GrPatternFilledPlot( 47+border,229+border,pat );
158   GrPatternFilledPlot( 47+border,230+border,pat );
159   GrPatternFilledPlot( 47+border,231+border,pat );
160   GrPatternFilledPlot( 47+border,232+border,pat );
161   for( i=0; i<4; i++ )
162     for( j=0; j<2; j++ )
163       ptaux[i][j] = pt1[i][j] + border;
164   GrPatternFilledPolygon( 4,ptaux,pat );
165   for( i=0; i<4; i++ )
166     for( j=0; j<2; j++ )
167       ptaux[i][j] = pt2[i][j] + border;
168   GrPatternFilledConvexPolygon( 4,ptaux,pat );
169 }
170 
171 /***/
172 
drawp(int border,GrLinePattern * grlp)173 static void drawp( int border, GrLinePattern *grlp )
174 {
175   int pt1[4][2] = {{130,200},{140,240},{150,250},{160,180}};
176   int pt2[4][2] = {{230,200},{235,240},{246,250},{258,180}};
177   int ptaux[4][2];
178   int i,j;
179 
180   GrPatternedBox( 0+border,0+border,93+border,93+border,grlp );
181   GrPatternedCircle( 139+border,46+border,45,grlp );
182   GrPatternedEllipse( 232+border,46+border,45,35,grlp );
183   GrPatternedCircleArc( 46+border,139+border,45,-300,600,
184                         GR_ARC_STYLE_CLOSE2,grlp );
185   GrPatternedEllipseArc( 139+border,139+border,45,35,-700,400,
186                          GR_ARC_STYLE_CLOSE2,grlp );
187   GrPatternedLine( 188+border,139+border,278+border,139+border,grlp );
188   for( i=0; i<4; i++ )
189     for( j=0; j<2; j++ )
190       ptaux[i][j] = pt1[i][j] + border;
191   GrPatternedPolygon( 4,ptaux,grlp );
192   for( i=0; i<4; i++ )
193     for( j=0; j<2; j++ )
194       ptaux[i][j] = pt2[i][j] + border;
195   GrPatternedPolyLine( 4,ptaux,grlp );
196 }
197 
198