diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2016-02-13 12:57:00 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2016-02-13 12:57:00 +0000 |
| commit | 5d1df0e789c794b8040c5db0d84b03ae2b42fd8d (patch) | |
| tree | 4e99ebb978d30bf6c7138181489dd37ce435c310 /src/drivers | |
| parent | 8deac1e6baf7a016aabd3b6cb5ccffd7f09263cd (diff) | |
Details on PORTME items. Move fl_parse_color() to screen drivers.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11163 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx | 26 | ||||
| -rw-r--r-- | src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.h | 2 | ||||
| -rw-r--r-- | src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx | 33 | ||||
| -rw-r--r-- | src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.h | 3 | ||||
| -rw-r--r-- | src/drivers/X11/Fl_X11_Screen_Driver.cxx | 36 | ||||
| -rw-r--r-- | src/drivers/X11/Fl_X11_Screen_Driver.h | 5 |
6 files changed, 101 insertions, 4 deletions
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx index 787a9967a..9c6ff5dfa 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx +++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx @@ -20,6 +20,7 @@ #include "../../config_lib.h" #include "Fl_Cocoa_Screen_Driver.h" #include <FL/fl_ask.h> +#include <stdio.h> extern "C" void NSBeep(void); @@ -119,6 +120,31 @@ void Fl_Cocoa_Screen_Driver::flush() { } +// simulation of XParseColor: +int Fl_Cocoa_Screen_Driver::parse_color(const char* p, uchar& r, uchar& g, uchar& b) +{ + if (*p == '#') p++; + size_t n = strlen(p); + size_t m = n/3; + const char *pattern = 0; + switch(m) { + case 1: pattern = "%1x%1x%1x"; break; + case 2: pattern = "%2x%2x%2x"; break; + case 3: pattern = "%3x%3x%3x"; break; + case 4: pattern = "%4x%4x%4x"; break; + default: return 0; + } + int R,G,B; if (sscanf(p,pattern,&R,&G,&B) != 3) return 0; + switch(m) { + case 1: R *= 0x11; G *= 0x11; B *= 0x11; break; + case 3: R >>= 4; G >>= 4; B >>= 4; break; + case 4: R >>= 8; G >>= 8; B >>= 8; break; + } + r = (uchar)R; g = (uchar)G; b = (uchar)B; + return 1; +} + + // // End of "$Id$". // diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.h b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.h index 00ee70c18..02852c514 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.h +++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.h @@ -59,6 +59,8 @@ public: virtual void beep(int type); // --- global events virtual void flush(); + // --- global colors + virtual int parse_color(const char* p, uchar& r, uchar& g, uchar& b); }; diff --git a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx index 0569caca2..f30bee01c 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx @@ -20,11 +20,12 @@ #include "../../config_lib.h" #include "Fl_WinAPI_Screen_Driver.h" #include <FL/fl_ask.h> +#include <stdio.h> -# if !defined(HMONITOR_DECLARED) && (_WIN32_WINNT < 0x0500) -# define COMPILE_MULTIMON_STUBS -# include <multimon.h> -# endif // !HMONITOR_DECLARED && _WIN32_WINNT < 0x0500 +#if !defined(HMONITOR_DECLARED) && (_WIN32_WINNT < 0x0500) +# define COMPILE_MULTIMON_STUBS +# include <multimon.h> +#endif // !HMONITOR_DECLARED && _WIN32_WINNT < 0x0500 /** @@ -239,6 +240,30 @@ void Fl_WinAPI_Screen_Driver::flush() } +// simulation of XParseColor: +int Fl_WinAPI_Screen_Driverparse_color(const char* p, uchar& r, uchar& g, uchar& b) +{ + if (*p == '#') p++; + size_t n = strlen(p); + size_t m = n/3; + const char *pattern = 0; + switch(m) { + case 1: pattern = "%1x%1x%1x"; break; + case 2: pattern = "%2x%2x%2x"; break; + case 3: pattern = "%3x%3x%3x"; break; + case 4: pattern = "%4x%4x%4x"; break; + default: return 0; + } + int R,G,B; if (sscanf(p,pattern,&R,&G,&B) != 3) return 0; + switch(m) { + case 1: R *= 0x11; G *= 0x11; B *= 0x11; break; + case 3: R >>= 4; G >>= 4; B >>= 4; break; + case 4: R >>= 8; G >>= 8; B >>= 8; break; + } + r = (uchar)R; g = (uchar)G; b = (uchar)B; + return 1; +} + // // End of "$Id$". diff --git a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.h b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.h index 14bd1ff2d..ac9849246 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.h +++ b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.h @@ -40,6 +40,7 @@ protected: BOOL screen_cb(HMONITOR mon, HDC, LPRECT r); public: + // --- screen configuration virtual void init(); virtual int x(); virtual int y(); @@ -52,6 +53,8 @@ public: virtual void beep(int type); // --- global events virtual void flush(); + // --- global colors + virtual int parse_color(const char* p, uchar& r, uchar& g, uchar& b); }; diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.cxx b/src/drivers/X11/Fl_X11_Screen_Driver.cxx index e98dc3413..49fa840f5 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Screen_Driver.cxx @@ -42,8 +42,30 @@ Fl_Screen_Driver *Fl_Screen_Driver::newScreenDriver() } +void Fl_X11_Screen_Driver::display(const char *d) +{ + if (!d) return; + + static const char *cmd = "DISPLAY="; + static const char *ext = ":0.0"; + int nc = strlen(cmd); + int ne = strlen(ext); + int nd = strlen(d); + + char *buf = malloc(nc+ne+nd+1); + strcpy(buf, cmd); + strcat(buf, d); + if (strchr(d, ':')) { + strcat(d, ext); + } + putenv(e); + free(buf); +} + + static int fl_workarea_xywh[4] = { -1, -1, -1, -1 }; + void Fl_X11_Screen_Driver::init_workarea() { fl_open_display(); @@ -210,6 +232,20 @@ void Fl_X11_Screen_Driver::flush() } +// Wrapper around XParseColor... +int Fl_X11_Screen_Driver::parse_color(const char* p, uchar& r, uchar& g, uchar& b) +{ + XColor x; + if (!fl_display) fl_open_display(); + if (XParseColor(fl_display, fl_colormap, p, &x)) { + r = (uchar)(x.red>>8); + g = (uchar)(x.green>>8); + b = (uchar)(x.blue>>8); + return 1; + } else return 0; +} + + // // End of "$Id$". // diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.h b/src/drivers/X11/Fl_X11_Screen_Driver.h index 4a4667cf5..27ced8822 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.h +++ b/src/drivers/X11/Fl_X11_Screen_Driver.h @@ -41,6 +41,9 @@ protected: float dpi[MAX_SCREENS][2]; public: + // --- display management + virtual void display(const char *disp); + // --- screen configuration void init_workarea(); virtual void init(); virtual int x(); @@ -54,6 +57,8 @@ public: virtual void beep(int type); // --- global events virtual void flush(); + // --- global colors + virtual int parse_color(const char* p, uchar& r, uchar& g, uchar& b); }; |
