Logo ROOT   6.14/05
Reference Guide
TObjectDrawable.hxx
Go to the documentation of this file.
1 /// \file ROOT/TDisplayItem.h
2 /// \ingroup Base ROOT7
3 /// \author Sergey Linev
4 /// \date 2017-05-31
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_TObjectDrawable
17 #define ROOT7_TObjectDrawable
18 
19 #include <ROOT/TDrawable.hxx>
20 #include <ROOT/TDrawingOptsBase.hxx>
21 #include "ROOT/RStringView.hxx"
22 #include "ROOT/TDisplayItem.hxx"
23 
24 #include <memory>
25 #include <string>
26 #include <vector>
27 
28 class TObject;
29 
30 namespace ROOT {
31 namespace Experimental {
32 
33 class TPadBase;
34 
35 /// \class ROOT::Experimental::Internal::TObjectDrawingOpts Drawing options for TObject.
36 class TObjectDrawingOpts : public TDrawingOptsBase {
37  std::string fOpts; ///< The drawing options
38 
39 public:
40  TObjectDrawingOpts(const std::string &opts = "") : fOpts(opts) {}
41 
42  const std::string &GetOptionString() const { return fOpts; }
43 };
44 
45 /// \class ROOT::Experimental::Internal::TObjectDrawable
46 /// Provides v7 drawing facilities for TObject types (TGraph etc).
47 class TObjectDrawable : public TDrawableBase<TObjectDrawable> {
48  const std::shared_ptr<TObject> fObj; ///< The object to be painted
50 
51 public:
52  TObjectDrawable() = default;
53 
54  TObjectDrawable(const std::shared_ptr<TObject> &obj, const std::string &opt) : fObj(obj), fOpts(opt) {}
55 
56  /// Paint the object
57  void Paint(Internal::TPadPainter &canv) final;
58 
59  /// Fill menu items for the object
60  void PopulateMenu(TMenuItems &) final;
61 
62  /// Get the options - a string!
63  const TObjectDrawingOpts &GetOptions() const { return fOpts; }
64 
66 
67  /// Executes menu item
68  void Execute(const std::string &) final;
69 };
70 
71 class TObjectDisplayItem : public TDisplayItem {
72 protected:
73  const TObject *fObject; ///< object to draw
74  std::string fOption; ///< v6 draw options
75 public:
76  TObjectDisplayItem(TObject *obj, const std::string &opt) : fObject(obj), fOption(opt) {}
77 };
78 
79 } // namespace Experimental
80 } // namespace ROOT
81 
82 /// Interface to graphics taking a shared_ptr<TObject>.
83 /// Must be on global scope, else lookup cannot find it (no ADL for TObject).
84 inline std::unique_ptr<ROOT::Experimental::TObjectDrawable>
85 GetDrawable(const std::shared_ptr<TObject> &obj, const std::string &opt = "")
86 {
87  return std::make_unique<ROOT::Experimental::TObjectDrawable>(obj, opt);
88 }
89 
90 #endif
std::string fOpts
The drawing options.
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
TObjectDrawingOpts(const std::string &opts="")
TObjectDrawable(const std::shared_ptr< TObject > &obj, const std::string &opt)
Base class for graphic containers for TDrawable-s.
Definition: TPad.hxx:41
std::string fOption
v6 draw options
const std::shared_ptr< TObject > fObj
The object to be painted.
const std::string & GetOptionString() const
const TObjectDrawingOpts & GetOptions() const
Get the options - a string!
Abstract interface for object painting on the pad/canvas.
Definition: TPadPainter.hxx:37
TObjectDisplayItem(TObject *obj, const std::string &opt)
std::shared_ptr< TPadDrawable > GetDrawable(std::unique_ptr< TPad > &&pad, ARGS... args)
Definition: TPad.hxx:287
const TObject * fObject
object to draw
Mother of all ROOT objects.
Definition: TObject.h:37