From: <hba...@us...> - 2009-06-17 03:54:29
|
Revision: 10053 http://plplot.svn.sourceforge.net/plplot/?rev=10053&view=rev Author: hbabcock Date: 2009-06-17 03:54:28 +0000 (Wed, 17 Jun 2009) Log Message: ----------- Correct y coordinate returned by X windows for differing origins. 0,0 in X windows is the upper left corner. 0,0 in PLplot is the bottom left corner. Thanks to Dmitri Gribenko for pointing out this bug. Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2009-06-17 02:53:08 UTC (rev 10052) +++ trunk/drivers/cairo.c 2009-06-17 03:54:28 UTC (rev 10053) @@ -215,6 +215,7 @@ static void set_current_context(PLStream *); static void poly_line(PLStream *, short *, short *, PLINT); static void filled_polygon(PLStream *pls, short *xa, short *ya, PLINT npts); +static void arc(PLStream *, arc_struct *); static void rotate_cairo_surface(PLStream *, float, float, float, float, float, float); /* Rasterization of plotted material */ static void start_raster(PLStream*); @@ -486,6 +487,9 @@ case PLESC_END_RASTERIZE: /* End offscreen/rasterized rendering */ end_raster(pls); break; + case PLESC_ARC: /* Draw an arc, either filled or outline */ + arc(pls, (arc_struct *) ptr); + break; } } @@ -992,6 +996,7 @@ pls->alt_unicode = 1; /* Wants to handle unicode character by character */ pls->page = 0; pls->dev_fill0 = 1; /* Supports hardware solid fills */ + pls->dev_arc = 1; /* Supports driver-level arcs */ pls->plbuf_write = 1; /* Activate plot buffer */ @@ -1149,6 +1154,60 @@ } /*--------------------------------------------------------------------- + arc() + + Draws an arc, possibly filled. + ---------------------------------------------------------------------*/ + +void arc(PLStream *pls, arc_struct *arc_info) +{ + /* + TODO: + - Decide on a direction for increasing angles and make sure this Cairo + implementation matches the software/fallback implementation. + - Add clipping to viewport boundaries + */ + PLCairo *aStream; + double x, y, a, b; + double angle1, angle2; + double rotation; + + set_current_context(pls); + + aStream = (PLCairo *)pls->dev; + + /* Scale to the proper Cairo coordinates */ + x = aStream->downscale * arc_info->x; + y = aStream->downscale * arc_info->y; + a = aStream->downscale * arc_info->a; + b = aStream->downscale * arc_info->b; + + /* Degrees to radians */ + angle1 = arc_info->angle1 * M_PI / 180.0; + angle2 = arc_info->angle2 * M_PI / 180.0; + rotation = - arc_info->rotation * M_PI / 180.0; + + /* Make sure the arc is properly shaped */ + cairo_save(aStream->cairoContext); + cairo_translate(aStream->cairoContext, x, y); + cairo_rotate(aStream->cairoContext, rotation); + cairo_scale(aStream->cairoContext, a, b); + cairo_arc(aStream->cairoContext, 0.0, 0.0, 1.0, angle1, angle2); + cairo_restore(aStream->cairoContext); + cairo_set_source_rgba(aStream->cairoContext, + (double)pls->curcolor.r/255.0, + (double)pls->curcolor.g/255.0, + (double)pls->curcolor.b/255.0, + (double)pls->curcolor.a); + if (arc_info->fill) { + cairo_fill(aStream->cairoContext); + } + else { + cairo_stroke(aStream->cairoContext); + } +} + +/*--------------------------------------------------------------------- rotate_cairo_surface() Rotates the cairo surface to the appropriate orientation. @@ -1553,9 +1612,9 @@ gin->state = xButtonEvent->state; gin->button = xButtonEvent->button; gin->pX = event.xbutton.x; - gin->pY = event.xbutton.y; + gin->pY = pls->ylength - event.xbutton.y; gin->dX = (PLFLT)event.xbutton.x/((PLFLT)(pls->xlength)); - gin->dY = (PLFLT)event.xbutton.y/((PLFLT)(pls->ylength)); + gin->dY = (PLFLT)(pls->ylength - event.xbutton.y)/((PLFLT)(pls->ylength)); /* Switch back to normal cursor */ XUndefineCursor(aStream->XDisplay, aStream->XWindow); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |