139 #ifndef NO_GRAPHICS // Strip everything out and just put in stubs if NO_GRAPHICS defined
158 #if defined(X11) || defined(WIN32)
161 #define XPOST(worldx) (((worldx)-xleft)*ps_xmult + ps_left)
162 #define YPOST(worldy) (((worldy)-ybot)*ps_ymult + ps_bot)
167 #define XTOWORLD(x) (((float) x)*xdiv + xleft)
168 #define YTOWORLD(y) (((float) y)*ydiv + ytop)
171 #define max(a,b) (((a) > (b))? (a) : (b))
174 #define min(a,b) ((a) > (b)? (b) : (a))
178 #define T_AREA_HEIGHT 24
179 #define MAX_FONT_SIZE 24
181 #define PI 3.141592654
183 #define BUTTON_TEXT_LEN 100
192 #include <X11/Xlib.h>
193 #include <X11/Xutil.h>
195 #include <X11/Xatom.h>
202 #define MAXPIXEL 15000
203 #define MINPIXEL -15000
212 #pragma warning(disable : 4996) // Turn off annoying warnings about strcmp.
217 #define SELECT_ERROR() { char msg[BUFSIZE]; sprintf (msg, "Error %i: Couldn't select graphics object on line %d of graphics.c\n", GetLastError(), __LINE__); MessageBox(NULL, msg, NULL, MB_OK); exit(-1); }
218 #define DELETE_ERROR() { char msg[BUFSIZE]; sprintf (msg, "Error %i: Couldn't delete graphics object on line %d of graphics.c\n", GetLastError(), __LINE__); MessageBox(NULL, msg, NULL, MB_OK); exit(-1); }
219 #define CREATE_ERROR() { char msg[BUFSIZE]; sprintf (msg, "Error %i: Couldn't create graphics object on line %d of graphics.c\n", GetLastError(), __LINE__); MessageBox(NULL, msg, NULL, MB_OK); exit(-1); }
220 #define DRAW_ERROR() { char msg[BUFSIZE]; sprintf (msg, "Error %i: Couldn't draw graphics object on line %d of graphics.c\n", GetLastError(), __LINE__); MessageBox(NULL, msg, NULL, MB_OK); exit(-1); }
225 #define MAXPIXEL 3000
226 #define MINPIXEL -3000
228 #define DEGTORAD(x) ((x)/180.*PI)
343 "blue",
"green",
"yellow",
"cyan",
"red",
"darkgreen",
"magenta",
344 "bisque",
"lightblue",
"thistle",
"plum",
"khaki",
"coral",
345 "turquoise",
"mediumpurple",
"darkslateblue",
"darkkhaki"};
353 static void *
my_realloc(
void *memblk,
int ibytes);
354 static int xcoord (
float worldx);
355 static int ycoord (
float worldy);
403 static void drawbut (
int bnum);
418 static const int win32_line_styles[2] = { PS_SOLID, PS_DASH };
420 static const COLORREF win32_colors[
NUM_COLOR] = { RGB(255, 255, 255),
421 RGB(0, 0, 0), RGB(128, 128, 128), RGB(192, 192, 192), RGB(0, 0, 255),
422 RGB(0, 255, 0), RGB(255, 255, 0), RGB(0, 255, 255), RGB(255, 0, 0), RGB(0, 128, 0),
423 RGB(255, 0, 255), RGB(255, 228, 196), RGB(173, 216, 230), RGB(216, 191, 216), RGB(221, 160, 221),
424 RGB(240, 230, 140), RGB(255, 127, 80), RGB(64, 224, 208), RGB(147, 112, 219), RGB(72, 61, 139),
427 static TCHAR szAppName[256],
428 szGraphicsName[] = TEXT(
"VPR Graphics"),
429 szStatusName[] = TEXT(
"VPR Status"),
430 szButtonsName[] = TEXT(
"VPR Buttons");
431 static HPEN hGraphicsPen;
432 static HBRUSH hGraphicsBrush, hGrayBrush;
433 static HDC hGraphicsDC, hForegroundDC, hBackgroundDC,
435 hObjtestDC, hAllObjtestDC;
438 static HFONT hGraphicsFont;
442 static HWND hMainWnd, hGraphicsWnd, hButtonsWnd, hStatusWnd;
444 static int cxClient, cyClient;
449 static int windowAdjustFlag = 0, adjustButton = -1;
450 static RECT adjustRect, updateRect;
452 static boolean InEventLoop =
FALSE;
464 static LRESULT CALLBACK GraphicsWND(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
465 static LRESULT CALLBACK StatusWND(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
466 static LRESULT CALLBACK ButtonsWND(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
467 static LRESULT CALLBACK MainWND(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
477 static void (*mouseclick_ptr)(
float x,
float y);
478 static void (*mousemove_ptr)(
float x,
float y);
479 static void (*keypress_ptr)(
char entered_char);
480 static void (*drawscreen_ptr)(void);
482 static void invalidate_screen();
484 static void reset_win32_state ();
485 static void win32_drain_message_queue ();
488 void displaybuffer();
502 mem = (
void*)malloc(ibytes);
504 printf(
"memory allocation failed!");
515 mem = (
void*)realloc(memblk, ibytes);
517 printf(
"memory allocation failed!");
556 winy = (int) ((worldy-
ytop)*
ymult + 0.5);
567 static void invalidate_screen(
void)
571 if(!InvalidateRect(hGraphicsWnd, NULL,
FALSE))
573 if(!UpdateWindow(hGraphicsWnd))
591 lb.lbStyle = BS_SOLID;
592 lb.lbColor = win32_colors[cindex];
593 lb.lbHatch = (LONG)NULL;
596 if(!DeleteObject(hGraphicsPen))
600 hGraphicsPen = ExtCreatePen(PS_GEOMETRIC | win_linestyle |
601 PS_ENDCAP_FLAT, linewidth, &lb, (LONG)NULL, NULL);
605 if(!DeleteObject(hGraphicsBrush))
607 hGraphicsBrush = CreateSolidBrush(win32_colors[
currentcolor]);
640 cout <<
"Error: unknown color " << cname << endl;
661 static int x_vals[2] = {LineSolid, LineOnOffDash};
666 lb.lbStyle = BS_SOLID;
668 lb.lbHatch = (LONG)NULL;
669 int win_linestyle = win32_line_styles[linestyle];
671 if(!DeleteObject(hGraphicsPen))
674 hGraphicsPen = ExtCreatePen(PS_GEOMETRIC | win_linestyle |
675 PS_ENDCAP_FLAT, linewidth, &lb, (LONG)NULL, NULL);
682 if (linestyle ==
SOLID)
683 fprintf (
ps,
"linesolid\n");
684 else if (linestyle ==
DASHED)
685 fprintf (
ps,
"linedashed\n");
687 printf (
"Error: invalid linestyle: %d\n", linestyle);
714 static int x_vals[2] = {LineSolid, LineOnOffDash};
719 lb.lbStyle = BS_SOLID;
721 lb.lbHatch = (LONG)NULL;
724 if(!DeleteObject(hGraphicsPen))
728 hGraphicsPen = ExtCreatePen(PS_GEOMETRIC | win_linestyle |
729 PS_ENDCAP_FLAT, linewidth, &lb, (LONG)NULL, NULL);
736 fprintf(
ps,
"%d setlinewidth\n", linewidth);
761 pointsize = (int)((
float)pointsize * FONTMAG);
773 if(!DeleteObject(hGraphicsFont))
775 hGraphicsFont = CreateFontIndirect(
font_info[pointsize]);
778 if(!SelectObject(hGraphicsDC, hGraphicsFont) )
786 fprintf(
ps,
"%d setfontsize\n",pointsize);
809 static void setpoly (
int bnum,
int xc,
int yc,
int r,
float theta)
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);
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))
842 if(!UpdateWindow(hButtonsWnd))
851 if(!InvalidateRect(hButtonsWnd, NULL,
TRUE))
853 if(!UpdateWindow(hButtonsWnd))
867 if(!DestroyWindow(
button[bnum].hwnd))
869 if(!InvalidateRect(hButtonsWnd, NULL,
TRUE))
871 if(!UpdateWindow(hButtonsWnd))
882 void (*button_func) (
void (*
drawscreen) (
void)))
884 int i, bnum, space, bheight;
897 strcmp (
button[i].text, prev_button_text) == 0) {
904 printf (
"Error in create_button: button with text %s not found.\n",
914 if (!strncmp(button_text,
"---", 3)) {
921 for (i=num_buttons;i>bnum;i--) {
956 int i, bnum, space, bheight;
962 strcmp (
button[i].text, button_text) == 0) {
969 printf (
"Error in destroy_button: button with text %s not found.\n",
1010 reset_win32_state ();
1018 char *display_name = NULL;
1020 unsigned int border_width = 2;
1021 XTextProperty windowName;
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" };
1031 unsigned long valuemask = 0;
1036 if ( (
display=XOpenDisplay(display_name)) == NULL )
1038 fprintf( stderr,
"Cannot connect to X server %s\n",
1039 XDisplayName(display_name));
1058 if (!XParseColor(
display,cmap,cnames[i],&exact_def)) {
1059 fprintf(stderr,
"Color name %s not in database", cnames[i]);
1062 if (!XAllocColor(
display, cmap, &exact_def)) {
1063 fprintf(stderr,
"Couldn't allocate color %s.\n",cnames[i]);
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");
1074 if (!XAllocColor (
display, cmap, &exact_def)) {
1075 fprintf (stderr,
"Couldn't allocate color %s as private.\n",
1082 fprintf (stderr,
"Couldn't allocate color %s as private.\n",
1087 colors[i] = exact_def.pixel;
1098 ButtonPressMask | PointerMotionMask | KeyPressMask);
1105 values.function = GXxor;
1106 values.foreground =
colors[cindex];
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;
1135 free (windowName.value);
1151 HINSTANCE hInstance = GetModuleHandle(NULL);
1154 lb.lbStyle = BS_SOLID;
1156 lb.lbHatch = (LONG)NULL;
1171 wsprintf(szAppName, TEXT(window_name));
1174 hGraphicsPen = ExtCreatePen(PS_GEOMETRIC | win32_line_styles[
currentlinestyle] |
1175 PS_ENDCAP_FLAT, 1, &lb, (LONG)NULL, NULL);
1178 hGraphicsBrush = CreateSolidBrush(win32_colors[
DARKGREY]);
1181 hGrayBrush = CreateSolidBrush(win32_colors[
LIGHTGREY]);
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;
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);
1210 wndclass.lpfnWndProc = GraphicsWND;
1211 wndclass.hIcon = NULL;
1212 wndclass.lpszClassName = szGraphicsName;
1214 if(!RegisterClass(&wndclass))
1218 wndclass.lpfnWndProc = StatusWND;
1219 wndclass.hIcon = NULL;
1220 wndclass.lpszClassName = szStatusName;
1221 wndclass.hbrBackground = hGrayBrush;
1223 if(!RegisterClass(&wndclass))
1227 wndclass.lpfnWndProc = ButtonsWND;
1228 wndclass.hIcon = NULL;
1229 wndclass.lpszClassName = szButtonsName;
1230 wndclass.hbrBackground = hGrayBrush;
1232 if (!RegisterClass(&wndclass))
1235 hMainWnd = CreateWindow(szAppName, TEXT(window_name),
1237 NULL, NULL, hInstance, NULL);
1245 if (ShowWindow(hMainWnd, SW_SHOWNORMAL))
1248 if (!UpdateWindow(hMainWnd))
1250 win32_drain_message_queue ();
1278 float mult, y1, y2, x1, x2;
1317 float ps_width, ps_height;
1329 ps_right = (float)(36. + ps_width);
1337 ps_top = (float)(36. + ps_height);
1353 void (*act_on_mousemove)(
float x,
float y),
1354 void (*act_on_keypress)(
char key_pressed),
1367 XNextEvent (
display, &report);
1368 switch (report.type) {
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);
1375 if (report.xexpose.count != 0)
1377 if (report.xexpose.window ==
menu)
1379 else if (report.xexpose.window ==
toplevel)
1381 else if (report.xexpose.window ==
textarea)
1384 case ConfigureNotify:
1391 printf(
"Got a ConfigureNotify.\n");
1397 printf(
"Got a buttonpress.\n");
1398 printf(
"Window ID is: %d.\n",report.xbutton.window);
1400 if (report.xbutton.window ==
toplevel) {
1403 act_on_mousebutton (x, y);
1408 printf(
"Button number is %d\n",bnum);
1410 if (
button[bnum].enabled) {
1428 printf(
"Got a MotionNotify Event.\n");
1429 printf(
"x: %d y: %d\n",report.xmotion.x,report.xmotion.y);
1438 printf(
"Got a KeyPress Event.\n");
1442 char keyb_buffer[20];
1443 XComposeStatus composestatus;
1445 int length, max_bytes;
1449 length = XLookupString( &report.xkey, keyb_buffer, max_bytes, &keysym,
1452 keyb_buffer[length] =
'\0';
1453 act_on_keypress(keyb_buffer[0]);
1462 mouseclick_ptr = act_on_mousebutton;
1463 mousemove_ptr = act_on_mousemove;
1464 keypress_ptr = act_on_keypress;
1469 invalidate_screen();
1473 if (msg.message == WM_CHAR) {
1474 msg.hwnd = hMainWnd;
1476 DispatchMessage(&msg);
1478 InEventLoop =
FALSE;
1502 fprintf(
ps,
"clippath fill\n\n");
1517 float xmin, xmax, ymin, ymax;
1520 if (x1 < xmin && x2 < xmin)
1524 if (x1 > xmax && x2 > xmax)
1528 if (y1 < ymin && y2 < ymin)
1532 if (y1 > ymax && y2 > ymax)
1556 hOldPen = (HPEN)SelectObject(hGraphicsDC, hGraphicsPen);
1559 if (!BeginPath(hGraphicsDC))
1561 if(!MoveToEx (hGraphicsDC,
xcoord(x1),
ycoord(y1), NULL))
1565 if (!EndPath(hGraphicsDC))
1567 if (!StrokePath(hGraphicsDC))
1569 if(!SelectObject(hGraphicsDC, hOldPen))
1574 fprintf(
ps,
"%.2f %.2f %.2f %.2f drawline\n",
XPOST(x1),
YPOST(y1),
1583 int xw1, yw1, xw2, yw2;
1588 unsigned int width, height;
1604 width = abs (xw1-xw2);
1605 height = abs (yw1-yw2);
1619 hOldPen = (HPEN)SelectObject(hGraphicsDC, hGraphicsPen);
1622 hOldBrush = (HBRUSH)SelectObject(hGraphicsDC, GetStockObject(NULL_BRUSH));
1625 if(!Rectangle(hGraphicsDC, xw1, yw1, xw2, yw2))
1627 if(!SelectObject(hGraphicsDC, hOldPen))
1629 if(!SelectObject(hGraphicsDC, hOldBrush))
1635 fprintf(
ps,
"%.2f %.2f %.2f %.2f drawrect\n",
XPOST(x1),
YPOST(y1),
1645 int xw1, yw1, xw2, yw2;
1650 unsigned int width, height;
1666 width = abs (xw1-xw2);
1667 height = abs (yw1-yw2);
1681 hOldPen = (HPEN)SelectObject(hGraphicsDC, hGraphicsPen);
1684 hOldBrush = (HBRUSH)SelectObject(hGraphicsDC, hGraphicsBrush);
1687 if(!Rectangle(hGraphicsDC, xw1, yw1, xw2, yw2))
1689 if(!SelectObject(hGraphicsDC, hOldPen))
1691 if(!SelectObject(hGraphicsDC, hOldBrush))
1696 fprintf(
ps,
"%.2f %.2f %.2f %.2f fillrect\n",
XPOST(x1),
YPOST(y1),
1709 scale = (int) (ang / 360. - 1);
1712 scale = (int) (ang / 360.);
1714 ang = ang - scale * 360;
1719 drawellipticarc (
float xc,
float yc,
float radx,
float rady,
float startang,
float angextent)
1722 unsigned int width, height;
1736 if (fabs(angextent) > 360.)
1739 startang =
angnorm (startang);
1744 width = (
unsigned int) (2*fabs(
xmult*radx));
1745 height = (
unsigned int) (2*fabs(
ymult*rady));
1748 (
int) (startang*64), (
int) (angextent*64));
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)));
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)));
1764 hOldPen = (HPEN)SelectObject(hGraphicsDC, hGraphicsPen);
1767 if(!Arc(hGraphicsDC, xl, yt, xl+width, yt+height, p1, p2, p3, p4))
1769 if(!SelectObject(hGraphicsDC, hOldPen))
1774 fprintf(
ps,
"gsave\n");
1775 fprintf(
ps,
"%.2f %.2f translate\n",
XPOST(xc),
YPOST(yc));
1777 fprintf(
ps,
"0 0 %.2f %.2f %.2f %s\n",
1778 fabs(rady*ps_xmult), startang, startang+angextent,
1779 (angextent < 0) ?
"drawarcn" :
"drawarc") ;
1780 fprintf(
ps,
"grestore\n");
1787 drawarc (
float xc,
float yc,
float rad,
float startang,
1802 unsigned int width, height;
1818 if (fabs(angextent) > 360.)
1821 startang =
angnorm (startang);
1826 width = (
unsigned int) (2*fabs(
xmult*radx));
1827 height = (
unsigned int) (2*fabs(
ymult*rady));
1830 (
int) (startang*64), (
int) (angextent*64));
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)));
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)));
1846 hOldPen = (HPEN)SelectObject(hGraphicsDC, GetStockObject(NULL_PEN));
1849 hOldBrush = (HBRUSH)SelectObject(hGraphicsDC, hGraphicsBrush);
1854 Pie(hGraphicsDC, xl, yt, xl+width, yt+height, p1, p2, p3, p4);
1858 if(!SelectObject(hGraphicsDC, hOldPen))
1860 if(!SelectObject(hGraphicsDC, hOldBrush))
1865 fprintf(
ps,
"gsave\n");
1866 fprintf(
ps,
"%.2f %.2f translate\n",
XPOST(xc),
YPOST(yc));
1868 fprintf(
ps,
"%.2f %.2f %.2f 0 0 %s\n",
1869 fabs(rady*ps_xmult), startang, startang+angextent,
1870 (angextent < 0) ?
"fillarcn" :
"fillarc") ;
1871 fprintf(
ps,
"grestore\n");
1876 fillarc (
float xc,
float yc,
float rad,
float startang,
float angextent) {
1884 XPoint transpoints[
MAXPTS];
1886 POINT transpoints[
MAXPTS];
1891 float xmin, ymin, xmax, ymax;
1894 printf(
"Error in fillpoly: Only %d points allowed per polygon.\n",
1896 printf(
"%d points were requested. Polygon is not drawn.\n",npoints);
1903 xmin = xmax = points[0].
x;
1904 ymin = ymax = points[0].
y;
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);
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);
1925 hOldPen = (HPEN)SelectObject(hGraphicsDC, GetStockObject(NULL_PEN));
1928 hOldBrush = (HBRUSH)SelectObject(hGraphicsDC, hGraphicsBrush);
1931 if(!Polygon (hGraphicsDC, transpoints, npoints))
1933 if(!SelectObject(hGraphicsDC, hOldPen))
1935 if(!SelectObject(hGraphicsDC, hOldBrush))
1942 for (i=npoints-1;i>=0;i--)
1943 fprintf (
ps,
"%.2f %.2f\n",
XPOST(points[i].x),
YPOST(points[i].y));
1945 fprintf (
ps,
"%d fillpoly\n", npoints);
1952 drawtext (
float xc,
float yc,
const char *text,
float boundx)
1954 int len, width, xw_off, yw_off, font_ascent, font_descent;
1964 TEXTMETRIC textmetric;
1966 hOldFont = (HFONT)SelectObject(hGraphicsDC, hGraphicsFont);
1969 if(SetTextColor(hGraphicsDC, win32_colors[
currentcolor]) == CLR_INVALID)
1973 if (!GetTextExtentPoint32(hGraphicsDC, text, len, &textsize))
1975 width = textsize.cx;
1976 if (!GetTextMetrics(hGraphicsDC, &textmetric))
1978 font_ascent = textmetric.tmAscent;
1979 font_descent = textmetric.tmDescent;
1981 if (width > fabs(boundx*
xmult)) {
1983 if(!SelectObject(hGraphicsDC, hOldFont))
1989 xw_off = (int)(width/(2.*xmult));
1992 yw_off = (int)((font_ascent + 2 * font_descent)/(2.*
ymult));
2000 if(!SelectObject(hGraphicsDC, hOldFont))
2012 SetBkMode(hGraphicsDC, TRANSPARENT);
2013 if(!TextOut (hGraphicsDC,
xcoord(xc)-width/2,
ycoord(yc) - (font_ascent + font_descent)/2,
2016 if(!SelectObject(hGraphicsDC, hOldFont))
2021 fprintf(
ps,
"(%s) %.2f %.2f censhow\n",text,
XPOST(xc),
YPOST(yc));
2065 int savefontsize, savecolor;
2087 if(!InvalidateRect(hStatusWnd, NULL,
TRUE))
2089 if(!UpdateWindow(hStatusWnd))
2235 float x1, x2, y1, y2;
2242 if ((x[0] == x[1]) || (y[0] == y[1])) {
2243 printf(
"Illegal (zero area) window. Window unchanged.\n");
2267 int corner, xold, yold, x[2], y[2];
2274 XNextEvent (
display, &report);
2275 switch (report.type) {
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);
2282 if (report.xexpose.count != 0)
2284 if (report.xexpose.window ==
menu)
2286 else if (report.xexpose.window ==
toplevel) {
2290 else if (report.xexpose.window ==
textarea)
2293 case ConfigureNotify:
2300 printf(
"Got a ConfigureNotify.\n");
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,
2311 if (report.xbutton.window !=
toplevel)
break;
2312 x[corner] = report.xbutton.x;
2313 y[corner] = report.xbutton.y;
2326 printf(
"Got a MotionNotify Event.\n");
2327 printf(
"x: %d y: %d\n",report.xmotion.x,report.xmotion.y);
2333 min(y[0],yold),abs(x[0]-xold),abs(y[0]-yold));
2338 yold = report.xmotion.y;
2351 min(y[0],yold),abs(x[0]-xold),abs(y[0]-yold));
2363 if (!windowAdjustFlag) {
2364 windowAdjustFlag = 1;
2376 static int piccount = 1;
2380 sprintf(fname,
"pic%d.ps",piccount);
2381 printf(
"Writing postscript output to file %s\n", fname);
2391 printf (
"Error initializing for postscript output.\n");
2393 MessageBox(hMainWnd,
"Error initializing postscript output.", NULL, MB_OK);
2446 if(!DestroyWindow(hMainWnd))
2453 if (!UnregisterClass (szAppName, GetModuleHandle(NULL)) )
2455 if (!UnregisterClass (szGraphicsName, GetModuleHandle(NULL)) )
2457 if (!UnregisterClass (szStatusName, GetModuleHandle(NULL)) )
2459 if (!UnregisterClass (szButtonsName, GetModuleHandle(NULL)) )
2480 ps = fopen (fname,
"w");
2482 printf(
"Error: could not open %s for PostScript output.\n",fname);
2483 printf(
"Drawing to screen instead.\n");
2489 fprintf(
ps,
"%%!PS-Adobe-1.0\n");
2490 fprintf(
ps,
"%%%%DocumentFonts: Helvetica\n");
2491 fprintf(
ps,
"%%%%Pages: 1\n");
2495 fprintf(
ps,
"%%%%HiResBoundingBox: %.2f %.2f %.2f %.2f\n",
2497 fprintf(
ps,
"%%%%EndComments\n");
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");
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");
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");
2522 fprintf(
ps,
"/drawline %% draw a line from (x2,y2) to (x1,y1)\n");
2523 fprintf(
ps,
" { moveto lineto stroke } def\n\n");
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");
2533 fprintf(
ps,
"/drawrect %% draw outline of a rectanagle\n");
2534 fprintf(
ps,
" { rect stroke } def\n\n");
2536 fprintf(
ps,
"/fillrect %% fill in a rectanagle\n");
2537 fprintf(
ps,
" { rect fill } def\n\n");
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");
2543 fprintf (
ps,
"%%Fill a counterclockwise or clockwise arc sector, "
2545 fprintf (
ps,
"/fillarc { moveto currentpoint 5 2 roll arc closepath fill } "
2547 fprintf (
ps,
"/fillarcn { moveto currentpoint 5 2 roll arcn closepath fill } "
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");
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");
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");
2582 fprintf(
ps,
"\n%%%%EndProlog\n");
2583 fprintf(
ps,
"%%%%Page: 1 1\n\n");
2596 fprintf(
ps,
"clip newpath\n\n");
2605 fprintf(
ps,
"showpage\n");
2606 fprintf(
ps,
"\n%%%%Trailer\n");
2630 int i, xcen, x1, y1, bwid, bheight, space;
2631 const int NUM_ARROW_BUTTONS = 4, NUM_STANDARD_BUTTONS = 12, SEPARATOR_BUTTON_INDEX = 8;
2635 unsigned long valuemask;
2636 XSetWindowAttributes menu_attributes;
2641 menu_attributes.event_mask = ExposureMask;
2643 menu_attributes.do_not_propagate_mask = ButtonPressMask;
2645 menu_attributes.win_gravity = NorthEastGravity;
2646 valuemask = CWWinGravity | CWEventMask | CWDontPropagate;
2647 XChangeWindowAttributes(
display,
menu, valuemask, &menu_attributes);
2662 setpoly (0, bwid/2, bwid/2, bwid/3, -
PI/2.);
2665 strcpy(
button[0].text,
"U");
2670 x1 = xcen - 3*bwid/2 - space;
2674 setpoly (1, bwid/2, bwid/2, bwid/3,
PI);
2677 strcpy(
button[1].text,
"L");
2681 x1 = xcen + bwid/2 + space;
2685 setpoly (2, bwid/2, bwid/2, bwid/3, 0);
2688 strcpy(
button[2].text,
"R");
2697 setpoly (3, bwid/2, bwid/2, bwid/3, +
PI/2.);
2700 strcpy(
button[3].text,
"D");
2704 for (i = 0; i < NUM_ARROW_BUTTONS; i++) {
2712 y1 += bwid + space + 6;
2717 for (i = NUM_ARROW_BUTTONS; i < NUM_STANDARD_BUTTONS; i++) {
2723 if (i != SEPARATOR_BUTTON_INDEX) {
2725 y1 += bheight + space;
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");
2752 for (i = 0; i < NUM_STANDARD_BUTTONS; i++)
2758 if(!InvalidateRect(hButtonsWnd, NULL,
TRUE))
2760 if(!UpdateWindow(hButtonsWnd))
2772 printf (
"Error: font size %d is out of valid range, 1 to %d.\n",
2781 #define NUM_FONT_TYPES 3
2784 bool success =
false;
2789 sprintf(fontname[0],
"-*-helvetica-medium-r-*--*-%d0-*-*-*-*-*-*",
2791 sprintf(fontname[1],
"lucidasans-%d", pointsize);
2792 sprintf(fontname[2],
"-schumacher-clean-medium-r-*--*-%d0-*-*-*-*-*-*",
2800 printf (
"Loading font: point size: %d, fontname: %s\n",pointsize,
2804 if ((
font_info[pointsize] = XLoadQueryFont(
display,fontname[ifont])) == NULL) {
2806 fprintf( stderr,
"Cannot open font %s\n", fontname[ifont]);
2815 printf (
"Error in load_font: cannot load any font of pointsize %d.\n",
2817 printf (
"Use xlsfonts to list available fonts, and modify load_font\n");
2818 printf (
"in graphics.cpp.\n");
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");
2872 EnableWindow(
button[ibutton].hwnd,
button[ibutton].enabled);
2890 if (!SetROP2(hGraphicsDC, R2_COPYPEN))
2898 if (!SetROP2(hGraphicsDC, R2_XORPEN))
2917 strcmp (
button[i].text, button_name) == 0) {
2928 SetWindowText(
button[bnum].hwnd, new_button_text);
2944 XSetWindowAttributes menu_attributes;
2945 unsigned long valuemask;
2950 menu_attributes.event_mask = ExposureMask;
2952 menu_attributes.do_not_propagate_mask = ButtonPressMask;
2954 menu_attributes.win_gravity = SouthWestGravity;
2955 valuemask = CWWinGravity | CWEventMask | CWDontPropagate;
2956 XChangeWindowAttributes(
display,
textarea, valuemask, &menu_attributes);
2969 if (event_ptr->type == Expose) {
2977 static void menutext(Window win,
int xc,
int yc,
const char *text)
2997 int width, height, thick, i, ispressed;
3029 mypoly[0].y = height;
3032 mypoly[2].x = width;
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;
3051 mypoly[0].y = height;
3052 mypoly[1].x = width;
3053 mypoly[1].y = height;
3054 mypoly[2].x = width;
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;
3075 width-2*thick, height-2*thick);
3090 if (
button[bnum].enabled)
3105 if (
button[i].win == win)
3108 printf(
"Error: Unknown button ID in which_button.\n");
3151 static LRESULT CALLBACK
3152 MainWND(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3154 MINMAXINFO FAR *lpMinMaxInfo;
3160 hStatusWnd = CreateWindow(szStatusName, NULL, WS_CHILDWINDOW | WS_VISIBLE,
3161 0, 0, 0, 0, hwnd, (HMENU) 102, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
3162 hButtonsWnd = CreateWindow(szButtonsName, NULL, WS_CHILDWINDOW | WS_VISIBLE,
3163 0, 0, 0, 0, hwnd, (HMENU) 103, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
3164 hGraphicsWnd = CreateWindow(szGraphicsName, NULL, WS_CHILDWINDOW | WS_VISIBLE,
3165 0, 0, 0, 0, hwnd, (HMENU) 101, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
3186 case WM_GETMINMAXINFO:
3188 lpMinMaxInfo = (MINMAXINFO FAR *) lParam;
3196 if(!DeleteObject(hGrayBrush))
3203 keypress_ptr((
char) wParam);
3207 return DefWindowProc(hwnd, message, wParam, lParam);
3211 static LRESULT CALLBACK
3212 GraphicsWND(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3214 static TEXTMETRIC tm;
3217 static RECT oldAdjustRect;
3218 static HPEN hDotPen = 0;
3219 static HBITMAP hbmBuffer = 0, hbmObjtest, hbmAllObjtest;
3227 hCurrentDC = hGraphicsDC = hForegroundDC = GetDC (hwnd);
3231 hBackgroundDC = CreateCompatibleDC(hForegroundDC);
3234 if (!SetMapMode(hBackgroundDC, MM_TEXT))
3239 if (!SelectObject(hBackgroundDC, hbmBuffer))
3243 hObjtestDC = CreateCompatibleDC(hForegroundDC);
3246 if (!SetMapMode(hObjtestDC, MM_TEXT))
3251 if (!SelectObject(hObjtestDC, hbmObjtest))
3255 hAllObjtestDC = CreateCompatibleDC(hForegroundDC);
3258 if (!SetMapMode(hAllObjtestDC, MM_TEXT))
3261 if (!(hbmAllObjtest))
3263 if (!SelectObject(hAllObjtestDC, hbmAllObjtest))
3268 if(!SetBkMode(hGraphicsDC, TRANSPARENT))
3289 invalidate_screen();
3292 hCurrentDC = hGraphicsDC;
3294 BeginPaint(hwnd, &ps);
3299 if(!GetUpdateRect(hwnd, &updateRect,
FALSE)) {
3300 updateRect.left = 0;
3306 if(windowAdjustFlag > 1) {
3310 if (!SetROP2(hGraphicsDC, R2_XORPEN))
3312 if(!SelectObject(hGraphicsDC, GetStockObject(NULL_BRUSH)))
3314 if(!SelectObject(hGraphicsDC, hDotPen))
3316 if(!Rectangle(hGraphicsDC, oldAdjustRect.left, oldAdjustRect.top,
3317 oldAdjustRect.right, oldAdjustRect.bottom))
3319 if(!Rectangle(hGraphicsDC, adjustRect.left, adjustRect.top, adjustRect.right,
3322 oldAdjustRect = adjustRect;
3323 if (!SetROP2(hGraphicsDC, R2_COPYPEN))
3325 if(!SelectObject(hGraphicsDC, GetStockObject(NULL_PEN)))
3327 if(!DeleteObject(hDotPen))
3333 EndPaint(hwnd, &ps);
3334 hGraphicsDC = hCurrentDC;
3342 cxClient = LOWORD (lParam);
3343 cyClient = HIWORD (lParam);
3349 if(!DeleteObject(hGraphicsPen))
3351 if(!DeleteObject(hGraphicsBrush))
3353 if(!DeleteObject(hGraphicsFont))
3355 if (!DeleteObject(hbmBuffer))
3357 if (!DeleteObject(hbmObjtest))
3359 if (!DeleteObject(hbmAllObjtest))
3361 if(!DeleteDC(hBackgroundDC))
3363 if(!DeleteDC(hObjtestDC))
3365 if(!DeleteDC(hAllObjtestDC))
3367 if(!ReleaseDC(hwnd, hForegroundDC))
3372 case WM_LBUTTONDOWN:
3373 if (!windowAdjustFlag) {
3380 if(windowAdjustFlag == 1) {
3381 windowAdjustFlag ++;
3382 X = adjustRect.left = adjustRect.right = LOWORD(lParam);
3383 Y = adjustRect.top = adjustRect.bottom = HIWORD(lParam);
3384 oldAdjustRect = adjustRect;
3388 int adjustx[2], adjusty[2];
3390 windowAdjustFlag = 0;
3392 SendMessage(
button[adjustButton].hwnd, BM_SETSTATE, 0, 0);
3400 adjustx[0] = adjustRect.left;
3401 adjustx[1] = adjustRect.right;
3402 adjusty[0] = adjustRect.top;
3403 adjusty[1] = adjustRect.bottom;
3405 update_win(adjustx, adjusty, invalidate_screen);
3411 case WM_RBUTTONDOWN:
3412 if (!windowAdjustFlag) {
3418 SendMessage(
button[i].hwnd, BM_SETSTATE,
button[i].ispressed, 0);
3421 windowAdjustFlag = 2;
3422 X = adjustRect.left = adjustRect.right = LOWORD(lParam);
3423 Y = adjustRect.top = adjustRect.bottom = HIWORD(lParam);
3424 oldAdjustRect = adjustRect;
3428 int adjustx[2], adjusty[2];
3430 windowAdjustFlag = 0;
3432 SendMessage(
button[adjustButton].hwnd, BM_SETSTATE, 0, 0);
3440 adjustx[0] = adjustRect.left;
3441 adjustx[1] = adjustRect.right;
3442 adjusty[0] = adjustRect.top;
3443 adjusty[1] = adjustRect.bottom;
3445 update_win(adjustx, adjusty, invalidate_screen);
3450 if(windowAdjustFlag == 1) {
3453 else if (windowAdjustFlag >= 2) {
3454 if ( X > LOWORD(lParam)) {
3455 adjustRect.left = LOWORD(lParam);
3456 adjustRect.right = X;
3459 adjustRect.left = X;
3460 adjustRect.right = LOWORD(lParam);
3462 if ( Y > HIWORD(lParam)) {
3463 adjustRect.top = HIWORD(lParam);
3464 adjustRect.bottom = Y;
3468 adjustRect.bottom = HIWORD(lParam);
3470 if(!InvalidateRect(hGraphicsWnd, &oldAdjustRect,
FALSE))
3472 if(!InvalidateRect(hGraphicsWnd, &adjustRect,
FALSE))
3474 if(!UpdateWindow(hGraphicsWnd))
3485 return DefWindowProc(hwnd, message, wParam, lParam);
3489 static LRESULT CALLBACK
3490 StatusWND(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3502 if(!SetBkMode(hdc, TRANSPARENT))
3504 if(!ReleaseDC(hwnd, hdc))
3509 hdc = BeginPaint(hwnd, &ps);
3513 if(!GetClientRect(hwnd, &rect))
3516 if(!SelectObject(hdc, GetStockObject(NULL_BRUSH)))
3518 if(!SelectObject(hdc, GetStockObject(WHITE_PEN)))
3520 if(!Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom))
3522 if(!SelectObject(hdc, GetStockObject(BLACK_PEN)))
3524 if(!MoveToEx(hdc, rect.left, rect.bottom-1, NULL))
3526 if(!LineTo(hdc, rect.right-1, rect.bottom-1))
3528 if(!LineTo(hdc, rect.right-1, rect.top))
3531 if(!DrawText(hdc, TEXT(
statusMessage), -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE))
3534 if(!EndPaint(hwnd, &ps))
3546 return DefWindowProc(hwnd, message, wParam, lParam);
3550 static LRESULT CALLBACK
3551 ButtonsWND(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3556 static HBRUSH hBrush;
3562 if (!windowAdjustFlag) {
3563 button[LOWORD(wParam) - 200].
fcn(invalidate_screen);
3564 if (windowAdjustFlag) {
3565 adjustButton = LOWORD(wParam) - 200;
3569 SendMessage(
button[i].hwnd, BM_SETSTATE,
button[i].ispressed, 0);
3580 hBrush = CreateSolidBrush(win32_colors[
LIGHTGREY]);
3583 if(!SelectObject(hdc, hBrush))
3585 if(!SetBkMode(hdc, TRANSPARENT))
3587 if(!ReleaseDC(hwnd, hdc))
3593 hdc = BeginPaint(hwnd, &ps);
3597 if(!GetClientRect(hwnd, &rect))
3600 if(!SelectObject(hdc, GetStockObject(NULL_BRUSH)))
3602 if(!SelectObject(hdc, GetStockObject(WHITE_PEN)))
3604 if(!Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom))
3606 if(!SelectObject(hdc, GetStockObject(BLACK_PEN)))
3608 if(!MoveToEx(hdc, rect.left, rect.bottom-1, NULL))
3610 if(!LineTo(hdc, rect.right-1, rect.bottom-1))
3612 if(!LineTo(hdc, rect.right-1, rect.top))
3623 if(!MoveToEx (hdc, x, y, NULL))
3625 if(!LineTo (hdc, x + w, y))
3627 if(!SelectObject(hdc, GetStockObject(WHITE_PEN)))
3629 if(!MoveToEx (hdc, x, y+1, NULL))
3631 if(!LineTo (hdc, x + w, y+1))
3633 if(!SelectObject(hdc, GetStockObject(BLACK_PEN)))
3637 if(!EndPaint(hwnd, &ps))
3644 if(!DeleteObject(hBrush))
3650 return DefWindowProc(hwnd, message, wParam, lParam);
3654 void reset_win32_state () {
3672 windowAdjustFlag = 0;
3674 InEventLoop =
FALSE;
3678 void win32_drain_message_queue () {
3682 while (PeekMessage(&msg, hMainWnd, 0, 0, PM_REMOVE)) {
3683 if (msg.message == WM_QUIT) {
3684 printf (
"Got the quit message.\n");
3690 void drawtobuffer(
void) {
3691 hGraphicsDC = hBackgroundDC;
3695 void drawtoscreen(
void) {
3696 hGraphicsDC = hForegroundDC;
3700 void displaybuffer(
void) {
3708 static void _drawcurve(
t_point *points,
int npoints,
int fill) {
3715 float xmin, ymin, xmax, ymax;
3718 if ((npoints - 1) % 3 != 0 || npoints >
MAXPTS)
3724 xmin = xmax = points[0].
x;
3725 ymin = ymax = points[0].
y;
3727 for (i=1;i<npoints;i++) {
3728 xmin =
min (xmin,points[i].x);
3729 xmax =
max (xmax,points[i].x);
3730 ymin =
min (ymin,points[i].y);
3731 ymax =
max (ymax,points[i].y);
3745 for (i = 0; i < npoints; i++) {
3746 pts[i].x =
xcoord(points[i].x);
3747 pts[i].y =
ycoord(points[i].y);
3751 hOldPen = (HPEN)SelectObject(hGraphicsDC, hGraphicsPen);
3756 hOldPen = (HPEN)SelectObject(hGraphicsDC, GetStockObject(NULL_PEN));
3759 hOldBrush = (HBRUSH)SelectObject(hGraphicsDC, hGraphicsBrush);
3764 if (!BeginPath(hGraphicsDC))
3766 if(!PolyBezier(hGraphicsDC, pts, npoints))
3768 if (!EndPath(hGraphicsDC))
3772 if (!StrokePath(hGraphicsDC))
3776 if (!FillPath(hGraphicsDC))
3780 if(!SelectObject(hGraphicsDC, hOldPen))
3784 if(!SelectObject(hGraphicsDC, hOldBrush))
3792 fprintf(ps,
"newpath\n");
3793 fprintf(ps,
"%.2f %.2f moveto\n",
XPOST(points[0].x),
YPOST(points[0].y));
3794 for (i = 1; i < npoints; i+= 3)
3795 fprintf(ps,
"%.2f %.2f %.2f %.2f %.2f %.2f curveto\n",
XPOST(points[i].x),
YPOST(points[i].y),
3798 fprintf(ps,
"stroke\n");
3800 fprintf(ps,
"fill\n");
3805 void drawcurve(
t_point *points,
3807 _drawcurve(points, npoints, 0);
3811 void fillcurve(
t_point *points,
3813 _drawcurve(points, npoints, 1);
3817 void object_start(
int all) {
3819 hGraphicsDC = hAllObjtestDC;
3821 hGraphicsDC = hObjtestDC;
3829 hGraphicsDC = hCurrentDC;
3834 int pt_on_object(
int all,
float x,
float y) {
3844 return c == win32_colors[
BLACK];
3847 static int check_fontsize(
int pointsize,
3852 TEXTMETRIC textmetric;
3858 hOldFont = (HFONT)SelectObject(hGraphicsDC, hGraphicsFont);
3862 if (!GetTextMetrics(hGraphicsDC, &textmetric))
3864 height = (textmetric.tmAscent + 2 * textmetric.tmDescent) /
ymult;
3866 if (height >= ymax * 0.9) {
3875 if(!SelectObject(hGraphicsDC, hOldFont))
3881 int findfontsize(
float ymax) {
3888 while (bot <= top) {
3891 check = check_fontsize(mid, ymax);
3915 void event_loop (
void (*act_on_mousebutton) (
float x,
float y),
3916 void (*act_on_mousemove) (
float x,
float y),
3917 void (*act_on_keypress) (
char key_pressed),
3920 void init_graphics (
const char *window_name,
int cindex) { }
3924 void init_world (
float xl,
float yt,
float xr,
float yb) { }
3931 void drawline (
float x1,
float y1,
float x2,
float y2) { }
3932 void drawrect (
float x1,
float y1,
float x2,
float y2) { }
3933 void fillrect (
float x1,
float y1,
float x2,
float y2) { }
3935 void drawarc (
float xcen,
float ycen,
float rad,
float startang,
3936 float angextent) { }
3937 void drawellipticarc (
float xc,
float yc,
float radx,
float rady,
float startang,
float angextent) { }
3939 void fillarc (
float xcen,
float ycen,
float rad,
float startang,
3940 float angextent) { }
3941 void fillellipticarc (
float xc,
float yc,
float radx,
float rady,
float startang,
float angextent) { }
3943 void drawtext (
float xc,
float yc,
const char *text,
float boundx) { }
3946 void create_button (
const char *prev_button_text ,
const char *button_text,
3947 void (*button_func) (
void (*
drawscreen) (
void))) { }
3970 void drawtobuffer(
void) { }
3972 void drawtoscreen(
void) { }
3974 void displaybuffer(
void) { }
3976 void drawcurve(
t_point *points,
int npoints) { }
3978 void fillcurve(
t_point *points,
int npoints) { }
3980 void object_start(
int all) { }
3982 void object_end() { }
3984 int pt_on_object(
float x,
float y) { }
3986 int findfontsize(
float ymax) { }
3989 #endif // WIN32 (subset of commands)
3991 #endif // NO_GRAPHICS
static t_gl_state gl_state
static Bool test_if_exposed(Display *disp, XEvent *event_ptr, XPointer dummy)
static XFontStruct * font_info[MAX_FONT_SIZE+1]
static void reset_common_state()
void init_world(float x1, float y1, float x2, float y2)
static void update_win(int x[2], int y[2], void(*drawscreen)(void))
void close_graphics(void)
void fillpoly(t_point *points, int npoints)
static void zoom_out(void(*drawscreen)(void))
static void translate_up(void(*drawscreen)(void))
static const char * ps_cnames[NUM_COLOR]
static const int menu_font_size
static char statusMessage[BUFSIZE]
static void proceed(void(*drawscreen)(void))
void drawrect(float x1, float y1, float x2, float y2)
static void update_transform(void)
static int display_height
static void force_setcolor(int cindex)
static void postscript(void(*drawscreen)(void))
static bool get_mouse_move_input
void report_structure(t_report *report)
static int ycoord(float worldy)
void destroy_button(const char *button_text)
static bool get_keypress_input
static int currentlinewidth
static void load_font(int pointsize)
static void unmap_button(int bnum)
static int currentfontsize
void drawline(float x1, float y1, float x2, float y2)
static void force_setfontsize(int pointsize)
static void drawscreen(void)
void enable_or_disable_button(int ibutton, bool enabled)
void create_button(const char *prev_button_text, const char *button_text, void(*button_func)(void(*drawscreen)(void)))
void set_keypress_input(bool enable)
void drawtext(float xc, float yc, const char *text, float boundx)
void init_graphics(const char *window_name, int cindex)
static int which_button(Window win)
void fillellipticarc(float xc, float yc, float radx, float rady, float startang, float angextent)
static Colormap private_cmap
void fillrect(float x1, float y1, float x2, float y2)
static void drawbut(int bnum)
static void * my_malloc(int ibytes)
static void drawmenu(void)
static int ProceedPressed
static void adjustwin(void(*drawscreen)(void))
void setfontsize(int pointsize)
int init_postscript(const char *fname)
static void force_setlinewidth(int linewidth)
static void quit(void(*drawscreen)(void))
void drawarc(float xc, float yc, float rad, float startang, float angextent)
void setlinewidth(int linewidth)
static int rect_off_screen(float x1, float y1, float x2, float y2)
static void translate_right(void(*drawscreen)(void))
static void build_textarea(void)
void fillarc(float xc, float yc, float rad, float startang, float angextent)
static void menutext(Window win, int xc, int yc, const char *text)
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))
static void map_button(int bnum)
static void turn_on_off(int pressed)
static float angnorm(float ang)
static int currentlinestyle
static void zoom_fit(void(*drawscreen)(void))
void setlinestyle(int linestyle)
static void * my_realloc(void *memblk, int ibytes)
void change_button_text(const char *button_name, const char *new_button_text)
static void translate_down(void(*drawscreen)(void))
static float saved_xright
static void force_setlinestyle(int linestyle)
static void setpoly(int bnum, int xc, int yc, int r, float theta)
static int colors[NUM_COLOR]
static void translate_left(void(*drawscreen)(void))
void set_draw_mode(enum e_draw_mode draw_mode)
void update_message(const char *msg)
static void zoom_in(void(*drawscreen)(void))
void drawellipticarc(float xc, float yc, float radx, float rady, float startang, float angextent)
static void build_default_menu(void)
void set_mouse_move_input(bool enable)
static int xcoord(float worldx)
static bool font_is_loaded[MAX_FONT_SIZE+1]
static void update_ps_transform(void)
void setcolor(int cindex)
void close_postscript(void)
static e_draw_mode current_draw_mode