]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPainterColorSlider.cxx
Fix some coverity compilation warnings (-Wunused-but-set-variable)
[u/mrichter/AliRoot.git] / MUON / AliMUONPainterColorSlider.cxx
1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 *                                                                        *
4 * Author: The ALICE Off-line Project.                                    *
5 * Contributors are mentioned in the code where appropriate.              *
6 *                                                                        *
7 * Permission to use, copy, modify and distribute this software and its   *
8 * documentation strictly for non-commercial purposes is hereby granted   *
9 * without fee, provided that the above copyright notice appears in all   *
10 * copies and that both the copyright notice and this permission notice   *
11 * appear in the supporting documentation. The authors make no claims     *
12 * about the suitability of this software for any purpose. It is          *
13 * provided "as is" without express or implied warranty.                  *
14 **************************************************************************/
15
16 // $Id$
17
18 #include "AliMUONPainterColorSlider.h"
19 #include "AliMUONPainterHelper.h"
20 #include "AliLog.h"
21 #include <TGNumberEntry.h>
22 #include <TGButton.h>
23 #include <TMath.h>
24
25 ///\class AliMUONPainterColorSlider
26 ///
27 /// A painter color palette
28 ///
29 ///\author Laurent Aphecetche, Subatech
30
31 ///\cond CLASSIMP
32 ClassImp(AliMUONPainterColorSlider)
33 ///\endcond
34
35 //_____________________________________________________________________________
36 AliMUONPainterColorSlider::AliMUONPainterColorSlider(const TGWindow* p, 
37                                                      UInt_t w, UInt_t h)
38 : TGCompositeFrame(p,w,h,kVerticalFrame),
39   fEntryMin(0x0),
40   fEntryMax(0x0),
41   fMin(FLT_MAX),
42   fMax(-FLT_MAX),
43   fAutoButton(new TGTextButton(this,"Auto")),
44   fLockButton(new TGTextButton(this,"Lock"))
45 {
46     /// ctor
47     Int_t ndivisions(20);
48   
49     Int_t hsize = (h-100)/(ndivisions+2);
50   Int_t topBorder(5);
51   
52   Double_t min(0.0);
53   Double_t max(1.0);
54   
55   Double_t step = (max-min)/ndivisions;
56   
57   for ( Int_t i = -1; i < ndivisions+1; ++i ) 
58   {
59     Double_t value = max - (min + step*i);
60     
61     Int_t color = AliMUONPainterHelper::Instance()->ColorFromValue(value,
62                                                                    min,max);
63     Pixel_t pixel = gVirtualX->GetPixel(color);
64     TGVerticalFrame* frame = new TGVerticalFrame(this,w,hsize,kFixedSize,pixel);
65     
66     AddFrame(frame,new TGLayoutHints(kLHintsExpandX,0,0,topBorder,0));
67     
68     topBorder = 0;
69   }
70   
71   fEntryMax = new TGNumberEntry(this);
72   
73   AddFrame(fEntryMax,new TGLayoutHints(kLHintsExpandX,0,0,topBorder,0));
74     
75   fEntryMin = new TGNumberEntry(this);
76   
77   AddFrame(fEntryMin,new TGLayoutHints(kLHintsExpandX,0,0,topBorder,0));
78   
79   AddFrame(fAutoButton,new TGLayoutHints(kLHintsExpandX,0,0,topBorder,0));
80   
81   fAutoButton->Connect("Clicked()","AliMUONPainterColorSlider",this,"DataRangeAutoRequested()");
82   
83   AddFrame(fLockButton,new TGLayoutHints(kLHintsExpandX,0,0,topBorder,0));
84   
85   fLockButton->Connect("Clicked()","AliMUONPainterColorSlider",this,"LockButtonWasClicked()");
86   
87   fEntryMax->Connect("ValueSet(Long_t)","AliMUONPainterColorSlider",this,"DataRangeWasChanged(Double_t*)");
88   fEntryMin->Connect("ValueSet(Long_t)","AliMUONPainterColorSlider",this,"DataRangeWasChanged(Double_t*)");
89 }
90
91 //_____________________________________________________________________________
92 AliMUONPainterColorSlider::~AliMUONPainterColorSlider()
93 {
94   /// dtor
95 }
96
97 //_____________________________________________________________________________
98 void 
99 AliMUONPainterColorSlider::DataRangeAutoRequested()
100 {
101   /// Signal that the "Auto" button was clicked
102   AliDebug(1,"");
103   Emit("DataRangeAutoRequested()");
104 }
105
106 //_____________________________________________________________________________
107 void 
108 AliMUONPainterColorSlider::DataRangeWasChanged(Double_t*)
109 {
110   /// Data range was changed
111   
112   Double_t values[] = { fEntryMin->GetNumber(), fEntryMax->GetNumber() };
113   
114   Long_t param[] = { (Long_t)values };
115   
116   AliDebug(1,Form("double min %e max %e",values[0],values[1]));
117   
118   Emit("DataRangeWasChanged(Double_t*)",param);
119 }
120
121 //_____________________________________________________________________________
122 Bool_t 
123 AliMUONPainterColorSlider::IsLocked() const
124 {
125   /// Whether our range is locked or not
126
127   return (fLockButton->GetString() == "Unlock"); // if we can unlock it means we are locked...
128 }
129
130 //_____________________________________________________________________________
131 void 
132 AliMUONPainterColorSlider::LockButtonWasClicked()
133 {
134   /// Lock (toggle button) was clicked
135   
136   if ( IsLocked() )
137   {
138     // unlock it
139     fLockButton->SetText("Lock");
140     fEntryMin->SetState(kTRUE);
141     fEntryMax->SetState(kTRUE);
142     fAutoButton->SetEnabled(kTRUE);
143   }
144   else
145   {
146     // lock it
147     fLockButton->SetText("Unlock");
148     fEntryMin->SetState(kFALSE);
149     fEntryMax->SetState(kFALSE);
150     fAutoButton->SetEnabled(kFALSE);
151   }
152 }
153
154 //_____________________________________________________________________________
155 void 
156 AliMUONPainterColorSlider::SetRange(Double_t min, Double_t max, Bool_t emit)
157 {
158   /// Set the data range
159   
160   AliDebug(1,Form("min %e max %e emit %d",min,max,emit));
161   
162   if ( !IsLocked() ) 
163   {
164     fMin = min;
165     fMax = max;
166   
167     fEntryMin->SetNumber(fMin);
168     fEntryMax->SetNumber(fMax);
169   }
170   
171   if ( emit ) 
172   {
173     DataRangeWasChanged(0x0);
174   }
175 }
176