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 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 }
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 = 0;
126 auto 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 if (pad)
132 dy = (pad->AbsPixeltoY(0) - pad->AbsPixeltoY(npixels))/(pl->GetY2() - pl->GetY1());
133 snprintf(params, nmax, "%f", dy);
134 obj->Execute("SetTextSize",params);
135 } else if (obj->InheritsFrom("TPave")) {
136 if (pad)
137 dy = (pad->AbsPixeltoY(0) - pad->AbsPixeltoY(npixels))/(pad->GetY2() - pad->GetY1());
138 snprintf(params, nmax, "%f", dy);
139 obj->Execute("SetTextSize",params);
140 } else {
141 snprintf(params, nmax, "%d", npixels);
142 obj->Execute("SetTextSizePixels", params);
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;
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
221void TGroupButton::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
222{
224 char quote = '"';
225 if (gROOT->ClassSaved(TGroupButton::Class()))
226 out<<" ";
227 else
228 out<<" TGroupButton *";
229
230 out<<"grbutton = 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, "grbutton", 0, 1001);
239 SaveLineAttributes(out, "grbutton", 1, 1, 1);
240 SaveTextAttributes(out, "grbutton", 22, 0, 1, 62, .75);
241
242 if (GetBorderSize() != 2)
243 out<<" grbutton->SetBorderSize("<<GetBorderSize()<<");"<<std::endl;
244
245 if (GetBorderMode() != 1)
246 out<<" grbutton->SetBorderMode("<<GetBorderMode()<<");"<<std::endl;
247
248 out<<" grbutton->Draw();"<<std::endl;
249
251 next(); //do not save first primitive
252
253 Int_t nprim = 0;
254 while (auto obj = next()) {
255 if (nprim++ == 0)
256 out<<" grbutton->cd();"<<std::endl;
257 obj->SavePrimitive(out, (Option_t *)next.GetOption());
258 }
259
260 if (ctxt.GetSaved() && (nprim > 0))
261 out<<" "<<ctxt.GetSaved()->GetName()<<"->cd();"<<std::endl;
262}
@ 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
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t button
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char y1
#define gROOT
Definition TROOT.h:406
#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:239
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:275
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:373
Create a Box.
Definition TBox.h:22
Double_t GetY1() const
Definition TBox.h:53
Double_t GetY2() const
Definition TBox.h:54
A TButton object is a user interface object.
Definition TButton.h:18
virtual const char * GetMethod() const
Definition TButton.h:37
void Draw(Option_t *option="") override
Draw this button with its current attributes.
Definition TButton.cxx:139
void SetName(const char *name) override
Definition TButton.h:49
void SetBorderMode(Short_t bordermode) override
Definition TButton.h:42
virtual void SetFraming(Bool_t f=kTRUE)
if framing is set, button will be highlighted
Definition TButton.cxx:315
The Canvas class.
Definition TCanvas.h:23
void Close(Option_t *option="") override
Close canvas.
Definition TCanvas.cxx:785
void FeedbackMode(Bool_t set)
Turn rubberband feedback mode on or off.
Definition TCanvas.cxx:1126
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.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
TGroupButton()
GroupButton default constructor.
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.
static TClass * Class()
virtual void ExecuteAction()
Execute action of this button.
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
~TGroupButton() override
GroupButton default destructor.
Option_t * GetOption() const
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:657
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Execute(const char *method, const char *params, Int_t *error=nullptr)
Execute method on this object with the given parameter string, e.g.
Definition TObject.cxx:359
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:525
The most important graphics class in the ROOT system.
Definition TPad.h:28
Short_t GetBorderMode() const override
Definition TPad.h:197
void SetBorderSize(Short_t bordersize) override
Definition TPad.h:323
Double_t fWNDC
Width of pad along X in Normalized Coordinates (NDC)
Definition TPad.h:66
Bool_t IsEditable() const override
Definition TPad.h:270
const char * GetTitle() const override
Returns title of object.
Definition TPad.h:259
TList * GetListOfPrimitives() const override
Definition TPad.h:243
Double_t fYlowNDC
Y bottom left corner of pad in NDC [0,1].
Definition TPad.h:63
void Update() override
Update pad.
Definition TPad.cxx:2882
Int_t YtoPixel(Double_t y) const override
Convert Y coordinate to pixel.
Definition TPad.cxx:7439
TVirtualPad * GetMother() const override
Definition TPad.h:257
void Modified(Bool_t flag=true) override
Mark pad modified Will be repainted when TCanvas::Update() will be called next time.
Definition TPad.cxx:7298
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TPad.cxx:1733
Short_t GetBorderSize() const override
Definition TPad.h:198
TCanvas * GetCanvas() const override
Definition TPad.h:260
Double_t fHNDC
Height of pad along Y in Normalized Coordinates (NDC)
Definition TPad.h:67
Double_t fXlowNDC
X bottom left corner of pad in NDC [0,1].
Definition TPad.h:62
TPad * fMother
! pointer to mother of the list
Definition TPad.h:105
const char * GetName() const override
Returns name of object.
Definition TPad.h:258
Base class for several text objects.
Definition TText.h:22
small helper class to store/restore gPad context in TPad methods
Definition TVirtualPad.h:61
auto GetSaved() const
Definition TVirtualPad.h:69
TLine * line