summaryrefslogtreecommitdiffstats
path: root/tksao/colorbar
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2017-03-27 16:00:44 (GMT)
committerWilliam Joye <wjoye@cfa.harvard.edu>2017-03-27 16:00:44 (GMT)
commite8be6faf948526283b914305758aece629e8d617 (patch)
treea59302d46a131bd0f36b24724aac847ad71f7393 /tksao/colorbar
parent6cbd586d1439b7189e3349533ded31de37a2da43 (diff)
downloadblt-e8be6faf948526283b914305758aece629e8d617.zip
blt-e8be6faf948526283b914305758aece629e8d617.tar.gz
blt-e8be6faf948526283b914305758aece629e8d617.tar.bz2
grid GC
Diffstat (limited to 'tksao/colorbar')
-rw-r--r--tksao/colorbar/cbgrid.C1
-rw-r--r--tksao/colorbar/colorbarbase.C48
-rw-r--r--tksao/colorbar/colorbarbase.h14
3 files changed, 62 insertions, 1 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