VPR-7.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
graphics.c File Reference
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
#include "graphics.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
+ Include dependency graph for graphics.c:

Go to the source code of this file.

Data Structures

struct  t_button
 
struct  t_gl_state
 

Macros

#define TRUE   1
 
#define FALSE   0
 
#define XPOST(worldx)   (((worldx)-xleft)*ps_xmult + ps_left)
 
#define YPOST(worldy)   (((worldy)-ybot)*ps_ymult + ps_bot)
 
#define XTOWORLD(x)   (((float) x)*xdiv + xleft)
 
#define YTOWORLD(y)   (((float) y)*ydiv + ytop)
 
#define max(a, b)   (((a) > (b))? (a) : (b))
 
#define min(a, b)   ((a) > (b)? (b) : (a))
 
#define MWIDTH   104 /* width of menu window */
 
#define T_AREA_HEIGHT   24 /* Height of text window */
 
#define MAX_FONT_SIZE   24 /* Largest point size of text. */
 
#define PI   3.141592654
 
#define BUTTON_TEXT_LEN   100
 
#define BUFSIZE   1000
 
#define MAXPIXEL   15000
 
#define MINPIXEL   -15000
 
#define OFF   1
 
#define ON   0
 
#define NUM_FONT_TYPES   3
 

Enumerations

enum  t_display_type { SCREEN = 0, POSTSCRIPT = 1 }
 
enum  t_button_type { BUTTON_TEXT = 0, BUTTON_POLY, BUTTON_SEPARATOR }
 

Functions

static void * my_malloc (int ibytes)
 
static void * my_realloc (void *memblk, int ibytes)
 
static int xcoord (float worldx)
 
static int ycoord (float worldy)
 
static void force_setcolor (int cindex)
 
static void force_setlinestyle (int linestyle)
 
static void force_setlinewidth (int linewidth)
 
static void force_setfontsize (int pointsize)
 
static void load_font (int pointsize)
 
static void reset_common_state ()
 
static void build_default_menu (void)
 
static void translate_up (void(*drawscreen)(void))
 
static void translate_left (void(*drawscreen)(void))
 
static void translate_right (void(*drawscreen)(void))
 
static void translate_down (void(*drawscreen)(void))
 
static void zoom_in (void(*drawscreen)(void))
 
static void zoom_out (void(*drawscreen)(void))
 
static void zoom_fit (void(*drawscreen)(void))
 
static void adjustwin (void(*drawscreen)(void))
 
static void postscript (void(*drawscreen)(void))
 
static void proceed (void(*drawscreen)(void))
 
static void quit (void(*drawscreen)(void))
 
static void map_button (int bnum)
 
static void unmap_button (int bnum)
 
static Bool test_if_exposed (Display *disp, XEvent *event_ptr, XPointer dummy)
 
static void build_textarea (void)
 
static void drawbut (int bnum)
 
static int which_button (Window win)
 
static void turn_on_off (int pressed)
 
static void drawmenu (void)
 
void setcolor (int cindex)
 
void setcolor (string cname)
 
int getcolor ()
 
void setlinestyle (int linestyle)
 
void setlinewidth (int linewidth)
 
void setfontsize (int pointsize)
 
static void setpoly (int bnum, int xc, int yc, int r, float theta)
 
void create_button (const char *prev_button_text, const char *button_text, void(*button_func)(void(*drawscreen)(void)))
 
void destroy_button (const char *button_text)
 
void init_graphics (const char *window_name, int cindex)
 
static void update_transform (void)
 
static void update_ps_transform (void)
 
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))
 
void clearscreen (void)
 
static int rect_off_screen (float x1, float y1, float x2, float y2)
 
void drawline (float x1, float y1, float x2, float y2)
 
void drawrect (float x1, float y1, float x2, float y2)
 
void fillrect (float x1, float y1, float x2, float y2)
 
static float angnorm (float ang)
 
void drawellipticarc (float xc, float yc, float radx, float rady, float startang, float angextent)
 
void drawarc (float xc, float yc, float rad, float startang, float angextent)
 
void fillellipticarc (float xc, float yc, float radx, float rady, float startang, float angextent)
 
void fillarc (float xc, float yc, float rad, float startang, float angextent)
 
void fillpoly (t_point *points, int npoints)
 
void drawtext (float xc, float yc, const char *text, float boundx)
 
void flushinput (void)
 
void init_world (float x1, float y1, float x2, float y2)
 
void draw_message (void)
 
void update_message (const char *msg)
 
static void update_win (int x[2], int y[2], void(*drawscreen)(void))
 
void close_graphics (void)
 
int init_postscript (const char *fname)
 
void close_postscript (void)
 
void report_structure (t_report *report)
 
void set_mouse_move_input (bool enable)
 
void set_keypress_input (bool enable)
 
void enable_or_disable_button (int ibutton, bool enabled)
 
void set_draw_mode (enum e_draw_mode draw_mode)
 
void change_button_text (const char *button_name, const char *new_button_text)
 
static void menutext (Window win, int xc, int yc, const char *text)
 

Variables

static t_gl_state gl_state = {false, SCREEN, 0}
 
static const int menu_font_size = 12
 
static t_buttonbutton = NULL
 
static int num_buttons = 0
 
static int display_width
 
static int display_height
 
static int top_width
 
static int top_height
 
static float xleft
 
static float xright
 
static float ytop
 
static float ybot
 
static float saved_xleft
 
static float saved_xright
 
static float saved_ytop
 
static float saved_ybot
 
static float ps_left
 
static float ps_right
 
static float ps_top
 
static float ps_bot
 
static float ps_xmult
 
static float ps_ymult
 
static float xmult
 
static float ymult
 
static float xdiv
 
static float ydiv
 
static int currentcolor
 
static int currentlinestyle
 
static int currentlinewidth
 
static int currentfontsize
 
static e_draw_mode current_draw_mode
 
static FILE * ps
 
static int ProceedPressed
 
static char statusMessage [BUFSIZE] = ""
 
static bool font_is_loaded [MAX_FONT_SIZE+1]
 
static bool get_keypress_input
 
static bool get_mouse_move_input
 
static const char * ps_cnames [NUM_COLOR]
 
static Display * display
 
static int screen_num
 
static GC gc
 
static GC gcxor
 
static GC gc_menus
 
static GC current_gc
 
static XFontStruct * font_info [MAX_FONT_SIZE+1]
 
static Window toplevel
 
static Window menu
 
static Window textarea
 
static Colormap private_cmap
 
static int colors [NUM_COLOR]
 

Macro Definition Documentation

#define BUFSIZE   1000

Definition at line 184 of file graphics.c.

#define BUTTON_TEXT_LEN   100

Definition at line 183 of file graphics.c.

#define FALSE   0

Definition at line 146 of file graphics.c.

#define max (   a,
 
)    (((a) > (b))? (a) : (b))

Definition at line 171 of file graphics.c.

#define MAX_FONT_SIZE   24 /* Largest point size of text. */

Definition at line 179 of file graphics.c.

#define MAXPIXEL   15000

Definition at line 202 of file graphics.c.

#define min (   a,
 
)    ((a) > (b)? (b) : (a))

Definition at line 174 of file graphics.c.

#define MINPIXEL   -15000

Definition at line 203 of file graphics.c.

#define MWIDTH   104 /* width of menu window */

Definition at line 177 of file graphics.c.

#define NUM_FONT_TYPES   3
#define OFF   1
#define ON   0
#define PI   3.141592654

Definition at line 181 of file graphics.c.

#define T_AREA_HEIGHT   24 /* Height of text window */

Definition at line 178 of file graphics.c.

#define TRUE   1

Definition at line 145 of file graphics.c.

#define XPOST (   worldx)    (((worldx)-xleft)*ps_xmult + ps_left)

Definition at line 161 of file graphics.c.

#define XTOWORLD (   x)    (((float) x)*xdiv + xleft)

Definition at line 167 of file graphics.c.

#define YPOST (   worldy)    (((worldy)-ybot)*ps_ymult + ps_bot)

Definition at line 162 of file graphics.c.

#define YTOWORLD (   y)    (((float) y)*ydiv + ytop)

Definition at line 168 of file graphics.c.

Enumeration Type Documentation

Enumerator
BUTTON_TEXT 
BUTTON_POLY 
BUTTON_SEPARATOR 

Definition at line 248 of file graphics.c.

248  {
249  BUTTON_TEXT = 0,
250  BUTTON_POLY,
252 } t_button_type;
t_button_type
Definition: graphics.c:248
Enumerator
SCREEN 
POSTSCRIPT 

Definition at line 240 of file graphics.c.

240  {
241  SCREEN = 0,
242  POSTSCRIPT = 1
t_display_type
Definition: graphics.c:240

Function Documentation

static void adjustwin ( void(*)(void)  drawscreen)
static

Definition at line 2262 of file graphics.c.

2263 {
2264 #ifdef X11
2265 
2266  XEvent report;
2267  int corner, xold, yold, x[2], y[2];
2268 
2269  corner = 0;
2270  xold = -1;
2271  yold = -1; /* Don't need to init yold, but stops compiler warning. */
2272 
2273  while (corner<2) {
2274  XNextEvent (display, &report);
2275  switch (report.type) {
2276  case Expose:
2277 #ifdef VERBOSE
2278  printf("Got an expose event.\n");
2279  printf("Count is: %d.\n",report.xexpose.count);
2280  printf("Window ID is: %d.\n",report.xexpose.window);
2281 #endif
2282  if (report.xexpose.count != 0)
2283  break;
2284  if (report.xexpose.window == menu)
2285  drawmenu();
2286  else if (report.xexpose.window == toplevel) {
2287  drawscreen();
2288  xold = -1; /* No rubber band on screen */
2289  }
2290  else if (report.xexpose.window == textarea)
2291  draw_message();
2292  break;
2293  case ConfigureNotify:
2294  top_width = report.xconfigure.width;
2295  top_height = report.xconfigure.height;
2296  update_transform();
2297  drawmenu();
2298  draw_message();
2299 #ifdef VERBOSE
2300  printf("Got a ConfigureNotify.\n");
2301  printf("New width: %d New height: %d.\n",top_width,top_height);
2302 #endif
2303  break;
2304  case ButtonPress:
2305 #ifdef VERBOSE
2306  printf("Got a buttonpress.\n");
2307  printf("Window ID is: %d.\n",report.xbutton.window);
2308  printf("Location (%d, %d).\n", report.xbutton.x,
2309  report.xbutton.y);
2310 #endif
2311  if (report.xbutton.window != toplevel) break;
2312  x[corner] = report.xbutton.x;
2313  y[corner] = report.xbutton.y;
2314  if (corner == 0) {
2315  /* XSelectInput (display, toplevel, ExposureMask |
2316  StructureNotifyMask | ButtonPressMask | PointerMotionMask); */
2317  }
2318  else {
2319  update_win(x,y,drawscreen);
2320  }
2321  corner++;
2322  break;
2323  case MotionNotify:
2324  if (corner) {
2325 #ifdef VERBOSE
2326  printf("Got a MotionNotify Event.\n");
2327  printf("x: %d y: %d\n",report.xmotion.x,report.xmotion.y);
2328 #endif
2329  if (xold >= 0) { /* xold set -ve before we draw first box */
2330  // Erase prior box.
2332  XDrawRectangle(display,toplevel,gcxor,min(x[0],xold),
2333  min(y[0],yold),abs(x[0]-xold),abs(y[0]-yold));
2335  }
2336  /* Don't allow user to window under menu region */
2337  xold = min(report.xmotion.x,top_width-1-MWIDTH);
2338  yold = report.xmotion.y;
2340 
2341  // Use forcing versions, as we want these modes to apply
2342  // to the xor drawing context, and the regular versions
2343  // won't update the drawing context if there is no change in line
2344  // width etc. (but they might only be on the normal context)
2345  force_setlinewidth(1);
2348 
2349  // Draw rubber band box.
2350  XDrawRectangle(display,toplevel,gcxor,min(x[0],xold),
2351  min(y[0],yold),abs(x[0]-xold),abs(y[0]-yold));
2353  }
2354  break;
2355  }
2356  }
2357  /* XSelectInput (display, toplevel, ExposureMask | StructureNotifyMask
2358  | ButtonPressMask); */
2359 #else /* Win32 */
2360  /* Implemented as WM_LB... events */
2361 
2362  /* Begin window adjust */
2363  if (!windowAdjustFlag) {
2364  windowAdjustFlag = 1;
2365  }
2366 #endif
2367 }
static t_gl_state gl_state
Definition: graphics.c:309
#define MWIDTH
Definition: graphics.c:177
static void update_win(int x[2], int y[2], void(*drawscreen)(void))
Definition: graphics.c:2233
static Display * display
Definition: graphics.c:385
static Window textarea
Definition: graphics.c:389
static void update_transform(void)
Definition: graphics.c:1273
static void force_setcolor(int cindex)
Definition: graphics.c:581
int background_cindex
Definition: graphics.c:298
static void drawscreen(void)
Definition: draw.c:212
static GC gcxor
Definition: graphics.c:387
void draw_message(void)
Definition: graphics.c:2063
#define min(a, b)
Definition: graphics.c:174
static Window toplevel
Definition: graphics.c:389
static void drawmenu(void)
Definition: graphics.c:3126
static Window menu
Definition: graphics.c:389
static int top_height
Definition: graphics.c:317
static void force_setlinewidth(int linewidth)
Definition: graphics.c:707
static int top_width
Definition: graphics.c:317
static void force_setlinestyle(int linestyle)
Definition: graphics.c:654
void set_draw_mode(enum e_draw_mode draw_mode)
Definition: graphics.c:2881

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static float angnorm ( float  ang)
static

Definition at line 1704 of file graphics.c.

1705 {
1706  int scale;
1707 
1708  if (ang < 0) {
1709  scale = (int) (ang / 360. - 1);
1710  }
1711  else {
1712  scale = (int) (ang / 360.);
1713  }
1714  ang = ang - scale * 360;
1715  return (ang);
1716 }

+ Here is the caller graph for this function:

static void build_default_menu ( void  )
static

Definition at line 2628 of file graphics.c.

2629 {
2630  int i, xcen, x1, y1, bwid, bheight, space;
2631  const int NUM_ARROW_BUTTONS = 4, NUM_STANDARD_BUTTONS = 12, SEPARATOR_BUTTON_INDEX = 8;
2632 
2633 
2634 #ifdef X11
2635  unsigned long valuemask;
2636  XSetWindowAttributes menu_attributes;
2637 
2638  menu = XCreateSimpleWindow(display,toplevel,
2641  menu_attributes.event_mask = ExposureMask;
2642  /* Ignore button presses on the menu background. */
2643  menu_attributes.do_not_propagate_mask = ButtonPressMask;
2644  /* Keep menu on top right */
2645  menu_attributes.win_gravity = NorthEastGravity;
2646  valuemask = CWWinGravity | CWEventMask | CWDontPropagate;
2647  XChangeWindowAttributes(display, menu, valuemask, &menu_attributes);
2648  XMapWindow (display, menu);
2649 #endif
2650 
2651  button = (t_button *) my_malloc (NUM_STANDARD_BUTTONS * sizeof (t_button));
2652 
2653  /* Now do the arrow buttons */
2654  bwid = 28;
2655  space = 3;
2656  y1 = 10;
2657  xcen = 51;
2658  x1 = xcen - bwid/2;
2659  button[0].xleft = x1;
2660  button[0].ytop = y1;
2661 #ifdef X11
2662  setpoly (0, bwid/2, bwid/2, bwid/3, -PI/2.); /* Up */
2663 #else
2664  button[0].type = BUTTON_TEXT;
2665  strcpy(button[0].text, "U");
2666 #endif
2667  button[0].fcn = translate_up;
2668 
2669  y1 += bwid + space;
2670  x1 = xcen - 3*bwid/2 - space;
2671  button[1].xleft = x1;
2672  button[1].ytop = y1;
2673 #ifdef X11
2674  setpoly (1, bwid/2, bwid/2, bwid/3, PI); /* Left */
2675 #else
2676  button[1].type = BUTTON_TEXT;
2677  strcpy(button[1].text, "L");
2678 #endif
2679  button[1].fcn = translate_left;
2680 
2681  x1 = xcen + bwid/2 + space;
2682  button[2].xleft = x1;
2683  button[2].ytop = y1;
2684 #ifdef X11
2685  setpoly (2, bwid/2, bwid/2, bwid/3, 0); /* Right */
2686 #else
2687  button[2].type = BUTTON_TEXT;
2688  strcpy(button[2].text, "R");
2689 #endif
2690  button[2].fcn = translate_right;
2691 
2692  y1 += bwid + space;
2693  x1 = xcen - bwid/2;
2694  button[3].xleft = x1;
2695  button[3].ytop = y1;
2696 #ifdef X11
2697  setpoly (3, bwid/2, bwid/2, bwid/3, +PI/2.); /* Down */
2698 #else
2699  button[3].type = BUTTON_TEXT;
2700  strcpy(button[3].text, "D");
2701 #endif
2702  button[3].fcn = translate_down;
2703 
2704  for (i = 0; i < NUM_ARROW_BUTTONS; i++) {
2705  button[i].width = bwid;
2706  button[i].height = bwid;
2707  button[i].enabled = 1;
2708  }
2709 
2710  /* Rectangular buttons */
2711 
2712  y1 += bwid + space + 6;
2713  space = 8;
2714  bwid = 90;
2715  bheight = 26;
2716  x1 = xcen - bwid/2;
2717  for (i = NUM_ARROW_BUTTONS; i < NUM_STANDARD_BUTTONS; i++) {
2718  button[i].xleft = x1;
2719  button[i].ytop = y1;
2720  button[i].type = BUTTON_TEXT;
2721  button[i].width = bwid;
2722  button[i].enabled = 1;
2723  if (i != SEPARATOR_BUTTON_INDEX) {
2724  button[i].height = bheight;
2725  y1 += bheight + space;
2726  }
2727  else {
2728  button[i].height = 2;
2730  y1 += 2 + space;
2731  }
2732  }
2733 
2734  strcpy (button[4].text,"Zoom In");
2735  strcpy (button[5].text,"Zoom Out");
2736  strcpy (button[6].text,"Zoom Fit");
2737  strcpy (button[7].text,"Window");
2738  strcpy (button[8].text,"---1");
2739  strcpy (button[9].text,"PostScript");
2740  strcpy (button[10].text,"Proceed");
2741  strcpy (button[11].text,"Exit");
2742 
2743  button[4].fcn = zoom_in;
2744  button[5].fcn = zoom_out;
2745  button[6].fcn = zoom_fit;
2746  button[7].fcn = adjustwin; // see 'adjustButton' below in WIN32 section
2747  button[8].fcn = NULL;
2748  button[9].fcn = postscript;
2749  button[10].fcn = proceed;
2750  button[11].fcn = quit;
2751 
2752  for (i = 0; i < NUM_STANDARD_BUTTONS; i++)
2753  map_button (i);
2754  num_buttons = NUM_STANDARD_BUTTONS;
2755 
2756 #ifdef WIN32
2757  adjustButton = 7;
2758  if(!InvalidateRect(hButtonsWnd, NULL, TRUE))
2759  DRAW_ERROR();
2760  if(!UpdateWindow(hButtonsWnd))
2761  DRAW_ERROR();
2762 #endif
2763 }
t_button_type type
Definition: graphics.c:280
#define MWIDTH
Definition: graphics.c:177
static Display * display
Definition: graphics.c:385
static void zoom_out(void(*drawscreen)(void))
Definition: graphics.c:2144
static void translate_up(void(*drawscreen)(void))
Definition: graphics.c:2177
static int num_buttons
Definition: graphics.c:314
static void proceed(void(*drawscreen)(void))
Definition: graphics.c:2400
static int display_height
Definition: graphics.c:316
static void postscript(void(*drawscreen)(void))
Definition: graphics.c:2371
void(* fcn)(void(*drawscreen)(void))
Definition: graphics.c:274
static t_button * button
Definition: graphics.c:313
static Window toplevel
Definition: graphics.c:389
static void * my_malloc(int ibytes)
Definition: graphics.c:499
static Window menu
Definition: graphics.c:389
static void adjustwin(void(*drawscreen)(void))
Definition: graphics.c:2262
static void quit(void(*drawscreen)(void))
Definition: graphics.c:2407
int xleft
Definition: graphics.c:272
#define TRUE
Definition: graphics.c:145
static void translate_right(void(*drawscreen)(void))
Definition: graphics.c:2220
bool enabled
Definition: graphics.c:284
int height
Definition: graphics.c:271
static void map_button(int bnum)
Definition: graphics.c:824
static void zoom_fit(void(*drawscreen)(void))
Definition: graphics.c:2163
static int top_width
Definition: graphics.c:317
int ytop
Definition: graphics.c:273
static void translate_down(void(*drawscreen)(void))
Definition: graphics.c:2191
#define PI
Definition: graphics.c:181
static void setpoly(int bnum, int xc, int yc, int r, float theta)
Definition: graphics.c:809
static int colors[NUM_COLOR]
Definition: graphics.c:393
static void translate_left(void(*drawscreen)(void))
Definition: graphics.c:2205
static void zoom_in(void(*drawscreen)(void))
Definition: graphics.c:2126
int width
Definition: graphics.c:270

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void build_textarea ( void  )
static

Definition at line 2942 of file graphics.c.

2943 {
2944  XSetWindowAttributes menu_attributes;
2945  unsigned long valuemask;
2946 
2947  textarea = XCreateSimpleWindow(display,toplevel,
2950  menu_attributes.event_mask = ExposureMask;
2951  /* ButtonPresses in this area are ignored. */
2952  menu_attributes.do_not_propagate_mask = ButtonPressMask;
2953  /* Keep text area on bottom left */
2954  menu_attributes.win_gravity = SouthWestGravity;
2955  valuemask = CWWinGravity | CWEventMask | CWDontPropagate;
2956  XChangeWindowAttributes(display, textarea, valuemask, &menu_attributes);
2957  XMapWindow (display, textarea);
2958 }
#define MWIDTH
Definition: graphics.c:177
static Display * display
Definition: graphics.c:385
static Window textarea
Definition: graphics.c:389
static Window toplevel
Definition: graphics.c:389
static int top_height
Definition: graphics.c:317
static int colors[NUM_COLOR]
Definition: graphics.c:393
static int display_width
Definition: graphics.c:316
#define T_AREA_HEIGHT
Definition: graphics.c:178

+ Here is the caller graph for this function:

void change_button_text ( const char *  button_name,
const char *  new_button_text 
)

Definition at line 2906 of file graphics.c.

2906  {
2907 /* Change the text on a button with button_name to new_button_text.
2908  * Not a strictly necessary function, since you could intead just
2909  * destroy button_name and make a new buton.
2910  */
2911  int i, bnum;
2912 
2913  bnum = -1;
2914 
2915  for (i=4;i<num_buttons;i++) {
2916  if (button[i].type == BUTTON_TEXT &&
2917  strcmp (button[i].text, button_name) == 0) {
2918  bnum = i;
2919  break;
2920  }
2921  }
2922 
2923  if (bnum != -1) {
2924  strncpy (button[i].text, new_button_text, BUTTON_TEXT_LEN);
2925 #ifdef X11
2926  drawbut (i);
2927 #else // Win32
2928  SetWindowText(button[bnum].hwnd, new_button_text);
2929 #endif
2930  }
2931 }
#define BUTTON_TEXT_LEN
Definition: graphics.c:183
static int num_buttons
Definition: graphics.c:314
static t_button * button
Definition: graphics.c:313
static void drawbut(int bnum)
Definition: graphics.c:2992

+ Here is the call graph for this function:

void clearscreen ( void  )

Definition at line 1483 of file graphics.c.

1484 {
1485  int savecolor;
1486  if (gl_state.disp_type == SCREEN) {
1487 #ifdef X11
1488  XClearWindow (display, toplevel);
1489 #else /* Win32 */
1490  savecolor = currentcolor;
1492  fillrect (xleft, ytop, xright, ybot);
1493  setcolor(savecolor);
1494 #endif
1495  }
1496  else { // Postscript
1497  /* erases current page. Don't use erasepage, since this will erase *
1498  * everything, (even stuff outside the clipping path) causing *
1499  * problems if this picture is incorporated into a larger document. */
1500  savecolor = currentcolor;
1502  fprintf(ps,"clippath fill\n\n");
1503  setcolor (savecolor);
1504  }
1505 }
static t_gl_state gl_state
Definition: graphics.c:309
static Display * display
Definition: graphics.c:385
static float xleft
Definition: graphics.c:318
int background_cindex
Definition: graphics.c:298
static Window toplevel
Definition: graphics.c:389
void fillrect(float x1, float y1, float x2, float y2)
Definition: graphics.c:1643
static float xright
Definition: graphics.c:318
static float ybot
Definition: graphics.c:318
static FILE * ps
Definition: graphics.c:334
static int currentcolor
Definition: graphics.c:327
int disp_type
Definition: graphics.c:297
static float ytop
Definition: graphics.c:318
void setcolor(int cindex)
Definition: graphics.c:619

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void close_graphics ( void  )

Definition at line 2417 of file graphics.c.

2418 {
2419  if (!gl_state.initialized)
2420  return;
2421 #ifdef X11
2422  int i;
2423  for (i=0;i<=MAX_FONT_SIZE;i++) {
2424  if (font_is_loaded[i])
2425  XFreeFont(display,font_info[i]);
2426  }
2427 
2428  XFreeGC(display,gc);
2429  XFreeGC(display,gcxor);
2430  XFreeGC(display,gc_menus);
2431 
2432  if (private_cmap != None)
2433  XFreeColormap (display, private_cmap);
2434 
2435  XCloseDisplay(display);
2436 #else /* Win32 */
2437  int i;
2438  // Free the font data structure for each loaded font.
2439  for (i = 0; i <= MAX_FONT_SIZE; i++) {
2440  if (font_is_loaded[i]) {
2441  free (font_info[i]);
2442  }
2443  }
2444 
2445  // Destroy the window
2446  if(!DestroyWindow(hMainWnd))
2447  DRAW_ERROR();
2448 
2449  // free the window class (type information held by MS Windows)
2450  // for each of the four window types we created. Otherwise a
2451  // later call to init_graphics to open the graphics window up again
2452  // will fail.
2453  if (!UnregisterClass (szAppName, GetModuleHandle(NULL)) )
2454  DRAW_ERROR();
2455  if (!UnregisterClass (szGraphicsName, GetModuleHandle(NULL)) )
2456  DRAW_ERROR();
2457  if (!UnregisterClass (szStatusName, GetModuleHandle(NULL)) )
2458  DRAW_ERROR();
2459  if (!UnregisterClass (szButtonsName, GetModuleHandle(NULL)) )
2460  DRAW_ERROR();
2461 #endif
2462 
2463  free(button);
2464  button = NULL;
2465 
2466  for (i = 0; i <= MAX_FONT_SIZE; i++) {
2467  font_is_loaded[i] = false;
2468  font_info[i] = NULL;
2469  }
2470  gl_state.initialized = false;
2471 }
static t_gl_state gl_state
Definition: graphics.c:309
static XFontStruct * font_info[MAX_FONT_SIZE+1]
Definition: graphics.c:388
static Display * display
Definition: graphics.c:385
bool initialized
Definition: graphics.c:296
static t_button * button
Definition: graphics.c:313
static GC gcxor
Definition: graphics.c:387
static Colormap private_cmap
Definition: graphics.c:390
#define MAX_FONT_SIZE
Definition: graphics.c:179
static GC gc_menus
Definition: graphics.c:387
static GC gc
Definition: graphics.c:387
static bool font_is_loaded[MAX_FONT_SIZE+1]
Definition: graphics.c:340

+ Here is the caller graph for this function:

void close_postscript ( void  )

Definition at line 2602 of file graphics.c.

2603 {
2604 
2605  fprintf(ps,"showpage\n");
2606  fprintf(ps,"\n%%%%Trailer\n");
2607  fclose (ps);
2609  update_transform(); /* Ensure screen world reflects any changes *
2610  * made while printing. */
2611 
2612  /* Need to make sure that we really set up the graphics context.
2613  * The current font set indicates the last font used in a postscript call,
2614  * etc., *NOT* the font set in the X11 or Win32 graphics context. Force the
2615  * current font, colour etc. to be applied to the graphics context, so
2616  * subsequent drawing commands work properly.
2617  */
2618 
2623 }
static t_gl_state gl_state
Definition: graphics.c:309
static void update_transform(void)
Definition: graphics.c:1273
static void force_setcolor(int cindex)
Definition: graphics.c:581
static int currentlinewidth
Definition: graphics.c:329
static int currentfontsize
Definition: graphics.c:330
static void force_setfontsize(int pointsize)
Definition: graphics.c:755
static void force_setlinewidth(int linewidth)
Definition: graphics.c:707
static FILE * ps
Definition: graphics.c:334
static int currentlinestyle
Definition: graphics.c:328
static int currentcolor
Definition: graphics.c:327
int disp_type
Definition: graphics.c:297
static void force_setlinestyle(int linestyle)
Definition: graphics.c:654

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void create_button ( const char *  prev_button_text,
const char *  button_text,
void(*)(void(*drawscreen)(void))  button_func 
)

Definition at line 881 of file graphics.c.

883 {
884  int i, bnum, space, bheight;
885  t_button_type button_type = BUTTON_TEXT;
886 
887  space = 8;
888 
889  /* Only allow new buttons that are text or separator (not poly) types.
890  * They can also only go after buttons that are text buttons.
891  */
892 
893  bnum = -1;
894 
895  for (i=0; i < num_buttons;i++) {
896  if (button[i].type == BUTTON_TEXT &&
897  strcmp (button[i].text, prev_button_text) == 0) {
898  bnum = i + 1;
899  break;
900  }
901  }
902 
903  if (bnum == -1) {
904  printf ("Error in create_button: button with text %s not found.\n",
905  prev_button_text);
906  exit (1);
907  }
908 
909  button = (t_button *) my_realloc (button, (num_buttons+1) * sizeof (t_button));
910  /* NB: Requirement that you specify the button that this button goes under *
911  * guarantees that button[num_buttons-2] exists and is a text button. */
912 
913  /* Special string to make a separator. */
914  if (!strncmp(button_text, "---", 3)) {
915  bheight = 2;
916  button_type = BUTTON_SEPARATOR;
917  }
918  else
919  bheight = 26;
920 
921  for (i=num_buttons;i>bnum;i--) {
922  button[i].xleft = button[i-1].xleft;
923  button[i].ytop = button[i-1].ytop + bheight + space;
924  button[i].height = button[i-1].height;
925  button[i].width = button[i-1].width;
926  button[i].type = button[i-1].type;
927  strcpy (button[i].text, button[i-1].text);
928  button[i].fcn = button[i-1].fcn;
929  button[i].ispressed = button[i-1].ispressed;
930  button[i].enabled = button[i-1].enabled;
931  unmap_button (i-1);
932  }
933 
934  i = bnum;
935  button[i].xleft = 6;
936  button[i].ytop = button[i-1].ytop + button[i-1].height + space;
937  button[i].height = bheight;
938  button[i].width = 90;
939  button[i].type = button_type;
940  strncpy (button[i].text, button_text, BUTTON_TEXT_LEN);
941  button[i].fcn = button_func;
942  button[i].ispressed = false;
943  button[i].enabled = true;
944 
945  num_buttons++;
946 
947  for (i = 0; i<num_buttons;i++)
948  map_button (i);
949 }
t_button_type type
Definition: graphics.c:280
#define BUTTON_TEXT_LEN
Definition: graphics.c:183
static int num_buttons
Definition: graphics.c:314
t_button_type
Definition: graphics.c:248
void(* fcn)(void(*drawscreen)(void))
Definition: graphics.c:274
static void unmap_button(int bnum)
Definition: graphics.c:860
static t_button * button
Definition: graphics.c:313
int xleft
Definition: graphics.c:272
bool enabled
Definition: graphics.c:284
int height
Definition: graphics.c:271
static void map_button(int bnum)
Definition: graphics.c:824
bool ispressed
Definition: graphics.c:283
static void * my_realloc(void *memblk, int ibytes)
Definition: graphics.c:512
int ytop
Definition: graphics.c:273
int width
Definition: graphics.c:270

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void destroy_button ( const char *  button_text)

Definition at line 954 of file graphics.c.

955 {
956  int i, bnum, space, bheight;
957 
958  bnum = -1;
959  space = 8;
960  for (i = 0; i < num_buttons; i++) {
961  if (button[i].type == BUTTON_TEXT &&
962  strcmp (button[i].text, button_text) == 0) {
963  bnum = i;
964  break;
965  }
966  }
967 
968  if (bnum == -1) {
969  printf ("Error in destroy_button: button with text %s not found.\n",
970  button_text);
971  exit (1);
972  }
973 
974  bheight = button[bnum].height;
975 
976  for (i=bnum+1;i<num_buttons;i++) {
977  button[i-1].xleft = button[i].xleft;
978  button[i-1].ytop = button[i].ytop - bheight - space;
979  button[i-1].height = button[i].height;
980  button[i-1].width = button[i].width;
981  button[i-1].type = button[i].type;
982  strcpy (button[i-1].text, button[i].text);
983  button[i-1].fcn = button[i].fcn;
984  button[i-1].ispressed = button[i].ispressed;
985  button[i-1].enabled = button[i].enabled;
986  unmap_button (i);
987  }
988  unmap_button(bnum);
989 
990  button = (t_button *) my_realloc (button, (num_buttons-1) * sizeof (t_button));
991 
992  num_buttons--;
993 
994  for (i=bnum; i<num_buttons;i++)
995  map_button (i);
996 }
t_button_type type
Definition: graphics.c:280
static int num_buttons
Definition: graphics.c:314
void(* fcn)(void(*drawscreen)(void))
Definition: graphics.c:274
static void unmap_button(int bnum)
Definition: graphics.c:860
static t_button * button
Definition: graphics.c:313
int xleft
Definition: graphics.c:272
bool enabled
Definition: graphics.c:284
int height
Definition: graphics.c:271
static void map_button(int bnum)
Definition: graphics.c:824
bool ispressed
Definition: graphics.c:283
static void * my_realloc(void *memblk, int ibytes)
Definition: graphics.c:512
int ytop
Definition: graphics.c:273
int width
Definition: graphics.c:270

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void draw_message ( void  )

Definition at line 2063 of file graphics.c.

2064 {
2065  int savefontsize, savecolor;
2066  float ylow;
2067 #ifdef X11
2068  int len, width;
2069 #endif
2070 
2071  if (gl_state.disp_type == SCREEN) {
2072 #ifdef X11
2073  XClearWindow (display, textarea);
2074  len = strlen (statusMessage);
2075  width = XTextWidth(font_info[menu_font_size], statusMessage, len);
2076  XSetForeground(display, gc_menus,colors[WHITE]);
2077  XDrawRectangle(display, textarea, gc_menus, 0, 0, top_width - MWIDTH, T_AREA_HEIGHT);
2078  XSetForeground(display, gc_menus,colors[BLACK]);
2081 
2082  XDrawString(display, textarea, gc_menus,
2083  (top_width - MWIDTH - width)/2,
2084  T_AREA_HEIGHT/2 + (font_info[menu_font_size]->ascent -
2085  font_info[menu_font_size]->descent)/2, statusMessage, len);
2086 #else
2087  if(!InvalidateRect(hStatusWnd, NULL, TRUE))
2088  DRAW_ERROR();
2089  if(!UpdateWindow(hStatusWnd))
2090  DRAW_ERROR();
2091 #endif
2092  }
2093 
2094  else {
2095  /* Draw the message in the bottom margin. Printer's generally can't *
2096  * print on the bottom 1/4" (area with y < 18 in PostScript coords.) */
2097 
2098  savecolor = currentcolor;
2099  setcolor (BLACK);
2100  savefontsize = currentfontsize;
2101  setfontsize (menu_font_size - 2); /* Smaller OK on paper */
2102  ylow = ps_bot - 8;
2103  fprintf(ps,"(%s) %.2f %.2f censhow\n",statusMessage,(ps_left+ps_right)/2.,
2104  ylow);
2105  setcolor (savecolor);
2106  setfontsize (savefontsize);
2107  }
2108 }
static t_gl_state gl_state
Definition: graphics.c:309
static XFontStruct * font_info[MAX_FONT_SIZE+1]
Definition: graphics.c:388
#define MWIDTH
Definition: graphics.c:177
static Display * display
Definition: graphics.c:385
static const int menu_font_size
Definition: graphics.c:311
static char statusMessage[BUFSIZE]
Definition: graphics.c:338
static Window textarea
Definition: graphics.c:389
static int currentfontsize
Definition: graphics.c:330
void setfontsize(int pointsize)
Definition: graphics.c:796
#define TRUE
Definition: graphics.c:145
static FILE * ps
Definition: graphics.c:334
static float ps_right
Definition: graphics.c:321
static int top_width
Definition: graphics.c:317
static int currentcolor
Definition: graphics.c:327
int disp_type
Definition: graphics.c:297
static GC gc_menus
Definition: graphics.c:387
static int colors[NUM_COLOR]
Definition: graphics.c:393
static float ps_left
Definition: graphics.c:321
#define T_AREA_HEIGHT
Definition: graphics.c:178
static float ps_bot
Definition: graphics.c:321
void setcolor(int cindex)
Definition: graphics.c:619

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void drawarc ( float  xc,
float  yc,
float  rad,
float  startang,
float  angextent 
)

Definition at line 1787 of file graphics.c.

1789 {
1790  drawellipticarc(xc, yc, rad, rad, startang, angextent);
1791 }
void drawellipticarc(float xc, float yc, float radx, float rady, float startang, float angextent)
Definition: graphics.c:1719

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void drawbut ( int  bnum)
static

Definition at line 2992 of file graphics.c.

2993 {
2994 
2995  /* Draws button bnum in either its pressed or unpressed state. */
2996 
2997  int width, height, thick, i, ispressed;
2998  XPoint mypoly[6];
2999 
3000  width = button[bnum].width;
3001  height = button[bnum].height;
3002 
3003  if (button[bnum].type == BUTTON_SEPARATOR) {
3004  int x,y;
3005 
3006  x = button[bnum].xleft;
3007  y = button[bnum].ytop;
3008  XSetForeground(display, gc_menus,colors[WHITE]);
3009  XDrawLine(display, menu, gc_menus, x, y+1, x+width, y+1);
3010  XSetForeground(display, gc_menus,colors[BLACK]);
3011  XDrawLine(display, menu, gc_menus, x, y, x+width, y);
3012  return;
3013  }
3014 
3015  ispressed = button[bnum].ispressed;
3016  thick = 2;
3017  /* Draw top and left edges of 3D box. */
3018  if (ispressed) {
3019  XSetForeground(display, gc_menus,colors[BLACK]);
3020  }
3021  else {
3022  XSetForeground(display, gc_menus,colors[WHITE]);
3023  }
3024 
3025  /* Note: X Windows doesn't appear to draw the bottom pixel of *
3026  * a polygon with XFillPolygon, so I make this 1 pixel thicker *
3027  * to compensate. */
3028  mypoly[0].x = 0;
3029  mypoly[0].y = height;
3030  mypoly[1].x = 0;
3031  mypoly[1].y = 0;
3032  mypoly[2].x = width;
3033  mypoly[2].y = 0;
3034  mypoly[3].x = width-thick;
3035  mypoly[3].y = thick;
3036  mypoly[4].x = thick;
3037  mypoly[4].y = thick;
3038  mypoly[5].x = thick;
3039  mypoly[5].y = height-thick;
3040  XFillPolygon(display,button[bnum].win,gc_menus,mypoly,6,Convex,
3041  CoordModeOrigin);
3042 
3043  /* Draw bottom and right edges of 3D box. */
3044  if (ispressed) {
3045  XSetForeground(display, gc_menus,colors[WHITE]);
3046  }
3047  else {
3048  XSetForeground(display, gc_menus,colors[BLACK]);
3049  }
3050  mypoly[0].x = 0;
3051  mypoly[0].y = height;
3052  mypoly[1].x = width;
3053  mypoly[1].y = height;
3054  mypoly[2].x = width;
3055  mypoly[2].y = 0;
3056  mypoly[3].x = width-thick;
3057  mypoly[3].y = thick;
3058  mypoly[4].x = width-thick;
3059  mypoly[4].y = height-thick;
3060  mypoly[5].x = thick;
3061  mypoly[5].y = height-thick;
3062  XFillPolygon(display,button[bnum].win,gc_menus,mypoly,6,Convex,
3063  CoordModeOrigin);
3064 
3065  /* Draw background */
3066  if (ispressed) {
3067  XSetForeground(display, gc_menus,colors[DARKGREY]);
3068  }
3069  else {
3070  XSetForeground(display, gc_menus,colors[LIGHTGREY]);
3071  }
3072 
3073  /* Give x,y of top corner and width and height */
3074  XFillRectangle (display,button[bnum].win,gc_menus,thick,thick,
3075  width-2*thick, height-2*thick);
3076 
3077  /* Draw polygon, if there is one */
3078  if (button[bnum].type == BUTTON_POLY) {
3079  for (i=0;i<3;i++) {
3080  mypoly[i].x = button[bnum].poly[i][0];
3081  mypoly[i].y = button[bnum].poly[i][1];
3082  }
3083  XSetForeground(display, gc_menus,colors[BLACK]);
3084  XFillPolygon(display,button[bnum].win,gc_menus,mypoly,3,Convex,
3085  CoordModeOrigin);
3086  }
3087 
3088  /* Draw text, if there is any */
3089  if (button[bnum].type == BUTTON_TEXT) {
3090  if (button[bnum].enabled)
3091  XSetForeground(display, gc_menus,colors[BLACK]);
3092  else
3093  XSetForeground(display, gc_menus,colors[DARKGREY]);
3094  menutext(button[bnum].win,button[bnum].width/2,
3095  button[bnum].height/2,button[bnum].text);
3096  }
3097 }
static Display * display
Definition: graphics.c:385
static t_button * button
Definition: graphics.c:313
int poly[3][2]
Definition: graphics.c:282
static Window menu
Definition: graphics.c:389
int xleft
Definition: graphics.c:272
static void menutext(Window win, int xc, int yc, const char *text)
Definition: graphics.c:2977
int height
Definition: graphics.c:271
bool ispressed
Definition: graphics.c:283
int ytop
Definition: graphics.c:273
static GC gc_menus
Definition: graphics.c:387
static int colors[NUM_COLOR]
Definition: graphics.c:393
int width
Definition: graphics.c:270

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void drawellipticarc ( float  xc,
float  yc,
float  radx,
float  rady,
float  startang,
float  angextent 
)

Definition at line 1719 of file graphics.c.

1720 {
1721  int xl, yt;
1722  unsigned int width, height;
1723 #ifdef WIN32
1724  HPEN hOldPen;
1725  int p1, p2, p3, p4;
1726 #endif
1727 
1728  /* Conservative (but fast) clip test -- check containing rectangle of *
1729  * an ellipse. */
1730 
1731  if (rect_off_screen (xc-radx,yc-rady,xc+radx,yc+rady))
1732  return;
1733 
1734  /* X Windows has trouble with very large angles. (Over 360). *
1735  * Do following to prevent its inaccurate (overflow?) problems. */
1736  if (fabs(angextent) > 360.)
1737  angextent = 360.;
1738 
1739  startang = angnorm (startang);
1740 
1741  if (gl_state.disp_type == SCREEN) {
1742  xl = (int) (xcoord(xc) - fabs(xmult*radx));
1743  yt = (int) (ycoord(yc) - fabs(ymult*rady));
1744  width = (unsigned int) (2*fabs(xmult*radx));
1745  height = (unsigned int) (2*fabs(ymult*rady));
1746 #ifdef X11
1747  XDrawArc (display, toplevel, current_gc, xl, yt, width, height,
1748  (int) (startang*64), (int) (angextent*64));
1749 #else // Win32
1750  /* set arc direction */
1751  if (angextent > 0) {
1752  p1 = (int)(xcoord(xc) + fabs(xmult*radx)*cos(DEGTORAD(startang)));
1753  p2 = (int)(ycoord(yc) - fabs(ymult*rady)*sin(DEGTORAD(startang)));
1754  p3 = (int)(xcoord(xc) + fabs(xmult*radx)*cos(DEGTORAD(startang+angextent-.001)));
1755  p4 = (int)(ycoord(yc) - fabs(ymult*rady)*sin(DEGTORAD(startang+angextent-.001)));
1756  }
1757  else {
1758  p1 = (int)(xcoord(xc) + fabs(xmult*radx)*cos(DEGTORAD(startang+angextent+.001)));
1759  p2 = (int)(ycoord(yc) - fabs(ymult*rady)*sin(DEGTORAD(startang+angextent+.001)));
1760  p3 = (int)(xcoord(xc) + fabs(xmult*radx)*cos(DEGTORAD(startang)));
1761  p4 = (int)(ycoord(yc) - fabs(ymult*rady)*sin(DEGTORAD(startang)));
1762  }
1763 
1764  hOldPen = (HPEN)SelectObject(hGraphicsDC, hGraphicsPen);
1765  if(!(hOldPen))
1766  SELECT_ERROR();
1767  if(!Arc(hGraphicsDC, xl, yt, xl+width, yt+height, p1, p2, p3, p4))
1768  DRAW_ERROR();
1769  if(!SelectObject(hGraphicsDC, hOldPen))
1770  SELECT_ERROR();
1771 #endif
1772  }
1773  else {
1774  fprintf(ps, "gsave\n");
1775  fprintf(ps, "%.2f %.2f translate\n", XPOST(xc), YPOST(yc));
1776  fprintf(ps, "%.2f 1 scale\n", fabs(radx*ps_xmult)/fabs(rady*ps_ymult));
1777  fprintf(ps, "0 0 %.2f %.2f %.2f %s\n", /*XPOST(xc)*/
1778  /*YPOST(yc)*/ fabs(rady*ps_xmult), startang, startang+angextent,
1779  (angextent < 0) ? "drawarcn" : "drawarc") ;
1780  fprintf(ps, "grestore\n");
1781  }
1782 }
static t_gl_state gl_state
Definition: graphics.c:309
static Display * display
Definition: graphics.c:385
static GC current_gc
Definition: graphics.c:387
static float ymult
Definition: graphics.c:324
static float ps_ymult
Definition: graphics.c:323
#define XPOST(worldx)
Definition: graphics.c:161
static int ycoord(float worldy)
Definition: graphics.c:552
static Window toplevel
Definition: graphics.c:389
#define YPOST(worldy)
Definition: graphics.c:162
static int rect_off_screen(float x1, float y1, float x2, float y2)
Definition: graphics.c:1514
static FILE * ps
Definition: graphics.c:334
static float xmult
Definition: graphics.c:324
static float ps_xmult
Definition: graphics.c:323
static float angnorm(float ang)
Definition: graphics.c:1704
int disp_type
Definition: graphics.c:297
static int xcoord(float worldx)
Definition: graphics.c:527

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void drawline ( float  x1,
float  y1,
float  x2,
float  y2 
)

Definition at line 1539 of file graphics.c.

1540 {
1541 /* Draw a line from (x1,y1) to (x2,y2) in the user-drawable area. *
1542  * Coordinates are in world (user) space. */
1543 
1544 #ifdef WIN32
1545  HPEN hOldPen;
1546 #endif
1547 
1548  if (rect_off_screen(x1,y1,x2,y2))
1549  return;
1550 
1551  if (gl_state.disp_type == SCREEN) {
1552 #ifdef X11
1553  /* Xlib.h prototype has x2 and y1 mixed up. */
1554  XDrawLine(display, toplevel, current_gc, xcoord(x1), ycoord(y1), xcoord(x2), ycoord(y2));
1555 #else /* Win32 */
1556  hOldPen = (HPEN)SelectObject(hGraphicsDC, hGraphicsPen);
1557  if(!(hOldPen))
1558  SELECT_ERROR();
1559  if (!BeginPath(hGraphicsDC))
1560  DRAW_ERROR();
1561  if(!MoveToEx (hGraphicsDC, xcoord(x1), ycoord(y1), NULL))
1562  DRAW_ERROR();
1563  if(!LineTo (hGraphicsDC, xcoord(x2), ycoord(y2)))
1564  DRAW_ERROR();
1565  if (!EndPath(hGraphicsDC))
1566  DRAW_ERROR();
1567  if (!StrokePath(hGraphicsDC))
1568  DRAW_ERROR();
1569  if(!SelectObject(hGraphicsDC, hOldPen))
1570  SELECT_ERROR();
1571 #endif
1572  }
1573  else {
1574  fprintf(ps,"%.2f %.2f %.2f %.2f drawline\n",XPOST(x1),YPOST(y1),
1575  XPOST(x2),YPOST(y2));
1576  }
1577 }
static t_gl_state gl_state
Definition: graphics.c:309
static Display * display
Definition: graphics.c:385
static GC current_gc
Definition: graphics.c:387
#define XPOST(worldx)
Definition: graphics.c:161
static int ycoord(float worldy)
Definition: graphics.c:552
static Window toplevel
Definition: graphics.c:389
#define YPOST(worldy)
Definition: graphics.c:162
static int rect_off_screen(float x1, float y1, float x2, float y2)
Definition: graphics.c:1514
static FILE * ps
Definition: graphics.c:334
int disp_type
Definition: graphics.c:297
static int xcoord(float worldx)
Definition: graphics.c:527

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void drawmenu ( void  )
static

Definition at line 3126 of file graphics.c.

3127 {
3128  int i;
3129 
3130  XClearWindow (display, menu);
3131  XSetForeground(display, gc_menus,colors[WHITE]);
3132  XDrawRectangle(display, menu, gc_menus, 0, 0, MWIDTH, top_height);
3133  XSetForeground(display, gc_menus,colors[BLACK]);
3134  XDrawLine(display, menu, gc_menus, 0, top_height-1, MWIDTH, top_height-1);
3135  XDrawLine(display, menu, gc_menus, MWIDTH-1, top_height, MWIDTH-1, 0);
3136 
3137  for (i=0;i<num_buttons;i++) {
3138  drawbut(i);
3139  }
3140 }
#define MWIDTH
Definition: graphics.c:177
static Display * display
Definition: graphics.c:385
static int num_buttons
Definition: graphics.c:314
static void drawbut(int bnum)
Definition: graphics.c:2992
static Window menu
Definition: graphics.c:389
static int top_height
Definition: graphics.c:317
static GC gc_menus
Definition: graphics.c:387
static int colors[NUM_COLOR]
Definition: graphics.c:393

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void drawrect ( float  x1,
float  y1,
float  x2,
float  y2 
)

Definition at line 1581 of file graphics.c.

1582 {
1583  int xw1, yw1, xw2, yw2;
1584 #ifdef WIN32
1585  HPEN hOldPen;
1586  HBRUSH hOldBrush;
1587 #else
1588  unsigned int width, height;
1589  int xl, yt;
1590 #endif
1591 
1592  if (rect_off_screen(x1,y1,x2,y2))
1593  return;
1594 
1595  if (gl_state.disp_type == SCREEN) {
1596  /* translate to X Windows calling convention. */
1597  xw1 = xcoord(x1);
1598  xw2 = xcoord(x2);
1599  yw1 = ycoord(y1);
1600  yw2 = ycoord(y2);
1601 #ifdef X11
1602  xl = min(xw1,xw2);
1603  yt = min(yw1,yw2);
1604  width = abs (xw1-xw2);
1605  height = abs (yw1-yw2);
1606  XDrawRectangle(display, toplevel, current_gc, xl, yt, width, height);
1607 #else /* Win32 */
1608  if(xw1 > xw2) {
1609  int temp = xw1;
1610  xw1 = xw2;
1611  xw2 = temp;
1612  }
1613  if(yw1 > yw2) {
1614  int temp = yw1;
1615  yw1 = yw2;
1616  yw2 = temp;
1617  }
1618 
1619  hOldPen = (HPEN)SelectObject(hGraphicsDC, hGraphicsPen);
1620  if(!(hOldPen))
1621  SELECT_ERROR();
1622  hOldBrush = (HBRUSH)SelectObject(hGraphicsDC, GetStockObject(NULL_BRUSH));
1623  if(!(hOldBrush))
1624  SELECT_ERROR();
1625  if(!Rectangle(hGraphicsDC, xw1, yw1, xw2, yw2))
1626  DRAW_ERROR();
1627  if(!SelectObject(hGraphicsDC, hOldPen))
1628  SELECT_ERROR();
1629  if(!SelectObject(hGraphicsDC, hOldBrush))
1630  SELECT_ERROR();
1631 #endif
1632 
1633  }
1634  else {
1635  fprintf(ps,"%.2f %.2f %.2f %.2f drawrect\n",XPOST(x1),YPOST(y1),
1636  XPOST(x2),YPOST(y2));
1637  }
1638 }
static t_gl_state gl_state
Definition: graphics.c:309
static Display * display
Definition: graphics.c:385
static GC current_gc
Definition: graphics.c:387
#define XPOST(worldx)
Definition: graphics.c:161
static int ycoord(float worldy)
Definition: graphics.c:552
#define min(a, b)
Definition: graphics.c:174
static Window toplevel
Definition: graphics.c:389
#define YPOST(worldy)
Definition: graphics.c:162
static int rect_off_screen(float x1, float y1, float x2, float y2)
Definition: graphics.c:1514
static FILE * ps
Definition: graphics.c:334
int disp_type
Definition: graphics.c:297
static int xcoord(float worldx)
Definition: graphics.c:527

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void drawtext ( float  xc,
float  yc,
const char *  text,
float  boundx 
)

Definition at line 1952 of file graphics.c.

1953 {
1954  int len, width, xw_off, yw_off, font_ascent, font_descent;
1955 
1956 #ifdef X11
1957  len = strlen(text);
1958  width = XTextWidth(font_info[currentfontsize], text, len);
1959  font_ascent = font_info[currentfontsize]->ascent;
1960  font_descent = font_info[currentfontsize]->descent;
1961 #else /* WC : WIN32 */
1962  HFONT hOldFont;
1963  SIZE textsize;
1964  TEXTMETRIC textmetric;
1965 
1966  hOldFont = (HFONT)SelectObject(hGraphicsDC, hGraphicsFont);
1967  if(!(hOldFont))
1968  SELECT_ERROR();
1969  if(SetTextColor(hGraphicsDC, win32_colors[currentcolor]) == CLR_INVALID)
1970  DRAW_ERROR();
1971 
1972  len = strlen(text);
1973  if (!GetTextExtentPoint32(hGraphicsDC, text, len, &textsize))
1974  DRAW_ERROR();
1975  width = textsize.cx;
1976  if (!GetTextMetrics(hGraphicsDC, &textmetric))
1977  DRAW_ERROR();
1978  font_ascent = textmetric.tmAscent;
1979  font_descent = textmetric.tmDescent;
1980 #endif
1981  if (width > fabs(boundx*xmult)) {
1982 #ifdef WIN32
1983  if(!SelectObject(hGraphicsDC, hOldFont))
1984  SELECT_ERROR();
1985 #endif
1986  return; /* Don't draw if it won't fit */
1987  }
1988 
1989  xw_off = (int)(width/(2.*xmult)); /* NB: sign doesn't matter. */
1990 
1991  /* NB: 2 * descent makes this slightly conservative but simplifies code. */
1992  yw_off = (int)((font_ascent + 2 * font_descent)/(2.*ymult));
1993 
1994  /* Note: text can be clipped when a little bit of it would be visible *
1995  * right now. Perhaps X doesn't return extremely accurate width and *
1996  * ascent values, etc? Could remove this completely by multiplying *
1997  * xw_off and yw_off by, 1.2 or 1.5. */
1998  if (rect_off_screen(xc-xw_off, yc-yw_off, xc+xw_off, yc+yw_off)) {
1999 #ifdef WIN32
2000  if(!SelectObject(hGraphicsDC, hOldFont))
2001  SELECT_ERROR();
2002 #endif
2003  return;
2004  }
2005 
2006  if (gl_state.disp_type == SCREEN) {
2007 #ifdef X11
2008  XDrawString(display, toplevel, current_gc, xcoord(xc)-width/2, ycoord(yc) +
2009  (font_info[currentfontsize]->ascent - font_info[currentfontsize]->descent)/2,
2010  text, len);
2011 #else /* Win32 */
2012  SetBkMode(hGraphicsDC, TRANSPARENT);
2013  if(!TextOut (hGraphicsDC, xcoord(xc)-width/2, ycoord(yc) - (font_ascent + font_descent)/2,
2014  text, len))
2015  DRAW_ERROR();
2016  if(!SelectObject(hGraphicsDC, hOldFont))
2017  SELECT_ERROR();
2018 #endif
2019  }
2020  else {
2021  fprintf(ps,"(%s) %.2f %.2f censhow\n",text,XPOST(xc),YPOST(yc));
2022  }
2023 }
static t_gl_state gl_state
Definition: graphics.c:309
static XFontStruct * font_info[MAX_FONT_SIZE+1]
Definition: graphics.c:388
static Display * display
Definition: graphics.c:385
static GC current_gc
Definition: graphics.c:387
static float ymult
Definition: graphics.c:324
#define XPOST(worldx)
Definition: graphics.c:161
static int ycoord(float worldy)
Definition: graphics.c:552
static int currentfontsize
Definition: graphics.c:330
static Window toplevel
Definition: graphics.c:389
#define YPOST(worldy)
Definition: graphics.c:162
static int rect_off_screen(float x1, float y1, float x2, float y2)
Definition: graphics.c:1514
static FILE * ps
Definition: graphics.c:334
static float xmult
Definition: graphics.c:324
static int currentcolor
Definition: graphics.c:327
int disp_type
Definition: graphics.c:297
static int xcoord(float worldx)
Definition: graphics.c:527

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void enable_or_disable_button ( int  ibutton,
bool  enabled 
)

Definition at line 2867 of file graphics.c.

2867  {
2868 
2869  if (button[ibutton].type != BUTTON_SEPARATOR) {
2870  button[ibutton].enabled = enabled;
2871 #ifdef WIN32
2872  EnableWindow(button[ibutton].hwnd, button[ibutton].enabled);
2873 #else // X11
2874  drawbut(ibutton);
2875  XFlush(display);
2876 #endif
2877  }
2878 }
static Display * display
Definition: graphics.c:385
static t_button * button
Definition: graphics.c:313
static void drawbut(int bnum)
Definition: graphics.c:2992
bool enabled
Definition: graphics.c:284

+ Here is the call graph for this function:

void event_loop ( void(*)(float x, float y)  act_on_mousebutton,
void(*)(float x, float y)  act_on_mousemove,
void(*)(char key_pressed)  act_on_keypress,
void(*)(void)  drawscreen 
)

Definition at line 1352 of file graphics.c.

1356 {
1357 #ifdef X11
1358  XEvent report;
1359  int bnum;
1360  float x, y;
1361 
1362 #define OFF 1
1363 #define ON 0
1364 
1365  turn_on_off (ON);
1366  while (1) {
1367  XNextEvent (display, &report);
1368  switch (report.type) {
1369  case Expose:
1370 #ifdef VERBOSE
1371  printf("Got an expose event.\n");
1372  printf("Count is: %d.\n",report.xexpose.count);
1373  printf("Window ID is: %d.\n",report.xexpose.window);
1374 #endif
1375  if (report.xexpose.count != 0)
1376  break;
1377  if (report.xexpose.window == menu)
1378  drawmenu();
1379  else if (report.xexpose.window == toplevel)
1380  drawscreen();
1381  else if (report.xexpose.window == textarea)
1382  draw_message();
1383  break;
1384  case ConfigureNotify:
1385  top_width = report.xconfigure.width;
1386  top_height = report.xconfigure.height;
1387  update_transform();
1388  drawmenu();
1389  draw_message();
1390 #ifdef VERBOSE
1391  printf("Got a ConfigureNotify.\n");
1392  printf("New width: %d New height: %d.\n",top_width,top_height);
1393 #endif
1394  break;
1395  case ButtonPress:
1396 #ifdef VERBOSE
1397  printf("Got a buttonpress.\n");
1398  printf("Window ID is: %d.\n",report.xbutton.window);
1399 #endif
1400  if (report.xbutton.window == toplevel) {
1401  x = XTOWORLD(report.xbutton.x);
1402  y = YTOWORLD(report.xbutton.y);
1403  act_on_mousebutton (x, y);
1404  }
1405  else { /* A menu button was pressed. */
1406  bnum = which_button(report.xbutton.window);
1407 #ifdef VERBOSE
1408  printf("Button number is %d\n",bnum);
1409 #endif
1410  if (button[bnum].enabled) {
1411  button[bnum].ispressed = 1;
1412  drawbut(bnum);
1413  XFlush(display); /* Flash the button */
1414  button[bnum].fcn (drawscreen);
1415  button[bnum].ispressed = 0;
1416  drawbut(bnum);
1417  if (button[bnum].fcn == proceed) {
1418  turn_on_off(OFF);
1419  flushinput ();
1420  return; /* Rather clumsy way of returning *
1421  * control to the simulator */
1422  }
1423  }
1424  }
1425  break;
1426  case MotionNotify:
1427 #ifdef VERBOSE
1428  printf("Got a MotionNotify Event.\n");
1429  printf("x: %d y: %d\n",report.xmotion.x,report.xmotion.y);
1430 #endif
1431  if (get_mouse_move_input &&
1432  report.xmotion.x <= top_width-MWIDTH &&
1433  report.xmotion.y <= top_height-T_AREA_HEIGHT)
1434  act_on_mousemove(XTOWORLD(report.xmotion.x), YTOWORLD(report.xmotion.y));
1435  break;
1436  case KeyPress:
1437 #ifdef VERBOSE
1438  printf("Got a KeyPress Event.\n");
1439 #endif
1440  if (get_keypress_input)
1441  {
1442  char keyb_buffer[20];
1443  XComposeStatus composestatus;
1444  KeySym keysym;
1445  int length, max_bytes;
1446 
1447  max_bytes = 1;
1448 
1449  length = XLookupString( &report.xkey, keyb_buffer, max_bytes, &keysym,
1450  &composestatus );
1451 
1452  keyb_buffer[length] = '\0'; /* terminating NULL */
1453  act_on_keypress(keyb_buffer[0]);
1454  }
1455 
1456  break;
1457  }
1458  }
1459 #else /* Win32 */
1460  MSG msg;
1461 
1462  mouseclick_ptr = act_on_mousebutton;
1463  mousemove_ptr = act_on_mousemove;
1464  keypress_ptr = act_on_keypress;
1465  drawscreen_ptr = drawscreen;
1467  InEventLoop = TRUE;
1468 
1469  invalidate_screen();
1470 
1471  while(!ProceedPressed && GetMessage(&msg, NULL, 0, 0)) {
1472  //TranslateMessage(&msg);
1473  if (msg.message == WM_CHAR) { // only the top window can get keyboard events
1474  msg.hwnd = hMainWnd;
1475  }
1476  DispatchMessage(&msg);
1477  }
1478  InEventLoop = FALSE;
1479 #endif
1480 }
#define YTOWORLD(y)
Definition: graphics.c:168
#define MWIDTH
Definition: graphics.c:177
static Display * display
Definition: graphics.c:385
static void proceed(void(*drawscreen)(void))
Definition: graphics.c:2400
static Window textarea
Definition: graphics.c:389
static void update_transform(void)
Definition: graphics.c:1273
static bool get_mouse_move_input
Definition: graphics.c:341
void(* fcn)(void(*drawscreen)(void))
Definition: graphics.c:274
#define FALSE
Definition: graphics.c:146
static bool get_keypress_input
Definition: graphics.c:341
static t_button * button
Definition: graphics.c:313
static void drawscreen(void)
Definition: draw.c:212
void draw_message(void)
Definition: graphics.c:2063
static Window toplevel
Definition: graphics.c:389
static int which_button(Window win)
Definition: graphics.c:3100
static void drawbut(int bnum)
Definition: graphics.c:2992
static void drawmenu(void)
Definition: graphics.c:3126
static int ProceedPressed
Definition: graphics.c:336
static Window menu
Definition: graphics.c:389
#define XTOWORLD(x)
Definition: graphics.c:167
static int top_height
Definition: graphics.c:317
#define OFF
#define TRUE
Definition: graphics.c:145
bool ispressed
Definition: graphics.c:283
static void turn_on_off(int pressed)
Definition: graphics.c:3113
static int top_width
Definition: graphics.c:317
#define ON
void flushinput(void)
Definition: graphics.c:2027
#define T_AREA_HEIGHT
Definition: graphics.c:178

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void fillarc ( float  xc,
float  yc,
float  rad,
float  startang,
float  angextent 
)

Definition at line 1876 of file graphics.c.

1876  {
1877  fillellipticarc(xc, yc, rad, rad, startang, angextent);
1878 }
void fillellipticarc(float xc, float yc, float radx, float rady, float startang, float angextent)
Definition: graphics.c:1798

+ Here is the call graph for this function:

void fillellipticarc ( float  xc,
float  yc,
float  radx,
float  rady,
float  startang,
float  angextent 
)

Definition at line 1798 of file graphics.c.

1800 {
1801  int xl, yt;
1802  unsigned int width, height;
1803 #ifdef WIN32
1804  HPEN hOldPen;
1805  HBRUSH hOldBrush;
1806  int p1, p2, p3, p4;
1807 #endif
1808 
1809  /* Conservative (but fast) clip test -- check containing rectangle of *
1810  * a circle. */
1811 
1812  if (rect_off_screen (xc-radx,yc-rady,xc+radx,yc+rady))
1813  return;
1814 
1815  /* X Windows has trouble with very large angles. (Over 360). *
1816  * Do following to prevent its inaccurate (overflow?) problems. */
1817 
1818  if (fabs(angextent) > 360.)
1819  angextent = 360.;
1820 
1821  startang = angnorm (startang);
1822 
1823  if (gl_state.disp_type == SCREEN) {
1824  xl = (int) (xcoord(xc) - fabs(xmult*radx));
1825  yt = (int) (ycoord(yc) - fabs(ymult*rady));
1826  width = (unsigned int) (2*fabs(xmult*radx));
1827  height = (unsigned int) (2*fabs(ymult*rady));
1828 #ifdef X11
1829  XFillArc (display, toplevel, current_gc, xl, yt, width, height,
1830  (int) (startang*64), (int) (angextent*64));
1831 #else // Win32
1832  /* set pie direction */
1833  if (angextent > 0) {
1834  p1 = (int)(xcoord(xc) + fabs(xmult*radx)*cos(DEGTORAD(startang)));
1835  p2 = (int)(ycoord(yc) - fabs(ymult*rady)*sin(DEGTORAD(startang)));
1836  p3 = (int)(xcoord(xc) + fabs(xmult*radx)*cos(DEGTORAD(startang+angextent-.001)));
1837  p4 = (int)(ycoord(yc) - fabs(ymult*rady)*sin(DEGTORAD(startang+angextent-.001)));
1838  }
1839  else {
1840  p1 = (int)(xcoord(xc) + fabs(xmult*radx)*cos(DEGTORAD(startang+angextent+.001)));
1841  p2 = (int)(ycoord(yc) - fabs(ymult*rady)*sin(DEGTORAD(startang+angextent+.001)));
1842  p3 = (int)(xcoord(xc) + fabs(xmult*radx)*cos(DEGTORAD(startang)));
1843  p4 = (int)(ycoord(yc) - fabs(ymult*rady)*sin(DEGTORAD(startang)));
1844  }
1845 
1846  hOldPen = (HPEN)SelectObject(hGraphicsDC, GetStockObject(NULL_PEN));
1847  if(!(hOldPen))
1848  SELECT_ERROR();
1849  hOldBrush = (HBRUSH)SelectObject(hGraphicsDC, hGraphicsBrush);
1850  if(!(hOldBrush))
1851  SELECT_ERROR();
1852 // Win32 API says a zero return value indicates an error, but it seems to always
1853 // return zero. Don't check for an error on Pie.
1854  Pie(hGraphicsDC, xl, yt, xl+width, yt+height, p1, p2, p3, p4);
1855 
1856 // if(!Pie(hGraphicsDC, xl, yt, xl+width, yt+height, p1, p2, p3, p4));
1857 // DRAW_ERROR();
1858  if(!SelectObject(hGraphicsDC, hOldPen))
1859  SELECT_ERROR();
1860  if(!SelectObject(hGraphicsDC, hOldBrush))
1861  SELECT_ERROR();
1862 #endif
1863  }
1864  else {
1865  fprintf(ps, "gsave\n");
1866  fprintf(ps, "%.2f %.2f translate\n", XPOST(xc), YPOST(yc));
1867  fprintf(ps, "%.2f 1 scale\n", fabs(radx*ps_xmult)/fabs(rady*ps_ymult));
1868  fprintf(ps, "%.2f %.2f %.2f 0 0 %s\n", /*XPOST(xc)*/
1869  /*YPOST(yc)*/ fabs(rady*ps_xmult), startang, startang+angextent,
1870  (angextent < 0) ? "fillarcn" : "fillarc") ;
1871  fprintf(ps, "grestore\n");
1872  }
1873 }
static t_gl_state gl_state
Definition: graphics.c:309
static Display * display
Definition: graphics.c:385
static GC current_gc
Definition: graphics.c:387
static float ymult
Definition: graphics.c:324
static float ps_ymult
Definition: graphics.c:323
#define XPOST(worldx)
Definition: graphics.c:161
static int ycoord(float worldy)
Definition: graphics.c:552
static Window toplevel
Definition: graphics.c:389
#define YPOST(worldy)
Definition: graphics.c:162
static int rect_off_screen(float x1, float y1, float x2, float y2)
Definition: graphics.c:1514
static FILE * ps
Definition: graphics.c:334
static float xmult
Definition: graphics.c:324
static float ps_xmult
Definition: graphics.c:323
static float angnorm(float ang)
Definition: graphics.c:1704
int disp_type
Definition: graphics.c:297
static int xcoord(float worldx)
Definition: graphics.c:527

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void fillpoly ( t_point points,
int  npoints 
)

Definition at line 1881 of file graphics.c.

1882 {
1883 #ifdef X11
1884  XPoint transpoints[MAXPTS];
1885 #else
1886  POINT transpoints[MAXPTS];
1887  HPEN hOldPen;
1888  HBRUSH hOldBrush;
1889 #endif
1890  int i;
1891  float xmin, ymin, xmax, ymax;
1892 
1893  if (npoints > MAXPTS) {
1894  printf("Error in fillpoly: Only %d points allowed per polygon.\n",
1895  MAXPTS);
1896  printf("%d points were requested. Polygon is not drawn.\n",npoints);
1897  return;
1898  }
1899 
1900  /* Conservative (but fast) clip test -- check containing rectangle of *
1901  * polygon. */
1902 
1903  xmin = xmax = points[0].x;
1904  ymin = ymax = points[0].y;
1905 
1906  for (i=1;i<npoints;i++) {
1907  xmin = min (xmin,points[i].x);
1908  xmax = max (xmax,points[i].x);
1909  ymin = min (ymin,points[i].y);
1910  ymax = max (ymax,points[i].y);
1911  }
1912 
1913  if (rect_off_screen(xmin,ymin,xmax,ymax))
1914  return;
1915 
1916  if (gl_state.disp_type == SCREEN) {
1917  for (i=0;i<npoints;i++) {
1918  transpoints[i].x = (short) xcoord (points[i].x);
1919  transpoints[i].y = (short) ycoord (points[i].y);
1920  }
1921 #ifdef X11
1922  XFillPolygon(display, toplevel, current_gc, transpoints, npoints, Complex,
1923  CoordModeOrigin);
1924 #else
1925  hOldPen = (HPEN)SelectObject(hGraphicsDC, GetStockObject(NULL_PEN));
1926  if(!(hOldPen))
1927  SELECT_ERROR();
1928  hOldBrush = (HBRUSH)SelectObject(hGraphicsDC, hGraphicsBrush);
1929  if(!(hOldBrush))
1930  SELECT_ERROR();
1931  if(!Polygon (hGraphicsDC, transpoints, npoints))
1932  DRAW_ERROR();
1933  if(!SelectObject(hGraphicsDC, hOldPen))
1934  SELECT_ERROR();
1935  if(!SelectObject(hGraphicsDC, hOldBrush))
1936  SELECT_ERROR();
1937 #endif
1938  }
1939  else {
1940  fprintf(ps,"\n");
1941 
1942  for (i=npoints-1;i>=0;i--)
1943  fprintf (ps, "%.2f %.2f\n", XPOST(points[i].x), YPOST(points[i].y));
1944 
1945  fprintf (ps, "%d fillpoly\n", npoints);
1946  }
1947 }
#define MAXPTS
static t_gl_state gl_state
Definition: graphics.c:309
static Display * display
Definition: graphics.c:385
static GC current_gc
Definition: graphics.c:387
#define XPOST(worldx)
Definition: graphics.c:161
static int ycoord(float worldy)
Definition: graphics.c:552
#define min(a, b)
Definition: graphics.c:174
static Window toplevel
Definition: graphics.c:389
#define YPOST(worldy)
Definition: graphics.c:162
#define max(a, b)
Definition: graphics.c:171
static int rect_off_screen(float x1, float y1, float x2, float y2)
Definition: graphics.c:1514
static FILE * ps
Definition: graphics.c:334
int disp_type
Definition: graphics.c:297
static int xcoord(float worldx)
Definition: graphics.c:527

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void fillrect ( float  x1,
float  y1,
float  x2,
float  y2 
)

Definition at line 1643 of file graphics.c.

1644 {
1645  int xw1, yw1, xw2, yw2;
1646 #ifdef WIN32
1647  HPEN hOldPen;
1648  HBRUSH hOldBrush;
1649 #else
1650  unsigned int width, height;
1651  int xl, yt;
1652 #endif
1653 
1654  if (rect_off_screen(x1,y1,x2,y2))
1655  return;
1656 
1657  if (gl_state.disp_type == SCREEN) {
1658  /* translate to X Windows calling convention. */
1659  xw1 = xcoord(x1);
1660  xw2 = xcoord(x2);
1661  yw1 = ycoord(y1);
1662  yw2 = ycoord(y2);
1663 #ifdef X11
1664  xl = min(xw1,xw2);
1665  yt = min(yw1,yw2);
1666  width = abs (xw1-xw2);
1667  height = abs (yw1-yw2);
1668  XFillRectangle(display, toplevel, current_gc, xl, yt, width, height);
1669 #else /* Win32 */
1670  if(xw1 > xw2) {
1671  int temp = xw1;
1672  xw1 = xw2;
1673  xw2 = temp;
1674  }
1675  if(yw1 > yw2) {
1676  int temp = yw1;
1677  yw1 = yw2;
1678  yw2 = temp;
1679  }
1680 
1681  hOldPen = (HPEN)SelectObject(hGraphicsDC, hGraphicsPen);
1682  if(!(hOldPen))
1683  SELECT_ERROR();
1684  hOldBrush = (HBRUSH)SelectObject(hGraphicsDC, hGraphicsBrush);
1685  if(!(hOldBrush))
1686  SELECT_ERROR();
1687  if(!Rectangle(hGraphicsDC, xw1, yw1, xw2, yw2))
1688  DRAW_ERROR();
1689  if(!SelectObject(hGraphicsDC, hOldPen))
1690  SELECT_ERROR();
1691  if(!SelectObject(hGraphicsDC, hOldBrush))
1692  SELECT_ERROR();
1693 #endif
1694  }
1695  else {
1696  fprintf(ps,"%.2f %.2f %.2f %.2f fillrect\n",XPOST(x1),YPOST(y1),
1697  XPOST(x2),YPOST(y2));
1698  }
1699 }
static t_gl_state gl_state
Definition: graphics.c:309
static Display * display
Definition: graphics.c:385
static GC current_gc
Definition: graphics.c:387
#define XPOST(worldx)
Definition: graphics.c:161
static int ycoord(float worldy)
Definition: graphics.c:552
#define min(a, b)
Definition: graphics.c:174
static Window toplevel
Definition: graphics.c:389
#define YPOST(worldy)
Definition: graphics.c:162
static int rect_off_screen(float x1, float y1, float x2, float y2)
Definition: graphics.c:1514
static FILE * ps
Definition: graphics.c:334
int disp_type
Definition: graphics.c:297
static int xcoord(float worldx)
Definition: graphics.c:527

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void flushinput ( void  )

Definition at line 2027 of file graphics.c.

2028 {
2029  if (gl_state.disp_type != SCREEN)
2030  return;
2031 #ifdef X11
2032  XFlush(display);
2033 #endif
2034 }
static t_gl_state gl_state
Definition: graphics.c:309
static Display * display
Definition: graphics.c:385
int disp_type
Definition: graphics.c:297

+ Here is the caller graph for this function:

static void force_setcolor ( int  cindex)
static

Definition at line 581 of file graphics.c.

582 {
583  currentcolor = cindex;
584 
585  if (gl_state.disp_type == SCREEN) {
586 #ifdef X11
587  XSetForeground (display, current_gc, colors[cindex]);
588 #else /* Win32 */
589  int win_linestyle;
590  LOGBRUSH lb;
591  lb.lbStyle = BS_SOLID;
592  lb.lbColor = win32_colors[cindex];
593  lb.lbHatch = (LONG)NULL;
594  win_linestyle = win32_line_styles[currentlinestyle];
595 
596  if(!DeleteObject(hGraphicsPen))
597  DELETE_ERROR();
598 
599  int linewidth = max (currentlinewidth, 1); // Win32 won't draw 0 width dashed lines.
600  hGraphicsPen = ExtCreatePen(PS_GEOMETRIC | win_linestyle |
601  PS_ENDCAP_FLAT, linewidth, &lb, (LONG)NULL, NULL);
602  if(!hGraphicsPen)
603  CREATE_ERROR();
604 
605  if(!DeleteObject(hGraphicsBrush))
606  DELETE_ERROR();
607  hGraphicsBrush = CreateSolidBrush(win32_colors[currentcolor]);
608  if(!hGraphicsBrush)
609  CREATE_ERROR();
610 #endif
611  }
612  else {
613  fprintf (ps,"%s\n", ps_cnames[cindex]);
614  }
615 }
static t_gl_state gl_state
Definition: graphics.c:309
static Display * display
Definition: graphics.c:385
static GC current_gc
Definition: graphics.c:387
static const char * ps_cnames[NUM_COLOR]
Definition: graphics.c:342
static int currentlinewidth
Definition: graphics.c:329
#define max(a, b)
Definition: graphics.c:171
static FILE * ps
Definition: graphics.c:334
static int currentlinestyle
Definition: graphics.c:328
static int currentcolor
Definition: graphics.c:327
int disp_type
Definition: graphics.c:297
static int colors[NUM_COLOR]
Definition: graphics.c:393

+ Here is the caller graph for this function:

static void force_setfontsize ( int  pointsize)
static

Definition at line 755 of file graphics.c.

756 {
757 
758  if (pointsize < 1)
759  pointsize = 1;
760 #ifdef WIN32
761  pointsize = (int)((float)pointsize * FONTMAG);
762 #endif
763  if (pointsize > MAX_FONT_SIZE)
764  pointsize = MAX_FONT_SIZE;
765 
766  currentfontsize = pointsize;
767 
768  if (gl_state.disp_type == SCREEN) {
769  load_font (pointsize);
770 #ifdef X11
771  XSetFont(display, current_gc, font_info[pointsize]->fid);
772 #else /* Win32 */
773  if(!DeleteObject(hGraphicsFont))
774  DELETE_ERROR();
775  hGraphicsFont = CreateFontIndirect(font_info[pointsize]);
776  if(!hGraphicsFont)
777  CREATE_ERROR();
778  if(!SelectObject(hGraphicsDC, hGraphicsFont) )
779  SELECT_ERROR();
780 
781 #endif
782  }
783 
784  else {
785  /* PostScript: set up font and centering function */
786  fprintf(ps,"%d setfontsize\n",pointsize);
787  }
788 }
static t_gl_state gl_state
Definition: graphics.c:309
static XFontStruct * font_info[MAX_FONT_SIZE+1]
Definition: graphics.c:388
static Display * display
Definition: graphics.c:385
static GC current_gc
Definition: graphics.c:387
static void load_font(int pointsize)
Definition: graphics.c:2768
static int currentfontsize
Definition: graphics.c:330
static FILE * ps
Definition: graphics.c:334
int disp_type
Definition: graphics.c:297
#define MAX_FONT_SIZE
Definition: graphics.c:179

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void force_setlinestyle ( int  linestyle)
static

Definition at line 654 of file graphics.c.

655 {
656  currentlinestyle = linestyle;
657 
658  if (gl_state.disp_type == SCREEN) {
659 
660 #ifdef X11
661  static int x_vals[2] = {LineSolid, LineOnOffDash};
662  XSetLineAttributes (display, current_gc, currentlinewidth, x_vals[linestyle],
663  CapButt, JoinMiter);
664 #else // Win32
665  LOGBRUSH lb;
666  lb.lbStyle = BS_SOLID;
667  lb.lbColor = win32_colors[currentcolor];
668  lb.lbHatch = (LONG)NULL;
669  int win_linestyle = win32_line_styles[linestyle];
670 
671  if(!DeleteObject(hGraphicsPen))
672  DELETE_ERROR();
673  int linewidth = max (currentlinewidth, 1); // Win32 won't draw 0 width dashed lines.
674  hGraphicsPen = ExtCreatePen(PS_GEOMETRIC | win_linestyle |
675  PS_ENDCAP_FLAT, linewidth, &lb, (LONG)NULL, NULL);
676  if(!hGraphicsPen)
677  CREATE_ERROR();
678 #endif
679  }
680 
681  else {
682  if (linestyle == SOLID)
683  fprintf (ps,"linesolid\n");
684  else if (linestyle == DASHED)
685  fprintf (ps, "linedashed\n");
686  else {
687  printf ("Error: invalid linestyle: %d\n", linestyle);
688  exit (1);
689  }
690  }
691 }
static t_gl_state gl_state
Definition: graphics.c:309
static Display * display
Definition: graphics.c:385
static GC current_gc
Definition: graphics.c:387
static int currentlinewidth
Definition: graphics.c:329
#define max(a, b)
Definition: graphics.c:171
static FILE * ps
Definition: graphics.c:334
static int currentlinestyle
Definition: graphics.c:328
static int currentcolor
Definition: graphics.c:327
int disp_type
Definition: graphics.c:297

+ Here is the caller graph for this function:

static void force_setlinewidth ( int  linewidth)
static

Definition at line 707 of file graphics.c.

708 {
709  currentlinewidth = linewidth;
710 
711  if (gl_state.disp_type == SCREEN) {
712 
713 #ifdef X11
714  static int x_vals[2] = {LineSolid, LineOnOffDash};
715  XSetLineAttributes (display, current_gc, linewidth, x_vals[currentlinestyle],
716  CapButt, JoinMiter);
717 #else /* Win32 */
718  LOGBRUSH lb;
719  lb.lbStyle = BS_SOLID;
720  lb.lbColor = win32_colors[currentcolor];
721  lb.lbHatch = (LONG)NULL;
722  int win_linestyle = win32_line_styles[currentlinestyle];
723 
724  if(!DeleteObject(hGraphicsPen))
725  DELETE_ERROR();
726  if (linewidth == 0)
727  linewidth = 1; // Win32 won't draw dashed 0 width lines.
728  hGraphicsPen = ExtCreatePen(PS_GEOMETRIC | win_linestyle |
729  PS_ENDCAP_FLAT, linewidth, &lb, (LONG)NULL, NULL);
730  if(!hGraphicsPen)
731  CREATE_ERROR();
732 #endif
733  }
734 
735  else {
736  fprintf(ps,"%d setlinewidth\n", linewidth);
737  }
738 }
static t_gl_state gl_state
Definition: graphics.c:309
static Display * display
Definition: graphics.c:385
static GC current_gc
Definition: graphics.c:387
static int currentlinewidth
Definition: graphics.c:329
static FILE * ps
Definition: graphics.c:334
static int currentlinestyle
Definition: graphics.c:328
static int currentcolor
Definition: graphics.c:327
int disp_type
Definition: graphics.c:297

+ Here is the caller graph for this function:

int getcolor ( void  )

Definition at line 647 of file graphics.c.

647  {
648  return currentcolor;
649 }
static int currentcolor
Definition: graphics.c:327

+ Here is the caller graph for this function:

void init_graphics ( const char *  window_name,
int  cindex 
)

Definition at line 1003 of file graphics.c.

1004 {
1005  if (gl_state.initialized) // Singleton graphics.
1006  return;
1007 
1008  reset_common_state ();
1009 #ifdef WIN32
1010  reset_win32_state ();
1011 #endif
1012 
1014  gl_state.background_cindex = cindex;
1015 
1016 
1017 #ifdef X11
1018  char *display_name = NULL;
1019  int x, y; /* window position */
1020  unsigned int border_width = 2; /* ignored by OpenWindows */
1021  XTextProperty windowName;
1022 
1023  /* X Windows' names for my colours. */
1024  const char *cnames[NUM_COLOR] = {"white", "black", "grey55", "grey75", "blue",
1025  "green", "yellow", "cyan", "red", "RGBi:0.0/0.5/0.0", "magenta",
1026  "bisque", "lightblue", "thistle", "plum", "khaki", "coral",
1027  "turquoise", "mediumpurple", "darkslateblue", "darkkhaki" };
1028 
1029  XColor exact_def;
1030  Colormap cmap;
1031  unsigned long valuemask = 0; /* ignore XGCvalues and use defaults */
1032  XGCValues values;
1033  XEvent event;
1034 
1035  /* connect to X server */
1036  if ( (display=XOpenDisplay(display_name)) == NULL )
1037  {
1038  fprintf( stderr, "Cannot connect to X server %s\n",
1039  XDisplayName(display_name));
1040  exit( -1 );
1041  }
1042 
1043  /* get screen size from display structure macro */
1044  screen_num = DefaultScreen(display);
1045  display_width = DisplayWidth(display, screen_num);
1046  display_height = DisplayHeight(display, screen_num);
1047 
1048  x = 0;
1049  y = 0;
1050 
1051  top_width = 2 * display_width / 3;
1052  top_height = 4 * display_height / 5;
1053 
1054  cmap = DefaultColormap(display, screen_num);
1055  private_cmap = None;
1056 
1057  for (int i=0;i<NUM_COLOR;i++) {
1058  if (!XParseColor(display,cmap,cnames[i],&exact_def)) {
1059  fprintf(stderr, "Color name %s not in database", cnames[i]);
1060  exit(-1);
1061  }
1062  if (!XAllocColor(display, cmap, &exact_def)) {
1063  fprintf(stderr, "Couldn't allocate color %s.\n",cnames[i]);
1064 
1065  if (private_cmap == None) {
1066  fprintf(stderr, "Will try to allocate a private colourmap.\n");
1067  fprintf(stderr, "Colours will only display correctly when your "
1068  "cursor is in the graphics window.\n"
1069  "Exit other colour applications and rerun this "
1070  "program if you don't like that.\n\n");
1071 
1072  private_cmap = XCopyColormapAndFree (display, cmap);
1073  cmap = private_cmap;
1074  if (!XAllocColor (display, cmap, &exact_def)) {
1075  fprintf (stderr, "Couldn't allocate color %s as private.\n",
1076  cnames[i]);
1077  exit (1);
1078  }
1079  }
1080 
1081  else {
1082  fprintf (stderr, "Couldn't allocate color %s as private.\n",
1083  cnames[i]);
1084  exit (1);
1085  }
1086  }
1087  colors[i] = exact_def.pixel;
1088  } // End setting up colours
1089 
1090  toplevel = XCreateSimpleWindow(display,RootWindow(display,screen_num),
1091  x, y, top_width, top_height, border_width, colors[BLACK],
1092  colors[cindex]);
1093 
1094  if (private_cmap != None)
1095  XSetWindowColormap (display, toplevel, private_cmap);
1096 
1097  XSelectInput (display, toplevel, ExposureMask | StructureNotifyMask |
1098  ButtonPressMask | PointerMotionMask | KeyPressMask);
1099 
1100  /* Create default Graphics Contexts. valuemask = 0 -> use defaults. */
1101  current_gc = gc = XCreateGC(display, toplevel, valuemask, &values);
1102  gc_menus = XCreateGC(display, toplevel, valuemask, &values);
1103 
1104  /* Create XOR graphics context for Rubber Banding */
1105  values.function = GXxor;
1106  values.foreground = colors[cindex];
1107  gcxor = XCreateGC(display, toplevel, (GCFunction | GCForeground),
1108  &values);
1109 
1110  /* specify font for menus. */
1112  XSetFont(display, gc_menus, font_info[menu_font_size]->fid);
1113 
1114  /* Set drawing defaults for user-drawable area. Use whatever the *
1115  * initial values of the current stuff was set to. */
1120 
1121  // Need a non-const name to pass to XStringListTo...
1122  // (even though X11 won't change it).
1123  char *window_name_copy = (char *) my_malloc (BUFSIZE * sizeof (char));
1124  strncpy (window_name_copy, window_name, BUFSIZE);
1125  XStringListToTextProperty(&window_name_copy, 1, &windowName);
1126  free (window_name_copy);
1127  window_name_copy = NULL;
1128 
1129  XSetWMName (display, toplevel, &windowName);
1130  /* XSetWMIconName (display, toplevel, &windowName); */
1131 
1132  /* XStringListToTextProperty copies the window_name string into *
1133  * windowName.value. Free this memory now. */
1134 
1135  free (windowName.value);
1136 
1137  XMapWindow (display, toplevel);
1138  build_textarea ();
1139  build_default_menu ();
1140 
1141  /* The following is completely unnecessary if the user is using the *
1142  * interactive (event_loop) graphics. It waits for the first Expose *
1143  * event before returning so that I can tell the window manager has got *
1144  * the top-level window up and running. Thus the user can start drawing *
1145  * into this window immediately, and there's no danger of the window not *
1146  * being ready and output being lost. */
1147  XPeekIfEvent (display, &event, test_if_exposed, NULL);
1148 
1149 #else /* WIN32 */
1150  WNDCLASS wndclass;
1151  HINSTANCE hInstance = GetModuleHandle(NULL);
1152  int x, y;
1153  LOGBRUSH lb;
1154  lb.lbStyle = BS_SOLID;
1155  lb.lbColor = win32_colors[currentcolor];
1156  lb.lbHatch = (LONG)NULL;
1157  x = 0;
1158  y = 0;
1159 
1160  /* get screen size from display structure macro */
1161  display_width = GetSystemMetrics( SM_CXSCREEN );
1162  if (!(display_width))
1163  CREATE_ERROR();
1164  display_height = GetSystemMetrics( SM_CYSCREEN );
1165  if (!(display_height))
1166  CREATE_ERROR();
1167  top_width = 2*display_width/3;
1168  top_height = 4*display_height/5;
1169 
1170  /* Grab the Application name */
1171  wsprintf(szAppName, TEXT(window_name));
1172 
1173  //hGraphicsPen = CreatePen(win32_line_styles[SOLID], 1, win32_colors[BLACK]);
1174  hGraphicsPen = ExtCreatePen(PS_GEOMETRIC | win32_line_styles[currentlinestyle] |
1175  PS_ENDCAP_FLAT, 1, &lb, (LONG)NULL, NULL);
1176  if(!hGraphicsPen)
1177  CREATE_ERROR();
1178  hGraphicsBrush = CreateSolidBrush(win32_colors[DARKGREY]);
1179  if(!hGraphicsBrush)
1180  CREATE_ERROR();
1181  hGrayBrush = CreateSolidBrush(win32_colors[LIGHTGREY]);
1182  if(!hGrayBrush)
1183  CREATE_ERROR();
1184 
1186  hGraphicsFont = CreateFontIndirect(font_info[currentfontsize]);
1187  if (!hGraphicsFont)
1188  CREATE_ERROR();
1189 
1190  /* Register the Main Window class */
1191  wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
1192  wndclass.lpfnWndProc = MainWND;
1193  wndclass.cbClsExtra = 0;
1194  wndclass.cbWndExtra = 0;
1195  wndclass.hInstance = hInstance;
1196  wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
1197  wndclass.hCursor = LoadCursor( NULL, IDC_ARROW);
1198  wndclass.hbrBackground = (HBRUSH) CreateSolidBrush(win32_colors[cindex]);
1199  wndclass.lpszMenuName = NULL;
1200  wndclass.lpszClassName = szAppName;
1201 
1202  if (!RegisterClass(&wndclass)) {
1203  printf ("Error code: %d\n", GetLastError());
1204  MessageBox(NULL, TEXT("Initialization of Windows graphics (init_graphics) failed."),
1205  szAppName, MB_ICONERROR);
1206  exit(-1);
1207  }
1208 
1209  /* Register the Graphics Window class */
1210  wndclass.lpfnWndProc = GraphicsWND;
1211  wndclass.hIcon = NULL;
1212  wndclass.lpszClassName = szGraphicsName;
1213 
1214  if(!RegisterClass(&wndclass))
1215  DRAW_ERROR();
1216 
1217  /* Register the Status Window class */
1218  wndclass.lpfnWndProc = StatusWND;
1219  wndclass.hIcon = NULL;
1220  wndclass.lpszClassName = szStatusName;
1221  wndclass.hbrBackground = hGrayBrush;
1222 
1223  if(!RegisterClass(&wndclass))
1224  DRAW_ERROR();
1225 
1226  /* Register the Buttons Window class */
1227  wndclass.lpfnWndProc = ButtonsWND;
1228  wndclass.hIcon = NULL;
1229  wndclass.lpszClassName = szButtonsName;
1230  wndclass.hbrBackground = hGrayBrush;
1231 
1232  if (!RegisterClass(&wndclass))
1233  DRAW_ERROR();
1234 
1235  hMainWnd = CreateWindow(szAppName, TEXT(window_name),
1236  WS_OVERLAPPEDWINDOW, x, y, top_width, top_height,
1237  NULL, NULL, hInstance, NULL);
1238 
1239  if(!hMainWnd)
1240  DRAW_ERROR();
1241 
1242  /* Set drawing defaults for user-drawable area. Use whatever the *
1243  * initial values of the current stuff was set to. */
1244 
1245  if (ShowWindow(hMainWnd, SW_SHOWNORMAL))
1246  DRAW_ERROR();
1248  if (!UpdateWindow(hMainWnd))
1249  DRAW_ERROR();
1250  win32_drain_message_queue ();
1251 #endif
1252  gl_state.initialized = true;
1253 }
static t_gl_state gl_state
Definition: graphics.c:309
static Bool test_if_exposed(Display *disp, XEvent *event_ptr, XPointer dummy)
Definition: graphics.c:2962
static XFontStruct * font_info[MAX_FONT_SIZE+1]
Definition: graphics.c:388
static void reset_common_state()
Definition: graphics.c:1256
static Display * display
Definition: graphics.c:385
static GC current_gc
Definition: graphics.c:387
static const int menu_font_size
Definition: graphics.c:311
bool initialized
Definition: graphics.c:296
static int display_height
Definition: graphics.c:316
static void force_setcolor(int cindex)
Definition: graphics.c:581
static int currentlinewidth
Definition: graphics.c:329
#define BUFSIZE
Definition: graphics.c:184
int background_cindex
Definition: graphics.c:298
static void load_font(int pointsize)
Definition: graphics.c:2768
static int currentfontsize
Definition: graphics.c:330
static void force_setfontsize(int pointsize)
Definition: graphics.c:755
static GC gcxor
Definition: graphics.c:387
static Window toplevel
Definition: graphics.c:389
static Colormap private_cmap
Definition: graphics.c:390
static void * my_malloc(int ibytes)
Definition: graphics.c:499
static int top_height
Definition: graphics.c:317
static void force_setlinewidth(int linewidth)
Definition: graphics.c:707
static int screen_num
Definition: graphics.c:386
static void build_textarea(void)
Definition: graphics.c:2942
static int currentlinestyle
Definition: graphics.c:328
static int top_width
Definition: graphics.c:317
static int currentcolor
Definition: graphics.c:327
int disp_type
Definition: graphics.c:297
static void force_setlinestyle(int linestyle)
Definition: graphics.c:654
static GC gc_menus
Definition: graphics.c:387
static int colors[NUM_COLOR]
Definition: graphics.c:393
static int display_width
Definition: graphics.c:316
static void build_default_menu(void)
Definition: graphics.c:2628
static GC gc
Definition: graphics.c:387

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int init_postscript ( const char *  fname)

Definition at line 2477 of file graphics.c.

2478 {
2479 
2480  ps = fopen (fname,"w");
2481  if (ps == NULL) {
2482  printf("Error: could not open %s for PostScript output.\n",fname);
2483  printf("Drawing to screen instead.\n");
2484  return (0);
2485  }
2486  gl_state.disp_type = POSTSCRIPT; /* Graphics go to postscript file now. */
2487 
2488  /* Header for minimal conformance with the Adobe structuring convention */
2489  fprintf(ps,"%%!PS-Adobe-1.0\n");
2490  fprintf(ps,"%%%%DocumentFonts: Helvetica\n");
2491  fprintf(ps,"%%%%Pages: 1\n");
2492  /* Set up postscript transformation macros and page boundaries */
2494  /* Bottom margin is at ps_bot - 15. to leave room for the on-screen message. */
2495  fprintf(ps,"%%%%HiResBoundingBox: %.2f %.2f %.2f %.2f\n",
2496  ps_left, ps_bot - 15., ps_right, ps_top);
2497  fprintf(ps,"%%%%EndComments\n");
2498 
2499  fprintf(ps,"/censhow %%draw a centered string\n");
2500  fprintf(ps," { moveto %% move to proper spot\n");
2501  fprintf(ps," dup stringwidth pop %% get x length of string\n");
2502  fprintf(ps," -2 div %% Proper left start\n");
2503  fprintf(ps," yoff rmoveto %% Move left that much and down half font height\n");
2504  fprintf(ps," show newpath } def %% show the string\n\n");
2505 
2506  fprintf(ps,"/setfontsize %% set font to desired size and compute "
2507  "centering yoff\n");
2508  fprintf(ps," { /Helvetica findfont\n");
2509  fprintf(ps," 8 scalefont\n");
2510  fprintf(ps," setfont %% Font size set ...\n\n");
2511  fprintf(ps," 0 0 moveto %% Get vertical centering offset\n");
2512  fprintf(ps," (Xg) true charpath\n");
2513  fprintf(ps," flattenpath pathbbox\n");
2514  fprintf(ps," /ascent exch def pop -1 mul /descent exch def pop\n");
2515  fprintf(ps," newpath\n");
2516  fprintf(ps," descent ascent sub 2 div /yoff exch def } def\n\n");
2517 
2518  fprintf(ps,"%% Next two lines for debugging only.\n");
2519  fprintf(ps,"/str 20 string def\n");
2520  fprintf(ps,"/pnum {str cvs print ( ) print} def\n");
2521 
2522  fprintf(ps,"/drawline %% draw a line from (x2,y2) to (x1,y1)\n");
2523  fprintf(ps," { moveto lineto stroke } def\n\n");
2524 
2525  fprintf(ps,"/rect %% outline a rectangle \n");
2526  fprintf(ps," { /y2 exch def /x2 exch def /y1 exch def /x1 exch def\n");
2527  fprintf(ps," x1 y1 moveto\n");
2528  fprintf(ps," x2 y1 lineto\n");
2529  fprintf(ps," x2 y2 lineto\n");
2530  fprintf(ps," x1 y2 lineto\n");
2531  fprintf(ps," closepath } def\n\n");
2532 
2533  fprintf(ps,"/drawrect %% draw outline of a rectanagle\n");
2534  fprintf(ps," { rect stroke } def\n\n");
2535 
2536  fprintf(ps,"/fillrect %% fill in a rectanagle\n");
2537  fprintf(ps," { rect fill } def\n\n");
2538 
2539  fprintf (ps,"/drawarc { arc stroke } def %% draw an arc\n");
2540  fprintf (ps,"/drawarcn { arcn stroke } def "
2541  " %% draw an arc in the opposite direction\n\n");
2542 
2543  fprintf (ps,"%%Fill a counterclockwise or clockwise arc sector, "
2544  "respectively.\n");
2545  fprintf (ps,"/fillarc { moveto currentpoint 5 2 roll arc closepath fill } "
2546  "def\n");
2547  fprintf (ps,"/fillarcn { moveto currentpoint 5 2 roll arcn closepath fill } "
2548  "def\n\n");
2549 
2550  fprintf (ps,"/fillpoly { 3 1 roll moveto %% move to first point\n"
2551  " 2 exch 1 exch {pop lineto} for %% line to all other points\n"
2552  " closepath fill } def\n\n");
2553 
2554 
2555  fprintf(ps,"%%Color Definitions:\n");
2556  fprintf(ps,"/white { 1 setgray } def\n");
2557  fprintf(ps,"/black { 0 setgray } def\n");
2558  fprintf(ps,"/grey55 { .55 setgray } def\n");
2559  fprintf(ps,"/grey75 { .75 setgray } def\n");
2560  fprintf(ps,"/blue { 0 0 1 setrgbcolor } def\n");
2561  fprintf(ps,"/green { 0 1 0 setrgbcolor } def\n");
2562  fprintf(ps,"/yellow { 1 1 0 setrgbcolor } def\n");
2563  fprintf(ps,"/cyan { 0 1 1 setrgbcolor } def\n");
2564  fprintf(ps,"/red { 1 0 0 setrgbcolor } def\n");
2565  fprintf(ps,"/darkgreen { 0 0.5 0 setrgbcolor } def\n");
2566  fprintf(ps,"/magenta { 1 0 1 setrgbcolor } def\n");
2567  fprintf(ps,"/bisque { 1 0.89 0.77 setrgbcolor } def\n");
2568  fprintf(ps,"/lightblue { 0.68 0.85 0.9 setrgbcolor } def\n");
2569  fprintf(ps,"/thistle { 0.85 0.75 0.85 setrgbcolor } def\n");
2570  fprintf(ps,"/plum { 0.87 0.63 0.87 setrgbcolor } def\n");
2571  fprintf(ps,"/khaki { 0.94 0.9 0.55 setrgbcolor } def\n");
2572  fprintf(ps,"/coral { 1 0.5 0.31 setrgbcolor } def\n");
2573  fprintf(ps,"/turquoise { 0.25 0.88 0.82 setrgbcolor } def\n");
2574  fprintf(ps,"/mediumpurple { 0.58 0.44 0.86 setrgbcolor } def\n");
2575  fprintf(ps,"/darkslateblue { 0.28 0.24 0.55 setrgbcolor } def\n");
2576  fprintf(ps,"/darkkhaki { 0.74 0.72 0.42 setrgbcolor } def\n");
2577 
2578  fprintf(ps,"\n%%Solid and dashed line definitions:\n");
2579  fprintf(ps,"/linesolid {[] 0 setdash} def\n");
2580  fprintf(ps,"/linedashed {[3 3] 0 setdash} def\n");
2581 
2582  fprintf(ps,"\n%%%%EndProlog\n");
2583  fprintf(ps,"%%%%Page: 1 1\n\n");
2584 
2585  /* Set up PostScript graphics state to match current one. */
2590 
2591  /* Draw this in the bottom margin -- must do before the clippath is set */
2592  draw_message ();
2593 
2594  /* Set clipping on page. */
2595  fprintf(ps,"%.2f %.2f %.2f %.2f rect ",ps_left, ps_bot,ps_right,ps_top);
2596  fprintf(ps,"clip newpath\n\n");
2597 
2598  return (1);
2599 }
static t_gl_state gl_state
Definition: graphics.c:309
static void force_setcolor(int cindex)
Definition: graphics.c:581
static int currentlinewidth
Definition: graphics.c:329
static int currentfontsize
Definition: graphics.c:330
static void force_setfontsize(int pointsize)
Definition: graphics.c:755
void draw_message(void)
Definition: graphics.c:2063
static void force_setlinewidth(int linewidth)
Definition: graphics.c:707
static FILE * ps
Definition: graphics.c:334
static int currentlinestyle
Definition: graphics.c:328
static float ps_right
Definition: graphics.c:321
static int currentcolor
Definition: graphics.c:327
int disp_type
Definition: graphics.c:297
static void force_setlinestyle(int linestyle)
Definition: graphics.c:654
static float ps_top
Definition: graphics.c:321
static float ps_left
Definition: graphics.c:321
static float ps_bot
Definition: graphics.c:321
static void update_ps_transform(void)
Definition: graphics.c:1308

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void init_world ( float  x1,
float  y1,
float  x2,
float  y2 
)

Definition at line 2038 of file graphics.c.

2039 {
2040  /* Sets the coordinate system the user wants to draw into. */
2041 
2042  xleft = x1;
2043  xright = x2;
2044  ytop = y1;
2045  ybot = y2;
2046 
2047  saved_xleft = xleft; /* Save initial world coordinates to allow full */
2048  saved_xright = xright; /* view button to zoom all the way out. */
2049  saved_ytop = ytop;
2050  saved_ybot = ybot;
2051 
2052  if (gl_state.disp_type == SCREEN) {
2053  update_transform();
2054  }
2055  else {
2057  }
2058 }
static t_gl_state gl_state
Definition: graphics.c:309
static void update_transform(void)
Definition: graphics.c:1273
static float xleft
Definition: graphics.c:318
static float saved_ytop
Definition: graphics.c:319
static float saved_xleft
Definition: graphics.c:319
static float saved_ybot
Definition: graphics.c:319
static float xright
Definition: graphics.c:318
static float ybot
Definition: graphics.c:318
static float saved_xright
Definition: graphics.c:319
int disp_type
Definition: graphics.c:297
static float ytop
Definition: graphics.c:318
static void update_ps_transform(void)
Definition: graphics.c:1308

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void load_font ( int  pointsize)
static

Definition at line 2768 of file graphics.c.

2769 {
2770 
2771  if (pointsize > MAX_FONT_SIZE || pointsize < 1) {
2772  printf ("Error: font size %d is out of valid range, 1 to %d.\n",
2773  pointsize, MAX_FONT_SIZE);
2774  return;
2775  }
2776 
2777  if (font_is_loaded[pointsize]) // Nothing to do.
2778  return;
2779 
2780 #ifdef X11
2781  #define NUM_FONT_TYPES 3
2782  char fontname[NUM_FONT_TYPES][BUFSIZE];
2783  int ifont;
2784  bool success = false;
2785 
2786  /* Use proper point-size medium-weight upright helvetica font */
2787  // Exists on most X11 systems.
2788  // Backup font: lucidasans, in the new naming style.
2789  sprintf(fontname[0],"-*-helvetica-medium-r-*--*-%d0-*-*-*-*-*-*",
2790  pointsize);
2791  sprintf(fontname[1], "lucidasans-%d", pointsize);
2792  sprintf(fontname[2],"-schumacher-clean-medium-r-*--*-%d0-*-*-*-*-*-*",
2793  pointsize);
2794 
2795 
2796 
2797 
2798  for (ifont = 0; ifont < NUM_FONT_TYPES; ifont++) {
2799 #ifdef VERBOSE
2800  printf ("Loading font: point size: %d, fontname: %s\n",pointsize,
2801  fontname[ifont]);
2802 #endif
2803  /* Load font and get font information structure. */
2804  if ((font_info[pointsize] = XLoadQueryFont(display,fontname[ifont])) == NULL) {
2805 #ifdef VERBOSE
2806  fprintf( stderr, "Cannot open font %s\n", fontname[ifont]);
2807 #endif
2808  }
2809  else {
2810  success = true;
2811  break;
2812  }
2813  }
2814  if (!success) {
2815  printf ("Error in load_font: cannot load any font of pointsize %d.\n",
2816  pointsize);
2817  printf ("Use xlsfonts to list available fonts, and modify load_font\n");
2818  printf ("in graphics.cpp.\n");
2819  exit (1);
2820  }
2821 #else /* WIN32 */
2822  LOGFONT *lf = font_info[pointsize] = (LOGFONT*)my_malloc(sizeof(LOGFONT));
2823  ZeroMemory(lf, sizeof(LOGFONT));
2824  lf->lfHeight = pointsize;
2825  lf->lfWeight = FW_NORMAL;
2826  lf->lfCharSet = ANSI_CHARSET;
2827  lf->lfOutPrecision = OUT_DEFAULT_PRECIS;
2828  lf->lfClipPrecision = CLIP_DEFAULT_PRECIS;
2829  lf->lfQuality = PROOF_QUALITY;
2830  lf->lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS;
2831  strcpy(lf->lfFaceName, "Arial");
2832 #endif
2833 
2834  font_is_loaded[pointsize] = true;
2835 }
static XFontStruct * font_info[MAX_FONT_SIZE+1]
Definition: graphics.c:388
static Display * display
Definition: graphics.c:385
#define BUFSIZE
Definition: graphics.c:184
static void * my_malloc(int ibytes)
Definition: graphics.c:499
#define NUM_FONT_TYPES
#define MAX_FONT_SIZE
Definition: graphics.c:179
static bool font_is_loaded[MAX_FONT_SIZE+1]
Definition: graphics.c:340

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void map_button ( int  bnum)
static

Definition at line 824 of file graphics.c.

825 {
826  button[bnum].ispressed = 0;
827 
828  if (button[bnum].type != BUTTON_SEPARATOR) {
829 #ifdef X11
830  button[bnum].win = XCreateSimpleWindow(display,menu,
831  button[bnum].xleft, button[bnum].ytop, button[bnum].width,
832  button[bnum].height, 0, colors[WHITE], colors[LIGHTGREY]);
833  XMapWindow (display, button[bnum].win);
834  XSelectInput (display, button[bnum].win, ButtonPressMask);
835 #else
836  button[bnum].hwnd = CreateWindow( TEXT("button"), TEXT(button[bnum].text),
837  WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, button[bnum].xleft, button[bnum].ytop,
838  button[bnum].width, button[bnum].height, hButtonsWnd, (HMENU)(200+bnum),
839  (HINSTANCE) GetWindowLong(hMainWnd, GWL_HINSTANCE), NULL);
840  if(!InvalidateRect(hButtonsWnd, NULL, TRUE))
841  DRAW_ERROR();
842  if(!UpdateWindow(hButtonsWnd))
843  DRAW_ERROR();
844 #endif
845  }
846  else { // Separator, not a button.
847 #ifdef X11
848  button[bnum].win = -1;
849 #else // WIN32
850  button[bnum].hwnd = NULL;
851  if(!InvalidateRect(hButtonsWnd, NULL, TRUE))
852  DRAW_ERROR();
853  if(!UpdateWindow(hButtonsWnd))
854  DRAW_ERROR();
855 #endif
856  }
857 }
static Display * display
Definition: graphics.c:385
static float xleft
Definition: graphics.c:318
static t_button * button
Definition: graphics.c:313
static Window menu
Definition: graphics.c:389
#define TRUE
Definition: graphics.c:145
bool ispressed
Definition: graphics.c:283
Window win
Definition: graphics.c:276
static int colors[NUM_COLOR]
Definition: graphics.c:393
static float ytop
Definition: graphics.c:318

+ Here is the caller graph for this function:

static void menutext ( Window  win,
int  xc,
int  yc,
const char *  text 
)
static

Definition at line 2977 of file graphics.c.

2978 {
2979 
2980  /* draws text center at xc, yc -- used only by menu drawing stuff */
2981 
2982  int len, width;
2983 
2984  len = strlen(text);
2985  width = XTextWidth(font_info[menu_font_size], text, len);
2986  XDrawString(display, win, gc_menus, xc-width/2, yc +
2987  (font_info[menu_font_size]->ascent - font_info[menu_font_size]->descent)/2,
2988  text, len);
2989 }
static XFontStruct * font_info[MAX_FONT_SIZE+1]
Definition: graphics.c:388
static Display * display
Definition: graphics.c:385
static const int menu_font_size
Definition: graphics.c:311
static GC gc_menus
Definition: graphics.c:387

+ Here is the caller graph for this function:

static void * my_malloc ( int  ibytes)
static

Definition at line 499 of file graphics.c.

499  {
500  void *mem;
501 
502  mem = (void*)malloc(ibytes);
503  if (mem == NULL) {
504  printf("memory allocation failed!");
505  exit(-1);
506  }
507 
508  return mem;
509 }
static void * my_realloc ( void *  memblk,
int  ibytes 
)
static

Definition at line 512 of file graphics.c.

512  {
513  void *mem;
514 
515  mem = (void*)realloc(memblk, ibytes);
516  if (mem == NULL) {
517  printf("memory allocation failed!");
518  exit(-1);
519  }
520 
521  return mem;
522 }

+ Here is the caller graph for this function:

static void postscript ( void(*)(void)  drawscreen)
static

Definition at line 2371 of file graphics.c.

2372 {
2373 /* Takes a snapshot of the screen and stores it in pic?.ps. The *
2374  * first picture goes in pic1.ps, the second in pic2.ps, etc. */
2375 
2376  static int piccount = 1;
2377  int success;
2378  char fname[BUFSIZE];
2379 
2380  sprintf(fname,"pic%d.ps",piccount);
2381  printf("Writing postscript output to file %s\n", fname);
2382  success = init_postscript (fname);
2383 
2384  if (success) {
2385 
2386  drawscreen();
2387  close_postscript ();
2388  piccount++;
2389  }
2390  else {
2391  printf ("Error initializing for postscript output.\n");
2392 #ifdef WIN32
2393  MessageBox(hMainWnd, "Error initializing postscript output.", NULL, MB_OK);
2394 #endif
2395  }
2396 }
#define BUFSIZE
Definition: graphics.c:184
static void drawscreen(void)
Definition: draw.c:212
int init_postscript(const char *fname)
Definition: graphics.c:2477
void close_postscript(void)
Definition: graphics.c:2602

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void proceed ( void(*)(void)  drawscreen)
static

Definition at line 2400 of file graphics.c.

2401 {
2402  ProceedPressed = TRUE;
2403 }
static int ProceedPressed
Definition: graphics.c:336
#define TRUE
Definition: graphics.c:145

+ Here is the caller graph for this function:

static void quit ( void(*)(void)  drawscreen)
static

Definition at line 2407 of file graphics.c.

2408 {
2409  close_graphics();
2410  exit(0);
2411 }
void close_graphics(void)
Definition: graphics.c:2417

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int rect_off_screen ( float  x1,
float  y1,
float  x2,
float  y2 
)
static

Definition at line 1514 of file graphics.c.

1515 {
1516 
1517  float xmin, xmax, ymin, ymax;
1518 
1519  xmin = min (xleft, xright);
1520  if (x1 < xmin && x2 < xmin)
1521  return (1);
1522 
1523  xmax = max (xleft, xright);
1524  if (x1 > xmax && x2 > xmax)
1525  return (1);
1526 
1527  ymin = min (ytop, ybot);
1528  if (y1 < ymin && y2 < ymin)
1529  return (1);
1530 
1531  ymax = max (ytop, ybot);
1532  if (y1 > ymax && y2 > ymax)
1533  return (1);
1534 
1535  return (0);
1536 }
static float xleft
Definition: graphics.c:318
#define min(a, b)
Definition: graphics.c:174
#define max(a, b)
Definition: graphics.c:171
static float xright
Definition: graphics.c:318
static float ybot
Definition: graphics.c:318
static float ytop
Definition: graphics.c:318

+ Here is the caller graph for this function:

void report_structure ( t_report report)

Definition at line 2843 of file graphics.c.

2843  {
2844  report->xmult = xmult;
2845  report->ymult = ymult;
2846  report->xleft = xleft;
2847  report->xright = xright;
2848  report->ytop = ytop;
2849  report->ybot = ybot;
2850  report->ps_xmult = ps_xmult;
2851  report->ps_ymult = ps_ymult;
2852  report->top_width = top_width;
2853  report->top_height = top_height;
2854 }
float ps_ymult
Definition: graphics.h:38
static float ymult
Definition: graphics.c:324
static float ps_ymult
Definition: graphics.c:323
float ymult
Definition: graphics.h:37
static float xleft
Definition: graphics.c:318
float xright
Definition: graphics.h:39
float xmult
Definition: graphics.h:37
static int top_height
Definition: graphics.c:317
static float xright
Definition: graphics.c:318
int top_width
Definition: graphics.h:40
static float ybot
Definition: graphics.c:318
static float xmult
Definition: graphics.c:324
static float ps_xmult
Definition: graphics.c:323
static int top_width
Definition: graphics.c:317
float ybot
Definition: graphics.h:39
int top_height
Definition: graphics.h:40
float xleft
Definition: graphics.h:39
static float ytop
Definition: graphics.c:318
float ps_xmult
Definition: graphics.h:38
float ytop
Definition: graphics.h:39
static void reset_common_state ( )
static

Definition at line 1256 of file graphics.c.

1256  {
1257  currentcolor = BLACK;
1259  currentlinewidth = 0;
1260  currentfontsize = 12;
1262 
1263  for (int i=0;i<=MAX_FONT_SIZE;i++)
1264  font_is_loaded[i] = false; /* No fonts loaded yet. */
1265 
1266  ProceedPressed = false;
1267  get_keypress_input = false;
1268  get_mouse_move_input = false;
1269 }
static bool get_mouse_move_input
Definition: graphics.c:341
static bool get_keypress_input
Definition: graphics.c:341
static int currentlinewidth
Definition: graphics.c:329
static int currentfontsize
Definition: graphics.c:330
static int ProceedPressed
Definition: graphics.c:336
static int currentlinestyle
Definition: graphics.c:328
static int currentcolor
Definition: graphics.c:327
#define MAX_FONT_SIZE
Definition: graphics.c:179
static bool font_is_loaded[MAX_FONT_SIZE+1]
Definition: graphics.c:340
static e_draw_mode current_draw_mode
Definition: graphics.c:331

+ Here is the caller graph for this function:

void set_draw_mode ( enum e_draw_mode  draw_mode)

Definition at line 2881 of file graphics.c.

2881  {
2882 /* Set normal (overwrite) or xor (useful for rubber-banding)
2883  * drawing mode.
2884  */
2885 
2886  if (draw_mode == DRAW_NORMAL) {
2887 #ifdef X11
2888  current_gc = gc;
2889 #else
2890  if (!SetROP2(hGraphicsDC, R2_COPYPEN))
2891  SELECT_ERROR();
2892 #endif
2893  }
2894  else { // DRAW_XOR
2895 #ifdef X11
2896  current_gc = gcxor;
2897 #else
2898  if (!SetROP2(hGraphicsDC, R2_XORPEN))
2899  SELECT_ERROR();
2900 #endif
2901  }
2902  current_draw_mode = draw_mode;
2903 }
static GC current_gc
Definition: graphics.c:387
static GC gcxor
Definition: graphics.c:387
static GC gc
Definition: graphics.c:387
static e_draw_mode current_draw_mode
Definition: graphics.c:331

+ Here is the caller graph for this function:

void set_keypress_input ( bool  enable)

Definition at line 2862 of file graphics.c.

2862  {
2863  get_keypress_input = enable;
2864 }
static bool get_keypress_input
Definition: graphics.c:341
void set_mouse_move_input ( bool  enable)

Definition at line 2857 of file graphics.c.

2857  {
2858  get_mouse_move_input = enable;
2859 }
static bool get_mouse_move_input
Definition: graphics.c:341
void setcolor ( int  cindex)

Definition at line 619 of file graphics.c.

620 {
621  if (currentcolor != cindex)
622  force_setcolor (cindex);
623 
624 }
static void force_setcolor(int cindex)
Definition: graphics.c:581
static int currentcolor
Definition: graphics.c:327

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void setcolor ( string  cname)

Definition at line 631 of file graphics.c.

631  {
632  int icolor = -1;
633  for (int i = 0; i < NUM_COLOR; i++) {
634  if (cname == ps_cnames[i]) {
635  icolor = i;
636  break;
637  }
638  }
639  if (icolor == -1) {
640  cout << "Error: unknown color " << cname << endl;
641  }
642  else {
643  setcolor (icolor);
644  }
645 }
static const char * ps_cnames[NUM_COLOR]
Definition: graphics.c:342
void setcolor(int cindex)
Definition: graphics.c:619

+ Here is the call graph for this function:

void setfontsize ( int  pointsize)

Definition at line 796 of file graphics.c.

797 {
798 
799  if (pointsize != currentfontsize)
800  force_setfontsize (pointsize);
801 }
static int currentfontsize
Definition: graphics.c:330
static void force_setfontsize(int pointsize)
Definition: graphics.c:755

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void setlinestyle ( int  linestyle)

Definition at line 697 of file graphics.c.

698 {
699  if (linestyle != currentlinestyle)
700  force_setlinestyle (linestyle);
701 }
static int currentlinestyle
Definition: graphics.c:328
static void force_setlinestyle(int linestyle)
Definition: graphics.c:654

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void setlinewidth ( int  linewidth)

Definition at line 743 of file graphics.c.

744 {
745  if (linewidth != currentlinewidth)
746  force_setlinewidth (linewidth);
747 }
static int currentlinewidth
Definition: graphics.c:329
static void force_setlinewidth(int linewidth)
Definition: graphics.c:707

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void setpoly ( int  bnum,
int  xc,
int  yc,
int  r,
float  theta 
)
static

Definition at line 809 of file graphics.c.

810 {
811  int i;
812 
813  button[bnum].type = BUTTON_POLY;
814  for (i=0;i<3;i++) {
815  button[bnum].poly[i][0] = (int) (xc + r*cos(theta) + 0.5);
816  button[bnum].poly[i][1] = (int) (yc + r*sin(theta) + 0.5);
817  theta += (float)(2*PI/3);
818  }
819 }
t_button_type type
Definition: graphics.c:280
static t_button * button
Definition: graphics.c:313
int poly[3][2]
Definition: graphics.c:282
#define PI
Definition: graphics.c:181

+ Here is the caller graph for this function:

static Bool test_if_exposed ( Display *  disp,
XEvent *  event_ptr,
XPointer  dummy 
)
static

Definition at line 2962 of file graphics.c.

2966 {
2967 
2968 
2969  if (event_ptr->type == Expose) {
2970  return (True);
2971  }
2972 
2973  return (False);
2974 }

+ Here is the caller graph for this function:

static void translate_down ( void(*)(void)  drawscreen)
static

Definition at line 2191 of file graphics.c.

2192 {
2193  float ystep;
2194 
2195  ystep = (ybot - ytop)/2;
2196  ytop += ystep;
2197  ybot += ystep;
2198  update_transform();
2199  drawscreen();
2200 }
static void update_transform(void)
Definition: graphics.c:1273
static void drawscreen(void)
Definition: draw.c:212
static float ybot
Definition: graphics.c:318
static float ytop
Definition: graphics.c:318

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void translate_left ( void(*)(void)  drawscreen)
static

Definition at line 2205 of file graphics.c.

2206 {
2207 
2208  float xstep;
2209 
2210  xstep = (xright - xleft)/2;
2211  xleft -= xstep;
2212  xright -= xstep;
2213  update_transform();
2214  drawscreen();
2215 }
static void update_transform(void)
Definition: graphics.c:1273
static float xleft
Definition: graphics.c:318
static void drawscreen(void)
Definition: draw.c:212
static float xright
Definition: graphics.c:318

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void translate_right ( void(*)(void)  drawscreen)
static

Definition at line 2220 of file graphics.c.

2221 {
2222  float xstep;
2223 
2224  xstep = (xright - xleft)/2;
2225  xleft += xstep;
2226  xright += xstep;
2227  update_transform();
2228  drawscreen();
2229 }
static void update_transform(void)
Definition: graphics.c:1273
static float xleft
Definition: graphics.c:318
static void drawscreen(void)
Definition: draw.c:212
static float xright
Definition: graphics.c:318

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void translate_up ( void(*)(void)  drawscreen)
static

Definition at line 2177 of file graphics.c.

2178 {
2179  float ystep;
2180 
2181  ystep = (ybot - ytop)/2;
2182  ytop -= ystep;
2183  ybot -= ystep;
2184  update_transform();
2185  drawscreen();
2186 }
static void update_transform(void)
Definition: graphics.c:1273
static void drawscreen(void)
Definition: draw.c:212
static float ybot
Definition: graphics.c:318
static float ytop
Definition: graphics.c:318

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void turn_on_off ( int  pressed)
static

Definition at line 3113 of file graphics.c.

3113  {
3114 /* Shows when the menu is active or inactive by colouring the
3115  * buttons.
3116  */
3117  int i;
3118 
3119  for (i=0;i<num_buttons;i++) {
3120  button[i].ispressed = pressed;
3121  drawbut(i);
3122  }
3123 }
static int num_buttons
Definition: graphics.c:314
static t_button * button
Definition: graphics.c:313
static void drawbut(int bnum)
Definition: graphics.c:2992
bool ispressed
Definition: graphics.c:283

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void unmap_button ( int  bnum)
static

Definition at line 860 of file graphics.c.

861 {
862  /* Unmaps (removes) a button from the screen. */
863  if (button[bnum].type != BUTTON_SEPARATOR) {
864 #ifdef X11
865  XUnmapWindow (display, button[bnum].win);
866 #else
867  if(!DestroyWindow(button[bnum].hwnd))
868  DRAW_ERROR();
869  if(!InvalidateRect(hButtonsWnd, NULL, TRUE))
870  DRAW_ERROR();
871  if(!UpdateWindow(hButtonsWnd))
872  DRAW_ERROR();
873 #endif
874  }
875 }
static Display * display
Definition: graphics.c:385
static t_button * button
Definition: graphics.c:313
#define TRUE
Definition: graphics.c:145

+ Here is the caller graph for this function:

void update_message ( const char *  msg)

Definition at line 2113 of file graphics.c.

2114 {
2115  strncpy (statusMessage, msg, BUFSIZE);
2116  draw_message ();
2117 #ifdef X11
2118 // Make this appear immediately. Win32 does that automaticaly.
2119  XFlush (display);
2120 #endif // X11
2121 }
static Display * display
Definition: graphics.c:385
static char statusMessage[BUFSIZE]
Definition: graphics.c:338
#define BUFSIZE
Definition: graphics.c:184
void draw_message(void)
Definition: graphics.c:2063

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void update_ps_transform ( void  )
static

Definition at line 1308 of file graphics.c.

1309 {
1310 
1311 /* Postscript coordinates start at (0,0) for the lower left hand corner *
1312 * of the page and increase upwards and to the right. For 8.5 x 11 *
1313 * sheet, coordinates go from (0,0) to (612,792). Spacing is 1/72 inch.*
1314 * I'm leaving a minimum of half an inch (36 units) of border around *
1315  * each edge. */
1316 
1317  float ps_width, ps_height;
1318 
1319  ps_width = 540.; /* 72 * 7.5 */
1320  ps_height = 720.; /* 72 * 10 */
1321 
1322  ps_xmult = ps_width / (xright - xleft);
1323  ps_ymult = ps_height / (ytop - ybot);
1324  /* Need to use same scaling factor to preserve aspect ratio. *
1325  * I show exactly as much on paper as the screen window shows, *
1326  * or the user specifies. */
1327  if (fabs(ps_xmult) <= fabs(ps_ymult)) {
1328  ps_left = 36.;
1329  ps_right = (float)(36. + ps_width);
1330  ps_bot = (float)(396. - fabs(ps_xmult * (ytop - ybot))/2);
1331  ps_top = (float)(396. + fabs(ps_xmult * (ytop - ybot))/2);
1332  /* Maintain aspect ratio but watch signs */
1334  }
1335  else {
1336  ps_bot = 36.;
1337  ps_top = (float)(36. + ps_height);
1338  ps_left = (float)(306. - fabs(ps_ymult * (xright - xleft))/2);
1339  ps_right = (float)(306. + fabs(ps_ymult * (xright - xleft))/2);
1340  /* Maintain aspect ratio but watch signs */
1342  }
1343 }
static float ps_ymult
Definition: graphics.c:323
static float xleft
Definition: graphics.c:318
static float xright
Definition: graphics.c:318
static float ybot
Definition: graphics.c:318
static float ps_xmult
Definition: graphics.c:323
static float ps_right
Definition: graphics.c:321
static float ps_top
Definition: graphics.c:321
static float ps_left
Definition: graphics.c:321
static float ytop
Definition: graphics.c:318
static float ps_bot
Definition: graphics.c:321

+ Here is the caller graph for this function:

static void update_transform ( void  )
static

Definition at line 1273 of file graphics.c.

1274 {
1275 /* Set up the factors for transforming from the user world to X Windows *
1276  * coordinates. */
1277 
1278  float mult, y1, y2, x1, x2;
1279 
1280  /* X Window coordinates go from (0,0) to (width-1,height-1) */
1281  xmult = (top_width - 1 - MWIDTH) / (xright - xleft);
1282  ymult = (top_height - 1 - T_AREA_HEIGHT)/ (ybot - ytop);
1283 
1284  /* Need to use same scaling factor to preserve aspect ratio */
1285  if (fabs(xmult) <= fabs(ymult)) {
1286  mult = (float)(fabs(ymult/xmult));
1287  y1 = ytop - (ybot-ytop)*(mult-1)/2;
1288  y2 = ybot + (ybot-ytop)*(mult-1)/2;
1289  ytop = y1;
1290  ybot = y2;
1291  }
1292  else {
1293  mult = (float)(fabs(xmult/ymult));
1294  x1 = xleft - (xright-xleft)*(mult-1)/2;
1295  x2 = xright + (xright-xleft)*(mult-1)/2;
1296  xleft = x1;
1297  xright = x2;
1298  }
1299  xmult = (top_width - 1 - MWIDTH) / (xright - xleft);
1300  ymult = (top_height - 1 - T_AREA_HEIGHT)/ (ybot - ytop);
1301 
1302  xdiv = 1/xmult;
1303  ydiv = 1/ymult;
1304 }
#define MWIDTH
Definition: graphics.c:177
static float ymult
Definition: graphics.c:324
static float xdiv
Definition: graphics.c:325
static float xleft
Definition: graphics.c:318
static float ydiv
Definition: graphics.c:325
static int top_height
Definition: graphics.c:317
static float xright
Definition: graphics.c:318
static float ybot
Definition: graphics.c:318
static float xmult
Definition: graphics.c:324
static int top_width
Definition: graphics.c:317
#define T_AREA_HEIGHT
Definition: graphics.c:178
static float ytop
Definition: graphics.c:318

+ Here is the caller graph for this function:

static void update_win ( int  x[2],
int  y[2],
void(*)(void)  drawscreen 
)
static

Definition at line 2233 of file graphics.c.

2234 {
2235  float x1, x2, y1, y2;
2236 
2237  x[0] = min(x[0],top_width-MWIDTH); /* Can't go under menu */
2238  x[1] = min(x[1],top_width-MWIDTH);
2239  y[0] = min(y[0],top_height-T_AREA_HEIGHT); /* Can't go under text area */
2240  y[1] = min(y[1],top_height-T_AREA_HEIGHT);
2241 
2242  if ((x[0] == x[1]) || (y[0] == y[1])) {
2243  printf("Illegal (zero area) window. Window unchanged.\n");
2244  return;
2245  }
2246  x1 = XTOWORLD(min(x[0],x[1]));
2247  x2 = XTOWORLD(max(x[0],x[1]));
2248  y1 = YTOWORLD(min(y[0],y[1]));
2249  y2 = YTOWORLD(max(y[0],y[1]));
2250  xleft = x1;
2251  xright = x2;
2252  ytop = y1;
2253  ybot = y2;
2254  update_transform();
2255  drawscreen();
2256 }
#define YTOWORLD(y)
Definition: graphics.c:168
#define MWIDTH
Definition: graphics.c:177
static void update_transform(void)
Definition: graphics.c:1273
static float xleft
Definition: graphics.c:318
static void drawscreen(void)
Definition: draw.c:212
#define min(a, b)
Definition: graphics.c:174
#define max(a, b)
Definition: graphics.c:171
#define XTOWORLD(x)
Definition: graphics.c:167
static int top_height
Definition: graphics.c:317
static float xright
Definition: graphics.c:318
static float ybot
Definition: graphics.c:318
static int top_width
Definition: graphics.c:317
#define T_AREA_HEIGHT
Definition: graphics.c:178
static float ytop
Definition: graphics.c:318

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int which_button ( Window  win)
static

Definition at line 3100 of file graphics.c.

3101 {
3102  int i;
3103 
3104  for (i=0;i<num_buttons;i++) {
3105  if (button[i].win == win)
3106  return(i);
3107  }
3108  printf("Error: Unknown button ID in which_button.\n");
3109  return(0);
3110 }
static int num_buttons
Definition: graphics.c:314
static t_button * button
Definition: graphics.c:313

+ Here is the caller graph for this function:

static int xcoord ( float  worldx)
static

Definition at line 527 of file graphics.c.

528 {
529  int winx;
530 
531  winx = (int) ((worldx-xleft)*xmult + 0.5);
532 
533  /* Avoids overflow in the Window routines. This will allow horizontal *
534  * and vertical lines to be drawn correctly regardless of zooming, but *
535  * will cause diagonal lines that go way off screen to change their *
536  * slope as you zoom in. The only way I can think of to completely fix *
537  * this problem is to do all the clipping in advance in floating point, *
538  * then convert to integers and call Windows. This is a lot of extra *
539  * coding, and means that coordinates will be clipped twice, even though *
540  * this "Super Zoom" problem won't occur unless users zoom way in on *
541  * the graphics. */
542 
543  winx = max (winx, MINPIXEL);
544  winx = min (winx, MAXPIXEL);
545 
546  return (winx);
547 }
static float xleft
Definition: graphics.c:318
#define min(a, b)
Definition: graphics.c:174
#define max(a, b)
Definition: graphics.c:171
static float xmult
Definition: graphics.c:324
#define MINPIXEL
Definition: graphics.c:203
#define MAXPIXEL
Definition: graphics.c:202

+ Here is the caller graph for this function:

static int ycoord ( float  worldy)
static

Definition at line 552 of file graphics.c.

553 {
554  int winy;
555 
556  winy = (int) ((worldy-ytop)*ymult + 0.5);
557 
558  /* Avoid overflow in the X/Win32 Window routines. */
559  winy = max (winy, MINPIXEL);
560  winy = min (winy, MAXPIXEL);
561 
562  return (winy);
563 }
static float ymult
Definition: graphics.c:324
#define min(a, b)
Definition: graphics.c:174
#define max(a, b)
Definition: graphics.c:171
#define MINPIXEL
Definition: graphics.c:203
static float ytop
Definition: graphics.c:318
#define MAXPIXEL
Definition: graphics.c:202

+ Here is the caller graph for this function:

static void zoom_fit ( void(*)(void)  drawscreen)
static

Definition at line 2163 of file graphics.c.

2164 {
2165  xleft = saved_xleft;
2166  xright = saved_xright;
2167  ytop = saved_ytop;
2168  ybot = saved_ybot;
2169 
2170  update_transform ();
2171  drawscreen();
2172 }
static void update_transform(void)
Definition: graphics.c:1273
static float xleft
Definition: graphics.c:318
static float saved_ytop
Definition: graphics.c:319
static void drawscreen(void)
Definition: draw.c:212
static float saved_xleft
Definition: graphics.c:319
static float saved_ybot
Definition: graphics.c:319
static float xright
Definition: graphics.c:318
static float ybot
Definition: graphics.c:318
static float saved_xright
Definition: graphics.c:319
static float ytop
Definition: graphics.c:318

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void zoom_in ( void(*)(void)  drawscreen)
static

Definition at line 2126 of file graphics.c.

2127 {
2128  float xdiff, ydiff;
2129 
2130  xdiff = xright - xleft;
2131  ydiff = ybot - ytop;
2132  xleft += xdiff/5;
2133  xright -= xdiff/5;
2134  ytop += ydiff/5;
2135  ybot -= ydiff/5;
2136 
2137  update_transform ();
2138  drawscreen();
2139 }
static void update_transform(void)
Definition: graphics.c:1273
static float xleft
Definition: graphics.c:318
static void drawscreen(void)
Definition: draw.c:212
static float xright
Definition: graphics.c:318
static float ybot
Definition: graphics.c:318
static float ytop
Definition: graphics.c:318

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void zoom_out ( void(*)(void)  drawscreen)
static

Definition at line 2144 of file graphics.c.

2145 {
2146  float xdiff, ydiff;
2147 
2148  xdiff = xright - xleft;
2149  ydiff = ybot - ytop;
2150  xleft -= xdiff/3;
2151  xright += xdiff/3;
2152  ytop -= ydiff/3;
2153  ybot += ydiff/3;
2154 
2155  update_transform ();
2156  drawscreen();
2157 }
static void update_transform(void)
Definition: graphics.c:1273
static float xleft
Definition: graphics.c:318
static void drawscreen(void)
Definition: draw.c:212
static float xright
Definition: graphics.c:318
static float ybot
Definition: graphics.c:318
static float ytop
Definition: graphics.c:318

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

t_button* button = NULL
static

Definition at line 313 of file graphics.c.

int colors[NUM_COLOR]
static

Definition at line 393 of file graphics.c.

e_draw_mode current_draw_mode
static

Definition at line 331 of file graphics.c.

GC current_gc
static

Definition at line 387 of file graphics.c.

int currentcolor
static

Definition at line 327 of file graphics.c.

int currentfontsize
static

Definition at line 330 of file graphics.c.

int currentlinestyle
static

Definition at line 328 of file graphics.c.

int currentlinewidth
static

Definition at line 329 of file graphics.c.

Display* display
static

Definition at line 385 of file graphics.c.

int display_height
static

Definition at line 316 of file graphics.c.

int display_width
static

Definition at line 316 of file graphics.c.

XFontStruct* font_info[MAX_FONT_SIZE+1]
static

Definition at line 388 of file graphics.c.

bool font_is_loaded[MAX_FONT_SIZE+1]
static

Definition at line 340 of file graphics.c.

GC gc
static

Definition at line 387 of file graphics.c.

GC gc_menus
static

Definition at line 387 of file graphics.c.

GC gcxor
static

Definition at line 387 of file graphics.c.

bool get_keypress_input
static

Definition at line 341 of file graphics.c.

bool get_mouse_move_input
static

Definition at line 341 of file graphics.c.

t_gl_state gl_state = {false, SCREEN, 0}
static

Definition at line 309 of file graphics.c.

Window menu
static

Definition at line 389 of file graphics.c.

const int menu_font_size = 12
static

Definition at line 311 of file graphics.c.

int num_buttons = 0
static

Definition at line 314 of file graphics.c.

Colormap private_cmap
static

Definition at line 390 of file graphics.c.

int ProceedPressed
static

Definition at line 336 of file graphics.c.

FILE* ps
static

Definition at line 334 of file graphics.c.

float ps_bot
static

Definition at line 321 of file graphics.c.

const char* ps_cnames[NUM_COLOR]
static
Initial value:
= {"white", "black", "grey55", "grey75",
"blue", "green", "yellow", "cyan", "red", "darkgreen", "magenta",
"bisque", "lightblue", "thistle", "plum", "khaki", "coral",
"turquoise", "mediumpurple", "darkslateblue", "darkkhaki"}

Definition at line 342 of file graphics.c.

float ps_left
static

Definition at line 321 of file graphics.c.

float ps_right
static

Definition at line 321 of file graphics.c.

float ps_top
static

Definition at line 321 of file graphics.c.

float ps_xmult
static

Definition at line 323 of file graphics.c.

float ps_ymult
static

Definition at line 323 of file graphics.c.

float saved_xleft
static

Definition at line 319 of file graphics.c.

float saved_xright
static

Definition at line 319 of file graphics.c.

float saved_ybot
static

Definition at line 319 of file graphics.c.

float saved_ytop
static

Definition at line 319 of file graphics.c.

int screen_num
static

Definition at line 386 of file graphics.c.

char statusMessage[BUFSIZE] = ""
static

Definition at line 338 of file graphics.c.

Window textarea
static

Definition at line 389 of file graphics.c.

int top_height
static

Definition at line 317 of file graphics.c.

int top_width
static

Definition at line 317 of file graphics.c.

Window toplevel
static

Definition at line 389 of file graphics.c.

float xdiv
static

Definition at line 325 of file graphics.c.

float xleft
static

Definition at line 318 of file graphics.c.

float xmult
static

Definition at line 324 of file graphics.c.

float xright
static

Definition at line 318 of file graphics.c.

float ybot
static

Definition at line 318 of file graphics.c.

float ydiv
static

Definition at line 325 of file graphics.c.

float ymult
static

Definition at line 324 of file graphics.c.

float ytop
static

Definition at line 318 of file graphics.c.