ROOT  6.06/09
Reference Guide
TGroupButton.cxx
Go to the documentation of this file.
1 // @(#)root/gpad:$Id: faa839c41a9482cbcb403b991070b15d606c9137 $
2 // Author: Rene Brun 01/07/96
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "Riostream.h"
13 #include "TROOT.h"
14 #include "TBox.h"
15 #include "TGroupButton.h"
16 #include "TVirtualX.h"
17 #include "TDialogCanvas.h"
18 #include "TCanvas.h"
19 #include "TText.h"
20 #include "TInterpreter.h"
21 #include "TTimer.h"
22 #include <string.h>
23 
25 
26 
27 /** \class TGroupButton
28 \ingroup gpad
29 
30 A specialized TButton used in a group of Buttons.
31 When a button from a group of TGroupButtons is selected, all other buttons
32 from the group with the same name are disabled.
33 
34 For examples of use of TGroupButton objects, see:
35 AttFillCanvas, TAttLineCanvas, TAttTextCanvas and TAttMarkerCanvas.
36 */
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// GroupButton default constructor.
40 
42 {
43  SetFraming();
44 }
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// GroupButton normal constructor.
48 
49 TGroupButton::TGroupButton(const char *groupname, const char *title, const char *method, Double_t x1, Double_t y1,Double_t x2, Double_t y2)
50  :TButton(title,method,x1,y1,x2,y2)
51 {
52  SetName((char*)groupname);
53  SetFraming();
54 }
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// GroupButton default destructor.
58 
60 {
61 }
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 /// Display Color Table in an attribute canvas.
65 
66 void TGroupButton::DisplayColorTable(const char *action, Double_t x0, Double_t y0, Double_t wc, Double_t hc)
67 {
68  TGroupButton *colorpad;
69  Int_t i, j;
70  Int_t color;
71  Double_t xlow, ylow, hs, ws;
72 
73  // draw colortable buttons
74  hs = hc/5;
75  ws = wc/10;
76  char command[32];
77  for (i=0;i<10;i++) {
78  xlow = x0 + ws*i;
79  for (j=0;j<5;j++) {
80  ylow = y0 + hs*j;
81  color = 10*j + i + 1;
82  snprintf(command,32,"%s(%d)",action,10*j+i+1);
83  colorpad = new TGroupButton("Color","",command,xlow, ylow, xlow+0.9*ws, ylow+0.9*hs);
84  colorpad->SetFillColor(color);
85  colorpad->SetBorderSize(1);
86  if (i == 0 && j == 0) colorpad->SetBorderMode(-1);
87  colorpad->Draw();
88  }
89  }
90 }
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// Execute action of this button.
94 ///
95 /// If an object has been selected before executing the APPLY button
96 /// in the control canvas, The member function and its parameters
97 /// for this object is executed via the interpreter.
98 
100 {
101  TVirtualPad *pad;
102  char line[128];
103  strlcpy(line,GetMethod(),128);
104  char *method = line;
105  if(!line[0]) return;
106  char *params = strchr(method,'(');
107  if (params) {
108  *params = 0;
109  params++;
110  char *end = strrchr(params,')');
111  if (end) *end = 0;
112  }
113  TDialogCanvas *canvas = (TDialogCanvas*)GetMother();
114  TObject *obj = canvas->GetRefObject();
115  if (!obj) return;
116  if (strcmp(method,"PIXELS")) {
117  obj->Execute(method,params);
118  } else {
120  Int_t npixels = Int_t((YtoPixel(0) - YtoPixel(1))*text->GetTextSize());
121  Double_t dy;
122  pad = gROOT->GetSelectedPad();
123  if (!params) return;
124  Int_t nmax = (Int_t)(params-method);
125  if (obj->InheritsFrom("TPaveLabel")) {
126  TBox *pl = (TBox*)obj;
127  dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY(npixels);
128  snprintf(params,nmax,"%f",dy/(pl->GetY2() - pl->GetY1()));
129  obj->Execute("SetTextSize",params);
130  } else {
131  if (obj->InheritsFrom("TPave")) {
132  dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY(npixels);
133  snprintf(params,nmax,"%f",dy/(pad->GetY2() - pad->GetY1()));
134  obj->Execute("SetTextSize",params);
135  } else {
136  snprintf(params,nmax,"%d",npixels);
137  obj->Execute("SetTextSizePixels",params);
138  }
139  }
140  }
141 }
142 
143 ////////////////////////////////////////////////////////////////////////////////
144 /// Execute action corresponding to one event.
145 ///
146 /// This member function is called when a Button object is clicked.
147 
149 {
150  if (fMother->IsEditable()) {
151  TPad::ExecuteEvent(event,px,py);
152  return;
153  }
154 
155  TCanvas *c = gPad->GetCanvas();
156  if (!c) return;
158  TObject *obj;
159  TGroupButton *button;
160  TPad *pad;
161  TDialogCanvas *canvas;
162 
163  switch (event) {
164 
165  case kButton1Down:
166 
167  case kMouseMotion:
168 
169  break;
170 
171  case kButton1Motion:
172 
173  break;
174 
175  case kButton1Up:
176  //Clicked on APPLY button?
177  if (!strcasecmp(GetName(),"APPLY")) {
178  canvas = (TDialogCanvas*)GetMother();
179  if (!strcasecmp(GetTitle(),"CLOSE")) {
180  canvas->Close();
181  return;
182  }
183  pad = canvas->GetRefPad();
184  if (pad) pad->GetCanvas()->FeedbackMode(kFALSE);
185  canvas->Apply(GetTitle()); //just in case the apply button executes some code
186  if (pad) {
187  pad->Modified(kTRUE);
188  pad->Update();
189  }
190  break;
191  }
192  //Unset other buttons with same name
193  while ((obj = next())) {
194  if (obj == this) continue;
195  if (obj->InheritsFrom(TGroupButton::Class())) {
196  button = (TGroupButton*)obj;
197  if (!strcmp(button->GetName(),GetName())) {
198  if (button->GetBorderMode() < 0) {
199  button->SetBorderMode(1);
200  button->Modified();
201  }
202  }
203  }
204  }
205  //Set button on
206  SetBorderMode(-1);
207  Modified();
208  c->Modified();
209  gPad->Update();
210  break;
211  }
212 }
213 
214 ////////////////////////////////////////////////////////////////////////////////
215 /// Save primitive as a C++ statement(s) on output stream out
216 
217 void TGroupButton::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
218 {
219  TPad *padsav = (TPad*)gPad;
220  char quote = '"';
221  if (gROOT->ClassSaved(TGroupButton::Class())) {
222  out<<" ";
223  } else {
224  out<<" TGroupButton *";
225  }
226  out<<"button = new TGroupButton("<<quote<<GetName()<<quote<<", "<<quote<<GetTitle()
227  <<quote<<","<<quote<<GetMethod()<<quote
228  <<","<<fXlowNDC
229  <<","<<fYlowNDC
230  <<","<<fXlowNDC+fWNDC
231  <<","<<fYlowNDC+fHNDC
232  <<");"<<std::endl;
233 
234  SaveFillAttributes(out,"button",0,1001);
235  SaveLineAttributes(out,"button",1,1,1);
236  SaveTextAttributes(out,"button",22,0,1,62,.75);
237 
238  if (GetBorderSize() != 2) {
239  out<<" button->SetBorderSize("<<GetBorderSize()<<");"<<std::endl;
240  }
241  if (GetBorderMode() != 1) {
242  out<<" button->SetBorderMode("<<GetBorderMode()<<");"<<std::endl;
243  }
244 
245  out<<" button->Draw();"<<std::endl;
246  out<<" button->cd();"<<std::endl;
247 
249  TObject *obj = next(); //do not save first primitive
250 
251  while ((obj = next()))
252  obj->SavePrimitive(out, (Option_t *)next.GetOption());
253 
254  out<<" "<<padsav->GetName()<<"->cd();"<<std::endl;
255  padsav->cd();
256 }
void FeedbackMode(Bool_t set)
Turn rubberband feedback mode on or off.
Definition: TCanvas.cxx:1039
TPad * GetRefPad() const
Definition: TDialogCanvas.h:50
virtual const char * GetMethod() const
Definition: TButton.h:51
virtual TCanvas * GetCanvas() const
Definition: TPad.h:257
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:487
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
TLine * line
virtual void SetBorderMode(Short_t bordermode)
Definition: TButton.h:56
const char Option_t
Definition: RtypesCore.h:62
Create a Box.
Definition: TBox.h:44
virtual Float_t GetTextSize() const
Definition: TAttText.h:50
#define gROOT
Definition: TROOT.h:340
virtual void Update()
Update pad.
Definition: TPad.cxx:2725
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual Short_t GetBorderMode() const
Definition: TPad.h:200
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
TObject * GetRefObject() const
Definition: TDialogCanvas.h:49
virtual void Draw(Option_t *option="")
Draw this button with its current attributes.
Definition: TButton.cxx:139
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:514
static const double x2[5]
void Class()
Definition: Class.C:29
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition: TAttLine.cxx:257
Base class for several text objects.
Definition: TText.h:42
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:59
char * out
Definition: TBase64.cxx:29
Double_t fYlowNDC
Definition: TPad.h:79
virtual Double_t AbsPixeltoY(Int_t py)=0
const char * GetName() const
Returns name of object.
Definition: TPad.h:255
virtual Double_t GetY2() const =0
TPad * fMother
Definition: TPad.h:121
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TPad.cxx:1587
virtual void Apply(const char *action="")
Called when the APPLY button is executed.
virtual void SaveTextAttributes(std::ostream &out, const char *name, Int_t alidef=12, Float_t angdef=0, Int_t coldef=1, Int_t fondef=61, Float_t sizdef=1)
Save text attributes as C++ statement(s) on output stream out.
Definition: TAttText.cxx:344
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
virtual void ExecuteAction()
Execute action of this button.
virtual void Execute(const char *method, const char *params, Int_t *error=0)
Execute method on this object with the given parameter string, e.g.
Definition: TObject.cxx:335
virtual void SetName(const char *name)
Definition: TButton.h:63
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
Save fill attributes as C++ statement(s) on output stream out.
Definition: TAttFill.cxx:229
The most important graphics class in the ROOT system.
Definition: TPad.h:46
virtual Short_t GetBorderSize() const
Definition: TPad.h:201
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
A TButton object is a user interface object.
Definition: TButton.h:32
virtual TVirtualPad * GetMother() const
Definition: TPad.h:254
virtual Double_t GetY1() const =0
const char * GetTitle() const
Returns title of object.
Definition: TPad.h:256
Option_t * GetOption() const
Definition: TCollection.h:160
The Canvas class.
Definition: TCanvas.h:48
virtual void SetFraming(Bool_t f=1)
if framing is set, button will be highlighted
Definition: TButton.cxx:320
static const double x1[5]
#define ClassImp(name)
Definition: Rtypes.h:279
double Double_t
Definition: RtypesCore.h:55
TText * text
virtual Bool_t IsEditable() const
Definition: TPad.h:267
A canvas specialized to set attributes.
Definition: TDialogCanvas.h:31
virtual ~TGroupButton()
GroupButton default destructor.
Double_t fXlowNDC
Definition: TPad.h:78
Mother of all ROOT objects.
Definition: TObject.h:58
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:556
TList * GetListOfPrimitives() const
Definition: TPad.h:240
Int_t YtoPixel(Double_t y) const
Definition: TPad.h:503
virtual void DisplayColorTable(const char *action, Double_t x0, Double_t y0, Double_t wc, Double_t hc)
Display Color Table in an attribute canvas.
Double_t GetY1() const
Definition: TBox.h:74
void Close(Option_t *option="")
Close canvas.
Definition: TCanvas.cxx:729
Double_t fHNDC
Definition: TPad.h:83
#define gPad
Definition: TVirtualPad.h:288
virtual void SetBorderSize(Short_t bordersize)
Definition: TPad.h:317
Double_t GetY2() const
Definition: TBox.h:75
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
void Modified(Bool_t flag=1)
Definition: TPad.h:407
Double_t fWNDC
Definition: TPad.h:82
A specialized TButton used in a group of Buttons.
Definition: TGroupButton.h:34
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TObject.cxx:702