VPR-7.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
graphics.h
Go to the documentation of this file.
1 //<<<<<<< .mine
2 #ifndef GRAPHICS_H
3 #define GRAPHICS_H
4 #include <iostream>
5 #include <string>
6 #include "easygl_constants.h"
7 using namespace std;
8 
9 // Set X11 by default, if neither NO_GRAPHICS nor WIN32 are defined
10 #ifndef NO_GRAPHICS
11 #ifndef WIN32
12  #ifndef X11
13  #define X11
14  #endif
15 #endif // !WIN32
16 #endif // !NO_GRAPHICS
17 
18 /* Graphics.h
19 * Originally written by Vaughn Betz (vaughn@eecg.utoronto.ca)
20 * Win32 port by Paul Leventis (leventi@eecg.utoronto.ca)
21 * Enhanced version by William Chow (chow@eecg.utoronto.ca)
22 * Minor updates by Guy Lemieux (lemieux@ece.ubc.ca)
23 * More updates by Vaughn Betz to make win32 cleaner and more robust.
24 */
25 
26 
27 /******* Constants and enums ******************************************/
28 
29 /* Data structure below is for debugging. Lets you get a bunch
30  * of info about the low-level graphics state.
31  * xmult, ymult: world to pixel coordinate multiplier for screen
32  * ps_xmult, ps_ymult: world to pixel coordinate multiplier for postscript
33  * xleft, xright, ytop, yleft: current world coordinates of user-graphics display corners
34  * top_width, top_height: size (in pixels) of top-level window
35  */
36 typedef struct {
37  float xmult, ymult;
39  float xleft, xright, ytop, ybot;
41 } t_report;
42 
43 /************** ESSENTIAL FUNCTIONS ******************/
44 
45 /* This is the main routine for the graphics. When event_loop is
46 * called, it will continue executing until the Proceed button is
47 * pressed.
48 * Whenever the graphics need to be redrawn, drawscreen will be called;
49 * you must pass in a function pointer to a routine you write that can
50 * draw the picture you want.
51 * You can also pass in event handlers for user input if you wish.
52 * act_on_mouse_button() will be called whenever the user left-clicks
53 * in the graphics area.
54 * act_on_keypress() and act_on_mousemove() will be called whenever a
55 * keyboard key is pressed or the mouse is moved, respectively, in the
56 * graphics area. You can turn keypress input and mouse_move input
57 * on or off using the set_mouse_move_input () and set_keypress_input ()
58 * functions (default for both: off).
59 */
60 void event_loop (void (*act_on_mousebutton) (float x, float y),
61  void (*act_on_mousemove) (float x, float y),
62  void (*act_on_keypress) (char key_pressed),
63  void (*drawscreen) (void));
64 
65 /* Opens up the graphics; the window will have window_name in its
66  * title bar and the specified background colour.
67  * Known bug: can't re-open graphics after closing them.
68  */
69 void init_graphics (const char *window_name, int cindex_background);
70 
71 /* Sets world coordinates of the graphics window so that the
72  * upper-left corner has virtual coordinate (xl, yt) and the
73  * bottom-right corner has virtual coordinate (xr, yb).
74  * Call this function before you call event_loop. Do not call it
75  * in your drawscreen () callback function, since it will undo any
76  * panning or zooming the user has done.
77  */
78 void init_world (float xl, float yt, float xr, float yb);
79 
80 /* Closes the graphics */
81 void close_graphics (void);
82 
83 /* Changes the status bar message to msg. */
84 void update_message (const char *msg);
85 
86 /* Creates a button on the menu bar below the button with text
87  * prev_button_text. The button will have text button_text,
88  * and when clicked will call function button_func.
89  * button_func is a function that accepts a void function as
90  * an argument; this argument is set to the drawscreen routine
91  * as passed into the event loop.
92  */
93 void create_button (const char *prev_button_text , const char *button_text,
94  void (*button_func) (void (*drawscreen) (void)));
95 
96 /* Destroys the button with the given text; i.e. removes it from
97  * the display.
98  */
99 void destroy_button (const char *button_text);
100 
101 /*************** PostScript Routines *****************/
102 
103 /* Opens file for postscript commands and initializes it. All subsequent
104  * drawing commands go to this file until close_postscript is called.
105  * You can generate postscript output by explicitly calling
106  * this routine, and then calling drawscreen. More commonly you'll
107  * just click on the "PostScript" button though, and that button
108  * calls this routine and drawscreen to generate a postscript file
109  * that exactly matches the graphics area display on the screen.
110  */
111 int init_postscript (const char *fname); /* Returns 1 if successful */
112 
113 /* Closes file and directs output to screen again. */
114 void close_postscript (void);
115 
116 
117 /*************** DRAWING ROUTINES ******************/
118 
119 /* Clears the screen. Should normally be the first call in your
120  * screen redrawing function.
121  */
122 void clearscreen (void);
123 
124 /* The following routines draw to SCREEN if disp_type = SCREEN
125  * and to a PostScript file if disp_type = POSTSCRIPT
126  */
127 
128 /* Set the current draw colour to the supplied colour index from color_types */
129 void setcolor (int cindex);
130 
131 /* Set the color with a string instead of an enumerated constant */
132 void setcolor (string cname);
133 
134 /* Get the current color */
135 int getcolor(void);
136 
137 /* Sets the line style to the specified line_style */
138 void setlinestyle (int linestyle);
139 
140 /* Sets the line width in pixels (for screen output) or points (1/72 of an inch)
141  * for PostScript output. A value of 0 means thinnest possible line.
142  */
143 void setlinewidth (int linewidth);
144 
145 /* Sets the font size, in points. 72 points is 1 inch high. I allow
146  * fonts from 1 to 24 points in size; change MAX_FONT_SIZE if you want
147  * bigger fonts still.
148  */
149 void setfontsize (int pointsize);
150 
151 /* Draws a line from (x1, y1) to (x2, y2) in world coordinates */
152 void drawline (float x1, float y1, float x2, float y2);
153 
154 /* Draws a rectangle from (x1, y1) to (x2, y2) in world coordinates, using
155  * the current line style, colour and width.
156  */
157 void drawrect (float x1, float y1, float x2, float y2);
158 
159 /* Draws a filled rectangle with the specified corners, in world coordinates. */
160 void fillrect (float x1, float y1, float x2, float y2);
161 
162 /* Draws a filled polygon */
163 void fillpoly (t_point *points, int npoints);
164 
165 /* Draw or fill a circular arc or elliptical arc. Angles in degrees.
166  * startang is measured from positive x-axis of Window.
167  * A positive angextent means a counterclockwise arc; a negative
168  * angextent means clockwise.
169  */
170 void drawarc (float xcen, float ycen, float rad, float startang,
171  float angextent);
172 void fillarc (float xcen, float ycen, float rad, float startang,
173  float angextent);
174 void drawellipticarc (float xc, float yc, float radx, float rady, float startang, float angextent);
175 void fillellipticarc (float xc, float yc, float radx, float rady, float startang, float angextent);
176 
177 /* boundx specifies horizontal bounding box. If text won't fit in
178  * the space specified by boundx (world coordinates) the text isn't drawn.
179  * That avoids text going everywhere for high zoom levels.
180  * If you always want the text to display (even if it overwrites lots of
181  * stuff at high zoom levels), just specify a huge boundx.
182  */
183 void drawtext (float xc, float yc, const char *text, float boundx);
184 
185 /* Control what buttons are active (default: all enabled) and
186  * whether mouse movements and keypresses are sent to callback
187  * functions (default: disabled).
188  */
189 void set_mouse_move_input (bool turn_on);
190 void set_keypress_input (bool turn_on);
191 void enable_or_disable_button (int ibutton, bool enabled);
192 
193 /*************** ADVANCED FUNCTIONS *****************/
194 
195 /* Normal users shouldn't have to use draw_message. Should only be
196  * useful if using non-interactive graphics and you want to redraw
197  * yourself because of an expose. i
198  */
199 void draw_message (void);
200 
201 /* Empties event queue. Can be useful with non-interactive graphics to make
202  * sure things display.
203  */
204 void flushinput (void);
205 
206 /* DRAW_NORMAL is the default mode (overwrite, also known as copy_pen).
207  * Can use DRAW_XOR for fast rubber-banding.
208  */
210 void set_draw_mode (enum e_draw_mode draw_mode);
211 
212 /* Change the text on a button.
213  */
214 void change_button_text(const char *button_text, const char *new_button_text);
215 
216 /* For debugging only. Get window size etc. */
218 
219 
220 /**************** Extra functions available only in WIN32. *******/
221 #ifdef WIN32
222 /* VB: TODO: I should make any generally useful functions below work in
223  * X11 as well, and probably delete anything else.
224  */
225 
226 /* Added by William to provide double buffering in Windows */
227 void drawtobuffer(void);
228 void drawtoscreen(void);
229 void displaybuffer(void);
230 void drawcurve(t_point *points, int npoints);
231 void fillcurve(t_point *points, int npoints);
232 void object_start(int all);
233 void object_end();
234 int pt_on_object(int all, float x, float y);
235 int findfontsize(float ymax);
236 
237 #endif // WIN32
238 
239 #endif // GRAPHICS_H
void draw_message(void)
Definition: graphics.c:2063
void enable_or_disable_button(int ibutton, bool enabled)
Definition: graphics.c:2867
void create_button(const char *prev_button_text, const char *button_text, void(*button_func)(void(*drawscreen)(void)))
Definition: graphics.c:881
void destroy_button(const char *button_text)
Definition: graphics.c:954
float ps_ymult
Definition: graphics.h:38
int init_postscript(const char *fname)
Definition: graphics.c:2477
void drawellipticarc(float xc, float yc, float radx, float rady, float startang, float angextent)
Definition: graphics.c:1719
void report_structure(t_report *)
Definition: graphics.c:2843
float ymult
Definition: graphics.h:37
void drawtext(float xc, float yc, const char *text, float boundx)
Definition: graphics.c:1952
void fillellipticarc(float xc, float yc, float radx, float rady, float startang, float angextent)
Definition: graphics.c:1798
void change_button_text(const char *button_text, const char *new_button_text)
Definition: graphics.c:2906
void fillrect(float x1, float y1, float x2, float y2)
Definition: graphics.c:1643
void flushinput(void)
Definition: graphics.c:2027
void set_mouse_move_input(bool turn_on)
Definition: graphics.c:2857
static float xleft
Definition: graphics.c:318
void set_draw_mode(enum e_draw_mode draw_mode)
Definition: graphics.c:2881
void init_graphics(const char *window_name, int cindex_background)
Definition: graphics.c:1003
void set_keypress_input(bool turn_on)
Definition: graphics.c:2862
static void drawscreen(void)
Definition: draw.c:212
void close_postscript(void)
Definition: graphics.c:2602
void fillarc(float xcen, float ycen, float rad, float startang, float angextent)
Definition: graphics.c:1876
static int top_height
Definition: graphics.c:317
void clearscreen(void)
Definition: graphics.c:1483
void setcolor(int cindex)
Definition: graphics.c:619
static float xright
Definition: graphics.c:318
int top_width
Definition: graphics.h:40
static float ybot
Definition: graphics.c:318
void drawline(float x1, float y1, float x2, float y2)
Definition: graphics.c:1539
void update_message(const char *msg)
Definition: graphics.c:2113
static float xmult
Definition: graphics.c:324
static float ps_xmult
Definition: graphics.c:323
void fillpoly(t_point *points, int npoints)
Definition: graphics.c:1881
void init_world(float xl, float yt, float xr, float yb)
Definition: graphics.c:2038
int getcolor(void)
Definition: graphics.c:647
void close_graphics(void)
Definition: graphics.c:2417
void event_loop(void(*act_on_mousebutton)(float x, float y), void(*act_on_mousemove)(float x, float y), void(*act_on_keypress)(char key_pressed), void(*drawscreen)(void))
Definition: graphics.c:1352
void drawarc(float xcen, float ycen, float rad, float startang, float angextent)
Definition: graphics.c:1787
void setfontsize(int pointsize)
Definition: graphics.c:796
void setlinestyle(int linestyle)
Definition: graphics.c:697
float ytop
Definition: graphics.h:39
void drawrect(float x1, float y1, float x2, float y2)
Definition: graphics.c:1581
e_draw_mode
Definition: graphics.h:209
void setlinewidth(int linewidth)
Definition: graphics.c:743