Skip to content

Commit 673551b

Browse files
committed
Implement a simple box "RBox" for ROOT 7.
It has more attributes than TBox (round corners for instance).
1 parent e65b34a commit 673551b

File tree

3 files changed

+167
-0
lines changed

3 files changed

+167
-0
lines changed

graf2d/primitives/inc/LinkDef.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
#pragma link C++ class ROOT::Experimental::RDrawableBase<ROOT::Experimental::RLine>+;
3535
#pragma link C++ class ROOT::Experimental::Internal::TUniWeakPtr<ROOT::Experimental::RLine>+;
3636
#pragma link C++ class ROOT::Experimental::ROrdinaryDisplayItem<ROOT::Experimental::RLine>+;
37+
#pragma link C++ class ROOT::Experimental::RBox+;
38+
#pragma link C++ class ROOT::Experimental::RBox::DrawingOpts+;
39+
#pragma link C++ class ROOT::Experimental::RDrawableBase<ROOT::Experimental::RBox>+;
40+
#pragma link C++ class ROOT::Experimental::Internal::TUniWeakPtr<ROOT::Experimental::RBox>+;
41+
#pragma link C++ class ROOT::Experimental::ROrdinaryDisplayItem<ROOT::Experimental::RBox>+;
3742
#pragma link C++ class ROOT::Experimental::RMarker+;
3843
#pragma link C++ class ROOT::Experimental::RMarker::DrawingOpts+;
3944
#pragma link C++ class ROOT::Experimental::RDrawableBase<ROOT::Experimental::RMarker>+;
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/// \file ROOT/RBox.hxx
2+
/// \ingroup Graf ROOT7
3+
/// \author Olivier Couet <[email protected]>
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_RBox
17+
#define ROOT7_RBox
18+
19+
#include <ROOT/RDrawable.hxx>
20+
#include <ROOT/RDrawingAttr.hxx>
21+
#include <ROOT/RDrawingOptsBase.hxx>
22+
#include <ROOT/RPadPos.hxx>
23+
#include <ROOT/RPadPainter.hxx>
24+
25+
#include <initializer_list>
26+
#include <memory>
27+
28+
namespace ROOT {
29+
namespace Experimental {
30+
31+
/** \class ROOT::Experimental::RBox
32+
A simple box.
33+
*/
34+
35+
class RBox : public RDrawableBase<RBox> {
36+
public:
37+
38+
/** class ROOT::Experimental::RBox::DrawingOpts
39+
Drawing options for RBox.
40+
*/
41+
42+
class DrawingOpts: public RDrawingOptsBase {
43+
RDrawingAttr<RColor> fLineColor {*this, "Line.Color" , RColor::kBlack}; ///< The box line color.
44+
RDrawingAttr<int> fLineWidth {*this, "Line.Width" , 1}; ///< The box line width.
45+
RDrawingAttr<int> fLineStyle {*this, "Line.Style" , 1}; ///< The box line style.
46+
RDrawingAttr<float> fLineOpacity{*this, "Line.Opacity", 1.}; ///< The box line opacity.
47+
RDrawingAttr<RColor> fFillColor {*this, "Fill.Color" , RColor::kBlack}; ///< The box fill color.
48+
RDrawingAttr<int> fFillStyle {*this, "Fill.Style" , 1}; ///< The box line style.
49+
RDrawingAttr<float> fFillOpacity{*this, "Fill.Opacity", 1.}; ///< The box fill opacity.
50+
RDrawingAttr<int> fRoundWidth {*this, "Round.Width" , 0}; ///< Determines how wide the corners'rounding is.
51+
RDrawingAttr<int> fRoundHeight{*this, "Round.Height", 0}; ///< Determines how high the corners'rounding is.
52+
53+
public:
54+
/// The color of the box line.
55+
void SetLineColor(const RColor &col) { fLineColor = col; }
56+
RDrawingAttr<RColor> &GetLineColor() { return fLineColor; }
57+
const RColor &GetLineColor() const { return fLineColor.Get(); }
58+
59+
/// The width of the box line.
60+
void SetLineWidth(int width) { fLineWidth = width; }
61+
RDrawingAttr<int> &GetLineWidth() { return fLineWidth; }
62+
int GetLineWidth() const { return (int)fLineWidth; }
63+
64+
/// The style of the box line.
65+
void SetLineStyle(int style) { fLineStyle = style; }
66+
RDrawingAttr<int> &GetLineStyle() { return fLineStyle; }
67+
int GetLineStyle() const { return (int)fLineStyle; }
68+
69+
/// The opacity of the box line.
70+
void SetLineColorAlpha(float opacity) { fLineOpacity = opacity; }
71+
RDrawingAttr<float> &GetLineColorAlpha() { return fLineOpacity; }
72+
float GetLineColorAlpha() const { return (float)fLineOpacity; }
73+
74+
/// The color of the box fill.
75+
void SetFillColor(const RColor &col) { fFillColor = col; }
76+
RDrawingAttr<RColor> &GetFillColor() { return fFillColor; }
77+
const RColor &GetFillColor() const { return fFillColor.Get(); }
78+
79+
/// The style of the box fill.
80+
void SetFillStyle(int style) { fFillStyle = style; }
81+
RDrawingAttr<int> &GetFillStyle() { return fFillStyle; }
82+
int GetFillStyle() const { return (int)fFillStyle; }
83+
84+
/// How wide the corners'rounding is.
85+
void SetRoundWidth(int width) { fRoundWidth = width; }
86+
RDrawingAttr<int> &GetRoundWidth() { return fRoundWidth; }
87+
int GetRoundWidth() const { return (int)fRoundWidth; }
88+
89+
/// How high the corners'rounding is.
90+
void SetRoundHeight(int height) { fRoundHeight = height; }
91+
RDrawingAttr<int> &GetRoundHeight() { return fRoundHeight; }
92+
int GetRoundHeight() const { return (int)fRoundHeight; }
93+
94+
/// The opacity of the box fill.
95+
void SetFillColorAlpha(float opacity) { fFillOpacity = opacity; }
96+
RDrawingAttr<float> &GetFillColorAlpha() { return fFillOpacity; }
97+
float GetFillColorAlpha() const { return (float)fFillOpacity; }
98+
};
99+
100+
101+
private:
102+
103+
/// Box's coordinates
104+
105+
RPadPos fP1; ///< 1st point, bottom left
106+
RPadPos fP2; ///< 2nd point, top right
107+
108+
/// Box's attributes
109+
DrawingOpts fOpts;
110+
111+
public:
112+
113+
RBox() = default;
114+
115+
RBox(const RPadPos& p1, const RPadPos& p2) : fP1(p1), fP2(p2) {}
116+
117+
void SetP1(const RPadPos& p1) { fP1 = p1; }
118+
void SetP2(const RPadPos& p2) { fP2 = p2; }
119+
120+
const RPadPos& GetP1() const { return fP1; }
121+
const RPadPos& GetP2() const { return fP2; }
122+
123+
/// Get the drawing options.
124+
DrawingOpts &GetOptions() { return fOpts; }
125+
const DrawingOpts &GetOptions() const { return fOpts; }
126+
127+
void Paint(Internal::RPadPainter &topPad) final
128+
{
129+
topPad.AddDisplayItem(
130+
std::make_unique<ROOT::Experimental::ROrdinaryDisplayItem<ROOT::Experimental::RBox>>(this));
131+
}
132+
};
133+
134+
inline std::shared_ptr<ROOT::Experimental::RBox>
135+
GetDrawable(const std::shared_ptr<ROOT::Experimental::RBox> &box)
136+
{
137+
/// A RBox is a RDrawable itself.
138+
return box;
139+
}
140+
141+
} // namespace Experimental
142+
} // namespace ROOT
143+
144+
#endif

graf2d/primitives/v7/src/RBox.cxx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// \file RLine.cxx
2+
/// \ingroup Graf ROOT7
3+
/// \author Olivier Couet <[email protected]>
4+
/// \date 2018-03-08
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+
#include "ROOT/RBox.hxx"
17+
18+
using namespace ROOT::Experimental;

0 commit comments

Comments
 (0)