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.

42 lines
1.2KB

  1. #include <FL/Fl.H>
  2. #include "Fl_VU_Meter.h"
  3. #include <FL/fl_draw.H>
  4. Fl_VU_Meter::Fl_VU_Meter (int x, int y, int w, int h, const char *l = 0) :
  5. Fl_Progress (x, y, w, h, l) {
  6. }
  7. void Fl_VU_Meter::draw() {
  8. int progress, bx, by, bw, bh, tx, tw;
  9. bx = Fl::box_dx (box());
  10. by = Fl::box_dy (box());
  11. bw = Fl::box_dw (box());
  12. bh = Fl::box_dh (box());
  13. tx = x() + bx;
  14. tw = w() - bw;
  15. if (maximum() > minimum())
  16. progress = (int)(tw * (value() - minimum()) / (maximum() - minimum()) + 0.5f);
  17. else progress = 0;
  18. draw_box (box(), x(), y(), w(), h(), color());
  19. if (progress > 0) {
  20. int block_width = w() / 16;
  21. int block = 0;
  22. for (int block_pos = 0; block_pos < progress; block_pos += block_width) {
  23. Fl_Color colour;
  24. if (++block == 16) colour = FL_RED;
  25. else if (block > 10) colour = FL_YELLOW;
  26. else colour = FL_GREEN;
  27. if (!active_r()) colour = fl_inactive (colour);
  28. fl_push_clip (x() + block_pos, y(), block_width - 2, h());
  29. draw_box (box(), x(), y(), w(), h(), colour);
  30. fl_pop_clip();
  31. }
  32. }
  33. // we don't care about the label
  34. // draw_label (tx, y() + by, tw, h() - bh);
  35. }