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