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.

109 lines
3.1KB

  1. //
  2. // "$Id: Fl_Value_Output.cxx 7903 2010-11-28 21:06:39Z matt $"
  3. //
  4. // Value output widget for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2010 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. // Fltk widget for drag-adjusting a floating point value.
  28. // This is much lighter than Fl_Value_Input because it has no text editor
  29. // If step() is zero then it can be used to display a floating-point value
  30. #include <FL/Fl.H>
  31. #include <FL/Fl_Value_Output.H>
  32. #include <FL/fl_draw.H>
  33. void Fl_Value_Output::draw() {
  34. Fl_Boxtype b = box() ? box() : FL_DOWN_BOX;
  35. int X = x()+Fl::box_dx(b);
  36. int Y = y()+Fl::box_dy(b);
  37. int W = w()-Fl::box_dw(b);
  38. int H = h()-Fl::box_dh(b);
  39. if (damage()&~FL_DAMAGE_CHILD)
  40. draw_box(b, color());
  41. else {
  42. fl_color(color());
  43. fl_rectf(X, Y, W, H);
  44. }
  45. char buf[128];
  46. format(buf);
  47. fl_color(active_r() ? textcolor() : fl_inactive(textcolor()));
  48. fl_font(textfont(), textsize());
  49. fl_draw(buf,X,Y,W,H,FL_ALIGN_LEFT);
  50. }
  51. int Fl_Value_Output::handle(int event) {
  52. if (!step()) return 0;
  53. double v;
  54. int delta;
  55. int mx = Fl::event_x();
  56. static int ix, drag;
  57. switch (event) {
  58. case FL_PUSH:
  59. ix = mx;
  60. drag = Fl::event_button();
  61. handle_push();
  62. return 1;
  63. case FL_DRAG:
  64. delta = Fl::event_x()-ix;
  65. if (delta > 5) delta -= 5;
  66. else if (delta < -5) delta += 5;
  67. else delta = 0;
  68. switch (drag) {
  69. case 3: v = increment(previous_value(),delta*100); break;
  70. case 2: v = increment(previous_value(),delta*10); break;
  71. default:v = increment(previous_value(),delta); break;
  72. }
  73. v = round(v);
  74. handle_drag(soft()?softclamp(v):clamp(v));;
  75. return 1;
  76. case FL_RELEASE:
  77. handle_release();
  78. return 1;
  79. case FL_ENTER :
  80. case FL_LEAVE :
  81. return 1;
  82. default:
  83. return 0;
  84. }
  85. }
  86. /**
  87. Creates a new Fl_Value_Output widget using the given
  88. position, size, and label string. The default boxtype is FL_NO_BOX.
  89. <P> Inherited destructor destroys the Valuator.
  90. */
  91. Fl_Value_Output::Fl_Value_Output(int X, int Y, int W, int H,const char *l)
  92. : Fl_Valuator(X,Y,W,H,l) {
  93. box(FL_NO_BOX);
  94. align(FL_ALIGN_LEFT);
  95. textfont_ = FL_HELVETICA;
  96. textsize_ = FL_NORMAL_SIZE;
  97. textcolor_ = FL_FOREGROUND_COLOR;
  98. soft_ = 0;
  99. }
  100. //
  101. // End of "$Id: Fl_Value_Output.cxx 7903 2010-11-28 21:06:39Z matt $".
  102. //