aboutsummaryrefslogtreecommitdiff
path: root/generic/Map.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/Map.c')
-rw-r--r--generic/Map.c239
1 files changed, 223 insertions, 16 deletions
diff --git a/generic/Map.c b/generic/Map.c
index e5d94ca..ebf4525 100644
--- a/generic/Map.c
+++ b/generic/Map.c
@@ -34,6 +34,7 @@
#include "Draw.h"
#include "WidgetInfo.h"
#include "tkZinc.h"
+#include "Image.h"
#include <memory.h>
#include <malloc.h>
@@ -57,6 +58,7 @@ typedef struct _MapItemStruct {
/* Public data */
ZnBool filled;
+ int alpha;
Pixmap fill_pattern;
ZnColor color;
ZnFont text_font; /* null value -> use zn_map_text_font */
@@ -76,10 +78,15 @@ typedef struct _MapItemStruct {
ZnList marks;
ZnList symbols;
ZnList texts;
+#ifdef GLX
+ TexFont *txf;
+#endif
} MapItemStruct, *MapItem;
static ZnAttrConfig map_attrs[] = {
+ { ZN_CONFIG_ALPHA, "-alpha", NULL,
+ Tk_Offset(MapItemStruct, alpha), 1, ZN_DRAW_FLAG, False },
{ ZN_CONFIG_COLOR, "-color", NULL,
Tk_Offset(MapItemStruct, color), 0, ZN_DRAW_FLAG, False },
{ ZN_CONFIG_BOOL, "-composerotation", NULL,
@@ -202,6 +209,7 @@ Init(Item item,
item->part_sensitive = 0;
item->priority = DEFAULT_MAP_PRIORITY;
map->filled = False;
+ map->alpha = 100;
map->fill_pattern = ZnUnspecifiedPattern;
map->symbol_patterns = NULL;
map->color = ZnGetColorByValue(wi->win, wi->fore_color);
@@ -220,7 +228,10 @@ Init(Item item,
map->marks = NULL;
map->symbols = NULL;
map->texts = NULL;
-
+#ifdef GLX
+ map->txf = NULL;
+#endif
+
return ZN_OK;
}
@@ -974,7 +985,7 @@ Draw(Item item)
char *text;
char tmp_str[] = ".";
XGCValues values;
- unsigned int i, cnt, tst = 0;
+ unsigned int i, cnt;
int line_width;
if (map->map_info == NULL) {
@@ -1020,7 +1031,7 @@ Draw(Item item)
else { /* Not filled */
if (ZnListSize(map->vectors)) {
- SetLineStyle(wi->dpy, wi->gc, LINE_SIMPLE);
+ SetLineStyle(wi, LINE_SIMPLE);
values.fill_style = FillSolid;
values.line_width = 0;
XChangeGC(wi->dpy, wi->gc,
@@ -1043,13 +1054,12 @@ Draw(Item item)
}
XDrawLine(wi->dpy, wi->draw_buffer, wi->gc,
points[i].x, points[i].y, points[i+1].x, points[i+1].y);
- tst++;
}
}
}
if (ZnListSize(map->dashed_vectors)) {
- SetLineStyle(wi->dpy, wi->gc, LINE_DASHED);
+ SetLineStyle(wi, LINE_DASHED);
values.fill_style = FillSolid;
values.line_width = 0;
XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values);
@@ -1069,13 +1079,12 @@ Draw(Item item)
}
XDrawLine(wi->dpy, wi->draw_buffer, wi->gc,
points[i].x, points[i].y, points[i+1].x, points[i+1].y);
- tst++;
}
}
}
if (ZnListSize(map->dotted_vectors)) {
- SetLineStyle(wi->dpy, wi->gc, LINE_DOTTED);
+ SetLineStyle(wi, LINE_DOTTED);
values.fill_style = FillSolid;
values.line_width = 0;
XChangeGC(wi->dpy, wi->gc,
@@ -1096,13 +1105,12 @@ Draw(Item item)
}
XDrawLine(wi->dpy, wi->draw_buffer, wi->gc,
points[i].x, points[i].y, points[i+1].x, points[i+1].y);
- tst++;
}
}
}
if (ZnListSize(map->mixed_vectors)) {
- SetLineStyle(wi->dpy, wi->gc, LINE_MIXED);
+ SetLineStyle(wi, LINE_MIXED);
values.fill_style = FillSolid;
values.line_width = 0;
XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values);
@@ -1122,14 +1130,13 @@ Draw(Item item)
}
XDrawLine(wi->dpy, wi->draw_buffer, wi->gc,
points[i].x, points[i].y, points[i+1].x, points[i+1].y);
- tst++;
}
}
}
if (ZnListSize(map->arcs)) {
- SetLineStyle(wi->dpy, wi->gc, LINE_SIMPLE);
+ SetLineStyle(wi, LINE_SIMPLE);
values.fill_style = FillSolid;
values.line_width = 0;
XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values);
@@ -1143,7 +1150,7 @@ Draw(Item item)
if (ZnListSize(map->dashed_arcs)) {
- SetLineStyle(wi->dpy, wi->gc, LINE_DASHED);
+ SetLineStyle(wi, LINE_DASHED);
values.fill_style = FillSolid;
values.line_width = 0;
XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values);
@@ -1158,7 +1165,7 @@ Draw(Item item)
if (ZnListSize(map->dotted_arcs)) {
- SetLineStyle(wi->dpy, wi->gc, LINE_DOTTED);
+ SetLineStyle(wi, LINE_DOTTED);
values.fill_style = FillSolid;
values.line_width = 0;
XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values);
@@ -1173,7 +1180,7 @@ Draw(Item item)
if (ZnListSize(map->mixed_arcs)) {
- SetLineStyle(wi->dpy, wi->gc, LINE_MIXED);
+ SetLineStyle(wi, LINE_MIXED);
values.fill_style = FillSolid;
values.line_width = 0;
XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values);
@@ -1264,8 +1271,208 @@ Draw(Item item)
static void
Render(Item item)
{
- /*WidgetInfo *wi = item->wi;
- MapItem map = (MapItem) item;*/
+#ifdef GLX
+ WidgetInfo *wi = item->wi;
+ MapItem map = (MapItem) item;
+ MapInfoId map_info;
+ ZnPoint *points, p;
+ char *text;
+ char tmp_str[] = ".";
+ unsigned int i, cnt;
+ int line_width, new_width;
+ XColor *color;
+
+ if (map->map_info == NULL) {
+ return;
+ }
+
+ map_info = map->map_info;
+ color = map->color;
+ glColor4us(color->red, color->green, color->blue, map->alpha*65535/100);
+ if (map->filled) {
+ if (ZnListSize(map->vectors) || ZnListSize(map->arcs)) {
+ if (map->fill_pattern != ZnUnspecifiedPattern) { /* Fill stippled */
+ glEnable(GL_POLYGON_STIPPLE);
+ glPolygonStipple(GetBitmapMask(wi->dpy, map->fill_pattern)->pixels);
+ }
+ cnt = ZnListSize(map->vectors);
+ if (cnt) {
+ /* Need to have a tesselated polygon */
+ }
+ if (ZnListSize(map->arcs)) {
+ }
+ glDisable(GL_POLYGON_STIPPLE);
+ }
+ }
+ else { /* Not filled */
+ if (ZnListSize(map->vectors)) {
+ line_width = 1;
+ glLineWidth(line_width);
+ SetLineStyle(wi, LINE_SIMPLE);
+ cnt = ZnListSize(map->vectors);
+ points = ZnListArray(map->vectors);
+ glBegin(GL_LINES);
+ for (i = 0; i < cnt; i += 2) {
+ if (LineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) {
+ MapInfoGetLine(map_info, i/2, NULL, NULL, &new_width, NULL,
+ NULL, NULL, NULL);
+ if (new_width != line_width) {
+ line_width = new_width;
+ glLineWidth(line_width);
+ }
+ glVertex2f(points[i].x, points[i].y);
+ glVertex2f(points[i+1].x, points[i+1].y);
+ }
+ }
+ glEnd();
+ }
+ if (ZnListSize(map->dashed_vectors)) {
+ line_width = 1;
+ glLineWidth(line_width);
+ SetLineStyle(wi, LINE_DASHED);
+ cnt = ZnListSize(map->dashed_vectors);
+ points = ZnListArray(map->dashed_vectors);
+ glBegin(GL_LINES);
+ for (i = 0; i < cnt; i += 2) {
+ if (LineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) {
+ MapInfoGetLine(map_info, i/2, NULL, NULL, &new_width, NULL,
+ NULL, NULL, NULL);
+ if (new_width != line_width) {
+ line_width = new_width;
+ glLineWidth(line_width);
+ }
+ glVertex2f(points[i].x, points[i].y);
+ glVertex2f(points[i+1].x, points[i+1].y);
+ }
+ }
+ glEnd();
+ glDisable(GL_LINE_STIPPLE);
+ }
+ if (ZnListSize(map->dotted_vectors)) {
+ line_width = 1;
+ glLineWidth(line_width);
+ SetLineStyle(wi, LINE_DOTTED);
+ cnt = ZnListSize(map->dotted_vectors);
+ points = ZnListArray(map->dotted_vectors);
+ glBegin(GL_LINES);
+ for (i = 0; i < cnt; i += 2) {
+ if (LineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) {
+ MapInfoGetLine(map_info, i/2, NULL, NULL, &new_width, NULL,
+ NULL, NULL, NULL);
+ if (new_width != line_width) {
+ line_width = new_width;
+ glLineWidth(line_width);
+ }
+ glVertex2f(points[i].x, points[i].y);
+ glVertex2f(points[i+1].x, points[i+1].y);
+ }
+ }
+ glEnd();
+ glDisable(GL_LINE_STIPPLE);
+ }
+ if (ZnListSize(map->mixed_vectors)) {
+ line_width = 1;
+ glLineWidth(line_width);
+ SetLineStyle(wi, LINE_MIXED);
+ cnt = ZnListSize(map->mixed_vectors);
+ points = ZnListArray(map->mixed_vectors);
+ glBegin(GL_LINES);
+ for (i = 0; i < cnt; i += 2) {
+ if (LineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) {
+ MapInfoGetLine(map_info, i/2, NULL, NULL, &new_width, NULL,
+ NULL, NULL, NULL);
+ if (new_width != line_width) {
+ line_width = new_width;
+ glLineWidth(line_width);
+ }
+ glVertex2f(points[i].x, points[i].y);
+ glVertex2f(points[i+1].x, points[i+1].y);
+ }
+ }
+ glEnd();
+ glDisable(GL_LINE_STIPPLE);
+ }
+
+ if (ZnListSize(map->arcs)) {
+ line_width = 1;
+ glLineWidth(line_width);
+ }
+ if (ZnListSize(map->dashed_arcs)) {
+ line_width = 1;
+ glLineWidth(line_width);
+ glLineStipple(1, 0xF0F0);
+ glEnable(GL_LINE_STIPPLE);
+ glDisable(GL_LINE_STIPPLE);
+ }
+ if (ZnListSize(map->dotted_arcs)) {
+ line_width = 1;
+ glLineWidth(line_width);
+ glLineStipple(1, 0x18C3);
+ glEnable(GL_LINE_STIPPLE);
+ glDisable(GL_LINE_STIPPLE);
+ }
+ if (ZnListSize(map->mixed_arcs)) {
+ line_width = 1;
+ glLineWidth(line_width);
+ glLineStipple(1, 0x27FF);
+ glEnable(GL_LINE_STIPPLE);
+ glDisable(GL_LINE_STIPPLE);
+ }
+
+ if (ZnListSize(map->texts)) {
+ if (!map->txf) {
+ map->txf = GetTexFont(wi->win, map->text_font);
+ }
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ glEnable(GL_TEXTURE_2D);
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glBindTexture(GL_TEXTURE_2D, map->txf->texobj);
+ cnt = ZnListSize(map->texts);
+ points = (ZnPoint *) ZnListArray(map->texts);
+ for (i = 0; i < cnt; i++, points++) {
+ glPushMatrix();
+ MapInfoGetText(map_info, i, NULL, NULL, NULL, NULL, NULL, &text);
+ glTranslatef(points->x, points->y, 0.0);
+ txfRenderString(map->txf, text, strlen(text));
+ glPopMatrix();
+ }
+ glDisable(GL_TEXTURE_2D);
+ }
+
+ if (map->symbol_patterns) {
+ Pixmap sym, *syms = ZnListArray(map->symbol_patterns);
+ int w, h, num_syms = ZnListSize(map->symbol_patterns);
+
+ cnt = ZnListSize(map->symbols);
+ points = ZnListArray(map->symbols);
+ for (i = 0; i < cnt; i++) {
+ MapInfoGetSymbol(map_info, i, NULL, NULL, NULL, &(tmp_str[0]));
+ sym = syms[tmp_str[0]%num_syms];
+ if (sym != ZnUnspecifiedPattern) {
+ Tk_SizeOfBitmap(wi->dpy, sym, &w, &h);
+ p.x = points[i].x-(w+1.0)/2.0;
+ p.y = points[i].y-(h+1.0)/2.0;
+ RenderImage(wi, (ImageBits *) GetBitmapTexture(wi->dpy, sym),
+ color, map->alpha, &p);
+ }
+ }
+ }
+
+ if (wi->map_distance_symbol != ZnUnspecifiedPattern) {
+ ImageBits *im_bits = (ImageBits *) GetBitmapTexture(wi->dpy, wi->map_distance_symbol);
+ int w, h;
+
+ Tk_SizeOfBitmap(wi->dpy, wi->map_distance_symbol, &w, &h);
+ cnt = ZnListSize(map->marks);
+ points = ZnListArray(map->marks);
+ for (i = 0; i < cnt; i++, points++) {
+ p.x = points->x-(w+1)/2;
+ p.y = points->y-(h+1)/2;
+ RenderImage(wi, im_bits, color, map->alpha, &p);
+ }
+ }
+ }
+#endif
}