You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.6KB

  1. //
  2. // "$Id: fl_rounded_box.cxx 7903 2010-11-28 21:06:39Z matt $"
  3. //
  4. // Rounded box drawing routines for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2010 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. #include <FL/Fl.H>
  28. #include <FL/fl_draw.H>
  29. #define RN 5
  30. #define RS 15
  31. #define BW 3
  32. static double offset[RN] = { 0.0, 0.07612, 0.29289, 0.61732, 1.0};
  33. static void rbox(int fill, int x, int y, int w, int h, int asym = 0 ) {
  34. int i;
  35. int rsx ,rsy, rs;
  36. rsx = w*2/5; rsy = h*2/5;
  37. if (rsx > rsy) rs = rsy; else rs = rsx;
  38. if (rs > RS) rs = RS;
  39. rsx = rs; rsy = rs;
  40. if (fill) fl_begin_polygon(); else fl_begin_loop();
  41. for (i=0; i<RN; i++)
  42. fl_vertex(x + offset[RN-i-1]*rsx, y + offset[i] * rsy);
  43. if ( ! asym )
  44. for (i=0; i<RN; i++)
  45. fl_vertex(x + offset[i]*rsx, y + h-1 - offset[RN-i-1] * rsy);
  46. else
  47. fl_vertex( x, y + h - 1 );
  48. for (i=0; i<RN; i++)
  49. fl_vertex(x + w-1 - offset[RN-i-1]*rsx, y + h-1 - offset[i] * rsy);
  50. if ( ! asym )
  51. for (i=0; i<RN; i++)
  52. fl_vertex(x + w-1 - offset[i]*rsx, y + offset[RN-i-1] * rsy);
  53. else
  54. fl_vertex( x + w - 1, y );
  55. if (fill) fl_end_polygon(); else fl_end_loop();
  56. }
  57. static void fl_rflat_box(int x, int y, int w, int h, Fl_Color c) {
  58. fl_color(c); rbox(1, x, y, w, h); rbox(0, x, y, w, h);
  59. }
  60. static void fl_rounded_frame(int x, int y, int w, int h, Fl_Color c) {
  61. fl_color(c); rbox(0, x, y, w, h);
  62. }
  63. static void fl_rounded_box(int x, int y, int w, int h, Fl_Color c) {
  64. fl_color(c); rbox(1, x, y, w, h);
  65. fl_color(FL_BLACK); rbox(0, x, y, w, h);
  66. }
  67. static void fl_asym_box(int x, int y, int w, int h, Fl_Color c) {
  68. fl_color(c); rbox(1, x, y, w, h, 1);
  69. fl_color(FL_BLACK); rbox(0, x, y, w, h, 1 );
  70. }
  71. static void fl_asym_flat_box(int x, int y, int w, int h, Fl_Color c) {
  72. fl_color(c); rbox(1, x, y, w, h, 1);
  73. }
  74. static void fl_rshadow_box(int x, int y, int w, int h, Fl_Color c) {
  75. // draw shadow:
  76. fl_color(FL_DARK3);
  77. rbox(1, x+BW, y+BW, w, h);
  78. rbox(0, x+BW, y+BW, w, h);
  79. // draw the box:
  80. fl_rounded_box(x, y, w, h, c);
  81. }
  82. extern void fl_internal_boxtype(Fl_Boxtype, Fl_Box_Draw_F*);
  83. Fl_Boxtype fl_define_FL_ROUNDED_BOX() {
  84. fl_internal_boxtype(_FL_ROUNDED_FRAME, fl_rounded_frame);
  85. fl_internal_boxtype(_FL_ROUNDED_BOX, fl_rounded_box);
  86. return _FL_ROUNDED_BOX;
  87. }
  88. Fl_Boxtype fl_define_FL_RFLAT_BOX() {
  89. fl_internal_boxtype(_FL_RFLAT_BOX, fl_rflat_box);
  90. return _FL_RFLAT_BOX;
  91. }
  92. Fl_Boxtype fl_define_FL_RSHADOW_BOX() {
  93. fl_internal_boxtype(_FL_RSHADOW_BOX, fl_rshadow_box);
  94. return _FL_RSHADOW_BOX;
  95. }
  96. Fl_Boxtype fl_define_FL_ASYM_BOX() {
  97. fl_internal_boxtype(_FL_ASYM_BOX, fl_asym_box);
  98. fl_internal_boxtype(_FL_ASYM_FLAT_BOX, fl_asym_flat_box);
  99. return _FL_ASYM_BOX;
  100. }
  101. //
  102. // End of "$Id: fl_rounded_box.cxx 7903 2010-11-28 21:06:39Z matt $".
  103. //