aboutsummaryrefslogtreecommitdiff
path: root/generic
diff options
context:
space:
mode:
authorlecoanet2006-10-17 12:10:05 +0000
committerlecoanet2006-10-17 12:10:05 +0000
commit9c7580c5eeec27f4ce772cee18ea04662cd5a278 (patch)
treef6b408c5c4a03e82ecccfcc6844dd23cd8f0fe63 /generic
parentebe36f9605d87a095beaaec3dcf7179cd55c5d27 (diff)
downloadtkzinc-9c7580c5eeec27f4ce772cee18ea04662cd5a278.zip
tkzinc-9c7580c5eeec27f4ce772cee18ea04662cd5a278.tar.gz
tkzinc-9c7580c5eeec27f4ce772cee18ea04662cd5a278.tar.bz2
tkzinc-9c7580c5eeec27f4ce772cee18ea04662cd5a278.tar.xz
Ported to Mac Os (without X11).
Diffstat (limited to 'generic')
-rw-r--r--generic/Arc.c2
-rw-r--r--generic/Attrs.c6
-rw-r--r--generic/Curve.c8
-rw-r--r--generic/Draw.c2
-rw-r--r--generic/Field.c2
-rw-r--r--generic/Group.c8
-rw-r--r--generic/Item.c27
-rw-r--r--generic/Map.c16
-rw-r--r--generic/MapInfo.c48
-rw-r--r--generic/Rectangle.c2
-rw-r--r--generic/Reticle.c4
-rw-r--r--generic/Track.c6
-rw-r--r--generic/Types.h27
-rw-r--r--generic/perfos.c7
-rw-r--r--generic/perfos.h8
-rw-r--r--generic/tkZinc.c295
-rw-r--r--generic/tkZinc.h10
17 files changed, 309 insertions, 169 deletions
diff --git a/generic/Arc.c b/generic/Arc.c
index adb1656..1e20a41 100644
--- a/generic/Arc.c
+++ b/generic/Arc.c
@@ -733,7 +733,7 @@ Draw(ZnItem item)
ZnSetLineStyle(wi, arc->line_style);
values.foreground = ZnGetGradientPixel(arc->line_color, 0.0);
- values.line_width = (arc->line_width == 1) ? 0 : (int) arc->line_width;
+ values.line_width = (int) arc->line_width;
values.cap_style = CapRound;
values.join_style = JoinRound;
if (arc->line_pattern == ZnUnspecifiedImage) {
diff --git a/generic/Attrs.c b/generic/Attrs.c
index bc64977..7a09597 100644
--- a/generic/Attrs.c
+++ b/generic/Attrs.c
@@ -22,7 +22,11 @@
#include "Geo.h"
#include "WidgetInfo.h"
-#include <GL/glu.h>
+#if defined(MAC_OSX_TK)
+ #include <AGL/glu.h>
+#else
+ #include <GL/glu.h>
+#endif
#include <memory.h>
#include <stdlib.h>
diff --git a/generic/Curve.c b/generic/Curve.c
index 832b125..4c9022b 100644
--- a/generic/Curve.c
+++ b/generic/Curve.c
@@ -24,7 +24,11 @@
#include "Color.h"
#include "tkZinc.h"
-#include <GL/glu.h>
+#if defined(MAC_OSX_TK)
+ #include <AGL/glu.h>
+#else
+ #include <GL/glu.h>
+#endif
#include <ctype.h>
static const char rcsid[] = "$Id$";
@@ -1148,7 +1152,7 @@ Draw(ZnItem item)
else {
ZnSetLineStyle(wi, cv->line_style);
values.foreground = ZnGetGradientPixel(cv->line_color, 0.0);
- values.line_width = (cv->line_width == 1) ? 0 : (int) cv->line_width;
+ values.line_width = (int) cv->line_width;
values.join_style = cv->join_style;
values.cap_style = cv->cap_style;
if (cv->line_pattern == ZnUnspecifiedImage) {
diff --git a/generic/Draw.c b/generic/Draw.c
index b772f5c..b2eb709 100644
--- a/generic/Draw.c
+++ b/generic/Draw.c
@@ -309,7 +309,7 @@ ZnDrawLineShape(ZnWInfo *wi,
*/
ZnSetLineStyle(wi, line_style);
values.foreground = foreground_pixel;
- values.line_width = (line_width == 1) ? 0 : (int) line_width;
+ values.line_width = (int) line_width;
values.fill_style = FillSolid;
values.join_style = JoinRound;
values.cap_style = CapRound;
diff --git a/generic/Field.c b/generic/Field.c
index 395d63b..6026a4d 100644
--- a/generic/Field.c
+++ b/generic/Field.c
@@ -1919,7 +1919,7 @@ DrawField(ZnWInfo *wi,
*/
if (fptr->border_edges != ZN_NO_BORDER) {
values.foreground = ZnGetGradientPixel(fptr->border_color, 0.0);
- values.line_width = 0;
+ values.line_width = 1;
values.line_style = LineSolid;
values.fill_style = FillSolid;
XChangeGC(wi->dpy, wi->gc,
diff --git a/generic/Group.c b/generic/Group.c
index c4fef66..9249adc 100644
--- a/generic/Group.c
+++ b/generic/Group.c
@@ -23,7 +23,7 @@
#include "Geo.h"
#include "tkZinc.h"
-#ifndef _WIN32
+#if defined(SHAPE)
#include <X11/extensions/shape.h>
#endif
@@ -258,7 +258,7 @@ Destroy(ZnItem item)
*
**********************************************************************************
*/
-#if defined(SHAPE) && !defined(_WIN32)
+#if defined(SHAPE)
static void
SetXShape(ZnItem grp)
{
@@ -493,7 +493,7 @@ PushClip(GroupItem group,
if ((group->clip != ZN_NO_ITEM) &&
((((ZnItem) group) != wi->top_group)
-#if defined(SHAPE) && ! defined (_WIN32)
+#if defined(SHAPE)
|| !wi->reshape
#endif
)) {
@@ -522,7 +522,7 @@ PopClip(GroupItem group,
if ((group->clip != ZN_NO_ITEM) &&
((((ZnItem) group) != wi->top_group)
-#if defined(SHAPE) && !defined(_WIN32)
+#if defined(SHAPE)
|| !wi->reshape
#endif
)) {
diff --git a/generic/Item.c b/generic/Item.c
index 10be057..31852f8 100644
--- a/generic/Item.c
+++ b/generic/Item.c
@@ -31,7 +31,11 @@
#include "OverlapMan.h"
#endif
-#include <GL/glu.h>
+#if defined(MAC_OSX_TK)
+ #include <AGL/glu.h>
+#else
+ #include <GL/glu.h>
+#endif
#include <limits.h> /* For INT_MAX */
#include <stdarg.h>
#include <stdio.h>
@@ -2111,6 +2115,7 @@ ZnCurrentClip(ZnWInfo *wi,
return False;
}
+#include "tkMacOSXInt.h"
/*
* If simple is True poly is a pointer to an
* array of two points. In the other case it
@@ -2126,7 +2131,7 @@ ZnPushClip(ZnWInfo *wi,
unsigned int num_pts, max_num_pts;
ZnPoint *p;
ClipState *previous_clip=NULL;
- TkRegion reg, reg_op, reg_to;
+ TkRegion reg, reg_op/*, reg_to*/;
XRectangle rect;
XPoint xpts[3];
@@ -2185,11 +2190,12 @@ ZnPushClip(ZnWInfo *wi,
xpts[2].x = ZnNearestInt(p->x);
xpts[2].y = ZnNearestInt(p->y);
reg_op = (TkRegion) ZnPolygonRegion(xpts, 3, EvenOddRule);
- reg_to = TkCreateRegion();
- ZnUnionRegion(reg, reg_op, reg_to);
- TkDestroyRegion(reg);
+ //reg_to = TkCreateRegion();
+ //ZnUnionRegion(reg, reg_op, reg_to);
+ ZnUnionRegion(reg, reg_op, reg);
+ //TkDestroyRegion(reg);
TkDestroyRegion(reg_op);
- reg = reg_to;
+ //reg = reg_to;
xpts[1] = xpts[2];
}
}
@@ -2204,11 +2210,12 @@ ZnPushClip(ZnWInfo *wi,
xpts[2].x = (short) p->x;
xpts[2].y = (short) p->y;
reg_op = (TkRegion) ZnPolygonRegion(xpts, 3, EvenOddRule);
- reg_to = TkCreateRegion();
- ZnUnionRegion(reg, reg_op, reg_to);
- TkDestroyRegion(reg);
+ //reg_to = TkCreateRegion();
+ //ZnUnionRegion(reg, reg_op, reg_to);
+ ZnUnionRegion(reg, reg_op, reg);
+ //TkDestroyRegion(reg);
TkDestroyRegion(reg_op);
- reg = reg_to;
+ //reg = reg_to;
xpts[0] = xpts[1];
xpts[1] = xpts[2];
}
diff --git a/generic/Map.c b/generic/Map.c
index 37b1549..0ceb966 100644
--- a/generic/Map.c
+++ b/generic/Map.c
@@ -1050,7 +1050,7 @@ Draw(ZnItem item)
if (ZnListSize(map->vectors)) {
ZnSetLineStyle(wi, ZN_LINE_SIMPLE);
values.fill_style = FillSolid;
- values.line_width = 0;
+ values.line_width = 1;
XChangeGC(wi->dpy, wi->gc,
GCFillStyle | GCLineWidth | GCForeground, &values);
@@ -1085,7 +1085,7 @@ Draw(ZnItem item)
if (ZnListSize(map->dashed_vectors)) {
ZnSetLineStyle(wi, ZN_LINE_DASHED);
values.fill_style = FillSolid;
- values.line_width = 0;
+ values.line_width = 1;
XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values);
/* !! WARNING !! XDrawSegments can't handle an unlimited number of segments
@@ -1114,7 +1114,7 @@ Draw(ZnItem item)
if (ZnListSize(map->dotted_vectors)) {
ZnSetLineStyle(wi, ZN_LINE_DOTTED);
values.fill_style = FillSolid;
- values.line_width = 0;
+ values.line_width = 1;
XChangeGC(wi->dpy, wi->gc,
GCFillStyle | GCLineWidth | GCForeground, &values);
@@ -1144,7 +1144,7 @@ Draw(ZnItem item)
if (ZnListSize(map->mixed_vectors)) {
ZnSetLineStyle(wi, ZN_LINE_MIXED);
values.fill_style = FillSolid;
- values.line_width = 0;
+ values.line_width = 1;
XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values);
/* !! WARNING !! XDrawSegments can't handle an unlimited number of segments
@@ -1174,7 +1174,7 @@ Draw(ZnItem item)
ZnSetLineStyle(wi, ZN_LINE_SIMPLE);
values.fill_style = FillSolid;
- values.line_width = 0;
+ values.line_width = 1;
XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values);
arcs = ZnListArray(map->arcs);
cnt = ZnListSize(map->arcs);
@@ -1189,7 +1189,7 @@ Draw(ZnItem item)
ZnSetLineStyle(wi, ZN_LINE_DASHED);
values.fill_style = FillSolid;
- values.line_width = 0;
+ values.line_width = 1;
XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values);
arcs = ZnListArray(map->arcs);
cnt = ZnListSize(map->arcs);
@@ -1204,7 +1204,7 @@ Draw(ZnItem item)
ZnSetLineStyle(wi, ZN_LINE_DOTTED);
values.fill_style = FillSolid;
- values.line_width = 0;
+ values.line_width = 1;
XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values);
arcs = ZnListArray(map->arcs);
cnt = ZnListSize(map->arcs);
@@ -1219,7 +1219,7 @@ Draw(ZnItem item)
ZnSetLineStyle(wi, ZN_LINE_MIXED);
values.fill_style = FillSolid;
- values.line_width = 0;
+ values.line_width = 1;
XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values);
arcs = ZnListArray(map->arcs);
cnt = ZnListSize(map->arcs);
diff --git a/generic/MapInfo.c b/generic/MapInfo.c
index 2af18bd..24678df 100644
--- a/generic/MapInfo.c
+++ b/generic/MapInfo.c
@@ -314,12 +314,7 @@ ZnMapInfoAddLine(ZnMapInfoId map_info,
}
line_struct.style = line_style;
- if (line_width == 1.0) {
- line_struct.width = 0;
- }
- else {
- line_struct.width = (int) line_width;
- }
+ line_struct.width = (int) line_width;
line_struct.tag = tag;
line_struct.from.x = x_from;
line_struct.from.y = y_from;
@@ -357,12 +352,7 @@ ZnMapInfoReplaceLine(ZnMapInfoId map_info,
}
line_ptr->style = line_style;
- if (line_width == 1.0) {
- line_ptr->width = 0;
- }
- else {
- line_ptr->width = (int) line_width;
- }
+ line_ptr->width = (int) line_width;
line_ptr->tag = tag;
line_ptr->from.x = x_from;
line_ptr->from.y = y_from;
@@ -421,12 +411,7 @@ ZnMapInfoGetLine(ZnMapInfoId map_info,
*line_style = line_ptr->style;
}
if (line_width) {
- if (line_ptr->width == 1.0) {
- *line_width = 0;
- }
- else {
- *line_width = line_ptr->width;
- }
+ *line_width = line_ptr->width;
}
if (x_from) {
*x_from = line_ptr->from.x;
@@ -742,12 +727,7 @@ ZnMapInfoAddArc(ZnMapInfoId map_info,
}
arc_struct.style = NOT_MARKED_STYLE(line_style);
- if (line_width == 1.0) {
- arc_struct.width = 0;
- }
- else {
- arc_struct.width = (int) line_width;
- }
+ arc_struct.width = (int) line_width;
arc_struct.tag = tag;
arc_struct.center.x = center_x;
arc_struct.center.y = center_y;
@@ -779,12 +759,7 @@ ZnMapInfoReplaceArc(ZnMapInfoId map_info,
arc_ptr = ZnListAt(cur_map->arcs, index);
if (arc_ptr) {
arc_ptr->style = NOT_MARKED_STYLE(line_style);
- if (line_width == 1.0) {
- arc_ptr->width = 0;
- }
- else {
- arc_ptr->width = (int) line_width;
- }
+ arc_ptr->width = (int) line_width;
arc_ptr->tag = tag;
arc_ptr->center.x = center_x;
arc_ptr->center.y = center_y;
@@ -837,12 +812,7 @@ ZnMapInfoGetArc(ZnMapInfoId map_info,
*line_style = arc_ptr->style;
}
if (line_width) {
- if (arc_ptr->width == 1.0) {
- *line_width = 0;
- }
- else {
- *line_width = arc_ptr->width;
- }
+ *line_width = arc_ptr->width;
}
if (center_x) {
*center_x = arc_ptr->center.x;
@@ -1127,17 +1097,17 @@ FillMap(ZnMapInfoId map,
if (vm->dashed) {
ZnMapInfoAddLine(map, ZnMapInfoNumLines(map), NULL, ZnMapInfoLineDashed,
- 0, x_cur, y_cur,
+ 1, x_cur, y_cur,
(int) (short) vm->x[i], (int) (short) vm->y[i]);
}
else if (vm->marked) {
ZnMapInfoAddLine(map, ZnMapInfoNumLines(map), NULL, ZnMapInfoLineMarked,
- 0, x_cur, y_cur,
+ 1, x_cur, y_cur,
(int) (short) vm->x[i], (int) (short) vm->y[i]);
}
else {
ZnMapInfoAddLine(map, ZnMapInfoNumLines(map), NULL, ZnMapInfoLineSimple,
- 0, x_cur, y_cur,
+ 1, x_cur, y_cur,
(int) (short) vm->x[i], (int) (short) vm->y[i]);
}
diff --git a/generic/Rectangle.c b/generic/Rectangle.c
index 798239a..fbfeca6 100644
--- a/generic/Rectangle.c
+++ b/generic/Rectangle.c
@@ -560,7 +560,7 @@ Draw(ZnItem item)
ZnSetLineStyle(wi, rect->line_style);
gc_mask = GCFillStyle|GCLineWidth|GCForeground|GCJoinStyle;
values.foreground = ZnGetGradientPixel(rect->line_color, 0.0);
- values.line_width = (rect->line_width == 1) ? 0 : (int) rect->line_width;
+ values.line_width = (int) rect->line_width;
values.join_style = JoinMiter;
if (ISCLEAR(rect->flags, ALIGNED_BIT)) {
gc_mask |= GCCapStyle;
diff --git a/generic/Reticle.c b/generic/Reticle.c
index 0c7abe2..72d6a80 100644
--- a/generic/Reticle.c
+++ b/generic/Reticle.c
@@ -343,7 +343,7 @@ Draw(ZnItem item)
while (radius <= radius_max_dev) {
ZnSetLineStyle(wi, reticle->line_style);
values.foreground = ZnGetGradientPixel(reticle->line_color, 0.0);
- values.line_width = 0;
+ values.line_width = 1;
values.fill_style = FillSolid;
XChangeGC(wi->dpy, wi->gc, GCForeground | GCLineWidth | GCFillStyle, &values);
for (i = 1; ((radius <= radius_max_dev) && (i < reticle->period)); i++) {
@@ -368,7 +368,7 @@ Draw(ZnItem item)
(reticle->dev.y <= wi->damaged_area.corner.y + radius)) {
ZnSetLineStyle(wi, reticle->bright_line_style);
values.foreground = ZnGetGradientPixel(reticle->bright_line_color, 0.0);
- values.line_width = 0;
+ values.line_width = 1;
values.fill_style = FillSolid;
XChangeGC(wi->dpy, wi->gc, GCForeground | GCLineWidth | GCFillStyle, &values);
XDrawArc(wi->dpy, wi->draw_buffer, wi->gc,
diff --git a/generic/Track.c b/generic/Track.c
index fd6d33d..86a90b0 100644
--- a/generic/Track.c
+++ b/generic/Track.c
@@ -1171,7 +1171,7 @@ Draw(ZnItem item)
if (track->marker_size_dev != 0) {
ZnSetLineStyle(wi, track->marker_style);
values.foreground = ZnGetGradientPixel(track->marker_color, 0.0);
- values.line_width = 0;
+ values.line_width = 1;
if (ISSET(track->flags, MARKER_FILLED_BIT)) {
if (track->marker_fill_pattern == ZnUnspecifiedImage) {
/* Fill solid */
@@ -1223,7 +1223,7 @@ Draw(ZnItem item)
*/
if ((item->class == ZnTrack) && (track->speed_vector_width > 0)) {
values.foreground = ZnGetGradientPixel(track->speed_vector_color, 0.0);
- values.line_width = (int) (track->speed_vector_width > 1 ? track->speed_vector_width : 0);
+ values.line_width = (int) track->speed_vector_width;
values.line_style = LineSolid;
values.fill_style = FillSolid;
XChangeGC(wi->dpy, wi->gc,
@@ -1288,7 +1288,7 @@ Draw(ZnItem item)
values.fill_style = FillSolid;
XChangeGC(wi->dpy, wi->gc, GCForeground|GCFillStyle, &values);
if (ISCLEAR(track->flags, FILLED_HISTORY_BIT)) {
- values.line_width = 0;
+ values.line_width = 1;
values.line_style = LineSolid;
XChangeGC(wi->dpy, wi->gc, GCLineWidth | GCLineStyle, &values);
}
diff --git a/generic/Types.h b/generic/Types.h
index d52128c..f08ca15 100644
--- a/generic/Types.h
+++ b/generic/Types.h
@@ -38,7 +38,12 @@
# ifdef _WIN32
# include <GL/gl.h>
# else
-# include <GL/glx.h>
+# ifdef MAC_OSX_TK
+# include <AGL/agl.h>
+# include <AGL/glu.h>
+# else
+# include <GL/glx.h>
+# endif
# endif
#endif
@@ -170,7 +175,25 @@ TkRegion ZnPolygonRegion(XPoint *points, int n,
# define ZN_GL_LINE_WIDTH_RANGE GL_LINE_WIDTH_RANGE
# define ZN_GL_POINT_SIZE_RANGE GL_POINT_SIZE_RANGE
# endif
-#else /* !_WIN32 */
+
+#elif defined(MAC_OSX_TK)
+
+ZnBool ZnPointInRegion(TkRegion reg, int x, int y);
+void ZnUnionRegion(TkRegion sra, TkRegion srb,
+ TkRegion dr_return);
+void ZnOffsetRegion(TkRegion reg, int dx, int dy);
+TkRegion ZnPolygonRegion(XPoint *points, int n,
+ int fill_rule);
+# ifdef GL
+# define ZnGLContext AGLContext
+# define ZnGLWaitX()
+# define ZnGLWaitGL()
+# define ZN_GL_LINE_WIDTH_RANGE GL_SMOOTH_LINE_WIDTH_RANGE
+# define ZN_GL_POINT_SIZE_RANGE GL_SMOOTH_POINT_SIZE_RANGE
+# endif
+
+#else /* Other unices and X11 */
+
# define ZnPointInRegion(reg, x, y) \
XPointInRegion((Region) reg, x, y)
# define ZnPolygonRegion(points, npoints, fillrule) \
diff --git a/generic/perfos.c b/generic/perfos.c
index 77d19a4..1da2295 100644
--- a/generic/perfos.c
+++ b/generic/perfos.c
@@ -19,10 +19,15 @@
#include "perfos.h"
#include "List.h"
-#include "Types.h"
#include <X11/Xutil.h>
+#include <stdio.h>
+#include <math.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/times.h>
+
static const char rcsid[] = "$Id$";
static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " $";
diff --git a/generic/perfos.h b/generic/perfos.h
index fb54bf5..ecd0bfb 100644
--- a/generic/perfos.h
+++ b/generic/perfos.h
@@ -25,12 +25,8 @@ extern "C" {
#ifndef _WIN32
-#include <stdio.h>
-#include <math.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/times.h>
-#include <X11/Xlib.h>
+#include "Types.h"
+
typedef struct
{
diff --git a/generic/tkZinc.c b/generic/tkZinc.c
index 736cebd..f014aee 100644
--- a/generic/tkZinc.c
+++ b/generic/tkZinc.c
@@ -49,7 +49,6 @@ static const char * const zinc_version = "zinc-version-" VERSION;
#include "perfos.h"
#endif
-#include <GL/glu.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
@@ -59,6 +58,10 @@ static const char * const zinc_version = "zinc-version-" VERSION;
#if defined(_WIN32) && defined(PTK) && !defined(PTK_800)
#include <tkPlatDecls.m>
#endif
+#if defined(MAC_OSX_TK) && defined(GL)
+#include <tkMacOSX.h>
+#include <tkMacOSXInt.h>
+#endif
typedef struct _TagSearchExpr {
@@ -123,7 +126,18 @@ static Tk_Uid star_uid;
#ifdef GL
static ZnGLContextEntry *gl_contexts = NULL;
-#ifndef _WIN32
+#if defined(MAC_OSX_TK)
+static GLint ZnGLAttribs[] = {
+ AGL_RGBA,
+ AGL_DOUBLEBUFFER,
+ AGL_RED_SIZE, 8,
+ AGL_GREEN_SIZE, 8,
+ AGL_BLUE_SIZE, 8,
+ AGL_STENCIL_SIZE, 8,
+ AGL_DEPTH_SIZE, 0,
+ AGL_NONE
+};
+#elif !defined(_WIN32)
static int ZnMajorGlx, ZnMinorGlx;
static int ZnGLAttribs[] = {
GLX_RGBA,
@@ -900,19 +914,37 @@ ZnNeedRedisplay(ZnWInfo *wi)
*
* ZnGetGlContext --
*
+ * On AGL there is one context per window/widget. The Oldest context
+ * is used to share the resources until it is destroyed, this task is
+ * then transferred to the next older and so on.
+ * On the other platforms a single context is created and shared
+ * amongst all the windows for a sinlge display.
+ *
*----------------------------------------------------------------------
*/
#ifdef GL
ZnGLContextEntry *
ZnGetGLContext(Display *dpy)
{
- ZnGLContextEntry *context_entry;
+ ZnGLContextEntry *cur, *last;
- for (context_entry = gl_contexts;
- context_entry && context_entry->dpy != dpy;
- context_entry = context_entry->next);
+ //
+ // Find the first context matching.
+ for (cur = gl_contexts; cur && cur->dpy != dpy; cur = cur->next);
+
+ if (!cur) {
+ return cur;
+ }
- return context_entry;
+ //
+ // Now proceed to the oldest.
+ for (last = cur; cur->next; cur = cur->next) {
+ if (cur->dpy == dpy) {
+ last = cur;
+ }
+ }
+
+ return last;
}
ZnGLContextEntry *
@@ -954,6 +986,10 @@ ZnGLMakeCurrent(Display *dpy,
if (!wglMakeCurrent(ce->hdc, ce->context)) {
fprintf(stderr, "Can't make the GL context current: %d\n", GetLastError());
}
+#elif defined(MAC_OSX_TK)
+ if (aglSetCurrentContext(ce->context) == GL_FALSE) {
+ fprintf(stderr, "Can't make the GL context current\n");
+ }
#else
glXMakeCurrent(dpy, Tk_WindowId(wi->win), ce->context);
#endif
@@ -980,6 +1016,8 @@ ZnGLSwapBuffers(ZnGLContextEntry *ce,
if (ce) {
#ifdef _WIN32
SwapBuffers(ce->hdc);
+#elif defined(MAC_OSX_TK)
+ aglSwapBuffers(ce->context);
#else
glXSwapBuffers(ce->dpy, Tk_WindowId(wi->win));
#endif
@@ -994,8 +1032,8 @@ InitRendering1(ZnWInfo *wi)
{
if (wi->render) {
-# ifndef _WIN32
- ZnGLContextEntry *ce;
+# if !defined(_WIN32) && !defined(MAC_OSX_TK)
+ ZnGLContextEntry *ce;
ZnGLContext gl_context;
XVisualInfo *gl_visual = NULL;
Colormap colormap = 0;
@@ -1075,24 +1113,45 @@ InitRendering1(ZnWInfo *wi)
if (gl_visual && colormap) {
Tk_SetWindowVisual(wi->win, gl_visual->visual, 24, colormap);
}
-# endif /* _WIN32 */
+# endif
}
}
+#if defined(MAC_OSX_TK)
static void
-InitRendering2(ZnWInfo *wi)
+UpdateBufferRect(ZnGLContextEntry *ce,
+ Tk_Window win)
{
- ZnGLContextEntry *ce;
- ZnGLContext gl_context;
- GLfloat r[2]; /* Min, Max */
- GLint i[1];
+ GLint rect[4];
+ Rect bounds;
+
+ TkMacOSXWinBounds((TkWindow *) win, &bounds);
+ rect[0] = bounds.left;
+ rect[1] = Tk_Height(ce->top_win) - bounds.bottom;
+ rect[2] = bounds.right - bounds.left;
+ rect[3] = bounds.bottom - bounds.top;;
+ //printf("BUFFER_RECT: %d %d %d %d\n", rect[0], rect[1], rect[2], rect[3]);
+ aglSetInteger(ce->context, AGL_BUFFER_RECT, rect);
+ aglEnable(ce->context, AGL_BUFFER_RECT);
+}
+#endif
+
+static void
+InitRendering2(ZnWInfo *wi,
+ Tk_Window top_level)
+{
+ ZnGLContextEntry *ce;
+ ZnGLContext gl_context;
+ GLfloat r[2]; /* Min, Max */
+ GLint i[1];
if (wi->render) {
-# ifdef _WIN32
/*
* Look for a matching context already available.
*/
ce = ZnGetGLContext(wi->dpy);
+
+# ifdef _WIN32
if (ce) {
gl_context = ce->context;
ce->hwnd = Tk_GetHWND(Tk_WindowId(wi->win));
@@ -1151,6 +1210,48 @@ InitRendering2(ZnWInfo *wi)
}
}
ReleaseDC(ce->hwnd, ce->hdc);
+
+#elif defined(MAC_OSX_TK)
+
+ {
+ AGLPixelFormat pix_fmt;
+ GLenum err;
+
+ pix_fmt = aglChoosePixelFormat(NULL, 0, ZnGLAttribs);
+ err = aglGetError();
+ if (pix_fmt && (err == AGL_NO_ERROR)) {
+ gl_context = aglCreateContext(pix_fmt, ce ? ce->context : NULL);
+ err = aglGetError();
+ }
+ else {
+ fprintf(stderr, "error when selecting a pixel format 0x%x %d\n", pix_fmt, err);
+ return;
+ }
+ if ((err != AGL_NO_ERROR) || (gl_context == NULL)) {
+ fprintf(stderr, "No GL context\n");
+ return;
+ }
+ else {
+ ce = ZnMalloc(sizeof(ZnGLContextEntry));
+ ce->widgets = ZnListNew(1, sizeof(ZnWInfo *));
+ ZnListAdd(ce->widgets, &wi, ZnListTail);
+
+ ce->context = gl_context;
+ ce->dpy = wi->dpy;
+ ce->max_tex_size = 64; /* Minimum value is always valid */
+ ce->max_line_width = 1;
+ ce->max_point_width = 1;
+ ce->next = gl_contexts;
+ gl_contexts = ce;
+ ce->pix_fmt = pix_fmt;
+ ce->gworld = TkMacOSXGetDrawablePort(Tk_WindowId(wi->win));
+ ce->top_win = top_level;
+ if (aglSetDrawable(ce->context, ce->gworld) == GL_FALSE) {
+ fprintf(stderr, "Can't attach the window to the GL context\n");
+ }
+ }
+ }
+
#endif
ce = ZnGLMakeCurrent(wi->dpy, wi);
@@ -1178,6 +1279,9 @@ InitRendering2(ZnWInfo *wi)
ce->max_tex_size);
}
+#if defined(MAC_OSX_TK)
+ UpdateBufferRect(ce, wi->win);
+#endif
ZnGLReleaseContext(ce);
}
}
@@ -1209,7 +1313,7 @@ ZincObjCmd(ClientData client_data, /* Main window associated with
#endif
unsigned int num;
ZnBool has_gl = False;
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(MAC_OSX_TK)
# if defined(GL) || defined(SHAPE)
int major_op, first_err, first_evt;
# endif
@@ -1222,7 +1326,7 @@ ZincObjCmd(ClientData client_data, /* Main window associated with
InitZinc(interp);
#ifdef GL
-# ifdef _WIN32
+# if defined(_WIN32) || defined(MAC_OSX_TK)
has_gl = True;
# else
if (XQueryExtension(dpy, "GLX", &major_op, &first_evt, &first_err)) {
@@ -1287,7 +1391,7 @@ ZincObjCmd(ClientData client_data, /* Main window associated with
wi->real_top = None;
ASSIGN(wi->flags, ZN_HAS_GL, has_gl);
-#if defined(SHAPE) && !defined(_WIN32)
+#if defined(SHAPE)
ASSIGN(wi->flags, ZN_HAS_X_SHAPE,
XQueryExtension(wi->dpy, "SHAPE", &major_op, &first_evt, &first_err));
wi->reshape = wi->full_reshape = True;
@@ -2643,7 +2747,7 @@ LayoutItems(ZnWInfo *wi,
/*
*----------------------------------------------------------------------
*
- * SetOrigin --
+ * ZnSetOrigin --
*
* This procedure is invoked to translate the viewed area so
* that the given point is displayed in the top left corner.
@@ -2661,9 +2765,9 @@ LayoutItems(ZnWInfo *wi,
*----------------------------------------------------------------------
*/
static void
-SetOrigin(ZnWInfo *wi,
- ZnReal x_origin,
- ZnReal y_origin)
+ZnSetOrigin(ZnWInfo *wi,
+ ZnReal x_origin,
+ ZnReal y_origin)
{
int left, right, top, bottom, delta;
@@ -6490,7 +6594,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget.
}
break;
}
- SetOrigin(wi, new_x, wi->origin.y);
+ ZnSetOrigin(wi, new_x, wi->origin.y);
}
break;
}
@@ -6534,7 +6638,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget.
}
break;
}
- SetOrigin(wi, wi->origin.x, new_y);
+ ZnSetOrigin(wi, wi->origin.x, new_y);
}
break;
}
@@ -6783,7 +6887,7 @@ Configure(Tcl_Interp *interp,/* Used for error reporting. */
if (CONFIG_PROBE(SCROLL_REGION_SPEC) ||
CONFIG_PROBE(CONFINE_SPEC)) {
- SetOrigin(wi, wi->origin.x, wi->origin.y);
+ ZnSetOrigin(wi, wi->origin.x, wi->origin.y);
SET(wi->flags, ZN_UPDATE_SCROLLBARS);
}
@@ -6900,7 +7004,7 @@ Configure(Tcl_Interp *interp,/* Used for error reporting. */
}
if ((mask & CONFIG_SET_ORIGIN) || init) {
- SetOrigin(wi, wi->origin.x, wi->origin.y);
+ ZnSetOrigin(wi, wi->origin.x, wi->origin.y);
SET(wi->flags, ZN_UPDATE_SCROLLBARS);
}
@@ -7184,75 +7288,82 @@ TopEvent(ClientData client_data, /* Information about widget. */
}
static void
-Event(ClientData client_data, /* Information about widget. */
- XEvent *event) /* Information about event. */
+FinishSetup(ZnWInfo *wi)
{
- ZnWInfo *wi = (ZnWInfo *) client_data;
- XGCValues values;
- ZnBBox bbox;
+ XGCValues values;
+ Tk_Window top_level;
- /*printf("=============== DEBUT %s %d EVENT ==================\n",
- event->type == MapNotify ? "MAP":
- event->type == Expose? "EXPOSE" :
- event->type == ConfigureNotify ? "CONFIGURE" :
- event->type == VisibilityNotify ? "VISIBILITY" :
- event->type == DestroyNotify ? "DESTROY" :
- "??", event->type);*/
- if (event->type == MapNotify) {
- SET(wi->flags, ZN_CONFIGURE_EVENT);
- if (!wi->gc) {
- SET(wi->flags, ZN_REALIZED);
+ if (!wi->gc) {
+ SET(wi->flags, ZN_REALIZED);
+ top_level = wi->win;
+ while (!Tk_IsTopLevel(top_level)) {
+ top_level = Tk_Parent(top_level);
+ }
#ifdef GL
- InitRendering2(wi);
+ InitRendering2(wi, top_level);
#endif
- /*
- * Get the work GC and suppress GraphicExpose
- * and NoExpose events reception.
- */
- wi->gc = XCreateGC(wi->dpy, Tk_WindowId(wi->win), 0, NULL);
- values.graphics_exposures = False;
- XChangeGC(wi->dpy, wi->gc, GCGraphicsExposures, &values);
+ /*
+ * Get the work GC and suppress GraphicExpose
+ * and NoExpose events reception.
+ */
+ wi->gc = XCreateGC(wi->dpy, Tk_WindowId(wi->win), 0, NULL);
+ values.graphics_exposures = False;
+ XChangeGC(wi->dpy, wi->gc, GCGraphicsExposures, &values);
+ /*
+ * Set the real top window above us.
+ */
+ {
+ Window parent, root, *children=NULL;
+ int num_children, success;
+
+ success = XQueryTree(wi->dpy, Tk_WindowId(top_level), &root, &parent,
+ &children, &num_children);
+ if (!success || (root == parent)) {
+ wi->real_top = Tk_WindowId(top_level);
+ }
+ else {
+ wi->real_top = parent;
+ }
/*
- * Set the real top window above us.
+ * Needed under glx to suspend update with scissors after
+ * a move to synchronise the two buffers. Fix a refresh
+ * bug when the window is partially clipped by the display
+ * border. Can be usefull under Windows too.
*/
- {
- Window parent, root, *children=NULL;
- Tk_Window top_level;
- int num_children, success;
-
- top_level = wi->win;
- while (!Tk_IsTopLevel(top_level)) {
- top_level = Tk_Parent(top_level);
- }
- success = XQueryTree(wi->dpy, Tk_WindowId(top_level), &root, &parent,
- &children, &num_children);
- if (!success || (root == parent)) {
- wi->real_top = Tk_WindowId(top_level);
- }
- else {
- wi->real_top = parent;
- }
- /*
- * Needed under glx to suspend update with scissors after
- * a move to synchronise the two buffers. Fix a refresh
- * bug when the window is partially clipped by the display
- * border. Can be usefull under Windows too.
- */
- Tk_CreateEventHandler(top_level, StructureNotifyMask, TopEvent, (ClientData) wi);
- if (children && success) {
- XFree(children);
- }
+ Tk_CreateEventHandler(top_level, StructureNotifyMask, TopEvent, (ClientData) wi);
+ if (children && success) {
+ XFree(children);
}
}
+ }
+}
+
+static void
+Event(ClientData client_data, /* Information about widget. */
+ XEvent *event) /* Information about event. */
+{
+ ZnWInfo *wi = (ZnWInfo *) client_data;
+ ZnBBox bbox;
+
+ //printf("=============== DEBUT %s %d EVENT ==================\n",
+ // event->type == MapNotify ? "MAP":
+ // event->type == Expose? "EXPOSE" :
+ // event->type == ConfigureNotify ? "CONFIGURE" :
+ // event->type == VisibilityNotify ? "VISIBILITY" :
+ // event->type == DestroyNotify ? "DESTROY" :
+ // "??", event->type);
+ if (event->type == MapNotify) {
+ SET(wi->flags, ZN_CONFIGURE_EVENT);
+ FinishSetup(wi);
ZnNeedRedisplay(wi);
}
else if (event->type == Expose) {
ZnDim width, height;
SET(wi->flags, ZN_CONFIGURE_EVENT);
-
+ FinishSetup(wi);
bbox.orig.x = (((XExposeEvent*) event)->x);
bbox.orig.y = (((XExposeEvent*) event)->y);
width = ((XExposeEvent*) event)->width;
@@ -7268,9 +7379,9 @@ Event(ClientData client_data, /* Information about widget. */
bbox.corner.x = MIN(wi->width, bbox.orig.x + width);
bbox.corner.y = MIN(wi->height, bbox.orig.y + height);
- /*printf("expose %d %d %d %d\n",
- ((XExposeEvent*) event)->x, ((XExposeEvent*) event)->y,
- ((XExposeEvent*) event)->width, ((XExposeEvent*) event)->height);*/
+ //printf("expose %d %d %d %d\n",
+ // ((XExposeEvent*) event)->x, ((XExposeEvent*) event)->y,
+ // ((XExposeEvent*) event)->width, ((XExposeEvent*) event)->height);
/*
* Add the exposed area to the expose region and
* schedule an asynchronous redisplay of the window
@@ -7292,6 +7403,7 @@ Event(ClientData client_data, /* Information about widget. */
int int_width, int_height;
SET(wi->flags, ZN_CONFIGURE_EVENT);
+ FinishSetup(wi);
int_width = Tk_Width(wi->win);
int_height = Tk_Height(wi->win);
@@ -7311,7 +7423,7 @@ Event(ClientData client_data, /* Information about widget. */
* it's confined and the scroll region is smaller than the
* window.
*/
- SetOrigin(wi, wi->origin.x, wi->origin.y);
+ ZnSetOrigin(wi, wi->origin.x, wi->origin.y);
ZnDamage(wi, &bbox);
ZnITEM.Invalidate(wi->top_group, ZN_TRANSFO_FLAG);
@@ -7328,6 +7440,14 @@ Event(ClientData client_data, /* Information about widget. */
int_width, int_height,
DefaultDepthOfScreen(wi->screen));
}
+#if defined(MAC_OSX_TK)
+ else {
+ ZnGLContextEntry *ce = ZnGLMakeCurrent(wi->dpy, wi);
+ UpdateBufferRect(ce, wi->win);
+ aglUpdateContext(ce->context);
+ }
+#endif
+
}
else {
/*
@@ -8237,9 +8357,12 @@ Destroy(ZnWInfo *wi)
}
}
}
-#ifdef _WIN32
+#if defined(_WIN32)
ZnGLReleaseContext(ce);
wglDeleteContext(ce->context);
+#elif defined(MAC_OSX_TK)
+ aglDestroyPixelFormat(ce->pix_fmt);
+ aglDestroyContext(ce->context);
#else
glXDestroyContext(ce->dpy, ce->context);
/*
@@ -8447,7 +8570,7 @@ Repair(ZnWInfo *wi)
}
#endif
- /*printf("Repair, scissors: %d\n", ISCLEAR(wi->flags, ZN_CONFIGURE_EVENT));*/
+ //printf("Repair, scissors: %d\n", ISCLEAR(wi->flags, ZN_CONFIGURE_EVENT));
ce = ZnGLMakeCurrent(wi->dpy, wi);
glEnable(GL_POINT_SMOOTH);
glEnable(GL_LINE_SMOOTH);
diff --git a/generic/tkZinc.h b/generic/tkZinc.h
index 2eb105b..bea3576 100644
--- a/generic/tkZinc.h
+++ b/generic/tkZinc.h
@@ -24,7 +24,11 @@
#include "List.h"
#include "MapInfo.h"
-#include <GL/glu.h>
+#if defined(MAC_OSX_TK)
+ #include <AGL/glu.h>
+#else
+ #include <GL/glu.h>
+#endif
typedef struct _ZnTagSearch {
ZnWInfo *wi;
@@ -84,6 +88,10 @@ typedef struct _ZnGLContextEntry {
int ipixel;
HWND hwnd; /* Temporary storage between MakeCurrent and Release */
HDC hdc;
+#elif defined(__APPLE__)
+ AGLPixelFormat pix_fmt;
+ GWorldPtr gworld;
+ Tk_Window top_win;
#else
XVisualInfo *visual; /* Should these two be managed by screen ? */
Colormap colormap;