ROOT  6.06/09
Reference Guide
TArrowEditor.cxx
Go to the documentation of this file.
1 // @(#)root/ged:$Id$
2 // Author: Ilka Antcheva 20/10/04
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, 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 "TArrowEditor.h"
13 #include "TGComboBox.h"
14 #include "TGLabel.h"
15 #include "TGNumberEntry.h"
16 #include "TArrow.h"
17 
19 
20 enum EArrowWid {
21  kARROW_ANG,
22  kARROW_OPT,
23  kARROW_SIZ
24 };
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 
28 /* Begin_Html
29 <center><h2>Implements user interface for editing of arrow attributes:
30 shape, size, angle.</h2></center>
31 The picture below shows this interface.
32 End_Html
33 Begin_Macro(GUI)
34 {
35  gROOT->ProcessLine(".x $ROOTSYS/tutorials/graphics/arrow.C");
36  TCanvas *c1 = (TCanvas *)gROOT->GetListOfCanvases()->FindObject("c1");
37  c1->SetBorderMode(0);
38  c1->ToggleEditor();
39  c1->Selected(c1, new TArrow(), 1);
40  TRootCanvas *r = (TRootCanvas*)c1->GetCanvasImp();
41  r->SetWindowSize(700,500);
42  return r->GetMainFrame();
43 }
44 End_Macro */
45 
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Constructor of arrow GUI.
49 
51  Int_t height, UInt_t options, Pixel_t back)
52  : TGedFrame(p, width, height, options | kVerticalFrame, back)
53 {
54  fArrow = 0;
55 
56  MakeTitle("Arrow");
57 
59  AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
60 
61  TGCompositeFrame *f2a = new TGCompositeFrame(f2, 80, 20);
62  f2->AddFrame(f2a, new TGLayoutHints(kLHintsTop, 10, 0, 0, 0));
63 
64  TGLabel *fShapeLabel = new TGLabel(f2a, "Shape:");
65  f2a->AddFrame(fShapeLabel, new TGLayoutHints(kLHintsNormal, 0, 0, 1, 5));
66 
67  TGLabel *fAngleLabel = new TGLabel(f2a, "Angle:");
68  f2a->AddFrame(fAngleLabel, new TGLayoutHints(kLHintsNormal, 0, 0, 5, 5));
69 
70  TGLabel *fSizeLabel = new TGLabel(f2a, "Size: ");
71  f2a->AddFrame(fSizeLabel, new TGLayoutHints(kLHintsNormal, 0, 0, 5, 1));
72 
73  TGCompositeFrame *f2b = new TGCompositeFrame(f2, 80, 20, kFixedWidth);
74  f2->AddFrame(f2b, new TGLayoutHints(kLHintsTop, 10, 0, 0, 0));
75 
76  fOptionCombo = BuildOptionComboBox(f2b, kARROW_OPT);
77  fOptionCombo->Resize(80, 20);
78  f2b->AddFrame(fOptionCombo, new TGLayoutHints(kLHintsExpandX, 1, 1, 1, 1));
79  fOptionCombo->Associate(this);
80 
81  fAngleEntry = new TGNumberEntry(f2b, 30, 8, kARROW_ANG,
85  fAngleEntry->GetNumberEntry()->SetToolTipText("Set the arrow opening angle in degrees.");
86  f2b->AddFrame(fAngleEntry, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
87 
88  fSizeEntry = new TGNumberEntry(f2b, 0.03, 8, kARROW_SIZ,
92  fSizeEntry->GetNumberEntry()->SetToolTipText("Set the size of arrow.");
93  f2b->AddFrame(fSizeEntry, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
94 
95 }
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// Destructor of arrow editor.
99 
101 {
102  TGFrameElement *el;
103  TIter next(GetList());
104 
105  while ((el = (TGFrameElement *)next())) {
106  if (!strcmp(el->fFrame->ClassName(), "TGCompositeFrame"))
107  ((TGCompositeFrame *)el->fFrame)->Cleanup();
108  }
109  Cleanup();
110 }
111 
112 ////////////////////////////////////////////////////////////////////////////////
113 /// Connect signals to slots.
114 
116 {
117  fOptionCombo->Connect("Selected(Int_t)", "TArrowEditor", this, "DoOption(Int_t)");
118  fAngleEntry->Connect("ValueSet(Long_t)", "TArrowEditor", this, "DoAngle()");
119  (fAngleEntry->GetNumberEntry())->Connect("ReturnPressed()", "TArrowEditor", this, "DoAngle()");
120  fSizeEntry->Connect("ValueSet(Long_t)", "TArrowEditor", this, "DoSize()");
121  (fSizeEntry->GetNumberEntry())->Connect("ReturnPressed()", "TArrowEditor", this, "DoSize()");
122 
123  fInit = kFALSE;
124 }
125 
126 ////////////////////////////////////////////////////////////////////////////////
127 /// Pick up the used arrow attributes.
128 
130 {
131  fArrow = (TArrow *)obj;
133 
135  if (id != fOptionCombo->GetSelected())
136  fOptionCombo->Select(id);
137 
138  Float_t sz = fArrow->GetArrowSize();
139  fSizeEntry->SetNumber(sz);
140 
141  Int_t deg = (Int_t)fArrow->GetAngle();
142  fAngleEntry->SetNumber(deg);
143 
146 }
147 
148 ////////////////////////////////////////////////////////////////////////////////
149 /// Slot connected to the arrow opening angle setting.
150 
152 {
153  if (fAvoidSignal) return;
156  Update();
157 }
158 
159 ////////////////////////////////////////////////////////////////////////////////
160 /// Slot connected to the arrow shape setting.
161 
163 {
164  if (fAvoidSignal) return;
165  const char* opt=0;
166  switch (id) {
167  case 1:
168  opt = "|>";
169  break;
170  case 2:
171  opt = "<|";
172  break;
173  case 3:
174  opt = ">";
175  break;
176  case 4:
177  opt = "<";
178  break;
179  case 5:
180  opt = "->-";
181  break;
182  case 6:
183  opt = "-<-";
184  break;
185  case 7:
186  opt = "-|>-";
187  break;
188  case 8:
189  opt = "-<|-";
190  break;
191  case 9:
192  opt = "<>";
193  break;
194  case 10:
195  opt = "<|>";
196  break;
197  }
198  fArrow->SetDrawOption(opt);
200  Update();
201 }
202 
203 
204 ////////////////////////////////////////////////////////////////////////////////
205 /// Slot connected to the arrow size.
206 
208 {
209  if (fAvoidSignal) return;
212  Update();
213 }
214 
215 ////////////////////////////////////////////////////////////////////////////////
216 /// Arrow shape combobox.
217 
219 {
220  TGComboBox *cb = new TGComboBox(parent, id);
221 
222  cb->AddEntry(" -------|>",1);
223  cb->AddEntry(" <|-------",2);
224  cb->AddEntry(" -------->",3);
225  cb->AddEntry(" <--------",4);
226  cb->AddEntry(" ---->----",5);
227  cb->AddEntry(" ----<----",6);
228  cb->AddEntry(" ----|>---",7);
229  cb->AddEntry(" ---<|----",8);
230  cb->AddEntry(" <------>", 9);
231  cb->AddEntry(" <|-----|>",10);
232  (cb->GetListBox())->Resize((cb->GetListBox())->GetWidth(), 136);
233  cb->Select(1);
234  return cb;
235 }
236 
237 ////////////////////////////////////////////////////////////////////////////////
238 /// Return shape entry according to the arrow draw option.
239 
241 {
242  TString opt = option;
243  opt.ToLower();
244  Int_t id = 0;
245 
246  if (opt == "|>") id = 1;
247  if (opt == "<|") id = 2;
248  if (opt == ">") id = 3;
249  if (opt == "<") id = 4;
250  if (opt == "->-") id = 5;
251  if (opt == "-<-") id = 6;
252  if (opt == "-|>-") id = 7;
253  if (opt == "-<|-") id = 8;
254  if (opt == "<>") id = 9;
255  if (opt == "<|>") id = 10;
256  return id;
257 }
TGNumberEntry * fAngleEntry
Definition: TArrowEditor.h:36
virtual void Paint(Option_t *option="")
Paint this arrow with its current attributes.
Definition: TArrow.cxx:159
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
Int_t GetShapeEntry(Option_t *opt)
Return shape entry according to the arrow draw option.
TGComboBox * fOptionCombo
Definition: TArrowEditor.h:35
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
float Float_t
Definition: RtypesCore.h:53
const char Option_t
Definition: RtypesCore.h:62
virtual void DoOption(Int_t id)
Slot connected to the arrow shape setting.
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
UInt_t GetWidth() const
Definition: TGFrame.h:287
virtual void SetModel(TObject *obj)
Pick up the used arrow attributes.
virtual void SetNumber(Double_t val)
Basic string class.
Definition: TString.h:137
virtual TList * GetList() const
Definition: TGFrame.h:385
Float_t GetAngle() const
Definition: TArrow.h:57
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1088
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: Rtypes.h:92
TArrow * fArrow
Definition: TArrowEditor.h:34
Bool_t fAvoidSignal
Definition: TGedFrame.h:58
TGNumberEntryField * GetNumberEntry() const
ULong_t Pixel_t
Definition: GuiTypes.h:41
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition: TObject.cxx:399
virtual ~TArrowEditor()
Destructor of arrow editor.
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition: TGedFrame.cxx:73
virtual void Select(Int_t id, Bool_t emit=kTRUE)
Make the selected item visible in the combo box window and emit signals according to the second param...
Definition: TGComboBox.cxx:443
TGCompositeFrame(const TGCompositeFrame &)
virtual void SetArrowSize(Float_t arrowsize=0.05)
Definition: TArrow.h:65
XFontStruct * id
Definition: TGX11.cxx:108
TArrowEditor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor of arrow GUI.
TGComboBox * BuildOptionComboBox(TGFrame *parent, Int_t id)
Arrow shape combobox.
virtual Int_t GetSelected() const
Definition: TGComboBox.h:136
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot...
Definition: TQObject.cxx:1135
virtual void DoAngle()
Slot connected to the arrow opening angle setting.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:187
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:90
Float_t GetArrowSize() const
Definition: TArrow.h:58
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual TGListBox * GetListBox() const
Definition: TGComboBox.h:132
ClassImp(TArrowEditor) enum EArrowWid
TGFrame * fFrame
Definition: TGLayout.h:125
virtual void ConnectSignals2Slots()
Connect signals to slots.
virtual void AddEntry(TGString *s, Int_t id)
Definition: TGComboBox.h:108
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
Mother of all ROOT objects.
Definition: TObject.h:58
virtual void DoSize()
Slot connected to the arrow size.
Bool_t fInit
Definition: TGedFrame.h:55
double f2(const double *x)
virtual Double_t GetNumber() const
Draw all kinds of Arrows.
Definition: TArrow.h:35
virtual void SetDrawOption(Option_t *option="")
Set drawing option for object.
Definition: TObject.cxx:715
virtual void Cleanup()
Cleanup and delete all objects contained in this composite frame.
Definition: TGFrame.cxx:949
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
TGNumberEntry * fSizeEntry
Definition: TArrowEditor.h:37
virtual void SetAngle(Float_t angle=60)
Definition: TArrow.h:64