Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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
16Implements 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
35
44
45////////////////////////////////////////////////////////////////////////////////
46/// Constructor of text attributes GUI.
47
49 Int_t height, UInt_t options, Pixel_t back)
50 : TGedFrame(p, width, height, options | kVerticalFrame, back)
51{
52 fPriority = 3;
53
54 fAttText = 0;
55
56 MakeTitle("Text");
57
58 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
59 fColorSelect = new TGColorSelect(f2, 0, kCOLOR);
60 f2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
61 fColorSelect->Associate(this);
63 f2->AddFrame(fSizeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
64 fSizeCombo->Resize(91, 20);
65 fSizeCombo->Associate(this);
66 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
68 fTypeCombo->Resize(137, 20);
71 fAlignCombo->Resize(137, 20);
73
74 TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
75 AddFrame(AlphaLabel,
77 TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
79 fAlpha->SetRange(0,1000);
84 fAlphaField->Resize(40,20);
85 if (!TCanvas::SupportAlpha()) {
86 fAlpha->SetEnabled(kFALSE);
87 AlphaLabel->Disable(kTRUE);
88 fAlphaField->SetEnabled(kFALSE);
89 }
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Destructor of text editor.
96
100
101////////////////////////////////////////////////////////////////////////////////
102/// Connect signals to slots.
103
105{
106 fAlpha->Connect("Released()","TAttTextEditor", this, "DoAlpha()");
107 fAlpha->Connect("PositionChanged(Int_t)","TAttTextEditor", this, "DoLiveAlpha(Int_t)");
108 fAlphaField->Connect("ReturnPressed()","TAttTextEditor", this, "DoAlphaField()");
109 fAlpha->Connect("Pressed()","TAttTextEditor", this, "GetCurAlpha()");
110 fColorSelect->Connect("ColorSelected(Pixel_t)", "TAttTextEditor", this, "DoTextColor(Pixel_t)");
111 fColorSelect->Connect("AlphaColorSelected(ULong_t)", "TAttTextEditor", this, "DoTextAlphaColor(ULong_t)");
112 fInit = kFALSE;
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Pick up the values of used text attributes.
117
119{
120 TAttText *atttext = dynamic_cast<TAttText *>(obj);
121 if (!atttext) return;
122
123 fAttText = atttext;
125
126 fTypeCombo->Select(fAttText->GetTextFont() / 10);
127
128 Float_t s = fAttText->GetTextSize();
129 Float_t dy;
130
131 if (obj->InheritsFrom(TPaveLabel::Class())) {
132 TBox *pl = (TBox*)obj;
133 dy = s * (pl->GetY2() - pl->GetY1());
134 }
135 else
136 dy = s * (fGedEditor->GetPad()->GetY2() - fGedEditor->GetPad()->GetY1());
137
138 Int_t size = fGedEditor->GetPad()->YtoPixel(0.0) - fGedEditor->GetPad()->YtoPixel(dy);
139 if (size > 50) size = 50;
140 if (size < 0) size = 0;
141 fSizeCombo->Select(size, kFALSE);
142
143 fAlignCombo->Select(fAttText->GetTextAlign(), kFALSE);
144
145 Color_t c = fAttText->GetTextColor();
147 fColorSelect->SetColor(p, kFALSE);
148
151
152 if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
153 fAlpha->SetPosition((Int_t)color->GetAlpha()*1000);
154 fAlphaField->SetNumber(color->GetAlpha());
155 }
156}
157
158////////////////////////////////////////////////////////////////////////////////
159/// Slot connected to the marker color.
160
162{
163 if (fAvoidSignal) return;
164 fAttText->SetTextColor(TColor::GetColor(color));
165
166 if (TColor *tcolor = gROOT->GetColor(TColor::GetColor(color))) {
167 fAlpha->SetPosition((Int_t)(tcolor->GetAlpha()*1000));
168 fAlphaField->SetNumber(tcolor->GetAlpha());
169 }
170
171 Update();
172}
173
174////////////////////////////////////////////////////////////////////////////////
175/// Slot connected to the color with alpha.
176
178{
179 TColor *color = (TColor *)p;
180
181 if (fAvoidSignal) return;
182 fAttText->SetTextColor(color->GetNumber());
183 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
184 fAlphaField->SetNumber(color->GetAlpha());
185
186 Update();
187}
188
189////////////////////////////////////////////////////////////////////////////////
190/// Process message.
191
193{
194 if(!fGedEditor || !fGedEditor->GetModel()) return kTRUE;
195
196 Bool_t b = kFALSE;
197
198 if (GET_MSG(msg) == kC_COLORSEL && GET_SUBMSG(msg) == kCOL_SELCHANGED) {
199 if (parm1 != 0) fAttText->SetTextColor(TColor::GetColor(parm2));
200 b = kTRUE;
201 // SendMessage(fMsgWindow, msg, parm1, parm2);
202 }
203
204 if (GET_MSG(msg) == kC_COMMAND && GET_SUBMSG(msg) == kCM_COMBOBOX) {
205
206 if (parm1 == kFONT_SIZE) {
207 TVirtualPad* pad = fGedEditor->GetPad();
208 Float_t dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY(parm2);
209 Float_t textSize;
210
211 if (fGedEditor->GetModel()->InheritsFrom(TPaveLabel::Class())) {
212 TBox *pl = (TBox*)fGedEditor->GetModel();
213 textSize = dy/(pl->GetY2() - pl->GetY1());
214 }
215 else
216 textSize = dy/(pad->GetY2() - pad->GetY1());
217
218 fAttText->SetTextSize(textSize);
219 b = kTRUE;
220 } else if (parm1 == kFONT_STYLE) {
221 Int_t fontPrec = fAttText->GetTextFont()%10;
222 fAttText->SetTextFont(parm2 * 10 + fontPrec);
223 b = kTRUE;
224 } else if (parm1 == kFONT_ALIGN) {
225 fAttText->SetTextAlign(parm2);
226 b = kTRUE;
227 }
228 }
229
230 if (b && !fAvoidSignal) Update();
231
232 return kTRUE;
233}
234
235////////////////////////////////////////////////////////////////////////////////
236/// Create text size combo box.
237
239{
240 char a[100];
241 TGComboBox *c = new TGComboBox(parent, id);
242
243 c->AddEntry("Default", 0);
244 for (int i = 1; i <= 50; i++) {
245 snprintf(a, 99, "%d", i);
246 c->AddEntry(a, i);
247 }
248
249 return c;
250}
251
252////////////////////////////////////////////////////////////////////////////////
253/// Create text align combo box.
254
256{
257 TGComboBox *c = new TGComboBox(parent, id);
258
259 c->AddEntry("11 Bottom, Left", 11);
260 c->AddEntry("21 Bottom, Middle", 21);
261 c->AddEntry("31 Bottom, Right", 31);
262 c->AddEntry("12 Middle, Left", 12);
263 c->AddEntry("22 Middle, Middle", 22);
264 c->AddEntry("32 Middle, Right", 32);
265 c->AddEntry("13 Top, Left", 13);
266 c->AddEntry("23 Top, Middle", 23);
267 c->AddEntry("33 Top, Right", 33);
268
269 return c;
270}
271
272////////////////////////////////////////////////////////////////////////////////
273/// Slot to set the alpha value from the entry field.
274
276{
277 if (fAvoidSignal) return;
278
279 if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
280 color->SetAlpha((Float_t)fAlphaField->GetNumber());
281 fAlpha->SetPosition((Int_t)(fAlphaField->GetNumber()*1000));
282 }
283 Update();
284}
285
286////////////////////////////////////////////////////////////////////////////////
287/// Slot to set the alpha value
288
290{
291 if (fAvoidSignal) return;
292
293 if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
294 color->SetAlpha((Float_t)fAlpha->GetPosition()/1000);
295 fAlphaField->SetNumber((Float_t)fAlpha->GetPosition()/1000);
296 }
297 Update();
298}
299
300////////////////////////////////////////////////////////////////////////////////
301/// Slot to set alpha value online.
302
304{
305 if (fAvoidSignal) return;
306 fAlphaField->SetNumber((Float_t)a/1000);
307
308 if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
309 // In case the color is not transparent a new color is created.
310 if (color->GetAlpha() == 1.) {
311 fAttText->SetTextColor(TColor::GetColorTransparent(color->GetNumber(),0.99));
312 } else {
313 color->SetAlpha((Float_t)a/1000);
314 }
315 }
316 Update();
317}
318
319////////////////////////////////////////////////////////////////////////////////
320/// Slot to update alpha value on click on Slider
321
323{
324 if (fAvoidSignal) return;
325
326 if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
327 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
328 fAlphaField->SetNumber(color->GetAlpha());
329 }
330 Update();
331}
@ kVerticalFrame
Definition GuiTypes.h:382
@ kHorizontalFrame
Definition GuiTypes.h:383
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:41
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
long Longptr_t
Integer large enough to hold a pointer (platform-dependent).
Definition RtypesCore.h:89
unsigned long ULongptr_t
Unsigned integer large enough to hold a pointer (platform-dependent).
Definition RtypesCore.h:90
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
short Color_t
Color number (short).
Definition RtypesCore.h:99
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kALPHAFIELD
@ kCOLOR
@ kALPHA
@ kFONT_STYLE
@ kFONT_SIZE
@ kFONT_ALIGN
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsCenterY
Definition TGLayout.h:28
@ kLHintsTop
Definition TGLayout.h:27
@ kScaleNo
Definition TGSlider.h:34
@ kSlider2
Definition TGSlider.h:31
#define gROOT
Definition TROOT.h:417
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:1579
TGHSlider * fAlpha
fill opacity
TAttTextEditor(const TGWindow *p=nullptr, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor of text attributes GUI.
TGComboBox * fSizeCombo
font size combo box
static TGComboBox * BuildFontSizeComboBox(TGFrame *parent, Int_t id)
Create text size combo box.
void SetModel(TObject *obj) override
Pick up the values of used text attributes.
TGComboBox * fAlignCombo
font aligh combo box
virtual void GetCurAlpha()
Slot to update alpha value on click on Slider.
TAttText * fAttText
text attribute object
virtual void DoAlpha()
Slot to set the alpha value.
TGFontTypeComboBox * fTypeCombo
font style combo box
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.
virtual void DoTextAlphaColor(ULongptr_t p)
Slot connected to the color with alpha.
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.
Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override
Process message.
TGNumberEntryField * fAlphaField
TGColorSelect * fColorSelect
color selection widget
~TAttTextEditor() override
Destructor of text editor.
void ConnectSignals2Slots()
Connect signals to slots.
Create a Box.
Definition TBox.h:22
Double_t GetY1() const
Definition TBox.h:53
Double_t GetY2() const
Definition TBox.h:54
static Bool_t SupportAlpha()
Static function returning "true" if transparency is supported.
Definition TCanvas.cxx:2471
static Int_t GetColorTransparent(Int_t color, Float_t a)
static Int_t GetColor(const char *hexcolor)
static ULong_t Number2Pixel(Int_t ci)
Like a checkbutton but instead of the check mark there is color area with a little down arrow.
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
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
TGCompositeFrame(const TGCompositeFrame &)=delete
The TGFontTypeComboBox is user callable and it creates a combobox for selecting the font.
Definition TGComboBox.h:178
TGFrame(const TGFrame &)=delete
Concrete class for horizontal slider.
Definition TGSlider.h:119
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:387
This class handles GUI labels.
Definition TGLabel.h:24
virtual void Disable(Bool_t on=kTRUE)
Definition TGLabel.h:89
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
@ kNEANonNegative
Non-negative number.
@ kNESReal
Real number.
ROOT GUI Window base class.
Definition TGWindow.h:23
TGedEditor * fGedEditor
manager of this frame
Definition TGedFrame.h:48
TGedFrame(const TGedFrame &)=delete
Bool_t fInit
init flag for setting signals/slots
Definition TGedFrame.h:47
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition TGedFrame.cxx:94
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition TGedFrame.cxx:71
Int_t fPriority
location in GedEditor
Definition TGedFrame.h:53
Bool_t fAvoidSignal
flag for executing slots
Definition TGedFrame.h:50
Mother of all ROOT objects.
Definition TObject.h:42
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:549
static TClass * Class()
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
virtual Double_t GetY1() const =0
virtual Double_t GetY2() const =0
virtual Double_t AbsPixeltoY(Double_t py)=0