VPR-7.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
graphics.h File Reference
#include <iostream>
#include <string>
#include "easygl_constants.h"
+ Include dependency graph for graphics.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  t_report
 

Macros

#define X11
 

Enumerations

enum  e_draw_mode { DRAW_NORMAL = 0, DRAW_XOR }
 

Functions

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 init_graphics (const char *window_name, int cindex_background)
 
void init_world (float xl, float yt, float xr, float yb)
 
void close_graphics (void)
 
void update_message (const char *msg)
 
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)
 
int init_postscript (const char *fname)
 
void close_postscript (void)
 
void clearscreen (void)
 
void setcolor (int cindex)
 
void setcolor (string cname)
 
int getcolor (void)
 
void setlinestyle (int linestyle)
 
void setlinewidth (int linewidth)
 
void setfontsize (int pointsize)
 
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)
 
void fillpoly (t_point *points, int npoints)
 
void drawarc (float xcen, float ycen, float rad, float startang, float angextent)
 
void fillarc (float xcen, float ycen, float rad, float startang, float angextent)
 
void drawellipticarc (float xc, float yc, float radx, float rady, float startang, float angextent)
 
void fillellipticarc (float xc, float yc, float radx, float rady, float startang, float angextent)
 
void drawtext (float xc, float yc, const char *text, float boundx)
 
void set_mouse_move_input (bool turn_on)
 
void set_keypress_input (bool turn_on)
 
void enable_or_disable_button (int ibutton, bool enabled)
 
void draw_message (void)
 
void flushinput (void)
 
void set_draw_mode (enum e_draw_mode draw_mode)
 
void change_button_text (const char *button_text, const char *new_button_text)
 
void report_structure (t_report *)
 

Macro Definition Documentation

#define X11

Definition at line 13 of file graphics.h.

Enumeration Type Documentation

Enumerator
DRAW_NORMAL 
DRAW_XOR 

Definition at line 209 of file graphics.h.

Function Documentation

void change_button_text ( const char *  button_text,
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  xcen,
float  ycen,
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:

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:

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  xcen,
float  ycen,
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:

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_background 
)

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  xl,
float  yt,
float  xr,
float  yb 
)

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:

void report_structure ( t_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 }
static float ymult
Definition: graphics.c:324
static float ps_ymult
Definition: graphics.c:323
static float xleft
Definition: graphics.c:318
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 float ps_xmult
Definition: graphics.c:323
static int top_width
Definition: graphics.c:317
static float ytop
Definition: graphics.c:318
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  turn_on)

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  turn_on)

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:

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: