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
This commit is contained in:
Albrecht Schlosser 2020-09-01 12:33:11 +02:00
parent 95799bd364
commit b65d3a249d
8 changed files with 58 additions and 11 deletions

View File

@ -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).

30
FL/Fl.H
View File

@ -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 */
/** @{ */

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -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.

View File

@ -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);
}

View File

@ -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};

View File

@ -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);

View File

@ -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];