From 3eca2271a775a3b4f892746a082d8835e88e44bf Mon Sep 17 00:00:00 2001 From: joye Date: Mon, 14 Apr 2014 19:51:53 +0000 Subject: *** empty log message *** --- configure | 1 + configure.in | 1 + src/bltGrHairs.C | 197 ++++------------------------------------------------- src/bltGrHairs.h | 57 ++++++++++++++++ src/bltGrHairsOp.C | 185 +++++++++++++++++++++++++++++++++++++++++++++++++ src/bltGrHairsOp.h | 43 ++++++++++++ src/bltGrLegd.C | 3 +- src/bltGraph.C | 3 +- src/bltGraph.h | 8 --- 9 files changed, 304 insertions(+), 194 deletions(-) create mode 100644 src/bltGrHairs.h create mode 100644 src/bltGrHairsOp.C create mode 100644 src/bltGrHairsOp.h diff --git a/configure b/configure index f846303..fb121d2 100755 --- a/configure +++ b/configure @@ -5539,6 +5539,7 @@ done bltGrElemBar.C bltGrElemLine.C bltGrHairs.C + bltGrHairsOp.C bltGrLegd.C bltGrLegdOp.C bltGrMarkerOp.C diff --git a/configure.in b/configure.in index 0432717..a7dc716 100755 --- a/configure.in +++ b/configure.in @@ -84,6 +84,7 @@ TEA_ADD_SOURCES([ bltGrElemBar.C bltGrElemLine.C bltGrHairs.C + bltGrHairsOp.C bltGrLegd.C bltGrLegdOp.C bltGrMarkerOp.C diff --git a/src/bltGrHairs.C b/src/bltGrHairs.C index c9fe101..0aea9c6 100644 --- a/src/bltGrHairs.C +++ b/src/bltGrHairs.C @@ -30,47 +30,16 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "bltC.h" - extern "C" { -#include "bltInt.h" #include "bltGraph.h" -#include "bltOp.h" } -#include "bltConfig.h" - -#define PointInGraph(g,x,y) (((x) <= (g)->right) && ((x) >= (g)->left) && ((y) <= (g)->bottom) && ((y) >= (g)->top)) -struct _Crosshairs { - Tk_OptionTable optionTable; - XPoint hotSpot; /* Hot spot for crosshairs */ - int visible; /* Internal state of crosshairs. If non-zero, - * crosshairs are displayed. */ - int hide; /* If non-zero, crosshairs are not displayed. - * This is not necessarily consistent with the - * internal state variable. This is true when - * the hot spot is off the graph. */ - Blt_Dashes dashes; /* Dashstyle of the crosshairs. This represents - * an array of alternatingly drawn pixel - * values. If NULL, the hairs are drawn as a - * solid line */ - int lineWidth; /* Width of the simulated crosshair lines */ - XSegment segArr[2]; /* Positions of line segments representing the - * simulated crosshairs. */ - XColor* colorPtr; /* Foreground color of crosshairs */ - GC gc; /* Graphics context for crosshairs. Set to - * GXxor to not require redraws of graph */ -}; +#include "bltGrHairs.h" -// Defs +extern void TurnOffHairs(Tk_Window tkwin, Crosshairs *chPtr); +extern void TurnOnHairs(Graph* graphPtr, Crosshairs *chPtr); -static int CrosshairsObjConfigure(Tcl_Interp* interp, Graph* graphPtr, - int objc, Tcl_Obj* const objv[]); -static void ConfigureCrosshairs(Graph* graphPtr); -static void TurnOffHairs(Tk_Window tkwin, Crosshairs *chPtr); -static void TurnOnHairs(Graph* graphPtr, Crosshairs *chPtr); -typedef int (GraphCrosshairProc)(Graph* graphPtr, Tcl_Interp* interp, - int objc, Tcl_Obj* const objv[]); +#define PointInGraph(g,x,y) (((x) <= (g)->right) && ((x) >= (g)->left) && ((y) <= (g)->bottom) && ((y) >= (g)->top)) // OptionSpecs @@ -119,86 +88,7 @@ void Blt_DestroyCrosshairs(Graph* graphPtr) // Configure -static int CgetOp(Graph* graphPtr, Tcl_Interp* interp, - int objc, Tcl_Obj* const objv[]) -{ - if (objc != 4) { - Tcl_WrongNumArgs(interp, 2, objv, "cget option"); - return TCL_ERROR; - } - - Crosshairs* chPtr = graphPtr->crosshairs; - Tcl_Obj* objPtr = Tk_GetOptionValue(interp, - (char*)chPtr, - chPtr->optionTable, - objv[3], graphPtr->tkwin); - if (objPtr == NULL) - return TCL_ERROR; - else - Tcl_SetObjResult(interp, objPtr); - return TCL_OK; -} - -static int ConfigureOp(Graph* graphPtr, Tcl_Interp* interp, - int objc, Tcl_Obj* const objv[]) -{ - Crosshairs* chPtr = graphPtr->crosshairs; - if (objc <= 4) { - Tcl_Obj* objPtr = Tk_GetOptionInfo(graphPtr->interp, - (char*)chPtr, - chPtr->optionTable, - (objc == 4) ? objv[3] : NULL, - graphPtr->tkwin); - if (objPtr == NULL) - return TCL_ERROR; - else - Tcl_SetObjResult(interp, objPtr); - return TCL_OK; - } - else - return CrosshairsObjConfigure(interp, graphPtr, objc-3, objv+3); -} - -static int CrosshairsObjConfigure(Tcl_Interp* interp, Graph* graphPtr, - int objc, Tcl_Obj* const objv[]) -{ - Crosshairs* chPtr = graphPtr->crosshairs; - Tk_SavedOptions savedOptions; - int mask =0; - int error; - Tcl_Obj* errorResult; - - for (error=0; error<=1; error++) { - if (!error) { - if (Tk_SetOptions(interp, (char*)chPtr, chPtr->optionTable, - objc, objv, graphPtr->tkwin, &savedOptions, &mask) - != TCL_OK) - continue; - } - else { - errorResult = Tcl_GetObjResult(interp); - Tcl_IncrRefCount(errorResult); - Tk_RestoreSavedOptions(&savedOptions); - } - - graphPtr->flags |= mask; - ConfigureCrosshairs(graphPtr); - - break; - } - - if (!error) { - Tk_FreeSavedOptions(&savedOptions); - return TCL_OK; - } - else { - Tcl_SetObjResult(interp, errorResult); - Tcl_DecrRefCount(errorResult); - return TCL_ERROR; - } -} - -static void ConfigureCrosshairs(Graph* graphPtr) +void ConfigureCrosshairs(Graph* graphPtr) { Crosshairs *chPtr = graphPtr->crosshairs; @@ -241,69 +131,21 @@ static void ConfigureCrosshairs(Graph* graphPtr) TurnOnHairs(graphPtr, chPtr); } -// Ops - -static int OnOp(Graph* graphPtr, Tcl_Interp* interp, - int objc, Tcl_Obj* const objv[]) -{ - Crosshairs *chPtr = graphPtr->crosshairs; - - if (chPtr->hide) { - TurnOnHairs(graphPtr, chPtr); - chPtr->hide = 0; - } - return TCL_OK; -} - -static int OffOp(Graph* graphPtr, Tcl_Interp* interp, - int objc, Tcl_Obj* const objv[]) -{ - Crosshairs *chPtr = graphPtr->crosshairs; - - if (!chPtr->hide) { - TurnOffHairs(graphPtr->tkwin, chPtr); - chPtr->hide = 1; - } - return TCL_OK; -} +// Support -static int ToggleOp(Graph* graphPtr, Tcl_Interp* interp, - int objc, Tcl_Obj* const objv[]) +void Blt_EnableCrosshairs(Graph* graphPtr) { - Crosshairs *chPtr = graphPtr->crosshairs; - - chPtr->hide = (chPtr->hide == 0); - if (chPtr->hide) - TurnOffHairs(graphPtr->tkwin, chPtr); - else - TurnOnHairs(graphPtr, chPtr); - - return TCL_OK; + if (!graphPtr->crosshairs->hide) + TurnOnHairs(graphPtr, graphPtr->crosshairs); } -static Blt_OpSpec xhairOps[] = - { - {"cget", 2, (void*)CgetOp, 4, 4, "option",}, - {"configure", 2, (void*)ConfigureOp, 3, 0, "?options...?",}, - {"off", 2, (void*)OffOp, 3, 3, "",}, - {"on", 2, (void*)OnOp, 3, 3, "",}, - {"toggle", 1, (void*)ToggleOp, 3, 3, "",}, - }; -static int nXhairOps = sizeof(xhairOps) / sizeof(Blt_OpSpec); - -int Blt_CrosshairsOp(Graph* graphPtr, Tcl_Interp* interp, - int objc, Tcl_Obj* const objv[]) +void Blt_DisableCrosshairs(Graph* graphPtr) { - GraphCrosshairProc* proc = (GraphCrosshairProc*)Blt_GetOpFromObj(interp, nXhairOps, xhairOps, BLT_OP_ARG2, objc, objv, 0); - if (proc == NULL) - return TCL_ERROR; - - return (*proc)(graphPtr, interp, objc, objv); + if (!graphPtr->crosshairs->hide) + TurnOffHairs(graphPtr->tkwin, graphPtr->crosshairs); } -// Support - -static void TurnOffHairs(Tk_Window tkwin, Crosshairs *chPtr) +void TurnOffHairs(Tk_Window tkwin, Crosshairs *chPtr) { if (Tk_IsMapped(tkwin) && (chPtr->visible)) { XDrawSegments(Tk_Display(tkwin), Tk_WindowId(tkwin), chPtr->gc, @@ -312,7 +154,7 @@ static void TurnOffHairs(Tk_Window tkwin, Crosshairs *chPtr) } } -static void TurnOnHairs(Graph* graphPtr, Crosshairs *chPtr) +void TurnOnHairs(Graph* graphPtr, Crosshairs *chPtr) { if (Tk_IsMapped(graphPtr->tkwin) && (!chPtr->visible)) { if (!PointInGraph(graphPtr, chPtr->hotSpot.x, chPtr->hotSpot.y)) { @@ -324,14 +166,3 @@ static void TurnOnHairs(Graph* graphPtr, Crosshairs *chPtr) } } -void Blt_EnableCrosshairs(Graph* graphPtr) -{ - if (!graphPtr->crosshairs->hide) - TurnOnHairs(graphPtr, graphPtr->crosshairs); -} - -void Blt_DisableCrosshairs(Graph* graphPtr) -{ - if (!graphPtr->crosshairs->hide) - TurnOffHairs(graphPtr->tkwin, graphPtr->crosshairs); -} diff --git a/src/bltGrHairs.h b/src/bltGrHairs.h new file mode 100644 index 0000000..040a35a --- /dev/null +++ b/src/bltGrHairs.h @@ -0,0 +1,57 @@ +/* + * Smithsonian Astrophysical Observatory, Cambridge, MA, USA + * This code has been modified under the terms listed below and is made + * available under the same terms. + */ + +/* + * Copyright 1993-2004 George A Howlett. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY + * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS + * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BltGrHairs_h__ +#define __BltGrHairs_h__ + +#include +#include +#include +using namespace std; + +extern "C" { +#include "bltGraph.h" +}; + +struct _Crosshairs { + Tk_OptionTable optionTable; + XPoint hotSpot; + int visible; + int hide; + Blt_Dashes dashes; + int lineWidth; + XSegment segArr[2]; + XColor* colorPtr; + GC gc; +}; + +#endif diff --git a/src/bltGrHairsOp.C b/src/bltGrHairsOp.C new file mode 100644 index 0000000..db2fe36 --- /dev/null +++ b/src/bltGrHairsOp.C @@ -0,0 +1,185 @@ +/* + * Smithsonian Astrophysical Observatory, Cambridge, MA, USA + * This code has been modified under the terms listed below and is made + * available under the same terms. + */ + +/* + * Copyright 1993-2004 George A Howlett. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY + * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS + * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +extern "C" { +#include "bltGraph.h" +#include "bltOp.h" +} + +#include "bltGrHairs.h" + +extern void ConfigureCrosshairs(Graph* graphPtr); +extern void TurnOffHairs(Tk_Window tkwin, Crosshairs *chPtr); +extern void TurnOnHairs(Graph* graphPtr, Crosshairs *chPtr); + +static int CrosshairsObjConfigure(Tcl_Interp* interp, Graph* graphPtr, + int objc, Tcl_Obj* const objv[]) +{ + Crosshairs* chPtr = graphPtr->crosshairs; + Tk_SavedOptions savedOptions; + int mask =0; + int error; + Tcl_Obj* errorResult; + + for (error=0; error<=1; error++) { + if (!error) { + if (Tk_SetOptions(interp, (char*)chPtr, chPtr->optionTable, + objc, objv, graphPtr->tkwin, &savedOptions, &mask) + != TCL_OK) + continue; + } + else { + errorResult = Tcl_GetObjResult(interp); + Tcl_IncrRefCount(errorResult); + Tk_RestoreSavedOptions(&savedOptions); + } + + graphPtr->flags |= mask; + ConfigureCrosshairs(graphPtr); + + break; + } + + if (!error) { + Tk_FreeSavedOptions(&savedOptions); + return TCL_OK; + } + else { + Tcl_SetObjResult(interp, errorResult); + Tcl_DecrRefCount(errorResult); + return TCL_ERROR; + } +} + +static int CgetOp(Graph* graphPtr, Tcl_Interp* interp, + int objc, Tcl_Obj* const objv[]) +{ + if (objc != 4) { + Tcl_WrongNumArgs(interp, 2, objv, "cget option"); + return TCL_ERROR; + } + + Crosshairs* chPtr = graphPtr->crosshairs; + Tcl_Obj* objPtr = Tk_GetOptionValue(interp, + (char*)chPtr, + chPtr->optionTable, + objv[3], graphPtr->tkwin); + if (objPtr == NULL) + return TCL_ERROR; + else + Tcl_SetObjResult(interp, objPtr); + return TCL_OK; +} + +static int ConfigureOp(Graph* graphPtr, Tcl_Interp* interp, + int objc, Tcl_Obj* const objv[]) +{ + Crosshairs* chPtr = graphPtr->crosshairs; + if (objc <= 4) { + Tcl_Obj* objPtr = Tk_GetOptionInfo(graphPtr->interp, + (char*)chPtr, + chPtr->optionTable, + (objc == 4) ? objv[3] : NULL, + graphPtr->tkwin); + if (objPtr == NULL) + return TCL_ERROR; + else + Tcl_SetObjResult(interp, objPtr); + return TCL_OK; + } + else + return CrosshairsObjConfigure(interp, graphPtr, objc-3, objv+3); +} + +static int OnOp(Graph* graphPtr, Tcl_Interp* interp, + int objc, Tcl_Obj* const objv[]) +{ + Crosshairs *chPtr = graphPtr->crosshairs; + + if (chPtr->hide) { + TurnOnHairs(graphPtr, chPtr); + chPtr->hide = 0; + } + return TCL_OK; +} + +static int OffOp(Graph* graphPtr, Tcl_Interp* interp, + int objc, Tcl_Obj* const objv[]) +{ + Crosshairs *chPtr = graphPtr->crosshairs; + + if (!chPtr->hide) { + TurnOffHairs(graphPtr->tkwin, chPtr); + chPtr->hide = 1; + } + return TCL_OK; +} + +static int ToggleOp(Graph* graphPtr, Tcl_Interp* interp, + int objc, Tcl_Obj* const objv[]) +{ + Crosshairs *chPtr = graphPtr->crosshairs; + + chPtr->hide = (chPtr->hide == 0); + if (chPtr->hide) + TurnOffHairs(graphPtr->tkwin, chPtr); + else + TurnOnHairs(graphPtr, chPtr); + + return TCL_OK; +} + +static Blt_OpSpec xhairOps[] = + { + {"cget", 2, (void*)CgetOp, 4, 4, "option",}, + {"configure", 2, (void*)ConfigureOp, 3, 0, "?options...?",}, + {"off", 2, (void*)OffOp, 3, 3, "",}, + {"on", 2, (void*)OnOp, 3, 3, "",}, + {"toggle", 1, (void*)ToggleOp, 3, 3, "",}, + }; +static int nXhairOps = sizeof(xhairOps) / sizeof(Blt_OpSpec); + +typedef int (GraphCrosshairProc)(Graph* graphPtr, Tcl_Interp* interp, + int objc, Tcl_Obj* const objv[]); + +int Blt_CrosshairsOp(Graph* graphPtr, Tcl_Interp* interp, + int objc, Tcl_Obj* const objv[]) +{ + GraphCrosshairProc* proc = (GraphCrosshairProc*)Blt_GetOpFromObj(interp, nXhairOps, xhairOps, BLT_OP_ARG2, objc, objv, 0); + if (proc == NULL) + return TCL_ERROR; + + return (*proc)(graphPtr, interp, objc, objv); +} + +// Support + diff --git a/src/bltGrHairsOp.h b/src/bltGrHairsOp.h new file mode 100644 index 0000000..3e47bf0 --- /dev/null +++ b/src/bltGrHairsOp.h @@ -0,0 +1,43 @@ +/* + * Smithsonian Astrophysical Observatory, Cambridge, MA, USA + * This code has been modified under the terms listed below and is made + * available under the same terms. + */ + +/* + * Copyright 1993-2004 George A Howlett. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY + * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS + * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef __BltGrHairsOp_h__ +#define __BltGrHairsOp_h__ + +extern int Blt_CrosshairsOp(Graph* graphPtr, Tcl_Interp* interp, int objc, + Tcl_Obj* const objv[]); +extern int Blt_CreateCrosshairs(Graph* graphPtr); +extern void Blt_DestroyCrosshairs(Graph* graphPtr); +extern void Blt_DisableCrosshairs(Graph* graphPtr); +extern void Blt_EnableCrosshairs(Graph* graphPtr); + +#endif diff --git a/src/bltGrLegd.C b/src/bltGrLegd.C index d307657..00d3dcb 100644 --- a/src/bltGrLegd.C +++ b/src/bltGrLegd.C @@ -29,13 +29,12 @@ extern "C" { #include "bltGraph.h" -#include "bltOp.h" }; #include "bltGrLegd.h" -#include "bltConfig.h" #include "bltGrElem.h" #include "bltGrElemOp.h" +#include "bltGrHairsOp.h" static void SelectCmdProc(ClientData); static Tcl_IdleProc DisplayProc; diff --git a/src/bltGraph.C b/src/bltGraph.C index db2759c..3a81a1c 100644 --- a/src/bltGraph.C +++ b/src/bltGraph.C @@ -27,7 +27,6 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "bltC.h" #include "bltMath.h" extern "C" { @@ -48,6 +47,8 @@ extern "C" { #include "bltGrMarkerOp.h" #include "bltGrLegd.h" #include "bltGrLegdOp.h" +#include "bltGrHairs.h" +#include "bltGrHairsOp.h" using namespace Blt; diff --git a/src/bltGraph.h b/src/bltGraph.h index 0c4ea73..c021574 100644 --- a/src/bltGraph.h +++ b/src/bltGraph.h @@ -391,14 +391,6 @@ extern int Blt_PointInPolygon(Point2d *samplePtr, Point2d *screenPts, int nScreenPts); -// Crosshairs -extern int Blt_CrosshairsOp(Graph* graphPtr, Tcl_Interp* interp, int objc, - Tcl_Obj* const objv[]); -extern int Blt_CreateCrosshairs(Graph* graphPtr); -extern void Blt_DestroyCrosshairs(Graph* graphPtr); -extern void Blt_DisableCrosshairs(Graph* graphPtr); -extern void Blt_EnableCrosshairs(Graph* graphPtr); - // Postscript extern int Blt_PostScriptOp(Graph* graphPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[]); -- cgit v0.12