Audio plugin host https://kx.studio/carla
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.

76 lines
1.3KB

  1. #include <cstdio>
  2. #include <cmath>
  3. #include <FL/Fl_Tooltip.H>
  4. #include <FL/fl_draw.H>
  5. #include "TipWin.h"
  6. TipWin::TipWin(void):Fl_Menu_Window(1, 1)
  7. {
  8. strcpy(format, "%0.2f");
  9. set_override();
  10. end();
  11. }
  12. void TipWin::setRounding(unsigned int digits)
  13. {
  14. format[3] = "0123456789"[digits < 9 ? digits : 9];
  15. }
  16. void TipWin::draw()
  17. {
  18. //setup window
  19. draw_box(FL_BORDER_BOX, 0, 0, w(), h(), Fl_Color(175));
  20. fl_color(Fl_Tooltip::textcolor());
  21. fl_font(labelfont(), labelsize());
  22. //Draw the current string
  23. fl_draw(getStr(), 3, 3, w() - 6, h() - 6,
  24. Fl_Align(FL_ALIGN_LEFT | FL_ALIGN_WRAP));
  25. }
  26. void TipWin::showValue(float f)
  27. {
  28. //convert the value to a string
  29. char tmp[10];
  30. snprintf(tmp, 9, format, f);
  31. tip = tmp;
  32. textmode = false;
  33. redraw();
  34. show();
  35. }
  36. void TipWin::setText(const char *c)
  37. {
  38. text = c;
  39. textmode = true;
  40. redraw();
  41. }
  42. void TipWin::showText()
  43. {
  44. if(!text.empty()) {
  45. textmode = true;
  46. redraw();
  47. show();
  48. }
  49. }
  50. void TipWin::redraw()
  51. {
  52. // Recalc size of window
  53. fl_font(labelfont(), labelsize());
  54. int W = 0, H = 0;
  55. fl_measure(getStr(), W, H, 0);
  56. //provide a bit of extra space
  57. W += 8;
  58. H += 4;
  59. size(W, H);
  60. Fl_Menu_Window::redraw();
  61. }
  62. const char *TipWin::getStr() const
  63. {
  64. return (textmode ? text : tip).c_str();
  65. }