aboutsummaryrefslogtreecommitdiff
path: root/plotlib/win32
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2009-05-11 00:27:49 +0000
committerDimitri Sokolyuk <demon@dim13.org>2009-05-11 00:27:49 +0000
commit0d4f43d355de79178b1142e9735902cf641670b6 (patch)
tree2ced2323f6351db2a51090b3fd13eb11f69ff53f /plotlib/win32
Xfoil 6.97
Diffstat (limited to 'plotlib/win32')
-rw-r--r--plotlib/win32/Makefile.NT169
-rw-r--r--plotlib/win32/Readme-win3216
-rw-r--r--plotlib/win32/W32win.c1709
-rw-r--r--plotlib/win32/Xdefs.h60
-rw-r--r--plotlib/win32/rgbtbl.h765
5 files changed, 2719 insertions, 0 deletions
diff --git a/plotlib/win32/Makefile.NT b/plotlib/win32/Makefile.NT
new file mode 100644
index 0000000..15f1941
--- /dev/null
+++ b/plotlib/win32/Makefile.NT
@@ -0,0 +1,169 @@
+#***********************************************************************
+# Module: Makefile
+#
+# Copyright (C) 1996 Harold Youngren, Mark Drela
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public
+# License along with this library; if not, write to the Free
+# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+# Report problems to: guppy@maine.com
+# or drela@orville.mit.edu
+#***********************************************************************
+
+
+
+#################################
+# makefile for Xplot11 library #
+#################################
+
+#point to your install directory
+INSTALLDIR= .
+DIR= ..
+
+#Library tool
+AR = lib
+
+### Use these to set library name
+### (add DP to keep double precision version separate)
+PLTLIB = libPlt.lib
+#PLTLIB = libPltDP.lib
+
+###========================ggggg===========================
+### Basic plot library object files
+OBJ = plt_base.obj plt_font.obj plt_util.obj \
+ plt_color.obj set_subs.obj gw_subs.obj \
+ ps_subs.obj W32win.obj
+OBJMISC =
+OBJ3D =
+OBJOLD =
+###
+###--------------------------------------------------------
+### Uncomment to add the old plot compatibility routines
+OBJOLD = plt_old.obj
+###
+###--------------------------------------------------------
+### Uncomment to add the 3D-view routines
+OBJ3D = plt_3D.obj
+###
+###--------------------------------------------------------
+### Uncomment for f77 compiler w/o AND() and RSHIFT/LSHIFT functions.
+### This adds some functions to duplicate these using IAND and ISHFT
+### which often appear in these offending fortran's libraries.
+### The compilers that this has affected include:
+### HPUX f77
+### Absoft f77 on Linux
+###
+#OBJMISC = util-ops.obj
+
+
+###================================================
+### Compaq Visual Fortran compiler and flags, install commands
+#FC = f77
+#CC = cl
+### Defines for C interface
+#DEFINE = -DUNDERSCORE -D_CVF
+### Uncomment DP to make double-precision version
+#DP = /realsize:64
+#FFLAGS = /Oxp $(DP) /threads
+#FLGOPT = /Oxp $(DP) /threads
+#CFLAGS = $(DEFINE) -MT
+#LFLAGS = /libs:qwin /threads /link /NODEFAULTLIB:LIBC.LIB
+
+###================================================
+### Intel Fortran compiler and flags, install commands
+FC = ifl
+CC = cl
+### Defines for C interface
+#DEFINE = -DUNDERSCORE
+# Uncomment DP to make double-precision version
+#DP = /4R8
+### use flags for processor optimization G5 G6 G7 for PII,PIII,P4
+#FFLAGS = /Od /Zi $(DP) /W0 /MT
+FFLAGS = /I.. /O2 $(DP) /W0 /MT /4Yportlib
+FLGOPT = /I.. /O3 $(DP) /W0 /MT /4Yportlib
+CFLAGS = $(DEFINE) -MT
+LFLAGS = /4Yportlib /MT /link /NODEFAULTLIB:LIBC.LIB
+
+###================================================
+
+
+
+###-------------------------------------------------------------------------
+### Basic make targets - build library, test programs
+
+$(PLTLIB): $(OBJ) $(OBJOLD) $(OBJ3D) $(OBJMISC)
+ $(AR) /out:$(PLTLIB) $(OBJ) $(OBJOLD) $(OBJ3D) $(OBJMISC)
+ copy $(PLTLIB) ..
+
+test: $(PLTLIB)
+ (cd examples; make test)
+
+
+###-------------------------------------------------------------------------
+### Utility functions - install the library, clean the directory
+
+install: $(PLTLIB)
+ mv $(PLTLIB) $(INSTALLDIR)
+
+clean:
+ del *.obj
+ del $(PLTLIB)
+ del plot*.ps
+ (cd examples; make clean)
+
+
+
+###-------------------------------------------------------------------------
+### compile plot package routines
+
+plt_base.obj: $(DIR)\plt_base.f $(DIR)\pltlib.inc
+ $(FC) /c $(FFLAGS) $(DIR)\plt_base.f
+
+plt_color.obj: $(DIR)\plt_color.f $(DIR)\pltlib.inc
+ $(FC) /c $(FFLAGS) $(DIR)\plt_color.f
+
+plt_font.obj: $(DIR)\plt_font.f $(DIR)\CHAR.INC $(DIR)\SLAN.INC $(DIR)\MATH.INC $(DIR)\SYMB.INC
+ $(FC) /c $(FFLAGS) $(DIR)\plt_font.f
+
+plt_util.obj: $(DIR)\plt_util.f
+ $(FC) /c $(FFLAGS) $(DIR)\plt_util.f
+
+plt_3D.obj: $(DIR)\plt_3D.f
+ $(FC) /c $(FFLAGS) $(DIR)\plt_3D.f
+
+plt_old.obj: $(DIR)\plt_old.f $(DIR)\pltlib.inc
+ $(FC) /c $(FFLAGS) $(DIR)\plt_old.f
+
+set_subs.obj: $(DIR)\set_subs.f $(DIR)\pltlib.inc
+ $(FC) /c $(FFLAGS) $(DIR)\set_subs.f
+
+gw_subs.obj: $(DIR)\gw_subs.f $(DIR)\pltlib.inc
+ $(FC) /c $(FFLAGS) $(DIR)\gw_subs.f
+
+ps_subs.obj: $(DIR)\ps_subs.f $(DIR)\pltlib.inc
+ $(FC) /c $(FFLAGS) $(DIR)\ps_subs.f
+
+util-ops.obj: $(DIR)\util-ops.f
+ $(FC) /c $(FFLAGS) $(DIR)\util-ops.f
+
+W32win.obj: W32win.c
+ $(CC) /c $(CFLAGS) W32win.c
+
+
+### May need to specify these on a brain-dead make system
+#.f.obj: $(FC) /c $(FFLAGS) $<
+#.c.obj: $(CC) /c $(CFLAGS) $<
+
+
+
diff --git a/plotlib/win32/Readme-win32 b/plotlib/win32/Readme-win32
new file mode 100644
index 0000000..c3fb339
--- /dev/null
+++ b/plotlib/win32/Readme-win32
@@ -0,0 +1,16 @@
+
+Make the plotlib under Windoze:
+
+ You need Visual C and either the Compaq Visual Fortran compiler or the Intel
+ Fortran compiler. You should check the options in Makefile.NT to ensure that
+ they match your system. The supplied files match the Intel Fortran compiler.
+
+ Compile and link with command in DOS window:
+ C:\Xfoil\plotlib: cd win32
+ C:\Xfoil\plotlib\win32: nmake /f Makefile.NT
+
+ This places all the .obj files in the win32 directory and copies libPltxx.lib
+ to the parent plotlib directory.
+
+ Alternatively you could load all the files into a Visual Studio project and
+ create the library that way.
diff --git a/plotlib/win32/W32win.c b/plotlib/win32/W32win.c
new file mode 100644
index 0000000..c3982d6
--- /dev/null
+++ b/plotlib/win32/W32win.c
@@ -0,0 +1,1709 @@
+/***********************************************************************
+ W32win.c - FORTRAN/C interface for Windows NT/95 Xplot11
+
+ Copyright (C) 1999 Harold Youngren, Mark Drela
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ Report problems to: guppy@maine.rr.com
+ or drela@henry.mit.edu
+***********************************************************************/
+
+/***********************************************************************
+* Xplot11 C-level Win32 interface
+C Version 4.43 3/5/99
+*
+* Status: This code is still pretty rough, it works but there are some
+* rough edges (some of which result from problems with the Win32
+* API). This is the interface code to create, draw to, refresh,
+* destroy a graphics window on a Win32 machine running a Fortran
+* application (like XFOIL) making Pltlib calls.
+*
+* The refresh problem for Win32 (as the Xwindows option for a
+* automatic refresh using the server's backing store startup
+* option is not available under Win32) is dealt with by creating
+* a plot thread that monitors the Windoze events and does window
+* refresh. This is done by doing plotting to a memory bitmap and
+* writing the bitmap to the screen whenever the window needs
+* refresh.
+*
+* Note that several problems arise in supporting the Xwindows
+* plotting functionality under Win32. Colors are handled differently
+* than under Xwindows, for color name compatibility I have included
+* a color table lookup routine that maps Xwindows color names into
+* RGB values. A more serious problem is the inconsistency of the
+* Win32 API itself, specifically the functionality varies with the
+* version of the Microsoft OS you are running. The most serious
+* problem showed up in drawing lines with arbitrary patterns and
+* widths. The Win32 API apparently does not support drawing these
+* types of lines (used in Pltlib for background grids, among other
+* things) satisfactorily. There appears to be no way to draw a line
+* with an arbitrary pattern and width. Also it appears that drawing
+* patterned lines with transparent background color is not supported.
+*
+* Harold Youngren 10/01
+***********************************************************************/
+
+
+/***********************************************************************
+* Defines graphics primitives for window management and line drawing
+* Primitives include:
+* gwxrevflag - checks environment variables for background color
+* gwxopen - initializes X display and returns size and depth of display
+* gwxwinopen - opens X plotting window with specified x,y size and position
+* gwxclear - clears plotting window
+* gwxstatus - gets current window size and location
+* gwxresize - resizes current window to specified size
+
+* gwxreset - resets plotting defaults for window
+* gwxclose - closes plotting to X display
+* gwxflush - flushes out graphics primitives in buffers
+* gwxline - plots line segment
+
+* gwxdash - sets line pattern from integer mask
+* gwxcurs - gets graphics cursor position and key pressed
+* gwxpen - sets line width in pixels
+*
+* More advanced routines beyond the original PLOT-10 requirements
+* gwxdestroy - closes plot window
+* gwxlinez - plots polyline
+* gwxpoly - plots filled polygon
+* gwxstring - plots string
+*
+* Color routines
+* gwxsetcolor - sets foreground color from color map
+* gwxsetbgcolor - sets background color from color map
+* gwxcolorname2rgb - find color components of color specified by name string
+* gwxallocrgbcolor - allocate a color specified by r,g,b components
+* gwxfreecolor - frees an allocated color from colormap
+*
+* Utility routines
+* mskbits - converts integer mask into dot/dash array
+*
+* Double-buffer routines
+* gwxdisplaybuffer - switches background buffer with foreground window
+* gwxdrawtobuffer - sets drawing to background buffer
+* gwxdrawtowindow - sets drawing to foreground window
+************************************************************************/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <windows.h>
+#include <process.h>
+
+#include "rgbtbl.h"
+#include "Xdefs.h"
+
+typedef struct {
+ HWND window;
+ HPEN pen;
+ HBRUSH fgbrush;
+ HBRUSH bgbrush;
+ int fg;
+ int bg;
+ int font;
+ int fun;
+} GC;
+
+typedef struct {
+ int ic;
+ int rgb;
+ HPEN pen;
+ HBRUSH brush;
+} COLTBL;
+
+typedef struct Event {
+ HWND window;
+ int type;
+ int x;
+ int y;
+ int state;
+ struct Event *next;
+} Event;
+
+
+/* Calling convention, Intel Fortran is simple, call is same as Unix
+ CVF requires Microsoft call */
+#ifdef _CVF
+#define W32CALL __stdcall
+#else
+#define W32CALL
+#endif
+
+
+/* Maximum number of polyline points per polyline call,
+ increase if necessary */
+#define MAXPTS 1000
+
+/* Maximum number of colors */
+#define MAXCOLS 256
+
+static char *gwxClass = "PltLib";
+static char *gwxName = "PltLib";
+
+/*
+BYTE ANDMask[128], ORNMask[128], ORWMask[128];
+static BYTE ANDMsk16[] = { 0xfe, 0x00,
+ 0xfe, 0x00,
+ 0xfe, 0x00,
+ 0xff, 0x80,
+ 0xff, 0x80,
+ 0xff, 0x00,
+ 0xfe, 0x00,
+ 0xfc, 0x18,
+ 0xf8, 0x38,
+ 0xf0, 0x7f,
+ 0xe0, 0xff,
+ 0xc1, 0xff,
+ 0x83, 0xff,
+ 0x07, 0xff,
+ 0x0f, 0xff,
+ 0x1f, 0xff };
+ static BYTE ORNMsk16[] = { 0x00, 0x00,
+ 0x00, 0xfe,
+ 0x00, 0x7e,
+ 0x00, 0x3e,
+ 0x00, 0x3e,
+ 0x00, 0x7e,
+ 0x00, 0xe6,
+ 0x01, 0xc2,
+ 0x03, 0x80,
+ 0x07, 0x00,
+ 0x0e, 0x00,
+ 0x1c, 0x00,
+ 0x38, 0x00,
+ 0x70, 0x00,
+ 0x60, 0x00,
+ 0x00, 0x00 };
+ static BYTE ORWMsk16[] = { 0x01, 0xff,
+ 0x01, 0x01,
+ 0x01, 0x01,
+ 0x00, 0x41,
+ 0x00, 0x41,
+ 0x00, 0x81,
+ 0x01, 0x19,
+ 0x02, 0x25,
+ 0x04, 0x47,
+ 0x08, 0x80,
+ 0x11, 0x00,
+ 0x22, 0x00,
+ 0x44, 0x00,
+ 0x88, 0x00,
+ 0x90, 0x00,
+ 0xe0, 0x00 };
+*/
+
+/* Window and graphics global data */
+HWND gwxWin;
+HDC gwxHDC, gwxmemHDC;
+HBITMAP gwxBMAP;
+HCURSOR gwxNormalC, gwxWaitC, gwxCurrentC;
+
+GC *gwxGC;
+
+COLTBL RGBmap[MAXCOLS];
+int nRGBmap;
+
+/* int xcsize,ycsize; */
+int wxstart,wystart,wxsize,wysize;
+int xrootsize, yrootsize, rootdepth;
+int gwxSize[5];
+int gwxXmatte, gwxYmatte, gwxYbar;
+int reversevideo;
+int initthread;
+int penwidth, penpattern, ndash, pendash[16];
+
+HINSTANCE gwxInstance;
+ATOM gwxRegister;
+WNDCLASSEX gwxWndClass;
+MSG Message;
+
+Event *gwxEvents, *gwxLEvent, gwxLast;
+
+/*static PARAMS params;*/
+
+void MSKBITS(int*,int*,int*);
+int gwxlookupcolor (char*,int*);
+
+
+
+/**********************************************************************/
+/************************Internal Event Code***************************/
+
+/*These routines simulate the Xwindows XEvents to do user interaction.
+ This is done here by collecting a list of relevant events from Windoze
+ and managing these for the user who deals only with the simulated XEvents.
+ This is probably a grungy hack (it was copied from Bob Haimes Visual3 and
+ pV3 ports to Win32) but it works. It may be better to get rid of the
+ extra event layer and deal directly with Win32 events.
+ HHY */
+
+void
+gwxAddEvent(int type, int x, int y, int state)
+{
+ Event *event;
+
+ event = (Event *) malloc(sizeof(Event));
+ if (event == NULL) return;
+
+ event->window = gwxWin;
+ event->type = type;
+ event->x = x;
+ event->y = y;
+ event->state = state;
+ event->next = NULL;
+
+ if (gwxLEvent != NULL) gwxLEvent->next = event;
+ gwxLEvent = event;
+ if (gwxEvents == NULL) gwxEvents = event;
+ gwxLast = *event;
+}
+
+void
+gwxRemEvent(int *type, int *x, int *y, int *state)
+{
+ Event *event;
+
+ if (gwxEvents == NULL) {
+ printf("Warning: No Events to remove!\n");
+ return;
+ }
+
+ event = gwxEvents;
+ if (event == gwxLEvent) gwxLEvent = NULL;
+ gwxEvents = event->next;
+
+ *type = event->type;
+ *x = event->x;
+ *y = event->y;
+ *state = event->state;
+ free(event);
+}
+
+/**********************************************************************/
+/**********************************************************************/
+
+
+
+LRESULT CALLBACK
+gwxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ int i, ix, iy;
+ PAINTSTRUCT paint;
+ HDC hdc;
+ POINT point;
+ RECT rect;
+
+ switch (message) {
+
+ case WM_USER:
+ return 0;
+
+ case WM_SIZE:
+ if (hWnd == gwxWin) {
+ if (gwxSize[4]) {
+ ix = LOWORD(lParam);
+ iy = HIWORD(lParam);
+ if ((ix != gwxSize[0]) || (iy != gwxSize[1])) {
+ gwxSize[0] = ix;
+ gwxSize[1] = iy;
+ gwxAddEvent(XExpose, ix, iy, 1);
+ }
+ } else {
+ ix = gwxSize[0] + 2*gwxXmatte;
+ iy = gwxSize[1] + 2*gwxYmatte + gwxYbar;
+ SetWindowPos(hWnd, HWND_TOP, gwxSize[2], gwxSize[3],
+ ix, iy, SWP_NOMOVE|SWP_NOZORDER);
+ }
+ return 0;
+ }
+ return 0;
+
+ case WM_MOVE:
+ if (hWnd == gwxWin) {
+ gwxSize[2] = LOWORD(lParam);
+ gwxSize[3] = HIWORD(lParam);
+ return 0;
+ }
+ return 0;
+
+ case WM_PAINT:
+ /* printf("WM_PAINT\n"); */
+ /*
+ * Validate the region even if there are no DisplayFunc.
+ * Otherwise, USER will not stop sending WM_PAINT messages.
+ */
+ hdc = BeginPaint(hWnd, &paint);
+ BitBlt(hdc,0,0,xrootsize,yrootsize,gwxmemHDC,0,0,SRCCOPY);
+ EndPaint(hWnd, &paint);
+ if (hWnd == gwxWin) {
+ gwxAddEvent(XExpose, gwxSize[0], gwxSize[1], 1);
+ return 0;
+ }
+ return 0;
+
+ case WM_PALETTECHANGED:
+ printf("WM_PALETTECHANGED\n");
+ return 0;
+
+ case WM_ACTIVATE:
+ break;
+
+ case WM_MOUSEMOVE:
+/* printf("mousemove active %d focus %d\n",GetActiveWindow(),GetFocus()); */
+ if (GetActiveWindow() != hWnd) {
+ SetForegroundWindow(hWnd);
+ SetActiveWindow(hWnd);
+ }
+ if (GetFocus() != hWnd) SetFocus(hWnd);
+/* printf("mousemove %d %d\n",hWnd,gwxWin); */
+ return 0;
+
+ case WM_LBUTTONDOWN:
+ if (GetAsyncKeyState(VK_RBUTTON) < 0) {
+ gwxAddEvent(XButtonPress, LOWORD(lParam), HIWORD(lParam), 2);
+ } else {
+ gwxAddEvent(XButtonPress, LOWORD(lParam), HIWORD(lParam), 1);
+ }
+ return 0;
+
+ case WM_LBUTTONUP:
+ if (GetAsyncKeyState(VK_RBUTTON) < 0) {
+ gwxAddEvent(XButtonRelease, LOWORD(lParam), HIWORD(lParam), 2);
+ } else {
+ gwxAddEvent(XButtonRelease, LOWORD(lParam), HIWORD(lParam), 1);
+ }
+ return 0;
+
+ case WM_MBUTTONDOWN:
+ gwxAddEvent(XButtonPress, LOWORD(lParam), HIWORD(lParam), 2);
+ return 0;
+
+ case WM_MBUTTONUP:
+ gwxAddEvent(XButtonRelease, LOWORD(lParam), HIWORD(lParam), 2);
+ return 0;
+
+ case WM_RBUTTONDOWN:
+ if (GetAsyncKeyState(VK_LBUTTON) < 0) {
+ gwxAddEvent(XButtonPress, LOWORD(lParam), HIWORD(lParam), 2);
+ } else {
+ gwxAddEvent(XButtonPress, LOWORD(lParam), HIWORD(lParam), 3);
+ }
+ return 0;
+
+ case WM_RBUTTONUP:
+ if (GetAsyncKeyState(VK_LBUTTON) < 0) {
+ gwxAddEvent(XButtonRelease, LOWORD(lParam), HIWORD(lParam), 2);
+ } else {
+ gwxAddEvent(XButtonRelease, LOWORD(lParam), HIWORD(lParam), 3);
+ }
+ return 0;
+
+ case WM_KEYDOWN:
+ GetCursorPos(&point);
+ GetWindowRect(hWnd, &rect);
+ ix = point.x - rect.left - gwxXmatte;
+ iy = point.y - rect.top - gwxYmatte - gwxYbar;
+ /* gwxAddEvent(XKeyPress, ix, iy, wParam+256); */
+ return 0;
+
+ case WM_KEYUP:
+ GetCursorPos(&point);
+ GetWindowRect(hWnd, &rect);
+ ix = point.x - rect.left - gwxXmatte;
+ iy = point.y - rect.top - gwxYmatte - gwxYbar;
+ i = wParam+256;
+ /* if (i == 300) gwxAddEvent(XKeyPress, ix, iy, i);
+ gwxAddEvent(XKeyRelease, ix, iy, i); */
+ return 0;
+
+ case WM_CHAR:
+ if (wParam == 27) return 0;
+ if ((gwxLast.type != 2) || (gwxLast.state < 352) ||
+ (gwxLast.state > 361) || (gwxLast.state-wParam != 304)) {
+ GetCursorPos(&point);
+ GetWindowRect(hWnd, &rect);
+ ix = point.x - rect.left - gwxXmatte;
+ iy = point.y - rect.top - gwxYmatte - gwxYbar;
+ gwxAddEvent(XKeyPress, ix, iy, wParam);
+ } else {
+ printf("Double Hit: state = %d\n", wParam);
+ }
+ return 0;
+
+ case WM_SYSCOMMAND:
+ /* special code for F10 */
+ if ((lParam == 0) && (wParam == 61696)) {
+ GetCursorPos(&point);
+ GetWindowRect(hWnd, &rect);
+ ix = point.x - rect.left - gwxXmatte;
+ iy = point.y - rect.top - gwxYmatte - gwxYbar;
+ gwxAddEvent(XKeyPress, ix, iy, 377);
+ return 0;
+ }
+ break;
+
+ case WM_CLOSE:
+ gwxAddEvent(XKeyPress, 0, 0, 283);
+ exit;
+ return 0;
+
+ case WM_DESTROY:
+ PostQuitMessage (0) ;
+ return 0 ;
+ }
+ return DefWindowProc( hWnd, message, wParam, lParam);
+}
+
+
+int
+rgb2winrgb(int acol)
+{
+ int col, r, g, b;
+
+ col = acol & 0x00ffffff;
+ r = col >> 16;
+ g = (col >> 8) & 0xff;
+ b = col & 0xff;
+ col = b << 16 | g << 8 | r;
+ return col;
+}
+
+
+
+/* gwxrevflag
+ Get XPLOT11 background default from users environment
+ Parameters:
+ revflag (int*) reverse video flag (0 for white, 1 for black)
+*/
+void W32CALL
+GWXREVFLAG(revflag)
+ int *revflag;
+{
+ char *bufp, *tmp;
+/* check environment variable XPLOT11_BACKGROUND for background color
+ XPLOT11_BACKGROUND = white gives black on white plotting (like paper)
+ XPLOT11_BACKGROUND != white gives white on black plotting (reverse video)
+*/
+ *revflag = 1;
+ bufp = getenv("XPLOT11_BACKGROUND");
+
+/* check lowercased environment for "black" to reverse video */
+ if(bufp) {
+ for(tmp = bufp; *tmp; tmp++)
+ *tmp = tolower(*tmp);
+ *revflag = (strcmp(bufp,"white")!=0);
+ }
+}
+
+
+
+/* gwxopen
+ Open X window display and get size and depth of root window
+ Parameters:
+ xsize,ysize (int*) root window size
+ depth (int*) screen color depth (pixel depth)
+*/
+void W32CALL
+GWXOPEN(int *xsize, int *ysize, int *depth)
+{
+ int i, j, k;
+
+/* set depth arbitrarily to 8 bits to work like Xwindows colormaps */
+ rootdepth = 8;
+ xrootsize = GetSystemMetrics(SM_CXSCREEN);
+ yrootsize = GetSystemMetrics(SM_CYSCREEN);
+
+ *depth = rootdepth;
+ *xsize = xrootsize;
+ *ysize = yrootsize;
+
+ gwxXmatte = GetSystemMetrics(SM_CXFRAME);
+ gwxYmatte = GetSystemMetrics(SM_CYFRAME);
+ gwxYbar = GetSystemMetrics(SM_CYCAPTION) -
+ GetSystemMetrics(SM_CYBORDER);
+ /*
+ printf("Screen is %d x %d\n", *xsize, *ysize);
+ if (gwxXmatte == gwxYmatte) {
+ printf("Window matte is %d\n",gwxXmatte);
+ } else {
+ printf("Window matte is %d x %d\n", gwxXmatte, gwxYmatte);
+ }
+ printf("Title bar height = %d\n", gwxYbar);
+ */
+
+/* check environment variables for default background color
+ XPLOT11_BACKGROUND != black gives black on white plotting (like paper)
+ XPLOT11_BACKGROUND = black gives white on black plotting (reverse video) */
+ GWXREVFLAG(&reversevideo);
+
+/* set up cursor bitmap arrays */
+ /* xcsize = GetSystemMetrics(SM_CXCURSOR);
+ ycsize = GetSystemMetrics(SM_CYCURSOR);
+ if ((xcsize != 16) && (xcsize != 32)) {
+ printf("Unkown Xcursor Size %d\n", xcsize);
+ exit(1);
+ }
+ if ((ycsize != 16) && (ycsize != 32)) {
+ printf("Unkown Ycursor Size %d\n", ycsize);
+ exit(1);
+ }
+ for (i = 0; i < 128; i++) {
+ ANDMask[i] = 0xff;
+ ORNMask[i] = 0;
+ ORWMask[i] = 0;
+ }
+ j = 3;
+ if (xcsize == 16) j = 1;
+ for (k = i = 0; i < 16; i++) {
+ ANDMask[k] = ANDMsk16[i*2];
+ ORNMask[k] = ORNMsk16[i*2];
+ ORWMask[k] = ORWMsk16[i*2];
+ k++;
+ ANDMask[k] = ANDMsk16[i*2+1];
+ ORNMask[k] = ORNMsk16[i*2+1];
+ ORWMask[k] = ORWMsk16[i*2+1];
+ k += j;
+ }
+ */
+
+/* set cursor */
+ gwxWaitC = LoadCursor(NULL, IDC_WAIT);
+ gwxNormalC = LoadCursor(NULL, IDC_CROSS);
+/* gwxNormalC = CreateCursor( gwxInstance, 14, 1, xcsize, ycsize,
+ ANDMask, ORNMask); */
+/* gwxInputC = CreateCursor( gwxInstance, 14, 1, xcsize, ycsize,
+ ANDMask, ORWMask); */
+ gwxCurrentC = gwxNormalC;
+
+
+/* Define window class */
+ gwxInstance = GetModuleHandle(NULL);
+
+ gwxWndClass.cbSize = sizeof(gwxWndClass);
+ gwxWndClass.style = CS_HREDRAW | CS_VREDRAW;
+ gwxWndClass.lpfnWndProc = (WNDPROC)gwxWndProc;
+ gwxWndClass.cbClsExtra = 0;
+ gwxWndClass.cbWndExtra = 0;
+ gwxWndClass.hInstance = gwxInstance;
+ gwxWndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
+ gwxWndClass.hCursor = gwxNormalC;
+ if(reversevideo) {
+ gwxWndClass.hbrBackground = GetStockObject(BLACK_BRUSH); }
+ else {
+ gwxWndClass.hbrBackground = GetStockObject(WHITE_BRUSH); }
+ gwxWndClass.lpszMenuName = NULL;
+ gwxWndClass.lpszClassName = (LPCSTR)gwxClass;
+
+ /* Register the window class */
+ gwxRegister = RegisterClassEx(&gwxWndClass);
+
+ /* Check for window register, bomb if no joy... */
+ if(gwxRegister == 0) {
+ printf("Failed to register window class\n");
+ exit(1);
+ }
+
+/* initialize private Xevents loop pointers */
+ gwxEvents = NULL;
+ gwxLEvent = NULL;
+
+}
+
+
+
+
+
+GC*
+gwxgc(HWND *window, int *fontsize)
+{
+ GC *gc;
+ int r, g, b, ic;
+
+ gc = (GC *) malloc(sizeof(GC));
+
+ gc->window = *window;
+ if(reversevideo) {
+ gc->fg = RGB(255,255,255);
+ gc->bg = RGB(0 ,0 ,0 );
+ }
+ else {
+ gc->fg = RGB(0 ,0 ,0 );
+ gc->bg = RGB(255,255,255);
+ }
+ gc->pen = CreatePen(PS_SOLID, penwidth, gc->fg);
+ gc->fgbrush = CreateSolidBrush(gc->fg);
+ gc->bgbrush = CreateSolidBrush(gc->bg);
+ gc->font = *fontsize;
+ gc->fun = GXcopy; /* copy */
+
+ return gc;
+}
+
+
+void
+gwxfreegc(GC **gc)
+{
+ GC *gcontext;
+
+ gcontext = *gc;
+ DeleteObject(gcontext->pen);
+ DeleteObject(gcontext->fgbrush);
+ DeleteObject(gcontext->bgbrush);
+ free(*gc);
+}
+
+
+void
+gwxgcfun(int *fun)
+{
+ GC *gcontext;
+
+ gcontext = gwxGC;
+ gcontext->fun = *fun;
+}
+
+
+
+void
+Thread1(PVOID pvoid)
+{
+ HWND winFocus, winFG, win;
+// HWND winF77;
+ RECT WinRect ,oldrect;
+ POINT point;
+ int fontsize;
+// int lunit;
+
+ /* printf("\nEntering display thread\n"); */
+ /*
+ * Make window large enough to hold a client area compensating for borders
+ */
+ WinRect.left = wxstart;
+ WinRect.right = wxstart + wxsize + 2*gwxXmatte;
+ WinRect.top = wystart;
+ WinRect.bottom = wystart + wysize + 2*gwxYmatte + gwxYbar;
+
+ /*
+ printf("\nwxstart %d wystart %d \n",wxstart,wystart);
+ printf("\nwxsize %d wysize %d \n",wxsize,wysize);
+
+ printf("\nsetting rectangle left %d right %d \n",WinRect.left,WinRect.right);
+ printf("\nsetting rectangle top %d bot %d \n",WinRect.top,WinRect.bottom);
+ */
+
+ winFG = GetForegroundWindow();
+ winFocus = GetActiveWindow();
+ GetWindowRect(winFG, &oldrect);
+ /*
+ printf("Entry conditions:\n foreground %d/n orig focus %d\n",winFG,winFocus);
+ printf("\nold rectangle left %d right %d \n",oldrect.left,oldrect.right);
+ printf("\nold rectangle top %d bot %d \n",oldrect.top,oldrect.bottom);
+ */
+
+ /* lunit = 5;
+ winF77 = fgethwndqq(&lunit);
+ printf("\nEntry conditions DVF window: %d/n",winF77);
+ */
+
+/* Must use WS_CLIPCHILDREN and WS_CLIPSIBLINGS styles. */
+
+ gwxWin = CreateWindow( gwxClass, gwxClass,
+ WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
+ WinRect.left, WinRect.top,
+ WinRect.right - WinRect.left, WinRect.bottom - WinRect.top,
+ NULL, NULL, gwxInstance, NULL );
+
+ if (gwxWin == NULL) {
+ fprintf(stderr, "Error: NULL window handle.\n");
+ exit(1);
+ }
+
+ ShowWindow(gwxWin, SW_SHOWDEFAULT);
+ UpdateWindow(gwxWin);
+
+ gwxHDC = GetDC(gwxWin);
+ if (gwxHDC == NULL) {
+ fprintf(stderr, "Error: NULL window DC.\n");
+ exit(1);
+ }
+
+ /* Create compatible window bitmap */
+ gwxmemHDC = CreateCompatibleDC(gwxHDC);
+ gwxBMAP = CreateCompatibleBitmap(gwxHDC,xrootsize,yrootsize);
+ SelectObject(gwxmemHDC, gwxBMAP);
+
+ SelectObject(gwxmemHDC, GetStockObject(ANSI_VAR_FONT));
+ SetTextAlign(gwxmemHDC, TA_LEFT | TA_BASELINE | TA_NOUPDATECP);
+ SetBkMode(gwxmemHDC, TRANSPARENT);
+
+ gwxSize[0] = wxsize;
+ gwxSize[1] = wysize;
+ gwxSize[2] = wxstart + 2*gwxXmatte;
+ gwxSize[3] = wystart + 2*gwxYmatte + gwxYbar;
+ gwxSize[4] = 1;
+ SetWindowPos(gwxWin, HWND_TOP, gwxSize[2], gwxSize[3],
+ wxsize, wysize, SWP_NOMOVE|SWP_NOZORDER);
+
+ /* SetWindowPos(gwxWin, HWND_TOP, 0,0, 0,0, SWP_NOMOVE | SWP_NOSIZE ); */
+ SetForegroundWindow(gwxWin);
+
+
+ nRGBmap = 0;
+ penwidth = 0;
+ penpattern = -1;
+ ndash = 0;
+ fontsize = 1;
+
+ gwxGC = gwxgc(&gwxWin, &fontsize);
+ SelectObject(gwxmemHDC, gwxGC->pen);
+
+ /* initially clear the background bitmap */
+ SelectObject(gwxmemHDC, gwxGC->bgbrush);
+ PatBlt(gwxmemHDC, 0, 0, xrootsize, yrootsize, PATCOPY);
+
+ SelectObject(gwxmemHDC, gwxGC->fgbrush);
+
+ /* allocate black and white colors */
+/* r = 0;
+ g = 0;
+ b = 0;
+ GWXALLOCRGBCOLOR(&r,&g,&b,&ic);
+ r = 0;
+ g = 0;
+ b = 0;
+ GWXALLOCRGBCOLOR(&r,&g,&b,&ic);
+*/
+
+ /* printf("entering message loop\n\n"); */
+
+ initthread = 1;
+
+ /* while (GetMessage(&Message, NULL, 0, 0)) { */
+
+ /* Custom message loop to check cursor window to do X-style focus */
+
+ while (1) {
+ if(PeekMessage(&Message, gwxWin, 0, 0, PM_REMOVE)) {
+
+ if(Message.message==WM_QUIT)
+ break;
+
+ TranslateMessage(&Message);
+ DispatchMessage(&Message);
+ Sleep(1);
+ }
+ else {
+ GetCursorPos(&point);
+ win = WindowFromPoint(point);
+ /* printf("pos x %d y %d win %d\n",point.x,point.y,win); */
+
+ /* if(win==winF77) {
+ SetActiveWindow(win);
+ SetFocus(win);
+ SetForegroundWindow(win);
+ } */
+ /* if(win == winFG) {
+ printf("pos x %d y %d win %d winFG %d\n",point.x,point.y,win,winFG);
+ SetActiveWindow(winFG);
+ SetFocus(winFG);
+ SetForegroundWindow(winFG);
+ } */
+ Sleep(1);
+ }
+ }
+
+ /* printf("window thread ending\n"); */
+/* return Message.wParam;
+ exit; */
+
+ _endthread();
+}
+
+
+/* gwxwinopen
+ Open window of specified size and position, return size and depth
+ Parameters:
+ xstart,ystart (int*) upper left corner coordinates in root
+ xsize,ysize (int*) desired window size
+*/
+
+void W32CALL
+GWXWINOPEN (int *xstart, int *ystart, int *xsize, int *ysize)
+{
+ /*
+ printf("GWXOPEN\nxstart %d\nystart %d\nxsize %d\nysize %d\n",*xstart,*ystart,*xsize,*ysize);
+ */
+ wxstart = *xstart;
+ wystart = *ystart;
+ wxsize = *xsize;
+ wysize = *ysize;
+
+ /* Start the window thread */
+ initthread = 0;
+ _beginthread(Thread1,0,NULL);
+ /* printf("beginthread called\n"); */
+
+ while(!initthread) {
+ Sleep(5);
+ }
+
+
+}
+
+
+
+
+void W32CALL
+GWXDESTROY()
+{
+ ReleaseDC( gwxWin, gwxHDC );
+ ReleaseDC( gwxWin, gwxmemHDC );
+}
+
+
+void W32CALL
+GWXCLOSE()
+{
+ PostQuitMessage (0) ;
+ /* DestroyCursor(gwxNormalC);
+ DestroyCursor(gwxInputC); */
+ UnregisterClass((LPCSTR)gwxClass, gwxInstance);
+}
+
+
+void W32CALL
+GWXFLUSH()
+{
+ BitBlt(gwxHDC,0,0,xrootsize,yrootsize,gwxmemHDC,0,0,SRCCOPY);
+ /* InvalidateRect(gwxWin,NULL,1); */
+}
+
+
+/* gwxreset
+ Reset graphics context to default
+ Parameters: None
+*/
+void W32CALL
+GWXRESET()
+{
+}
+
+
+/* getPEN
+ Creates pen using type, color, width, pattern
+*/
+HPEN
+makenewpen()
+{
+ HPEN newpen;
+ LOGBRUSH lb;
+ GC *gcontext;
+
+ gcontext = gwxGC;
+
+ /* printf("makenewpen\n ndash %d\n lmask %d\n fg %d\n width %d\n",ndash,penpattern,gcontext->fg,penwidth); */
+
+ if(ndash == 0) {
+ if(penpattern == 0) {
+ /* printf("making penpattern 0\n"); */
+ newpen = CreatePen(PS_SOLID, penwidth, gcontext->bg);
+ }
+ if (penpattern == -1) {
+ /* printf("making penpattern -1\n"); */
+ newpen = CreatePen(PS_SOLID, penwidth, gcontext->fg);
+ }
+ }
+ else {
+ /* printf("making dash pen\n"); */
+ newpen = CreatePen(PS_DOT, 0, gcontext->fg);
+/*
+ lb.lbStyle = BS_SOLID;
+ lb.lbColor = gcontext->fg;
+ lb.lbHatch = 0;
+ newpen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE,
+ penwidth, &lb, ndash, pendash);
+ */
+ }
+ return newpen;
+}
+
+int
+GWXNUMEVENTS()
+{
+ int stat;
+
+ stat = 1;
+ if (gwxEvents == NULL) stat = 0;
+ return stat;
+}
+
+
+void
+GWXEVENT(int *type, int *x, int *y, int *state)
+{
+ gwxRemEvent(type, x, y, state);
+}
+
+
+int
+GWXGETEVENT(int *type, int *x, int *y, int *state)
+{
+ int stat;
+ Event *event;
+
+ stat = -1;
+ event = gwxEvents;
+ gwxLEvent = NULL;
+ while (event != NULL) {
+ if ((*type == event->type) && (stat == -1)) {
+ *x = event->x;
+ *y = event->y;
+ *state = event->state;
+ stat = 0;
+ if (gwxLEvent == NULL) {
+ gwxEvents = event->next;
+ } else {
+ gwxLEvent->next = event->next;
+ }
+ free(event);
+ event = NULL;
+ if (gwxLEvent != NULL) event = gwxLEvent->next;
+ } else {
+ gwxLEvent = event;
+ event = event->next;
+ }
+ }
+ return stat;
+}
+
+
+
+
+
+
+/* gwxstatus
+ Return current window status (position, size)
+ Parameters:
+ xstart,ystart (int*) upper left corner coordinates in root
+ xsize,ysize (int*) desired window size
+*/
+void W32CALL
+GWXSTATUS(int *xstart, int *ystart, int *xsize, int *ysize)
+
+{
+ RECT rect;
+
+ /*
+ GetClientRect(gwxWin, &rect);
+ printf("\nstatus rectangle left %d right %d \n",rect.left,rect.right);
+ printf("\n top %d bot %d \n",rect.top,rect.bottom);
+ */
+ GetWindowRect(gwxWin, &rect);
+ *xstart = rect.left;
+ *ystart = rect.top;
+ *xsize = rect.right - rect.left - 2*gwxXmatte;
+ *ysize = rect.bottom - rect.top - 2*gwxYmatte - gwxYbar;
+
+ /*
+ printf("\nstatus xstart %d ystart %d \n",*xstart,*ystart);
+ printf("\n xsize %d ysize %d \n",*xsize,*ysize);
+ printf("\nstatus rectangle left %d right %d \n",rect.left,rect.right);
+ printf("\n top %d bot %d \n",rect.top,rect.bottom);
+ */
+}
+
+
+
+/* gwxresize
+ Resize screen window to x width, y height
+ Parameters:
+ x (int*) new width
+ y (int*) new height
+*/
+void W32CALL
+GWXRESIZE(x, y)
+ int *x, *y;
+{
+ int ix, iy;
+
+ gwxSize[0] = *x;
+ gwxSize[1] = *y;
+ ix = gwxSize[0] + 2*gwxXmatte;
+ iy = gwxSize[1] + 2*gwxYmatte + gwxYbar;
+ SetWindowPos(gwxWin, HWND_TOP, gwxSize[2], gwxSize[3],
+ ix, iy, SWP_NOMOVE|SWP_NOZORDER);
+}
+
+
+/* gwxclear
+ Clear current plot window
+ Parameters: None
+*/
+void W32CALL
+GWXCLEAR()
+{
+ int i;
+ RECT WinRect;
+
+ WinRect.left = 0;
+ WinRect.right = gwxSize[0] + 2*gwxXmatte;
+ WinRect.top = 0;
+ WinRect.bottom = gwxSize[1] + 2*gwxYmatte + gwxYbar;
+ FillRect(gwxmemHDC, &WinRect, gwxGC->bgbrush);
+ return;
+}
+
+
+/* gwxdisplaybuffer
+ Switches background buffer onto foreground window, displaying accumulated
+ graphics
+ Parameters: None
+*/
+void W32CALL
+GWXDISPLAYBUFFER()
+{
+}
+
+
+/* gwxdrawtobuffer
+ Switches graphics to draw to the background buffer
+ Parameters: None
+*/
+void W32CALL
+GWXDRAWTOBUFFER()
+{
+/* printf("called gwxdrawtobuffer\n"); */
+}
+
+/* gwxdrawtowindow
+ Switches graphics to draw to the foreground window
+ Parameters: None
+*/
+void W32CALL
+GWXDRAWTOWINDOW()
+{
+/* printf("called gwxdrawtowindow\n"); */
+}
+
+
+void W32CALL
+GWXSTRING(int *x, int *y, char *text, int *length)
+{
+ int i, xs, ys;
+ GC *gcontext;
+
+ xs = *x + gwxXmatte;
+ ys = *y + gwxYmatte;
+
+ gcontext = gwxGC;
+ if (gcontext->font != 3) {
+ SelectObject(gwxmemHDC, GetStockObject(ANSI_VAR_FONT));
+ } else {
+ SelectObject(gwxmemHDC, GetStockObject(SYSTEM_FONT));
+ }
+ SetTextColor(gwxmemHDC, gcontext->fg);
+ SetBkColor (gwxmemHDC, TRANSPARENT);
+ TextOut(gwxmemHDC, xs, ys, text, *length);
+}
+
+
+/* gwxline
+ Draw line from x1,y1 to x2,y2
+ Parameters:
+ x1,y1 (int*) starting position for line
+ x2,y2 (int*) ending position for line
+*/
+void W32CALL
+GWXLINE(int *x1, int *y1, int *x2, int *y2)
+{
+ int i, xs, ys;
+
+ xs = *x1;
+ ys = *y1;
+ MoveToEx(gwxmemHDC, xs, ys, NULL);
+ xs = *x2;
+ ys = *y2;
+ LineTo(gwxmemHDC, xs, ys);
+}
+
+
+/* gwxlinez
+ Draw polyline on window in current color and pen
+ Parameters:
+ ix (int*) array of x coordinates on polyline
+ iy (int*) array of y coordinates on polyline
+ n (int*) number of coordinate points
+ (see define for MAXPTS at start of this file)
+*/
+void W32CALL
+GWXLINEZ(int *ix, int *iy, int *n)
+{
+ int i, xs, ys;
+
+ POINT points[MAXPTS];
+
+ if (*n > MAXPTS) {
+ fprintf(stderr,"Xplot11.gwxlinez: Too many points in polyline\n");
+ printf("Xplot11.gwxlinez: Too many points in polyline\n");
+ return;
+ }
+
+ for(i=0; i < *n; i++) {
+ points[i].x = ix[i];
+ points[i].y = iy[i];
+/* printf("gwxlinez x %d y %d \n",ix[i],iy[i]); */
+ }
+ Polyline(gwxmemHDC, points, *n);
+}
+
+
+/* gwxpoly
+ Draw filled polyline on window in current color and pen
+ Parameters:
+ x_coord (int*) array of x coordinates on polyline
+ y_coord (int*) array of y coordinates on polyline
+ n_coord (int*) number of coordinate points
+ (see define for MAXPTS at start of this file)
+*/
+void W32CALL
+GWXPOLY(x_coord, y_coord, n_coord)
+ int *x_coord, *y_coord, *n_coord;
+
+{ POINT points[MAXPTS];
+ int i,n;
+
+ if (*n_coord >= MAXPTS) {
+ fprintf(stderr,"Xplot11.gwxpoly: Too many points in polyline\n");
+ printf("Xplot11.gwxpoly: Too many points in polyline\n");
+ return;
+ }
+
+ for (i=0; i < *n_coord; i++) {
+ points[i].x = x_coord[i];
+ points[i].y = y_coord[i];
+
+ }
+ n = *n_coord;
+/* if the polyline is not closed, duplicate first point to ensure closed
+
+ perimeter (speeds up X graphics drastically) */
+ if ( (points[n-1].x != points[0].x) ||
+ (points[n-1].y != points[0].y) ) {
+ points[n].x = points[0].x;
+ points[n].y = points[0].y;
+ n++;
+ }
+ Polygon(gwxmemHDC, points, n);
+}
+
+
+void W32CALL
+GWXARC(int *xc, int *yc,
+ int *xr, int *yr, float *alpha, float *beta)
+{
+ int i, j, xs, ys;
+
+ /* only does circles! */
+
+ xs = *xc + *xr;
+ ys = *yc;
+ MoveToEx(gwxmemHDC, xs, ys, NULL);
+ for (j = 2; j <= 360; j += 2) {
+ xs = (int) ((double)*xc + (double)*xr*cos((double)j*0.017453292));
+ ys = (int) ((double)*yc + (double)*yr*sin((double)j*0.017453292));
+ LineTo(gwxmemHDC, xs, ys);
+ }
+}
+
+void W32CALL
+GWXCURS(int *x, int *y, int *state)
+{
+int type;
+
+/* Eat up all the current events first */
+
+ while(GWXNUMEVENTS()) {
+ GWXEVENT(&type, x, y, state);
+ /* printf("eat up event %d\n",type); */
+ }
+/* Now run an event loop until a buttonpress or keypress is found */
+
+ while(1) {
+ if(GWXNUMEVENTS()) {
+ GWXEVENT(&type, x, y, state);
+ /* printf("get event %d\n",type); */
+ switch (type) {
+ case XKeyPress:
+ return;
+
+ case XButtonPress:
+ return;
+ }
+ }
+ }
+}
+
+
+void W32CALL
+GWXCURS2(int *x, int *y, int *state)
+{
+ int i, key;
+ POINT point;
+
+ key = 0;
+ if (GetAsyncKeyState(VK_SHIFT) < 0) key += 1;
+ if (GetAsyncKeyState(VK_CONTROL) < 0) key += 4;
+ if (GetAsyncKeyState(VK_MENU) < 0) key += 8;
+ if (GetAsyncKeyState(VK_LBUTTON) < 0) key += 256;
+ if (GetAsyncKeyState(VK_MBUTTON) < 0) key += 512;
+ if (GetAsyncKeyState(VK_RBUTTON) < 0) key += 1024;
+ if ((GetAsyncKeyState(VK_LBUTTON) < 0) &&
+ (GetAsyncKeyState(VK_RBUTTON) < 0)) key -= 768;
+
+ GetCursorPos(&point);
+
+ *x = -1;
+ *y = -1;
+ *state = 0;
+ *x = point.x - gwxSize[2];
+ *y = point.y - gwxSize[3];
+ *state = key;
+}
+
+
+HWND W32CALL
+GWXCURRENTPOINTER(int *x, int *y)
+{
+ POINT point;
+ RECT rect;
+ HWND win;
+
+ GetCursorPos(&point);
+ win = WindowFromPoint(point);
+ GetWindowRect(win, &rect);
+ *x = point.x - rect.left;
+ *y = point.y - rect.top;
+ return win;
+}
+
+
+void W32CALL
+GWXSETPOINTER(HWND win, int *x, int *y)
+{
+ int ix, iy;
+ RECT rect;
+
+ if (GetActiveWindow() != win) SetActiveWindow(win);
+ if (GetFocus() != win) SetFocus(win);
+ if (GetForegroundWindow() != win) SetForegroundWindow(win);
+ GetWindowRect(win, &rect);
+ ix = *x + rect.left;
+ iy = *y + rect.top;
+ SetCursorPos(ix, iy);
+}
+
+
+
+
+/* gwxdash
+ Set line drawing pattern to mask pattern
+ Parameters:
+ mask (int*) integer mask value (bits set pen pattern for lines)
+*/
+void W32CALL
+GWXDASH(int* lmask)
+{
+GC *gcontext;
+int i, ndsh;
+HPEN oldpen;
+
+ penpattern = *lmask;
+ gcontext = gwxGC;
+
+ if(*lmask==0) {
+ ndash = 0;
+ }
+ else if(*lmask==-1) {
+ ndash = 0;
+ }
+ else {
+ (void) MSKBITS(lmask,pendash,&ndsh);
+ ndash = ndsh;
+/* for(i=1; i<=ndash; i++) printf("%d dashes %d\n",i,pendash[i-1]); */
+ }
+ oldpen = gcontext->pen;
+ gcontext->pen = makenewpen();
+ oldpen = SelectObject(gwxmemHDC, gcontext->pen);
+ DeleteObject(oldpen);
+}
+
+
+
+/* gwxpen
+ Set pen width for line drawing
+ Parameters:
+ ipen (int*) integer pen width
+*/
+void W32CALL
+GWXPEN(int* ipen)
+{
+GC *gcontext;
+HPEN oldpen;
+
+ penwidth = *ipen;
+ gcontext = gwxGC;
+ oldpen = gcontext->pen;
+ gcontext->pen = makenewpen();
+ oldpen = SelectObject(gwxmemHDC, gcontext->pen);
+ DeleteObject(oldpen);
+}
+
+
+/* mskbits
+ Utility routine to convert lower 16 bits of pattern mask
+ into pattern array of on/off bit lengths. The 16
+ bits of ipat can contain up to 16 on/off bit lengths.
+ i.e. 0XAAAAAAA produces ibits=(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
+ i.e. 0XCCCCCCC produces ibits=(2,2,2,2,2,2,2,2)
+ The output pattern stored in integer array ibits=(#on,#off,#on,#off,etc.)
+ Parameters:
+ mask (int*) input mask
+ ibits (int*) output pattern string (#on, #off...)
+ ndash (int*) number of entries in pattern array
+*/
+void
+MSKBITS(int* mask, int* ibits, int* ndash)
+{
+#define BITSINMASK 16 /* use only lower 16 bits of mask word */
+
+int i,ic,ibit,ibitold;
+int nbits, nshft;
+unsigned short lmask;
+
+/* shift mask until low bit is 1, filling high bits with 0's */
+ lmask = *mask;
+ nshft = 0;
+
+ if(lmask!=0) {
+ while (!(ibitold = (lmask & 0x01)))
+ lmask >>= 1;
+ nshft++;
+ }
+/* if no 1 bits just exit with no dashes set */
+ if(ibitold==0) {
+ *ndash = 0;
+ exit;
+ }
+
+/* cycle through the lower 'length-nshft' bits
+ checking for number of contiguous same bits,
+ store into ibits array */
+ nbits = ic = 0;
+
+ for (i=0; i<(BITSINMASK-nshft); ++i) {
+
+ ibit=(lmask & 0x01);
+
+ if(ibit != ibitold) {
+ ibits[ic++] = nbits;
+ nbits = 0;
+ }
+
+ ibitold = ibit;
+ nbits++;
+
+ lmask >>= 1;
+ }
+
+/* add bits at end of shifted bits including any initial shift
+ to find the first 1 in the low bit */
+ if(ibit==1) {
+
+ ibits[ic++] = nbits;
+ if(nshft>0)
+ ibits[ic++] = nshft;
+
+ }
+ else
+ ibits[ic++] = nbits + nshft;
+
+ *ndash = ic;
+}
+
+
+
+
+/* gwxsetcolor
+ Set foreground color to stored colormap pixel value
+ Parameters:
+ icol (int*) index of pixel value (mapped in colormap)
+*/
+void W32CALL
+GWXSETCOLOR(icol)
+ int *icol;
+{
+ int ic, n, fg;
+ GC *gcontext;
+ HPEN oldpen;
+
+/* is the color index in range for stored colormap data? */
+ ic = *icol;
+/* find the color in the table */
+ for (n=0; n < nRGBmap; n++) {
+ if(ic == RGBmap[n].ic) {
+ fg = RGBmap[n].rgb;
+ gcontext = gwxGC;
+ gcontext->fg = rgb2winrgb(fg);
+/* printf("gwxsetfgcolor fg %d wfg %d\n",*fg,gcontext->fg); */
+ gcontext->pen = makenewpen();
+ gcontext->fgbrush = RGBmap[n].brush;
+ oldpen = SelectObject(gwxmemHDC, gcontext->pen);
+ DeleteObject(oldpen);
+ SelectObject(gwxmemHDC, gcontext->fgbrush);
+ return;
+ }
+ }
+ fprintf(stderr,"Xplot11.gwxsetcolor: color index %d out of range\n",*icol);
+
+ printf("Xplot11.gwxsetcolor: color index %d out of range\n",*icol);
+}
+
+
+
+/* gwxsetbgcolor
+ Set background color to pixel value
+ Parameters:
+ pixel (int*) pixel value (mapped in colormap)
+*/
+void W32CALL
+GWXSETBGCOLOR(icol)
+ int *icol;
+{
+ int ic, n, bg;
+ GC *gcontext;
+/* is the color index in range for stored colormap data? */
+ ic = *icol;
+/* find the color in the table */
+ for (n=0; n < nRGBmap; n++) {
+ if(ic == RGBmap[n].ic) {
+ bg = RGBmap[n].rgb;
+ gcontext = gwxGC;
+ gcontext->bg = rgb2winrgb(bg);
+ gcontext->bgbrush = RGBmap[n].brush;
+ return;
+ }
+ }
+ fprintf(stderr,"Xplot11.gwxsetbgcolor: color index %d out of range\n",*icol);
+ printf("Xplot11.gwxsetbgcolor: color index %d out of range\n",*icol);
+}
+
+
+
+/* gwxcolorname2rgb
+ Find r,g,b components for color specified by name string
+ Parameters:
+ red,grn,blu (int*) output color components (0-255)
+ nc (int*) string length (# of chars)
+ colorname (char*) string containing name of valid color
+ Note: color names are not case sensitive
+ len (int) fortran appended string length (passed by value)
+
+ Valid color names are any color name that is known to X11 color database
+ Examples are "Black","White","Yellow","Orange","Red","Green",
+ "Cyan","Blue","Magenta", "ivory", etc.
+*/
+void W32CALL
+GWXCOLORNAME2RGB(int *red, int *grn, int *blu,
+ int *nc, char *colorname, int len)
+{
+ char cname[32];
+ int i,n;
+ int irgb;
+
+ n = *nc;
+ /* copy string to avoid overwriting possibly static input string
+ Note that string length is explicitly passed to avoid compatibility
+ problems with by fortran character arg length */
+ if(n>31) {
+ n = 31;
+ fprintf(stderr,"Xplot11.gwxcolorname2rgb: color name '%s' truncated\n",
+ cname);
+ printf("Xplot11.gwxcolorname2rgb: color name '%s' truncated\n",cname);
+ }
+ strncpy(cname,colorname,n);
+ cname[n] = '\0';
+
+ *red = -1;
+ *grn = -1;
+ *blu = -1;
+ if (!gwxlookupcolor(cname,&irgb)) {
+ fprintf(stderr,"Xplot11.gwxcolorname2rgb: color name '%s' not found\n",
+ cname);
+ printf("Xplot11.gwxcolorname2rgb: color name '%s' not found\n",cname);
+ return;
+ }
+ *red = 0x000000ff & (irgb >> 16);
+ *grn = 0x000000ff & (irgb >> 8);
+ *blu = 0x000000ff & (irgb);
+
+ /*
+ printf("gwxcolorname2rgb red = %d\ngrn = %d\nblu = %d\n",*red,*grn,*blu);
+ */
+}
+
+
+int
+gwxlookupcolor (char *colorname, int *irgb)
+{
+ int IC,ic,ncolors;
+ int i;
+ char cname[32], *ctmp;
+
+ IC = sizeof(Colordef);
+ ic = sizeof(colordef);
+ ncolors = ic/IC;
+
+ /*
+ printf("Colordef %d\n",IC);
+ printf("colordef %d\n",ic);
+ printf("#entries %d\n",ncolors);
+ */
+
+ if(ctmp=strcpy(cname,colorname)) {
+ for(ctmp = cname; *ctmp; ctmp++)
+ *ctmp = tolower(*ctmp);
+ }
+ /* printf("cname %s\n",cname); */
+
+ for (i=0; i < ncolors; i++) {
+ if(!strcmp(colordef[i].name,cname)) {
+ /* printf("found string %s code %d\n",colordef[i].name,colordef[i].rgb); */
+ *irgb = colordef[i].rgb;
+ return(1);
+ }
+ }
+ return(0);
+}
+
+
+/* gwxallocrgbcolor
+ Allocate a color in colormap specified by r,g,b components
+
+ Parameters:
+ red,grn,blu (int*) input color components (0-255)
+ ic (int*) returned color index or pixel value
+*/
+void W32CALL
+GWXALLOCRGBCOLOR(int *red, int *grn, int *blu, int *ic)
+{
+ int rgb,col;
+ int i;
+
+ rgb = ((0xff & *red) << 16) | ((0xff & *grn) << 8) | (0xff & *blu);
+ *ic = -1;
+
+ /* printf("red %d\ngrn %d\nblu %d\nrgb %d\n",*red,*grn,*blu,rgb); */
+
+/* check for rgb color already allocated in table */
+
+ if(nRGBmap > 0) {
+ for (i=0; i < nRGBmap; i++) {
+ if(rgb == RGBmap[i].rgb) {
+ *ic = RGBmap[i].ic;
+ /* printf("found color %d in table at %d index %d\n",rgb,i+1,*ic); */
+ return;
+ }
+ }
+ }
+/* this color's RGB was not in table, allocate it to table
+ if there is room allocate a new color */
+
+ if(nRGBmap < MAXCOLS) {
+ RGBmap[nRGBmap].rgb = rgb;
+ RGBmap[nRGBmap].ic = nRGBmap+1;
+ col = rgb2winrgb(rgb);
+ RGBmap[nRGBmap].pen = NULL;
+ RGBmap[nRGBmap].brush = CreateSolidBrush(col);
+ nRGBmap++;
+ *ic = nRGBmap;
+ /* printf("allocating color table entry %d at %d\n",*ic,nRGBmap-1); */
+ }
+ else {
+ fprintf (stderr,"Xplot11.gwxallocrgbcolor: can't allocate color.\n");
+ printf ("Xplot11.gwxallocrgbcolor: can't allocate color.\n");
+ }
+}
+
+
+/* gwxfreecolor
+ Free a color from color map
+ Parameters:
+ pix (int*) pixel in colormap
+*/
+void W32CALL
+GWXFREECOLOR(int *icol)
+{
+ int i,ic,n;
+
+/* is the color index in range for stored colormap data? */
+ ic = *icol;
+/* printf("color to delete %d\n",ic); */
+ if((ic > 0) && (ic <= MAXCOLS)) {
+
+/* find the color in the table */
+/* printf("checking colortable of size %d\n",nRGBmap); */
+ for (n=0; n < nRGBmap; n++) {
+/* printf("comparing RGBmap %d with %d to %d\n",n,RGBmap[n].ic,ic); */
+ if(ic == RGBmap[n].ic) {
+/* delete the table entry */
+/* printf("found color %d to delete at %d\n",ic,n); */
+
+ if(RGBmap[n].pen) DeleteObject(RGBmap[n].pen);
+ if(RGBmap[n].brush) DeleteObject(RGBmap[n].brush);
+
+ if(n < nRGBmap-1) {
+ for (i=n; i < nRGBmap; i++) {
+ RGBmap[i-1].rgb = RGBmap[i].rgb;
+ RGBmap[i-1].ic = RGBmap[i].ic;
+ RGBmap[i-1].pen = RGBmap[i].pen;
+ RGBmap[i-1].brush = RGBmap[i].brush;
+ }
+ }
+ nRGBmap--;
+/* printf("deleted color %d\n",*icol); */
+ return;
+ }
+ }
+ }
+ fprintf(stderr,"Xplot11.gwxfreecolor: color index %d out of range\n",*icol);
+ printf("Xplot11.gwxfreecolor: color index %d out of range\n",*icol);
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/plotlib/win32/Xdefs.h b/plotlib/win32/Xdefs.h
new file mode 100644
index 0000000..d742315
--- /dev/null
+++ b/plotlib/win32/Xdefs.h
@@ -0,0 +1,60 @@
+
+/* Event definitions from Xwindows */
+#define XKeyPress 2
+#define XKeyRelease 3
+#define XButtonPress 4
+#define XButtonRelease 5
+#define XMotionNotify 6
+#define XEnterNotify 7
+#define XLeaveNotify 8
+#define XFocusIn 9
+#define XFocusOut 10
+#define XKeymapNotify 11
+#define XExpose 12
+#define XGraphicsExpose 13
+#define XNoExpose 14
+#define XCreateNotify 16
+#define XDestroyNotify 17
+#define XUnmapNotify 18
+#define XMapNotify 19
+#define XMapRequest 20
+#define XReparentNotify 21
+#define XConfigureNotify 22
+#define XConfigureRequest 23
+#define XGravityNotify 24
+#define XResizeRequest 25
+#define XCirculateNotify 26
+#define XCirculateRequest 27
+#define XPropertyNotify 28
+#define XSelectionClear 29
+#define XSelectionRequest 30
+#define XSelectionNotify 31
+#define XColormapNotify 32
+#define XClientMessage 33
+#define XMappingNotify 34
+#define XLASTEvent 35
+
+/* Graphics functions (src to dest) from Xwindows */
+#define GXclear 0
+#define GXand 1
+#define GXandReverse 2
+#define GXcopy 3
+#define GXandInverted 4
+#define GXnoop 5
+#define GXxor 6
+#define GXor 7
+#define GXnor 8
+#define GXequiv 9
+#define GXinvert 10
+#define GXorReverse 11
+#define GXcopyInverted 12
+#define GXorInverted 13
+#define GXnand 14
+#define GXset 15
+
+/* Synchronization functions from Xwindows */
+#define XFDIOff 0
+#define XFDIOn 1
+#define XFDINotThere 2
+
+
diff --git a/plotlib/win32/rgbtbl.h b/plotlib/win32/rgbtbl.h
new file mode 100644
index 0000000..c09cc2f
--- /dev/null
+++ b/plotlib/win32/rgbtbl.h
@@ -0,0 +1,765 @@
+/* RGB lookup table
+ duplicates Xwindows rgb.txt as a color name to integer RGB table
+ H.Youngren 3/99
+*/
+
+typedef struct {
+ char *name;
+ unsigned int rgb;
+} Colordef;
+
+static Colordef colordef[] = {
+"snow", 16775930,
+"ghost white", 16316671,
+"ghostwhite", 16316671,
+"white smoke", 16119285,
+"whitesmoke", 16119285,
+"gainsboro", 14474460,
+"floral white", 16775920,
+"floralwhite", 16775920,
+"old lace", 16643558,
+"oldlace", 16643558,
+"linen", 16445670,
+"antique white", 16444375,
+"antiquewhite", 16444375,
+"papaya whip", 16773077,
+"papayawhip", 16773077,
+"blanched almond", 16772045,
+"blanchedalmond", 16772045,
+"bisque", 16770244,
+"peach puff", 16767673,
+"peachpuff", 16767673,
+"navajo white", 16768685,
+"navajowhite", 16768685,
+"moccasin", 16770229,
+"cornsilk", 16775388,
+"ivory", 16777200,
+"lemon chiffon", 16775885,
+"lemonchiffon", 16775885,
+"seashell", 16774638,
+"honeydew", 15794160,
+"mint cream", 16121850,
+"mintcream", 16121850,
+"azure", 15794175,
+"alice blue", 15792383,
+"aliceblue", 15792383,
+"lavender", 15132410,
+"lavender blush", 16773365,
+"lavenderblush", 16773365,
+"misty rose", 16770273,
+"mistyrose", 16770273,
+"white", 16777215,
+"black", 0,
+"dark slate gray", 3100495,
+"darkslategray", 3100495,
+"dark slate grey", 3100495,
+"darkslategrey", 3100495,
+"dim gray", 6908265,
+"dimgray", 6908265,
+"dim grey", 6908265,
+"dimgrey", 6908265,
+"slate gray", 7372944,
+"slategray", 7372944,
+"slate grey", 7372944,
+"slategrey", 7372944,
+"light slate gray", 7833753,
+"lightslategray", 7833753,
+"light slate grey", 7833753,
+"lightslategrey", 7833753,
+"gray", 12500670,
+"grey", 12500670,
+"light grey", 13882323,
+"lightgrey", 13882323,
+"light gray", 13882323,
+"lightgray", 13882323,
+"midnight blue", 1644912,
+"midnightblue", 1644912,
+"navy", 128,
+"navy blue", 128,
+"navyblue", 128,
+"cornflower blue", 6591981,
+"cornflowerblue", 6591981,
+"dark slate blue", 4734347,
+"darkslateblue", 4734347,
+"slate blue", 6970061,
+"slateblue", 6970061,
+"medium slate blue", 8087790,
+"mediumslateblue", 8087790,
+"light slate blue", 8679679,
+"lightslateblue", 8679679,
+"medium blue", 205,
+"mediumblue", 205,
+"royal blue", 4286945,
+"royalblue", 4286945,
+"blue", 255,
+"dodger blue", 2003199,
+"dodgerblue", 2003199,
+"deep sky blue", 49151,
+"deepskyblue", 49151,
+"sky blue", 8900331,
+"skyblue", 8900331,
+"light sky blue", 8900346,
+"lightskyblue", 8900346,
+"steel blue", 4620980,
+"steelblue", 4620980,
+"light steel blue", 11584734,
+"lightsteelblue", 11584734,
+"light blue", 11393254,
+"lightblue", 11393254,
+"powder blue", 11591910,
+"powderblue", 11591910,
+"pale turquoise", 11529966,
+"paleturquoise", 11529966,
+"dark turquoise", 52945,
+"darkturquoise", 52945,
+"medium turquoise", 4772300,
+"mediumturquoise", 4772300,
+"turquoise", 4251856,
+"cyan", 65535,
+"light cyan", 14745599,
+"lightcyan", 14745599,
+"cadet blue", 6266528,
+"cadetblue", 6266528,
+"medium aquamarine", 6737322,
+"mediumaquamarine", 6737322,
+"aquamarine", 8388564,
+"dark green", 25600,
+"darkgreen", 25600,
+"dark olive green", 5597999,
+"darkolivegreen", 5597999,
+"dark sea green", 9419919,
+"darkseagreen", 9419919,
+"sea green", 3050327,
+"seagreen", 3050327,
+"medium sea green", 3978097,
+"mediumseagreen", 3978097,
+"light sea green", 2142890,
+"lightseagreen", 2142890,
+"pale green", 10025880,
+"palegreen", 10025880,
+"spring green", 65407,
+"springgreen", 65407,
+"lawn green", 8190976,
+"lawngreen", 8190976,
+"green", 65280,
+"chartreuse", 8388352,
+"medium spring green", 64154,
+"mediumspringgreen", 64154,
+"green yellow", 11403055,
+"greenyellow", 11403055,
+"lime green", 3329330,
+"limegreen", 3329330,
+"yellow green", 10145074,
+"yellowgreen", 10145074,
+"forest green", 2263842,
+"forestgreen", 2263842,
+"olive drab", 7048739,
+"olivedrab", 7048739,
+"dark khaki", 12433259,
+"darkkhaki", 12433259,
+"khaki", 15787660,
+"pale goldenrod", 15657130,
+"palegoldenrod", 15657130,
+"light goldenrod yellow", 16448210,
+"lightgoldenrodyellow", 16448210,
+"light yellow", 16777184,
+"lightyellow", 16777184,
+"yellow", 16776960,
+"gold", 16766720,
+"light goldenrod", 15654274,
+"lightgoldenrod", 15654274,
+"goldenrod", 14329120,
+"dark goldenrod", 12092939,
+"darkgoldenrod", 12092939,
+"rosy brown", 12357519,
+"rosybrown", 12357519,
+"indian red", 13458524,
+"indianred", 13458524,
+"saddle brown", 9127187,
+"saddlebrown", 9127187,
+"sienna", 10506797,
+"peru", 13468991,
+"burlywood", 14596231,
+"beige", 16119260,
+"wheat", 16113331,
+"sandy brown", 16032864,
+"sandybrown", 16032864,
+"tan", 13808780,
+"chocolate", 13789470,
+"firebrick", 11674146,
+"brown", 10824234,
+"dark salmon", 15308410,
+"darksalmon", 15308410,
+"salmon", 16416882,
+"light salmon", 16752762,
+"lightsalmon", 16752762,
+"orange", 16753920,
+"dark orange", 16747520,
+"darkorange", 16747520,
+"coral", 16744272,
+"light coral", 15761536,
+"lightcoral", 15761536,
+"tomato", 16737095,
+"orange red", 16729344,
+"orangered", 16729344,
+"red", 16711680,
+"hot pink", 16738740,
+"hotpink", 16738740,
+"deep pink", 16716947,
+"deeppink", 16716947,
+"pink", 16761035,
+"light pink", 16758465,
+"lightpink", 16758465,
+"pale violet red", 14381203,
+"palevioletred", 14381203,
+"maroon", 11546720,
+"medium violet red", 13047173,
+"mediumvioletred", 13047173,
+"violet red", 13639824,
+"violetred", 13639824,
+"magenta", 16711935,
+"violet", 15631086,
+"plum", 14524637,
+"orchid", 14315734,
+"medium orchid", 12211667,
+"mediumorchid", 12211667,
+"dark orchid", 10040012,
+"darkorchid", 10040012,
+"dark violet", 9699539,
+"darkviolet", 9699539,
+"blue violet", 9055202,
+"blueviolet", 9055202,
+"purple", 10494192,
+"medium purple", 9662683,
+"mediumpurple", 9662683,
+"thistle", 14204888,
+"snow1", 16775930,
+"snow2", 15657449,
+"snow3", 13486537,
+"snow4", 9144713,
+"seashell1", 16774638,
+"seashell2", 15656414,
+"seashell3", 13485503,
+"seashell4", 9143938,
+"antiquewhite1", 16773083,
+"antiquewhite2", 15654860,
+"antiquewhite3", 13484208,
+"antiquewhite4", 9143160,
+"bisque1", 16770244,
+"bisque2", 15652279,
+"bisque3", 13481886,
+"bisque4", 9141611,
+"peachpuff1", 16767673,
+"peachpuff2", 15649709,
+"peachpuff3", 13479829,
+"peachpuff4", 9140069,
+"navajowhite1", 16768685,
+"navajowhite2", 15650721,
+"navajowhite3", 13480843,
+"navajowhite4", 9140574,
+"lemonchiffon1", 16775885,
+"lemonchiffon2", 15657407,
+"lemonchiffon3", 13486501,
+"lemonchiffon4", 9144688,
+"cornsilk1", 16775388,
+"cornsilk2", 15657165,
+"cornsilk3", 13486257,
+"cornsilk4", 9144440,
+"ivory1", 16777200,
+"ivory2", 15658720,
+"ivory3", 13487553,
+"ivory4", 9145219,
+"honeydew1", 15794160,
+"honeydew2", 14741216,
+"honeydew3", 12701121,
+"honeydew4", 8620931,
+"lavenderblush1", 16773365,
+"lavenderblush2", 15655141,
+"lavenderblush3", 13484485,
+"lavenderblush4", 9143174,
+"mistyrose1", 16770273,
+"mistyrose2", 15652306,
+"mistyrose3", 13481909,
+"mistyrose4", 9141627,
+"azure1", 15794175,
+"azure2", 14741230,
+"azure3", 12701133,
+"azure4", 8620939,
+"slateblue1", 8613887,
+"slateblue2", 8021998,
+"slateblue3", 6904269,
+"slateblue4", 4668555,
+"royalblue1", 4749055,
+"royalblue2", 4419310,
+"royalblue3", 3825613,
+"royalblue4", 2572427,
+"blue1", 255,
+"blue2", 238,
+"blue3", 205,
+"blue4", 139,
+"dodgerblue1", 2003199,
+"dodgerblue2", 1869550,
+"dodgerblue3", 1602765,
+"dodgerblue4", 1068683,
+"steelblue1", 6535423,
+"steelblue2", 6073582,
+"steelblue3", 5215437,
+"steelblue4", 3564683,
+"deepskyblue1", 49151,
+"deepskyblue2", 45806,
+"deepskyblue3", 39629,
+"deepskyblue4", 26763,
+"skyblue1", 8900351,
+"skyblue2", 8306926,
+"skyblue3", 7120589,
+"skyblue4", 4878475,
+"lightskyblue1", 11592447,
+"lightskyblue2", 10802158,
+"lightskyblue3", 9287373,
+"lightskyblue4", 6323083,
+"slategray1", 13034239,
+"slategray2", 12178414,
+"slategray3", 10467021,
+"slategray4", 7109515,
+"lightsteelblue1", 13296127,
+"lightsteelblue2", 12374766,
+"lightsteelblue3", 10663373,
+"lightsteelblue4", 7240587,
+"lightblue1", 12578815,
+"lightblue2", 11722734,
+"lightblue3", 10141901,
+"lightblue4", 6849419,
+"lightcyan1", 14745599,
+"lightcyan2", 13758190,
+"lightcyan3", 11849165,
+"lightcyan4", 8031115,
+"paleturquoise1", 12320767,
+"paleturquoise2", 11464430,
+"paleturquoise3", 9883085,
+"paleturquoise4", 6720395,
+"cadetblue1", 10024447,
+"cadetblue2", 9364974,
+"cadetblue3", 8046029,
+"cadetblue4", 5473931,
+"turquoise1", 62975,
+"turquoise2", 58862,
+"turquoise3", 50637,
+"turquoise4", 34443,
+"cyan1", 65535,
+"cyan2", 61166,
+"cyan3", 52685,
+"cyan4", 35723,
+"darkslategray1", 9961471,
+"darkslategray2", 9301742,
+"darkslategray3", 7982541,
+"darkslategray4", 5409675,
+"aquamarine1", 8388564,
+"aquamarine2", 7794374,
+"aquamarine3", 6737322,
+"aquamarine4", 4557684,
+"darkseagreen1", 12713921,
+"darkseagreen2", 11857588,
+"darkseagreen3", 10210715,
+"darkseagreen4", 6916969,
+"seagreen1", 5570463,
+"seagreen2", 5172884,
+"seagreen3", 4443520,
+"seagreen4", 3050327,
+"palegreen1", 10157978,
+"palegreen2", 9498256,
+"palegreen3", 8179068,
+"palegreen4", 5540692,
+"springgreen1", 65407,
+"springgreen2", 61046,
+"springgreen3", 52582,
+"springgreen4", 35653,
+"green1", 65280,
+"green2", 60928,
+"green3", 52480,
+"green4", 35584,
+"chartreuse1", 8388352,
+"chartreuse2", 7794176,
+"chartreuse3", 6737152,
+"chartreuse4", 4557568,
+"olivedrab1", 12648254,
+"olivedrab2", 11791930,
+"olivedrab3", 10145074,
+"olivedrab4", 6916898,
+"darkolivegreen1", 13303664,
+"darkolivegreen2", 12381800,
+"darkolivegreen3", 10669402,
+"darkolivegreen4", 7244605,
+"khaki1", 16774799,
+"khaki2", 15656581,
+"khaki3", 13485683,
+"khaki4", 9143886,
+"lightgoldenrod1", 16772235,
+"lightgoldenrod2", 15654018,
+"lightgoldenrod3", 13483632,
+"lightgoldenrod4", 9142604,
+"lightyellow1", 16777184,
+"lightyellow2", 15658705,
+"lightyellow3", 13487540,
+"lightyellow4", 9145210,
+"yellow1", 16776960,
+"yellow2", 15658496,
+"yellow3", 13487360,
+"yellow4", 9145088,
+"gold1", 16766720,
+"gold2", 15649024,
+"gold3", 13479168,
+"gold4", 9139456,
+"goldenrod1", 16761125,
+"goldenrod2", 15643682,
+"goldenrod3", 13474589,
+"goldenrod4", 9136404,
+"darkgoldenrod1", 16759055,
+"darkgoldenrod2", 15641870,
+"darkgoldenrod3", 13473036,
+"darkgoldenrod4", 9135368,
+"rosybrown1", 16761281,
+"rosybrown2", 15643828,
+"rosybrown3", 13474715,
+"rosybrown4", 9136489,
+"indianred1", 16738922,
+"indianred2", 15623011,
+"indianred3", 13456725,
+"indianred4", 9124410,
+"sienna1", 16745031,
+"sienna2", 15628610,
+"sienna3", 13461561,
+"sienna4", 9127718,
+"burlywood1", 16765851,
+"burlywood2", 15648145,
+"burlywood3", 13478525,
+"burlywood4", 9139029,
+"wheat1", 16771002,
+"wheat2", 15653038,
+"wheat3", 13482646,
+"wheat4", 9141862,
+"tan1", 16753999,
+"tan2", 15637065,
+"tan3", 13468991,
+"tan4", 9132587,
+"chocolate1", 16744228,
+"chocolate2", 15627809,
+"chocolate3", 13461021,
+"chocolate4", 9127187,
+"firebrick1", 16724016,
+"firebrick2", 15608876,
+"firebrick3", 13444646,
+"firebrick4", 9116186,
+"brown1", 16728128,
+"brown2", 15612731,
+"brown3", 13447987,
+"brown4", 9118499,
+"salmon1", 16747625,
+"salmon2", 15630946,
+"salmon3", 13463636,
+"salmon4", 9129017,
+"lightsalmon1", 16752762,
+"lightsalmon2", 15635826,
+"lightsalmon3", 13468002,
+"lightsalmon4", 9131842,
+"orange1", 16753920,
+"orange2", 15636992,
+"orange3", 13468928,
+"orange4", 9132544,
+"darkorange1", 16744192,
+"darkorange2", 15627776,
+"darkorange3", 13460992,
+"darkorange4", 9127168,
+"coral1", 16740950,
+"coral2", 15624784,
+"coral3", 13458245,
+"coral4", 9125423,
+"tomato1", 16737095,
+"tomato2", 15621186,
+"tomato3", 13455161,
+"tomato4", 9123366,
+"orangered1", 16729344,
+"orangered2", 15613952,
+"orangered3", 13448960,
+"orangered4", 9118976,
+"red1", 16711680,
+"red2", 15597568,
+"red3", 13434880,
+"red4", 9109504,
+"deeppink1", 16716947,
+"deeppink2", 15602313,
+"deeppink3", 13439094,
+"deeppink4", 9112144,
+"hotpink1", 16740020,
+"hotpink2", 15624871,
+"hotpink3", 13459600,
+"hotpink4", 9124450,
+"pink1", 16758213,
+"pink2", 15641016,
+"pink3", 13472158,
+"pink4", 9134956,
+"lightpink1", 16756409,
+"lightpink2", 15639213,
+"lightpink3", 13470869,
+"lightpink4", 9133925,
+"palevioletred1", 16745131,
+"palevioletred2", 15628703,
+"palevioletred3", 13461641,
+"palevioletred4", 9127773,
+"maroon1", 16725171,
+"maroon2", 15610023,
+"maroon3", 13445520,
+"maroon4", 9116770,
+"violetred1", 16727702,
+"violetred2", 15612556,
+"violetred3", 13447800,
+"violetred4", 9118290,
+"magenta1", 16711935,
+"magenta2", 15597806,
+"magenta3", 13435085,
+"magenta4", 9109643,
+"orchid1", 16745466,
+"orchid2", 15629033,
+"orchid3", 13461961,
+"orchid4", 9127817,
+"plum1", 16759807,
+"plum2", 15642350,
+"plum3", 13473485,
+"plum4", 9135755,
+"mediumorchid1", 14706431,
+"mediumorchid2", 13721582,
+"mediumorchid3", 11817677,
+"mediumorchid4", 8009611,
+"darkorchid1", 12533503,
+"darkorchid2", 11680494,
+"darkorchid3", 10105549,
+"darkorchid4", 6824587,
+"purple1", 10170623,
+"purple2", 9514222,
+"purple3", 8201933,
+"purple4", 5577355,
+"mediumpurple1", 11240191,
+"mediumpurple2", 10451438,
+"mediumpurple3", 9005261,
+"mediumpurple4", 6113163,
+"thistle1", 16769535,
+"thistle2", 15651566,
+"thistle3", 13481421,
+"thistle4", 9141131,
+"gray0", 0,
+"grey0", 0,
+"gray1", 197379,
+"grey1", 197379,
+"gray2", 328965,
+"grey2", 328965,
+"gray3", 526344,
+"grey3", 526344,
+"gray4", 657930,
+"grey4", 657930,
+"gray5", 855309,
+"grey5", 855309,
+"gray6", 986895,
+"grey6", 986895,
+"gray7", 1184274,
+"grey7", 1184274,
+"gray8", 1315860,
+"grey8", 1315860,
+"gray9", 1513239,
+"grey9", 1513239,
+"gray10", 1710618,
+"grey10", 1710618,
+"gray11", 1842204,
+"grey11", 1842204,
+"gray12", 2039583,
+"grey12", 2039583,
+"gray13", 2171169,
+"grey13", 2171169,
+"gray14", 2368548,
+"grey14", 2368548,
+"gray15", 2500134,
+"grey15", 2500134,
+"gray16", 2697513,
+"grey16", 2697513,
+"gray17", 2829099,
+"grey17", 2829099,
+"gray18", 3026478,
+"grey18", 3026478,
+"gray19", 3158064,
+"grey19", 3158064,
+"gray20", 3355443,
+"grey20", 3355443,
+"gray21", 3552822,
+"grey21", 3552822,
+"gray22", 3684408,
+"grey22", 3684408,
+"gray23", 3881787,
+"grey23", 3881787,
+"gray24", 4013373,
+"grey24", 4013373,
+"gray25", 4210752,
+"grey25", 4210752,
+"gray26", 4342338,
+"grey26", 4342338,
+"gray27", 4539717,
+"grey27", 4539717,
+"gray28", 4671303,
+"grey28", 4671303,
+"gray29", 4868682,
+"grey29", 4868682,
+"gray30", 5066061,
+"grey30", 5066061,
+"gray31", 5197647,
+"grey31", 5197647,
+"gray32", 5395026,
+"grey32", 5395026,
+"gray33", 5526612,
+"grey33", 5526612,
+"gray34", 5723991,
+"grey34", 5723991,
+"gray35", 5855577,
+"grey35", 5855577,
+"gray36", 6052956,
+"grey36", 6052956,
+"gray37", 6184542,
+"grey37", 6184542,
+"gray38", 6381921,
+"grey38", 6381921,
+"gray39", 6513507,
+"grey39", 6513507,
+"gray40", 6710886,
+"grey40", 6710886,
+"gray41", 6908265,
+"grey41", 6908265,
+"gray42", 7039851,
+"grey42", 7039851,
+"gray43", 7237230,
+"grey43", 7237230,
+"gray44", 7368816,
+"grey44", 7368816,
+"gray45", 7566195,
+"grey45", 7566195,
+"gray46", 7697781,
+"grey46", 7697781,
+"gray47", 7895160,
+"grey47", 7895160,
+"gray48", 8026746,
+"grey48", 8026746,
+"gray49", 8224125,
+"grey49", 8224125,
+"gray50", 8355711,
+"grey50", 8355711,
+"gray51", 8553090,
+"grey51", 8553090,
+"gray52", 8750469,
+"grey52", 8750469,
+"gray53", 8882055,
+"grey53", 8882055,
+"gray54", 9079434,
+"grey54", 9079434,
+"gray55", 9211020,
+"grey55", 9211020,
+"gray56", 9408399,
+"grey56", 9408399,
+"gray57", 9539985,
+"grey57", 9539985,
+"gray58", 9737364,
+"grey58", 9737364,
+"gray59", 9868950,
+"grey59", 9868950,
+"gray60", 10066329,
+"grey60", 10066329,
+"gray61", 10263708,
+"grey61", 10263708,
+"gray62", 10395294,
+"grey62", 10395294,
+"gray63", 10592673,
+"grey63", 10592673,
+"gray64", 10724259,
+"grey64", 10724259,
+"gray65", 10921638,
+"grey65", 10921638,
+"gray66", 11053224,
+"grey66", 11053224,
+"gray67", 11250603,
+"grey67", 11250603,
+"gray68", 11382189,
+"grey68", 11382189,
+"gray69", 11579568,
+"grey69", 11579568,
+"gray70", 11776947,
+"grey70", 11776947,
+"gray71", 11908533,
+"grey71", 11908533,
+"gray72", 12105912,
+"grey72", 12105912,
+"gray73", 12237498,
+"grey73", 12237498,
+"gray74", 12434877,
+"grey74", 12434877,
+"gray75", 12566463,
+"grey75", 12566463,
+"gray76", 12763842,
+"grey76", 12763842,
+"gray77", 12895428,
+"grey77", 12895428,
+"gray78", 13092807,
+"grey78", 13092807,
+"gray79", 13224393,
+"grey79", 13224393,
+"gray80", 13421772,
+"grey80", 13421772,
+"gray81", 13619151,
+"grey81", 13619151,
+"gray82", 13750737,
+"grey82", 13750737,
+"gray83", 13948116,
+"grey83", 13948116,
+"gray84", 14079702,
+"grey84", 14079702,
+"gray85", 14277081,
+"grey85", 14277081,
+"gray86", 14408667,
+"grey86", 14408667,
+"gray87", 14606046,
+"grey87", 14606046,
+"gray88", 14737632,
+"grey88", 14737632,
+"gray89", 14935011,
+"grey89", 14935011,
+"gray90", 15066597,
+"grey90", 15066597,
+"gray91", 15263976,
+"grey91", 15263976,
+"gray92", 15461355,
+"grey92", 15461355,
+"gray93", 15592941,
+"grey93", 15592941,
+"gray94", 15790320,
+"grey94", 15790320,
+"gray95", 15921906,
+"grey95", 15921906,
+"gray96", 16119285,
+"grey96", 16119285,
+"gray97", 16250871,
+"grey97", 16250871,
+"gray98", 16448250,
+"grey98", 16448250,
+"gray99", 16579836,
+"grey99", 16579836,
+"gray100", 16777215,
+"grey100", 16777215,
+"dark grey", 11119017,
+"darkgrey", 11119017,
+"dark gray", 11119017,
+"darkgray", 11119017,
+"dark blue", 139,
+"darkblue", 139,
+"dark cyan", 35723,
+"darkcyan", 35723,
+"dark magenta", 9109643,
+"darkmagenta", 9109643,
+"dark red", 9109504,
+"darkred", 9109504,
+"light green", 9498256,
+"lightgreen", 9498256
+};
+