diff options
author | joye <joye> | 2014-03-11 20:26:59 (GMT) |
---|---|---|
committer | joye <joye> | 2014-03-11 20:26:59 (GMT) |
commit | f3967ea76f32972b342afd7e426d85ce7bf2f483 (patch) | |
tree | b17a35e9154366bf373535e86c27871ba3b4937e | |
parent | 97add888399d2bc493246bb0abfdd86fcaf221a4 (diff) | |
download | blt-f3967ea76f32972b342afd7e426d85ce7bf2f483.zip blt-f3967ea76f32972b342afd7e426d85ce7bf2f483.tar.gz blt-f3967ea76f32972b342afd7e426d85ce7bf2f483.tar.bz2 |
*** empty log message ***
-rw-r--r-- | bltGrMarkerBitmap.C | 43 | ||||
-rw-r--r-- | src/bltGrAxis.C | 2 | ||||
-rw-r--r-- | src/bltGrMarker.C | 89 | ||||
-rw-r--r-- | src/bltGrMarker.h | 5 | ||||
-rw-r--r-- | src/bltGrMarkerLine.C | 46 |
5 files changed, 179 insertions, 6 deletions
diff --git a/bltGrMarkerBitmap.C b/bltGrMarkerBitmap.C index a560ae7..304988c 100644 --- a/bltGrMarkerBitmap.C +++ b/bltGrMarkerBitmap.C @@ -33,6 +33,49 @@ #define GETBITMAP(b) (((b)->destBitmap == None) ? (b)->srcBitmap : (b)->destBitmap) +static Tk_OptionSpec bitmapOptionSpecs[] = { + {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor", + "center", -1, Tk_Offset(BitmapMarker, anchor), 0, NULL, 0}, + {TK_OPTION_COLOR, "-background", "background", "Background", + "white", -1, Tk_Offset(BitmapMarker, fillColor), TK_OPTION_NULL_OK, NULL, 0}, + {TK_OPTION_SYNONYM, "-bg", NULL, NULL, NULL, -1, 0, 0, "-background", 0}, + {TK_OPTION_CUSTOM, "-bindtags", "bindTags", "BindTags", + "Bitmap all", -1, Tk_Offset(BitmapMarker, obj.tags), + TK_OPTION_NULL_OK, &listObjOption, 0}, + {TK_OPTION_BITMAP, "-bitmap", "bitmap", "Bitmap", + NULL, -1, Tk_Offset(BitmapMarker, srcBitmap), TK_OPTION_NULL_OK, NULL, 0}, + {TK_OPTION_CUSTOM, "-coords", "coords", "Coords", + NULL, -1, Tk_Offset(BitmapMarker, worldPts), + TK_OPTION_NULL_OK, &coordsObjOption, 0}, + {TK_OPTION_STRING, "-element", "element", "Element", + NULL, -1, Tk_Offset(BitmapMarker, elemName), TK_OPTION_NULL_OK, NULL, 0}, + {TK_OPTION_SYNONYM, "-fg", NULL, NULL, NULL, -1, 0, 0, "-foreground", 0}, + {TK_OPTION_SYNONYM, "-fill", NULL, NULL, NULL, -1, 0, 0, "-background", 0}, + {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground", + "black", -1, Tk_Offset(BitmapMarker, outlineColor), + TK_OPTION_NULL_OK, NULL, 0}, + {TK_OPTION_BOOLEAN, "-hide", "hide", "Hide", + "no", -1, Tk_Offset(BitmapMarker, hide), 0, NULL, 0}, + {TK_OPTION_CUSTOM, "-mapx", "mapX", "MapX", + "x", -1, Tk_Offset(BitmapMarker, axes.x), 0, &xAxisObjOption, 0}, + {TK_OPTION_CUSTOM, "-mapy", "mapY", "MapY", + "y", -1, Tk_Offset(BitmapMarker, axes.y), 0, &yAxisObjOption, 0}, + {TK_OPTION_STRING, "-name", "name", "Name", + NULL, -1, Tk_Offset(BitmapMarker, obj.name), TK_OPTION_NULL_OK, NULL, 0}, + {TK_OPTION_SYNONYM, "-outline", NULL, NULL, NULL, -1, 0, 0, "-foreground", 0}, + {TK_OPTION_DOUBLE, "-rotate", "rotate", "Rotate", + "0", -1, Tk_Offset(BitmapMarker, reqAngle), 0, NULL, 0}, + {TK_OPTION_CUSTOM, "-state", "state", "State", + "normal", -1, Tk_Offset(BitmapMarker, state), 0, &stateObjOption, 0}, + {TK_OPTION_BOOLEAN, "-under", "under", "Under", + "no", -1, Tk_Offset(BitmapMarker, drawUnder), 0, NULL, 0}, + {TK_OPTION_PIXELS, "-xoffset", "xOffset", "XOffset", + "0", -1, Tk_Offset(BitmapMarker, xOffset), 0, NULL, 0}, + {TK_OPTION_PIXELS, "-yoffset", "yOffset", "YOffset", + "0", -1, Tk_Offset(BitmapMarker, yOffset), 0, NULL, 0}, + {TK_OPTION_END, NULL, NULL, NULL, NULL, -1, 0, 0, NULL, 0} +}; + static Blt_ConfigSpec bitmapConfigSpecs[] = { {BLT_CONFIG_ANCHOR, "-anchor", "anchor", "Anchor", "center", Tk_Offset(BitmapMarker, anchor), 0}, diff --git a/src/bltGrAxis.C b/src/bltGrAxis.C index 4155243..afc6f8f 100644 --- a/src/bltGrAxis.C +++ b/src/bltGrAxis.C @@ -138,7 +138,7 @@ static int AxisSetProc(ClientData clientData, Tcl_Interp* interp, static Tcl_Obj* AxisGetProc(ClientData clientData, Tk_Window tkwin, char *widgRec, int offset) { - Axis*axisPtr = *(Axis**)(widgRec + offset); + Axis* axisPtr = *(Axis**)(widgRec + offset); const char* name = (axisPtr ? axisPtr->obj.name : ""); return Tcl_NewStringObj(name, -1); diff --git a/src/bltGrMarker.C b/src/bltGrMarker.C index 91eff6c..7922e0c 100644 --- a/src/bltGrMarker.C +++ b/src/bltGrMarker.C @@ -39,10 +39,90 @@ #include "bltGrMarkerText.h" #include "bltGrMarkerWindow.h" +#define NORMALIZE(A,x) (((x) - (A)->axisRange.min) * (A)->axisRange.scale) + +// Defs + typedef int (GraphMarkerProc)(Graph* graphPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[]); -#define NORMALIZE(A,x) (((x) - (A)->axisRange.min) * (A)->axisRange.scale) +static int ParseCoordinates(Tcl_Interp* interp, Marker *markerPtr, + int objc, Tcl_Obj* const objv[]); +static Tcl_Obj* PrintCoordinate(double x); + +// OptionSpecs + +static Tk_CustomOptionSetProc CoordsSetProc; +static Tk_CustomOptionGetProc CoordsGetProc; +Tk_ObjCustomOption coordsObjOption = + { + "coords", CoordsSetProc, CoordsGetProc, NULL, NULL, NULL + }; + +static int CoordsSetProc(ClientData clientData, Tcl_Interp* interp, + Tk_Window tkwin, Tcl_Obj** objPtr, char* widgRec, + int offset, char* save, int flags) +{ + Marker *markerPtr = (Marker *)widgRec; + + int objc; + Tcl_Obj **objv; + if (Tcl_ListObjGetElements(interp, *objPtr, &objc, &objv) != TCL_OK) + return TCL_ERROR; + + if (objc == 0) + return TCL_OK; + + return ParseCoordinates(interp, markerPtr, objc, objv); +} + +static Tcl_Obj* CoordsGetProc(ClientData clientData, Tk_Window tkwin, + char *widgRec, int offset) +{ + Marker* markerPtr = (Marker*)widgRec; + + int cnt = markerPtr->nWorldPts*2; + Tcl_Obj** ll = calloc(cnt, sizeof(Tcl_Obj*)); + + Point2d* pp = markerPtr->worldPts; + for (int ii=0; ii < markerPtr->nWorldPts*2; pp++) { + ll[ii++] = PrintCoordinate(pp->x); + ll[ii++] = PrintCoordinate(pp->y); + } + + Tcl_Obj* listObjPtr = Tcl_NewListObj(cnt, ll); + free(ll); + return listObjPtr; +} + +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 Blt_OptionParseProc ObjToCoordsProc; static Blt_OptionPrintProc CoordsToObjProc; @@ -81,13 +161,12 @@ static int GetCoordinate(Tcl_Interp* interp, Tcl_Obj *objPtr, double *valuePtr) static Tcl_Obj* PrintCoordinate(double x) { - if (x == DBL_MAX) { + if (x == DBL_MAX) return Tcl_NewStringObj("+Inf", -1); - } else if (x == -DBL_MAX) { + else if (x == -DBL_MAX) return Tcl_NewStringObj("-Inf", -1); - } else { + else return Tcl_NewDoubleObj(x); - } } static int ParseCoordinates(Tcl_Interp* interp, Marker *markerPtr, diff --git a/src/bltGrMarker.h b/src/bltGrMarker.h index 7b62adf..f4493d7 100644 --- a/src/bltGrMarker.h +++ b/src/bltGrMarker.h @@ -95,6 +95,11 @@ struct _Marker { int state; }; +extern Tk_ObjCustomOption coordsObjOption; +extern Tk_ObjCustomOption capStyleObjOption; +extern Tk_ObjCustomOption xAxisObjOption; +extern Tk_ObjCustomOption yAxisObjOption; + Point2d Blt_MapPoint(Point2d *pointPtr, Axis2d *axesPtr); int Blt_BoxesDontOverlap(Graph* graphPtr, Region2d *extsPtr); void Blt_FreeMarker(char*); diff --git a/src/bltGrMarkerLine.C b/src/bltGrMarkerLine.C index f464dc8..92989f5 100644 --- a/src/bltGrMarkerLine.C +++ b/src/bltGrMarkerLine.C @@ -30,6 +30,52 @@ #include "bltGraph.h" #include "bltGrMarkerLine.h" +static Tk_OptionSpec lineOptionSpecs[] = { + {TK_OPTION_CUSTOM, "-bindtags", "bindTags", "BindTags", + "Line all", -1, Tk_Offset(LineMarker, obj.tags), + TK_OPTION_NULL_OK, &listObjOption, 0}, + {TK_OPTION_CUSTOM, "-cap", "cap", "Cap", + "butt", -1, Tk_Offset(LineMarker, capStyle), 0, &capStyleObjOption, 0}, + {TK_OPTION_CUSTOM, "-coords", "coords", "Coords", + NULL, -1, Tk_Offset(LineMarker, worldPts), + TK_OPTION_NULL_OK, &coordsObjOption, 0}, + {TK_OPTION_CUSTOM, "-dashes", "dashes", "Dashes", + NULL, -1, Tk_Offset(LineMarker, dashes), + TK_OPTION_NULL_OK, &dashesObjOption, 0}, + {TK_OPTION_PIXELS, "-dashoffset", "dashOffset", "DashOffset", + "0", -1, Tk_Offset(LineMarker, dashes.offset), 0, NULL, 0}, + {TK_OPTION_STRING, "-element", "element", "Element", + NULL, -1, Tk_Offset(LineMarker, elemName), TK_OPTION_NULL_OK, NULL, 0}, + {TK_OPTION_COLOR, "-fill", "fill", "Fill", + NULL, -1, Tk_Offset(LineMarker, fillColor), TK_OPTION_NULL_OK, NULL, 0}, + {TK_OPTION_CUSTOM, "-join", "join", "Join", + "miter", -1, Tk_Offset(LineMarker, joinStyle), 0, &capStyleObjOption, 0}, + {TK_OPTION_PIXELS, "-linewidth", "lineWidth", "LineWidth", + "1", -1, Tk_Offset(LineMarker, lineWidth), 0, NULL, 0}, + {TK_OPTION_BOOLEAN, "-hide", "hide", "Hide", + "no", -1, Tk_Offset(LineMarker, hide), 0, NULL, 0}, + {TK_OPTION_CUSTOM, "-mapx", "mapX", "MapX", + "x", -1, Tk_Offset(LineMarker, axes.x), 0, &xAxisObjOption, 0}, + {TK_OPTION_CUSTOM, "-mapy", "mapY", "MapY", + "y", -1, Tk_Offset(LineMarker, axes.y), 0, &yAxisObjOption, 0}, + {TK_OPTION_STRING, "-name", "name", "Name", + NULL, -1, Tk_Offset(LineMarker, obj.name), TK_OPTION_NULL_OK, NULL, 0}, + {TK_OPTION_COLOR, "-outline", "outline", "Outline", + "black", -1, Tk_Offset(LineMarker, outlineColor), + TK_OPTION_NULL_OK, NULL, 0}, + {TK_OPTION_CUSTOM, "-state", "state", "State", + "normal", -1, Tk_Offset(LineMarker, state), 0, &stateObjOption, 0}, + {TK_OPTION_BOOLEAN, "-under", "under", "Under", + "no", -1, Tk_Offset(LineMarker, drawUnder), 0, NULL, 0}, + {TK_OPTION_PIXELS, "-xoffset", "xOffset", "XOffset", + "0", -1, Tk_Offset(LineMarker, xOffset), 0, NULL, 0}, + {TK_OPTION_PIXELS, "-yoffset", "yOffset", "YOffset", + "0", -1, Tk_Offset(LineMarker, yOffset), 0, NULL, 0}, + {TK_OPTION_BOOLEAN, "-xor", "xor", "Xor", + "no", -1, Tk_Offset(LineMarker, xor), 0, NULL, 0}, + {TK_OPTION_END, NULL, NULL, NULL, NULL, -1, 0, 0, NULL, 0} +}; + static Blt_ConfigSpec lineConfigSpecs[] = { {BLT_CONFIG_CUSTOM, "-bindtags", "bindTags", "BindTags", "Line all", Tk_Offset(LineMarker, obj.tags), BLT_CONFIG_NULL_OK, |