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.

428 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 ( w == h )
  85. {
  86. for ( ; b > 1; b--, x++, y++, w -= 2, h -= 2 )
  87. {
  88. fl_color( shade_color( g[*c++], bc ) );
  89. fl_arc( x, y, w, h, 45.0, 135.0 );
  90. fl_color( shade_color( g[*c++], bc ) );
  91. fl_arc( x, y, w, h, 315.0, 405.0 );
  92. fl_color( shade_color( g[*c++], bc ) );
  93. fl_arc( x, y, w, h, 225.0, 315.0 );
  94. fl_color( shade_color( g[*c++], bc ) );
  95. fl_arc( x, y, w, h, 135.0, 225.0 );
  96. }
  97. }
  98. else if ( w > h )
  99. {
  100. int d = h / 2;
  101. for ( ; b > 1; d--, b--, x++, y++, w -= 2, h -= 2 )
  102. {
  103. fl_color( shade_color( g[*c++], bc ) );
  104. fl_arc( x, y, h, h, 90.0, 135.0 );
  105. fl_xyline( x + d, y, x + w - d );
  106. fl_arc( x + w - h, y, h, h, 45.0, 90.0 );
  107. fl_color( shade_color( g[*c++], bc ) );
  108. fl_arc( x + w - h, y, h, h, 315.0, 405.0 );
  109. fl_color( shade_color( g[*c++], bc ) );
  110. fl_arc( x + w - h, y, h, h, 270.0, 315.0 );
  111. fl_xyline( x + d, y + h - 1, x + w - d );
  112. fl_arc( x, y, h, h, 225.0, 270.0 );
  113. fl_color( shade_color( g[*c++], bc ) );
  114. fl_arc( x, y, h, h, 135.0, 225.0 );
  115. }
  116. }
  117. else if ( w < h )
  118. {
  119. int d = w / 2;
  120. for ( ; b > 1; d--, b--, x++, y++, w -= 2, h -= 2 )
  121. {
  122. fl_color( shade_color( g[*c++], bc ) );
  123. fl_arc( x, y, w, w, 45.0, 135.0 );
  124. fl_color( shade_color( g[*c++], bc ) );
  125. fl_arc( x, y, w, w, 0.0, 45.0 );
  126. fl_yxline( x + w - 1, y + d, y + h - d );
  127. fl_arc( x, y + h - w, w, w, 315.0, 360.0 );
  128. fl_color( shade_color( g[*c++], bc ) );
  129. fl_arc( x, y + h - w, w, w, 225.0, 315.0 );
  130. fl_color( shade_color( g[*c++], bc ) );
  131. fl_arc( x, y + h - w, w, w, 180.0, 225.0 );
  132. fl_yxline( x, y + d, y + h - d );
  133. fl_arc( x, y, w, w, 135.0, 180.0 );
  134. }
  135. }
  136. }
  137. static void
  138. shade_rect ( int x, int y, int w, int h, const char *c, Fl_Color bc )
  139. {
  140. uchar *g = fl_gray_ramp();
  141. int i, j;
  142. int clen = strlen( c ) - 1;
  143. int chalf = clen / 2;
  144. int cstep = 1;
  145. if ( h < ( w * 2 ) )
  146. {
  147. // Horizontal shading...
  148. if ( clen >= h )
  149. cstep = 2;
  150. for ( i = 0, j = 0; j < chalf; i++, j += cstep )
  151. {
  152. // Draw the top line and points...
  153. fl_color( shade_color( g[c[i]], bc ) );
  154. fl_xyline( x + 1, y + i, x + w - 2 );
  155. fl_color( shade_color( g[c[i] - 2], bc ) );
  156. fl_point( x, y + i + 1 );
  157. fl_point( x + w - 1, y + i + 1 );
  158. // Draw the bottom line and points...
  159. fl_color( shade_color( g[c[clen - i]], bc ) );
  160. fl_xyline( x + 1, y + h - i, x + w - 2 );
  161. fl_color( shade_color( g[c[clen - i] - 2], bc ) );
  162. fl_point( x, y + h - i );
  163. fl_point( x + w - 1, y + h - i );
  164. }
  165. // Draw the interior and sides...
  166. i = chalf / cstep;
  167. // fl_color( shade_color( g[c[chalf]], bc ) );
  168. fl_color( bc );
  169. fl_rectf( x + 1, y + i, w - 2, h - 2 * i + 1 );
  170. fl_color( shade_color( g[c[chalf] - 2], bc ) );
  171. fl_yxline( x, y + i, y + h - i );
  172. fl_yxline( x + w - 1, y + i, y + h - i );
  173. }
  174. else
  175. {
  176. // Vertical shading...
  177. if ( clen >= w )
  178. cstep = 2;
  179. for ( i = 0, j = 0; j < chalf; i++, j += cstep )
  180. {
  181. // Draw the left line and points...
  182. fl_color( shade_color( g[c[i]], bc ) );
  183. fl_yxline( x + i, y + 1, y + h - 1 );
  184. fl_color( shade_color( g[c[i] - 2], bc ) );
  185. fl_point( x + i + 1, y );
  186. fl_point( x + i + 1, y + h );
  187. // Draw the right line and points...
  188. fl_color( shade_color( g[c[clen - i]], bc ) );
  189. fl_yxline( x + w - 1 - i, y + 1, y + h - 1 );
  190. fl_color( shade_color( g[c[clen - i] - 2], bc ) );
  191. fl_point( x + w - 2 - i, y );
  192. fl_point( x + w - 2 - i, y + h );
  193. }
  194. // Draw the interior, top, and bottom...
  195. i = chalf / cstep;
  196. fl_color( shade_color( g[c[chalf]], bc ) );
  197. fl_rectf( x + i, y + 1, w - 2 * i, h - 1 );
  198. fl_color( shade_color( g[c[chalf] - 2], bc ) );
  199. fl_xyline( x + i, y, x + w - i );
  200. fl_xyline( x + i, y + h, x + w - i );
  201. }
  202. }
  203. static void
  204. shade_round ( int x, int y, int w, int h, const char *c, Fl_Color bc )
  205. {
  206. uchar *g = fl_gray_ramp();
  207. int i;
  208. int clen = strlen( c ) - 1;
  209. int chalf = clen / 2;
  210. if ( w > h )
  211. {
  212. int d = h / 2;
  213. const int na = 8;
  214. for ( i = 0; i < chalf; i++, d--, x++, y++, w -= 2, h -= 2 )
  215. {
  216. fl_color( shade_color( g[c[i]], bc ) );
  217. fl_pie( x, y, h, h, 90.0, 135.0 + i * na );
  218. fl_xyline( x + d, y, x + w - d );
  219. fl_pie( x + w - h, y, h, h, 45.0 + i * na, 90.0 );
  220. fl_color( shade_color( g[c[i] - 2], bc ) );
  221. fl_pie( x + w - h, y, h, h, 315.0 + i * na, 405.0 + i * na );
  222. fl_color( shade_color( g[c[clen - i]], bc ) );
  223. fl_pie( x + w - h, y, h, h, 270.0, 315.0 + i * na );
  224. fl_xyline( x + d, y + h - 1, x + w - d );
  225. fl_pie( x, y, h, h, 225.0 + i * na, 270.0 );
  226. fl_color( shade_color( g[c[clen - i] - 2], bc ) );
  227. fl_pie( x, y, h, h, 135.0 + i * na, 225.0 + i * na );
  228. }
  229. fl_color( shade_color( g[c[chalf]], bc ) );
  230. fl_rectf( x + d, y, w - h + 1, h + 1 );
  231. fl_pie( x, y, h, h, 90.0, 270.0 );
  232. fl_pie( x + w - h, y, h, h, 270.0, 90.0 );
  233. }
  234. else
  235. {
  236. int d = w / 2;
  237. const int na = 8;
  238. for ( i = 0; i < chalf; i++, d--, x++, y++, w -= 2, h -= 2 )
  239. {
  240. fl_color( shade_color( g[c[i]], bc ) );
  241. fl_pie( x, y, w, w, 45.0 + i * na, 135.0 + i * na );
  242. fl_color( shade_color( g[c[i] - 2], bc ) );
  243. fl_pie( x, y, w, w, 0.0, 45.0 + i * na );
  244. fl_yxline( x + w - 1, y + d, y + h - d );
  245. fl_pie( x, y + h - w, w, w, 315.0 + i * na, 360.0 );
  246. fl_color( shade_color( g[c[clen - i]], bc ) );
  247. fl_pie( x, y + h - w, w, w, 225.0 + i * na, 315.0 + i * na );
  248. fl_color( shade_color( g[c[clen - i] - 2], bc ) );
  249. fl_pie( x, y + h - w, w, w, 180.0, 225.0 + i * na );
  250. fl_yxline( x, y + d, y + h - d );
  251. fl_pie( x, y, w, w, 135.0 + i * na, 180.0 );
  252. }
  253. fl_color( shade_color( g[c[chalf]], bc ) );
  254. fl_rectf( x, y + d, w + 1, h - w + 1 );
  255. fl_pie( x, y, w, w, 0.0, 180.0 );
  256. fl_pie( x, y + h - w, w, w, 180.0, 360.0 );
  257. }
  258. }
  259. static void
  260. up_frame ( int x, int y, int w, int h, Fl_Color c )
  261. {
  262. frame_rect( x, y, w, h - 1, "KLDIIJLM", c );
  263. }
  264. static void
  265. narrow_thin_box ( int x, int y, int w, int h, Fl_Color c )
  266. {
  267. if ( h <= 0 || w <= 0 )
  268. return;
  269. uchar *g = fl_gray_ramp();
  270. fl_color( shade_color( g['R'], c ) );
  271. fl_rectf( x + 1, y + 1, w - 2, h - 2 );
  272. fl_color( shade_color( g['I'], c ) );
  273. if ( w > 1 )
  274. {
  275. fl_xyline( x + 1, y, x + w - 2 );
  276. fl_xyline( x + 1, y + h - 1, x + w - 2 );
  277. }
  278. if ( h > 1 )
  279. {
  280. fl_yxline( x, y + 1, y + h - 2 );
  281. fl_yxline( x + w - 1, y + 1, y + h - 2 );
  282. }
  283. }
  284. static void
  285. thin_up_box ( int x, int y, int w, int h, Fl_Color c )
  286. {
  287. if ( w > 4 && h > 4 )
  288. {
  289. shade_rect( x + 1, y + 1, w - 2, h - 3, "RQOQSUWQ", c );
  290. frame_rect( x, y, w, h - 1, "IJLM", c );
  291. }
  292. else
  293. narrow_thin_box( x, y, w, h, c );
  294. }
  295. static void
  296. up_box ( int x, int y, int w, int h, Fl_Color c )
  297. {
  298. if ( w > 8 && h > 8 )
  299. {
  300. // shade_rect( x + 1, y + 1, w - 2, h - 3, "RVQNOPQRSTUVWVQ", c );
  301. // shade_rect( x + 1, y + 1, w - 2, h - 3, "STUVWVQRWXVUVVQ", c );
  302. shade_rect( x + 1, y + 1, w - 2, h - 3, "FISPPQQRSSTTUPJ", c );
  303. /* stipple */
  304. fl_color( fl_color_average( FL_GRAY, c, 0.10f ) );
  305. for ( int i = y + 1; i < y + h - 8; i += 5 )
  306. fl_line( x, i, x + w, i );
  307. frame_rect( x, y, w, h - 1, "IJLM", c );
  308. }
  309. else
  310. thin_up_box( x, y, w, h, c );
  311. }
  312. static void
  313. up_round ( int x, int y, int w, int h, Fl_Color c )
  314. {
  315. shade_round( x, y, w, h, "RVQNOPQRSTUVWVQ", c );
  316. frame_round( x, y, w, h, "IJLM", c );
  317. }
  318. static void
  319. down_frame ( int x, int y, int w, int h, Fl_Color c )
  320. {
  321. frame_rect( x, y, w, h - 1, "LLLLTTRR", c );
  322. }
  323. static void
  324. down_box ( int x, int y, int w, int h, Fl_Color c )
  325. {
  326. if ( w > 6 && h > 6 )
  327. {
  328. shade_rect( x + 2, y + 2, w - 4, h - 5, "STUVWWWVT", c );
  329. down_frame( x, y, w, h, c );
  330. }
  331. else
  332. {
  333. narrow_thin_box( x, y, w, h, c );
  334. }
  335. }
  336. static void
  337. down_round ( int x, int y, int w, int h, Fl_Color c )
  338. {
  339. shade_round( x, y, w, h, "STUVWWWVT", c );
  340. frame_round( x, y, w, h, "IJLM", c );
  341. }
  342. void
  343. init_boxtypes ( void )
  344. {
  345. Fl::set_boxtype( FL_BURNISHED_OVAL_BOX, burnished_oval_box, 4, 4, 7, 7 );
  346. Fl::set_boxtype( FL_CRYSTAL_UP_BOX, up_box, 4,4,8,8 );
  347. Fl::set_boxtype( FL_CRYSTAL_DOWN_BOX, down_box, 2,2,4,4 );
  348. Fl::set_boxtype( FL_CRYSTAL_UP_FRAME, up_frame, 2,2,4,4 );
  349. Fl::set_boxtype( FL_CRYSTAL_DOWN_FRAME, down_frame, 2,2,4,4 );
  350. Fl::set_boxtype( FL_CRYSTAL_THIN_UP_BOX, thin_up_box, 1,1,2,2 );
  351. Fl::set_boxtype( FL_CRYSTAL_THIN_DOWN_BOX, down_box, 1,1,2,2 );
  352. /* replace the plastic boxes... (is there a better way?) */
  353. Fl::set_boxtype( FL_PLASTIC_UP_BOX, up_box, 4,4,8,8 );
  354. Fl::set_boxtype( FL_PLASTIC_DOWN_BOX, down_box, 2,2,4,4 );
  355. Fl::set_boxtype( FL_PLASTIC_UP_FRAME, up_frame, 2,2,4,4 );
  356. Fl::set_boxtype( FL_PLASTIC_DOWN_FRAME, down_frame, 2,2,4,4 );
  357. Fl::set_boxtype( FL_PLASTIC_THIN_UP_BOX, thin_up_box, 1,1,2,2 );
  358. Fl::set_boxtype( FL_PLASTIC_THIN_DOWN_BOX, down_box, 1,1,2,2 );
  359. /* Fl::set_boxtype( FL_CRYSTAL_ROUND_UP_BOX, up_round ); */
  360. /* Fl::set_boxtype( FL_CRYSTAL_ROUND_DOWN_BOX, down_round ); */
  361. }