[Redbutton-devel] SF.net SVN: redbutton: [249] redbutton-browser/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-03-16 16:57:13
|
Revision: 249
http://svn.sourceforge.net/redbutton/?rev=249&view=rev
Author: skilvington
Date: 2007-03-16 09:57:08 -0700 (Fri, 16 Mar 2007)
Log Message:
-----------
DrawArc/Sector DynamicLineArtClass methods
Modified Paths:
--------------
redbutton-browser/trunk/DynamicLineArtClass.c
redbutton-browser/trunk/MHEGCanvas.c
redbutton-browser/trunk/MHEGCanvas.h
Modified: redbutton-browser/trunk/DynamicLineArtClass.c
===================================================================
--- redbutton-browser/trunk/DynamicLineArtClass.c 2007-03-13 17:10:33 UTC (rev 248)
+++ redbutton-browser/trunk/DynamicLineArtClass.c 2007-03-16 16:57:08 UTC (rev 249)
@@ -459,20 +459,67 @@
void
DynamicLineArtClass_DrawArc(DynamicLineArtClass *t, DrawArc *params, OctetString *caller_gid)
{
+ XYPosition pos;
+ OriginalBoxSize box;
+ int start;
+ int arc;
+
verbose("DynamicLineArtClass: %s; DrawArc", ExternalReference_name(&t->rootClass.inst.ref));
-/* TODO */
-printf("TODO: DynamicLineArtClass_DrawArc not yet implemented\n");
+ pos.x_position = GenericInteger_getInteger(¶ms->x, caller_gid);
+ pos.y_position = GenericInteger_getInteger(¶ms->y, caller_gid);
+ box.x_length = GenericInteger_getInteger(¶ms->ellipse_width, caller_gid);
+ box.y_length = GenericInteger_getInteger(¶ms->ellipse_height, caller_gid);
+ start = GenericInteger_getInteger(¶ms->start_angle, caller_gid);
+ arc = GenericInteger_getInteger(¶ms->arc_angle, caller_gid);
+
+ /* ISO spec says ArcAngle should not be 0 */
+ if(arc == 0)
+ {
+ error("DynamicLineArtClass_DrawArc: invalid ArcAngle (%d)", arc);
+ return;
+ }
+
+ MHEGCanvas_drawArc(t->inst.canvas, &pos, &box, start, arc, t->inst.LineWidth, t->inst.LineStyle, &t->inst.RefLineColour);
+
+ /* if it is active, redraw it */
+ if(t->rootClass.inst.RunningStatus)
+ MHEGEngine_redrawArea(&t->inst.Position, &t->inst.BoxSize);
+
return;
}
void
DynamicLineArtClass_DrawSector(DynamicLineArtClass *t, DrawSector *params, OctetString *caller_gid)
{
+ XYPosition pos;
+ OriginalBoxSize box;
+ int start;
+ int arc;
+
verbose("DynamicLineArtClass: %s; DrawSector", ExternalReference_name(&t->rootClass.inst.ref));
-/* TODO */
-printf("TODO: DynamicLineArtClass_DrawSector not yet implemented\n");
+ pos.x_position = GenericInteger_getInteger(¶ms->x, caller_gid);
+ pos.y_position = GenericInteger_getInteger(¶ms->y, caller_gid);
+ box.x_length = GenericInteger_getInteger(¶ms->ellipse_width, caller_gid);
+ box.y_length = GenericInteger_getInteger(¶ms->ellipse_height, caller_gid);
+ start = GenericInteger_getInteger(¶ms->start_angle, caller_gid);
+ arc = GenericInteger_getInteger(¶ms->arc_angle, caller_gid);
+
+ /* ISO spec says ArcAngle should not be 0 */
+ if(arc == 0)
+ {
+ error("DynamicLineArtClass_DrawSector: invalid ArcAngle (%d)", arc);
+ return;
+ }
+
+ MHEGCanvas_drawSector(t->inst.canvas, &pos, &box, start, arc,
+ t->inst.LineWidth, t->inst.LineStyle, &t->inst.RefLineColour, &t->inst.RefFillColour);
+
+ /* if it is active, redraw it */
+ if(t->rootClass.inst.RunningStatus)
+ MHEGEngine_redrawArea(&t->inst.Position, &t->inst.BoxSize);
+
return;
}
Modified: redbutton-browser/trunk/MHEGCanvas.c
===================================================================
--- redbutton-browser/trunk/MHEGCanvas.c 2007-03-13 17:10:33 UTC (rev 248)
+++ redbutton-browser/trunk/MHEGCanvas.c 2007-03-16 16:57:08 UTC (rev 249)
@@ -2,6 +2,7 @@
* MHEGCanvas.c
*/
+#include <math.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xrender.h>
@@ -140,6 +141,113 @@
}
/*
+ * draw an arc enclosed by the given box, starting at start (0 = 3 o' clock) for arc degrees anticlockwise
+ * start and arc should be in degrees * 64
+ * the arc is drawn width pixels wide (ie it may stick out of the box) in the given colour
+ */
+
+void
+MHEGCanvas_drawArc(MHEGCanvas *c, XYPosition *pos, OriginalBoxSize *box, int start, int arc, int width, int style, MHEGColour *colour)
+{
+ MHEGDisplay *d = MHEGEngine_getDisplay();
+ XGCValues gcvals;
+ int x, y, w, h;
+
+ if(width <= 0)
+ return;
+
+ if(style != LineStyle_solid)
+ error("MHEGCanvas_drawArc: LineStyle %d not supported (using a solid line)", style);
+
+ /* scale up if fullscreen */
+ x = (pos->x_position * d->xres) / MHEG_XRES;
+ y = (pos->y_position * d->yres) / MHEG_YRES;
+ w = (box->x_length * d->xres) / MHEG_XRES;
+ h = (box->y_length * d->yres) / MHEG_YRES;
+ width = (width * d->xres) / MHEG_XRES;
+
+ /* set up the GC values */
+ gcvals.foreground = pixel_value(c->pic_format, colour);
+ gcvals.line_width = width;
+ XChangeGC(d->dpy, c->gc, GCForeground | GCLineWidth, &gcvals);
+
+ /* luckily X uses the same params as MHEG */
+ XDrawArc(d->dpy, c->contents, c->gc, x, y, w, h, start, arc);
+
+ return;
+}
+
+/*
+ * draw a pie chart sector enclosed by the given box, starting at start (0 = 3 o' clock) for arc degrees anticlockwise
+ * start and arc should be in degrees * 64
+ * the sector is drawn in fill_col
+ * the sector is outlined with a line width pixels wide (ie it may stick out of the box) in line_col
+ */
+
+void
+MHEGCanvas_drawSector(MHEGCanvas *c,
+ XYPosition *pos, OriginalBoxSize *box, int start, int arc,
+ int width, int style, MHEGColour *line_col, MHEGColour *fill_col)
+{
+ MHEGDisplay *d = MHEGEngine_getDisplay();
+ XGCValues gcvals;
+ int x, y, w, h;
+ int cx, cy;
+ double start_rads, end_rads;
+ int edgex, edgey;
+
+ if(style != LineStyle_solid)
+ error("MHEGCanvas_drawSector: LineStyle %d not supported (using a solid line)", style);
+
+ /* scale up if fullscreen */
+ x = (pos->x_position * d->xres) / MHEG_XRES;
+ y = (pos->y_position * d->yres) / MHEG_YRES;
+ w = (box->x_length * d->xres) / MHEG_XRES;
+ h = (box->y_length * d->yres) / MHEG_YRES;
+ width = (width * d->xres) / MHEG_XRES;
+
+ /* fill it */
+ gcvals.foreground = pixel_value(c->pic_format, fill_col);
+ gcvals.arc_mode = ArcPieSlice;
+ XChangeGC(d->dpy, c->gc, GCForeground | GCArcMode, &gcvals);
+
+ /* luckily X uses the same params as MHEG */
+ XFillArc(d->dpy, c->contents, c->gc, x, y, w, h, start, arc);
+
+ /* draw the outline */
+ if(width <= 0)
+ return;
+
+ gcvals.foreground = pixel_value(c->pic_format, line_col);
+ gcvals.line_width = width;
+ XChangeGC(d->dpy, c->gc, GCForeground | GCLineWidth, &gcvals);
+
+ /* easy bit */
+ XDrawArc(d->dpy, c->contents, c->gc, x, y, w, h, start, arc);
+
+ /* lines from the centre to the start and end of the arc */
+ cx = x + (w / 2);
+ cy = y + (h / 2);
+ start_rads = ((double) start / 64.0) * M_PI / 180.0;
+ edgex = cos(start_rads) * (w / 2);
+ edgey = sin(start_rads) * (h / 2);
+ /* cy - edgey, because Y increases as we go down the screen */
+ XDrawLine(d->dpy, c->contents, c->gc, cx, cy, cx + edgex, cy - edgey);
+
+ end_rads = ((double) (start + arc) / 64.0) * M_PI / 180.0;
+ edgex = cos(end_rads) * (w / 2);
+ edgey = sin(end_rads) * (h / 2);
+ XDrawLine(d->dpy, c->contents, c->gc, cx, cy, cx + edgex, cy - edgey);
+
+/* TODO */
+/* make proper joins between the arc and the 2 lines */
+/* ends of the arc are on a tangent to the ellipse */
+/* can't join to a length 0 line because it has no direction, but a 1 pixel long line may be too long */
+
+ return;
+}
+
+/*
* draw a line between p1 and p2
*/
@@ -210,6 +318,9 @@
XFillArc(d->dpy, c->contents, c->gc, x, y, w, h, 0, 360 * 64);
/* draw the outline */
+ if(width <= 0)
+ return;
+
gcvals.foreground = pixel_value(c->pic_format, line_col);
gcvals.line_width = width;
XChangeGC(d->dpy, c->gc, GCForeground | GCLineWidth, &gcvals);
@@ -249,6 +360,9 @@
XFillRectangle(d->dpy, c->contents, c->gc, x, y, w, h);
/* draw the outline */
+ if(width <= 0)
+ return;
+
gcvals.foreground = pixel_value(c->pic_format, line_col);
gcvals.line_width = width;
XChangeGC(d->dpy, c->gc, GCForeground | GCLineWidth, &gcvals);
Modified: redbutton-browser/trunk/MHEGCanvas.h
===================================================================
--- redbutton-browser/trunk/MHEGCanvas.h 2007-03-13 17:10:33 UTC (rev 248)
+++ redbutton-browser/trunk/MHEGCanvas.h 2007-03-16 16:57:08 UTC (rev 249)
@@ -25,6 +25,8 @@
void MHEGCanvas_setBorder(MHEGCanvas *, int, int, MHEGColour *);
void MHEGCanvas_clear(MHEGCanvas *, MHEGColour *);
+void MHEGCanvas_drawArc(MHEGCanvas *, XYPosition *, OriginalBoxSize *, int, int, int, int, MHEGColour *);
+void MHEGCanvas_drawSector(MHEGCanvas *, XYPosition *, OriginalBoxSize *, int, int, int, int, MHEGColour *, MHEGColour *);
void MHEGCanvas_drawLine(MHEGCanvas *, XYPosition *, XYPosition *, int, int, MHEGColour *);
void MHEGCanvas_drawOval(MHEGCanvas *, XYPosition *, OriginalBoxSize *, int, int, MHEGColour *, MHEGColour *);
void MHEGCanvas_drawRectangle(MHEGCanvas *, XYPosition *, OriginalBoxSize *, int, int, MHEGColour *, MHEGColour *);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|