summaryrefslogtreecommitdiffstats
path: root/tksao/magnifier/magnifier.C
diff options
context:
space:
mode:
Diffstat (limited to 'tksao/magnifier/magnifier.C')
-rw-r--r--tksao/magnifier/magnifier.C114
1 files changed, 114 insertions, 0 deletions
diff --git a/tksao/magnifier/magnifier.C b/tksao/magnifier/magnifier.C
new file mode 100644
index 0000000..5d55824
--- /dev/null
+++ b/tksao/magnifier/magnifier.C
@@ -0,0 +1,114 @@
+// Copyright (C) 1999-2016
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <math.h>
+
+#include "magnifier.h"
+#include "util.h"
+
+// Parser Stuff
+#undef yyFlexLexer
+#define yyFlexLexer mgFlexLexer
+#include <FlexLexer.h>
+
+void* mglval;
+extern int mgparse(Magnifier*, mgFlexLexer*);
+
+int mglex(void* vval, mgFlexLexer* ll)
+{
+ mglval = vval;
+ return ll ? ll->yylex() : 0;
+}
+
+void mgerror(Magnifier* mg, mgFlexLexer* ll, const char* m)
+{
+ mg->error(m);
+ const char* cmd = ll ? ll->YYText() : (const char*)NULL;
+ if (cmd && cmd[0] != '\n') {
+ mg->error(": ");
+ mg->error(cmd);
+ }
+}
+
+// Public Member Functions
+
+Magnifier::Magnifier(Tcl_Interp* i, Tk_Canvas c, Tk_Item* item)
+ : Widget(i, c, item)
+{
+ thumbnail = 0;
+ needsUpdate = 0;
+}
+
+int Magnifier::parse(istringstream& istr)
+{
+ result = TCL_OK;
+ mgFlexLexer* ll = new mgFlexLexer(&istr);
+ mgparse(this, ll);
+ delete ll;
+
+ return result;
+}
+
+void Magnifier::update()
+{
+ needsUpdate = 1;
+ redrawNow();
+}
+
+// Required Virtual Functions
+
+// UpdatePixmap. This function is responsable for creating a valid
+// pixmap the size of the current Magnifier
+
+int Magnifier::updatePixmap(const BBox& bb)
+{
+ if (!widgetGC)
+ widgetGC = XCreateGC(display, Tk_WindowId(tkwin), 0, NULL);
+
+ // create a valid pixmap if needed
+ // bb is in canvas coords
+
+ if (!pixmap)
+ if (!(pixmap = Tk_GetPixmap(display, Tk_WindowId(tkwin),
+ options->width, options->height, depth))) {
+ internalError("Magnifier: Unable to Create Pixmap");
+ return TCL_OK;
+ }
+
+ if (needsUpdate) {
+ if (thumbnail) {
+ XSetClipOrigin(display, widgetGC, 0, 0);
+ XCopyArea(display, thumbnail, pixmap, widgetGC, 0, 0,
+ options->width, options->height, 0, 0);
+ }
+ else
+ clearPixmap();
+
+ needsUpdate = 0;
+ }
+
+ return TCL_OK;
+}
+
+void Magnifier::invalidPixmap()
+{
+ Widget::invalidPixmap();
+ update();
+}
+
+// Command Functions
+
+void Magnifier::getBBoxCmd()
+{
+ ostringstream str;
+ str << options->width << " " << options->height << ends;
+ Tcl_AppendResult(interp, str.str().c_str(), NULL);
+}
+
+void Magnifier::updateCmd(void* p)
+{
+ thumbnail = (Pixmap)p;
+ update();
+}
+