ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TAttTextEditor.cxx
Go to the documentation of this file.
1 // @(#)root/ged:$Id$
2 // Author: Ilka Antcheva 11/05/04
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2002, 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 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TAttTextEditor //
15 // //
16 // Implements GUI for editing text attributes. //
17 // color, font, font size and alignment //
18 // //
19 //////////////////////////////////////////////////////////////////////////
20 //Begin_Html
21 /*
22 <img src="gif/TAttTextEditor.gif">
23 */
24 //End_Html
25 
26 
27 #include "TAttTextEditor.h"
28 #include "TGedEditor.h"
29 #include "TGColorSelect.h"
30 #include "TGComboBox.h"
31 #include "TColor.h"
32 #include "TPaveLabel.h"
33 #include "TVirtualPad.h"
34 #include "TGLabel.h"
35 #include "TGNumberEntry.h"
36 #include "TPad.h"
37 #include "TCanvas.h"
38 #include "TROOT.h"
39 
41 
42 enum ETextWid {
43  kCOLOR,
44  kFONT_SIZE,
45  kFONT_STYLE,
46  kFONT_ALIGN,
47  kALPHA,
48  kALPHAFIELD
49 };
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Constructor of text attributes GUI.
53 
55  Int_t height, UInt_t options, Pixel_t back)
56  : TGedFrame(p, width, height, options | kVerticalFrame, back)
57 {
58  fPriority = 3;
59 
60  fAttText = 0;
61 
62  MakeTitle("Text");
63 
65  fColorSelect = new TGColorSelect(f2, 0, kCOLOR);
66  f2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
67  fColorSelect->Associate(this);
68  fSizeCombo = BuildFontSizeComboBox(f2, kFONT_SIZE);
69  f2->AddFrame(fSizeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
70  fSizeCombo->Resize(91, 20);
71  fSizeCombo->Associate(this);
72  AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
73  fTypeCombo = new TGFontTypeComboBox(this, kFONT_STYLE);
74  fTypeCombo->Resize(137, 20);
75  AddFrame(fTypeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
76  fAlignCombo = BuildTextAlignComboBox(this, kFONT_ALIGN);
77  fAlignCombo->Resize(137, 20);
78  AddFrame(fAlignCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
79 
80  TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
81  AddFrame(AlphaLabel,
83  TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
84  fAlpha = new TGHSlider(f2a,100,kSlider2|kScaleNo,kALPHA);
85  fAlpha->SetRange(0,1000);
87  fAlphaField = new TGNumberEntryField(f2a, kALPHAFIELD, 0,
90  fAlphaField->Resize(40,20);
91  if (!TCanvas::SupportAlpha()) {
93  AlphaLabel->Disable(kTRUE);
95  }
98 }
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 /// Destructor of text editor.
102 
104 {
105 }
106 
107 ////////////////////////////////////////////////////////////////////////////////
108 /// Connect signals to slots.
109 
111 {
112  fAlpha->Connect("Released()","TAttTextEditor", this, "DoAlpha()");
113  fAlpha->Connect("PositionChanged(Int_t)","TAttTextEditor", this, "DoLiveAlpha(Int_t)");
114  fAlphaField->Connect("ReturnPressed()","TAttTextEditor", this, "DoAlphaField()");
115  fAlpha->Connect("Pressed()","TAttTextEditor", this, "GetCurAlpha()");
116  fColorSelect->Connect("ColorSelected(Pixel_t)", "TAttTextEditor", this, "DoTextColor(Pixel_t)");
117  fColorSelect->Connect("AlphaColorSelected(ULong_t)", "TAttTextEditor", this, "DoTextAlphaColor(ULong_t)");
118  fInit = kFALSE;
119 }
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// Pick up the values of used text attributes.
123 
125 {
126  TAttText *atttext = dynamic_cast<TAttText *>(obj);
127  if (!atttext) return;
128 
129  fAttText = atttext;
131 
133 
135  Float_t dy;
136 
137  if (obj->InheritsFrom(TPaveLabel::Class())) {
138  TBox *pl = (TBox*)obj;
139  dy = s * (pl->GetY2() - pl->GetY1());
140  }
141  else
142  dy = s * (fGedEditor->GetPad()->GetY2() - fGedEditor->GetPad()->GetY1());
143 
144  Int_t size = fGedEditor->GetPad()->YtoPixel(0.0) - fGedEditor->GetPad()->YtoPixel(dy);
145  if (size > 50) size = 50;
146  if (size < 0) size = 0;
147  fSizeCombo->Select(size, kFALSE);
148 
150 
154 
157 
158  if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
159  fAlpha->SetPosition((Int_t)color->GetAlpha()*1000);
160  fAlphaField->SetNumber(color->GetAlpha());
161  }
162 }
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Slot connected to the marker color.
166 
168 {
169  if (fAvoidSignal) return;
171 
172  if (TColor *tcolor = gROOT->GetColor(TColor::GetColor(color))) {
173  fAlpha->SetPosition((Int_t)(tcolor->GetAlpha()*1000));
174  fAlphaField->SetNumber(tcolor->GetAlpha());
175  }
176 
177  Update();
178 }
179 
180 ////////////////////////////////////////////////////////////////////////////////
181 /// Slot connected to the color with alpha.
182 
184 {
185  TColor *color = (TColor *)p;
186 
187  if (fAvoidSignal) return;
188  fAttText->SetTextColor(color->GetNumber());
189  fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
190  fAlphaField->SetNumber(color->GetAlpha());
191 
192  Update();
193 }
194 
195 ////////////////////////////////////////////////////////////////////////////////
196 /// Process message.
197 
199 {
200  if(!fGedEditor || !fGedEditor->GetModel()) return kTRUE;
201 
202  Bool_t b = kFALSE;
203 
204  if (GET_MSG(msg) == kC_COLORSEL && GET_SUBMSG(msg) == kCOL_SELCHANGED) {
205  if (parm1 != 0) fAttText->SetTextColor(TColor::GetColor(parm2));
206  b = kTRUE;
207  // SendMessage(fMsgWindow, msg, parm1, parm2);
208  }
209 
210  if (GET_MSG(msg) == kC_COMMAND && GET_SUBMSG(msg) == kCM_COMBOBOX) {
211 
212  if (parm1 == kFONT_SIZE) {
214  Float_t dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY(parm2);
215  Float_t textSize;
216 
218  TBox *pl = (TBox*)fGedEditor->GetModel();
219  textSize = dy/(pl->GetY2() - pl->GetY1());
220  }
221  else
222  textSize = dy/(pad->GetY2() - pad->GetY1());
223 
224  fAttText->SetTextSize(textSize);
225  b = kTRUE;
226  } else if (parm1 == kFONT_STYLE) {
227  Int_t fontPrec = fAttText->GetTextFont()%10;
228  fAttText->SetTextFont(parm2 * 10 + fontPrec);
229  b = kTRUE;
230  } else if (parm1 == kFONT_ALIGN) {
231  fAttText->SetTextAlign(parm2);
232  b = kTRUE;
233  }
234  }
235 
236  if (b && !fAvoidSignal) Update();
237 
238  return kTRUE;
239 }
240 
241 ////////////////////////////////////////////////////////////////////////////////
242 /// Create text size combo box.
243 
245 {
246  char a[100];
247  TGComboBox *c = new TGComboBox(parent, id);
248 
249  c->AddEntry("Default", 0);
250  for (int i = 1; i <= 50; i++) {
251  snprintf(a, 99, "%d", i);
252  c->AddEntry(a, i);
253  }
254 
255  return c;
256 }
257 
258 ////////////////////////////////////////////////////////////////////////////////
259 /// Create text align combo box.
260 
262 {
263  TGComboBox *c = new TGComboBox(parent, id);
264 
265  c->AddEntry("11 Bottom, Left", 11);
266  c->AddEntry("21 Bottom, Middle", 21);
267  c->AddEntry("31 Bottom, Right", 31);
268  c->AddEntry("12 Middle, Left", 12);
269  c->AddEntry("22 Middle, Middle", 22);
270  c->AddEntry("32 Middle, Right", 32);
271  c->AddEntry("13 Top, Left", 13);
272  c->AddEntry("23 Top, Middle", 23);
273  c->AddEntry("33 Top, Right", 33);
274 
275  return c;
276 }
277 
278 ////////////////////////////////////////////////////////////////////////////////
279 /// Slot to set the alpha value from the entry field.
280 
282 {
283  if (fAvoidSignal) return;
284 
285  if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
286  color->SetAlpha((Float_t)fAlphaField->GetNumber());
288  }
289  Update();
290 }
291 
292 ////////////////////////////////////////////////////////////////////////////////
293 /// Slot to set the alpha value
294 
296 {
297  if (fAvoidSignal) return;
298 
299  if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
300  color->SetAlpha((Float_t)fAlpha->GetPosition()/1000);
302  }
303  Update();
304 }
305 
306 ////////////////////////////////////////////////////////////////////////////////
307 /// Slot to set alpha value online.
308 
310 {
311  if (fAvoidSignal) return;
312  fAlphaField->SetNumber((Float_t)a/1000);
313 
314  if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
315  // In case the color is not transparent a new color is created.
316  if (color->GetAlpha() == 1.) {
317  fAttText->SetTextColor(TColor::GetColorTransparent(color->GetNumber(),0.99));
318  } else {
319  color->SetAlpha((Float_t)a/1000);
320  }
321  }
322  Update();
323 }
324 
325 ////////////////////////////////////////////////////////////////////////////////
326 /// Slot to update alpha value on click on Slider
327 
329 {
330  if (fAvoidSignal) return;
331 
332  if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
333  fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
334  fAlphaField->SetNumber(color->GetAlpha());
335  }
336  Update();
337 }
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
virtual Font_t GetTextFont() const
Definition: TAttText.h:49
virtual void DoTextColor(Pixel_t color)
Slot connected to the marker color.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:487
float Float_t
Definition: RtypesCore.h:53
static TGComboBox * BuildFontSizeComboBox(TGFrame *parent, Int_t id)
Create text size combo box.
virtual void SetRange(Int_t min, Int_t max)
Definition: TGSlider.h:105
return c
Create a Box.
Definition: TBox.h:44
TAttText * fAttText
tuple f2
Definition: surfaces.py:24
virtual void DoAlphaField()
Slot to set the alpha value from the entry field.
virtual void SetModel(TObject *obj)
Pick up the values of used text attributes.
void SetColor(Pixel_t color, Bool_t emit=kTRUE)
Set color.
virtual Float_t GetTextSize() const
Definition: TAttText.h:50
void ConnectSignals2Slots()
Connect signals to slots.
#define gROOT
Definition: TROOT.h:344
virtual Int_t YtoPixel(Double_t y) const =0
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
TGNumberEntryField * fAlphaField
virtual TVirtualPad * GetPad() const
Definition: TGedEditor.h:97
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void GetCurAlpha()
Slot to update alpha value on click on Slider.
virtual TObject * GetModel() const
Definition: TGedEditor.h:98
TGColorSelect * fColorSelect
virtual void SetTextFont(Font_t tfont=62)
Definition: TAttText.h:59
virtual Short_t GetTextAlign() const
Definition: TAttText.h:46
Bool_t fAvoidSignal
Definition: TGedFrame.h:58
TGFontTypeComboBox * fTypeCombo
ULong_t Pixel_t
Definition: GuiTypes.h:41
void Class()
Definition: Class.C:29
virtual void DoTextAlphaColor(ULong_t p)
Slot connected to the color with alpha.
static TGComboBox * BuildTextAlignComboBox(TGFrame *parent, Int_t id)
Create text align combo box.
virtual Color_t GetTextColor() const
Definition: TAttText.h:48
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 &)
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:59
short Color_t
Definition: RtypesCore.h:79
virtual void SetTextAlign(Short_t align=11)
Definition: TAttText.h:55
static Bool_t SupportAlpha()
Static function returning "true" if transparency is supported.
Definition: TCanvas.cxx:2169
virtual Double_t AbsPixeltoY(Int_t py)=0
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Process message.
TGHSlider * fAlpha
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 Double_t GetY2() const =0
virtual Int_t GetPosition() const
Definition: TGSlider.h:107
ClassImp(TAttTextEditor) enum ETextWid
Int_t GET_SUBMSG(Long_t val)
virtual void Disable(Bool_t on=kTRUE)
Definition: TGLabel.h:103
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:90
Text Attributes class.
Definition: TAttText.h:32
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void SetPosition(Int_t pos)
Definition: TGSlider.h:106
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb"...
Definition: TColor.cxx:1023
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
tuple pl
Definition: first.py:10
tuple pad
Definition: first.py:38
virtual Double_t GetY1() const =0
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:1196
Int_t GET_MSG(Long_t val)
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition: TColor.cxx:1219
long Long_t
Definition: RtypesCore.h:50
virtual void DoAlpha()
Slot to set the alpha value.
void SetEnabled(Bool_t flag=kTRUE)
Definition: TGTextEntry.h:170
virtual void AddEntry(TGString *s, Int_t id)
Definition: TGComboBox.h:108
unsigned long ULong_t
Definition: RtypesCore.h:51
virtual void SetEnabled(Bool_t flag=kTRUE)
Definition: TGSlider.h:102
The color creation and management class.
Definition: TColor.h:47
virtual void DoLiveAlpha(Int_t a)
Slot to set alpha value online.
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
TGComboBox * fSizeCombo
Mother of all ROOT objects.
Definition: TObject.h:58
TAttTextEditor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor of text attributes GUI.
Bool_t fInit
Definition: TGedFrame.h:55
virtual void SetNumber(Double_t val)
Set the numeric value (floating point representation).
Double_t GetY1() const
Definition: TBox.h:74
TGComboBox * fAlignCombo
Float_t GetAlpha() const
Definition: TColor.h:91
virtual void SetTextColor(Color_t tcolor=1)
Definition: TAttText.h:57
Double_t GetY2() const
Definition: TBox.h:75
virtual void SetTextSize(Float_t tsize=1)
Definition: TAttText.h:60
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
TGedEditor * fGedEditor
Definition: TGedFrame.h:56
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
Int_t GetNumber() const
Definition: TColor.h:83
virtual ~TAttTextEditor()
Destructor of text editor.
Int_t fPriority
Definition: TGedFrame.h:61