Logo ROOT   6.18/05
Reference Guide
RPadExtent.cxx
Go to the documentation of this file.
1/// \file RPadExtent.cxx
2/// \ingroup Gpad ROOT7
3/// \author Axel Naumann <axel@cern.ch>
4/// \date 2018-02-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-2018, 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/RPadExtent.hxx"
17
18#include <ROOT/RLogger.hxx>
19
20
21////////////////////////////////////////////////////////////////////////////////
22/// Initialize a RPadExtent from a style string.
23/// Syntax: X, Y
24/// where X and Y are a series of numbers separated by "+", where each number is
25/// followed by one of `px`, `user`, `normal` to specify an extent in pixel,
26/// user or normal coordinates. Spaces between any part is allowed.
27/// Example: `100 px + 0.1 user, 0.5 normal` is a `RPadExtent{100_px + 0.1_user, 0.5_normal}`.
28
30{
31 RPadExtent ret;
32 ret.SetFromAttrString(val, name);
33 return ret;
34}
35
36////////////////////////////////////////////////////////////////////////////////
37/// Convert a RPadExtent to a style string, matching what ExtentFromString can parse.
38
40{
41 std::string ret = ToAttributeString(extent.fHoriz);
42 ret += ", ";
43 ret += ToAttributeString(extent.fVert);
44 return ret;
45}
46
47////////////////////////////////////////////////////////////////////////////////
48/// Initialize a RPadHorizVert from a style string.
49/// Syntax: X, Y
50/// where X and Y are a series of numbers separated by "+", where each number is
51/// followed by one of `px`, `user`, `normal` to specify an extent in pixel,
52/// user or normal coordinates. Spaces between any part is allowed.
53/// Example: `100 px + 0.1 user, 0.5 normal` is a `RPadExtent{100_px + 0.1_user, 0.5_normal}`.
54
55void ROOT::Experimental::Internal::RPadHorizVert::SetFromAttrString(const std::string &val, const std::string &name)
56{
57 if (val.empty()) {
58 // Leave it at its default value.
59 return;
60 }
61
62 auto posComma = val.find(',');
63 if (posComma == std::string::npos) {
64 R__ERROR_HERE("Gpad") << "Parsing attribute for " << name << ": "
65 << "expected two coordinate dimensions but found only one in " << val;
66 return;
67 }
68 if (val.find(',', posComma + 1) != std::string::npos) {
69 R__ERROR_HERE("Gpad") << "Parsing attribute for " << name << ": "
70 << "found more than the expected two coordinate dimensions in " << val;
71 return;
72 }
73 fHoriz.SetFromAttrString(val.substr(0, posComma), name);
74 fVert.SetFromAttrString(val.substr(posComma + 1), name);
75}
#define R__ERROR_HERE(GROUP)
Definition: RLogger.hxx:183
char name[80]
Definition: TGX11.cxx:109
void SetFromAttrString(const std::string &val, const std::string &name)
Initialize a RPadLength from a style string.
Definition: RPadLength.cxx:163
std::string ToAttributeString(const RColor &val)
Return a std::string representation of a RColor, suitable as input to ColorFromString().
Definition: RColor.cxx:144
RColor FromAttributeString(const std::string &str, const std::string &name, RColor *)
Initialize a RColor from a string value.
Definition: RColor.cxx:132
void SetFromAttrString(const std::string &val, const std::string &name)
Initialize a RPadHorizVert from a style string.
Definition: RPadExtent.cxx:55
RPadLength fHoriz
Horizontal position.
Definition: RPadExtent.hxx:33
RPadLength fVert
Vertical position.
Definition: RPadExtent.hxx:34
An extent / size (horizontal and vertical) in a RPad.
Definition: RPadExtent.hxx:47