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 /** \class TAttTextEditor
14  \ingroup ged
15 
16 Implements GUI for editing text attributes.
17  color, font, font size and alignment
18 
19 */
20 
21 
22 #include "TAttTextEditor.h"
23 #include "TGedEditor.h"
24 #include "TGColorSelect.h"
25 #include "TGComboBox.h"
26 #include "TColor.h"
27 #include "TPaveLabel.h"
28 #include "TGLabel.h"
29 #include "TGSlider.h"
30 #include "TGNumberEntry.h"
31 #include "TCanvas.h"
32 #include "TROOT.h"
33 #include "snprintf.h"
34 
36 
37 enum ETextWid {
44 };
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Constructor of text attributes GUI.
48 
50  Int_t height, UInt_t options, Pixel_t back)
51  : TGedFrame(p, width, height, options | kVerticalFrame, back)
52 {
53  fPriority = 3;
54 
55  fAttText = 0;
56 
57  MakeTitle("Text");
58 
59  TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
60  fColorSelect = new TGColorSelect(f2, 0, kCOLOR);
61  f2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
62  fColorSelect->Associate(this);
64  f2->AddFrame(fSizeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
65  fSizeCombo->Resize(91, 20);
66  fSizeCombo->Associate(this);
67  AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
69  fTypeCombo->Resize(137, 20);
70  AddFrame(fTypeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
72  fAlignCombo->Resize(137, 20);
73  AddFrame(fAlignCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
74 
75  TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
76  AddFrame(AlphaLabel,
78  TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
79  fAlpha = new TGHSlider(f2a,100,kSlider2|kScaleNo,kALPHA);
80  fAlpha->SetRange(0,1000);
85  fAlphaField->Resize(40,20);
86  if (!TCanvas::SupportAlpha()) {
88  AlphaLabel->Disable(kTRUE);
90  }
93 }
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 /// Destructor of text editor.
97 
99 {
100 }
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 /// Connect signals to slots.
104 
106 {
107  fAlpha->Connect("Released()","TAttTextEditor", this, "DoAlpha()");
108  fAlpha->Connect("PositionChanged(Int_t)","TAttTextEditor", this, "DoLiveAlpha(Int_t)");
109  fAlphaField->Connect("ReturnPressed()","TAttTextEditor", this, "DoAlphaField()");
110  fAlpha->Connect("Pressed()","TAttTextEditor", this, "GetCurAlpha()");
111  fColorSelect->Connect("ColorSelected(Pixel_t)", "TAttTextEditor", this, "DoTextColor(Pixel_t)");
112  fColorSelect->Connect("AlphaColorSelected(ULong_t)", "TAttTextEditor", this, "DoTextAlphaColor(ULong_t)");
113  fInit = kFALSE;
114 }
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 /// Pick up the values of used text attributes.
118 
120 {
121  TAttText *atttext = dynamic_cast<TAttText *>(obj);
122  if (!atttext) return;
123 
124  fAttText = atttext;
126 
128 
130  Float_t dy;
131 
132  if (obj->InheritsFrom(TPaveLabel::Class())) {
133  TBox *pl = (TBox*)obj;
134  dy = s * (pl->GetY2() - pl->GetY1());
135  }
136  else
137  dy = s * (fGedEditor->GetPad()->GetY2() - fGedEditor->GetPad()->GetY1());
138 
140  if (size > 50) size = 50;
141  if (size < 0) size = 0;
143 
145 
149 
152 
153  if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
154  fAlpha->SetPosition((Int_t)color->GetAlpha()*1000);
155  fAlphaField->SetNumber(color->GetAlpha());
156  }
157 }
158 
159 ////////////////////////////////////////////////////////////////////////////////
160 /// Slot connected to the marker color.
161 
163 {
164  if (fAvoidSignal) return;
166 
167  if (TColor *tcolor = gROOT->GetColor(TColor::GetColor(color))) {
168  fAlpha->SetPosition((Int_t)(tcolor->GetAlpha()*1000));
169  fAlphaField->SetNumber(tcolor->GetAlpha());
170  }
171 
172  Update();
173 }
174 
175 ////////////////////////////////////////////////////////////////////////////////
176 /// Slot connected to the color with alpha.
177 
179 {
180  TColor *color = (TColor *)p;
181 
182  if (fAvoidSignal) return;
183  fAttText->SetTextColor(color->GetNumber());
184  fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
185  fAlphaField->SetNumber(color->GetAlpha());
186 
187  Update();
188 }
189 
190 ////////////////////////////////////////////////////////////////////////////////
191 /// Process message.
192 
194 {
195  if(!fGedEditor || !fGedEditor->GetModel()) return kTRUE;
196 
197  Bool_t b = kFALSE;
198 
199  if (GET_MSG(msg) == kC_COLORSEL && GET_SUBMSG(msg) == kCOL_SELCHANGED) {
200  if (parm1 != 0) fAttText->SetTextColor(TColor::GetColor(parm2));
201  b = kTRUE;
202  // SendMessage(fMsgWindow, msg, parm1, parm2);
203  }
204 
205  if (GET_MSG(msg) == kC_COMMAND && GET_SUBMSG(msg) == kCM_COMBOBOX) {
206 
207  if (parm1 == kFONT_SIZE) {
208  TVirtualPad* pad = fGedEditor->GetPad();
209  Float_t dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY(parm2);
210  Float_t textSize;
211 
213  TBox *pl = (TBox*)fGedEditor->GetModel();
214  textSize = dy/(pl->GetY2() - pl->GetY1());
215  }
216  else
217  textSize = dy/(pad->GetY2() - pad->GetY1());
218 
219  fAttText->SetTextSize(textSize);
220  b = kTRUE;
221  } else if (parm1 == kFONT_STYLE) {
222  Int_t fontPrec = fAttText->GetTextFont()%10;
223  fAttText->SetTextFont(parm2 * 10 + fontPrec);
224  b = kTRUE;
225  } else if (parm1 == kFONT_ALIGN) {
226  fAttText->SetTextAlign(parm2);
227  b = kTRUE;
228  }
229  }
230 
231  if (b && !fAvoidSignal) Update();
232 
233  return kTRUE;
234 }
235 
236 ////////////////////////////////////////////////////////////////////////////////
237 /// Create text size combo box.
238 
240 {
241  char a[100];
242  TGComboBox *c = new TGComboBox(parent, id);
243 
244  c->AddEntry("Default", 0);
245  for (int i = 1; i <= 50; i++) {
246  snprintf(a, 99, "%d", i);
247  c->AddEntry(a, i);
248  }
249 
250  return c;
251 }
252 
253 ////////////////////////////////////////////////////////////////////////////////
254 /// Create text align combo box.
255 
257 {
258  TGComboBox *c = new TGComboBox(parent, id);
259 
260  c->AddEntry("11 Bottom, Left", 11);
261  c->AddEntry("21 Bottom, Middle", 21);
262  c->AddEntry("31 Bottom, Right", 31);
263  c->AddEntry("12 Middle, Left", 12);
264  c->AddEntry("22 Middle, Middle", 22);
265  c->AddEntry("32 Middle, Right", 32);
266  c->AddEntry("13 Top, Left", 13);
267  c->AddEntry("23 Top, Middle", 23);
268  c->AddEntry("33 Top, Right", 33);
269 
270  return c;
271 }
272 
273 ////////////////////////////////////////////////////////////////////////////////
274 /// Slot to set the alpha value from the entry field.
275 
277 {
278  if (fAvoidSignal) return;
279 
280  if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
281  color->SetAlpha((Float_t)fAlphaField->GetNumber());
283  }
284  Update();
285 }
286 
287 ////////////////////////////////////////////////////////////////////////////////
288 /// Slot to set the alpha value
289 
291 {
292  if (fAvoidSignal) return;
293 
294  if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
295  color->SetAlpha((Float_t)fAlpha->GetPosition()/1000);
297  }
298  Update();
299 }
300 
301 ////////////////////////////////////////////////////////////////////////////////
302 /// Slot to set alpha value online.
303 
305 {
306  if (fAvoidSignal) return;
307  fAlphaField->SetNumber((Float_t)a/1000);
308 
309  if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
310  // In case the color is not transparent a new color is created.
311  if (color->GetAlpha() == 1.) {
312  fAttText->SetTextColor(TColor::GetColorTransparent(color->GetNumber(),0.99));
313  } else {
314  color->SetAlpha((Float_t)a/1000);
315  }
316  }
317  Update();
318 }
319 
320 ////////////////////////////////////////////////////////////////////////////////
321 /// Slot to update alpha value on click on Slider
322 
324 {
325  if (fAvoidSignal) return;
326 
327  if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
328  fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
329  fAlphaField->SetNumber(color->GetAlpha());
330  }
331  Update();
332 }
TGComboBox.h
c
#define c(i)
Definition: RSha256.hxx:101
TAttText
Text Attributes class.
Definition: TAttText.h:18
TAttTextEditor::GetCurAlpha
virtual void GetCurAlpha()
Slot to update alpha value on click on Slider.
Definition: TAttTextEditor.cxx:323
TAttTextEditor::ProcessMessage
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Process message.
Definition: TAttTextEditor.cxx:193
GET_MSG
Int_t GET_MSG(Long_t val)
Definition: WidgetMessageTypes.h:110
TGWindow
ROOT GUI Window base class.
Definition: TGWindow.h:23
TAttTextEditor.h
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:100
TGFontTypeComboBox
The TGFontTypeComboBox is user callable and it creates a combobox for selecting the font.
Definition: TGComboBox.h:177
snprintf
#define snprintf
Definition: civetweb.c:1540
kC_COLORSEL
@ kC_COLORSEL
Definition: WidgetMessageTypes.h:75
TAttTextEditor::fAlignCombo
TGComboBox * fAlignCombo
font aligh combo box
Definition: TAttTextEditor.h:30
TGSlider::GetPosition
virtual Int_t GetPosition() const
Definition: TGSlider.h:83
TGSlider.h
kLHintsTop
@ kLHintsTop
Definition: TGLayout.h:27
Pixel_t
ULong_t Pixel_t
Pixel value.
Definition: GuiTypes.h:40
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TAttText::GetTextColor
virtual Color_t GetTextColor() const
Return the text color.
Definition: TAttText.h:34
TAttText::SetTextColor
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition: TAttText.h:43
TAttTextEditor::BuildFontSizeComboBox
static TGComboBox * BuildFontSizeComboBox(TGFrame *parent, Int_t id)
Create text size combo box.
Definition: TAttTextEditor.cxx:239
kVerticalFrame
@ kVerticalFrame
Definition: GuiTypes.h:381
kLHintsLeft
@ kLHintsLeft
Definition: TGLayout.h:24
TGLabel
This class handles GUI labels.
Definition: TGLabel.h:24
TGedEditor.h
TGSlider::SetRange
virtual void SetRange(Int_t min, Int_t max)
Definition: TGSlider.h:75
TGHSlider
Concrete class for horizontal slider.
Definition: TGSlider.h:128
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
Non-negative number.
Definition: TGNumberEntry.h:42
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
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:304
kSlider2
@ kSlider2
Definition: TGSlider.h:31
TGNumberFormat::kNESReal
@ kNESReal
Real number.
Definition: TGNumberEntry.h:30
TAttText::SetTextSize
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition: TAttText.h:46
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:456
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:2022
TGHorizontalFrame
A composite frame that layout their children in horizontal way.
Definition: TGFrame.h:386
TGNumberEntryField::SetNumber
virtual void SetNumber(Double_t val)
Set the numeric value (floating point representation).
Definition: TGNumberEntry.cxx:1115
TAttText::GetTextSize
virtual Float_t GetTextSize() const
Return the text size.
Definition: TAttText.h:36
TCanvas.h
TGedFrame::Update
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition: TGedFrame.cxx:72
TGFrame
Definition: TGFrame.h:80
TGSlider::SetPosition
virtual void SetPosition(Int_t pos)
Definition: TGSlider.h:79
Color_t
short Color_t
Definition: RtypesCore.h:92
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:100
TColor::GetAlpha
Float_t GetAlpha() const
Definition: TColor.h:63
TVirtualPad::GetY2
virtual Double_t GetY2() const =0
bool
TPaveLabel.h
ETextWid
ETextWid
Definition: TAttTextEditor.cxx:37
kCOL_SELCHANGED
@ kCOL_SELCHANGED
Definition: WidgetMessageTypes.h:77
TROOT.h
TGedFrame::fAvoidSignal
Bool_t fAvoidSignal
flag for executing slots
Definition: TGedFrame.h:50
TGedEditor::GetPad
virtual TVirtualPad * GetPad() const
Definition: TGedEditor.h:78
kScaleNo
@ kScaleNo
Definition: TGSlider.h:34
kFONT_SIZE
@ kFONT_SIZE
Definition: TAttTextEditor.cxx:39
TAttTextEditor::ConnectSignals2Slots
void ConnectSignals2Slots()
Connect signals to slots.
Definition: TAttTextEditor.cxx:105
TCanvas::SupportAlpha
static Bool_t SupportAlpha()
Static function returning "true" if transparency is supported.
Definition: TCanvas.cxx:2489
TAttTextEditor::SetModel
virtual void SetModel(TObject *obj)
Pick up the values of used text attributes.
Definition: TAttTextEditor.cxx:119
TAttText::GetTextFont
virtual Font_t GetTextFont() const
Return the text font.
Definition: TAttText.h:35
kLHintsCenterY
@ kLHintsCenterY
Definition: TGLayout.h:28
TColor
The color creation and management class.
Definition: TColor.h:19
TBox::GetY1
Double_t GetY1() const
Definition: TBox.h:52
size
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
TVirtualPad::AbsPixeltoY
virtual Double_t AbsPixeltoY(Int_t py)=0
TGWidget::Associate
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:72
TGFrame::Resize
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:605
TAttTextEditor::BuildTextAlignComboBox
static TGComboBox * BuildTextAlignComboBox(TGFrame *parent, Int_t id)
Create text align combo box.
Definition: TAttTextEditor.cxx:256
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:276
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:101
TGNumberEntryField::GetNumber
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
Definition: TGNumberEntry.cxx:1245
Long_t
long Long_t
Definition: RtypesCore.h:54
TAttTextEditor::DoAlpha
virtual void DoAlpha()
Slot to set the alpha value.
Definition: TAttTextEditor.cxx:290
TGLayoutHints
This class describes layout hints used by the layout classes.
Definition: TGLayout.h:50
TBox::GetY2
Double_t GetY2() const
Definition: TBox.h:53
TGLabel::Disable
virtual void Disable(Bool_t on=kTRUE)
Definition: TGLabel.h:89
TAttTextEditor::fAlpha
TGHSlider * fAlpha
fill opacity
Definition: TAttTextEditor.h:32
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TAttText::GetTextAlign
virtual Short_t GetTextAlign() const
Return the text alignment.
Definition: TAttText.h:32
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:1775
TGedFrame::MakeTitle
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:95
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:49
TAttTextEditor::~TAttTextEditor
virtual ~TAttTextEditor()
Destructor of text editor.
Definition: TAttTextEditor.cxx:98
TAttTextEditor
Implements GUI for editing text attributes.
Definition: TAttTextEditor.h:24
TGNumberEntryField
Definition: TGNumberEntry.h:65
kFONT_STYLE
@ kFONT_STYLE
Definition: TAttTextEditor.cxx:40
unsigned int
TGComboBox
A combobox (also known as a drop down listbox) allows the selection of one item out of a list of item...
Definition: TGComboBox.h:47
TAttTextEditor::DoTextAlphaColor
virtual void DoTextAlphaColor(ULong_t p)
Slot connected to the color with alpha.
Definition: TAttTextEditor.cxx:178
kHorizontalFrame
@ kHorizontalFrame
Definition: GuiTypes.h:382
TAttTextEditor::DoTextColor
virtual void DoTextColor(Pixel_t color)
Slot connected to the marker color.
Definition: TAttTextEditor.cxx:162
TBox
Create a Box.
Definition: TBox.h:22
TGedFrame
Base frame for implementing GUI - a service class.
Definition: TGedFrame.h:27
TGLabel.h
TGedEditor::GetModel
virtual TObject * GetModel() const
Definition: TGedEditor.h:79
TAttText::SetTextAlign
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition: TAttText.h:41
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:869
TVirtualPad
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:51
TGTextEntry::SetEnabled
void SetEnabled(Bool_t flag=kTRUE)
Definition: TGTextEntry.h:149
TAttTextEditor::fAttText
TAttText * fAttText
text attribute object
Definition: TAttTextEditor.h:27
kCOLOR
@ kCOLOR
Definition: TAttTextEditor.cxx:38
kC_COMMAND
@ kC_COMMAND
Definition: WidgetMessageTypes.h:31
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:1985
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
TVirtualPad::GetY1
virtual Double_t GetY1() const =0
kALPHA
@ kALPHA
Definition: TAttTextEditor.cxx:42
GET_SUBMSG
Int_t GET_SUBMSG(Long_t val)
Definition: WidgetMessageTypes.h:111
kCM_COMBOBOX
@ kCM_COMBOBOX
Definition: WidgetMessageTypes.h:38
TAttTextEditor::fAlphaField
TGNumberEntryField * fAlphaField
Definition: TAttTextEditor.h:33
TGColorSelect::SetColor
void SetColor(Pixel_t color, Bool_t emit=kTRUE)
Set color.
Definition: TGColorSelect.cxx:654
TGColorSelect
Like a checkbutton but instead of the check mark there is color area with a little down arrow.
Definition: TGColorSelect.h:104
TAttTextEditor::fSizeCombo
TGComboBox * fSizeCombo
font size combo box
Definition: TAttTextEditor.h:29
TGNumberEntry.h
TGedFrame::fGedEditor
TGedEditor * fGedEditor
manager of this frame
Definition: TGedFrame.h:48
kFONT_ALIGN
@ kFONT_ALIGN
Definition: TAttTextEditor.cxx:41
TGCompositeFrame::TGCompositeFrame
TGCompositeFrame(const TGCompositeFrame &)=delete
TGColorSelect.h
TGedFrame::fInit
Bool_t fInit
init flag for setting signals/slots
Definition: TGedFrame.h:47
TAttTextEditor::fTypeCombo
TGFontTypeComboBox * fTypeCombo
font style combo box
Definition: TAttTextEditor.h:28
Class
void Class()
Definition: Class.C:29
TGCompositeFrame
The base class for composite widgets (menu bars, list boxes, etc.).
Definition: TGFrame.h:287
TGedFrame::fPriority
Int_t fPriority
location in GedEditor
Definition: TGedFrame.h:53
kALPHAFIELD
@ kALPHAFIELD
Definition: TAttTextEditor.cxx:43
TAttText::SetTextFont
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition: TAttText.h:45
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1117
TAttTextEditor::fColorSelect
TGColorSelect * fColorSelect
color selection widget
Definition: TAttTextEditor.h:31
TGSlider::SetEnabled
virtual void SetEnabled(Bool_t flag=kTRUE)
Definition: TGSlider.h:72
gROOT
#define gROOT
Definition: TROOT.h:406
int
TColor::GetNumber
Int_t GetNumber() const
Definition: TColor.h:55