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.

87 lines
1.7KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. TipWin.cpp - Tooltips
  4. Copyright (C) 2016 Mark McCurry
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. */
  10. #include <cstdio>
  11. #include <cmath>
  12. #include <FL/Fl_Tooltip.H>
  13. #include <FL/fl_draw.H>
  14. #include "TipWin.h"
  15. TipWin::TipWin(void):Fl_Menu_Window(1, 1)
  16. {
  17. strcpy(format, "%0.2f");
  18. set_override();
  19. end();
  20. }
  21. void TipWin::set_rounding(unsigned int digits)
  22. {
  23. format[3] = "0123456789"[digits < 9 ? digits : 9];
  24. }
  25. void TipWin::draw()
  26. {
  27. //setup window
  28. draw_box(FL_BORDER_BOX, 0, 0, w(), h(), Fl_Color(175));
  29. fl_color(Fl_Tooltip::textcolor());
  30. fl_font(labelfont(), labelsize());
  31. //Draw the current string
  32. fl_draw(getStr(), 3, 3, w() - 6, h() - 6,
  33. Fl_Align(FL_ALIGN_LEFT | FL_ALIGN_WRAP));
  34. }
  35. void TipWin::showValue(float f)
  36. {
  37. //convert the value to a string
  38. char tmp[10];
  39. snprintf(tmp, 9, format, f);
  40. tip = tmp;
  41. textmode = false;
  42. redraw();
  43. show();
  44. }
  45. void TipWin::setText(const char *c)
  46. {
  47. text = c;
  48. textmode = true;
  49. redraw();
  50. }
  51. void TipWin::showText()
  52. {
  53. if(!text.empty()) {
  54. textmode = true;
  55. redraw();
  56. show();
  57. }
  58. }
  59. void TipWin::redraw()
  60. {
  61. // Recalc size of window
  62. fl_font(labelfont(), labelsize());
  63. int W = 0, H = 0;
  64. fl_measure(getStr(), W, H, 0);
  65. //provide a bit of extra space
  66. W += 8;
  67. H += 4;
  68. size(W, H);
  69. Fl_Menu_Window::redraw();
  70. }
  71. const char *TipWin::getStr() const
  72. {
  73. return (textmode ? text : tip).c_str();
  74. }