Logo ROOT   master
Reference Guide
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 "TCanvas.h"
37 #include "TROOT.h"
38 
40 
41 enum ETextWid {
48 };
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Constructor of text attributes GUI.
52 
54  Int_t height, UInt_t options, Pixel_t back)
55  : TGedFrame(p, width, height, options | kVerticalFrame, back)
56 {
57  fPriority = 3;
58 
59  fAttText = 0;
60 
61  MakeTitle("Text");
62 
63  TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
64  fColorSelect = new TGColorSelect(f2, 0, kCOLOR);
65  f2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
66  fColorSelect->Associate(this);
68  f2->AddFrame(fSizeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
69  fSizeCombo->Resize(91, 20);
70  fSizeCombo->Associate(this);
71  AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
73  fTypeCombo->Resize(137, 20);
74  AddFrame(fTypeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
76  fAlignCombo->Resize(137, 20);
77  AddFrame(fAlignCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
78 
79  TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
80  AddFrame(AlphaLabel,
82  TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
83  fAlpha = new TGHSlider(f2a,100,kSlider2|kScaleNo,kALPHA);
84  fAlpha->SetRange(0,1000);
89  fAlphaField->Resize(40,20);
90  if (!TCanvas::SupportAlpha()) {
92  AlphaLabel->Disable(kTRUE);
94  }
97 }
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 /// Destructor of text editor.
101 
103 {
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Connect signals to slots.
108 
110 {
111  fAlpha->Connect("Released()","TAttTextEditor", this, "DoAlpha()");
112  fAlpha->Connect("PositionChanged(Int_t)","TAttTextEditor", this, "DoLiveAlpha(Int_t)");
113  fAlphaField->Connect("ReturnPressed()","TAttTextEditor", this, "DoAlphaField()");
114  fAlpha->Connect("Pressed()","TAttTextEditor", this, "GetCurAlpha()");
115  fColorSelect->Connect("ColorSelected(Pixel_t)", "TAttTextEditor", this, "DoTextColor(Pixel_t)");
116  fColorSelect->Connect("AlphaColorSelected(ULong_t)", "TAttTextEditor", this, "DoTextAlphaColor(ULong_t)");
117  fInit = kFALSE;
118 }
119 
120 ////////////////////////////////////////////////////////////////////////////////
121 /// Pick up the values of used text attributes.
122 
124 {
125  TAttText *atttext = dynamic_cast<TAttText *>(obj);
126  if (!atttext) return;
127 
128  fAttText = atttext;
130 
132 
134  Float_t dy;
135 
136  if (obj->InheritsFrom(TPaveLabel::Class())) {
137  TBox *pl = (TBox*)obj;
138  dy = s * (pl->GetY2() - pl->GetY1());
139  }
140  else
141  dy = s * (fGedEditor->GetPad()->GetY2() - fGedEditor->GetPad()->GetY1());
142 
143  Int_t size = fGedEditor->GetPad()->YtoPixel(0.0) - fGedEditor->GetPad()->YtoPixel(dy);
144  if (size > 50) size = 50;
145  if (size < 0) size = 0;
146  fSizeCombo->Select(size, kFALSE);
147 
149 
153 
156 
157  if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
158  fAlpha->SetPosition((Int_t)color->GetAlpha()*1000);
159  fAlphaField->SetNumber(color->GetAlpha());
160  }
161 }
162 
163 ////////////////////////////////////////////////////////////////////////////////
164 /// Slot connected to the marker color.
165 
167 {
168  if (fAvoidSignal) return;
170 
171  if (TColor *tcolor = gROOT->GetColor(TColor::GetColor(color))) {
172  fAlpha->SetPosition((Int_t)(tcolor->GetAlpha()*1000));
173  fAlphaField->SetNumber(tcolor->GetAlpha());
174  }
175 
176  Update();
177 }
178 
179 ////////////////////////////////////////////////////////////////////////////////
180 /// Slot connected to the color with alpha.
181 
183 {
184  TColor *color = (TColor *)p;
185 
186  if (fAvoidSignal) return;
187  fAttText->SetTextColor(color->GetNumber());
188  fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
189  fAlphaField->SetNumber(color->GetAlpha());
190 
191  Update();
192 }
193 
194 ////////////////////////////////////////////////////////////////////////////////
195 /// Process message.
196 
198 {
199  if(!fGedEditor || !fGedEditor->GetModel()) return kTRUE;
200 
201  Bool_t b = kFALSE;
202 
203  if (GET_MSG(msg) == kC_COLORSEL && GET_SUBMSG(msg) == kCOL_SELCHANGED) {
204  if (parm1 != 0) fAttText->SetTextColor(TColor::GetColor(parm2));
205  b = kTRUE;
206  // SendMessage(fMsgWindow, msg, parm1, parm2);
207  }
208 
209  if (GET_MSG(msg) == kC_COMMAND && GET_SUBMSG(msg) == kCM_COMBOBOX) {
210 
211  if (parm1 == kFONT_SIZE) {
212  TVirtualPad* pad = fGedEditor->GetPad();
213  Float_t dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY(parm2);
214  Float_t textSize;
215 
217  TBox *pl = (TBox*)fGedEditor->GetModel();
218  textSize = dy/(pl->GetY2() - pl->GetY1());
219  }
220  else
221  textSize = dy/(pad->GetY2() - pad->GetY1());
222 
223  fAttText->SetTextSize(textSize);
224  b = kTRUE;
225  } else if (parm1 == kFONT_STYLE) {
226  Int_t fontPrec = fAttText->GetTextFont()%10;
227  fAttText->SetTextFont(parm2 * 10 + fontPrec);
228  b = kTRUE;
229  } else if (parm1 == kFONT_ALIGN) {
230  fAttText->SetTextAlign(parm2);
231  b = kTRUE;
232  }
233  }
234 
235  if (b && !fAvoidSignal) Update();
236 
237  return kTRUE;
238 }
239 
240 ////////////////////////////////////////////////////////////////////////////////
241 /// Create text size combo box.
242 
244 {
245  char a[100];
246  TGComboBox *c = new TGComboBox(parent, id);
247 
248  c->AddEntry("Default", 0);
249  for (int i = 1; i <= 50; i++) {
250  snprintf(a, 99, "%d", i);
251  c->AddEntry(a, i);
252  }
253 
254  return c;
255 }
256 
257 ////////////////////////////////////////////////////////////////////////////////
258 /// Create text align combo box.
259 
261 {
262  TGComboBox *c = new TGComboBox(parent, id);
263 
264  c->AddEntry("11 Bottom, Left", 11);
265  c->AddEntry("21 Bottom, Middle", 21);
266  c->AddEntry("31 Bottom, Right", 31);
267  c->AddEntry("12 Middle, Left", 12);
268  c->AddEntry("22 Middle, Middle", 22);
269  c->AddEntry("32 Middle, Right", 32);
270  c->AddEntry("13 Top, Left", 13);
271  c->AddEntry("23 Top, Middle", 23);
272  c->AddEntry("33 Top, Right", 33);
273 
274  return c;
275 }
276 
277 ////////////////////////////////////////////////////////////////////////////////
278 /// Slot to set the alpha value from the entry field.
279 
281 {
282  if (fAvoidSignal) return;
283 
284  if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
285  color->SetAlpha((Float_t)fAlphaField->GetNumber());
287  }
288  Update();
289 }
290 
291 ////////////////////////////////////////////////////////////////////////////////
292 /// Slot to set the alpha value
293 
295 {
296  if (fAvoidSignal) return;
297 
298  if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
299  color->SetAlpha((Float_t)fAlpha->GetPosition()/1000);
301  }
302  Update();
303 }
304 
305 ////////////////////////////////////////////////////////////////////////////////
306 /// Slot to set alpha value online.
307 
309 {
310  if (fAvoidSignal) return;
311  fAlphaField->SetNumber((Float_t)a/1000);
312 
313  if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
314  // In case the color is not transparent a new color is created.
315  if (color->GetAlpha() == 1.) {
316  fAttText->SetTextColor(TColor::GetColorTransparent(color->GetNumber(),0.99));
317  } else {
318  color->SetAlpha((Float_t)a/1000);
319  }
320  }
321  Update();
322 }
323 
324 ////////////////////////////////////////////////////////////////////////////////
325 /// Slot to update alpha value on click on Slider
326 
328 {
329  if (fAvoidSignal) return;
330 
331  if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
332  fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
333  fAlphaField->SetNumber(color->GetAlpha());
334  }
335  Update();
336 }
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:588
virtual TVirtualPad * GetPad() const
Definition: TGedEditor.h:89
virtual void DoTextColor(Pixel_t color)
Slot connected to the marker color.
virtual Color_t GetTextColor() const
Return the text color.
Definition: TAttText.h:34
virtual Int_t GetPosition() const
Definition: TGSlider.h:109
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:101
virtual Short_t GetTextAlign() const
Return the text alignment.
Definition: TAttText.h:32
Create a Box.
Definition: TBox.h:24
TAttText * fAttText
Float_t GetAlpha() const
Definition: TColor.h:63
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.
void ConnectSignals2Slots()
Connect signals to slots.
#define gROOT
Definition: TROOT.h:415
virtual Int_t YtoPixel(Double_t y) const =0
Double_t GetY2() const
Definition: TBox.h:55
TGNumberEntryField * fAlphaField
ETextWid
virtual void GetCurAlpha()
Slot to update alpha value on click on Slider.
TGColorSelect * fColorSelect
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition: TAttText.h:45
Bool_t fAvoidSignal
Definition: TGedFrame.h:56
virtual TObject * GetModel() const
Definition: TGedEditor.h:90
TGFontTypeComboBox * fTypeCombo
ULong_t Pixel_t
Definition: GuiTypes.h:39
void Class()
Definition: Class.C:29
virtual Float_t GetTextSize() const
Return the text size.
Definition: TAttText.h:36
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 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:451
TGCompositeFrame(const TGCompositeFrame &)
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
static constexpr double s
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:50
short Color_t
Definition: RtypesCore.h:79
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition: TAttText.h:41
static Bool_t SupportAlpha()
Static function returning "true" if transparency is supported.
Definition: TCanvas.cxx:2327
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:867
virtual Double_t GetY2() const =0
Int_t GET_SUBMSG(Long_t val)
auto * a
Definition: textangle.C:12
virtual void Disable(Bool_t on=kTRUE)
Definition: TGLabel.h:97
virtual Font_t GetTextFont() const
Return the text font.
Definition: TAttText.h:35
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:84
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:442
Text Attributes class.
Definition: TAttText.h:18
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void SetPosition(Int_t pos)
Definition: TGSlider.h:105
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:1764
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:1966
Int_t GET_MSG(Long_t val)
const Bool_t kFALSE
Definition: RtypesCore.h:88
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:120
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition: TColor.cxx:2003
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:164
#define ClassImp(name)
Definition: Rtypes.h:365
unsigned long ULong_t
Definition: RtypesCore.h:51
virtual void SetEnabled(Bool_t flag=kTRUE)
Definition: TGSlider.h:98
The color creation and management class.
Definition: TColor.h:19
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:1100
TGComboBox * fSizeCombo
Mother of all ROOT objects.
Definition: TObject.h:37
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:53
virtual void SetNumber(Double_t val)
Set the numeric value (floating point representation).
TGComboBox * fAlignCombo
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
#define snprintf
Definition: civetweb.c:1540
Int_t GetNumber() const
Definition: TColor.h:55
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition: TAttText.h:43
#define c(i)
Definition: RSha256.hxx:101
Double_t GetY1() const
Definition: TBox.h:54
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition: TAttText.h:46
TGedEditor * fGedEditor
Definition: TGedFrame.h:54
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
virtual ~TAttTextEditor()
Destructor of text editor.
Int_t fPriority
Definition: TGedFrame.h:59