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
36
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));
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);
72 fAlignCombo->Resize(137, 20);
74
75 TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
76 AddFrame(AlphaLabel,
78 TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
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;
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;
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}
@ 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
Definition RtypesCore.h:92
long Longptr_t
Definition RtypesCore.h:82
unsigned long ULongptr_t
Definition RtypesCore.h:83
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
@ kALPHAFIELD
@ kCOLOR
@ kALPHA
@ kALPHAFIELD
@ kFONT_STYLE
@ kCOLOR
@ kALPHA
@ 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
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:405
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
Implements GUI for editing text attributes.
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.
virtual void SetModel(TObject *obj)
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 Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2)
Process message.
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.
TGNumberEntryField * fAlphaField
virtual ~TAttTextEditor()
Destructor of text editor.
TGColorSelect * fColorSelect
color selection widget
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:42
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:44
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:46
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:47
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:2455
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:2082
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:1823
Float_t GetAlpha() const
Definition TColor.h:64
Int_t GetNumber() const
Definition TColor.h:56
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition TColor.cxx:2034
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:287
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
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:605
Concrete class for horizontal slider.
Definition TGSlider.h:119
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:385
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
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:110
virtual void SetRange(Int_t min, Int_t max)
Set slider range.
Definition TGSlider.cxx:99
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:95
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition TGedFrame.cxx:72
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:525
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:869
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
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