FLTK logo

[master] b65d3a2 - Customize corner radius for rounded box/frame (#130)

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] b65d3a2 - Customize corner radius for rounded box/frame (#130) "Albrecht Schlosser" Sep 01, 2020  
 
commit b65d3a249d4db1ada6d0bc96031e55459e0d6381
Author:     Albrecht Schlosser <albrechts.fltk@online.de>
AuthorDate: Tue Sep 1 12:33:11 2020 +0200
Commit:     Albrecht Schlosser <albrechts.fltk@online.de>
CommitDate: Tue Sep 1 12:35:48 2020 +0200

    Customize corner radius for rounded box/frame (#130)
    
    Make maximum box corner radius and shadow width configurable.
    See Fl::box_border_radius_max() and Fl::box_shadow_width().
    
    Documentation: update image of box types.
    
    Fixes #130

 CHANGES.txt                    |   3 +++
 FL/Fl.H                        |  30 ++++++++++++++++++++++++++++++
 documentation/src/boxtypes.png | Bin 6758 -> 17302 bytes
 src/fl_boxtype.cxx             |   5 ++++-
 src/fl_oval_box.cxx            |  10 +++++++---
 src/fl_rounded_box.cxx         |  10 +++++-----
 src/fl_shadow_box.cxx          |   5 ++++-
 test/boxtype.cxx               |   6 +++++-
 8 files changed, 58 insertions(+), 11 deletions(-)

diff --git CHANGES.txt CHANGES.txt
index 97f0a28..f25859d 100644
--- CHANGES.txt
+++ CHANGES.txt
@@ -18,6 +18,9 @@ Changes in FLTK 1.4.0                            Released: ??? ?? 2020
   New Features and Extensions
 
   - (add new items here)
+  - The border radius of "rounded" box types can be limited and
+    the shadow width of "shadow" box types can be configured (issue #130).
+    See Fl::box_border_radius_max() and Fl::box_shadow_width().
   - New classes Fl_SVG_File_Surface and Fl_EPS_File_Surface to save any FLTK
     graphics to SVG or EPS files, respectively.
   - New fl_putenv() is a cross-platform putenv() wrapper (see docs).
diff --git FL/Fl.H FL/Fl.H
index 4221d95..fae3940 100644
--- FL/Fl.H
+++ FL/Fl.H
@@ -133,6 +133,8 @@ private:
 
   static int use_high_res_GL_;
   static int draw_GL_text_with_textures_;
+  static int box_shadow_width_;
+  static int box_border_radius_max_;
 
 public:
 
@@ -141,6 +143,34 @@ public:
   static void reset_marked_text(); // resets marked text
   static void insertion_point_location(int x, int y, int height); // sets window coordinates & height of insertion point
 
+  /** Get the box shadow width of all "shadow" boxtypes in pixels.
+    \since 1.4.0
+  */
+  static int box_shadow_width() { return box_shadow_width_; }
+  /** Set the box shadow width of all "shadow" boxtypes in pixels.
+    Must be at least 1, default = 3. There is no upper limit.
+    \since 1.4.0
+  */
+  static void box_shadow_width(int W) { box_shadow_width_ = W < 1 ? 1 : W; }
+
+  /** Get the maximum border radius of all "rounded" boxtypes in pixels.
+      \since 1.4.0
+  */
+  static int box_border_radius_max() { return box_border_radius_max_; }
+  /** Set the maximum border radius of all "rounded" boxtypes in pixels.
+    Must be at least 5, default = 15.
+
+    \note This does \b not apply to the "round" boxtypes which have really round sides
+      (i.e. composed of half circles) as opposed to "rounded" boxtypes that have only
+      rounded corners with a straight border between corners.
+
+    The box border radius of "rounded" boxtypes is typically calculated as about 2/5 of
+    the box height or width, whichever is smaller. The upper limit can be set by this
+    method for all "rounded" boxtypes.
+    \since 1.4.0
+  */
+  static void box_border_radius_max(int R) { box_border_radius_max_ = R < 5 ? 5 : R; }
+
 public: // run time information about compile time configuration
   /** \defgroup cfg_gfx runtime graphics driver configuration */
   /** @{ */
diff --git documentation/src/boxtypes.png documentation/src/boxtypes.png
index a64ccaa..8708f14 100644
Binary files documentation/src/boxtypes.png and documentation/src/boxtypes.png differ
diff --git src/fl_boxtype.cxx src/fl_boxtype.cxx
index 2d30ff4..e5e19d6 100644
--- src/fl_boxtype.cxx
+++ src/fl_boxtype.cxx
@@ -1,7 +1,7 @@
 //
 // Box drawing code for the Fast Light Tool Kit (FLTK).
 //
-// Copyright 1998-2015 by Bill Spitzak and others.
+// Copyright 1998-2020 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -46,6 +46,9 @@ static const uchar inactive_ramp[24] = {
   51, 51, 52, 52};
 static int draw_it_active = 1;
 
+int Fl::box_border_radius_max_ = 15;
+int Fl::box_shadow_width_ = 3;
+
 /**
   Determines if the currently drawn box is active or inactive.
 
diff --git src/fl_oval_box.cxx src/fl_oval_box.cxx
index c094d7a..9a0e196 100644
--- src/fl_oval_box.cxx
+++ src/fl_oval_box.cxx
@@ -1,7 +1,7 @@
 //
 // Oval box drawing code for the Fast Light Tool Kit (FLTK).
 //
-// Copyright 1998-2011 by Bill Spitzak and others.
+// Copyright 1998-2020 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -14,13 +14,17 @@
 //     https://www.fltk.org/bugs.php
 //
 
-
 // Less-used box types are in separate files so they are not linked
 // in if not used.
 
 #include <FL/Fl.H>
 #include <FL/fl_draw.H>
 
+// Global parameters for box drawing algorithm:
+//
+//  BW = box shadow width
+#define BW (Fl::box_shadow_width())
+
 static void fl_oval_flat_box(int x, int y, int w, int h, Fl_Color c) {
   Fl::set_box_color(c);
   fl_pie(x, y, w, h, 0, 360);
@@ -37,7 +41,7 @@ static void fl_oval_box(int x, int y, int w, int h, Fl_Color c) {
 }
 
 static void fl_oval_shadow_box(int x, int y, int w, int h, Fl_Color c) {
-  fl_oval_flat_box(x+3,y+3,w,h,FL_DARK3);
+  fl_oval_flat_box(x+BW,y+BW,w,h,FL_DARK3);
   fl_oval_box(x,y,w,h,c);
 }
 
diff --git src/fl_rounded_box.cxx src/fl_rounded_box.cxx
index 4c1eb6a..df41b4f 100644
--- src/fl_rounded_box.cxx
+++ src/fl_rounded_box.cxx
@@ -1,7 +1,7 @@
 //
 // Rounded box drawing routines for the Fast Light Tool Kit (FLTK).
 //
-// Copyright 1998-2016 by Bill Spitzak and others.
+// Copyright 1998-2020 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -17,15 +17,15 @@
 #include <FL/Fl.H>
 #include <FL/fl_draw.H>
 
-// Constants for rounded corner drawing algorithm:
+// Global parameters for rounded corner drawing algorithm:
 //
 //  RN = number of segments per corner (must match offset array size)
 //  RS = max. corner radius
 //  BW = box shadow width
 
-#define RN      5
-#define RS      15
-#define BW      3
+#define RN 5
+#define RS (Fl::box_border_radius_max())
+#define BW (Fl::box_shadow_width())
 
 static double offset[RN] = { 0.0, 0.07612, 0.29289, 0.61732, 1.0};
 
diff --git src/fl_shadow_box.cxx src/fl_shadow_box.cxx
index 1084da3..d89d09b 100644
--- src/fl_shadow_box.cxx
+++ src/fl_shadow_box.cxx
@@ -17,7 +17,10 @@
 #include <FL/Fl.H>
 #include <FL/fl_draw.H>
 
-#define BW 3
+// Global parameters for box drawing algorithm:
+//
+//  BW = box shadow width
+#define BW (Fl::box_shadow_width())
 
 static void fl_shadow_frame(int x, int y, int w, int h, Fl_Color c) {
   fl_color(FL_DARK3);
diff --git test/boxtype.cxx test/boxtype.cxx
index 8bcd1b0..9f67f07 100644
--- test/boxtype.cxx
+++ test/boxtype.cxx
@@ -103,9 +103,13 @@ int main(int argc, char ** argv) {
 #else // this code uses the nice bright blue background to show box vs. frame types
   Fl::args(argc, argv);
   Fl::get_system_colors();
-  window->color(12);// light blue
+  window->color(fl_rgb_color(51, 173, 255)); // light blue (#33adff)
 #endif
 
+  // TEST: set box shadow width and max. border radius (should be commented out)
+  // Fl::box_border_radius_max(5); // default: 15 (see documentation)
+  // Fl::box_shadow_width(6);      // default:  3 (see documentation)
+
   // set window title to show active scheme
   Fl::scheme(Fl::scheme()); // init scheme
   char title[100];
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'.