X Color must be unsigned, Caml color can be negative (i.e. -1 = transparent)

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@3194 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Jun FURUSE / 古瀬 淳 2000-06-07 16:32:50 +00:00
parent cadb9fc8f5
commit 6ed65e0522
3 changed files with 24 additions and 14 deletions

View File

@ -114,9 +114,16 @@ int gr_rgb_pixel(long unsigned int pixel)
value gr_set_color(value vrgb)
{
int xcolor;
gr_check_open();
grcolor = gr_pixel_rgb(Int_val(vrgb));
XSetForeground(grdisplay, grwindow.gc, grcolor);
XSetForeground(grdisplay, grbstore.gc, grcolor);
grcolor = Int_val(vrgb);
if (grcolor >= 0 ){
xcolor = gr_pixel_rgb(Int_val(vrgb));
XSetForeground(grdisplay, grwindow.gc, xcolor);
XSetForeground(grdisplay, grbstore.gc, xcolor);
} else {
XSetForeground(grdisplay, grwindow.gc, grbackground);
XSetForeground(grdisplay, grbstore.gc, grbackground);
}
return Val_unit;
}

View File

@ -28,11 +28,13 @@ extern int grscreen; /* The screen number */
extern Colormap grcolormap; /* The color map */
extern struct canvas grwindow; /* The graphics window */
extern struct canvas grbstore; /* The pixmap used for backing store */
extern int grwhite, grblack; /* Black and white pixels */
extern int grwhite, grblack; /* Black and white pixels for X */
extern int grbackground; /* Background color for X
(used for CAML color -1) */
extern Bool grdisplay_mode; /* Display-mode flag */
extern Bool grremember_mode; /* Remember-mode flag */
extern int grx, gry; /* Coordinates of the current point */
extern unsigned long grcolor; /* Current drawing color */
extern int grcolor; /* Current *CAML* drawing color (can be -1) */
extern XFontStruct * grfont; /* Current font */
extern Bool direct_rgb;

View File

@ -29,13 +29,13 @@
Display * grdisplay = NULL;
int grscreen;
Colormap grcolormap;
int grwhite, grblack;
int grwhite, grblack, grbackground;
struct canvas grwindow;
struct canvas grbstore;
Bool grdisplay_mode;
Bool grremember_mode;
int grx, gry;
unsigned long grcolor;
int grcolor;
extern XFontStruct * grfont;
static Bool gr_initialized = False;
@ -75,6 +75,7 @@ value gr_open_graph(value arg)
grscreen = DefaultScreen(grdisplay);
grblack = BlackPixel(grdisplay, grscreen);
grwhite = WhitePixel(grdisplay, grscreen);
grbackground = grwhite;
grcolormap = DefaultColormap(grdisplay, grscreen);
}
@ -100,7 +101,7 @@ value gr_open_graph(value arg)
}
/* Initial drawing color is black */
grcolor = grblack;
grcolor = 0; /* CAML COLOR */
/* Create the on-screen window */
grwindow.w = hints.width;
@ -108,12 +109,12 @@ value gr_open_graph(value arg)
grwindow.win =
XCreateSimpleWindow(grdisplay, DefaultRootWindow(grdisplay),
hints.x, hints.y, hints.width, hints.height,
BORDER_WIDTH, grblack, grwhite);
BORDER_WIDTH, grblack, grbackground);
XSetStandardProperties(grdisplay, grwindow.win, WINDOW_NAME, ICON_NAME,
None, NULL, 0, &hints);
grwindow.gc = XCreateGC(grdisplay, grwindow.win, 0, NULL);
XSetBackground(grdisplay, grwindow.gc, grwhite);
XSetForeground(grdisplay, grwindow.gc, grcolor);
XSetBackground(grdisplay, grwindow.gc, grbackground);
XSetForeground(grdisplay, grwindow.gc, grblack);
/* Require exposure, resize and keyboard events */
XSelectInput(grdisplay, grwindow.win, DEFAULT_EVENT_MASK);
@ -135,13 +136,13 @@ value gr_open_graph(value arg)
XCreatePixmap(grdisplay, grwindow.win, grbstore.w, grbstore.h,
XDefaultDepth(grdisplay, grscreen));
grbstore.gc = XCreateGC(grdisplay, grbstore.win, 0, NULL);
XSetBackground(grdisplay, grbstore.gc, grwhite);
XSetBackground(grdisplay, grbstore.gc, grbackground);
/* Clear the pixmap */
XSetForeground(grdisplay, grbstore.gc, grwhite);
XSetForeground(grdisplay, grbstore.gc, grbackground);
XFillRectangle(grdisplay, grbstore.win, grbstore.gc,
0, 0, grbstore.w, grbstore.h);
XSetForeground(grdisplay, grbstore.gc, grcolor);
XSetForeground(grdisplay, grbstore.gc, grblack);
/* Set the display and remember modes on */
grdisplay_mode = True ;