scx/c/xlib/gcontext.c

226 lines
8.0 KiB
C
Raw Normal View History

2001-05-08 10:21:00 -04:00
#include "xlib.h"
unsigned long Values_To_GCValues(s48_value values, XGCValues* GCV) {
unsigned long mask = s48_extract_integer(S48_CAR(values));
s48_value v = S48_CDR(values);
if (mask & GCFunction)
GCV->function = s48_extract_integer(S48_VECTOR_REF(v, 0));
if (mask & GCPlaneMask)
GCV->plane_mask = SCX_EXTRACT_PIXEL(S48_VECTOR_REF(v, 1));
if (mask & GCForeground)
GCV->foreground = SCX_EXTRACT_PIXEL(S48_VECTOR_REF(v, 2));
if (mask & GCBackground)
GCV->background = SCX_EXTRACT_PIXEL(S48_VECTOR_REF(v, 3));
if (mask & GCLineWidth)
GCV->line_width = s48_extract_integer(S48_VECTOR_REF(v, 4));
if (mask & GCLineStyle)
GCV->line_style = s48_extract_integer(S48_VECTOR_REF(v, 5));
if (mask & GCCapStyle)
GCV->cap_style = s48_extract_integer(S48_VECTOR_REF(v, 6));
if (mask & GCJoinStyle)
GCV->join_style = s48_extract_integer(S48_VECTOR_REF(v, 7));
if (mask & GCFillStyle)
GCV->fill_style = s48_extract_integer(S48_VECTOR_REF(v, 8));
if (mask & GCFillRule)
GCV->fill_rule = s48_extract_integer(S48_VECTOR_REF(v, 9));
if (mask & GCTile)
GCV->tile = SCX_EXTRACT_PIXMAP(S48_VECTOR_REF(v, 10));
if (mask & GCStipple)
GCV->stipple = SCX_EXTRACT_PIXMAP(S48_VECTOR_REF(v, 11));
if (mask & GCTileStipXOrigin)
GCV->ts_x_origin = s48_extract_integer(S48_VECTOR_REF(v, 12));
if (mask & GCTileStipYOrigin)
GCV->ts_y_origin = s48_extract_integer(S48_VECTOR_REF(v, 13));
if (mask & GCFont)
GCV->font = SCX_EXTRACT_FONT(S48_VECTOR_REF(v, 14));
if (mask & GCSubwindowMode)
GCV->subwindow_mode = s48_extract_integer(S48_VECTOR_REF(v, 15));
if (mask & GCGraphicsExposures)
GCV->graphics_exposures = S48_ENTER_BOOLEAN(S48_VECTOR_REF(v, 16));
if (mask & GCClipXOrigin)
GCV->clip_x_origin = s48_extract_integer(S48_VECTOR_REF(v, 17));
if (mask & GCClipYOrigin)
GCV->clip_y_origin = s48_extract_integer(S48_VECTOR_REF(v, 18));
if (mask & GCClipMask)
GCV->clip_mask = SCX_EXTRACT_PIXMAP(S48_VECTOR_REF(v, 19));
if (mask & GCDashOffset)
GCV->dash_offset = s48_extract_integer(S48_VECTOR_REF(v, 20));
if (mask & GCDashList)
GCV->dashes = (char)s48_extract_integer(S48_VECTOR_REF(v, 21));
if (mask & GCArcMode)
GCV->arc_mode = s48_extract_integer(S48_VECTOR_REF(v, 22));
return mask;
}
2001-05-08 10:21:00 -04:00
s48_value scx_Create_Gc(s48_value Xdisplay, s48_value Xdrawable,
s48_value values) {
XGCValues GCV;
unsigned long mask = Values_To_GCValues(values, &GCV);
2001-05-08 10:21:00 -04:00
GC Xgcontext = XCreateGC(SCX_EXTRACT_DISPLAY(Xdisplay),
SCX_EXTRACT_DRAWABLE(Xdrawable),
mask, &GCV);
2001-05-08 10:21:00 -04:00
return SCX_ENTER_GCONTEXT(Xgcontext);
2001-05-08 10:21:00 -04:00
}
s48_value scx_Copy_Gc(s48_value Xdisplay, s48_value Xsource, s48_value Xdest) {
XCopyGC(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_GCONTEXT(Xsource),
~0L, SCX_EXTRACT_GCONTEXT(Xdest));
return S48_UNSPECIFIC;
2001-05-08 10:21:00 -04:00
}
s48_value scx_Copy_Gc_To_Gc(s48_value Xdisplay, s48_value Xfrom, s48_value Xto,
s48_value attrs) {
unsigned long mask = s48_extract_integer(attrs); // -1 for all! ??
XCopyGC(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_GCONTEXT(Xfrom),
mask, SCX_EXTRACT_GCONTEXT(Xto));
return S48_UNSPECIFIC;
}
s48_value scx_Free_Gc(s48_value Xgcontext, s48_value Xdisplay) {
XFreeGC(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_GCONTEXT(Xgcontext));
return S48_UNSPECIFIC;
2001-05-08 10:21:00 -04:00
}
#define ValidGCValuesBits \
(GCFunction | GCPlaneMask | GCForeground | GCBackground | GCLineWidth |\
GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle | GCFillRule |\
GCTile | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin | GCFont |\
GCSubwindowMode | GCGraphicsExposures | GCClipXOrigin | GCClipYOrigin |\
GCDashOffset | GCArcMode)
2001-05-08 10:21:00 -04:00
s48_value scx_Get_Gc_Values (s48_value Xgcontext, s48_value Xdisplay) {
unsigned long mask = ValidGCValuesBits;
XGCValues GCV;
s48_value res = S48_FALSE;
S48_DECLARE_GC_PROTECT(1);
if (!XGetGCValues (SCX_EXTRACT_DISPLAY(Xdisplay),
SCX_EXTRACT_GCONTEXT(Xgcontext),
mask, &GCV))
res = S48_FALSE;
else {
res = s48_make_vector(23, S48_FALSE);
S48_GC_PROTECT_1(res);
S48_VECTOR_SET(res, 0, s48_enter_integer(GCV.function));
S48_VECTOR_SET(res, 1, SCX_ENTER_PIXEL(GCV.plane_mask));
S48_VECTOR_SET(res, 2, SCX_ENTER_PIXEL(GCV.foreground));
S48_VECTOR_SET(res, 3, SCX_ENTER_PIXEL(GCV.background));
S48_VECTOR_SET(res, 4, s48_enter_fixnum(GCV.line_width));
S48_VECTOR_SET(res, 5, s48_enter_integer(GCV.line_style));
S48_VECTOR_SET(res, 6, s48_enter_integer(GCV.cap_style));
S48_VECTOR_SET(res, 7, s48_enter_integer(GCV.join_style));
S48_VECTOR_SET(res, 8, s48_enter_integer(GCV.fill_style));
S48_VECTOR_SET(res, 9, s48_enter_integer(GCV.fill_rule));
2002-03-17 10:47:09 -05:00
S48_VECTOR_SET(res, 10, SCX_ENTER_PIXMAP(GCV.tile));
S48_VECTOR_SET(res, 11, SCX_ENTER_PIXMAP(GCV.stipple));
S48_VECTOR_SET(res, 12, s48_enter_fixnum(GCV.ts_x_origin));
S48_VECTOR_SET(res, 13, s48_enter_fixnum(GCV.ts_y_origin));
S48_VECTOR_SET(res, 14, SCX_ENTER_FONT(GCV.font));
S48_VECTOR_SET(res, 15, s48_enter_integer(GCV.subwindow_mode));
S48_VECTOR_SET(res, 16, S48_ENTER_BOOLEAN(GCV.graphics_exposures));
S48_VECTOR_SET(res, 17, s48_enter_fixnum(GCV.clip_x_origin));
S48_VECTOR_SET(res, 18, s48_enter_fixnum(GCV.clip_y_origin));
S48_VECTOR_SET(res, 19, SCX_ENTER_PIXMAP(GCV.clip_mask));
S48_VECTOR_SET(res, 20, s48_enter_integer(GCV.dash_offset));
S48_VECTOR_SET(res, 21, s48_enter_integer(GCV.dashes));
S48_VECTOR_SET(res, 22, s48_enter_integer(GCV.arc_mode));
res = s48_cons(s48_enter_integer(mask), res);
S48_GC_UNPROTECT();
}
return res;
2001-05-08 10:21:00 -04:00
}
s48_value scx_Change_Gc (s48_value Xgcontext, s48_value Xdisplay, s48_value args) {
XGCValues GCV;
unsigned long mask = Values_To_GCValues(args, &GCV);
XChangeGC(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_GCONTEXT(Xgcontext),
mask, &GCV);
return S48_UNSPECIFIC;
2001-05-08 10:21:00 -04:00
}
s48_value scx_Set_Gcontext_Dashlist(s48_value Xgcontext, s48_value Xdisplay,
s48_value dashoffset, s48_value dashlist) {
int n = S48_VECTOR_LENGTH(dashlist);
char v[n];
int i;
for (i=0; i<n; i++) {
v[i] = (char)s48_extract_integer(S48_VECTOR_REF(dashlist, i));
}
2001-05-08 10:21:00 -04:00
XSetDashes( SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_GCONTEXT(Xgcontext),
s48_extract_integer(dashoffset), v, n);
2001-05-08 10:21:00 -04:00
return S48_UNSPECIFIC;
2001-05-08 10:21:00 -04:00
}
s48_value scx_Set_Gcontext_Clip_Rectangles (s48_value Xgcontext,
s48_value Xdisplay, s48_value x,
s48_value y, s48_value v,
s48_value ord) {
int n = S48_VECTOR_LENGTH(v);
XRectangle p[n];
int i;
s48_value rect;
for (i = 0; i < n; i++) {
rect = S48_VECTOR_REF(v, i);
p[i].x = (int)s48_extract_integer (S48_CAR (rect));
rect = S48_CDR (rect);
p[i].y = (int)s48_extract_integer (S48_CAR (rect));
rect = S48_CDR (rect);
p[i].width = (int)s48_extract_integer (S48_CAR (rect));
rect = S48_CDR (rect);
p[i].height = (int)s48_extract_integer (S48_CAR (rect));
}
XSetClipRectangles (SCX_EXTRACT_DISPLAY(Xdisplay),
SCX_EXTRACT_GCONTEXT(Xgcontext),
(int)s48_extract_integer (x),
(int)s48_extract_integer (y), p, n,
s48_extract_integer(ord));
return S48_UNSPECIFIC;
2001-05-08 10:21:00 -04:00
}
s48_value scx_Query_Best_Size (s48_value Xdisplay, s48_value width,
s48_value height, s48_value shape) {
unsigned int rw, rh;
Display* dpy = SCX_EXTRACT_DISPLAY(Xdisplay);
2001-05-08 10:21:00 -04:00
if (!XQueryBestSize (dpy,
s48_extract_integer(shape),
DefaultRootWindow (dpy), //??
(int)s48_extract_integer (width),
(int)s48_extract_integer (height),
&rw, &rh))
return S48_FALSE;
else
return s48_cons (s48_enter_fixnum (rw), s48_enter_fixnum (rh));
2001-05-08 10:21:00 -04:00
}
void scx_init_gcontext(void) {
S48_EXPORT_FUNCTION(scx_Create_Gc);
S48_EXPORT_FUNCTION(scx_Free_Gc);
S48_EXPORT_FUNCTION(scx_Copy_Gc);
S48_EXPORT_FUNCTION(scx_Copy_Gc_To_Gc);
S48_EXPORT_FUNCTION(scx_Get_Gc_Values);
S48_EXPORT_FUNCTION(scx_Change_Gc);
S48_EXPORT_FUNCTION(scx_Set_Gcontext_Dashlist);
S48_EXPORT_FUNCTION(scx_Set_Gcontext_Clip_Rectangles);
S48_EXPORT_FUNCTION(scx_Query_Best_Size);
2001-05-08 10:21:00 -04:00
}