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
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((char*)groupname);
57 SetFraming();
58}
59
60////////////////////////////////////////////////////////////////////////////////
61/// GroupButton default destructor.
62
66
67////////////////////////////////////////////////////////////////////////////////
68/// Display Color Table in an attribute canvas.
69
71{
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{
153 if (fMother->IsEditable()) {
154 TPad::ExecuteEvent(event,px,py);
155 return;
156 }
157
158 TCanvas *c = gPad->GetCanvas();
159 if (!c) return;
160 TIter next(c->GetListOfPrimitives());
161 TObject *obj;
163 TPad *pad;
164 TDialogCanvas *canvas;
165
166 switch (event) {
167
168 case kButton1Down:
169
170 case kMouseMotion:
171
172 break;
173
174 case kButton1Motion:
175
176 break;
177
178 case kButton1Up:
179 //Clicked on APPLY button?
180 if (!strcasecmp(GetName(),"APPLY")) {
181 canvas = (TDialogCanvas*)GetMother();
182 if (!strcasecmp(GetTitle(),"CLOSE")) {
183 canvas->Close();
184 return;
185 }
186 pad = canvas->GetRefPad();
187 if (pad) pad->GetCanvas()->FeedbackMode(kFALSE);
188 canvas->Apply(GetTitle()); //just in case the apply button executes some code
189 if (pad) {
190 pad->Modified(kTRUE);
191 pad->Update();
192 }
193 break;
194 }
195 //Unset other buttons with same name
196 while ((obj = next())) {
197 if (obj == this) continue;
198 if (obj->InheritsFrom(TGroupButton::Class())) {
199 button = (TGroupButton*)obj;
200 if (!strcmp(button->GetName(),GetName())) {
201 if (button->GetBorderMode() < 0) {
202 button->SetBorderMode(1);
203 button->Modified();
204 }
205 }
206 }
207 }
208 //Set button on
209 SetBorderMode(-1);
210 Modified();
211 c->Modified();
212 gPad->Update();
213 break;
214 }
215}
216
217////////////////////////////////////////////////////////////////////////////////
218/// Save primitive as a C++ statement(s) on output stream out
219
220void TGroupButton::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
221{
223
224 SavePrimitiveConstructor(out, Class(), "grbutton",
225 TString::Format("\"%s\", \"%s\", \"%s\", %g, %g, %g, %g",
226 TString(GetName()).ReplaceSpecialCppChars().Data(),
227 TString(GetTitle()).ReplaceSpecialCppChars().Data(),
228 TString(GetMethod()).ReplaceSpecialCppChars().Data(), fXlowNDC, fYlowNDC,
230
231 SaveFillAttributes(out, "grbutton", 0, 1001);
232 SaveLineAttributes(out, "grbutton", 1, 1, 1);
233 SaveTextAttributes(out, "grbutton", 22, 0, 1, 62, .75);
234
235 if (GetBorderSize() != 2)
236 out << " grbutton->SetBorderSize(" << GetBorderSize() << ");\n";
237
238 if (GetBorderMode() != 1)
239 out << " grbutton->SetBorderMode(" << GetBorderMode() << ");\n";
240
241 out << " grbutton->Draw();\n";
242
244 next(); // do not save first primitive
245
246 Int_t nprim = 0;
247 while (auto obj = next()) {
248 if (nprim++ == 0)
249 out << " grbutton->cd();\n";
250 obj->SavePrimitive(out, next.GetOption());
251 }
252
253 if (ctxt.GetSaved() && (nprim > 0))
254 out << " " << ctxt.GetSaved()->GetName() << "->cd();\n";
255}
@ 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
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:411
#define gPad
#define snprintf
Definition civetweb.c:1579
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:238
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:274
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:372
Create a Box.
Definition TBox.h:22
A TButton object is a user interface object.
Definition TButton.h:18
virtual const char * GetMethod() const
Definition TButton.h:38
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
The Canvas class.
Definition TCanvas.h:23
void Close(Option_t *option="") override
Close canvas.
Definition TCanvas.cxx:786
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:656
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:377
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:543
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:771
The most important graphics class in the ROOT system.
Definition TPad.h:28
Short_t GetBorderMode() const override
Definition TPad.h:200
Double_t fWNDC
Width of pad along X in Normalized Coordinates (NDC)
Definition TPad.h:66
Bool_t IsEditable() const override
Definition TPad.h:273
const char * GetTitle() const override
Returns title of object.
Definition TPad.h:262
TList * GetListOfPrimitives() const override
Definition TPad.h:246
Double_t fYlowNDC
Y bottom left corner of pad in NDC [0,1].
Definition TPad.h:63
Int_t YtoPixel(Double_t y) const override
Convert Y coordinate to pixel.
Definition TPad.cxx:7600
TVirtualPad * GetMother() const override
Definition TPad.h:260
void Modified(Bool_t flag=true) override
Mark pad modified Will be repainted when TCanvas::Update() will be called next time.
Definition TPad.cxx:7459
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TPad.cxx:1897
Short_t GetBorderSize() const override
Definition TPad.h:201
TCanvas * GetCanvas() const override
Definition TPad.h:263
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:261
Basic string class.
Definition TString.h:138
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:2384
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
TLine * line