aboutsummaryrefslogtreecommitdiff
path: root/generic/Reticle.c
diff options
context:
space:
mode:
authorlecoanet2003-04-16 09:49:22 +0000
committerlecoanet2003-04-16 09:49:22 +0000
commit3261805fee19e346b4d1f84b23816daa1628764a (patch)
tree63ca1d7e4b0a3d9ae49cc0888e58033c3ef3fe22 /generic/Reticle.c
parenteed2656db0adae2c234c3d74af0913746ed5c444 (diff)
downloadtkzinc-3261805fee19e346b4d1f84b23816daa1628764a.zip
tkzinc-3261805fee19e346b4d1f84b23816daa1628764a.tar.gz
tkzinc-3261805fee19e346b4d1f84b23816daa1628764a.tar.bz2
tkzinc-3261805fee19e346b4d1f84b23816daa1628764a.tar.xz
Update from the Windows port and general cleanup/restructure
Diffstat (limited to 'generic/Reticle.c')
-rw-r--r--generic/Reticle.c192
1 files changed, 107 insertions, 85 deletions
diff --git a/generic/Reticle.c b/generic/Reticle.c
index 9fa9616..4855499 100644
--- a/generic/Reticle.c
+++ b/generic/Reticle.c
@@ -41,6 +41,17 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ "
/*
+ * Draw as many circles as visible.
+ */
+#define ANY_CIRCLES -1
+
+/*
+ * Some default values.
+ */
+#define DEFAULT_RETICLE_STEP_SIZE 80
+#define DEFAULT_RETICLE_PERIOD 5
+
+/*
**********************************************************************************
*
* Specific Reticle item record
@@ -49,7 +60,7 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ "
*/
typedef struct _ReticleItemStruct {
- ItemStruct header;
+ ZnItemStruct header;
/* Public data */
ZnPoint pos; /* Origin world coordinates */
@@ -59,8 +70,8 @@ typedef struct _ReticleItemStruct {
ZnDim step_size; /* step world size */
int period; /* bright circle period */
int num_circles; /* num cercles max */
- LineStyle line_style; /* circles lines styles */
- LineStyle bright_line_style;
+ ZnLineStyle line_style; /* circles lines styles */
+ ZnLineStyle bright_line_style;
/* Private data */
ZnPoint dev; /* item device coordinate */
@@ -75,13 +86,13 @@ static ZnAttrConfig reticle_attrs[] = {
{ ZN_CONFIG_LINE_STYLE, "-brightlinestyle", NULL,
Tk_Offset(ReticleItemStruct, bright_line_style), 0, ZN_DRAW_FLAG, False },
{ ZN_CONFIG_BOOL, "-composealpha", NULL,
- Tk_Offset(ReticleItemStruct, header.flags), COMPOSE_ALPHA_BIT,
+ Tk_Offset(ReticleItemStruct, header.flags), ZN_COMPOSE_ALPHA_BIT,
ZN_DRAW_FLAG, False },
{ ZN_CONFIG_BOOL, "-composerotation", NULL,
- Tk_Offset(ReticleItemStruct, header.flags), COMPOSE_ROTATION_BIT,
+ Tk_Offset(ReticleItemStruct, header.flags), ZN_COMPOSE_ROTATION_BIT,
ZN_COORDS_FLAG, False },
{ ZN_CONFIG_BOOL, "-composescale", NULL,
- Tk_Offset(ReticleItemStruct, header.flags), COMPOSE_SCALE_BIT,
+ Tk_Offset(ReticleItemStruct, header.flags), ZN_COMPOSE_SCALE_BIT,
ZN_COORDS_FLAG, False },
{ ZN_CONFIG_DIM, "-stepsize", NULL,
Tk_Offset(ReticleItemStruct, step_size), 0,
@@ -105,15 +116,15 @@ static ZnAttrConfig reticle_attrs[] = {
Tk_Offset(ReticleItemStruct, header.priority), 0,
ZN_DRAW_FLAG|ZN_REPICK_FLAG, False },
{ ZN_CONFIG_BOOL, "-sensitive", NULL,
- Tk_Offset(ReticleItemStruct, header.flags), SENSITIVE_BIT,
+ Tk_Offset(ReticleItemStruct, header.flags), ZN_SENSITIVE_BIT,
ZN_REPICK_FLAG, False },
{ ZN_CONFIG_TAG_LIST, "-tags", NULL,
Tk_Offset(ReticleItemStruct, header.tags), 0, 0, False },
{ ZN_CONFIG_BOOL, "-visible", NULL,
- Tk_Offset(ReticleItemStruct, header.flags), VISIBLE_BIT,
+ Tk_Offset(ReticleItemStruct, header.flags), ZN_VISIBLE_BIT,
ZN_DRAW_FLAG|ZN_REPICK_FLAG|ZN_VIS_FLAG, False },
- { ZN_CONFIG_END, NULL, NULL, 0, 0, 0 }
+ { ZN_CONFIG_END, NULL, NULL, 0, 0, 0, False }
};
@@ -125,28 +136,28 @@ static ZnAttrConfig reticle_attrs[] = {
**********************************************************************************
*/
static int
-Init(Item item,
- int *argc,
- Tcl_Obj *CONST *args[])
+Init(ZnItem item,
+ int *argc __unused,
+ Tcl_Obj *CONST *args[] __unused)
{
ReticleItem reticle = (ReticleItem) item;
- WidgetInfo *wi = item->wi;
+ ZnWInfo *wi = item->wi;
- SET(item->flags, VISIBLE_BIT);
- CLEAR(item->flags, SENSITIVE_BIT);
- SET(item->flags, COMPOSE_ALPHA_BIT);
- SET(item->flags, COMPOSE_ROTATION_BIT);
- SET(item->flags, COMPOSE_SCALE_BIT);
- item->priority = DEFAULT_RETICLE_PRIORITY;
+ SET(item->flags, ZN_VISIBLE_BIT);
+ CLEAR(item->flags, ZN_SENSITIVE_BIT);
+ SET(item->flags, ZN_COMPOSE_ALPHA_BIT);
+ SET(item->flags, ZN_COMPOSE_ROTATION_BIT);
+ SET(item->flags, ZN_COMPOSE_SCALE_BIT);
+ item->priority = 0;
item->part_sensitive = 0;
reticle->line_color = ZnGetGradientByValue(wi->fore_color);
reticle->bright_line_color = ZnGetGradientByValue(wi->fore_color);
reticle->first_radius = DEFAULT_RETICLE_STEP_SIZE;
reticle->step_size = DEFAULT_RETICLE_STEP_SIZE;
reticle->period = DEFAULT_RETICLE_PERIOD;
- reticle->num_circles = ZN_ANY_CIRCLES;
- reticle->line_style = LINE_SIMPLE;
- reticle->bright_line_style = LINE_SIMPLE;
+ reticle->num_circles = ANY_CIRCLES;
+ reticle->line_style = ZN_LINE_SIMPLE;
+ reticle->bright_line_style = ZN_LINE_SIMPLE;
reticle->pos.x = 0;
reticle->pos.y = 0;
reticle->dev.x = 0;
@@ -154,7 +165,7 @@ Init(Item item,
reticle->first_radius_dev = 0;
reticle->step_size_dev = 0;
- return ZN_OK;
+ return TCL_OK;
}
@@ -166,7 +177,7 @@ Init(Item item,
**********************************************************************************
*/
static void
-Clone(Item item)
+Clone(ZnItem item)
{
ReticleItem reticle = (ReticleItem) item;
@@ -183,7 +194,7 @@ Clone(Item item)
**********************************************************************************
*/
static void
-Destroy(Item item)
+Destroy(ZnItem item)
{
ReticleItem reticle = (ReticleItem) item;
@@ -200,17 +211,17 @@ Destroy(Item item)
**********************************************************************************
*/
static int
-Configure(Item item,
+Configure(ZnItem item,
int argc,
Tcl_Obj *CONST argv[],
int *flags)
{
if (ZnConfigureAttributes(item->wi, item, reticle_attrs,
- argc, argv, flags) == ZN_ERROR) {
- return ZN_ERROR;
+ argc, argv, flags) == TCL_ERROR) {
+ return TCL_ERROR;
}
- return ZN_OK;
+ return TCL_OK;
}
@@ -222,15 +233,15 @@ Configure(Item item,
**********************************************************************************
*/
static int
-Query(Item item,
- int argc,
+Query(ZnItem item,
+ int argc __unused,
Tcl_Obj *CONST argv[])
{
- if (ZnQueryAttribute(item->wi, item, reticle_attrs, argv[0]) == ZN_ERROR) {
- return ZN_ERROR;
+ if (ZnQueryAttribute(item->wi, item, reticle_attrs, argv[0]) == TCL_ERROR) {
+ return TCL_ERROR;
}
- return ZN_OK;
+ return TCL_OK;
}
@@ -242,10 +253,10 @@ Query(Item item,
**********************************************************************************
*/
static void
-ComputeCoordinates(Item item,
- ZnBool force)
+ComputeCoordinates(ZnItem item,
+ ZnBool force __unused)
{
- WidgetInfo *wi = item->wi;
+ ZnWInfo *wi = item->wi;
ReticleItem reticle = (ReticleItem) item;
ZnDim half_width;
ZnPoint p, xp;
@@ -267,7 +278,7 @@ ComputeCoordinates(Item item,
}
/* Reticle bounding box is zn bounding box or depends on num_circles */
- if (reticle->num_circles == ZN_ANY_CIRCLES) {
+ if (reticle->num_circles == ANY_CIRCLES) {
item->item_bounding_box.orig.x = 0;
item->item_bounding_box.orig.y = 0;
item->item_bounding_box.corner.x = wi->width;
@@ -294,8 +305,8 @@ ComputeCoordinates(Item item,
**********************************************************************************
*/
static int
-ToArea(Item item,
- ZnToArea ta)
+ToArea(ZnItem item __unused,
+ ZnToArea ta __unused)
{
return -1;
}
@@ -309,14 +320,14 @@ ToArea(Item item,
**********************************************************************************
*/
static void
-Draw(Item item)
+Draw(ZnItem item)
{
- WidgetInfo *wi = item->wi;
+ ZnWInfo *wi = item->wi;
ReticleItem reticle = (ReticleItem) item;
ZnDim radius = reticle->first_radius_dev;
ZnDim radius_max_dev;
XGCValues values;
- unsigned int i;
+ int i;
ZnDim l1, l2, l3, l4;
/* int count = 0;*/
@@ -338,18 +349,20 @@ Draw(Item item)
while (radius <= radius_max_dev) {
ZnSetLineStyle(wi, reticle->line_style);
- values.foreground = ZnPixel(ZnGetGradientColor(reticle->line_color, 0, NULL));
+ values.foreground = ZnPixel(ZnGetGradientColor(reticle->line_color, 0.0, NULL));
values.line_width = 0;
values.fill_style = FillSolid;
XChangeGC(wi->dpy, wi->gc, GCForeground | GCLineWidth | GCFillStyle, &values);
- for (i = 1; (radius <= radius_max_dev && i < reticle->period); i++) {
+ for (i = 1; ((radius <= radius_max_dev) && (i < reticle->period)); i++) {
if ((reticle->dev.x >= wi->damaged_area.orig.x - radius) &&
(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)) {
XDrawArc(wi->dpy, wi->draw_buffer, wi->gc,
- reticle->dev.x - (ZnPos) radius, reticle->dev.y - (ZnPos) radius,
- (ZnPos) radius * 2 - 1, (ZnPos) radius * 2 - 1,
+ (int) (reticle->dev.x - radius),
+ (int) (reticle->dev.y - radius),
+ (unsigned int) (radius * 2 - 1),
+ (unsigned int) (radius * 2 - 1),
0, 360 * 64);
/* count++;*/
}
@@ -361,13 +374,16 @@ Draw(Item item)
(reticle->dev.y >= wi->damaged_area.orig.y - radius) &&
(reticle->dev.y <= wi->damaged_area.corner.y + radius)) {
ZnSetLineStyle(wi, reticle->bright_line_style);
- values.foreground = ZnPixel(ZnGetGradientColor(reticle->bright_line_color, 0, NULL));
+ values.foreground = ZnPixel(ZnGetGradientColor(reticle->bright_line_color, 0.0, NULL));
values.line_width = 0;
values.fill_style = FillSolid;
XChangeGC(wi->dpy, wi->gc, GCForeground | GCLineWidth | GCFillStyle, &values);
XDrawArc(wi->dpy, wi->draw_buffer, wi->gc,
- reticle->dev.x - (ZnPos) radius, reticle->dev.y - (ZnPos) radius,
- (ZnPos) radius * 2 - 1, (ZnPos) radius * 2 - 1, 0, 360 * 64);
+ (int) (reticle->dev.x - radius),
+ (int) (reticle->dev.y - radius),
+ (unsigned int) (radius * 2 - 1),
+ (unsigned int) (radius * 2 - 1),
+ 0, 360 * 64);
/*count++;*/
}
radius += (reticle->step_size_dev);
@@ -383,17 +399,18 @@ Draw(Item item)
*
**********************************************************************************
*/
+#ifdef GL
static void
-Render(Item item)
+Render(ZnItem item)
{
-#ifdef GLX
- WidgetInfo *wi = item->wi;
+ ZnWInfo *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;
+ int i, j;
ZnPoint *genarc;
- int num_p, alpha;
+ int num_p;
+ unsigned short alpha;
XColor *color;
xo = reticle->dev.x;
@@ -431,14 +448,14 @@ Render(Item item)
(reticle->num_circles - 1) * reticle->step_size_dev);
}
- genarc = GetCirclePoints(3, ZN_CIRCLE_FINEST, 0, 2*M_PI, &num_p, NULL);
- glLineWidth(1);
+ genarc = ZnGetCirclePoints(3, ZN_CIRCLE_FINEST, 0.0, 2*M_PI, &num_p, NULL);
+ glLineWidth(1.0);
while (radius <= radius_max_dev) {
ZnSetLineStyle(wi, reticle->line_style);
- color = ZnGetGradientColor(reticle->line_color, 0, &alpha);
+ color = ZnGetGradientColor(reticle->line_color, 0.0, &alpha);
alpha = ZnComposeAlpha(alpha, wi->alpha);
glColor4us(color->red, color->green, color->blue, alpha);
- for (i = 1; (radius <= radius_max_dev && i < reticle->period); i++) {
+ 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) &&
@@ -447,7 +464,7 @@ Render(Item item)
for (j = 0; j < num_p; j++) {
x = xo + genarc[j].x * radius;
y = yo + genarc[j].y * radius;
- glVertex2f(x, y);
+ glVertex2d(x, y);
}
glEnd();
}
@@ -459,22 +476,27 @@ Render(Item item)
(yo >= wi->damaged_area.orig.y - radius) &&
(yo <= wi->damaged_area.corner.y + radius)) {
ZnSetLineStyle(wi, reticle->bright_line_style);
- color = ZnGetGradientColor(reticle->bright_line_color, 0, &alpha);
+ color = ZnGetGradientColor(reticle->bright_line_color, 0.0, &alpha);
alpha = ZnComposeAlpha(alpha, wi->alpha);
glColor4us(color->red, color->green, color->blue, alpha);
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);
+ glVertex2d(x, y);
}
glEnd();
}
radius += (reticle->step_size_dev);
}
glDisable(GL_LINE_STIPPLE);
-#endif
}
+#else
+static void
+Render(ZnItem item __unused)
+{
+}
+#endif
/*
@@ -485,10 +507,10 @@ Render(Item item)
**********************************************************************************
*/
static ZnBool
-IsSensitive(Item item,
- int item_part)
+IsSensitive(ZnItem item,
+ int item_part __unused)
{
- return (ISSET(item->flags, SENSITIVE_BIT) &&
+ return (ISSET(item->flags, ZN_SENSITIVE_BIT) &&
item->parent->class->IsSensitive(item->parent, ZN_NO_PART));
}
@@ -502,8 +524,8 @@ IsSensitive(Item item,
**********************************************************************************
*/
static double
-Pick(Item item,
- ZnPick ps)
+Pick(ZnItem item __unused,
+ ZnPick ps __unused)
{
return 1e40;
}
@@ -518,35 +540,35 @@ Pick(Item item,
**********************************************************************************
*/
static int
-Coords(Item item,
- int contour,
- int index,
- int cmd,
- ZnPoint **pts,
- char **controls,
- int *num_pts)
+Coords(ZnItem item,
+ int contour __unused,
+ int index __unused,
+ int cmd,
+ ZnPoint **pts,
+ char **controls __unused,
+ unsigned int *num_pts)
{
ReticleItem reticle = (ReticleItem) item;
- if ((cmd == COORDS_ADD) || (cmd == COORDS_ADD_LAST) || (cmd == COORDS_REMOVE)) {
+ if ((cmd == ZN_COORDS_ADD) || (cmd == ZN_COORDS_ADD_LAST) || (cmd == ZN_COORDS_REMOVE)) {
Tcl_AppendResult(item->wi->interp,
" reticles can't add or remove vertices", NULL);
- return ZN_ERROR;
+ return TCL_ERROR;
}
- else if ((cmd == COORDS_REPLACE) || (cmd == COORDS_REPLACE_ALL)) {
+ else if ((cmd == ZN_COORDS_REPLACE) || (cmd == ZN_COORDS_REPLACE_ALL)) {
if (*num_pts == 0) {
Tcl_AppendResult(item->wi->interp,
" coords command need 1 point on reticles", NULL);
- return ZN_ERROR;
+ return TCL_ERROR;
}
reticle->pos = (*pts)[0];
- ITEM.Invalidate(item, ZN_COORDS_FLAG);
+ ZnITEM.Invalidate(item, ZN_COORDS_FLAG);
}
- else if ((cmd == COORDS_READ) || (cmd == COORDS_READ_ALL)) {
+ else if ((cmd == ZN_COORDS_READ) || (cmd == ZN_COORDS_READ_ALL)) {
*num_pts = 1;
*pts = &reticle->pos;
}
- return ZN_OK;
+ return TCL_OK;
}
@@ -558,8 +580,8 @@ Coords(Item item,
**********************************************************************************
*/
static void
-PostScript(Item item,
- PostScriptInfo ps_info)
+PostScript(ZnItem item __unused,
+ ZnPostScriptInfo ps_info __unused)
{
}
@@ -571,7 +593,7 @@ PostScript(Item item,
*
**********************************************************************************
*/
-static ItemClassStruct RETICLE_ITEM_CLASS = {
+static ZnItemClassStruct RETICLE_ITEM_CLASS = {
sizeof(ReticleItemStruct),
0, /* num_parts */
False, /* has_anchors */