diff options
author | joye <joye> | 2014-06-20 16:10:53 (GMT) |
---|---|---|
committer | joye <joye> | 2014-06-20 16:10:53 (GMT) |
commit | 472d825d2666b06a63770c012a929ce18c370ad3 (patch) | |
tree | 0751247613b5daabb8000bd6b0645e15b3c68714 /src | |
parent | 44af28b3c45ae5c2b8185b1801fa4e63c6eccd1c (diff) | |
download | blt-472d825d2666b06a63770c012a929ce18c370ad3.zip blt-472d825d2666b06a63770c012a929ce18c370ad3.tar.gz blt-472d825d2666b06a63770c012a929ce18c370ad3.tar.bz2 |
*** empty log message ***
Diffstat (limited to 'src')
-rw-r--r-- | src/bltGrHairs.C | 75 |
1 files changed, 24 insertions, 51 deletions
diff --git a/src/bltGrHairs.C b/src/bltGrHairs.C index 3931681..7f77670 100644 --- a/src/bltGrHairs.C +++ b/src/bltGrHairs.C @@ -39,16 +39,12 @@ using namespace Blt; -#define PointInGraph(g,x,y) (((x) <= (g)->right_) && ((x) >= (g)->left_) && ((y) <= (g)->bottom_) && ((y) >= (g)->top_)) - static Tk_OptionSpec optionSpecs[] = { {TK_OPTION_COLOR, "-color", "color", "Color", "green", -1, Tk_Offset(CrosshairsOptions, colorPtr), 0, NULL, 0}, {TK_OPTION_CUSTOM, "-dashes", "dashes", "Dashes", NULL, -1, Tk_Offset(CrosshairsOptions, dashes), TK_OPTION_NULL_OK, &dashesObjOption, 0}, - {TK_OPTION_BOOLEAN, "-hide", "hide", "Hide", - "yes", -1, Tk_Offset(CrosshairsOptions, hide), 0, NULL, 0}, {TK_OPTION_PIXELS, "-linewidth", "lineWidth", "Linewidth", "1", -1, Tk_Offset(CrosshairsOptions, lineWidth), 0, NULL, 0}, {TK_OPTION_PIXELS, "-x", "x", "X", @@ -67,7 +63,8 @@ Crosshairs::Crosshairs(Graph* graphPtr) gc_ =NULL; optionTable_ = Tk_CreateOptionTable(graphPtr->interp_, optionSpecs); - Tk_InitOptions(graphPtr->interp_, (char*)ops_, optionTable_, graphPtr->tkwin_); + Tk_InitOptions(graphPtr->interp_, (char*)ops_, optionTable_, + graphPtr->tkwin_); } Crosshairs::~Crosshairs() @@ -84,22 +81,11 @@ Crosshairs::~Crosshairs() int Crosshairs::configure() { CrosshairsOptions* ops = (CrosshairsOptions*)ops_; - GraphOptions* gops = (GraphOptions*)graphPtr_->ops_; - - // Turn off the crosshairs temporarily. This is in case the new - // configuration changes the size, style, or position of the lines. - off(); XGCValues gcValues; - gcValues.function = GXxor; - - unsigned long int pixel = Tk_3DBorderColor(gops->plotBg)->pixel; - gcValues.background = pixel; - gcValues.foreground = (pixel ^ ops->colorPtr->pixel); - + gcValues.foreground = ops->colorPtr->pixel; gcValues.line_width = ops->lineWidth; - unsigned long gcMask = - (GCForeground | GCBackground | GCFunction | GCLineWidth); + unsigned long gcMask = (GCForeground | GCLineWidth); if (LineIsDashed(ops->dashes)) { gcValues.line_style = LineOnOffDash; gcMask |= GCLineStyle; @@ -108,12 +94,20 @@ int Crosshairs::configure() if (LineIsDashed(ops->dashes)) graphPtr_->setDashes(newGC, &ops->dashes); - if (gc_ != NULL) + if (gc_) graphPtr_->freePrivateGC(gc_); - gc_ = newGC; // Are the new coordinates on the graph? + map(); + + return TCL_OK; +} + +void Crosshairs::map() +{ + CrosshairsOptions* ops = (CrosshairsOptions*)ops_; + segArr_[0].x1 = ops->x; segArr_[0].x2 = ops->x; segArr_[0].y1 = graphPtr_->bottom_; @@ -122,48 +116,27 @@ int Crosshairs::configure() segArr_[1].y2 = ops->y; segArr_[1].x1 = graphPtr_->left_; segArr_[1].x2 = graphPtr_->right_; - - enable(); - - return TCL_OK; } -void Crosshairs::enable() -{ - CrosshairsOptions* ops = (CrosshairsOptions*)ops_; - if (!ops->hide) - on(); -} - -void Crosshairs::disable() +void Crosshairs::on() { - CrosshairsOptions* ops = (CrosshairsOptions*)ops_; - if (!ops->hide) - off(); + visible_ =1; } void Crosshairs::off() { - if (Tk_IsMapped(graphPtr_->tkwin_) && (visible_)) { - XDrawSegments(graphPtr_->display_, Tk_WindowId(graphPtr_->tkwin_), - gc_, segArr_, 2); - visible_ = 0; - } + visible_ =0; } -void Crosshairs::on() +void Crosshairs::draw(Drawable drawable) { CrosshairsOptions* ops = (CrosshairsOptions*)ops_; - if (Tk_IsMapped(graphPtr_->tkwin_) && (!visible_)) { - if (!PointInGraph(graphPtr_, ops->x, ops->y)) - return; - - XDrawSegments(graphPtr_->display_, Tk_WindowId(graphPtr_->tkwin_), - gc_, segArr_, 2); - visible_ = 1; + if (visible_ && Tk_IsMapped(graphPtr_->tkwin_)) { + if (ops->x <= graphPtr_->right_ && + ops->x >= graphPtr_->left_ && + ops->y <= graphPtr_->bottom_ && + ops->y >= graphPtr_->top_) + XDrawSegments(graphPtr_->display_, drawable, gc_, segArr_, 2); } } - - - |