From c78262e0f1d0674bc94022bd0b2cd7f52004307e Mon Sep 17 00:00:00 2001 From: William Joye Date: Fri, 18 Oct 2019 16:00:37 -0400 Subject: add support for MacOS darkmode --- ds9/library/magnifier.tcl | 3 ++- tksao/magnifier/magnifier.C | 2 ++ tksao/magnifier/magnifier.h | 17 +++++++++++++++++ tksao/magnifier/magnifiertrue.C | 36 +++++++++++++++++++++++------------- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/ds9/library/magnifier.tcl b/ds9/library/magnifier.tcl index fe0ad11..806db53 100644 --- a/ds9/library/magnifier.tcl +++ b/ds9/library/magnifier.tcl @@ -22,7 +22,8 @@ proc CreateMagnifier {} { -tag magnifier \ -helvetica $ds9(helvetica) \ -courier $ds9(courier) \ - -times $ds9(times) + -times $ds9(times) \ + -bg $ds9(background) } proc MagnifierDef {} { diff --git a/tksao/magnifier/magnifier.C b/tksao/magnifier/magnifier.C index ae9797e..2c097dc 100644 --- a/tksao/magnifier/magnifier.C +++ b/tksao/magnifier/magnifier.C @@ -38,6 +38,8 @@ Magnifier::Magnifier(Tcl_Interp* i, Tk_Canvas c, Tk_Item* item) { thumbnail = 0; needsUpdate = 0; + + ((MagnifierTrueOptions*)options)->bgColor = NULL; } int Magnifier::parse(istringstream& istr) diff --git a/tksao/magnifier/magnifier.h b/tksao/magnifier/magnifier.h index c007fe8..a9d6b65 100644 --- a/tksao/magnifier/magnifier.h +++ b/tksao/magnifier/magnifier.h @@ -7,6 +7,23 @@ #include "widget.h" +struct MagnifierTrueOptions { + Tk_Item item; // required by tk + int x, y; // Coordinates of positioning point on canvas + int width; // widget width + int height; // widget height + Tk_Anchor anchor; // Where to anchor widget relative to x,y + char* cmdName; // Suggested Tcl command name + + char* helvetica; // name of X11 font + char* courier; // name of X11 font + char* times; // name of X11 font + + Widget* widget; // pointer to widget class + + XColor* bgColor; +}; + class Magnifier : public Widget { private: Pixmap thumbnail; // current gterm thumbnail pixmap diff --git a/tksao/magnifier/magnifiertrue.C b/tksao/magnifier/magnifiertrue.C index d022f62..c1e26bf 100644 --- a/tksao/magnifier/magnifiertrue.C +++ b/tksao/magnifier/magnifiertrue.C @@ -21,26 +21,30 @@ static Tk_CustomOption tagsOption = { static Tk_ConfigSpec magnifierTrueColorSpecs[] = { {TK_CONFIG_STRING, (char*)"-command", NULL, NULL, "magnifier", - Tk_Offset(WidgetOptions, cmdName), TK_CONFIG_OPTION_SPECIFIED, NULL}, + Tk_Offset(MagnifierTrueOptions, cmdName), TK_CONFIG_OPTION_SPECIFIED, NULL}, {TK_CONFIG_INT, (char*)"-x", NULL, NULL, "1", - Tk_Offset(WidgetOptions, x), TK_CONFIG_OPTION_SPECIFIED, NULL}, + Tk_Offset(MagnifierTrueOptions, x), TK_CONFIG_OPTION_SPECIFIED, NULL}, {TK_CONFIG_INT, (char*)"-y", NULL, NULL, "1", - Tk_Offset(WidgetOptions, y), TK_CONFIG_OPTION_SPECIFIED, NULL}, + Tk_Offset(MagnifierTrueOptions, y), TK_CONFIG_OPTION_SPECIFIED, NULL}, {TK_CONFIG_INT, (char*)"-width", NULL, NULL, "256", - Tk_Offset(WidgetOptions, width), TK_CONFIG_OPTION_SPECIFIED, NULL}, + Tk_Offset(MagnifierTrueOptions, width), TK_CONFIG_OPTION_SPECIFIED, NULL}, {TK_CONFIG_INT, (char*)"-height", NULL, NULL, "256", - Tk_Offset(WidgetOptions, height), TK_CONFIG_OPTION_SPECIFIED, NULL}, + Tk_Offset(MagnifierTrueOptions, height), TK_CONFIG_OPTION_SPECIFIED, NULL}, {TK_CONFIG_ANCHOR, (char*)"-anchor", NULL, NULL, "nw", - Tk_Offset(WidgetOptions, anchor), 0, NULL}, + Tk_Offset(MagnifierTrueOptions, anchor), 0, NULL}, {TK_CONFIG_CUSTOM, (char*)"-tags", NULL, NULL, NULL, 0, TK_CONFIG_NULL_OK, &tagsOption}, {TK_CONFIG_STRING, (char*)"-helvetica", NULL, NULL, "helvetica", - Tk_Offset(WidgetOptions, helvetica), 0, NULL}, + Tk_Offset(MagnifierTrueOptions, helvetica), 0, NULL}, {TK_CONFIG_STRING, (char*)"-courier", NULL, NULL, "courier", - Tk_Offset(WidgetOptions, courier), 0, NULL}, + Tk_Offset(MagnifierTrueOptions, courier), 0, NULL}, {TK_CONFIG_STRING, (char*)"-times", NULL, NULL, "times", - Tk_Offset(WidgetOptions, times), 0, NULL}, + Tk_Offset(MagnifierTrueOptions, times), 0, NULL}, + + {TK_CONFIG_SYNONYM, "-bg", "background", NULL, NULL, 0, 0, NULL}, + {TK_CONFIG_COLOR, "-background", "background", "Background", "white", + Tk_Offset(MagnifierTrueOptions, bgColor), 0, NULL}, {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL}, }; @@ -49,7 +53,7 @@ static Tk_ConfigSpec magnifierTrueColorSpecs[] = { static Tk_ItemType magnifierTrueColorType = { (char*)"magnifiertruecolor", // name - sizeof(WidgetOptions), // size + sizeof(MagnifierTrueOptions), // size MagnifierTrueColorCreateProc, // configProc magnifierTrueColorSpecs, // configSpecs WidgetConfigProc, // configProc @@ -105,16 +109,22 @@ MagnifierTrueColor::MagnifierTrueColor(Tcl_Interp* i, Tk_Canvas c, void MagnifierTrueColor::clearPixmap() { + if (0) { XImage* xmap = XGetImage(display, pixmap, 0, 0, options->width, options->height, AllPlanes, ZPixmap); if (!xmap) { internalError("MagnifierTrueColor: Unable to Create XImage"); return; } - memset(xmap->data, 255, xmap->bytes_per_line * xmap->height); - TkPutImage(NULL, 0, display, pixmap, widgetGC, xmap, - 0, 0, 0, 0, options->width, options->height); + 0, 0, 0, 0, options->width, options->height); XDestroyImage(xmap); + } + + MagnifierTrueOptions* opts = (MagnifierTrueOptions*)options; + + XSetForeground(display, widgetGC, opts->bgColor->pixel); + XFillRectangle(display, pixmap, widgetGC, 0, 0, \ + options->width,options->height); } -- cgit v0.12