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
21#include <cstdio>
22#include <cstring>
23#include <iostream>
24
25
26
27/** \class TGroupButton
28\ingroup gpad
29
30A specialized TButton used in a group of Buttons.
31When a button from a group of TGroupButtons is selected, all other buttons
32from the group with the same name are disabled.
33
34For examples of use of TGroupButton objects, see:
35AttFillCanvas, TAttLineCanvas, TAttTextCanvas and TAttMarkerCanvas.
36
37A TGroupButton object is a specialized TPad including possible list
38of primitives used to build selections and options menus in a canvas.
39*/
40
41
42////////////////////////////////////////////////////////////////////////////////
43/// GroupButton default constructor.
44
49
50////////////////////////////////////////////////////////////////////////////////
51/// GroupButton normal constructor.
52
53TGroupButton::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(groupname);
57 SetFraming();
58}
59
60////////////////////////////////////////////////////////////////////////////////
61/// GroupButton default destructor.
62
66
67////////////////////////////////////////////////////////////////////////////////
68/// Display Color Table in an attribute canvas.
69
70void 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 char line[128];
106 strlcpy(line,GetMethod(),128);
107 char *method = line;
108 if(!line[0]) return;
109 char *params = strchr(method,'(');
110 if (params) {
111 *params = 0;
112 params++;
113 char *end = strrchr(params,')');
114 if (end) *end = 0;
115 }
117 TObject *obj = canvas->GetRefObject();
118 if (!obj) return;
119 if (strcmp(method,"PIXELS")) {
120 obj->Execute(method, params);
121 } else {
123 Int_t npixels = Int_t((YtoPixel(0) - YtoPixel(1))*text->GetTextSize());
124 Double_t dy = 0;
125 auto pad = gROOT->GetSelectedPad();
126 if (!params) return;
127 Int_t nmax = (Int_t)(params - method);
128 if (obj->InheritsFrom("TPaveLabel")) {
129 TBox *pl = (TBox*)obj;
130 if (pad)
131 dy = (pad->AbsPixeltoY(0) - pad->AbsPixeltoY(npixels))/(pl->GetY2() - pl->GetY1());
132 snprintf(params, nmax, "%f", dy);
133 obj->Execute("SetTextSize",params);
134 } else if (obj->InheritsFrom("TPave")) {
135 if (pad)
136 dy = (pad->AbsPixeltoY(0) - pad->AbsPixeltoY(npixels))/(pad->GetY2() - pad->GetY1());
137 snprintf(params, nmax, "%f", dy);
138 obj->Execute("SetTextSize",params);
139 } else {
140 snprintf(params, nmax, "%d", npixels);
141 obj->Execute("SetTextSizePixels", params);
142 }
143 }
144}
145
146////////////////////////////////////////////////////////////////////////////////
147/// Execute action corresponding to one event.
148///
149/// This member function is called when a Button object is clicked.
150
152{
154 return;
155
156 if (IsEditable()) {
158 return;
159 }
160
161 Bool_t is_apply = !strcasecmp(GetName(),"APPLY");
162
163 switch (event) {
164
165 case kMouseMotion:
166
167 break;
168
169 case kButton1Motion:
170
171 break;
172
173 case kButton1Down:
174 if (is_apply) {
175 SetBorderMode(-1);
176 Modified();
177 Update();
178 }
179 break;
180
181 case kButton1Up: {
182 if (is_apply) {
183 if (!strcasecmp(GetTitle(),"CLOSE")) {
184 GetCanvas()->Close();
185 return;
186 }
187 auto canvas = static_cast<TDialogCanvas *>(GetCanvas());
188 canvas->Apply(GetTitle()); //just in case the apply button executes some code
189 if (auto pad = canvas->GetRefPad()) {
190 pad->Modified(kTRUE);
191 pad->Update();
192 }
193 SetBorderMode(1);
194 Modified();
195 Update();
196 break;
197 }
198
200 //Set only this button on
201 while (auto obj = next()) {
202 if (auto btn = dynamic_cast<TGroupButton *>(obj)) {
203 if (!strcmp(btn->GetName(), GetName())) {
204 btn->SetBorderMode(btn == this ? -1 : 1);
205 btn->Modified();
206 }
207 }
208 }
209 GetCanvas()->Modified();
210 GetCanvas()->Update();
211 break;
212 }
213 }
214}
215
216////////////////////////////////////////////////////////////////////////////////
217/// Save primitive as a C++ statement(s) on output stream out
218
219void TGroupButton::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
220{
222
223 SavePrimitiveConstructor(out, Class(), "grbutton",
224 TString::Format("\"%s\", \"%s\", \"%s\", %g, %g, %g, %g",
225 TString(GetName()).ReplaceSpecialCppChars().Data(),
226 TString(GetTitle()).ReplaceSpecialCppChars().Data(),
227 TString(GetMethod()).ReplaceSpecialCppChars().Data(), fXlowNDC, fYlowNDC,
229
230 SaveFillAttributes(out, "grbutton", -1, -1);
231 SaveLineAttributes(out, "grbutton", 1, 1, 1);
232 SaveTextAttributes(out, "grbutton", 22, 0, 1, 62, .75);
233
234 if (GetBorderSize() != 2)
235 out << " grbutton->SetBorderSize(" << GetBorderSize() << ");\n";
236
237 if (GetBorderMode() != 1)
238 out << " grbutton->SetBorderMode(" << GetBorderMode() << ");\n";
239
240 if (GetFraming())
241 out << " grbutton->SetFraming();\n";
242 if (IsEditable())
243 out << " grbutton->SetEditable(kTRUE);\n";
244
245
246 out << " grbutton->Draw();\n";
247
249 next(); // do not save first primitive
250
251 Int_t nprim = 0;
252 while (auto obj = next()) {
253 if (nprim++ == 0)
254 out << " grbutton->cd();\n";
255 obj->SavePrimitive(out, next.GetOption());
256 }
257
258 if (ctxt.GetSaved() && (nprim > 0))
259 out << " " << ctxt.GetSaved()->GetName() << "->cd();\n";
260}
@ kMouseMotion
Definition Buttons.h:23
@ kButton1Motion
Definition Buttons.h:20
@ kButton1Up
Definition Buttons.h:19
@ kButton1Down
Definition Buttons.h:17
cudaEvent_t event
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
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 text
Option_t Option_t TPoint TPoint const char y1
#define gROOT
Definition TROOT.h:417
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:40
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:240
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:289
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:399
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:38
void Draw(Option_t *option="") override
Draw this button with its current attributes.
Definition TButton.cxx:145
Bool_t GetFraming() const override
Definition TButton.h:45
void SetName(const char *name) override
Definition TButton.h:50
void SetBorderMode(Short_t bordermode) override
Definition TButton.h:43
virtual void SetFraming(Bool_t f=kTRUE)
if framing is set, button will be highlighted
Definition TButton.cxx:324
void Close(Option_t *option="") override
Close canvas.
Definition TCanvas.cxx:814
void Update() override
Update canvas pad buffers.
Definition TCanvas.cxx:2543
A canvas specialized to set attributes.
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:789
Mother of all ROOT objects.
Definition TObject.h:42
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:377
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:548
static void SavePrimitiveConstructor(std::ostream &out, TClass *cl, const char *variable_name, const char *constructor_agrs="", Bool_t empty_line=kTRUE)
Save object constructor in the output stream "out".
Definition TObject.cxx:776
Short_t GetBorderMode() const override
Definition TPad.h:210
void SetBorderSize(Short_t bordersize) override
Definition TPad.h:345
Double_t fWNDC
Width of pad along X in Normalized Coordinates (NDC)
Definition TPad.h:72
Bool_t IsEditable() const override
Definition TPad.h:286
const char * GetTitle() const override
Returns title of object.
Definition TPad.h:275
TList * GetListOfPrimitives() const override
Definition TPad.h:259
Double_t fYlowNDC
Y bottom left corner of pad in NDC [0,1].
Definition TPad.h:69
void Update() override
Update pad.
Definition TPad.cxx:2770
Int_t YtoPixel(Double_t y) const override
Convert Y coordinate to pixel.
Definition TPad.cxx:7445
TVirtualPad * GetMother() const override
Definition TPad.h:273
void Modified(Bool_t flag=true) override
Mark pad modified Will be repainted when TCanvas::Update() will be called next time.
Definition TPad.cxx:7277
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TPad.cxx:2005
Short_t GetBorderSize() const override
Definition TPad.h:211
TCanvas * GetCanvas() const override
Definition TPad.h:276
Double_t fHNDC
Height of pad along Y in Normalized Coordinates (NDC)
Definition TPad.h:73
Double_t fXlowNDC
X bottom left corner of pad in NDC [0,1].
Definition TPad.h:68
const char * GetName() const override
Returns name of object.
Definition TPad.h:274
Basic string class.
Definition TString.h:137
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2460
Base class for several text objects.
Definition TText.h:22
small helper class to store/restore gPad context in TPad methods
Definition TVirtualPad.h:58
auto GetSaved() const
Definition TVirtualPad.h:66
TLine * line
R__ALWAYS_INLINE bool HasBeenDeleted(const TObject *obj)
Check if the TObject's memory has been deleted.
Definition TObject.h:409