|
fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation) ![]() |
00001 // 00002 // "$Id: Fl_Value_Output.cxx 7903 2010-11-28 21:06:39Z matt $" 00003 // 00004 // Value output widget for the Fast Light Tool Kit (FLTK). 00005 // 00006 // Copyright 1998-2010 by Bill Spitzak and others. 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // Library General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Library General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00021 // USA. 00022 // 00023 // Please report all bugs and problems on the following page: 00024 // 00025 // http://www.fltk.org/str.php 00026 // 00027 00028 // Fltk widget for drag-adjusting a floating point value. 00029 // This is much lighter than Fl_Value_Input because it has no text editor 00030 // If step() is zero then it can be used to display a floating-point value 00031 00032 #include <FL/Fl.H> 00033 #include <FL/Fl_Value_Output.H> 00034 #include <FL/fl_draw.H> 00035 00036 void Fl_Value_Output::draw() { 00037 Fl_Boxtype b = box() ? box() : FL_DOWN_BOX; 00038 int X = x()+Fl::box_dx(b); 00039 int Y = y()+Fl::box_dy(b); 00040 int W = w()-Fl::box_dw(b); 00041 int H = h()-Fl::box_dh(b); 00042 if (damage()&~FL_DAMAGE_CHILD) 00043 draw_box(b, color()); 00044 else { 00045 fl_color(color()); 00046 fl_rectf(X, Y, W, H); 00047 } 00048 char buf[128]; 00049 format(buf); 00050 fl_color(active_r() ? textcolor() : fl_inactive(textcolor())); 00051 fl_font(textfont(), textsize()); 00052 fl_draw(buf,X,Y,W,H,FL_ALIGN_LEFT); 00053 } 00054 00055 int Fl_Value_Output::handle(int event) { 00056 if (!step()) return 0; 00057 double v; 00058 int delta; 00059 int mx = Fl::event_x(); 00060 static int ix, drag; 00061 switch (event) { 00062 case FL_PUSH: 00063 ix = mx; 00064 drag = Fl::event_button(); 00065 handle_push(); 00066 return 1; 00067 case FL_DRAG: 00068 delta = Fl::event_x()-ix; 00069 if (delta > 5) delta -= 5; 00070 else if (delta < -5) delta += 5; 00071 else delta = 0; 00072 switch (drag) { 00073 case 3: v = increment(previous_value(),delta*100); break; 00074 case 2: v = increment(previous_value(),delta*10); break; 00075 default:v = increment(previous_value(),delta); break; 00076 } 00077 v = round(v); 00078 handle_drag(soft()?softclamp(v):clamp(v));; 00079 return 1; 00080 case FL_RELEASE: 00081 handle_release(); 00082 return 1; 00083 case FL_ENTER : 00084 case FL_LEAVE : 00085 return 1; 00086 default: 00087 return 0; 00088 } 00089 } 00090 00096 Fl_Value_Output::Fl_Value_Output(int X, int Y, int W, int H,const char *l) 00097 : Fl_Valuator(X,Y,W,H,l) { 00098 box(FL_NO_BOX); 00099 align(FL_ALIGN_LEFT); 00100 textfont_ = FL_HELVETICA; 00101 textsize_ = FL_NORMAL_SIZE; 00102 textcolor_ = FL_FOREGROUND_COLOR; 00103 soft_ = 0; 00104 } 00105 00106 // 00107 // End of "$Id: Fl_Value_Output.cxx 7903 2010-11-28 21:06:39Z matt $". 00108 //