FLTK logo

[master] d95dd7a - New virtual member function Fl_Graphics_Driver::colored_rectf().

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] d95dd7a - New virtual member function Fl_Graphics_Driver::colored_rectf(). "ManoloFLTK" May 28, 2021  
 
commit d95dd7acc4af3a4bd521d151ba3576b91d8ace53
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Fri May 28 13:29:05 2021 +0200
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Fri May 28 13:30:59 2021 +0200

    New virtual member function Fl_Graphics_Driver::colored_rectf().

 FL/Fl_Graphics_Driver.H                                |  2 ++
 FL/fl_draw.H                                           |  3 +--
 src/Fl_Graphics_Driver.cxx                             |  5 +++++
 src/drivers/Android/Fl_Android_Graphics_Driver.cxx     | 13 -------------
 src/drivers/GDI/Fl_GDI_Graphics_Driver.H               |  3 +++
 src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx       | 10 +++++-----
 src/drivers/GDI/Fl_GDI_Graphics_Driver_line_style.cxx  |  1 +
 src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx |  4 ----
 src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H             |  1 +
 src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx     |  8 ++++----
 10 files changed, 22 insertions(+), 28 deletions(-)

diff --git FL/Fl_Graphics_Driver.H FL/Fl_Graphics_Driver.H
index 58ea006..67b7a31 100644
--- FL/Fl_Graphics_Driver.H
+++ FL/Fl_Graphics_Driver.H
@@ -257,6 +257,8 @@ public:
   virtual void rect(int x, int y, int w, int h);
   virtual void focus_rect(int x, int y, int w, int h);
   virtual void rectf(int x, int y, int w, int h);
+  // the default implementation is most likely enough
+  virtual void colored_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b);
   virtual void line(int x, int y, int x1, int y1);
   /** see fl_line(int, int, int, int, int, int) */
   virtual void line(int x, int y, int x1, int y1, int x2, int y2);
diff --git FL/fl_draw.H FL/fl_draw.H
index 30f5cfe..a84f310 100644
--- FL/fl_draw.H
+++ FL/fl_draw.H
@@ -264,8 +264,7 @@ inline void fl_rectf(int x, int y, int w, int h, Fl_Color c) {fl_color(c); fl_re
   solid-colored block using fl_draw_image() so that the correct color
   shade is produced.
   */
-/* note: doxygen comment here to avoid triplication in os-speciic files */
-FL_EXPORT void fl_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b);
+inline void fl_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b) { fl_graphics_driver->colored_rectf(x,y,w,h,r,g,b); }
 
 // line segments:
 /**
diff --git src/Fl_Graphics_Driver.cxx src/Fl_Graphics_Driver.cxx
index 3ac4d31..d558b73 100644
--- src/Fl_Graphics_Driver.cxx
+++ src/Fl_Graphics_Driver.cxx
@@ -461,6 +461,11 @@ void Fl_Graphics_Driver::rect(int x, int y, int w, int h) {}
 /** see fl_rectf() */
 void Fl_Graphics_Driver::rectf(int x, int y, int w, int h) {}
 
+void Fl_Graphics_Driver::colored_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b) {
+  color(r, g, b);
+  rectf(x, y, w, h);
+}
+
 /** see fl_line(int, int, int, int) */
 void Fl_Graphics_Driver::line(int x, int y, int x1, int y1) {}
 
diff --git src/drivers/Android/Fl_Android_Graphics_Driver.cxx src/drivers/Android/Fl_Android_Graphics_Driver.cxx
index 1aed581..75c4e08 100644
--- src/drivers/Android/Fl_Android_Graphics_Driver.cxx
+++ src/drivers/Android/Fl_Android_Graphics_Driver.cxx
@@ -1255,16 +1255,3 @@ void Fl_Android_Graphics_Driver::color(uchar r, uchar g, uchar b)
 {
   color( (((Fl_Color)r)<<24)|(((Fl_Color)g)<<16)|(((Fl_Color)b)<<8) );
 }
-
-/**
- Draw a rectangle that may be dithered if we are in colormap mode (which in
- the year 2018 is as likely has a user with a berstein colored tube TV).
- FIXME: This function should be virtual as well, or should not exist at all.
- */
-void fl_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b) {
-#if USE_COLORMAP
-  // ...
-#endif
-  fl_color(r,g,b);
-  fl_rectf(x,y,w,h);
-}
diff --git src/drivers/GDI/Fl_GDI_Graphics_Driver.H src/drivers/GDI/Fl_GDI_Graphics_Driver.H
index 9016e9f..76d9c5c 100644
--- src/drivers/GDI/Fl_GDI_Graphics_Driver.H
+++ src/drivers/GDI/Fl_GDI_Graphics_Driver.H
@@ -98,6 +98,9 @@ protected:
   virtual void point(int x, int y);
   void focus_rect(int x, int y, int w, int h);
   virtual void rectf_unscaled(int x, int y, int w, int h);
+#if USE_COLORMAP
+  virtual void colored_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b);
+#endif
   virtual void line_unscaled(int x, int y, int x1, int y1);
   virtual void line_unscaled(int x, int y, int x1, int y1, int x2, int y2);
   virtual void xyline_unscaled(int x, int y, int x1);
diff --git src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx
index 1032640..e104660 100644
--- src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx
+++ src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx
@@ -320,19 +320,19 @@ void Fl_GDI_Graphics_Driver::draw_image_mono_unscaled(Fl_Draw_Image_Cb cb, void*
   }
 }
 
-void fl_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b) {
 #if USE_COLORMAP
+void Fl_GDI_Graphics_Driver::colored_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b) {
   // use the error diffusion dithering code to produce a much nicer block:
   if (fl_palette) {
     uchar c[3];
     c[0] = r; c[1] = g; c[2] = b;
-    innards(c,x,y,w,h,0,0,0,0,0,(HDC)fl_graphics_driver->gc());
+    innards(c, floor(x), floor(y), floor(x + w) - floor(x), floor(y + h) - floor(y),
+            0,0,0,0,0, (HDC)gc());
     return;
   }
-#endif
-  fl_color(r,g,b);
-  fl_rectf(x,y,w,h);
+  Fl_Graphics_Driver::colored_rectf(x, y, w, h, r, g, b);
 }
+#endif
 
 // 'fl_create_bitmask()' - Create an N-bit bitmap for masking...
 Fl_Bitmask Fl_GDI_Graphics_Driver::create_bitmask(int w, int h, const uchar *data) {
diff --git src/drivers/GDI/Fl_GDI_Graphics_Driver_line_style.cxx src/drivers/GDI/Fl_GDI_Graphics_Driver_line_style.cxx
index 2cf6d82..91cfe2c 100644
--- src/drivers/GDI/Fl_GDI_Graphics_Driver_line_style.cxx
+++ src/drivers/GDI/Fl_GDI_Graphics_Driver_line_style.cxx
@@ -46,6 +46,7 @@ void Fl_GDI_Graphics_Driver::line_style_unscaled(int style, int width, char* das
     s1 |= style & 0xff; // allow them to pass any low 8 bits for style
   }
   if ((style || n) && !width) width = int(scale()); // fix cards that do nothing for 0?
+  if (!width) width = 1;
   if (!fl_current_xmap) color(FL_BLACK);
   LOGBRUSH penbrush = {BS_SOLID,fl_RGB(),0}; // can this be fl_brush()?
   HPEN newpen = ExtCreatePen(s1, width, &penbrush, n, n ? a : 0);
diff --git src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx
index dd73fc8..739e5b2 100644
--- src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx
+++ src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx
@@ -121,10 +121,6 @@ void Fl_Quartz_Graphics_Driver::draw_image_mono(Fl_Draw_Image_Cb cb, void* data,
   innards(0,x,y,w,h,d,0,1,cb,data,gc_,this);
 }
 
-void fl_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b) {
-  fl_color(r,g,b);
-  fl_rectf(x,y,w,h);
-}
 
 void Fl_Quartz_Graphics_Driver::draw_bitmap(Fl_Bitmap *bm, int XP, int YP, int WP, int HP, int cx, int cy) {
   int X, Y, W, H;
diff --git src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
index bae7640..4dbf3c3 100644
--- src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
+++ src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
@@ -143,6 +143,7 @@ protected:
   void fixloop();
   virtual void focus_rect(int x, int y, int w, int h);
   virtual void rectf_unscaled(int x, int y, int w, int h);
+  virtual void colored_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b);
   virtual void line_unscaled(int x, int y, int x1, int y1);
   virtual void xyline_unscaled(int x, int y, int x1);
   virtual void *change_pen_width(int lwidth);
diff --git src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
index 9b2fc69..3b431e7 100644
--- src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
+++ src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
@@ -602,14 +602,14 @@ void Fl_Xlib_Graphics_Driver::draw_image_mono_unscaled(Fl_Draw_Image_Cb cb, void
   innards(0,x+floor(offset_x_),y+floor(offset_y_),w,h,d,0,1,cb,data,0,gc_);
 }
 
-void fl_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b) {
+void Fl_Xlib_Graphics_Driver::colored_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b) {
   if (fl_visual->depth > 16) {
-    fl_color(r,g,b);
-    fl_rectf(x,y,w,h);
+    Fl_Graphics_Driver::colored_rectf(x, y, w, h, r, g, b);
   } else {
     uchar c[3];
     c[0] = r; c[1] = g; c[2] = b;
-    innards(c,x,y,w,h,0,0,0,0,0,0,(GC)fl_graphics_driver->gc());
+    innards(c, floor(x), floor(y), floor(x + w) - floor(x), floor(y + h) - floor(y),
+            0,0,0,0,0,0, (GC)gc());
   }
 }
 
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.