Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functions for drawing rounded rectangles to the drawing api #262

Closed
wyhinton opened this issue Jul 20, 2021 · 5 comments
Closed

Add functions for drawing rounded rectangles to the drawing api #262

wyhinton opened this issue Jul 20, 2021 · 5 comments
Assignees

Comments

@wyhinton
Copy link

wyhinton commented Jul 20, 2021

Rounded rectangles have become a critical part of modern GUI design. Having a method for drawing them would be very handing. While it is nice to be able to set the global radius size for rounded frames, we might also want to have rounded frames with different radiuses. So, I think we could save people time by providing a method for drawing rounded rectangles a custom radius.

Such a method already exists in fl_rounded_box:

static void rbox(int fill, int x, int y, int w, int h) {
  int i;
  int rs, rsy;
  rs = w*2/5; rsy = h*2/5;
  if (rs > rsy) rs = rsy; // use smaller radius
  if (rs > RS) rs = RS;
  if (rs == 5) rs = 4;  // use only even sizes for small corners (STR #2943)
  if (rs == 7) rs = 8;  // note: 8 is better than 6 (really)

  if (fill) fl_begin_polygon(); else fl_begin_loop();
  for (i=0; i<RN; i++)
    fl_vertex_r(x + offset[RN-i-1]*rs, y + offset[i] * rs);
  for (i=0; i<RN; i++)
    fl_vertex_r(x + offset[i]*rs, y + h-1 - offset[RN-i-1] * rs);
  for (i=0; i<RN; i++)
    fl_vertex_r(x + w-1 - offset[RN-i-1]*rs, y + h-1 - offset[i] * rs);
  for (i=0; i<RN; i++)
    fl_vertex_r(x + w-1 - offset[i]*rs, y + offset[RN-i-1] * rs);
  if (fill) fl_end_polygon(); else fl_end_loop();
}
@MatthiasWM
Copy link
Contributor

With the current API, we do not have any additional parameters for box types besides the color. So storing the radius is only possible globally. It is however possible to add custom box types that could have different radii. See Fl::set_boxtype().

If that would solve the issue at hand, I'll take a look at the API and check if there is a way to make this option more reachable, maybe add an example.

@MatthiasWM
Copy link
Contributor

See #553 for an implementation of fl_rrect(int x, int y, int w, int h, int radius) and fl_rrectf(int x, int y, int w, int h, int radius). If I don't get any negative comments, this will be in 1.4.0 in a day or two.

@Albrecht-S
Copy link
Member

Please refer to my request for better names in #553 (comment).

@MatthiasWM
Copy link
Contributor

Will fix that tomorrow

@MatthiasWM
Copy link
Contributor

Renamed to fl_rounded_rect and fl_rounded_rectf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants