Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

GuiSlider.cxx

Go to the documentation of this file.
00001 #include "GuiSlider.h"
00002 
00003 
00004 #include <sigc++/sigc++.h>
00005  
00006 GuiHSlider::GuiHSlider(TGWindow& parent)
00007     : TGDoubleHSlider(&parent,10,kDoubleScaleBoth,-1,kHorizontalFrame,
00008                       TGFrame::GetDefaultFrameBackground(),
00009                       kFALSE,kTRUE)
00010     ,GuiSliderSignals(dynamic_cast<GuiSlider*>(&parent))
00011 {
00012 //    cerr << "TGDoubleHSlider ctor, fWidth="<< fWidth<<"\n";
00013     this->SetLayoutHints(kLHintsExpandX);
00014 }
00015 GuiHSlider::~GuiHSlider()
00016 {
00017 }
00018 
00019 void GuiHSlider::PositionChanged()
00020 {
00021 //    cerr << (void*)this << "->GuiHSlider::PositionChanged\n";
00022     this->TGDoubleHSlider::PositionChanged();
00023     position_changed();
00024 }
00025 void GuiHSlider::Pressed()
00026 {
00027 //    cerr << (void*)this << "->GuiHSlider::Pressed\n";
00028     fSlider->StartCompound();
00029     this->TGDoubleHSlider::Pressed();
00030     pressed();
00031 }
00032 void GuiHSlider::Released()
00033 {
00034 //    cerr << (void*)this << "->GuiHSlider::Released\n";
00035     fSlider->StopCompound();
00036     gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);  // ungrab pointer
00037     gVirtualX->Update();
00038     this->TGDoubleHSlider::Released();
00039     released();
00040 }
00041 
00042 static void fix_bounds(float& min, float& max)
00043 {
00044     if (min > max) min = max;
00045 
00046     float eps = 1e-6;
00047     if (max - min < eps) {
00048         if (max == 0) max += eps;
00049         else            max += max*eps;
00050         if (min == 0) min -= eps;
00051         else            min -= min*eps;
00052     }
00053 
00054 }
00055 
00056 void GuiHSlider::DoRedraw()
00057 {
00058     fix_bounds(fVmin,fVmax);
00059     this->TGDoubleHSlider::DoRedraw();
00060 }
00061 
00062 GuiVSlider::GuiVSlider(TGWindow& parent)
00063     : TGDoubleVSlider(&parent,10,kDoubleScaleBoth,-1,kVerticalFrame,
00064                       TGFrame::GetDefaultFrameBackground(),
00065                       kTRUE,kTRUE)
00066       ,GuiSliderSignals(dynamic_cast<GuiSlider*>(&parent))
00067 {
00068     this->SetLayoutHints(kLHintsExpandY);
00069 }
00070 GuiVSlider::~GuiVSlider()
00071 {
00072 }
00073 
00074 void GuiVSlider::PositionChanged()
00075 {
00076 //    cerr << (void*)this << "->GuiVSlider::PositionChanged\n";
00077     this->TGDoubleVSlider::PositionChanged();
00078     position_changed();
00079 }
00080 void GuiVSlider::Pressed()
00081 {
00082 //    cerr << (void*)this << "->GuiVSlider::Pressed\n";
00083     fSlider->StartCompound();
00084     this->TGDoubleVSlider::Pressed();
00085     pressed();
00086 }
00087 void GuiVSlider::Released()
00088 {
00089 //    cerr << (void*)this << "->GuiVSlider::Released\n";
00090     fSlider->StopCompound();
00091     gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);  // ungrab pointer
00092     gVirtualX->Update();
00093     this->TGDoubleVSlider::Released();
00094     released();
00095 }
00096 void GuiVSlider::DoRedraw()
00097 {
00098     fix_bounds(fVmin,fVmax);
00099     this->TGDoubleVSlider::DoRedraw();
00100 }
00101 
00102 
00103 GuiSlider::GuiSlider(TGWindow& parent, unsigned int option)
00104     : GuiBox(parent,option)
00105 {
00106     using SigC::slot;
00107 
00108     if (option & kVerticalFrame) {
00109         this->SetLayoutHints(kLHintsExpandY);
00110         GuiVSlider* s = manage(new GuiVSlider(*this));
00111         s->SetLayoutHints(kLHintsExpandY);
00112         this->Add(*s);
00113         fSlider = s;
00114         fSignals = s;
00115     }
00116     else {
00117         this->SetLayoutHints(kLHintsExpandX);
00118         GuiHSlider* s = manage(new GuiHSlider(*this));
00119         s->SetLayoutHints(kLHintsExpandX);
00120         this->Add(*s);
00121         fSlider = s;
00122         fSignals = s;
00123     }
00124     // hook up default controls
00125     RangeControl<double> rc, ec;
00126     this->UseRangeControl(rc);
00127     this->UseExtremaControl(ec);
00128 
00129     fSliderCon = fSignals->position_changed.connect
00130         (slot(*this,&GuiSlider::UpdateRange));
00131 }
00132 GuiSlider::~GuiSlider()
00133 {
00134     fSliderCon.disconnect();
00135     fRangeCon.disconnect();
00136     fExtremaCon.disconnect();
00137 }
00138 
00139 void GuiSlider::UseRange(Range<double>& r)
00140 {
00141     fRangeCon.disconnect();
00142     fRangeCtrl.UseRange(&r);
00143     fRangeCon = r.modified.connect(SigC::slot(*this,&GuiSlider::ApplyRange));
00144     this->ApplyRange();
00145 }
00146 void GuiSlider::UseExtrema(Range<double>& e)
00147 {
00148     fExtremaCon.disconnect();
00149     fExtremaCtrl.UseRange(&e);
00150     fExtremaCon = e.modified.connect(SigC::slot(*this,&GuiSlider::ApplyRange));
00151     this->ApplyRange();
00152 }
00153 
00154 void GuiSlider::UseRangeControl(RangeControl<double>& rc)
00155 {
00156     if (&fRangeCtrl == &rc) return;
00157     fRangeCon.disconnect();
00158     fRangeCtrl = rc;
00159     fRangeCon =
00160         fRangeCtrl.GetRange().modified.connect(SigC::slot(*this,&GuiSlider::ApplyRange));
00161     this->ApplyRange();
00162 }
00163 void GuiSlider::UseExtremaControl(RangeControl<double>& ec)
00164 {
00165     if (&fExtremaCtrl == &ec) return;
00166     fExtremaCon.disconnect();
00167     fExtremaCtrl = ec;
00168     fExtremaCon =
00169         fExtremaCtrl.GetRange().modified.connect(SigC::slot(*this,&GuiSlider::ApplyRange));
00170     this->ApplyRange();
00171 }
00172 
00173 void GuiSlider::UpdateRange()
00174 {
00175     fRangeCon.block(true);
00176     fRangeCtrl.Set(fSlider->GetMinPosition(),fSlider->GetMaxPosition());
00177     fRangeCon.block(false);
00178 }
00179 void GuiSlider::ApplyRange()
00180 {
00181     if (!fSlider) return;
00182 
00183     // Apply current ranges to the slider.  
00184     fSliderCon.block(true);
00185     fSlider->SetPosition(fRangeCtrl.GetRange().Min(),fRangeCtrl.GetRange().Max());
00186     double vmin = fExtremaCtrl.GetRange().Min();
00187     double vmax = fExtremaCtrl.GetRange().Max();
00188     const double eps = 1.0e-10;
00189     if (vmin == vmax) { vmin -= eps; vmax += eps; }
00190     fSlider->SetRange(vmin,vmax);
00191     fClient->ForceRedraw();
00192     fSliderCon.block(false);
00193 }
00194 void GuiSlider::StartCompound()
00195 {
00196     fRangeCtrl.StartCompound();
00197 }
00198 void GuiSlider::StopCompound()
00199 {
00200     fRangeCtrl.StopCompound();
00201 }

Generated on Mon Feb 15 11:06:47 2010 for loon by  doxygen 1.3.9.1