diff options
Diffstat (limited to 'generic')
-rw-r--r-- | generic/Reticle.c | 117 |
1 files changed, 102 insertions, 15 deletions
diff --git a/generic/Reticle.c b/generic/Reticle.c index 792bc59..5e701bb 100644 --- a/generic/Reticle.c +++ b/generic/Reticle.c @@ -33,8 +33,7 @@ #include "Geo.h" #include "Draw.h" - -#define /* void */ SQUARE(/* int */ x) ((x) * (x)) +#include <math.h> static const char rcsid[] = "$Id$"; @@ -65,8 +64,8 @@ typedef struct _ReticleItemStruct { /* Private data */ ZnPoint dev; /* item device coordinate */ - ZnDim first_radius_dev; /* first device radius */ - ZnDim step_size_dev; /* steps device size */ + ZnDim first_radius_dev; /* first device radius */ + ZnDim step_size_dev; /* steps device size */ } ReticleItemStruct, *ReticleItem; @@ -251,12 +250,18 @@ ComputeCoordinates(Item item, /* Compute center device coordinates */ ZnTransformPoint(wi->current_transfo, &reticle->pos, &reticle->dev); p.x = reticle->pos.x + reticle->step_size; - p.y = 0; + p.y = reticle->pos.y; ZnTransformPoint(wi->current_transfo, &p, &xp); - reticle->step_size_dev = xp.x - reticle->dev.x; + reticle->step_size_dev = hypot(xp.x - reticle->dev.x, xp.y - reticle->dev.y); p.x = reticle->pos.x + reticle->first_radius; ZnTransformPoint(wi->current_transfo, &p, &xp); - reticle->first_radius_dev = xp.x - reticle->dev.x; + reticle->first_radius_dev = hypot(xp.x - reticle->dev.x, xp.y - reticle->dev.y); + if (reticle->first_radius_dev < 1.0) { + reticle->first_radius_dev = 1.0; + } + if (reticle->step_size_dev < 1.0) { + reticle->step_size_dev = 1.0; + } /* Reticle bounding box is zn bounding box or depends on num_circles */ if (reticle->num_circles == ZN_ANY_CIRCLES) { @@ -317,13 +322,13 @@ Draw(Item item) /* Compute radius max */ l1 = (ZnDim) hypot(wi->damaged_area.orig.x - reticle->dev.x, - wi->damaged_area.orig.y - reticle->dev.y); + wi->damaged_area.orig.y - reticle->dev.y); l2 = (ZnDim) hypot(wi->damaged_area.corner.x - reticle->dev.x, - wi->damaged_area.orig.y - reticle->dev.y); + wi->damaged_area.orig.y - reticle->dev.y); l3 = (ZnDim) hypot(wi->damaged_area.orig.x - reticle->dev.x, - wi->damaged_area.corner.y - reticle->dev.y); + wi->damaged_area.corner.y - reticle->dev.y); l4 = (ZnDim) hypot(wi->damaged_area.corner.x - reticle->dev.x, - wi->damaged_area.corner.y - reticle->dev.y); + wi->damaged_area.corner.y - reticle->dev.y); radius_max_dev = MAX(MAX(l1,l2), MAX(l3, l4)); if (reticle->num_circles > 0) { @@ -332,7 +337,7 @@ Draw(Item item) } while (radius <= radius_max_dev) { - SetLineStyle(wi->dpy, wi->gc, reticle->line_style); + SetLineStyle(wi, reticle->line_style); values.foreground = ZnPixel(reticle->line_color); values.line_width = 0; values.fill_style = FillSolid; @@ -355,7 +360,7 @@ Draw(Item item) (reticle->dev.x <= wi->damaged_area.corner.x + radius) && (reticle->dev.y >= wi->damaged_area.orig.y - radius) && (reticle->dev.y <= wi->damaged_area.corner.y + radius)) { - SetLineStyle(wi->dpy, wi->gc, reticle->bright_line_style); + SetLineStyle(wi, reticle->bright_line_style); values.foreground = ZnPixel(reticle->bright_line_color); values.line_width = 0; values.fill_style = FillSolid; @@ -381,9 +386,91 @@ Draw(Item item) static void Render(Item item) { - /*WidgetInfo *wi = item->wi; - ReticleItem reticle = (ReticleItem) item;*/ +#ifdef GLX + WidgetInfo *wi = item->wi; + ReticleItem reticle = (ReticleItem) item; + ZnDim radius = reticle->first_radius_dev; + ZnDim radius_max_dev, new, x, y, xo, yo; + unsigned int i, j; + ZnPoint *genarc; + int num_p; + + xo = reticle->dev.x; + yo = reticle->dev.y; + /* Compute radius max */ + radius_max_dev = 0; + x = wi->damaged_area.orig.x - xo; + y = wi->damaged_area.orig.y - yo; + new = x*x + y*y; + if (new > radius_max_dev) { + radius_max_dev = new; + } + x = wi->damaged_area.corner.x - xo; + y = wi->damaged_area.orig.y - yo; + new = x*x + y*y; + if (new > radius_max_dev) { + radius_max_dev = new; + } + x = wi->damaged_area.orig.x - xo; + y = wi->damaged_area.corner.y - yo; + new = x*x + y*y; + if (new > radius_max_dev) { + radius_max_dev = new; + } + x = wi->damaged_area.corner.x - xo; + y = wi->damaged_area.corner.y - yo; + new = x*x + y*y; + if (new > radius_max_dev) { + radius_max_dev = new; + } + radius_max_dev = sqrt(radius_max_dev); + if (reticle->num_circles > 0) { + radius_max_dev = MIN(radius_max_dev, reticle->first_radius_dev + + (reticle->num_circles - 1) * reticle->step_size_dev); + } + + genarc = GetCirclePoints(3, ZN_CIRCLE_FINEST, 0, 360, &num_p, NULL); + glLineWidth(1); + while (radius <= radius_max_dev) { + SetLineStyle(wi, reticle->line_style); + glColor4us(reticle->line_color->red, reticle->line_color->green, + reticle->line_color->blue, 65535); + for (i = 1; (radius <= radius_max_dev && i < reticle->period); i++) { + if ((xo >= wi->damaged_area.orig.x - radius) && + (xo <= wi->damaged_area.corner.x + radius) && + (yo >= wi->damaged_area.orig.y - radius) && + (yo <= wi->damaged_area.corner.y + radius)) { + glBegin(GL_LINE_LOOP); + for (j = 0; j < num_p; j++) { + x = xo + genarc[j].x * radius; + y = yo + genarc[j].y * radius; + glVertex2f(x, y); + } + glEnd(); + } + radius += (reticle->step_size_dev); + } + if ((radius <= radius_max_dev) && + (xo >= wi->damaged_area.orig.x - radius) && + (xo <= wi->damaged_area.corner.x + radius) && + (yo >= wi->damaged_area.orig.y - radius) && + (yo <= wi->damaged_area.corner.y + radius)) { + SetLineStyle(wi, reticle->bright_line_style); + glColor4us(reticle->bright_line_color->red, reticle->bright_line_color->green, + reticle->bright_line_color->blue, 65535); + glBegin(GL_LINE_LOOP); + for (j = 0; j < num_p; j++) { + x = xo + genarc[j].x * radius; + y = yo + genarc[j].y * radius; + glVertex2f(x, y); + } + glEnd(); + } + radius += (reticle->step_size_dev); + } + glDisable(GL_LINE_STIPPLE); +#endif } |