Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
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.

434 lines
14KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2008 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. #include "Boxtypes.H"
  19. #include <FL/fl_draw.H>
  20. #include <string.h>
  21. /** This simple box is suitable for use with knob-type widgets. It
  22. * comprises a border with shadow, and a cap with glare-lines akin
  23. * to those seen on burnished aluminum knobs. */
  24. static void
  25. burnished_oval_box ( int x, int y, int w, int h, Fl_Color c )
  26. {
  27. /* draw background */
  28. fl_color( fl_darker( c ) );
  29. fl_pie( x, y, w, h, 0, 360 );
  30. fl_color( fl_darker( fl_darker( c ) ) );
  31. fl_pie( x, y, w, h, 180 + 215, 180 + 45 );
  32. /* shrink */
  33. x += 4;
  34. y += 4;
  35. w -= 7;
  36. h -= 7;
  37. /* draw cap */
  38. fl_color( c );
  39. fl_pie( x, y, w, h, 0, 360 );
  40. /* draw glare */
  41. const int a1 = 10;
  42. const int a2 = 90;
  43. fl_color( fl_lighter( c ) );
  44. fl_pie( x, y, w, h, a1, a2 );
  45. fl_pie( x, y, w, h, 180 + a1, 180 + a2 );
  46. fl_color( fl_lighter( fl_lighter( c ) ) );
  47. const int d = (a2 - a1) / 2;
  48. fl_pie( x, y, w, h, a1 + (d / 2), a2 - (d / 2) );
  49. fl_pie( x, y, w, h, 180 + a1 + (d / 2), 180 + a2 - (d / 2) );
  50. }
  51. /* Crystal boxes, base (obviously) on the FLTK1 'plastic' boxes, but
  52. * without the rude color blending and with a slightly enhanced
  53. * appearance. */
  54. extern uchar *fl_gray_ramp();
  55. inline Fl_Color
  56. shade_color ( uchar gc, Fl_Color bc )
  57. {
  58. return fl_color_average( ( Fl_Color ) gc, bc, 0.25f );
  59. }
  60. static void
  61. frame_rect ( int x, int y, int w, int h, const char *c, Fl_Color bc )
  62. {
  63. uchar *g = fl_gray_ramp();
  64. int b = strlen( c ) / 4 + 1;
  65. for ( x += b, y += b, w -= 2 * b, h -= 2 * b; b > 1; b-- )
  66. {
  67. // Draw lines around the perimeter of the button, 4 colors per
  68. // circuit.
  69. fl_color( shade_color( g[*c++], bc ) );
  70. fl_line( x, y + h + b, x + w - 1, y + h + b, x + w + b - 1, y + h );
  71. fl_color( shade_color( g[*c++], bc ) );
  72. fl_line( x + w + b - 1, y + h, x + w + b - 1, y, x + w - 1, y - b );
  73. fl_color( shade_color( g[*c++], bc ) );
  74. fl_line( x + w - 1, y - b, x, y - b, x - b, y );
  75. fl_color( shade_color( g[*c++], bc ) );
  76. fl_line( x - b, y, x - b, y + h, x, y + h + b );
  77. }
  78. }
  79. static void
  80. frame_round ( int x, int y, int w, int h, const char *c, Fl_Color bc )
  81. {
  82. uchar *g = fl_gray_ramp();
  83. int b = strlen( c ) / 4 + 1;
  84. if ( ! Fl::draw_box_active() )
  85. bc = fl_inactive( bc );
  86. if ( w == h )
  87. {
  88. for ( ; b > 1; b--, x++, y++, w -= 2, h -= 2 )
  89. {
  90. fl_color( shade_color( g[*c++], bc ) );
  91. fl_arc( x, y, w, h, 45.0, 135.0 );
  92. fl_color( shade_color( g[*c++], bc ) );
  93. fl_arc( x, y, w, h, 315.0, 405.0 );
  94. fl_color( shade_color( g[*c++], bc ) );
  95. fl_arc( x, y, w, h, 225.0, 315.0 );
  96. fl_color( shade_color( g[*c++], bc ) );
  97. fl_arc( x, y, w, h, 135.0, 225.0 );
  98. }
  99. }
  100. else if ( w > h )
  101. {
  102. int d = h / 2;
  103. for ( ; b > 1; d--, b--, x++, y++, w -= 2, h -= 2 )
  104. {
  105. fl_color( shade_color( g[*c++], bc ) );
  106. fl_arc( x, y, h, h, 90.0, 135.0 );
  107. fl_xyline( x + d, y, x + w - d );
  108. fl_arc( x + w - h, y, h, h, 45.0, 90.0 );
  109. fl_color( shade_color( g[*c++], bc ) );
  110. fl_arc( x + w - h, y, h, h, 315.0, 405.0 );
  111. fl_color( shade_color( g[*c++], bc ) );
  112. fl_arc( x + w - h, y, h, h, 270.0, 315.0 );
  113. fl_xyline( x + d, y + h - 1, x + w - d );
  114. fl_arc( x, y, h, h, 225.0, 270.0 );
  115. fl_color( shade_color( g[*c++], bc ) );
  116. fl_arc( x, y, h, h, 135.0, 225.0 );
  117. }
  118. }
  119. else if ( w < h )
  120. {
  121. int d = w / 2;
  122. for ( ; b > 1; d--, b--, x++, y++, w -= 2, h -= 2 )
  123. {
  124. fl_color( shade_color( g[*c++], bc ) );
  125. fl_arc( x, y, w, w, 45.0, 135.0 );
  126. fl_color( shade_color( g[*c++], bc ) );
  127. fl_arc( x, y, w, w, 0.0, 45.0 );
  128. fl_yxline( x + w - 1, y + d, y + h - d );
  129. fl_arc( x, y + h - w, w, w, 315.0, 360.0 );
  130. fl_color( shade_color( g[*c++], bc ) );
  131. fl_arc( x, y + h - w, w, w, 225.0, 315.0 );
  132. fl_color( shade_color( g[*c++], bc ) );
  133. fl_arc( x, y + h - w, w, w, 180.0, 225.0 );
  134. fl_yxline( x, y + d, y + h - d );
  135. fl_arc( x, y, w, w, 135.0, 180.0 );
  136. }
  137. }
  138. }
  139. static void
  140. shade_rect ( int x, int y, int w, int h, const char *c, Fl_Color bc )
  141. {
  142. uchar *g = fl_gray_ramp();
  143. int i, j;
  144. int clen = strlen( c ) - 1;
  145. int chalf = clen / 2;
  146. int cstep = 1;
  147. if ( ! Fl::draw_box_active() )
  148. bc = fl_inactive( bc );
  149. if ( h < ( w * 2 ) )
  150. {
  151. // Horizontal shading...
  152. if ( clen >= h )
  153. cstep = 2;
  154. for ( i = 0, j = 0; j < chalf; i++, j += cstep )
  155. {
  156. // Draw the top line and points...
  157. fl_color( shade_color( g[c[i]], bc ) );
  158. fl_xyline( x + 1, y + i, x + w - 2 );
  159. fl_color( shade_color( g[c[i] - 2], bc ) );
  160. fl_point( x, y + i + 1 );
  161. fl_point( x + w - 1, y + i + 1 );
  162. // Draw the bottom line and points...
  163. fl_color( shade_color( g[c[clen - i]], bc ) );
  164. fl_xyline( x + 1, y + h - i, x + w - 2 );
  165. fl_color( shade_color( g[c[clen - i] - 2], bc ) );
  166. fl_point( x, y + h - i );
  167. fl_point( x + w - 1, y + h - i );
  168. }
  169. // Draw the interior and sides...
  170. i = chalf / cstep;
  171. // fl_color( shade_color( g[c[chalf]], bc ) );
  172. fl_color( bc );
  173. fl_rectf( x + 1, y + i, w - 2, h - 2 * i + 1 );
  174. fl_color( shade_color( g[c[chalf] - 2], bc ) );
  175. fl_yxline( x, y + i, y + h - i );
  176. fl_yxline( x + w - 1, y + i, y + h - i );
  177. }
  178. else
  179. {
  180. // Vertical shading...
  181. if ( clen >= w )
  182. cstep = 2;
  183. for ( i = 0, j = 0; j < chalf; i++, j += cstep )
  184. {
  185. // Draw the left line and points...
  186. fl_color( shade_color( g[c[i]], bc ) );
  187. fl_yxline( x + i, y + 1, y + h - 1 );
  188. fl_color( shade_color( g[c[i] - 2], bc ) );
  189. fl_point( x + i + 1, y );
  190. fl_point( x + i + 1, y + h );
  191. // Draw the right line and points...
  192. fl_color( shade_color( g[c[clen - i]], bc ) );
  193. fl_yxline( x + w - 1 - i, y + 1, y + h - 1 );
  194. fl_color( shade_color( g[c[clen - i] - 2], bc ) );
  195. fl_point( x + w - 2 - i, y );
  196. fl_point( x + w - 2 - i, y + h );
  197. }
  198. // Draw the interior, top, and bottom...
  199. i = chalf / cstep;
  200. fl_color( shade_color( g[c[chalf]], bc ) );
  201. fl_rectf( x + i, y + 1, w - 2 * i, h - 1 );
  202. fl_color( shade_color( g[c[chalf] - 2], bc ) );
  203. fl_xyline( x + i, y, x + w - i );
  204. fl_xyline( x + i, y + h, x + w - i );
  205. }
  206. }
  207. static void
  208. shade_round ( int x, int y, int w, int h, const char *c, Fl_Color bc )
  209. {
  210. uchar *g = fl_gray_ramp();
  211. int i;
  212. int clen = strlen( c ) - 1;
  213. int chalf = clen / 2;
  214. if ( w > h )
  215. {
  216. int d = h / 2;
  217. const int na = 8;
  218. for ( i = 0; i < chalf; i++, d--, x++, y++, w -= 2, h -= 2 )
  219. {
  220. fl_color( shade_color( g[c[i]], bc ) );
  221. fl_pie( x, y, h, h, 90.0, 135.0 + i * na );
  222. fl_xyline( x + d, y, x + w - d );
  223. fl_pie( x + w - h, y, h, h, 45.0 + i * na, 90.0 );
  224. fl_color( shade_color( g[c[i] - 2], bc ) );
  225. fl_pie( x + w - h, y, h, h, 315.0 + i * na, 405.0 + i * na );
  226. fl_color( shade_color( g[c[clen - i]], bc ) );
  227. fl_pie( x + w - h, y, h, h, 270.0, 315.0 + i * na );
  228. fl_xyline( x + d, y + h - 1, x + w - d );
  229. fl_pie( x, y, h, h, 225.0 + i * na, 270.0 );
  230. fl_color( shade_color( g[c[clen - i] - 2], bc ) );
  231. fl_pie( x, y, h, h, 135.0 + i * na, 225.0 + i * na );
  232. }
  233. fl_color( shade_color( g[c[chalf]], bc ) );
  234. fl_rectf( x + d, y, w - h + 1, h + 1 );
  235. fl_pie( x, y, h, h, 90.0, 270.0 );
  236. fl_pie( x + w - h, y, h, h, 270.0, 90.0 );
  237. }
  238. else
  239. {
  240. int d = w / 2;
  241. const int na = 8;
  242. for ( i = 0; i < chalf; i++, d--, x++, y++, w -= 2, h -= 2 )
  243. {
  244. fl_color( shade_color( g[c[i]], bc ) );
  245. fl_pie( x, y, w, w, 45.0 + i * na, 135.0 + i * na );
  246. fl_color( shade_color( g[c[i] - 2], bc ) );
  247. fl_pie( x, y, w, w, 0.0, 45.0 + i * na );
  248. fl_yxline( x + w - 1, y + d, y + h - d );
  249. fl_pie( x, y + h - w, w, w, 315.0 + i * na, 360.0 );
  250. fl_color( shade_color( g[c[clen - i]], bc ) );
  251. fl_pie( x, y + h - w, w, w, 225.0 + i * na, 315.0 + i * na );
  252. fl_color( shade_color( g[c[clen - i] - 2], bc ) );
  253. fl_pie( x, y + h - w, w, w, 180.0, 225.0 + i * na );
  254. fl_yxline( x, y + d, y + h - d );
  255. fl_pie( x, y, w, w, 135.0 + i * na, 180.0 );
  256. }
  257. fl_color( shade_color( g[c[chalf]], bc ) );
  258. fl_rectf( x, y + d, w + 1, h - w + 1 );
  259. fl_pie( x, y, w, w, 0.0, 180.0 );
  260. fl_pie( x, y + h - w, w, w, 180.0, 360.0 );
  261. }
  262. }
  263. static void
  264. up_frame ( int x, int y, int w, int h, Fl_Color c )
  265. {
  266. frame_rect( x, y, w, h - 1, "KLDIIJLM", c );
  267. }
  268. static void
  269. narrow_thin_box ( int x, int y, int w, int h, Fl_Color c )
  270. {
  271. if ( h <= 0 || w <= 0 )
  272. return;
  273. uchar *g = fl_gray_ramp();
  274. fl_color( shade_color( g['R'], c ) );
  275. fl_rectf( x + 1, y + 1, w - 2, h - 2 );
  276. fl_color( shade_color( g['I'], c ) );
  277. if ( w > 1 )
  278. {
  279. fl_xyline( x + 1, y, x + w - 2 );
  280. fl_xyline( x + 1, y + h - 1, x + w - 2 );
  281. }
  282. if ( h > 1 )
  283. {
  284. fl_yxline( x, y + 1, y + h - 2 );
  285. fl_yxline( x + w - 1, y + 1, y + h - 2 );
  286. }
  287. }
  288. static void
  289. thin_up_box ( int x, int y, int w, int h, Fl_Color c )
  290. {
  291. if ( w > 4 && h > 4 )
  292. {
  293. shade_rect( x + 1, y + 1, w - 2, h - 3, "RQOQSUWQ", c );
  294. frame_rect( x, y, w, h - 1, "IJLM", c );
  295. }
  296. else
  297. narrow_thin_box( x, y, w, h, c );
  298. }
  299. static void
  300. up_box ( int x, int y, int w, int h, Fl_Color c )
  301. {
  302. if ( w > 8 && h > 8 )
  303. {
  304. // shade_rect( x + 1, y + 1, w - 2, h - 3, "RVQNOPQRSTUVWVQ", c );
  305. // shade_rect( x + 1, y + 1, w - 2, h - 3, "STUVWVQRWXVUVVQ", c );
  306. shade_rect( x + 1, y + 1, w - 2, h - 3, "FISPPQQRSSTTUPJ", c );
  307. /* stipple */
  308. fl_color( fl_color_average( FL_GRAY, c, 0.10f ) );
  309. for ( int i = y + 1; i < y + h - 8; i += 5 )
  310. fl_line( x + 1, i, x + w - 2, i );
  311. frame_rect( x, y, w, h - 1, "IJLM", c );
  312. }
  313. else
  314. thin_up_box( x, y, w, h, c );
  315. }
  316. static void
  317. up_round ( int x, int y, int w, int h, Fl_Color c )
  318. {
  319. shade_round( x, y, w, h, "RVQNOPQRSTUVWVQ", c );
  320. frame_round( x, y, w, h, "IJLM", c );
  321. }
  322. static void
  323. down_frame ( int x, int y, int w, int h, Fl_Color c )
  324. {
  325. frame_rect( x, y, w, h - 1, "LLLLTTRR", c );
  326. }
  327. static void
  328. down_box ( int x, int y, int w, int h, Fl_Color c )
  329. {
  330. if ( w > 6 && h > 6 )
  331. {
  332. shade_rect( x + 2, y + 2, w - 4, h - 5, "STUVWWWVT", c );
  333. down_frame( x, y, w, h, c );
  334. }
  335. else
  336. {
  337. narrow_thin_box( x, y, w, h, c );
  338. }
  339. }
  340. static void
  341. down_round ( int x, int y, int w, int h, Fl_Color c )
  342. {
  343. shade_round( x, y, w, h, "STUVWWWVT", c );
  344. frame_round( x, y, w, h, "IJLM", c );
  345. }
  346. void
  347. init_boxtypes ( void )
  348. {
  349. Fl::set_boxtype( FL_BURNISHED_OVAL_BOX, burnished_oval_box, 4, 4, 7, 7 );
  350. Fl::set_boxtype( FL_CRYSTAL_UP_BOX, up_box, 4,4,8,8 );
  351. Fl::set_boxtype( FL_CRYSTAL_DOWN_BOX, down_box, 2,2,4,4 );
  352. Fl::set_boxtype( FL_CRYSTAL_UP_FRAME, up_frame, 2,2,4,4 );
  353. Fl::set_boxtype( FL_CRYSTAL_DOWN_FRAME, down_frame, 2,2,4,4 );
  354. Fl::set_boxtype( FL_CRYSTAL_THIN_UP_BOX, thin_up_box, 1,1,2,2 );
  355. Fl::set_boxtype( FL_CRYSTAL_THIN_DOWN_BOX, down_box, 1,1,2,2 );
  356. /* replace the plastic boxes... (is there a better way?) */
  357. Fl::set_boxtype( FL_PLASTIC_UP_BOX, up_box, 4,4,8,8 );
  358. Fl::set_boxtype( FL_PLASTIC_DOWN_BOX, down_box, 2,2,4,4 );
  359. Fl::set_boxtype( FL_PLASTIC_UP_FRAME, up_frame, 2,2,4,4 );
  360. Fl::set_boxtype( FL_PLASTIC_DOWN_FRAME, down_frame, 2,2,4,4 );
  361. Fl::set_boxtype( FL_PLASTIC_THIN_UP_BOX, thin_up_box, 1,1,2,2 );
  362. Fl::set_boxtype( FL_PLASTIC_THIN_DOWN_BOX, down_box, 1,1,2,2 );
  363. /* Fl::set_boxtype( FL_CRYSTAL_ROUND_UP_BOX, up_round ); */
  364. /* Fl::set_boxtype( FL_CRYSTAL_ROUND_DOWN_BOX, down_round ); */
  365. }