summaryrefslogtreecommitdiffstats
path: root/src/bltGrMarkerOp.C
diff options
context:
space:
mode:
Diffstat (limited to 'src/bltGrMarkerOp.C')
-rw-r--r--src/bltGrMarkerOp.C187
1 files changed, 8 insertions, 179 deletions
diff --git a/src/bltGrMarkerOp.C b/src/bltGrMarkerOp.C
index b76df6a..cb5fcd2 100644
--- a/src/bltGrMarkerOp.C
+++ b/src/bltGrMarkerOp.C
@@ -32,6 +32,7 @@
extern "C" {
#include "bltGraph.h"
#include "bltOp.h"
+#include "bltGrMarkerOption.h"
};
#include "bltConfig.h"
@@ -54,8 +55,6 @@ static int MarkerObjConfigure( Tcl_Interp* interp, Graph* graphPtr,
int objc, Tcl_Obj* const objv[]);
static int GetMarkerFromObj(Tcl_Interp* interp, Graph* graphPtr,
Tcl_Obj* objPtr, Marker** markerPtrPtr);
-static int GetCoordinate(Tcl_Interp* interp, Tcl_Obj *objPtr, double *valuePtr);
-static Tcl_Obj* PrintCoordinate(double x);
static int IsElementHidden(Graph*, Marker*);
extern "C" {
@@ -69,151 +68,6 @@ extern "C" {
void* Blt_NearestMarker(Graph* graphPtr, int x, int y, int under);
};
-// OptionSpecs
-
-static Tk_CustomOptionSetProc CoordsSetProc;
-static Tk_CustomOptionGetProc CoordsGetProc;
-static Tk_CustomOptionFreeProc CoordsFreeProc;
-Tk_ObjCustomOption coordsObjOption =
- {
- "coords", CoordsSetProc, CoordsGetProc, RestoreProc, CoordsFreeProc, NULL
- };
-
-static int CoordsSetProc(ClientData clientData, Tcl_Interp* interp,
- Tk_Window tkwin, Tcl_Obj** objPtr, char* widgRec,
- int offset, char* savePtr, int flags)
-{
- Coords** coordsPtrPtr = (Coords**)(widgRec + offset);
- *(double*)savePtr = *(double*)coordsPtrPtr;
-
- if (!coordsPtrPtr)
- return TCL_OK;
-
- int objc;
- Tcl_Obj** objv;
- if (Tcl_ListObjGetElements(interp, *objPtr, &objc, &objv) != TCL_OK)
- return TCL_ERROR;
-
- if (objc == 0) {
- *coordsPtrPtr = NULL;
- return TCL_OK;
- }
-
- if (objc & 1) {
- Tcl_AppendResult(interp, "odd number of marker coordinates specified",NULL);
- return TCL_ERROR;
- }
-
- Coords* coordsPtr = (Coords*)calloc(1,sizeof(Coords));
- coordsPtr->num = objc/2;
- coordsPtr->points = (Point2d*)calloc(coordsPtr->num, sizeof(Point2d));
-
- Point2d* pp = coordsPtr->points;
- for (int ii=0; ii<objc; ii+=2) {
- double x, y;
- if ((GetCoordinate(interp, objv[ii], &x) != TCL_OK) ||
- (GetCoordinate(interp, objv[ii+1], &y) != TCL_OK))
- return TCL_ERROR;
- pp->x = x;
- pp->y = y;
- pp++;
- }
-
- *coordsPtrPtr = coordsPtr;
- return TCL_OK;
-}
-
-static Tcl_Obj* CoordsGetProc(ClientData clientData, Tk_Window tkwin,
- char *widgRec, int offset)
-{
- Coords* coordsPtr = *(Coords**)(widgRec + offset);
-
- if (!coordsPtr)
- return Tcl_NewListObj(0, NULL);
-
- int cnt = coordsPtr->num*2;
- Tcl_Obj** ll = (Tcl_Obj**)calloc(cnt, sizeof(Tcl_Obj*));
-
- Point2d* pp = coordsPtr->points;
- for (int ii=0; ii<cnt; pp++) {
- ll[ii++] = PrintCoordinate(pp->x);
- ll[ii++] = PrintCoordinate(pp->y);
- }
-
- Tcl_Obj* listObjPtr = Tcl_NewListObj(cnt, ll);
- free(ll);
- return listObjPtr;
-}
-
-static void CoordsFreeProc(ClientData clientData, Tk_Window tkwin,
- char *ptr)
-{
- Coords* coordsPtr = *(Coords**)ptr;
- if (coordsPtr) {
- if (coordsPtr->points)
- free(coordsPtr->points);
- free(coordsPtr);
- }
-}
-
-static Tk_CustomOptionSetProc CapStyleSetProc;
-static Tk_CustomOptionGetProc CapStyleGetProc;
-Tk_ObjCustomOption capStyleObjOption =
- {
- "capStyle", CapStyleSetProc, CapStyleGetProc, NULL, NULL, NULL
- };
-
-static int CapStyleSetProc(ClientData clientData, Tcl_Interp* interp,
- Tk_Window tkwin, Tcl_Obj** objPtr, char* widgRec,
- int offset, char* save, int flags)
-{
- int* ptr = (int*)(widgRec + offset);
-
- Tk_Uid uid = Tk_GetUid(Tcl_GetString(*objPtr));
- int cap;
- if (Tk_GetCapStyle(interp, uid, &cap) != TCL_OK)
- return TCL_ERROR;
- *ptr = cap;
-
- return TCL_OK;
-}
-
-static Tcl_Obj* CapStyleGetProc(ClientData clientData, Tk_Window tkwin,
- char *widgRec, int offset)
-{
- int* ptr = (int*)(widgRec + offset);
- return Tcl_NewStringObj(Tk_NameOfCapStyle(*ptr), -1);
-}
-
-static Tk_CustomOptionSetProc JoinStyleSetProc;
-static Tk_CustomOptionGetProc JoinStyleGetProc;
-Tk_ObjCustomOption joinStyleObjOption =
- {
- "joinStyle", JoinStyleSetProc, JoinStyleGetProc, NULL, NULL, NULL
- };
-
-static int JoinStyleSetProc(ClientData clientData, Tcl_Interp* interp,
- Tk_Window tkwin, Tcl_Obj** objPtr, char* widgRec,
- int offset, char* save, int flags)
-{
- int* ptr = (int*)(widgRec + offset);
-
- Tk_Uid uid = Tk_GetUid(Tcl_GetString(*objPtr));
- int join;
- if (Tk_GetJoinStyle(interp, uid, &join) != TCL_OK)
- return TCL_ERROR;
- *ptr = join;
-
- return TCL_OK;
-}
-
-static Tcl_Obj* JoinStyleGetProc(ClientData clientData, Tk_Window tkwin,
- char *widgRec, int offset)
-{
- int* ptr = (int*)(widgRec + offset);
- return Tcl_NewStringObj(Tk_NameOfJoinStyle(*ptr), -1);
-}
-
// Create
static int CreateMarker(Graph* graphPtr, Tcl_Interp* interp,
@@ -471,7 +325,7 @@ static int FindOp(Graph* graphPtr, Tcl_Interp* interp,
for (Blt_ChainLink link = Blt_Chain_FirstLink(graphPtr->markers.displayList);
link; link = Blt_Chain_NextLink(link)) {
Marker* markerPtr = (Marker*)Blt_Chain_GetValue(link);
- MarkerOptions* ops = markerPtr->ops();
+ MarkerOptions* ops = (MarkerOptions*)markerPtr->ops();
if ((markerPtr->flags & DELETE_PENDING) || ops->hide) {
continue;
}
@@ -541,7 +395,7 @@ static int RelinkOp(Graph* graphPtr, Tcl_Interp* interp,
Marker* markerPtr;
if (GetMarkerFromObj(interp, graphPtr, objv[3], &markerPtr) != TCL_OK)
return TCL_ERROR;
- MarkerOptions* ops = markerPtr->ops();
+ MarkerOptions* ops = (MarkerOptions*)markerPtr->ops();
Marker* placePtr =NULL;
if (objc == 5)
@@ -626,7 +480,7 @@ int Blt_MarkerOp(Graph* graphPtr, Tcl_Interp* interp,
static int IsElementHidden(Graph* graphPtr, Marker* markerPtr)
{
- MarkerOptions* ops = markerPtr->ops();
+ MarkerOptions* ops = (MarkerOptions*)markerPtr->ops();
if (ops->elemName) {
Tcl_HashEntry *hPtr
@@ -662,7 +516,7 @@ void Blt_MarkersToPostScript(Graph* graphPtr, Blt_Ps ps, int under)
for (Blt_ChainLink link = Blt_Chain_LastLink(graphPtr->markers.displayList);
link; link = Blt_Chain_PrevLink(link)) {
Marker* markerPtr = (Marker*)Blt_Chain_GetValue(link);
- MarkerOptions* ops = markerPtr->ops();
+ MarkerOptions* ops = (MarkerOptions*)markerPtr->ops();
if (ops->drawUnder != under)
continue;
@@ -683,7 +537,7 @@ void Blt_DrawMarkers(Graph* graphPtr, Drawable drawable, int under)
for (Blt_ChainLink link = Blt_Chain_LastLink(graphPtr->markers.displayList);
link; link = Blt_Chain_PrevLink(link)) {
Marker* markerPtr = (Marker*)Blt_Chain_GetValue(link);
- MarkerOptions* ops = markerPtr->ops();
+ MarkerOptions* ops = (MarkerOptions*)markerPtr->ops();
if ((ops->drawUnder != under) || (markerPtr->clipped()) ||
(markerPtr->flags & DELETE_PENDING) || (ops->hide))
@@ -710,7 +564,7 @@ void Blt_MapMarkers(Graph* graphPtr)
for (Blt_ChainLink link = Blt_Chain_FirstLink(graphPtr->markers.displayList);
link; link = Blt_Chain_NextLink(link)) {
Marker* markerPtr = (Marker*)Blt_Chain_GetValue(link);
- MarkerOptions* ops = markerPtr->ops();
+ MarkerOptions* ops = (MarkerOptions*)markerPtr->ops();
if ((markerPtr->flags & DELETE_PENDING) || ops->hide)
continue;
@@ -746,7 +600,7 @@ void* Blt_NearestMarker(Graph* graphPtr, int x, int y, int under)
for (Blt_ChainLink link = Blt_Chain_FirstLink(graphPtr->markers.displayList);
link; link = Blt_Chain_NextLink(link)) {
Marker* markerPtr = (Marker*)Blt_Chain_GetValue(link);
- MarkerOptions* ops = markerPtr->ops();
+ MarkerOptions* ops = (MarkerOptions*)markerPtr->ops();
if ((markerPtr->flags & (DELETE_PENDING|MAP_ITEM)) ||
(ops->hide))
@@ -776,28 +630,3 @@ void Blt_FreeMarker(char* dataPtr)
delete markerPtr;
}
-static Tcl_Obj* PrintCoordinate(double x)
-{
- if (x == DBL_MAX)
- return Tcl_NewStringObj("+Inf", -1);
- else if (x == -DBL_MAX)
- return Tcl_NewStringObj("-Inf", -1);
- else
- return Tcl_NewDoubleObj(x);
-}
-
-static int GetCoordinate(Tcl_Interp* interp, Tcl_Obj *objPtr, double *valuePtr)
-{
- const char* expr = Tcl_GetString(objPtr);
- char c = expr[0];
- if ((c == 'I') && (strcmp(expr, "Inf") == 0))
- *valuePtr = DBL_MAX; /* Elastic upper bound */
- else if ((c == '-') && (expr[1] == 'I') && (strcmp(expr, "-Inf") == 0))
- *valuePtr = -DBL_MAX; /* Elastic lower bound */
- else if ((c == '+') && (expr[1] == 'I') && (strcmp(expr, "+Inf") == 0))
- *valuePtr = DBL_MAX; /* Elastic upper bound */
- else if (Blt_ExprDoubleFromObj(interp, objPtr, valuePtr) != TCL_OK)
- return TCL_ERROR;
-
- return TCL_OK;
-}