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));
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");
79 fAlpha->SetRange(0,1000);
84 fAlphaField->Resize(40,20);
85 if (!TCanvas::SupportAlpha()) {
87 AlphaLabel->Disable(kTRUE);
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
125
127
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;
142
144
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;
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;
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
200 b = kTRUE;
201 // SendMessage(fMsgWindow, msg, parm1, parm2);
202 }
203
205
206 if (parm1 == kFONT_SIZE) {
208 Float_t dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY(parm2);
210
211 if (fGedEditor->GetModel()->InheritsFrom(TPaveLabel::Class())) {
213 textSize = dy/(pl->GetY2() - pl->GetY1());
214 }
215 else
216 textSize = dy/(pad->GetY2() - pad->GetY1());
217
219 b = kTRUE;
220 } else if (parm1 == kFONT_STYLE) {
223 b = kTRUE;
224 } else if (parm1 == kFONT_ALIGN) {
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());
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);
296 }
297 Update();
298}
299
300////////////////////////////////////////////////////////////////////////////////
301/// Slot to set alpha value online.
302
304{
305 if (fAvoidSignal) return;
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:381
@ kHorizontalFrame
Definition GuiTypes.h:382
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
#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
short Color_t
Color number (short)
Definition RtypesCore.h:99
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
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kALPHAFIELD
@ kCOLOR
@ kALPHA
@ kALPHAFIELD
@ kFONT_STYLE
@ kCOLOR
@ kALPHA
@ kFONT_SIZE
@ kFONT_ALIGN
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
@ 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
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
#define gROOT
Definition TROOT.h:411
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.
Text Attributes class.
Definition TAttText.h:20
virtual Float_t GetTextSize() const
Return the text size.
Definition TAttText.h:38
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition TAttText.h:44
virtual Short_t GetTextAlign() const
Return the text alignment.
Definition TAttText.h:34
virtual Font_t GetTextFont() const
Return the text font.
Definition TAttText.h:37
virtual Color_t GetTextColor() const
Return the text color.
Definition TAttText.h:36
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:46
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:48
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:49
Create a Box.
Definition TBox.h:22
static Bool_t SupportAlpha()
Static function returning "true" if transparency is supported.
Definition TCanvas.cxx:2473
The color creation and management class.
Definition TColor.h:22
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition TColor.cxx:2445
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:1926
Float_t GetAlpha() const
Definition TColor.h:67
Int_t GetNumber() const
Definition TColor.h:59
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition TColor.cxx:2182
Like a checkbutton but instead of the check mark there is color area with a little down arrow.
void SetColor(Pixel_t color, Bool_t emit=kTRUE)
Set color.
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 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...
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:289
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
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition TGFrame.h:80
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:597
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
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
virtual void SetNumber(Double_t val, Bool_t emit=kTRUE)
Set the numeric value (floating point representation).
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
@ kNEANonNegative
Non-negative number.
@ kNESReal
Real number.
virtual Int_t GetPosition() const
Definition TGSlider.h:77
virtual void SetPosition(Int_t pos)
Set slider position.
Definition TGSlider.cxx:107
virtual void SetRange(Int_t min, Int_t max)
Set slider range.
Definition TGSlider.cxx:96
virtual void SetEnabled(Bool_t flag=kTRUE)
Definition TGSlider.h:72
void SetEnabled(Bool_t flag=kTRUE)
virtual void Associate(const TGWindow *w)
Definition TGWidget.h:72
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual TVirtualPad * GetPad() const
Definition TGedEditor.h:78
virtual TObject * GetModel() const
Definition TGedEditor.h:79
Base frame for implementing GUI - a service class.
Definition TGedFrame.h:27
TGedEditor * fGedEditor
manager of this frame
Definition TGedFrame.h:48
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:41
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:543
static TClass * Class()
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:865
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51