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 "TVirtualX.h"
28#include "TPaveLabel.h"
29#include "TGLabel.h"
30#include "TGSlider.h"
31#include "TGNumberEntry.h"
32#include "TCanvas.h"
33#include "TROOT.h"
34
35#include <cstdio>
36
37
46
47////////////////////////////////////////////////////////////////////////////////
48/// Constructor of text attributes GUI.
49
51 Int_t height, UInt_t options, Pixel_t back)
52 : TGedFrame(p, width, height, options | kVerticalFrame, back)
53{
54 fPriority = 3;
55
56 fAttText = 0;
57
58 MakeTitle("Text");
59
60 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
61 fColorSelect = new TGColorSelect(f2, 0, kCOLOR);
62 f2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
65 f2->AddFrame(fSizeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
66 fSizeCombo->Resize(91, 20);
67 fSizeCombo->Associate(this);
68 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
70 fTypeCombo->Resize(137, 20);
73 fAlignCombo->Resize(137, 20);
75
76 TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
77 AddFrame(AlphaLabel,
79 TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
81 fAlpha->SetRange(0,1000);
86 fAlphaField->Resize(40,20);
87 if (!TCanvas::SupportAlpha()) {
89 AlphaLabel->Disable(kTRUE);
91 }
94}
95
96////////////////////////////////////////////////////////////////////////////////
97/// Destructor of text editor.
98
102
103////////////////////////////////////////////////////////////////////////////////
104/// Connect signals to slots.
105
107{
108 fAlpha->Connect("Released()","TAttTextEditor", this, "DoAlpha()");
109 fAlpha->Connect("PositionChanged(Int_t)","TAttTextEditor", this, "DoLiveAlpha(Int_t)");
110 fAlphaField->Connect("ReturnPressed()","TAttTextEditor", this, "DoAlphaField()");
111 fAlpha->Connect("Pressed()","TAttTextEditor", this, "GetCurAlpha()");
112 fColorSelect->Connect("ColorSelected(Pixel_t)", "TAttTextEditor", this, "DoTextColor(Pixel_t)");
113 fColorSelect->Connect("AlphaColorSelected(ULongptr_t)", "TAttTextEditor", this, "DoTextAlphaColor(ULongptr_t)");
114 fInit = kFALSE;
115}
116
117////////////////////////////////////////////////////////////////////////////////
118/// Pick up the values of used text attributes.
119
121{
122 TAttText *atttext = dynamic_cast<TAttText *>(obj);
123 if (!atttext) return;
124
125 fAttText = atttext;
127
129
131 Float_t dy;
132
133 if (obj->InheritsFrom(TPaveLabel::Class())) {
134 TBox *pl = (TBox*)obj;
135 dy = s * (pl->GetY2() - pl->GetY1());
136 }
137 else
138 dy = s * (fGedEditor->GetPad()->GetY2() - fGedEditor->GetPad()->GetY1());
139
141 if (size > 50) size = 50;
142 if (size < 0) size = 0;
144
146
150
153
154 if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
155 fAlpha->SetPosition((Int_t)color->GetAlpha()*1000);
156 fAlphaField->SetNumber(color->GetAlpha());
157 }
158}
159
160////////////////////////////////////////////////////////////////////////////////
161/// Slot connected to the marker color.
162
164{
165 if (fAvoidSignal) return;
167
168 if (TColor *tcolor = gROOT->GetColor(TVirtualX::Pixel2Number(color))) {
169 fAlpha->SetPosition((Int_t)(tcolor->GetAlpha()*1000));
170 fAlphaField->SetNumber(tcolor->GetAlpha());
171 }
172
173 Update();
174}
175
176////////////////////////////////////////////////////////////////////////////////
177/// Slot connected to the color with alpha.
178
180{
181 TColor *color = (TColor *)p;
182
183 if (fAvoidSignal) return;
185 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
186 fAlphaField->SetNumber(color->GetAlpha());
187
188 Update();
189}
190
191////////////////////////////////////////////////////////////////////////////////
192/// Process message.
193
195{
196 if(!fGedEditor || !fGedEditor->GetModel()) return kTRUE;
197
198 Bool_t b = kFALSE;
199
200 if (GET_MSG(msg) == kC_COLORSEL && GET_SUBMSG(msg) == kCOL_SELCHANGED) {
201 if (parm1 != 0) fAttText->SetTextColor(TVirtualX::Pixel2Number(parm2));
202 b = kTRUE;
203 // SendMessage(fMsgWindow, msg, parm1, parm2);
204 }
205
206 if (GET_MSG(msg) == kC_COMMAND && GET_SUBMSG(msg) == kCM_COMBOBOX) {
207
208 if (parm1 == kFONT_SIZE) {
209 TVirtualPad* pad = fGedEditor->GetPad();
210 Float_t dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY(parm2);
211 Float_t textSize;
212
214 TBox *pl = (TBox*)fGedEditor->GetModel();
215 textSize = dy/(pl->GetY2() - pl->GetY1());
216 }
217 else
218 textSize = dy/(pad->GetY2() - pad->GetY1());
219
220 fAttText->SetTextSize(textSize);
221 b = kTRUE;
222 } else if (parm1 == kFONT_STYLE) {
223 Int_t fontPrec = fAttText->GetTextFont()%10;
224 fAttText->SetTextFont(parm2 * 10 + fontPrec);
225 b = kTRUE;
226 } else if (parm1 == kFONT_ALIGN) {
227 fAttText->SetTextAlign(parm2);
228 b = kTRUE;
229 }
230 }
231
232 if (b && !fAvoidSignal) Update();
233
234 return kTRUE;
235}
236
237////////////////////////////////////////////////////////////////////////////////
238/// Create text size combo box.
239
241{
242 char a[100];
243 TGComboBox *c = new TGComboBox(parent, id);
244
245 c->AddEntry("Default", 0);
246 for (int i = 1; i <= 50; i++) {
247 snprintf(a, 99, "%d", i);
248 c->AddEntry(a, i);
249 }
250
251 return c;
252}
253
254////////////////////////////////////////////////////////////////////////////////
255/// Create text align combo box.
256
258{
259 TGComboBox *c = new TGComboBox(parent, id);
260
261 c->AddEntry("11 Bottom, Left", 11);
262 c->AddEntry("21 Bottom, Middle", 21);
263 c->AddEntry("31 Bottom, Right", 31);
264 c->AddEntry("12 Middle, Left", 12);
265 c->AddEntry("22 Middle, Middle", 22);
266 c->AddEntry("32 Middle, Right", 32);
267 c->AddEntry("13 Top, Left", 13);
268 c->AddEntry("23 Top, Middle", 23);
269 c->AddEntry("33 Top, Right", 33);
270
271 return c;
272}
273
274////////////////////////////////////////////////////////////////////////////////
275/// Slot to set the alpha value from the entry field.
276
278{
279 if (fAvoidSignal) return;
280
281 if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
282 color->SetAlpha((Float_t)fAlphaField->GetNumber());
284 }
285 Update();
286}
287
288////////////////////////////////////////////////////////////////////////////////
289/// Slot to set the alpha value
290
292{
293 if (fAvoidSignal) return;
294
295 if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
296 color->SetAlpha((Float_t)fAlpha->GetPosition()/1000);
298 }
299 Update();
300}
301
302////////////////////////////////////////////////////////////////////////////////
303/// Slot to set alpha value online.
304
306{
307 if (fAvoidSignal) return;
309
310 if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
311 // In case the color is not transparent a new color is created.
312 if (color->GetAlpha() == 1.) {
313 fAttText->SetTextColor(TColor::GetColorTransparent(color->GetNumber(),0.99));
314 } else {
315 color->SetAlpha((Float_t)a/1000);
316 }
317 }
318 Update();
319}
320
321////////////////////////////////////////////////////////////////////////////////
322/// Slot to update alpha value on click on Slider
323
325{
326 if (fAvoidSignal) return;
327
328 if (TColor *color = gROOT->GetColor(fAttText->GetTextColor())) {
329 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
330 fAlphaField->SetNumber(color->GetAlpha());
331 }
332 Update();
333}
@ 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
short Color_t
Color number (short)
Definition RtypesCore.h:100
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:90
unsigned long ULongptr_t
Unsigned integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:91
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
@ 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:417
Int_t GET_MSG(Long_t val)
@ kCM_COMBOBOX
@ kCOL_SELCHANGED
@ kC_COLORSEL
@ kC_COMMAND
Int_t GET_SUBMSG(Long_t val)
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:21
virtual Float_t GetTextSize() const
Return the text size.
Definition TAttText.h:39
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition TAttText.h:48
virtual Short_t GetTextAlign() const
Return the text alignment.
Definition TAttText.h:35
virtual Font_t GetTextFont() const
Return the text font.
Definition TAttText.h:38
virtual Color_t GetTextColor() const
Return the text color.
Definition TAttText.h:37
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:50
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:52
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:53
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:2505
The color creation and management class.
Definition TColor.h:23
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:1941
Float_t GetAlpha() const
Definition TColor.h:71
Int_t GetNumber() const
Definition TColor.h:63
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition TColor.cxx:2205
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:1111
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:599
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
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:108
virtual void SetRange(Int_t min, Int_t max)
Set slider range.
Definition TGSlider.cxx:97
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:42
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:548
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:53
virtual Int_t YtoPixel(Double_t y) const =0
virtual Double_t GetY1() const =0
virtual Double_t GetY2() const =0
virtual Double_t AbsPixeltoY(Double_t py)=0
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
static Int_t Pixel2Number(ULong_t pixel)
Static method returning color number for color specified by system dependent pixel value.