diff options
author | joye <joye> | 2014-02-25 19:22:00 (GMT) |
---|---|---|
committer | joye <joye> | 2014-02-25 19:22:00 (GMT) |
commit | 37cbef07267b33119fc6e98827774c459488b2e0 (patch) | |
tree | d8e9c713cdc772ce4a41496eefade4254e86062e /src | |
parent | b9f3b60fe28abc94aff915ae1ab934f20af8fe80 (diff) | |
download | blt-37cbef07267b33119fc6e98827774c459488b2e0.zip blt-37cbef07267b33119fc6e98827774c459488b2e0.tar.gz blt-37cbef07267b33119fc6e98827774c459488b2e0.tar.bz2 |
*** empty log message ***
Diffstat (limited to 'src')
-rw-r--r-- | src/bltConfig.C | 27 | ||||
-rw-r--r-- | src/bltConfig.h | 2 | ||||
-rw-r--r-- | src/bltGrElemBar.C | 10 | ||||
-rw-r--r-- | src/bltGrElemLine.C | 67 | ||||
-rw-r--r-- | src/bltGrElemOp.C | 86 | ||||
-rw-r--r-- | src/bltGrElemOp.h | 3 | ||||
-rw-r--r-- | src/bltGrPenOp.C | 6 |
7 files changed, 162 insertions, 39 deletions
diff --git a/src/bltConfig.C b/src/bltConfig.C index b77d502..a5c8bf0 100644 --- a/src/bltConfig.C +++ b/src/bltConfig.C @@ -83,6 +83,9 @@ #include "bltInt.h" +// State +char* stateObjOption[] = {"normal", "active", "disabled", NULL}; + // Point static Tk_CustomOptionSetProc PointSetProc; static Tk_CustomOptionGetProc PointGetProc; @@ -209,13 +212,21 @@ static Tcl_Obj* DashesGetProc(ClientData clientData, Tk_Window tkwin, { Blt_Dashes* dashesPtr = (Blt_Dashes*)(widgRec + offset); - Tcl_Obj* ll[12]; - int ii=0; - while (dashesPtr->values[ii]) { + // count how many + int cnt =0; + while (dashesPtr->values[cnt]) + cnt++; + + if (!cnt) + return Tcl_NewListObj(0, (Tcl_Obj**)NULL); + + Tcl_Obj** ll = calloc(cnt, sizeof(Tcl_Obj*)); + for (int ii=0; ii<cnt; ii++) ll[ii] = Tcl_NewIntObj(dashesPtr->values[ii]); - ii++; - } - return Tcl_NewListObj(ii, ll); + Tcl_Obj* listObjPtr = Tcl_NewListObj(cnt, ll); + free(ll); + + return listObjPtr; }; // List @@ -254,8 +265,10 @@ static Tcl_Obj* ListGetProc(ClientData clientData, Tk_Window tkwin, // count how many int cnt=0; for (const char** p = *listPtr; *p != NULL; p++,cnt++) {} + if (!cnt) + return Tcl_NewListObj(0, (Tcl_Obj**)NULL); - Tcl_Obj** ll = calloc(cnt,sizeof(Tcl_Obj*)); + Tcl_Obj** ll = calloc(cnt, sizeof(Tcl_Obj*)); for (int ii=0; ii<cnt; ii++) ll[ii] = Tcl_NewStringObj(*listPtr[ii], -1); Tcl_Obj* listObjPtr = Tcl_NewListObj(cnt, ll); diff --git a/src/bltConfig.h b/src/bltConfig.h index e8863c1..3f789b0 100644 --- a/src/bltConfig.h +++ b/src/bltConfig.h @@ -173,6 +173,8 @@ typedef struct { #define LineIsDashed(d) ((d).values[0] != 0) +extern char* stateObjOption[]; + extern Tk_ObjCustomOption backgroundObjOption; extern Tk_ObjCustomOption pointObjOption; extern Tk_ObjCustomOption dashesObjOption; diff --git a/src/bltGrElemBar.C b/src/bltGrElemBar.C index 8f06097..5977cf4 100644 --- a/src/bltGrElemBar.C +++ b/src/bltGrElemBar.C @@ -196,6 +196,13 @@ extern Blt_CustomOption bltBarStylesOption; //*** +static Tk_ObjCustomOption styleObjOption = + { + "style", StyleSetProc, StyleGetProc, NULL, NULL, + (ClientData)sizeof(BarStyle) + + }; + extern Tk_ObjCustomOption barPenObjOption; extern Tk_ObjCustomOption pairsObjOption; @@ -237,6 +244,8 @@ static Tk_OptionSpec barElemOptionSpecs[] = { {TK_OPTION_BITMAP, "-stipple", "stipple", "Stipple", NULL, -1, Tk_Offset(BarElement, builtinPen.stipple), TK_OPTION_NULL_OK, NULL, 0}, + {TK_OPTION_CUSTOM, "-styles", "styles", "Styles", + "", -1, Tk_Offset(BarElement, stylePalette), 0, &styleObjOption, 0}, {TK_OPTION_ANCHOR, "-valueanchor", "valueAnchor", "ValueAnchor", "s", -1, Tk_Offset(BarElement, builtinPen.valueStyle.anchor), 0, NULL, 0}, {TK_OPTION_COLOR, "-valuecolor", "valueColor", "ValueColor", @@ -2233,7 +2242,6 @@ Element* Blt_BarElement(Graph* graphPtr, const char* name, ClassId classId) elemPtr->builtinPenPtr = &elemPtr->builtinPen; InitBarPen(graphPtr, elemPtr->builtinPenPtr); elemPtr->stylePalette = Blt_Chain_Create(); - bltBarStylesOption.clientData = (ClientData)sizeof(BarStyle); return (Element *)elemPtr; } diff --git a/src/bltGrElemLine.C b/src/bltGrElemLine.C index c07b3eb..93f444d 100644 --- a/src/bltGrElemLine.C +++ b/src/bltGrElemLine.C @@ -275,7 +275,7 @@ typedef struct { LinePen *activePenPtr; /* Standard Pens */ LinePen *normalPenPtr; LinePen *builtinPenPtr; - Blt_Chain stylesPalette; /* Palette of pens. */ + Blt_Chain stylePalette; /* Palette of pens. */ /* Symbol scaling */ int scaleSymbols; /* If non-zero, the symbols will scale @@ -353,6 +353,16 @@ typedef struct { //*** +static char* smoothObjOption[] = + {"linear", "step", "natural", "quadratic", "catrom", NULL}; + +static Tk_ObjCustomOption styleObjOption = + { + "styles", StyleSetProc, StyleGetProc, NULL, NULL, + (ClientData)sizeof(LineStyle) + + }; + extern Tk_ObjCustomOption linePenObjOption; extern Tk_ObjCustomOption pairsObjOption; extern Tk_ObjCustomOption xAxisObjOption; @@ -419,6 +429,18 @@ static Tk_OptionSpec lineElemOptionSpecs[] = { 0, -1, Tk_Offset(LineElement, rTolerance), 0, NULL, 0}, {TK_OPTION_BOOLEAN, "-scalesymbols", "scaleSymbols", "ScaleSymbols", "yes", -1, Tk_Offset(LineElement, scaleSymbols), 0, NULL, 0}, + {TK_OPTION_STRING_TABLE, "-showerrorbars", "showErrorBars", "ShowErrorBars", + "both", -1, Tk_Offset(LineElement, builtinPen.errorBarShow), + 0, &fillObjOption, 0}, + {TK_OPTION_STRING_TABLE, "-showvalues", "showValues", "ShowValues", + "no", -1, Tk_Offset(LineElement, builtinPen.valueShow), + 0, &fillObjOption, 0}, + {TK_OPTION_STRING_TABLE, "-smooth", "smooth", "Smooth", + "linear", -1, Tk_Offset(LineElement, reqSmooth), 0, &smoothObjOption, 0}, + {TK_OPTION_STRING_TABLE, "-state", "state", "State", + "normal", -1, Tk_Offset(LineElement, state), 0, &stateObjOption, 0}, + {TK_OPTION_CUSTOM, "-styles", "styles", "Styles", + "", -1, Tk_Offset(LineElement, stylePalette), 0, &styleObjOption, 0}, {TK_OPTION_ANCHOR, "-valueanchor", "valueAnchor", "ValueAnchor", "s", -1, Tk_Offset(LineElement, builtinPen.valueStyle.anchor), 0, NULL, 0}, {TK_OPTION_COLOR, "-valuecolor", "valueColor", "ValueColor", @@ -434,7 +456,6 @@ static Tk_OptionSpec lineElemOptionSpecs[] = { {TK_OPTION_END, NULL, NULL, NULL, NULL, -1, 0, 0, NULL, 0} }; -extern Blt_CustomOption bltLineStylesOption; /* static Blt_OptionParseProc ObjToSmoothProc; static Blt_OptionPrintProc SmoothToObjProc; @@ -463,6 +484,7 @@ extern Blt_CustomOption bltValuesOption; extern Blt_CustomOption bltValuePairsOption; extern Blt_CustomOption bltXAxisOption; extern Blt_CustomOption bltYAxisOption; +extern Blt_CustomOption bltLineStylesOption; static Blt_ConfigSpec lineElemConfigSpecs[] = { {BLT_CONFIG_CUSTOM, "-activepen", "activePen", "ActivePen", @@ -552,7 +574,7 @@ static Blt_ConfigSpec lineElemConfigSpecs[] = { {BLT_CONFIG_CUSTOM, "-state", "state", "State", "normal", Tk_Offset(LineElement, state), BLT_CONFIG_DONT_SET_DEFAULT, &stateOption}, {BLT_CONFIG_CUSTOM, "-styles", "styles", "Styles", "", - Tk_Offset(LineElement, stylesPalette), 0, &bltLineStylesOption}, + Tk_Offset(LineElement, stylePalette), 0, &bltLineStylesOption}, {BLT_CONFIG_CUSTOM, "-symbol", "symbol", "Symbol", "none", Tk_Offset(LineElement, builtinPen.symbol), BLT_CONFIG_DONT_SET_DEFAULT, &symbolOption}, @@ -1772,11 +1794,11 @@ static void MapActiveSymbols(Graph *graphPtr, LineElement *elemPtr) */ static void MergePens(LineElement *elemPtr, LineStyle **styleMap) { - if (Blt_Chain_GetLength(elemPtr->stylesPalette) < 2) { + if (Blt_Chain_GetLength(elemPtr->stylePalette) < 2) { Blt_ChainLink link; LineStyle *stylePtr; - link = Blt_Chain_FirstLink(elemPtr->stylesPalette); + link = Blt_Chain_FirstLink(elemPtr->stylePalette); stylePtr = Blt_Chain_GetValue(link); stylePtr->errorBarCapWidth = elemPtr->errorBarCapWidth; stylePtr->lines.length = elemPtr->lines.length; @@ -1801,7 +1823,7 @@ static void MergePens(LineElement *elemPtr, LineStyle **styleMap) segments = malloc(elemPtr->lines.length * sizeof(Segment2d)); map = malloc(elemPtr->lines.length * sizeof(int)); sp = segments, ip = map; - for (link = Blt_Chain_FirstLink(elemPtr->stylesPalette); + for (link = Blt_Chain_FirstLink(elemPtr->stylePalette); link != NULL; link = Blt_Chain_NextLink(link)) { LineStyle *stylePtr; int i; @@ -1833,7 +1855,7 @@ static void MergePens(LineElement *elemPtr, LineStyle **styleMap) points = malloc(elemPtr->symbolPts.length * sizeof(Point2d)); map = malloc(elemPtr->symbolPts.length * sizeof(int)); pp = points, ip = map; - for (link = Blt_Chain_FirstLink(elemPtr->stylesPalette); + for (link = Blt_Chain_FirstLink(elemPtr->stylePalette); link != NULL; link = Blt_Chain_NextLink(link)) { LineStyle *stylePtr; int i; @@ -1864,7 +1886,7 @@ static void MergePens(LineElement *elemPtr, LineStyle **styleMap) segments = malloc(elemPtr->xeb.length * sizeof(Segment2d)); map = malloc(elemPtr->xeb.length * sizeof(int)); sp = segments, ip = map; - for (link = Blt_Chain_FirstLink(elemPtr->stylesPalette); + for (link = Blt_Chain_FirstLink(elemPtr->stylePalette); link != NULL; link = Blt_Chain_NextLink(link)) { LineStyle *stylePtr; int i; @@ -1895,7 +1917,7 @@ static void MergePens(LineElement *elemPtr, LineStyle **styleMap) segments = malloc(elemPtr->yeb.length * sizeof(Segment2d)); map = malloc(elemPtr->yeb.length * sizeof(int)); sp = segments, ip = map; - for (link = Blt_Chain_FirstLink(elemPtr->stylesPalette); + for (link = Blt_Chain_FirstLink(elemPtr->stylePalette); link != NULL; link = Blt_Chain_NextLink(link)) { LineStyle *stylePtr; int i; @@ -2184,7 +2206,7 @@ static void MapFillArea(Graph *graphPtr, LineElement *elemPtr, MapInfo *mapPtr) static void ResetLine(LineElement *elemPtr) { FreeTraces(elemPtr); - ResetStylePalette(elemPtr->stylesPalette); + ResetStylePalette(elemPtr->stylePalette); if (elemPtr->symbolPts.points != NULL) { free(elemPtr->symbolPts.points); } @@ -2428,7 +2450,7 @@ static void MapLineProc(Graph *graphPtr, Element *basePtr) free(mi.map); /* Set the symbol size of all the pen styles. */ - for (link = Blt_Chain_FirstLink(elemPtr->stylesPalette); link != NULL; + for (link = Blt_Chain_FirstLink(elemPtr->stylePalette); link != NULL; link = Blt_Chain_NextLink(link)) { LineStyle *stylePtr; LinePen *penPtr; @@ -2787,10 +2809,10 @@ static int ConfigureLineProc(Graph *graphPtr, Element *basePtr) * Point to the static normal/active pens if no external pens have been * selected. */ - link = Blt_Chain_FirstLink(elemPtr->stylesPalette); + link = Blt_Chain_FirstLink(elemPtr->stylePalette); if (link == NULL) { link = Blt_Chain_AllocLink(sizeof(LineStyle)); - Blt_Chain_LinkAfter(elemPtr->stylesPalette, link, NULL); + Blt_Chain_LinkAfter(elemPtr->stylePalette, link, NULL); } stylePtr = Blt_Chain_GetValue(link); stylePtr->penPtr = NORMALPEN(elemPtr); @@ -3746,7 +3768,7 @@ static void DrawNormalLineProc(Graph *graphPtr, Drawable drawable, /* Lines: stripchart segments or graph traces. */ if (elemPtr->lines.length > 0) { - for (link = Blt_Chain_FirstLink(elemPtr->stylesPalette); + for (link = Blt_Chain_FirstLink(elemPtr->stylePalette); link != NULL; link = Blt_Chain_NextLink(link)) { LineStyle *stylePtr; LinePen *penPtr; @@ -3773,7 +3795,7 @@ static void DrawNormalLineProc(Graph *graphPtr, Drawable drawable, int total; total = 0; - for (link = Blt_Chain_FirstLink(elemPtr->stylesPalette); + for (link = Blt_Chain_FirstLink(elemPtr->stylePalette); link != NULL; link = Blt_Chain_NextLink(link)) { LineStyle *stylePtr; @@ -3787,7 +3809,7 @@ static void DrawNormalLineProc(Graph *graphPtr, Drawable drawable, /* Symbols, error bars, values. */ count = 0; - for (link = Blt_Chain_FirstLink(elemPtr->stylesPalette); link != NULL; + for (link = Blt_Chain_FirstLink(elemPtr->stylePalette); link != NULL; link = Blt_Chain_NextLink(link)) { LineStyle *stylePtr; LinePen *penPtr; @@ -4104,7 +4126,7 @@ static void NormalLineToPostScriptProc(Graph *graphPtr, Blt_Ps ps, /* Draw lines (strip chart) or traces (xy graph) */ if (elemPtr->lines.length > 0) { - for (link = Blt_Chain_FirstLink(elemPtr->stylesPalette); link != NULL; + for (link = Blt_Chain_FirstLink(elemPtr->stylePalette); link != NULL; link = Blt_Chain_NextLink(link)) { LineStyle *stylePtr; LinePen *penPtr; @@ -4132,7 +4154,7 @@ static void NormalLineToPostScriptProc(Graph *graphPtr, Blt_Ps ps, /* Draw symbols, error bars, values. */ count = 0; - for (link = Blt_Chain_FirstLink(elemPtr->stylesPalette); link != NULL; + for (link = Blt_Chain_FirstLink(elemPtr->stylePalette); link != NULL; link = Blt_Chain_NextLink(link)) { LineStyle *stylePtr; LinePen *penPtr; @@ -4184,9 +4206,9 @@ static void DestroyLineProc(Graph* graphPtr, Element* basePtr) Blt_FreePen((Pen *)elemPtr->normalPenPtr); ResetLine(elemPtr); - if (elemPtr->stylesPalette != NULL) { - Blt_FreeStylePalette(elemPtr->stylesPalette); - Blt_Chain_Destroy(elemPtr->stylesPalette); + if (elemPtr->stylePalette != NULL) { + Blt_FreeStylePalette(elemPtr->stylePalette); + Blt_Chain_Destroy(elemPtr->stylePalette); } if (elemPtr->activeIndices != NULL) { free(elemPtr->activeIndices); @@ -4231,11 +4253,10 @@ Element * Blt_LineElement(Graph *graphPtr, const char *name, ClassId classId) elemPtr->label = Blt_Strdup(name); elemPtr->legendRelief = TK_RELIEF_FLAT; elemPtr->penDir = PEN_BOTH_DIRECTIONS; - elemPtr->stylesPalette = Blt_Chain_Create(); + elemPtr->stylePalette = Blt_Chain_Create(); elemPtr->builtinPenPtr = &elemPtr->builtinPen; elemPtr->reqSmooth = PEN_SMOOTH_LINEAR; InitLinePen(graphPtr, elemPtr->builtinPenPtr); - bltLineStylesOption.clientData = (ClientData)sizeof(LineStyle); Tk_InitOptions(graphPtr->interp, (char*)elemPtr->builtinPenPtr, elemPtr->builtinPenPtr->optionTable, graphPtr->tkwin); diff --git a/src/bltGrElemOp.C b/src/bltGrElemOp.C index f57524d..46d8f58 100644 --- a/src/bltGrElemOp.C +++ b/src/bltGrElemOp.C @@ -49,6 +49,12 @@ static int ParseValues(Tcl_Interp *interp, Tcl_Obj *objPtr, int *nValuesPtr, double **arrayPtr); static void FreeDataValues(ElemValues *valuesPtr); static void FindRange(ElemValues *valuesPtr); +static int GetPenStyleFromObj(Tcl_Interp *interp, Graph *graphPtr, + Tcl_Obj *objPtr, ClassId classId, + PenStyle *stylePtr); + +// Fill +char* fillObjOption[] = {"none", "x", "y", "both", NULL}; // Value Pairs static Tk_CustomOptionSetProc PairsSetProc; @@ -101,19 +107,91 @@ static Tcl_Obj* PairsGetProc(ClientData clientData, Tk_Window tkwin, char *widgRec, int offset) { Element *elemPtr = (Element*)widgRec; - int length = NUMBEROFPOINTS(elemPtr); + int cnt = NUMBEROFPOINTS(elemPtr); + if (!cnt) + return Tcl_NewListObj(0, (Tcl_Obj**)NULL); - Tcl_Obj** ll = calloc(2*length,sizeof(Tcl_Obj*)); - for (int ii=0, jj=0; ii<length; ii++) { + Tcl_Obj** ll = calloc(2*cnt,sizeof(Tcl_Obj*)); + for (int ii=0, jj=0; ii<cnt; ii++) { ll[jj++] = Tcl_NewDoubleObj(elemPtr->x.values[ii]); ll[jj++] = Tcl_NewDoubleObj(elemPtr->y.values[ii]); } - Tcl_Obj* listObjPtr = Tcl_NewListObj(2*length, ll); + Tcl_Obj* listObjPtr = Tcl_NewListObj(2*cnt, ll); free(ll); return listObjPtr; }; +// Style +int StyleSetProc(ClientData clientData, Tcl_Interp *interp, + Tk_Window tkwin, Tcl_Obj** objPtr, char* widgRec, + int offset, char* save, int flags) +{ + Blt_Chain stylePalette = *(Blt_Chain*)(widgRec + offset); + Element* elemPtr = (Element*)(widgRec); + size_t size = (size_t)clientData; + + Tcl_Obj** objv; + int objc; + if (Tcl_ListObjGetElements(interp, *objPtr, &objc, &objv) != TCL_OK) + return TCL_ERROR; + + /* Reserve the first entry for the "normal" pen. We'll set the + * style later */ + Blt_FreeStylePalette(stylePalette); + Blt_ChainLink link = Blt_Chain_FirstLink(stylePalette); + if (link == NULL) { + link = Blt_Chain_AllocLink(size); + Blt_Chain_LinkAfter(stylePalette, link, NULL); + } + PenStyle* stylePtr = Blt_Chain_GetValue(link); + stylePtr->penPtr = NORMALPEN(elemPtr); + for (int ii = 0; ii<objc; ii++) { + link = Blt_Chain_AllocLink(size); + stylePtr = Blt_Chain_GetValue(link); + stylePtr->weight.min = (double)ii; + stylePtr->weight.max = (double)ii + 1.0; + stylePtr->weight.range = 1.0; + if (GetPenStyleFromObj(interp, elemPtr->obj.graphPtr, objv[ii], + elemPtr->obj.classId, + (PenStyle *)stylePtr) != TCL_OK) { + Blt_FreeStylePalette(stylePalette); + return TCL_ERROR; + } + Blt_Chain_LinkAfter(stylePalette, link, NULL); + } + + return TCL_OK; +} + +Tcl_Obj* StyleGetProc(ClientData clientData, Tk_Window tkwin, + char *widgRec, int offset) +{ + Blt_Chain stylePalette = *(Blt_Chain*)(widgRec + offset); + + // count how many + int cnt =0; + for (Blt_ChainLink link = Blt_Chain_FirstLink(stylePalette); !link; + link = Blt_Chain_NextLink(link), cnt++) {} + if (!cnt) + return Tcl_NewListObj(0, (Tcl_Obj**)NULL); + + Tcl_Obj** ll = calloc(3*cnt, sizeof(Tcl_Obj*)); + int ii=0; + for (Blt_ChainLink link = Blt_Chain_FirstLink(stylePalette); !link; + link = Blt_Chain_NextLink(link)) { + PenStyle *stylePtr = Blt_Chain_GetValue(link); + ll[ii++] = Tcl_NewStringObj(stylePtr->penPtr->name, -1); + ll[ii++] = Tcl_NewDoubleObj(stylePtr->weight.min); + ll[ii++] = Tcl_NewDoubleObj(stylePtr->weight.max); + } + Tcl_Obj *listObjPtr = Tcl_NewListObj(3*cnt,ll); + free(ll); + + return listObjPtr; +} +//** + /* Along */ static Blt_OptionParseProc ObjToAlong; diff --git a/src/bltGrElemOp.h b/src/bltGrElemOp.h index b7303b9..b0a0b37 100644 --- a/src/bltGrElemOp.h +++ b/src/bltGrElemOp.h @@ -240,6 +240,9 @@ struct _Element { Blt_ChainLink link; /* Element's link in display list. */ }; +extern char* fillObjOption[]; +extern Tk_CustomOptionSetProc StyleSetProc; +extern Tk_CustomOptionGetProc StyleGetProc; extern double Blt_FindElemValuesMinimum(ElemValues *vecPtr, double minLimit); extern void Blt_ResizeStatusArray(Element *elemPtr, int nPoints); diff --git a/src/bltGrPenOp.C b/src/bltGrPenOp.C index a1f9f19..bac6f04 100644 --- a/src/bltGrPenOp.C +++ b/src/bltGrPenOp.C @@ -90,12 +90,10 @@ static Tcl_Obj* PenGetProc(ClientData clientData, Tk_Window tkwin, { Pen* penPtr = *(Pen**)(widgRec + offset); - if (penPtr == NULL) { + if (penPtr == NULL) return Tcl_NewStringObj("", -1); - } - else { + else return Tcl_NewStringObj(penPtr->name, -1); - } }; //*** |