mirror of
https://github.com/fltk/fltk.git
synced 2026-05-31 22:04:26 +08:00
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:
@@ -18,6 +18,9 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2020
|
|||||||
New Features and Extensions
|
New Features and Extensions
|
||||||
|
|
||||||
- (add new items here)
|
- (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
|
- New classes Fl_SVG_File_Surface and Fl_EPS_File_Surface to save any FLTK
|
||||||
graphics to SVG or EPS files, respectively.
|
graphics to SVG or EPS files, respectively.
|
||||||
- New fl_putenv() is a cross-platform putenv() wrapper (see docs).
|
- New fl_putenv() is a cross-platform putenv() wrapper (see docs).
|
||||||
|
|||||||
@@ -133,6 +133,8 @@ private:
|
|||||||
|
|
||||||
static int use_high_res_GL_;
|
static int use_high_res_GL_;
|
||||||
static int draw_GL_text_with_textures_;
|
static int draw_GL_text_with_textures_;
|
||||||
|
static int box_shadow_width_;
|
||||||
|
static int box_border_radius_max_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -141,6 +143,34 @@ public:
|
|||||||
static void reset_marked_text(); // resets marked text
|
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
|
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
|
public: // run time information about compile time configuration
|
||||||
/** \defgroup cfg_gfx runtime graphics driver 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 |
+4
-1
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// Box drawing code for the Fast Light Tool Kit (FLTK).
|
// 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
|
// 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
|
// 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};
|
51, 51, 52, 52};
|
||||||
static int draw_it_active = 1;
|
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.
|
Determines if the currently drawn box is active or inactive.
|
||||||
|
|
||||||
|
|||||||
+7
-3
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// Oval box drawing code for the Fast Light Tool Kit (FLTK).
|
// 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
|
// 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
|
// the file "COPYING" which should have been included with this file. If this
|
||||||
@@ -14,13 +14,17 @@
|
|||||||
// https://www.fltk.org/bugs.php
|
// https://www.fltk.org/bugs.php
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
// Less-used box types are in separate files so they are not linked
|
// Less-used box types are in separate files so they are not linked
|
||||||
// in if not used.
|
// in if not used.
|
||||||
|
|
||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
#include <FL/fl_draw.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) {
|
static void fl_oval_flat_box(int x, int y, int w, int h, Fl_Color c) {
|
||||||
Fl::set_box_color(c);
|
Fl::set_box_color(c);
|
||||||
fl_pie(x, y, w, h, 0, 360);
|
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) {
|
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);
|
fl_oval_box(x,y,w,h,c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// Rounded box drawing routines for the Fast Light Tool Kit (FLTK).
|
// 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
|
// 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
|
// the file "COPYING" which should have been included with this file. If this
|
||||||
@@ -17,15 +17,15 @@
|
|||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
#include <FL/fl_draw.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)
|
// RN = number of segments per corner (must match offset array size)
|
||||||
// RS = max. corner radius
|
// RS = max. corner radius
|
||||||
// BW = box shadow width
|
// BW = box shadow width
|
||||||
|
|
||||||
#define RN 5
|
#define RN 5
|
||||||
#define RS 15
|
#define RS (Fl::box_border_radius_max())
|
||||||
#define BW 3
|
#define BW (Fl::box_shadow_width())
|
||||||
|
|
||||||
static double offset[RN] = { 0.0, 0.07612, 0.29289, 0.61732, 1.0};
|
static double offset[RN] = { 0.0, 0.07612, 0.29289, 0.61732, 1.0};
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,10 @@
|
|||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
#include <FL/fl_draw.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) {
|
static void fl_shadow_frame(int x, int y, int w, int h, Fl_Color c) {
|
||||||
fl_color(FL_DARK3);
|
fl_color(FL_DARK3);
|
||||||
|
|||||||
+5
-1
@@ -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
|
#else // this code uses the nice bright blue background to show box vs. frame types
|
||||||
Fl::args(argc, argv);
|
Fl::args(argc, argv);
|
||||||
Fl::get_system_colors();
|
Fl::get_system_colors();
|
||||||
window->color(12);// light blue
|
window->color(fl_rgb_color(51, 173, 255)); // light blue (#33adff)
|
||||||
#endif
|
#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
|
// set window title to show active scheme
|
||||||
Fl::scheme(Fl::scheme()); // init scheme
|
Fl::scheme(Fl::scheme()); // init scheme
|
||||||
char title[100];
|
char title[100];
|
||||||
|
|||||||
Reference in New Issue
Block a user