Logo ROOT   6.18/05
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 "TPad.h"
37#include "TCanvas.h"
38#include "TROOT.h"
39
41
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
64 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
65 fColorSelect = new TGColorSelect(f2, 0, kCOLOR);
66 f2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
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));
74 fTypeCombo->Resize(137, 20);
77 fAlignCombo->Resize(137, 20);
79
80 TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
81 AddFrame(AlphaLabel,
83 TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
85 fAlpha->SetRange(0,1000);
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;
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) {
213 TVirtualPad* pad = fGedEditor->GetPad();
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;
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}
void Class()
Definition: Class.C:29
ULong_t Pixel_t
Definition: GuiTypes.h:39
#define b(i)
Definition: RSha256.hxx:100
#define c(i)
Definition: RSha256.hxx:101
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
unsigned long ULong_t
Definition: RtypesCore.h:51
long Long_t
Definition: RtypesCore.h:50
bool Bool_t
Definition: RtypesCore.h:59
short Color_t
Definition: RtypesCore.h:79
float Float_t
Definition: RtypesCore.h:53
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
ETextWid
@ kALPHAFIELD
@ kFONT_STYLE
@ kCOLOR
@ kALPHA
@ kFONT_SIZE
@ kFONT_ALIGN
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
@ kVerticalFrame
Definition: TGFrame.h:59
@ kHorizontalFrame
Definition: TGFrame.h:60
@ kLHintsLeft
Definition: TGLayout.h:31
@ kLHintsCenterY
Definition: TGLayout.h:35
@ kLHintsTop
Definition: TGLayout.h:34
@ kScaleNo
Definition: TGSlider.h:60
@ kSlider2
Definition: TGSlider.h:57
#define gROOT
Definition: TROOT.h:414
Int_t GET_MSG(Long_t val)
@ kCM_COMBOBOX
@ kCOL_SELCHANGED
@ kC_COLORSEL
@ kC_COMMAND
Int_t GET_SUBMSG(Long_t val)
#define snprintf
Definition: civetweb.c:1540
virtual void DoTextAlphaColor(ULong_t p)
Slot connected to the color with alpha.
TGHSlider * fAlpha
TGComboBox * fSizeCombo
static TGComboBox * BuildFontSizeComboBox(TGFrame *parent, Int_t id)
Create text size combo box.
virtual void SetModel(TObject *obj)
Pick up the values of used text attributes.
TGComboBox * fAlignCombo
virtual void GetCurAlpha()
Slot to update alpha value on click on Slider.
TAttText * fAttText
virtual void DoAlpha()
Slot to set the alpha value.
TGFontTypeComboBox * fTypeCombo
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.
virtual void DoLiveAlpha(Int_t a)
Slot to set alpha value online.
virtual void DoAlphaField()
Slot to set the alpha value from the entry field.
static TGComboBox * BuildTextAlignComboBox(TGFrame *parent, Int_t id)
Create text align combo box.
virtual void DoTextColor(Pixel_t color)
Slot connected to the marker color.
TGNumberEntryField * fAlphaField
virtual ~TAttTextEditor()
Destructor of text editor.
TGColorSelect * fColorSelect
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Process message.
void ConnectSignals2Slots()
Connect signals to slots.
Text Attributes class.
Definition: TAttText.h:18
virtual Float_t GetTextSize() const
Return the text size.
Definition: TAttText.h:36
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition: TAttText.h:41
virtual Short_t GetTextAlign() const
Return the text alignment.
Definition: TAttText.h:32
virtual Font_t GetTextFont() const
Return the text font.
Definition: TAttText.h:35
virtual Color_t GetTextColor() const
Return the text color.
Definition: TAttText.h:34
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition: TAttText.h:43
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition: TAttText.h:45
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition: TAttText.h:46
Create a Box.
Definition: TBox.h:24
Double_t GetY1() const
Definition: TBox.h:54
Double_t GetY2() const
Definition: TBox.h:55
static Bool_t SupportAlpha()
Static function returning "true" if transparency is supported.
Definition: TCanvas.cxx:2273
The color creation and management class.
Definition: TColor.h:19
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition: TColor.cxx:2003
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
Float_t GetAlpha() const
Definition: TColor.h:63
Int_t GetNumber() const
Definition: TColor.h:55
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:1966
void SetColor(Pixel_t color, Bool_t emit=kTRUE)
Set color.
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 AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
virtual void Disable(Bool_t on=kTRUE)
Definition: TGLabel.h:97
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
virtual void SetNumber(Double_t val)
Set the numeric value (floating point representation).
virtual Int_t GetPosition() const
Definition: TGSlider.h:109
virtual void SetPosition(Int_t pos)
Definition: TGSlider.h:105
virtual void SetRange(Int_t min, Int_t max)
Definition: TGSlider.h:101
virtual void SetEnabled(Bool_t flag=kTRUE)
Definition: TGSlider.h:98
void SetEnabled(Bool_t flag=kTRUE)
Definition: TGTextEntry.h:164
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:84
virtual TVirtualPad * GetPad() const
Definition: TGedEditor.h:89
virtual TObject * GetModel() const
Definition: TGedEditor.h:90
TGedEditor * fGedEditor
Definition: TGedFrame.h:54
Bool_t fInit
Definition: TGedFrame.h:53
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition: TGedFrame.cxx:73
Int_t fPriority
Definition: TGedFrame.h:59
Bool_t fAvoidSignal
Definition: TGedFrame.h:56
Mother of all ROOT objects.
Definition: TObject.h:37
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
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
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:50
virtual Int_t YtoPixel(Double_t y) const =0
virtual Double_t GetY1() const =0
virtual Double_t AbsPixeltoY(Int_t py)=0
virtual Double_t GetY2() const =0
static constexpr double s
auto * a
Definition: textangle.C:12