Logo ROOT   6.12/07
Reference Guide
TText.hxx
Go to the documentation of this file.
1 /// \file ROOT/TText.hxx
2 /// \ingroup Graf ROOT7
3 /// \author Olivier Couet <Olivier.Couet@cern.ch>
4 /// \date 2017-10-16
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6 /// is welcome!
7 
8 /*************************************************************************
9  * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 #ifndef ROOT7_TText
17 #define ROOT7_TText
18 
20 
21 #include <ROOT/TDrawable.hxx>
22 #include <ROOT/TPad.hxx>
23 #include <ROOT/TDisplayItem.hxx>
25 
26 #include <ROOT/TDrawingAttrs.hxx>
27 
28 #include <initializer_list>
29 #include <memory>
30 #include <string>
31 
32 namespace ROOT {
33 namespace Experimental {
34 
35 /** \class ROOT::Experimental::TText
36  A text.
37  */
38 
39 class TText {
40 private:
41  std::string fText{};
42 
43  /// Text's X position
44  double fX{0.};
45 
46  /// Text's Y position
47  double fY{0.};
48 
49 public:
50  TText() = default;
51 
52  TText(const std::string &str) : fText(str) {}
53 
54  void SetText(const std::string &txt) { fText = txt; }
55 
56  std::string GetText() const { return fText; }
57 
58  void SetPosition(double x, double y)
59  {
60  fX = x;
61  fY = y;
62  }
63 
64  double GetX() const { return fX; }
65 
66  double GetY() const { return fY; }
67 };
68 
69 class TextDrawingOpts : public TDrawingOptsBase<TextDrawingOpts> {
70 
71  TLineAttrs fLine{*this, "Text.Line", TColor::kBlack, TLineAttrs::Width{3}}; ///< The line attributes
72  TFillAttrs fFill{*this, "Text.Fill", TColor::kWhite}; ///< The fill attributes
73 
74 public:
75  TextDrawingOpts() = default;
76  explicit TextDrawingOpts(TPadBase &pad) : TDrawingOptsBase<TextDrawingOpts>(pad, "Text") {}
77  // fLine{*this, "Text.Line", TColor::kBlack, TLineAttrs::Width{3}},
78  // fAttr{*this, "Text.Fill", TColor::kWhite}
79  // {}
80 
81  /// The color of the line.
82  void SetLineColor(const TColor &col) { Update(fLine.fColor, col); }
83  TColor &GetLineColor() { return this->Get(fLine.fColor); }
84  // const TColor &GetLineColor() const { return this->Get(fLine.fColor); }
85 
86  /// The width of the line.
87  // void SetLineWidth(TLineAttrs::Width width) { this->Update(fLine.fWidth, width); }
88  // TLineAttrs::Width &GetLineWidth() { return this->Get(fLine.fWidth); }
89  // const TLineAttrs::Width GetLineWidth() const { return this->Get(fLine.fWidth); }
90 
91  /// The fill color
92  void SetFillColor(const TColor &col) { this->Update(fFill.fColor, col); }
93  TColor &GetFillColor() { return this->Get(fFill.fColor); }
94  // const TColor &GetFillColor() const { return this->Get(fFill.fColor); }
95 };
96 
97 class TTextDrawable : public TDrawable {
98 private:
99  /// Text string to be drawn
100 
102 
103  /// Text attributes
105 
106 public:
107  TTextDrawable() = default;
108 
109  TTextDrawable(const std::shared_ptr<ROOT::Experimental::TText> &txt, TPadBase &pad)
110  : TDrawable(), fText(txt), fOpts(pad)
111  {
112  }
113 
114  TextDrawingOpts &GetOptions() { return fOpts; }
115  const TextDrawingOpts &GetOptions() const { return fOpts; }
116 
118  {
120  }
121 };
122 
123 inline std::unique_ptr<ROOT::Experimental::TTextDrawable>
124 GetDrawable(const std::shared_ptr<ROOT::Experimental::TText> &text, TPadBase &pad)
125 {
126  return std::make_unique<ROOT::Experimental::TTextDrawable>(text, pad);
127 }
128 
129 } // namespace Experimental
130 } // namespace ROOT
131 
132 #endif
TText(const std::string &str)
Definition: TText.hxx:52
TextDrawingOpts & GetOptions()
Definition: TText.hxx:114
double fX
Text&#39;s X position.
Definition: TText.hxx:44
Base class for drawable entities: objects that can be painted on a TPad.
Definition: TDrawable.hxx:36
void SetPosition(double x, double y)
Definition: TText.hxx:58
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
Base class for drawing options.
void SetFillColor(const TColor &col)
The width of the line.
Definition: TText.hxx:92
const TextDrawingOpts & GetOptions() const
Definition: TText.hxx:115
Double_t x[n]
Definition: legend1.C:17
Base class for graphic containers for TDrawable-s.
Definition: TPad.hxx:41
TTextDrawable(const std::shared_ptr< ROOT::Experimental::TText > &txt, TPadBase &pad)
Definition: TText.hxx:109
double GetY() const
Definition: TText.hxx:66
static constexpr PredefinedRGB kBlack
Definition: TColor.hxx:189
double fY
Text&#39;s Y position.
Definition: TText.hxx:47
void SetLineColor(const TColor &col)
The color of the line.
Definition: TText.hxx:82
Abstract interface for painting a canvas.
TText * text
void SetText(const std::string &txt)
Definition: TText.hxx:54
Double_t y[n]
Definition: legend1.C:17
std::string GetText() const
Definition: TText.hxx:56
void Paint(Internal::TVirtualCanvasPainter &canv) final
Definition: TText.hxx:117
static constexpr PredefinedRGB kWhite
Definition: TColor.hxx:188
A color: Red|Green|Blue|Alpha, or a position in a TPalette.
Definition: TColor.hxx:27
std::unique_ptr< TPadDrawable > GetDrawable(std::unique_ptr< TPad > &&pad, TPadBase &parent)
Definition: TPad.hxx:237
double GetX() const
Definition: TText.hxx:64