scx/c/xlib/graphics.c

254 lines
9.2 KiB
C

/* Copyright 2001-2003 by Norbert Freudemann, David Frese */
#include "xlib.h"
#define scx_extract_coord_mode(x) S48_EXTRACT_ENUM(x, "scx-coord-mode")
#define scx_extract_polygon_shape(x) S48_EXTRACT_ENUM(x, "scx-polygon-shape")
s48_value scx_Copy_Area(s48_value display, s48_value src, s48_value dest,
s48_value gc, s48_value srcx, s48_value srcy,
s48_value width, s48_value height, s48_value destx,
s48_value desty) {
XCopyArea(scx_extract_display(display), scx_extract_drawable(src),
scx_extract_drawable(dest), scx_extract_gc(gc),
(int)s48_extract_integer(srcx), (int)s48_extract_integer(srcy),
(int)s48_extract_integer(width), (int)s48_extract_integer(height),
(int)s48_extract_integer(destx), (int)s48_extract_integer(desty));
return S48_UNSPECIFIC;
}
s48_value scx_Copy_Plane(s48_value display, s48_value src, s48_value dest,
s48_value gc, s48_value srcx, s48_value srcy,
s48_value width, s48_value height,
s48_value destx, s48_value desty, s48_value plane) {
XCopyPlane(scx_extract_display(display), scx_extract_drawable(src),
scx_extract_drawable(dest), scx_extract_gc(gc),
(int)s48_extract_integer(srcx), (int)s48_extract_integer(srcy),
(int)s48_extract_integer(width), (int)s48_extract_integer(height),
(int)s48_extract_integer(destx), (int)s48_extract_integer(desty),
(unsigned long)s48_extract_integer(plane));
return S48_UNSPECIFIC;
}
s48_value scx_Draw_Point(s48_value display, s48_value drawable,
s48_value gc, s48_value x, s48_value y) {
XDrawPoint(scx_extract_display(display), scx_extract_drawable(drawable),
scx_extract_gc(gc), (int)s48_extract_integer(x),
(int)s48_extract_integer(y));
return S48_UNSPECIFIC;
}
static void List_To_XPoints(s48_value l, XPoint* p, int n) {
int i;
for (i = 0; i < n; i++) {
s48_value point = S48_CAR(l);
p[i].x = (int)s48_extract_integer(S48_CAR(point));
p[i].y = (int)s48_extract_integer(S48_CDR(point));
l = S48_CDR(l);
}
}
s48_value scx_Draw_Points(s48_value display, s48_value drawable,
s48_value gc, s48_value points, s48_value mode) {
int n = s48_list_length(points);
XPoint p[n];
List_To_XPoints(points, p, n);
XDrawPoints(scx_extract_display(display), scx_extract_drawable(drawable),
scx_extract_gc(gc), p, n,
scx_extract_coord_mode(mode));
return S48_UNSPECIFIC;
}
s48_value scx_Draw_Line(s48_value display, s48_value drawable,
s48_value gc, s48_value x1, s48_value y1,
s48_value x2, s48_value y2) {
XDrawLine(scx_extract_display(display),scx_extract_drawable(drawable),
scx_extract_gc(gc), (int)s48_extract_integer(x1),
(int)s48_extract_integer(y1), (int)s48_extract_integer(x2),
(int)s48_extract_integer(y2));
return S48_UNSPECIFIC;
}
s48_value scx_Draw_Lines(s48_value display, s48_value drawable,
s48_value gc, s48_value points, s48_value mode) {
int n = s48_list_length(points);
XPoint p[n];
List_To_XPoints(points, p, n);
XDrawLines(scx_extract_display(display), scx_extract_drawable(drawable),
scx_extract_gc(gc), p, n,
scx_extract_coord_mode(mode));
return S48_UNSPECIFIC;
}
static void List_To_XSegments(s48_value l, XSegment* p, int n) {
int i;
s48_value rectype = s48_get_imported_binding("scx-segment");
for (i = 0; i < n; i++) {
s48_value s = S48_CAR(l);
s48_check_record_type(s, rectype);
p[i].x1 = (int)s48_extract_integer(S48_RECORD_REF(s, 0));
p[i].y1 = (int)s48_extract_integer(S48_RECORD_REF(s, 1));
p[i].x2 = (int)s48_extract_integer(S48_RECORD_REF(s, 2));
p[i].y2 = (int)s48_extract_integer(S48_RECORD_REF(s, 3));
l = S48_CDR(l);
}
}
s48_value scx_Draw_Segments(s48_value display, s48_value drawable,
s48_value gc, s48_value segs) {
int n = s48_list_length(segs);
XSegment p[n];
List_To_XSegments(segs, p, n);
XDrawSegments(scx_extract_display(display), scx_extract_drawable(drawable),
scx_extract_gc(gc), p, n);
return S48_UNSPECIFIC;
}
s48_value scx_Draw_Rectangle(s48_value display, s48_value drawable,
s48_value gc, s48_value x, s48_value y,
s48_value width, s48_value height) {
XDrawRectangle(scx_extract_display(display), scx_extract_drawable(drawable),
scx_extract_gc(gc),
(int)s48_extract_integer(x),
(int)s48_extract_integer(y),
(int)s48_extract_integer(width),
(int)s48_extract_integer(height));
return S48_UNSPECIFIC;
}
static void List_To_XRectangles(s48_value l, XRectangle* p, int n) {
int i;
s48_value rectype = s48_get_imported_binding("scx-rectangle");
for (i = 0; i < n; i++) {
s48_value r = S48_CAR(l);
s48_check_record_type(r, rectype);
p[i].x = (int)s48_extract_integer(S48_RECORD_REF(r, 0));
p[i].y = (int)s48_extract_integer(S48_RECORD_REF(r, 1));
p[i].width = (int)s48_extract_integer(S48_RECORD_REF(r, 2));
p[i].height = (int)s48_extract_integer(S48_RECORD_REF(r, 3));
l = S48_CDR(l);
}
}
s48_value scx_Draw_Rectangles(s48_value display, s48_value drawable,
s48_value gc, s48_value rects) {
int n = s48_list_length(rects);
XRectangle p[n];
List_To_XRectangles(rects, p, n);
XDrawRectangles(scx_extract_display(display), scx_extract_drawable(drawable),
scx_extract_gc(gc), p, n);
return S48_UNSPECIFIC;
}
s48_value scx_Draw_Arc(s48_value display, s48_value drawable,
s48_value gc, s48_value x, s48_value y, s48_value w,
s48_value h, s48_value a1, s48_value a2) {
XDrawArc(scx_extract_display(display), scx_extract_drawable(drawable),
scx_extract_gc(gc), (int)s48_extract_integer(x),
(int)s48_extract_integer(y), (int)s48_extract_integer(w),
(int)s48_extract_integer(h), (int)s48_extract_integer(a1),
(int)s48_extract_integer(a2));
return S48_UNSPECIFIC;
}
static void List_To_XArcs(s48_value l, XArc* p, int n) {
int i;
s48_value rectype = s48_get_imported_binding("scx-arc");
for (i = 0; i < n; i++) {
s48_value r = S48_CAR(l);
s48_check_record_type(r, rectype);
p[i].x = (int)s48_extract_integer(S48_RECORD_REF(r, 0));
p[i].y = (int)s48_extract_integer(S48_RECORD_REF(r, 1));
p[i].width = (int)s48_extract_integer(S48_RECORD_REF(r, 2));
p[i].height = (int)s48_extract_integer(S48_RECORD_REF(r, 3));
p[i].angle1 = (int)s48_extract_integer(S48_RECORD_REF(r, 4));
p[i].angle2 = (int)s48_extract_integer(S48_RECORD_REF(r, 5));
l = S48_CDR(l);
}
}
s48_value scx_Draw_Arcs(s48_value display, s48_value drawable,
s48_value gc, s48_value arcs) {
int n = s48_list_length(arcs);
XArc p[n];
List_To_XArcs(arcs, p, n);
XDrawArcs(scx_extract_display(display), scx_extract_drawable(drawable),
scx_extract_gc(gc), p, n);
return S48_UNSPECIFIC;
}
s48_value scx_Fill_Rectangle(s48_value display, s48_value drawable,
s48_value gc, s48_value x, s48_value y,
s48_value width, s48_value height) {
XFillRectangle(scx_extract_display(display), scx_extract_drawable(drawable),
scx_extract_gc(gc),
(int)s48_extract_integer(x),
(int)s48_extract_integer(y),
(int)s48_extract_integer(width),
(int)s48_extract_integer(height));
return S48_UNSPECIFIC;
}
s48_value scx_Fill_Rectangles(s48_value display, s48_value drawable,
s48_value gc, s48_value rects) {
int n = s48_list_length(rects);
XRectangle p[n];
List_To_XRectangles(rects, p, n);
XFillRectangles(scx_extract_display(display), scx_extract_drawable(drawable),
scx_extract_gc(gc), p, n);
return S48_UNSPECIFIC;
}
s48_value scx_Fill_Polygon(s48_value display, s48_value drawable,
s48_value gc, s48_value points,
s48_value shape, s48_value mode) {
int n = s48_list_length(points);
XPoint p[n];
List_To_XPoints(points, p, n);
XFillPolygon(scx_extract_display(display), scx_extract_drawable(drawable),
scx_extract_gc(gc), p, n,
scx_extract_polygon_shape(shape),
scx_extract_coord_mode(mode));
return S48_UNSPECIFIC;
}
s48_value scx_Fill_Arc(s48_value display, s48_value drawable,
s48_value gc, s48_value x, s48_value y, s48_value w,
s48_value h, s48_value a1, s48_value a2) {
XFillArc(scx_extract_display(display), scx_extract_drawable(drawable),
scx_extract_gc(gc), (int)s48_extract_integer(x),
(int)s48_extract_integer(y), (int)s48_extract_integer(w),
(int)s48_extract_integer(h), (int)s48_extract_integer(a1),
(int)s48_extract_integer(a2));
return S48_UNSPECIFIC;
}
s48_value scx_Fill_Arcs(s48_value display, s48_value drawable,
s48_value gc, s48_value arcs) {
int n = s48_list_length(arcs);
XArc p[n];
List_To_XArcs(arcs, p, n);
XFillArcs(scx_extract_display(display), scx_extract_drawable(drawable),
scx_extract_gc(gc), p, n);
return S48_UNSPECIFIC;
}
void scx_init_graphics(void) {
S48_EXPORT_FUNCTION(scx_Copy_Area);
S48_EXPORT_FUNCTION(scx_Copy_Plane);
S48_EXPORT_FUNCTION(scx_Draw_Point);
S48_EXPORT_FUNCTION(scx_Draw_Points);
S48_EXPORT_FUNCTION(scx_Draw_Line);
S48_EXPORT_FUNCTION(scx_Draw_Lines);
S48_EXPORT_FUNCTION(scx_Draw_Segments);
S48_EXPORT_FUNCTION(scx_Draw_Rectangle);
S48_EXPORT_FUNCTION(scx_Draw_Rectangles);
S48_EXPORT_FUNCTION(scx_Draw_Arc);
S48_EXPORT_FUNCTION(scx_Draw_Arcs);
S48_EXPORT_FUNCTION(scx_Fill_Rectangle);
S48_EXPORT_FUNCTION(scx_Fill_Rectangles);
S48_EXPORT_FUNCTION(scx_Fill_Polygon);
S48_EXPORT_FUNCTION(scx_Fill_Arc);
S48_EXPORT_FUNCTION(scx_Fill_Arcs);
}