Logo ROOT   6.10/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 A TGroupButton object is a specialized TPad including possible list
38 of primitives used to build selections and options menus in a canvas.
39 */
40 
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// GroupButton default constructor.
44 
46 {
47  SetFraming();
48 }
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// GroupButton normal constructor.
52 
53 TGroupButton::TGroupButton(const char *groupname, const char *title, const char *method, Double_t x1, Double_t y1,Double_t x2, Double_t y2)
54  :TButton(title,method,x1,y1,x2,y2)
55 {
56  SetName((char*)groupname);
57  SetFraming();
58 }
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// GroupButton default destructor.
62 
64 {
65 }
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 /// Display Color Table in an attribute canvas.
69 
70 void TGroupButton::DisplayColorTable(const char *action, Double_t x0, Double_t y0, Double_t wc, Double_t hc)
71 {
72  TGroupButton *colorpad;
73  Int_t i, j;
74  Int_t color;
75  Double_t xlow, ylow, hs, ws;
76 
77  // draw color table buttons
78  hs = hc/5;
79  ws = wc/10;
80  char command[32];
81  for (i=0;i<10;i++) {
82  xlow = x0 + ws*i;
83  for (j=0;j<5;j++) {
84  ylow = y0 + hs*j;
85  color = 10*j + i + 1;
86  snprintf(command,32,"%s(%d)",action,10*j+i+1);
87  colorpad = new TGroupButton("Color","",command,xlow, ylow, xlow+0.9*ws, ylow+0.9*hs);
88  colorpad->SetFillColor(color);
89  colorpad->SetBorderSize(1);
90  if (i == 0 && j == 0) colorpad->SetBorderMode(-1);
91  colorpad->Draw();
92  }
93  }
94 }
95 
96 ////////////////////////////////////////////////////////////////////////////////
97 /// Execute action of this button.
98 ///
99 /// If an object has been selected before executing the APPLY button
100 /// in the control canvas, The member function and its parameters
101 /// for this object is executed via the interpreter.
102 
104 {
105  TVirtualPad *pad;
106  char line[128];
107  strlcpy(line,GetMethod(),128);
108  char *method = line;
109  if(!line[0]) return;
110  char *params = strchr(method,'(');
111  if (params) {
112  *params = 0;
113  params++;
114  char *end = strrchr(params,')');
115  if (end) *end = 0;
116  }
117  TDialogCanvas *canvas = (TDialogCanvas*)GetMother();
118  TObject *obj = canvas->GetRefObject();
119  if (!obj) return;
120  if (strcmp(method,"PIXELS")) {
121  obj->Execute(method,params);
122  } else {
124  Int_t npixels = Int_t((YtoPixel(0) - YtoPixel(1))*text->GetTextSize());
125  Double_t dy;
126  pad = gROOT->GetSelectedPad();
127  if (!params) return;
128  Int_t nmax = (Int_t)(params-method);
129  if (obj->InheritsFrom("TPaveLabel")) {
130  TBox *pl = (TBox*)obj;
131  dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY(npixels);
132  snprintf(params,nmax,"%f",dy/(pl->GetY2() - pl->GetY1()));
133  obj->Execute("SetTextSize",params);
134  } else {
135  if (obj->InheritsFrom("TPave")) {
136  dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY(npixels);
137  snprintf(params,nmax,"%f",dy/(pad->GetY2() - pad->GetY1()));
138  obj->Execute("SetTextSize",params);
139  } else {
140  snprintf(params,nmax,"%d",npixels);
141  obj->Execute("SetTextSizePixels",params);
142  }
143  }
144  }
145 }
146 
147 ////////////////////////////////////////////////////////////////////////////////
148 /// Execute action corresponding to one event.
149 ///
150 /// This member function is called when a Button object is clicked.
151 
153 {
154  if (fMother->IsEditable()) {
155  TPad::ExecuteEvent(event,px,py);
156  return;
157  }
158 
159  TCanvas *c = gPad->GetCanvas();
160  if (!c) return;
161  TIter next(c->GetListOfPrimitives());
162  TObject *obj;
163  TGroupButton *button;
164  TPad *pad;
165  TDialogCanvas *canvas;
166 
167  switch (event) {
168 
169  case kButton1Down:
170 
171  case kMouseMotion:
172 
173  break;
174 
175  case kButton1Motion:
176 
177  break;
178 
179  case kButton1Up:
180  //Clicked on APPLY button?
181  if (!strcasecmp(GetName(),"APPLY")) {
182  canvas = (TDialogCanvas*)GetMother();
183  if (!strcasecmp(GetTitle(),"CLOSE")) {
184  canvas->Close();
185  return;
186  }
187  pad = canvas->GetRefPad();
188  if (pad) pad->GetCanvas()->FeedbackMode(kFALSE);
189  canvas->Apply(GetTitle()); //just in case the apply button executes some code
190  if (pad) {
191  pad->Modified(kTRUE);
192  pad->Update();
193  }
194  break;
195  }
196  //Unset other buttons with same name
197  while ((obj = next())) {
198  if (obj == this) continue;
199  if (obj->InheritsFrom(TGroupButton::Class())) {
200  button = (TGroupButton*)obj;
201  if (!strcmp(button->GetName(),GetName())) {
202  if (button->GetBorderMode() < 0) {
203  button->SetBorderMode(1);
204  button->Modified();
205  }
206  }
207  }
208  }
209  //Set button on
210  SetBorderMode(-1);
211  Modified();
212  c->Modified();
213  gPad->Update();
214  break;
215  }
216 }
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 /// Save primitive as a C++ statement(s) on output stream out
220 
221 void TGroupButton::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
222 {
223  TPad *padsav = (TPad*)gPad;
224  char quote = '"';
225  if (gROOT->ClassSaved(TGroupButton::Class())) {
226  out<<" ";
227  } else {
228  out<<" TGroupButton *";
229  }
230  out<<"button = new TGroupButton("<<quote<<GetName()<<quote<<", "<<quote<<GetTitle()
231  <<quote<<","<<quote<<GetMethod()<<quote
232  <<","<<fXlowNDC
233  <<","<<fYlowNDC
234  <<","<<fXlowNDC+fWNDC
235  <<","<<fYlowNDC+fHNDC
236  <<");"<<std::endl;
237 
238  SaveFillAttributes(out,"button",0,1001);
239  SaveLineAttributes(out,"button",1,1,1);
240  SaveTextAttributes(out,"button",22,0,1,62,.75);
241 
242  if (GetBorderSize() != 2) {
243  out<<" button->SetBorderSize("<<GetBorderSize()<<");"<<std::endl;
244  }
245  if (GetBorderMode() != 1) {
246  out<<" button->SetBorderMode("<<GetBorderMode()<<");"<<std::endl;
247  }
248 
249  out<<" button->Draw();"<<std::endl;
250  out<<" button->cd();"<<std::endl;
251 
252  TIter next(GetListOfPrimitives());
253  TObject *obj = next(); //do not save first primitive
254 
255  while ((obj = next()))
256  obj->SavePrimitive(out, (Option_t *)next.GetOption());
257 
258  out<<" "<<padsav->GetName()<<"->cd();"<<std::endl;
259  padsav->cd();
260 }
void FeedbackMode(Bool_t set)
Turn rubberband feedback mode on or off.
Definition: TCanvas.cxx:1062
TList * GetListOfPrimitives() const
Definition: TPad.h:236
virtual Short_t GetBorderSize() const
Definition: TPad.h:197
TLine * line
TObject * GetRefObject() const
Definition: TDialogCanvas.h:37
virtual void SetBorderMode(Short_t bordermode)
Definition: TButton.h:43
const char Option_t
Definition: RtypesCore.h:62
Int_t YtoPixel(Double_t y) const
Definition: TPad.h:506
Create a Box.
Definition: TBox.h:24
#define gROOT
Definition: TROOT.h:375
virtual void Update()
Update pad.
Definition: TPad.cxx:2786
int Int_t
Definition: RtypesCore.h:41
Double_t GetY2() const
Definition: TBox.h:55
Option_t * GetOption() const
Definition: TCollection.h:155
TGroupButton()
GroupButton default constructor.
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
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:565
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:260
virtual Float_t GetTextSize() const
Return the text size.
Definition: TAttText.h:36
const char * GetTitle() const
Returns title of object.
Definition: TPad.h:252
Base class for several text objects.
Definition: TText.h:23
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:49
Double_t fYlowNDC
Y bottom left corner of pad in NDC [0,1].
Definition: TPad.h:62
virtual Double_t AbsPixeltoY(Int_t py)=0
virtual Double_t GetY2() const =0
TPad * fMother
! pointer to mother of the list
Definition: TPad.h:104
virtual const char * GetMethod() const
Definition: TButton.h:38
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TPad.cxx:1645
virtual void Apply(const char *action="")
Called when the APPLY button is executed.
virtual TVirtualPad * GetMother() const
Definition: TPad.h:250
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:561
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:347
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
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:284
virtual Bool_t IsEditable() const
Definition: TPad.h:263
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:436
virtual void SetName(const char *name)
Definition: TButton.h:50
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:232
The most important graphics class in the ROOT system.
Definition: TPad.h:29
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:19
TPad * GetRefPad() const
Definition: TDialogCanvas.h:38
virtual TCanvas * GetCanvas() const
Definition: TPad.h:253
virtual Double_t GetY1() const =0
const Bool_t kFALSE
Definition: RtypesCore.h:92
The Canvas class.
Definition: TCanvas.h:31
virtual void SetFraming(Bool_t f=1)
if framing is set, button will be highlighted
Definition: TButton.cxx:334
static const double x1[5]
#define ClassImp(name)
Definition: Rtypes.h:336
double Double_t
Definition: RtypesCore.h:55
TText * text
A canvas specialized to set attributes.
Definition: TDialogCanvas.h:19
virtual ~TGroupButton()
GroupButton default destructor.
Double_t fXlowNDC
X bottom left corner of pad in NDC [0,1].
Definition: TPad.h:61
Mother of all ROOT objects.
Definition: TObject.h:37
const char * GetName() const
Returns name of object.
Definition: TPad.h:251
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.
virtual Short_t GetBorderMode() const
Definition: TPad.h:196
void Close(Option_t *option="")
Close canvas.
Definition: TCanvas.cxx:749
Double_t fHNDC
Height of pad along Y in NDC.
Definition: TPad.h:66
#define snprintf
Definition: civetweb.c:822
#define gPad
Definition: TVirtualPad.h:284
Double_t GetY1() const
Definition: TBox.h:54
virtual void SetBorderSize(Short_t bordersize)
Definition: TPad.h:314
const Bool_t kTRUE
Definition: RtypesCore.h:91
void Modified(Bool_t flag=1)
Definition: TPad.h:410
Double_t fWNDC
Width of pad along X in NDC.
Definition: TPad.h:65
A specialized TButton used in a group of Buttons.
Definition: TGroupButton.h:18
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TObject.cxx:657