summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2022-09-15 15:01:12 +0200
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2022-09-15 15:01:12 +0200
commit699cca8ff4367c15ea0cda1b5750c68eac174816 (patch)
tree9bba71685e9b649c80c5e1acff32597a05008a22 /src/drivers
parent700fb1aadd86f6fc81f4acccfe44dd539f487c57 (diff)
Make Fl::set_color(r,g,b,a) effective under Wayland and macOS.
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx27
-rw-r--r--src/drivers/Quartz/Fl_Quartz_Graphics_Driver_color.cxx9
2 files changed, 31 insertions, 5 deletions
diff --git a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
index ea651cf27..e601df142 100644
--- a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
+++ b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
@@ -31,6 +31,7 @@
#include <stdlib.h> // abs(int)
#include <string.h> // memcpy()
+extern unsigned fl_cmap[256]; // defined in fl_color.cxx
// duplicated from Fl_PostScript.cxx
struct callback_data {
@@ -331,9 +332,29 @@ void Fl_Cairo_Graphics_Driver::color(unsigned char r, unsigned char g, unsigned
check_status();
}
-void Fl_Cairo_Graphics_Driver::color(Fl_Color c) {
- Fl::get_color(c, cr_, cg_, cb_);
- Fl_Cairo_Graphics_Driver::color(cr_, cg_, cb_);
+void Fl_Cairo_Graphics_Driver::color(Fl_Color i) {
+ Fl_Graphics_Driver::color(i);
+ if (!cairo_) return; // no context yet? We will assign the color later.
+ uchar r, g, b;
+ double fa = 1.0;
+ if (i & 0xFFFFFF00) {
+ // translate rgb colors into color index
+ r = i>>24;
+ g = i>>16;
+ b = i>> 8;
+ } else {
+ // translate index into rgb:
+ unsigned c = fl_cmap[i];
+ c = c ^ 0x000000ff; // trick to restore the color's correct alpha value
+ r = c>>24;
+ g = c>>16;
+ b = c>> 8;
+ fa = (c & 0xff)/255.0;
+ }
+ double fr = r/255.0;
+ double fg = g/255.0;
+ double fb = b/255.0;
+ cairo_set_source_rgba(cairo_, fr, fg, fb, fa);
}
Fl_Color Fl_Cairo_Graphics_Driver::color() { return Fl_Graphics_Driver::color(); }
diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_color.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_color.cxx
index a4cb37d73..9d31f8573 100644
--- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_color.cxx
+++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_color.cxx
@@ -34,6 +34,7 @@ extern unsigned fl_cmap[256]; // defined in fl_color.cxx
void Fl_Quartz_Graphics_Driver::color(Fl_Color i) {
Fl_Graphics_Driver::color(i);
uchar r, g, b;
+ float fa = 1.0f;
if (i & 0xFFFFFF00) {
// translate rgb colors into color index
r = i>>24;
@@ -42,16 +43,20 @@ void Fl_Quartz_Graphics_Driver::color(Fl_Color i) {
} else {
// translate index into rgb:
unsigned c = fl_cmap[i];
+ c = c ^ 0x000000ff; // trick to restore the color's correct alpha value
r = c>>24;
g = c>>16;
b = c>> 8;
+ uchar a = c & 0xff;
+ //printf("i=%d rgb=%u,%u,%u a=%u\n",i,r,g,b,a);
+ fa = a/255.0f;
}
if (!gc_) return; // no context yet? We will assign the color later.
float fr = r/255.0f;
float fg = g/255.0f;
float fb = b/255.0f;
- CGContextSetRGBFillColor(gc_, fr, fg, fb, 1.0f);
- CGContextSetRGBStrokeColor(gc_, fr, fg, fb, 1.0f);
+ CGContextSetRGBFillColor(gc_, fr, fg, fb, fa);
+ CGContextSetRGBStrokeColor(gc_, fr, fg, fb, fa);
}
void Fl_Quartz_Graphics_Driver::color(uchar r, uchar g, uchar b) {