1 // Drawing mode setting and getting example.
2 //
3 // Copyright (C) 2011 Hezekiah M. Carty
4 //
5 // This file is part of PLplot.
6 //
7 // PLplot is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU Library General Public License as published
9 // by the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // PLplot is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public License
18 // along with PLplot; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21 //
22
23 #include "plcdemos.h"
24
25 // Drawing modes to demonstrate
26 #define NUM_MODES 3
27 PLINT drawing_modes[NUM_MODES] = {
28 PL_DRAWMODE_DEFAULT,
29 PL_DRAWMODE_REPLACE,
30 PL_DRAWMODE_XOR
31 };
32
33 PLCHAR_VECTOR drawing_mode_names[NUM_MODES] = {
34 "Default drawing mode",
35 "Replace destination with source",
36 "XOR drawing"
37 };
38
39 void initialize_colors( void );
40 void draw_page( PLINT mode, PLCHAR_VECTOR title );
41
42 //--------------------------------------------------------------------------
43 // main
44 //--------------------------------------------------------------------------
45
main(int argc,char * argv[])46 int main( int argc, char *argv[] )
47 {
48 PLINT mode;
49 PLINT i;
50
51 // PLplot initialization
52
53 // Parse and process command line arguments
54 plparseopts( &argc, argv, PL_PARSE_FULL );
55
56 // Initialize PLplot
57 plinit();
58
59 // Check for drawing mode support
60 mode = plgdrawmode();
61
62 if ( mode == PL_DRAWMODE_UNKNOWN )
63 {
64 printf( "WARNING: This driver does not support drawing mode getting/setting" );
65 }
66 else
67 {
68 // Setup colors
69 initialize_colors();
70
71 // Draw one page per drawing mode
72 for ( i = 0; i < NUM_MODES; i++ )
73 {
74 draw_page( drawing_modes[i], drawing_mode_names[i] );
75 }
76 }
77
78 // Clean up
79 plend();
80
81 exit( 0 );
82 }
83
initialize_colors(void)84 void initialize_colors( void )
85 {
86 plscol0( 0, 255, 255, 255 );
87 plscol0( 1, 0, 0, 0 );
88 plscol0( 2, 255, 0, 0 );
89 plscol0a( 3, 0, 0, 255, 0.3 );
90 }
91
draw_page(PLINT mode,PLCHAR_VECTOR title)92 void draw_page( PLINT mode, PLCHAR_VECTOR title )
93 {
94 PLFLT xs[3], ys[3];
95 PLFLT over_x, over_y, over_r;
96
97 // A triangle for the background
98 xs[0] = 0.0;
99 xs[1] = 1.0;
100 xs[2] = 0.0;
101 ys[0] = 0.0;
102 ys[1] = 1.0;
103 ys[2] = 1.0;
104
105 // A circle for the foreground
106 over_x = 0.5;
107 over_y = 0.5;
108 over_r = 0.4;
109
110 plcol0( 1 );
111
112 // Setup a plot window
113 plenv( 0.0, 1.0, 0.0, 1.0, 1, 0 );
114
115 // Show which mode we're using
116 pllab( "", "", title );
117
118 // Draw a background triangle using the default drawing mode
119 plcol0( 2 );
120 plsdrawmode( PL_DRAWMODE_DEFAULT );
121 plfill( 3, xs, ys );
122
123 // Draw a circle in the given drawing mode
124 plcol0( 3 );
125 plsdrawmode( mode );
126 plarc( over_x, over_y, over_r, over_r, 0.0, 360.0, 0.0, 1 );
127 }
128