ROOT  6.06/08
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 {
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 ~~~
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 ~~~
45 */
46 
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Constructor of arrow GUI.
50 
52  Int_t height, UInt_t options, Pixel_t back)
53  : TGedFrame(p, width, height, options | kVerticalFrame, back)
54 {
55  fArrow = 0;
56 
57  MakeTitle("Arrow");
58 
60  AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
61 
62  TGCompositeFrame *f2a = new TGCompositeFrame(f2, 80, 20);
63  f2->AddFrame(f2a, new TGLayoutHints(kLHintsTop, 10, 0, 0, 0));
64 
65  TGLabel *fShapeLabel = new TGLabel(f2a, "Shape:");
66  f2a->AddFrame(fShapeLabel, new TGLayoutHints(kLHintsNormal, 0, 0, 1, 5));
67 
68  TGLabel *fAngleLabel = new TGLabel(f2a, "Angle:");
69  f2a->AddFrame(fAngleLabel, new TGLayoutHints(kLHintsNormal, 0, 0, 5, 5));
70 
71  TGLabel *fSizeLabel = new TGLabel(f2a, "Size: ");
72  f2a->AddFrame(fSizeLabel, new TGLayoutHints(kLHintsNormal, 0, 0, 5, 1));
73 
74  TGCompositeFrame *f2b = new TGCompositeFrame(f2, 80, 20, kFixedWidth);
75  f2->AddFrame(f2b, new TGLayoutHints(kLHintsTop, 10, 0, 0, 0));
76 
78  fOptionCombo->Resize(80, 20);
79  f2b->AddFrame(fOptionCombo, new TGLayoutHints(kLHintsExpandX, 1, 1, 1, 1));
80  fOptionCombo->Associate(this);
81 
82  fAngleEntry = new TGNumberEntry(f2b, 30, 8, kARROW_ANG,
86  fAngleEntry->GetNumberEntry()->SetToolTipText("Set the arrow opening angle in degrees.");
87  f2b->AddFrame(fAngleEntry, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
88 
89  fSizeEntry = new TGNumberEntry(f2b, 0.03, 8, kARROW_SIZ,
93  fSizeEntry->GetNumberEntry()->SetToolTipText("Set the size of arrow.");
94  f2b->AddFrame(fSizeEntry, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
95 
96 }
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// Destructor of arrow editor.
100 
102 {
103  TGFrameElement *el;
104  TIter next(GetList());
105 
106  while ((el = (TGFrameElement *)next())) {
107  if (!strcmp(el->fFrame->ClassName(), "TGCompositeFrame"))
108  ((TGCompositeFrame *)el->fFrame)->Cleanup();
109  }
110  Cleanup();
111 }
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Connect signals to slots.
115 
117 {
118  fOptionCombo->Connect("Selected(Int_t)", "TArrowEditor", this, "DoOption(Int_t)");
119  fAngleEntry->Connect("ValueSet(Long_t)", "TArrowEditor", this, "DoAngle()");
120  (fAngleEntry->GetNumberEntry())->Connect("ReturnPressed()", "TArrowEditor", this, "DoAngle()");
121  fSizeEntry->Connect("ValueSet(Long_t)", "TArrowEditor", this, "DoSize()");
122  (fSizeEntry->GetNumberEntry())->Connect("ReturnPressed()", "TArrowEditor", this, "DoSize()");
123 
124  fInit = kFALSE;
125 }
126 
127 ////////////////////////////////////////////////////////////////////////////////
128 /// Pick up the used arrow attributes.
129 
131 {
132  fArrow = (TArrow *)obj;
134 
136  if (id != fOptionCombo->GetSelected())
137  fOptionCombo->Select(id);
138 
139  Float_t sz = fArrow->GetArrowSize();
140  fSizeEntry->SetNumber(sz);
141 
142  Int_t deg = (Int_t)fArrow->GetAngle();
143  fAngleEntry->SetNumber(deg);
144 
147 }
148 
149 ////////////////////////////////////////////////////////////////////////////////
150 /// Slot connected to the arrow opening angle setting.
151 
153 {
154  if (fAvoidSignal) return;
157  Update();
158 }
159 
160 ////////////////////////////////////////////////////////////////////////////////
161 /// Slot connected to the arrow shape setting.
162 
164 {
165  if (fAvoidSignal) return;
166  const char* opt=0;
167  switch (id) {
168  case 1:
169  opt = "|>";
170  break;
171  case 2:
172  opt = "<|";
173  break;
174  case 3:
175  opt = ">";
176  break;
177  case 4:
178  opt = "<";
179  break;
180  case 5:
181  opt = "->-";
182  break;
183  case 6:
184  opt = "-<-";
185  break;
186  case 7:
187  opt = "-|>-";
188  break;
189  case 8:
190  opt = "-<|-";
191  break;
192  case 9:
193  opt = "<>";
194  break;
195  case 10:
196  opt = "<|>";
197  break;
198  }
199  fArrow->SetDrawOption(opt);
201  Update();
202 }
203 
204 
205 ////////////////////////////////////////////////////////////////////////////////
206 /// Slot connected to the arrow size.
207 
209 {
210  if (fAvoidSignal) return;
213  Update();
214 }
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 /// Arrow shape combobox.
218 
220 {
221  TGComboBox *cb = new TGComboBox(parent, id);
222 
223  cb->AddEntry(" -------|>",1);
224  cb->AddEntry(" <|-------",2);
225  cb->AddEntry(" -------->",3);
226  cb->AddEntry(" <--------",4);
227  cb->AddEntry(" ---->----",5);
228  cb->AddEntry(" ----<----",6);
229  cb->AddEntry(" ----|>---",7);
230  cb->AddEntry(" ---<|----",8);
231  cb->AddEntry(" <------>", 9);
232  cb->AddEntry(" <|-----|>",10);
233  (cb->GetListBox())->Resize((cb->GetListBox())->GetWidth(), 136);
234  cb->Select(1);
235  return cb;
236 }
237 
238 ////////////////////////////////////////////////////////////////////////////////
239 /// Return shape entry according to the arrow draw option.
240 
242 {
243  TString opt = option;
244  opt.ToLower();
245  Int_t id = 0;
246 
247  if (opt == "|>") id = 1;
248  if (opt == "<|") id = 2;
249  if (opt == ">") id = 3;
250  if (opt == "<") id = 4;
251  if (opt == "->-") id = 5;
252  if (opt == "-<-") id = 6;
253  if (opt == "-|>-") id = 7;
254  if (opt == "-<|-") id = 8;
255  if (opt == "<>") id = 9;
256  if (opt == "<|>") id = 10;
257  return id;
258 }
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.
Float_t GetArrowSize() const
Definition: TArrow.h:58
TGComboBox * fOptionCombo
Definition: TArrowEditor.h:35
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.
virtual void SetModel(TObject *obj)
Pick up the used arrow attributes.
virtual void SetNumber(Double_t val)
Basic string class.
Definition: TString.h:137
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
UInt_t GetWidth() const
Definition: TGFrame.h:287
TArrow * fArrow
Definition: TArrowEditor.h:34
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:187
Bool_t fAvoidSignal
Definition: TGedFrame.h:58
ULong_t Pixel_t
Definition: GuiTypes.h:41
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
virtual TList * GetList() const
Definition: TGFrame.h:385
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 Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition: TObject.cxx:399
virtual TGListBox * GetListBox() const
Definition: TGComboBox.h:132
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 void Associate(const TGWindow *w)
Definition: TGWidget.h:90
unsigned int UInt_t
Definition: RtypesCore.h:42
TGFrame * fFrame
Definition: TGLayout.h:125
virtual void ConnectSignals2Slots()
Connect signals to slots.
#define ClassImp(name)
Definition: Rtypes.h:279
virtual void AddEntry(TGString *s, Int_t id)
Definition: TGComboBox.h:108
virtual Double_t GetNumber() const
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
virtual Int_t GetSelected() const
Definition: TGComboBox.h:136
TGNumberEntryField * GetNumberEntry() const
double f2(const double *x)
Float_t GetAngle() const
Definition: TArrow.h:57
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
EArrowWid
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