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.

305 lines
9.3KB

  1. //
  2. // "$Id: fl_gtk.cxx 7903 2010-11-28 21:06:39Z matt $"
  3. //
  4. // "GTK" drawing routines for the Fast Light Tool Kit (FLTK).
  5. //
  6. // These box types provide a GTK+ look, based on Red Hat's Bluecurve
  7. // theme...
  8. //
  9. // Copyright 2006-2010 by Michael Sweet.
  10. //
  11. // This library is free software; you can redistribute it and/or
  12. // modify it under the terms of the GNU Library General Public
  13. // License as published by the Free Software Foundation; either
  14. // version 2 of the License, or (at your option) any later version.
  15. //
  16. // This library is distributed in the hope that it will be useful,
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. // Library General Public License for more details.
  20. //
  21. // You should have received a copy of the GNU Library General Public
  22. // License along with this library; if not, write to the Free Software
  23. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  24. // USA.
  25. //
  26. // Please report all bugs and problems on the following page:
  27. //
  28. // http://www.fltk.org/str.php
  29. //
  30. // Box drawing code for an obscure box type.
  31. // These box types are in separate files so they are not linked
  32. // in if not used.
  33. #include <FL/Fl.H>
  34. #include <FL/fl_draw.H>
  35. extern void fl_internal_boxtype(Fl_Boxtype, Fl_Box_Draw_F*);
  36. static void gtk_color(Fl_Color c) {
  37. if (Fl::draw_box_active()) fl_color(c);
  38. else fl_color(fl_inactive(c));
  39. }
  40. static void gtk_up_frame(int x, int y, int w, int h, Fl_Color c) {
  41. gtk_color(fl_color_average(FL_WHITE, c, 0.5));
  42. fl_xyline(x + 2, y + 1, x + w - 3);
  43. fl_yxline(x + 1, y + 2, y + h - 3);
  44. gtk_color(fl_color_average(FL_BLACK, c, 0.5));
  45. fl_begin_loop();
  46. fl_vertex(x, y + 2);
  47. fl_vertex(x + 2, y);
  48. fl_vertex(x + w - 3, y);
  49. fl_vertex(x + w - 1, y + 2);
  50. fl_vertex(x + w - 1, y + h - 3);
  51. fl_vertex(x + w - 3, y + h - 1);
  52. fl_vertex(x + 2, y + h - 1);
  53. fl_vertex(x, y + h - 3);
  54. fl_end_loop();
  55. }
  56. static void gtk_up_box(int x, int y, int w, int h, Fl_Color c) {
  57. gtk_up_frame(x, y, w, h, c);
  58. gtk_color(fl_color_average(FL_WHITE, c, 0.4f));
  59. fl_xyline(x + 2, y + 2, x + w - 3);
  60. gtk_color(fl_color_average(FL_WHITE, c, 0.2f));
  61. fl_xyline(x + 2, y + 3, x + w - 3);
  62. gtk_color(fl_color_average(FL_WHITE, c, 0.1f));
  63. fl_xyline(x + 2, y + 4, x + w - 3);
  64. gtk_color(c);
  65. fl_rectf(x + 2, y + 5, w - 4, h - 7);
  66. gtk_color(fl_color_average(FL_BLACK, c, 0.025f));
  67. fl_xyline(x + 2, y + h - 4, x + w - 3);
  68. gtk_color(fl_color_average(FL_BLACK, c, 0.05f));
  69. fl_xyline(x + 2, y + h - 3, x + w - 3);
  70. gtk_color(fl_color_average(FL_BLACK, c, 0.1f));
  71. fl_xyline(x + 2, y + h - 2, x + w - 3);
  72. fl_yxline(x + w - 2, y + 2, y + h - 3);
  73. }
  74. static void gtk_down_frame(int x, int y, int w, int h, Fl_Color c) {
  75. gtk_color(fl_color_average(FL_BLACK, c, 0.5));
  76. fl_begin_loop();
  77. fl_vertex(x, y + 2);
  78. fl_vertex(x + 2, y);
  79. fl_vertex(x + w - 3, y);
  80. fl_vertex(x + w - 1, y + 2);
  81. fl_vertex(x + w - 1, y + h - 3);
  82. fl_vertex(x + w - 3, y + h - 1);
  83. fl_vertex(x + 2, y + h - 1);
  84. fl_vertex(x, y + h - 3);
  85. fl_end_loop();
  86. gtk_color(fl_color_average(FL_BLACK, c, 0.1f));
  87. fl_xyline(x + 2, y + 1, x + w - 3);
  88. fl_yxline(x + 1, y + 2, y + h - 3);
  89. gtk_color(fl_color_average(FL_BLACK, c, 0.05f));
  90. fl_yxline(x + 2, y + h - 2, y + 2, x + w - 2);
  91. }
  92. static void gtk_down_box(int x, int y, int w, int h, Fl_Color c) {
  93. gtk_down_frame(x, y, w, h, c);
  94. gtk_color(c);
  95. fl_rectf(x + 3, y + 3, w - 5, h - 4);
  96. fl_yxline(x + w - 2, y + 3, y + h - 3);
  97. }
  98. static void gtk_thin_up_frame(int x, int y, int w, int h, Fl_Color c) {
  99. gtk_color(fl_color_average(FL_WHITE, c, 0.6f));
  100. fl_xyline(x + 1, y, x + w - 2);
  101. fl_yxline(x, y + 1, y + h - 2);
  102. gtk_color(fl_color_average(FL_BLACK, c, 0.4f));
  103. fl_xyline(x + 1, y + h - 1, x + w - 2);
  104. fl_yxline(x + w - 1, y + 1, y + h - 2);
  105. }
  106. static void gtk_thin_up_box(int x, int y, int w, int h, Fl_Color c) {
  107. gtk_thin_up_frame(x, y, w, h, c);
  108. gtk_color(fl_color_average(FL_WHITE, c, 0.4f));
  109. fl_xyline(x + 1, y + 1, x + w - 2);
  110. gtk_color(fl_color_average(FL_WHITE, c, 0.2f));
  111. fl_xyline(x + 1, y + 2, x + w - 2);
  112. gtk_color(fl_color_average(FL_WHITE, c, 0.1f));
  113. fl_xyline(x + 1, y + 3, x + w - 2);
  114. gtk_color(c);
  115. fl_rectf(x + 1, y + 4, w - 2, h - 8);
  116. gtk_color(fl_color_average(FL_BLACK, c, 0.025f));
  117. fl_xyline(x + 1, y + h - 4, x + w - 2);
  118. gtk_color(fl_color_average(FL_BLACK, c, 0.05f));
  119. fl_xyline(x + 1, y + h - 3, x + w - 2);
  120. gtk_color(fl_color_average(FL_BLACK, c, 0.1f));
  121. fl_xyline(x + 1, y + h - 2, x + w - 2);
  122. }
  123. static void gtk_thin_down_frame(int x, int y, int w, int h, Fl_Color c) {
  124. gtk_color(fl_color_average(FL_BLACK, c, 0.4f));
  125. fl_xyline(x + 1, y, x + w - 2);
  126. fl_yxline(x, y + 1, y + h - 2);
  127. gtk_color(fl_color_average(FL_WHITE, c, 0.6f));
  128. fl_xyline(x + 1, y + h - 1, x + w - 2);
  129. fl_yxline(x + w - 1, y + 1, y + h - 2);
  130. }
  131. static void gtk_thin_down_box(int x, int y, int w, int h, Fl_Color c) {
  132. gtk_thin_down_frame(x, y, w, h, c);
  133. gtk_color(c);
  134. fl_rectf(x + 1, y + 1, w - 2, h - 2);
  135. }
  136. //------------------------
  137. // new GTK+ style for round buttons
  138. #if 1
  139. static void fl_arc_i(int x,int y,int w,int h,double a1,double a2) {
  140. fl_arc(x,y,w,h,a1,a2);
  141. }
  142. enum {UPPER_LEFT, LOWER_RIGHT, CLOSED, FILL};
  143. static void draw(int which, int x,int y,int w,int h, int inset)
  144. {
  145. if (inset*2 >= w) inset = (w-1)/2;
  146. if (inset*2 >= h) inset = (h-1)/2;
  147. x += inset;
  148. y += inset;
  149. w -= 2*inset;
  150. h -= 2*inset;
  151. int d = w <= h ? w : h;
  152. if (d <= 1) return;
  153. void (*f)(int,int,int,int,double,double);
  154. f = (which==FILL) ? fl_pie : fl_arc_i;
  155. if (which >= CLOSED) {
  156. f(x+w-d, y, d, d, w<=h ? 0 : -90, w<=h ? 180 : 90);
  157. f(x, y+h-d, d, d, w<=h ? 180 : 90, w<=h ? 360 : 270);
  158. } else if (which == UPPER_LEFT) {
  159. f(x+w-d, y, d, d, 45, w<=h ? 180 : 90);
  160. f(x, y+h-d, d, d, w<=h ? 180 : 90, 225);
  161. } else { // LOWER_RIGHT
  162. f(x, y+h-d, d, d, 225, w<=h ? 360 : 270);
  163. f(x+w-d, y, d, d, w<=h ? 360 : 270, 360+45);
  164. }
  165. if (which == FILL) {
  166. if (w < h)
  167. fl_rectf(x, y+d/2, w, h-(d&-2));
  168. else if (w > h)
  169. fl_rectf(x+d/2, y, w-(d&-2), h);
  170. } else {
  171. if (w < h) {
  172. if (which != UPPER_LEFT) fl_yxline(x+w-1, y+d/2-1, y+h-d/2+1);
  173. if (which != LOWER_RIGHT) fl_yxline(x, y+d/2-1, y+h-d/2+1);
  174. } else if (w > h) {
  175. if (which != UPPER_LEFT) fl_xyline(x+d/2-1, y+h-1, x+w-d/2+1);
  176. if (which != LOWER_RIGHT) fl_xyline(x+d/2-1, y, x+w-d/2+1);
  177. }
  178. }
  179. }
  180. void gtk_round_up_box(int x, int y, int w, int h, Fl_Color c) {
  181. fl_color(c);
  182. draw(FILL, x, y, w, h, 2);
  183. gtk_color(fl_color_average(FL_BLACK, c, 0.025f));
  184. draw(LOWER_RIGHT, x+1, y, w-2, h, 2);
  185. draw(LOWER_RIGHT, x, y, w, h, 3);
  186. gtk_color(fl_color_average(FL_BLACK, c, 0.05f));
  187. draw(LOWER_RIGHT, x+1, y, w-2, h, 1);
  188. draw(LOWER_RIGHT, x, y, w, h, 2);
  189. gtk_color(fl_color_average(FL_BLACK, c, 0.1f));
  190. draw(LOWER_RIGHT, x+1, y, w-2, h, 0);
  191. draw(LOWER_RIGHT, x, y, w, h, 1);
  192. gtk_color(fl_color_average(FL_WHITE, c, 0.1f));
  193. draw(UPPER_LEFT, x, y, w, h, 4);
  194. draw(UPPER_LEFT, x+1, y, w-2, h, 3);
  195. gtk_color(fl_color_average(FL_WHITE, c, 0.2f));
  196. draw(UPPER_LEFT, x, y, w, h, 3);
  197. draw(UPPER_LEFT, x+1, y, w-2, h, 2);
  198. gtk_color(fl_color_average(FL_WHITE, c, 0.4f));
  199. draw(UPPER_LEFT, x, y, w, h, 2);
  200. draw(UPPER_LEFT, x+1, y, w-2, h, 1);
  201. gtk_color(fl_color_average(FL_WHITE, c, 0.5f));
  202. draw(UPPER_LEFT, x, y, w, h, 1);
  203. draw(UPPER_LEFT, x+1, y, w-2, h, 0);
  204. gtk_color(fl_color_average(FL_BLACK, c, 0.5f));
  205. draw(CLOSED, x, y, w, h, 0);
  206. }
  207. void gtk_round_down_box(int x, int y, int w, int h, Fl_Color c) {
  208. fl_color(c);
  209. draw(FILL, x, y, w, h, 2);
  210. gtk_color(fl_color_average(FL_BLACK, c, 0.05f));
  211. draw(UPPER_LEFT, x, y, w, h, 2);
  212. draw(UPPER_LEFT, x+1, y, w-2, h, 1);
  213. gtk_color(fl_color_average(FL_BLACK, c, 0.1f));
  214. draw(UPPER_LEFT, x, y, w, h, 1);
  215. draw(UPPER_LEFT, x+1, y, w-2, h, 0);
  216. gtk_color(fl_color_average(FL_BLACK, c, 0.5f));
  217. draw(CLOSED, x, y, w, h, 0);
  218. }
  219. #else
  220. static void gtk_round_up_box(int x, int y, int w, int h, Fl_Color c) {
  221. gtk_color(c);
  222. fl_pie(x, y, w, h, 0.0, 360.0);
  223. gtk_color(fl_color_average(FL_WHITE, c, 0.5f));
  224. fl_arc(x, y, w, h, 45.0, 180.0);
  225. gtk_color(fl_color_average(FL_WHITE, c, 0.25f));
  226. fl_arc(x, y, w, h, 180.0, 405.0);
  227. gtk_color(fl_color_average(FL_BLACK, c, 0.5f));
  228. fl_arc(x, y, w, h, 225.0, 360.0);
  229. }
  230. static void gtk_round_down_box(int x, int y, int w, int h, Fl_Color c) {
  231. gtk_color(c);
  232. fl_pie(x, y, w, h, 0.0, 360.0);
  233. gtk_color(fl_color_average(FL_BLACK, c, 0.2));
  234. fl_arc(x + 1, y, w, h, 90.0, 210.0);
  235. gtk_color(fl_color_average(FL_BLACK, c, 0.6));
  236. fl_arc(x, y, w, h, 0.0, 360.0);
  237. }
  238. #endif
  239. Fl_Boxtype fl_define_FL_GTK_UP_BOX() {
  240. fl_internal_boxtype(_FL_GTK_UP_BOX, gtk_up_box);
  241. fl_internal_boxtype(_FL_GTK_DOWN_BOX, gtk_down_box);
  242. fl_internal_boxtype(_FL_GTK_UP_FRAME, gtk_up_frame);
  243. fl_internal_boxtype(_FL_GTK_DOWN_FRAME, gtk_down_frame);
  244. fl_internal_boxtype(_FL_GTK_THIN_UP_BOX, gtk_thin_up_box);
  245. fl_internal_boxtype(_FL_GTK_THIN_DOWN_BOX, gtk_thin_down_box);
  246. fl_internal_boxtype(_FL_GTK_THIN_UP_FRAME, gtk_thin_up_frame);
  247. fl_internal_boxtype(_FL_GTK_THIN_DOWN_FRAME, gtk_thin_down_frame);
  248. fl_internal_boxtype(_FL_GTK_ROUND_UP_BOX, gtk_round_up_box);
  249. fl_internal_boxtype(_FL_GTK_ROUND_DOWN_BOX, gtk_round_down_box);
  250. return _FL_GTK_UP_BOX;
  251. }
  252. //
  253. // End of "$Id: fl_gtk.cxx 7903 2010-11-28 21:06:39Z matt $".
  254. //