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.

272 lines
5.8KB

  1. // generated by Fast Light User Interface Designer (fluid) version 1.0010
  2. #include "Fl_SevenSeg.H"
  3. // Andy Preston changed
  4. // Fl_SevenSeg::Fl_SevenSeg(int x,int y,int w,int h):Fl_Widget(x,y,w,h) {
  5. // to
  6. Fl_SevenSeg::Fl_SevenSeg(int x, int y, int w, int h) :
  7. Fl_Widget (x, y, w, h),
  8. decpt (off) {
  9. color2(FL_BLACK);
  10. color(FL_RED);
  11. digit = 8;
  12. segwidth = (w-8)/13;
  13. segwidth = segwidth<(h-8)/13 ?(h-8)/13: segwidth;
  14. if (segwidth<1) segwidth =1;
  15. }
  16. Fl_SevenSeg::~Fl_SevenSeg(void) {
  17. }
  18. // Andy Preston changed
  19. //void Fl_SevenSeg::value(int v) {
  20. // if (v <0) digit = -1;
  21. // else
  22. // if (v>9) digit = 9;
  23. // else
  24. // digit = v;
  25. // if (active()) redraw();
  26. //}
  27. // to
  28. void Fl_SevenSeg::value (int v) {
  29. if (v>9) digit = 9;
  30. else digit = v;
  31. if (active()) redraw();
  32. }
  33. void Fl_SevenSeg::value(char c) {
  34. int v = c - '0';
  35. value(v);
  36. }
  37. const int Fl_SevenSeg::value(void) {
  38. return digit;
  39. }
  40. // Andy Preston changed
  41. // void Fl_SevenSeg::dp(int onoff) {
  42. // decpt =(onoff!=0);
  43. // }
  44. // to
  45. void Fl_SevenSeg::dp (dp_type state) {
  46. decpt = state;
  47. }
  48. // Andy Preston changed
  49. // const int Fl_SevenSeg::dp(void) {
  50. // to
  51. const dp_type Fl_SevenSeg::dp(void) {
  52. return decpt;
  53. }
  54. const int Fl_SevenSeg::bar_width(void) {
  55. return segwidth;
  56. }
  57. void Fl_SevenSeg::bar_width(int w) {
  58. segwidth = w > 2 ? w:2;
  59. if (active()) redraw();
  60. }
  61. // PRIVATE METHODS
  62. void Fl_SevenSeg::draw() {
  63. uchar r,g,b;
  64. int val;
  65. draw_box();
  66. // andy preston
  67. fl_color (color2());
  68. fl_rectf (x(), y(), w(), h());
  69. // Andy Preston Changed
  70. // int xx = x()+4;
  71. // int ww = w()-8;
  72. // int yy = y()+4;
  73. // int hh = h()-8;
  74. // to
  75. int xx = x()+2;
  76. int ww = w()-4;
  77. int yy = y()+2;
  78. int hh = h()-4;
  79. // Andy Preston removed
  80. // fl_clip(xx,yy,ww,hh);
  81. // fl_color(color2());
  82. // fl_rectf(xx,yy,ww,hh);
  83. // Andy Preston changed
  84. // if (digit == -1) return;
  85. if (digit < -1) return;
  86. Fl::get_color(color(),r,g,b);
  87. if (!active())
  88. {
  89. val = 64+(int)r/4; r = val > 255 ? 255:val;
  90. val = 64+(int)g/4; g = val > 255 ? 255:val;
  91. val = 64+(int)b/4; b = val > 255 ? 255:val;
  92. }
  93. fl_color(r,g,b);
  94. fl_line_style(FL_SOLID|FL_CAP_ROUND,segwidth);
  95. switch(digit)
  96. {
  97. // Andy Preston
  98. case -1:
  99. draw_seg_g (xx, yy, ww, hh);
  100. break;
  101. case 0:
  102. draw_seg_a(xx,yy,ww,hh);
  103. draw_seg_b(xx,yy,ww,hh);
  104. draw_seg_c(xx,yy,ww,hh);
  105. draw_seg_d(xx,yy,ww,hh);
  106. draw_seg_e(xx,yy,ww,hh);
  107. draw_seg_f(xx,yy,ww,hh);
  108. break;
  109. case 1:
  110. draw_seg_b(xx,yy,ww,hh);
  111. draw_seg_c(xx,yy,ww,hh);
  112. break;
  113. case 2:
  114. draw_seg_a(xx,yy,ww,hh);
  115. draw_seg_b(xx,yy,ww,hh);
  116. draw_seg_g(xx,yy,ww,hh);
  117. draw_seg_e(xx,yy,ww,hh);
  118. draw_seg_d(xx,yy,ww,hh);
  119. break;
  120. case 3:
  121. draw_seg_a(xx,yy,ww,hh);
  122. draw_seg_b(xx,yy,ww,hh);
  123. draw_seg_c(xx,yy,ww,hh);
  124. draw_seg_d(xx,yy,ww,hh);
  125. draw_seg_g(xx,yy,ww,hh);
  126. break;
  127. case 4:
  128. draw_seg_b(xx,yy,ww,hh);
  129. draw_seg_c(xx,yy,ww,hh);
  130. draw_seg_f(xx,yy,ww,hh);
  131. draw_seg_g(xx,yy,ww,hh);
  132. break;
  133. case 5:
  134. draw_seg_a(xx,yy,ww,hh);
  135. draw_seg_c(xx,yy,ww,hh);
  136. draw_seg_d(xx,yy,ww,hh);
  137. draw_seg_f(xx,yy,ww,hh);
  138. draw_seg_g(xx,yy,ww,hh);
  139. break;
  140. case 6:
  141. draw_seg_a(xx,yy,ww,hh);
  142. draw_seg_c(xx,yy,ww,hh);
  143. draw_seg_d(xx,yy,ww,hh);
  144. draw_seg_e(xx,yy,ww,hh);
  145. draw_seg_f(xx,yy,ww,hh);
  146. draw_seg_g(xx,yy,ww,hh);
  147. break;
  148. case 7:
  149. draw_seg_a(xx,yy,ww,hh);
  150. draw_seg_b(xx,yy,ww,hh);
  151. draw_seg_c(xx,yy,ww,hh);
  152. break;
  153. case 8:
  154. draw_seg_a(xx,yy,ww,hh);
  155. draw_seg_b(xx,yy,ww,hh);
  156. draw_seg_c(xx,yy,ww,hh);
  157. draw_seg_d(xx,yy,ww,hh);
  158. draw_seg_e(xx,yy,ww,hh);
  159. draw_seg_f(xx,yy,ww,hh);
  160. draw_seg_g(xx,yy,ww,hh);
  161. break;
  162. case 9:
  163. draw_seg_a(xx,yy,ww,hh);
  164. draw_seg_b(xx,yy,ww,hh);
  165. draw_seg_c(xx,yy,ww,hh);
  166. draw_seg_d(xx,yy,ww,hh);
  167. draw_seg_g(xx,yy,ww,hh);
  168. draw_seg_f(xx,yy,ww,hh);
  169. break;
  170. }
  171. // Andy Preston changed (naughty, naughty, who missed out the dp drawing code then?)
  172. // fl_line_style(FL_SOLID,1);
  173. // if (decpt) { }
  174. // to
  175. if (decpt==point) draw_seg_dp (xx, yy, ww, hh);
  176. else if (decpt==colon) draw_seg_col (xx, yy, ww, hh);
  177. fl_line_style(FL_SOLID,1);
  178. //fl_pop_clip();
  179. }
  180. // Andy Preston
  181. void Fl_SevenSeg::draw_seg_dp (int xx, int yy, int ww, int hh) {
  182. int x1 = xx - segwidth / 2;
  183. int y1 = yy + hh - segwidth;
  184. int x2 = x1 + segwidth / 3;
  185. fl_line (x1, y1, x2, y1);
  186. }
  187. // Andy Preston
  188. void Fl_SevenSeg::draw_seg_col (int xx, int yy, int ww, int hh) {
  189. int x1 = xx - segwidth/2;
  190. int x2 = x1 + segwidth/3;
  191. int y1 = yy + 1 + hh/4;
  192. int y2 = yy - 1 + (hh/4) * 3;
  193. fl_line (x1, y1, x2, y1);
  194. fl_line (x1, y2, x2, y2);
  195. }
  196. void Fl_SevenSeg::draw_seg_a(int xx,int yy,int ww,int hh) {
  197. int x1 = xx+2*segwidth+1;
  198. int y1 = yy+segwidth;
  199. int x2 = xx+ww-2*segwidth-1;
  200. fl_line(x1,y1,x2,y1);
  201. }
  202. void Fl_SevenSeg::draw_seg_b(int xx,int yy,int ww,int hh) {
  203. int x1 = xx+ww-segwidth;
  204. int y1 = yy+(3*segwidth)/2+1;
  205. int y2 = y1+hh/2-2*segwidth-1;
  206. fl_line(x1,y1,x1,y2);
  207. }
  208. void Fl_SevenSeg::draw_seg_c(int xx,int yy,int ww,int hh) {
  209. int x1 = xx+ww-segwidth;
  210. int y1 = yy+(hh+segwidth)/2+1;
  211. int y2 = y1+hh/2-2*segwidth-1;
  212. fl_line(x1,y1,x1,y2);
  213. }
  214. void Fl_SevenSeg::draw_seg_d(int xx,int yy,int ww,int hh) {
  215. int x1 = xx+2*segwidth+1;
  216. int y1 = yy+hh-segwidth;
  217. int x2 = xx+ww-2*segwidth-1;
  218. fl_line(x1,y1,x2,y1);
  219. }
  220. void Fl_SevenSeg::draw_seg_e(int xx,int yy,int ww,int hh) {
  221. int x1 = xx+segwidth;
  222. int y1 = yy+(hh+segwidth)/2+1;
  223. int y2 = y1+hh/2-2*segwidth-1;
  224. fl_line(x1,y1,x1,y2);
  225. }
  226. void Fl_SevenSeg::draw_seg_f(int xx,int yy,int ww,int hh) {
  227. int x1 = xx+segwidth;
  228. int y1 = yy+(3*segwidth)/2+1;
  229. int y2 = y1+hh/2-2*segwidth-1;
  230. fl_line(x1,y1,x1,y2);
  231. }
  232. void Fl_SevenSeg::draw_seg_g(int xx,int yy,int ww,int hh) {
  233. int x1 = xx+2*segwidth+1;
  234. int y1 = yy+(hh-segwidth/2)/2;
  235. int x2 = xx+ww-2*segwidth-1;
  236. fl_line(x1,y1,x2,y1);
  237. }