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.

281 lines
6.4KB

  1. # data file for the Fltk User Interface Designer (fluid)
  2. version 2.00
  3. header_name {.H}
  4. code_name {.cxx}
  5. gridx 5
  6. gridy 5
  7. snap 3
  8. decl {\#include <FL/Fl_Valuator.H>} {public
  9. }
  10. decl {\#include <FL/fl_draw.H>} {}
  11. decl {\#include <math.h>} {}
  12. class Fl_Knob {open : {public Fl_Valuator}
  13. } {
  14. decl {enum Fl_Knobtype {DOTLIN=0,DOTLOG_1,DOTLOG_2,DOTLOG_3,LINELIN,LINELOG_1,LINELOG_2,LINELOG_3};} {public
  15. }
  16. decl {int _type;} {}
  17. decl {float _percent;} {}
  18. decl {int _scaleticks;} {}
  19. decl {short a1,a2;} {}
  20. Function {Fl_Knob(int xx,int yy,int ww,int hh,const char *l=0): Fl_Valuator(xx,yy,ww,hh,l)} {} {
  21. code {a1 = 35;
  22. a2 = 325;
  23. _type = DOTLIN;
  24. _percent = 0.3;
  25. _scaleticks = 10;} {}
  26. }
  27. Function {~Fl_Knob()} {} {}
  28. Function {draw()} {open private
  29. } {
  30. code {int ox,oy,ww,hh,side;
  31. float sa,ca,a_r;
  32. unsigned char rr,gg,bb;
  33. ox = x();
  34. oy = y();
  35. ww = w();
  36. hh = h();
  37. draw_label();
  38. fl_clip(ox,oy,ww,hh);
  39. if (ww > hh)
  40. {
  41. side = hh;
  42. ox = ox + (ww - side) / 2;
  43. }
  44. else
  45. {
  46. side = ww;
  47. oy = oy + (hh - side) / 2;
  48. }
  49. side = w() > h () ? hh:ww;
  50. int dam = damage();
  51. if (dam & FL_DAMAGE_ALL)
  52. {
  53. int col = parent()->color();
  54. fl_color(col);
  55. fl_rectf(ox,oy,side,side);
  56. Fl::get_color((Fl_Color)col,rr,gg,bb);
  57. shadow(-60,rr,gg,bb);
  58. fl_pie(ox+9,oy+9,side-12,side-12,0,360);
  59. draw_scale(ox,oy,side);
  60. col = color();
  61. Fl::get_color((Fl_Color)col,rr,gg,bb);
  62. shadow(15,rr,gg,bb);
  63. fl_pie(ox+6,oy+6,side-12,side-12,40,80);
  64. shadow(30,rr,gg,bb);
  65. fl_pie(ox+6,oy+6,side-12,side-12,80,220);
  66. shadow(-15,rr,gg,bb);
  67. fl_pie(ox+6,oy+6,side-12,side-12,220,260);
  68. shadow(-30,rr,gg,bb);
  69. fl_pie(ox+6,oy+6,side-12,side-12,260,400);
  70. fl_color(FL_BLACK);
  71. fl_arc(ox+6,oy+6,side-11,side-11,0,360);
  72. fl_color(col);
  73. fl_pie(ox+10,oy+10,side-20,side-20,0,360);
  74. }
  75. else
  76. {
  77. fl_color(color());
  78. fl_pie(ox+10,oy+10,side-20,side-20,0,360);
  79. }
  80. Fl::get_color((Fl_Color)color(),rr,gg,bb);
  81. shadow(10,rr,gg,bb);
  82. fl_pie(ox+10,oy+10,side-20,side-20,110,150);
  83. fl_pie(ox+10,oy+10,side-20,side-20,290,330);
  84. shadow(17,rr,gg,bb);
  85. fl_pie(ox+10,oy+10,side-20,side-20,120,140);
  86. fl_pie(ox+10,oy+10,side-20,side-20,300,320);
  87. shadow(25,rr,gg,bb);
  88. fl_pie(ox+10,oy+10,side-20,side-20,127,133);
  89. fl_pie(ox+10,oy+10,side-20,side-20,307,313);
  90. draw_cursor(ox,oy,side);
  91. fl_pop_clip();} {selected
  92. }
  93. }
  94. Function {handle(int event)} {private return_type int
  95. } {
  96. code {int ox,oy,ww,hh;
  97. ox = x() + 10; oy = y() + 10;
  98. ww = w() - 20;
  99. hh = h()-20;
  100. switch (event)
  101. {
  102. case FL_PUSH:
  103. handle_push();
  104. case FL_DRAG:
  105. {
  106. int mx = Fl::event_x()-ox-ww/2;
  107. int my = Fl::event_y()-oy-hh/2;
  108. if (!mx && !my) return 1;
  109. double angle = 270-atan2((float)-my, (float)mx)*180/M_PI;
  110. double oldangle = (a2-a1)*(value()-minimum())/(maximum()-minimum()) + a1;
  111. while (angle < oldangle-180) angle += 360;
  112. while (angle > oldangle+180) angle -= 360;
  113. double val;
  114. if ((a1<a2) ? (angle <= a1) : (angle >= a1))
  115. {
  116. val = minimum();
  117. }
  118. else
  119. if ((a1<a2) ? (angle >= a2) : (angle <= a2))
  120. {
  121. val = maximum();
  122. }
  123. else
  124. {
  125. val = minimum() + (maximum()-minimum())*(angle-a1)/(a2-a1);
  126. }
  127. handle_drag(clamp(round(val)));
  128. }
  129. return 1;
  130. case FL_RELEASE:
  131. handle_release();
  132. return 1;
  133. default:
  134. return 0;
  135. }
  136. return 0;} {}
  137. }
  138. Function {type(int ty)} {} {
  139. code {_type = ty;} {}
  140. }
  141. Function {shadow(const int offs,const uchar r,uchar g,uchar b)} {private
  142. } {
  143. code {int rr,gg,bb;
  144. rr = r + offs;
  145. rr = rr > 255 ? 255:rr;
  146. rr = rr < 0 ? 0:rr;
  147. gg = g + offs;
  148. gg = gg > 255 ? 255:gg;
  149. gg = gg < 0 ? 0:gg;
  150. bb = b + offs;
  151. bb = bb > 255 ? 255:bb;
  152. bb = bb < 0 ? 0:bb;
  153. fl_color((uchar)rr,(uchar)gg,(uchar)bb);} {}
  154. }
  155. Function {draw_scale(const int ox,const int oy,const int side)} {private
  156. } {
  157. code {float x1,y1,x2,y2,rds,cx,cy,ca,sa;
  158. rds = side / 2;
  159. cx = ox + side / 2;
  160. cy = oy + side / 2;
  161. if (!(_type & DOTLOG_3))
  162. {
  163. if (_scaleticks == 0) return;
  164. double a_step = (10.0*3.14159/6.0) / _scaleticks;
  165. double a_orig = -(3.14159/3.0);
  166. for (int a = 0; a <= _scaleticks; a++)
  167. {
  168. double na = a_orig + a * a_step;
  169. ca = cos(na);
  170. sa = sin(na);
  171. x1 = cx + rds * ca;
  172. y1 = cy - rds * sa;
  173. x2 = cx + (rds-6) * ca;
  174. y2 = cy - (rds-6) * sa;
  175. fl_color(FL_BLACK);
  176. fl_line(x1,y1,x2,y2);
  177. fl_color(FL_WHITE);
  178. if (sa*ca >=0)
  179. fl_line(x1+1,y1+1,x2+1,y2+1);
  180. else
  181. fl_line(x1+1,y1-1,x2+1,y2-1);
  182. }
  183. }
  184. else
  185. {
  186. int nb_dec = (_type & DOTLOG_3);
  187. for (int k = 0; k < nb_dec; k++)
  188. {
  189. double a_step = (10.0*3.14159/6.0) / nb_dec;
  190. double a_orig = -(3.14159/3.0) + k * a_step;
  191. for (int a = (k) ? 2:1; a <= 10; )
  192. {
  193. double na = a_orig + log10((double)a) * a_step;
  194. ca = cos(na);
  195. sa = sin(na);
  196. x1 = cx - rds * ca;
  197. y1 = cy - rds * sa;
  198. x2 = cx - (rds-6) * ca;
  199. y2 = cy - (rds-6) * sa;
  200. fl_color(FL_BLACK);
  201. fl_line(x1,y1,x2,y2);
  202. fl_color(FL_WHITE);
  203. if (sa*ca <0)
  204. fl_line(x1+1,y1+1,x2+1,y2+1);
  205. else
  206. fl_line(x1+1,y1-1,x2+1,y2-1);
  207. if ((a == 1) || (nb_dec == 1))
  208. a += 1;
  209. else
  210. a += 2;
  211. }
  212. }
  213. }} {}
  214. }
  215. Function {draw_cursor(const int ox,const int oy,const int side)} {private
  216. } {
  217. code {float rds,cur,cx,cy;
  218. double angle;
  219. rds = (side - 20) / 2.0;
  220. cur = _percent * rds / 2;
  221. cx = ox + side / 2;
  222. cy = oy + side / 2;
  223. angle = (a2-a1)*(value()-minimum())/(maximum()-minimum()) + a1;
  224. fl_push_matrix();
  225. fl_scale(1,1);
  226. fl_translate(cx,cy);
  227. fl_rotate(-angle);
  228. fl_translate(0,rds-cur-2.0);
  229. if (_type<LINELIN)
  230. {
  231. fl_begin_polygon();
  232. fl_color(selection_color());
  233. fl_circle(0.0,0.0,cur);
  234. fl_end_polygon();
  235. fl_begin_loop();
  236. fl_color(FL_BLACK);
  237. fl_circle(0.0,0.0,cur);
  238. fl_end_loop();
  239. }
  240. else
  241. {
  242. fl_begin_polygon();
  243. fl_color(selection_color());
  244. fl_vertex(-1.5,-cur);
  245. fl_vertex(-1.5,cur);
  246. fl_vertex(1.5,cur);
  247. fl_vertex(1.5,-cur);
  248. fl_end_polygon();
  249. fl_begin_loop();
  250. fl_color(FL_BLACK);
  251. fl_vertex(-1.5,-cur);
  252. fl_vertex(-1.5,cur);
  253. fl_vertex(1.5,cur);
  254. fl_vertex(1.5,-cur);
  255. fl_end_loop();
  256. }
  257. fl_pop_matrix();} {}
  258. }
  259. Function {cursor(const int pc)} {} {
  260. code {_percent = (float)pc/100.0;
  261. if (_percent < 0.05) _percent = 0.05;
  262. if (_percent > 1.0) _percent = 1.0;
  263. if (visible()) damage(FL_DAMAGE_CHILD);} {}
  264. }
  265. Function {scaleticks(const int tck)} {} {
  266. code {_scaleticks = tck;
  267. if (_scaleticks < 0) _scaleticks = 0;
  268. if (_scaleticks > 31) _scaleticks = 31;
  269. if (visible()) damage(FL_DAMAGE_ALL);} {}
  270. }
  271. }