Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
lineRStyle.cxx
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_v7
3 ///
4 /// This ROOT 7 example demonstrates how to customize RLine object using RStyle
5 /// "normal" coordinates' system.
6 ///
7 /// \macro_code
8 ///
9 /// \date 2019-10-04
10 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
11 /// is welcome!
12 /// \author Iliana Betsou
13 
14 #include "ROOT/RCanvas.hxx"
15 #include "ROOT/RText.hxx"
16 #include "ROOT/RLine.hxx"
17 #include "ROOT/RDirectory.hxx"
18 #include <string>
19 
20 using namespace ROOT::Experimental;
21 
22 void lineRStyle()
23 {
24  auto canvas = RCanvas::Create("Canvas Title");
25  double num = 0.3;
26 
27  for (int i=10; i>0; i--){
28  num = num + 0.05;
29 
30  canvas->Draw<RText>(std::to_string(i))->SetPos({.3_normal, 1_normal*num}).AttrText().SetSize(13).SetAlign(32).SetFont(52);
31 
32  auto line = canvas->Draw<RLine>(RPadPos(.32_normal,1_normal*num), RPadPos(.8_normal, 1_normal*num));
33 
34  line->SetId(std::string("obj") + std::to_string(i));
35  line->SetCssClass(std::string("user_class_") + std::to_string(i % 3));
36 
37  }
38 
39  auto style = std::make_shared<RStyle>();
40 
41  style->AddBlock(".user_class_1").AddInt("line_style", 4); // all lines with user_class_1 should get style 1
42  style->AddBlock(".user_class_2").AddDouble("line_width", 5.); // all lines with user_class_2 should get line width 5
43  style->AddBlock("#obj7").AddString("line_color_rgb", "0000FF"); // line with id obj7 should be red
44 
45  style->AddBlock("line").AddString("line_color_rgb", "FF0000"); // all lines should get red color
46 
47  canvas->UseStyle(style);
48 
49  canvas->Show();
50 
51  // after leaving function scope style will be destroyed, one has to preserve it extra
52  RDirectory::Heap().Add("custom_style", style);
53 }