Logo ROOT  
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 "TGLabel.h"
34 #include "TGNumberEntry.h"
35 #include "TCanvas.h"
36 #include "TROOT.h"
37 #include "snprintf.h"
38 
40 
41 enum ETextWid {
42  kCOLOR,
43  kFONT_SIZE,
46  kALPHA,
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);
67  fSizeCombo = BuildFontSizeComboBox(f2, kFONT_SIZE);
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));
72  fTypeCombo = new TGFontTypeComboBox(this, kFONT_STYLE);
73  fTypeCombo->Resize(137, 20);
74  AddFrame(fTypeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
75  fAlignCombo = BuildTextAlignComboBox(this, kFONT_ALIGN);
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);
86  fAlphaField = new TGNumberEntryField(f2a, kALPHAFIELD, 0,
89  fAlphaField->Resize(40,20);
90  if (!TCanvas::SupportAlpha()) {
91  fAlpha->SetEnabled(kFALSE);
92  AlphaLabel->Disable(kTRUE);
93  fAlphaField->SetEnabled(kFALSE);
94  }
95  f2a->AddFrame(fAlphaField,new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
96  AddFrame(f2a, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
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 
131  fTypeCombo->Select(fAttText->GetTextFont() / 10);
132 
133  Float_t s = fAttText->GetTextSize();
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 
148  fAlignCombo->Select(fAttText->GetTextAlign(), kFALSE);
149 
150  Color_t c = fAttText->GetTextColor();
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;
169  fAttText->SetTextColor(TColor::GetColor(color));
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 }
TGComboBox.h
c
#define c(i)
Definition: RSha256.hxx:119
TAttText
Definition: TAttText.h:18
TAttTextEditor::GetCurAlpha
virtual void GetCurAlpha()
Slot to update alpha value on click on Slider.
Definition: TAttTextEditor.cxx:327
TAttTextEditor::ProcessMessage
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Process message.
Definition: TAttTextEditor.cxx:197
GET_MSG
Int_t GET_MSG(Long_t val)
Definition: WidgetMessageTypes.h:112
TGWindow
Definition: TGWindow.h:31
TAttTextEditor.h
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TGFontTypeComboBox
Definition: TGComboBox.h:206
snprintf
#define snprintf
Definition: civetweb.c:1540
kC_COLORSEL
@ kC_COLORSEL
Definition: WidgetMessageTypes.h:83
TAttTextEditor::fAlignCombo
TGComboBox * fAlignCombo
Definition: TAttTextEditor.h:39
TGSlider::GetPosition
virtual Int_t GetPosition() const
Definition: TGSlider.h:109
kLHintsTop
@ kLHintsTop
Definition: TGLayout.h:40
Pixel_t
ULong_t Pixel_t
Definition: GuiTypes.h:39
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TAttTextEditor::BuildFontSizeComboBox
static TGComboBox * BuildFontSizeComboBox(TGFrame *parent, Int_t id)
Create text size combo box.
Definition: TAttTextEditor.cxx:243
kVerticalFrame
@ kVerticalFrame
Definition: GuiTypes.h:381
kLHintsLeft
@ kLHintsLeft
Definition: TGLayout.h:37
TGLabel
Definition: TGLabel.h:32
TGedEditor.h
TGHSlider
Definition: TGSlider.h:154
Float_t
float Float_t
Definition: RtypesCore.h:57
width
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
TGNumberFormat::kNEANonNegative
@ kNEANonNegative
Definition: TGNumberEntry.h:57
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:168
Int_t
int Int_t
Definition: RtypesCore.h:45
TVirtualPad::YtoPixel
virtual Int_t YtoPixel(Double_t y) const =0
TAttTextEditor::DoLiveAlpha
virtual void DoLiveAlpha(Int_t a)
Slot to set alpha value online.
Definition: TAttTextEditor.cxx:308
kSlider2
@ kSlider2
Definition: TGSlider.h:57
TGNumberFormat::kNESReal
@ kNESReal
Definition: TGNumberEntry.h:51
TGComboBox::Select
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
TColor.h
TColor::Number2Pixel
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition: TColor.cxx:2013
TGHorizontalFrame
Definition: TGFrame.h:423
TGNumberEntryField::SetNumber
virtual void SetNumber(Double_t val)
Set the numeric value (floating point representation).
Definition: TGNumberEntry.cxx:1119
TCanvas.h
TGedFrame::Update
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition: TGedFrame.cxx:73
TGFrame
Definition: TGFrame.h:105
TGSlider::SetPosition
virtual void SetPosition(Int_t pos)
Definition: TGSlider.h:105
Color_t
short Color_t
Definition: RtypesCore.h:83
TObject::InheritsFrom
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
b
#define b(i)
Definition: RSha256.hxx:118
TColor::GetAlpha
Float_t GetAlpha() const
Definition: TColor.h:63
TVirtualPad::GetY2
virtual Double_t GetY2() const =0
bool
TPaveLabel.h
MakeTitle
std::string MakeTitle(std::string_view version, std::string_view histname, std::string_view title, std::string_view axis)
Definition: histspeedtest.cxx:124
ETextWid
ETextWid
Definition: TAttTextEditor.cxx:41
kCOL_SELCHANGED
@ kCOL_SELCHANGED
Definition: WidgetMessageTypes.h:85
TROOT.h
TGedFrame::fAvoidSignal
Bool_t fAvoidSignal
Definition: TGedFrame.h:56
TGedEditor::GetPad
virtual TVirtualPad * GetPad() const
Definition: TGedEditor.h:89
kScaleNo
@ kScaleNo
Definition: TGSlider.h:60
kFONT_SIZE
@ kFONT_SIZE
Definition: TAttTextEditor.cxx:49
TAttTextEditor::ConnectSignals2Slots
void ConnectSignals2Slots()
Connect signals to slots.
Definition: TAttTextEditor.cxx:109
TCanvas::SupportAlpha
static Bool_t SupportAlpha()
Static function returning "true" if transparency is supported.
Definition: TCanvas.cxx:2487
TAttTextEditor::SetModel
virtual void SetModel(TObject *obj)
Pick up the values of used text attributes.
Definition: TAttTextEditor.cxx:123
kLHintsCenterY
@ kLHintsCenterY
Definition: TGLayout.h:41
TColor
Definition: TColor.h:19
TBox::GetY1
Double_t GetY1() const
Definition: TBox.h:52
TVirtualPad::AbsPixeltoY
virtual Double_t AbsPixeltoY(Int_t py)=0
TAttTextEditor::BuildTextAlignComboBox
static TGComboBox * BuildTextAlignComboBox(TGFrame *parent, Int_t id)
Create text align combo box.
Definition: TAttTextEditor.cxx:260
a
auto * a
Definition: textangle.C:12
TAttTextEditor::DoAlphaField
virtual void DoAlphaField()
Slot to set the alpha value from the entry field.
Definition: TAttTextEditor.cxx:280
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TGNumberEntryField::GetNumber
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
Definition: TGNumberEntry.cxx:1249
Long_t
long Long_t
Definition: RtypesCore.h:54
TAttTextEditor::DoAlpha
virtual void DoAlpha()
Slot to set the alpha value.
Definition: TAttTextEditor.cxx:294
TGLayoutHints
Definition: TGLayout.h:57
TBox::GetY2
Double_t GetY2() const
Definition: TBox.h:53
TGLabel::Disable
virtual void Disable(Bool_t on=kTRUE)
Definition: TGLabel.h:97
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TAttTextEditor::fAlpha
TGHSlider * fAlpha
Definition: TAttTextEditor.h:41
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TColor::GetColor
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:1766
TAttTextEditor::TAttTextEditor
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.
Definition: TAttTextEditor.cxx:53
TAttTextEditor::~TAttTextEditor
virtual ~TAttTextEditor()
Destructor of text editor.
Definition: TAttTextEditor.cxx:102
TAttTextEditor
Definition: TAttTextEditor.h:33
TGNumberEntryField
Definition: TGNumberEntry.h:74
kFONT_STYLE
@ kFONT_STYLE
Definition: TAttTextEditor.cxx:50
TGComboBox
Definition: TGComboBox.h:67
TAttTextEditor::DoTextAlphaColor
virtual void DoTextAlphaColor(ULong_t p)
Slot connected to the color with alpha.
Definition: TAttTextEditor.cxx:182
kHorizontalFrame
@ kHorizontalFrame
Definition: GuiTypes.h:382
TAttTextEditor::DoTextColor
virtual void DoTextColor(Pixel_t color)
Slot connected to the marker color.
Definition: TAttTextEditor.cxx:166
TBox
Definition: TBox.h:22
TGedFrame
Definition: TGedFrame.h:33
TGLabel.h
TGedEditor::GetModel
virtual TObject * GetModel() const
Definition: TGedEditor.h:90
TQObject::Connect
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:864
TVirtualPad
Definition: TVirtualPad.h:50
TAttTextEditor::fAttText
TAttText * fAttText
Definition: TAttTextEditor.h:36
kCOLOR
@ kCOLOR
Definition: TAttTextEditor.cxx:48
kC_COMMAND
@ kC_COMMAND
Definition: WidgetMessageTypes.h:39
TColor::GetColorTransparent
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:1976
TObject
Definition: TObject.h:37
TVirtualPad::GetY1
virtual Double_t GetY1() const =0
kALPHA
@ kALPHA
Definition: TAttTextEditor.cxx:52
GET_SUBMSG
Int_t GET_SUBMSG(Long_t val)
Definition: WidgetMessageTypes.h:113
kCM_COMBOBOX
@ kCM_COMBOBOX
Definition: WidgetMessageTypes.h:46
TAttTextEditor::fAlphaField
TGNumberEntryField * fAlphaField
Definition: TAttTextEditor.h:42
TGColorSelect::SetColor
void SetColor(Pixel_t color, Bool_t emit=kTRUE)
Set color.
Definition: TGColorSelect.cxx:636
TGColorSelect
Definition: TGColorSelect.h:127
TAttTextEditor::fSizeCombo
TGComboBox * fSizeCombo
Definition: TAttTextEditor.h:38
TGNumberEntry.h
TGedFrame::fGedEditor
TGedEditor * fGedEditor
Definition: TGedFrame.h:54
kFONT_ALIGN
@ kFONT_ALIGN
Definition: TAttTextEditor.cxx:51
TGColorSelect.h
TGedFrame::fInit
Bool_t fInit
Definition: TGedFrame.h:53
TAttTextEditor::fTypeCombo
TGFontTypeComboBox * fTypeCombo
Definition: TAttTextEditor.h:37
Class
void Class()
Definition: Class.C:29
TGCompositeFrame
Definition: TGFrame.h:324
kALPHAFIELD
@ kALPHAFIELD
Definition: TAttTextEditor.cxx:53
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1102
TAttTextEditor::fColorSelect
TGColorSelect * fColorSelect
Definition: TAttTextEditor.h:40
gROOT
#define gROOT
Definition: TROOT.h:406
int
TColor::GetNumber
Int_t GetNumber() const
Definition: TColor.h:55