From 02b5ad0e3363f85a0a7e89cf4bd46d81dbcdc440 Mon Sep 17 00:00:00 2001 From: William Joye Date: Mon, 27 Mar 2017 11:52:41 -0400 Subject: use gridGC_ --- tksao/colorbar/cbgrid.C | 1 + tksao/colorbar/colorbarbase.C | 48 ++++++++++++++++++++++++++++++++++++++++++- tksao/colorbar/colorbarbase.h | 14 +++++++++++++ tksao/frame/base.C | 8 ++++---- tksao/frame/base.h | 2 +- tksao/frame/grid25d.C | 1 + tksao/frame/grid2d.C | 1 + tksao/frame/grid3d.C | 1 + tksao/util/gridbase.C | 9 ++------ 9 files changed, 72 insertions(+), 13 deletions(-) diff --git a/tksao/colorbar/cbgrid.C b/tksao/colorbar/cbgrid.C index 48bfb52..4c390a4 100644 --- a/tksao/colorbar/cbgrid.C +++ b/tksao/colorbar/cbgrid.C @@ -74,6 +74,7 @@ CBGrid::CBGrid(Widget* p, int cc, double* ll) int CBGrid::render() { pixmap_ = ((ColorbarBase*)parent_)->pixmap; + gridGC_ = ((ColorbarBase*)parent_)->gridGC_; return doit(X11); } diff --git a/tksao/colorbar/colorbarbase.C b/tksao/colorbar/colorbarbase.C index e454468..daa33dc 100644 --- a/tksao/colorbar/colorbarbase.C +++ b/tksao/colorbar/colorbarbase.C @@ -51,6 +51,7 @@ ColorbarBase::ColorbarBase(Tcl_Interp* i, Tk_Canvas c, Tk_Item* item) colorCount = 0; grid = NULL; + gridGC_ = NULL; cnt = 0; lut = NULL; @@ -73,6 +74,9 @@ ColorbarBase::~ColorbarBase() if (grid) delete grid; + if (gridGC_) + XFreeGC(display, gridGC_); + if (lut) delete [] lut; @@ -281,9 +285,14 @@ void ColorbarBase::updateColors() int ColorbarBase::updatePixmap(const BBox& bb) { + updateMatrices(); + if (!widgetGC) widgetGC = XCreateGC(display, Tk_WindowId(tkwin), 0, NULL); + if (!gridGC_) + gridGC_ = XCreateGC(display, Tk_WindowId(tkwin), 0, NULL); + ColorbarBaseOptions* opts = (ColorbarBaseOptions*)options; if (pixmap) @@ -297,10 +306,14 @@ int ColorbarBase::updatePixmap(const BBox& bb) options->height, depth))) { internalError("Colorbar: Unable to Create Pixmap"); return TCL_OK; + + // Geometry has changed, redefine our marker GCs including clip regions + updateGCs(); } XSetForeground(display, widgetGC, getColor("white")); - XFillRectangle(display, pixmap, widgetGC, 0, 0, options->width,options->height); + XFillRectangle(display, pixmap, widgetGC, 0, 0, + options->width,options->height); if (!opts->orientation) { if (!(xmap = XGetImage(display, pixmap, 1, 1, @@ -333,6 +346,39 @@ int ColorbarBase::updatePixmap(const BBox& bb) return TCL_OK; } +void ColorbarBase::updateMatrices() +{ + widgetToCanvas = Translate(originX, originY); + short xx, yy; + Tk_CanvasWindowCoords(canvas, 0, 0, &xx, &yy); + canvasToWindow = Translate(xx, yy); + widgetToWindow = widgetToCanvas * canvasToWindow; +} + +void ColorbarBase::updateGCs() +{ + // widget clip region + BBox bbWidget = BBox(0, 0, options->width, options->height); + Vector sizeWidget = bbWidget.size(); + + rectWidget[0].x = (int)bbWidget.ll[0]; + rectWidget[0].y = (int)bbWidget.ll[1]; + rectWidget[0].width = (int)sizeWidget[0]; + rectWidget[0].height = (int)sizeWidget[1]; + + // window clip region + BBox bbWindow = bbWidget * widgetToWindow; + Vector sizeWindow = bbWindow.size(); + + rectWindow[0].x = (int)bbWindow.ll[0]; + rectWindow[0].y = (int)bbWindow.ll[1]; + rectWindow[0].width = (int)sizeWindow[0]; + rectWindow[0].height = (int)sizeWindow[1]; + + // gridGC + XSetClipRectangles(display, gridGC_, 0, 0, rectWidget, 1, Unsorted); +} + void ColorbarBase::renderGrid() { ColorbarBaseOptions* opts = (ColorbarBaseOptions*)options; diff --git a/tksao/colorbar/colorbarbase.h b/tksao/colorbar/colorbarbase.h index 91cea8c..70c4736 100644 --- a/tksao/colorbar/colorbarbase.h +++ b/tksao/colorbar/colorbarbase.h @@ -70,6 +70,18 @@ class ColorbarBase : public Widget { int colorCount; CBGrid* grid; + GC gridGC_; + + XRectangle rectWidget[1]; + XRectangle rectWindow[1]; + + Matrix widgetToCanvas; + Matrix canvasToWidget; + Matrix widgetToWindow; + Matrix windowToWidget; + + Matrix canvasToWindow; + Matrix windowToCanvas; int cnt; double* lut; @@ -109,6 +121,8 @@ class ColorbarBase : public Widget { #endif protected: + void updateGCs(); + void updateMatrices(); void invalidPixmap(); int postscriptProc(int); // generate postscript diff --git a/tksao/frame/base.C b/tksao/frame/base.C index d981b9c..3a0c865 100644 --- a/tksao/frame/base.C +++ b/tksao/frame/base.C @@ -150,7 +150,7 @@ Base::Base(Tcl_Interp* i, Tk_Canvas c, Tk_Item* item) XSetForeground(display, selectGCXOR, getColor("white")); grid = NULL; - gridGC = XCreateGC(display, Tk_WindowId(tkwin), 0, NULL); + gridGC_ = XCreateGC(display, Tk_WindowId(tkwin), 0, NULL); contourGC = XCreateGC(display, Tk_WindowId(tkwin), 0, NULL); XSetLineAttributes(display, contourGC, 1, LineSolid, CapButt, JoinMiter); @@ -234,8 +234,8 @@ Base::~Base() if (grid) delete grid; - if (gridGC) - XFreeGC(display, gridGC); + if (gridGC_) + XFreeGC(display, gridGC_); if (contourGC) XFreeGC(display, contourGC); @@ -1665,7 +1665,7 @@ void Base::updateGCs() XSetClipRectangles(display, selectGCXOR, 0, 0, rectWindow, 1, Unsorted); // gridGC - XSetClipRectangles(display, gridGC, 0, 0, rectWidget, 1, Unsorted); + XSetClipRectangles(display, gridGC_, 0, 0, rectWidget, 1, Unsorted); // contourGC XSetClipRectangles(display, contourGC, 0, 0, rectWidget, 1, Unsorted); diff --git a/tksao/frame/base.h b/tksao/frame/base.h index 76aa468..3421536 100644 --- a/tksao/frame/base.h +++ b/tksao/frame/base.h @@ -260,7 +260,7 @@ public: GC selectGCXOR; // select gc Grid* grid; - GC gridGC; + GC gridGC_; GC contourGC; diff --git a/tksao/frame/grid25d.C b/tksao/frame/grid25d.C index cc9da43..e4789f8 100644 --- a/tksao/frame/grid25d.C +++ b/tksao/frame/grid25d.C @@ -28,6 +28,7 @@ int Grid25d::doit(RenderMode rm) matrix_ = pp->widgetToCanvas; pixmap_ = pp->pixmap; + gridGC_ = pp->gridGC_; renderMode_ = rm; Context* context = pp->keyContext; diff --git a/tksao/frame/grid2d.C b/tksao/frame/grid2d.C index 7549dea..d1813a9 100644 --- a/tksao/frame/grid2d.C +++ b/tksao/frame/grid2d.C @@ -28,6 +28,7 @@ int Grid2d::doit(RenderMode rm) matrix_ = pp->widgetToCanvas; pixmap_ = pp->pixmap; + gridGC_ = pp->gridGC_; renderMode_ = rm; Context* context = pp->keyContext; diff --git a/tksao/frame/grid3d.C b/tksao/frame/grid3d.C index d646418..009de90 100644 --- a/tksao/frame/grid3d.C +++ b/tksao/frame/grid3d.C @@ -56,6 +56,7 @@ int Grid3d::doit(RenderMode rm) matrix_ = pp->widgetToCanvas; pixmap_ = pp->pixmap; + gridGC_ = pp->gridGC_; renderMode_ = rm; Context* context = pp->keyContext; diff --git a/tksao/util/gridbase.C b/tksao/util/gridbase.C index a941755..389e025 100644 --- a/tksao/util/gridbase.C +++ b/tksao/util/gridbase.C @@ -24,8 +24,7 @@ GridBase::GridBase(Widget* pp) : parent_(pp) line_ = new Attribute(parent_); text_ = new Attribute(parent_); - gridGC_ = XCreateGC(parent_->getDisplay(), Tk_WindowId(parent_->getTkwin()), - 0, NULL); + gridGC_ = NULL; pixmap_ = 0; mode_ = Widget::RGB; @@ -39,8 +38,7 @@ GridBase::GridBase(Widget* pp, const char* op) : parent_(pp) line_ = new Attribute(parent_); text_ = new Attribute(parent_); - gridGC_ = XCreateGC(parent_->getDisplay(), Tk_WindowId(parent_->getTkwin()), - 0, NULL); + gridGC_ = NULL; pixmap_ = 0; mode_ = Widget::RGB; @@ -51,9 +49,6 @@ GridBase::~GridBase() if (option_) delete [] option_; - if (gridGC_) - XFreeGC(parent_->getDisplay(), gridGC_); - if (line_) delete line_; if (text_) -- cgit v0.12