]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPainterColorSlider.cxx
Load pythia libraries.
[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 //  fEntryMin->SetFormat(TGNumberFormat::kNESRealOne);
80 //  fEntryMax->SetFormat(TGNumberFormat::kNESRealOne);
81   
82   AddFrame(fAutoButton,new TGLayoutHints(kLHintsExpandX,0,0,topBorder,0));
83   
84   fAutoButton->Connect("Clicked()","AliMUONPainterColorSlider",this,"DataRangeAutoRequested()");
85   
86   AddFrame(fLockButton,new TGLayoutHints(kLHintsExpandX,0,0,topBorder,0));
87   
88   fLockButton->Connect("Clicked()","AliMUONPainterColorSlider",this,"LockButtonWasClicked()");
89   
90   fEntryMax->Connect("ValueSet(Long_t)","AliMUONPainterColorSlider",this,"DataRangeWasChanged(Double_t*)");
91   fEntryMin->Connect("ValueSet(Long_t)","AliMUONPainterColorSlider",this,"DataRangeWasChanged(Double_t*)");
92 }
93
94 //_____________________________________________________________________________
95 AliMUONPainterColorSlider::~AliMUONPainterColorSlider()
96 {
97   /// dtor
98 }
99
100 //_____________________________________________________________________________
101 void 
102 AliMUONPainterColorSlider::DataRangeAutoRequested()
103 {
104   /// Signal that the "Auto" button was clicked
105   AliDebug(1,"");
106   Emit("DataRangeAutoRequested()");
107 }
108
109 //_____________________________________________________________________________
110 void 
111 AliMUONPainterColorSlider::DataRangeWasChanged(Double_t*)
112 {
113   /// Data range was changed
114   
115   Double_t values[] = { fEntryMin->GetNumber(), fEntryMax->GetNumber() };
116   
117   Long_t param[] = { (Long_t)values };
118   
119   AliDebug(1,Form("double min %e max %e",values[0],values[1]));
120   
121   Emit("DataRangeWasChanged(Double_t*)",param);
122 }
123
124 //_____________________________________________________________________________
125 Bool_t 
126 AliMUONPainterColorSlider::IsLocked() const
127 {
128   /// Whether our range is locked or not
129
130   return (fLockButton->GetString() == "Unlock"); // if we can unlock it means we are locked...
131 }
132
133 //_____________________________________________________________________________
134 void 
135 AliMUONPainterColorSlider::LockButtonWasClicked()
136 {
137   /// Lock (toggle button) was clicked
138   
139   if ( IsLocked() )
140   {
141     // unlock it
142     fLockButton->SetText("Lock");
143     fEntryMin->SetState(kTRUE);
144     fEntryMax->SetState(kTRUE);
145     fAutoButton->SetEnabled(kTRUE);
146   }
147   else
148   {
149     // lock it
150     fLockButton->SetText("Unlock");
151     fEntryMin->SetState(kFALSE);
152     fEntryMax->SetState(kFALSE);
153     fAutoButton->SetEnabled(kFALSE);
154   }
155 }
156
157 //_____________________________________________________________________________
158 void 
159 AliMUONPainterColorSlider::SetRange(Double_t min, Double_t max, Bool_t emit)
160 {
161   /// Set the data range
162   
163   AliDebug(1,Form("min %e max %e emit %d",min,max,emit));
164   
165   if ( !IsLocked() ) 
166   {
167     fMin = min;
168     fMax = max;
169   
170     fEntryMin->SetNumber(fMin);
171     fEntryMax->SetNumber(fMax);
172   }
173   
174   if ( emit ) 
175   {
176     DataRangeWasChanged(0x0);
177   }
178 }
179