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