Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveLogo.cxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel
3
4/*************************************************************************
5 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include <ROOT/REveLogo.hxx>
13#include <ROOT/REveManager.hxx>
15
16#include "REveAssetDir.hxx"
17
18#include "TSystem.h"
19
20#include <nlohmann/json.hpp>
21
22using namespace ROOT::Experimental;
24
25/** \class REveLogo
26\ingroup REve
27A screen-space image for an overlay scene, such as an experiment logo or a
28watermark.
29
30The client draws it as a RenderCore ZLogo, a screen-space ZSprite. The size is
31in CSS pixels and does not change with the camera, and the outline comes from
32the image alpha. The logo can be moved, and resized from its corner grip, in
33the client only. Nothing is sent back, so each client places its own copy.
34
35Images are served from the directories registered with SetImageDir() and
36AddImageDir(), mapped under "eve-images/", as REveText maps its SDF fonts. An
37image is served from the first directory that has it. ROOT does not ship any
38images.
39*/
40
41std::string REveLogo::sImageDir;
42
43namespace {
44
45////////////////////////////////////////////////////////////////////////////////
46/// The image directories, served under "eve-images/".
47
48REveAssetDir &ImageDirs()
49{
50 static REveAssetDir s_dirs("eve-images/");
51 return s_dirs;
52}
53
54} // namespace
55
56////////////////////////////////////////////////////////////////////////////////
57/// Constructor. A `file` that IsRemote() accepts selects kRemote.
58
59REveLogo::REveLogo(std::string_view file, const Text_t *n, const Text_t *t) : REveElement(n, t), fFile(file)
60{
61 SetPickable(kTRUE); // otherwise it cannot be moved
62
63 if (IsRemote(fFile))
65}
66
67////////////////////////////////////////////////////////////////////////////////
68/// Is the file an absolute URL, to be fetched by the client directly?
69
70bool REveLogo::IsRemote(const std::string &f)
71{
72 return f.compare(0, 7, "http://") == 0 || f.compare(0, 8, "https://") == 0 || f.compare(0, 2, "//") == 0;
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// Check that `dir` is readable and return it with a trailing slash, or an
77/// empty string with an error from `tpfx`.
78
79static std::string CheckImageDir(std::string_view dir, const char *tpfx)
80{
81 std::string sanitized = REveAssetDir::NormalizeDir(std::string(dir));
82 if (sanitized.empty()) {
83 ::Error(tpfx, "Empty directory given.");
84 return {};
85 }
86 if (gSystem->AccessPathName(sanitized.c_str(), kReadPermission)) {
87 ::Error(tpfx, "Image directory '%s' does not exist or is not readable.", sanitized.c_str());
88 return {};
89 }
90 return sanitized;
91}
92
93////////////////////////////////////////////////////////////////////////////////
94/// Register the directory images are served from, mapped under "eve-images/".
95/// It replaces the directories added with AddImageDir(). Mirrors
96/// REveText::SetSdfFontDir; can be called before REveManager::Create().
97
98bool REveLogo::SetImageDir(std::string_view dir)
99{
100 std::string sanitized = CheckImageDir(dir, "REveLogo::SetImageDir");
101 if (sanitized.empty())
102 return false;
103
104 sImageDir = sanitized;
105 ImageDirs().SetUserDir(sImageDir);
106 return true;
107}
108
109////////////////////////////////////////////////////////////////////////////////
110/// Add a directory images are served from, searched after the ones registered
111/// before it. Can be called before REveManager::Create().
112
113bool REveLogo::AddImageDir(std::string_view dir)
114{
115 std::string sanitized = CheckImageDir(dir, "REveLogo::AddImageDir");
116 if (sanitized.empty())
117 return false;
118
119 if (sImageDir.empty())
120 sImageDir = sanitized;
121 ImageDirs().AddUserDir(sanitized);
122 return true;
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Stream the file, source, position, size, opacity and resizability.
127
128Int_t REveLogo::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
129{
130 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
131
132 j["fFile"] = fFile;
133 j["fSource"] = (int)fSource;
134 j["fPosX"] = fPosX;
135 j["fPosY"] = fPosY;
136 j["fSize"] = fSize;
137 j["fOpacity"] = fOpacity;
138 j["fResizable"] = fResizable;
139
140 return ret;
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Name the client factory makeLogo. No geometry is sent.
145
147{
148 fRenderData = std::make_unique<REveRenderData>("makeLogo");
150 fRenderData->PushV(0.f, 0.f, 0.f); // keep the buffer non-empty
151}
static std::string CheckImageDir(std::string_view dir, const char *tpfx)
Check that dir is readable and return it with a trailing slash, or an empty string with an error from...
Definition REveLogo.cxx:79
#define f(i)
Definition RSha256.hxx:104
char Text_t
General string (char)
Definition RtypesCore.h:77
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
@ kReadPermission
Definition TSystem.h:55
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
Directories of one kind of file the REve server serves under one http location prefix.
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
std::unique_ptr< REveRenderData > fRenderData
! Vertex / normal / triangle index information for rendering.
virtual void BuildRenderData()
Build fRenderData, what the client draws.
Float_t fPosX
position in the (0,1) overlay box; the image is centred on it
Definition REveLogo.hxx:39
Float_t fSize
height in CSS pixels; width follows the image aspect
Definition REveLogo.hxx:41
Float_t fOpacity
resting opacity; the client brightens it on hover
Definition REveLogo.hxx:42
static bool AddImageDir(std::string_view dir)
Add a directory images are served from, searched after the ones registered before it.
Definition REveLogo.cxx:113
std::string fFile
file name or URL, interpreted according to fSource
Definition REveLogo.hxx:37
static bool IsRemote(const std::string &f)
Is the file an absolute URL, to be fetched by the client directly?
Definition REveLogo.cxx:70
void BuildRenderData() override
Name the client factory makeLogo. No geometry is sent.
Definition REveLogo.cxx:146
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Stream the file, source, position, size, opacity and resizability.
Definition REveLogo.cxx:128
static std::string sImageDir
Definition REveLogo.hxx:48
static bool SetImageDir(std::string_view dir)
Register the directory images are served from, mapped under "eve-images/".
Definition REveLogo.cxx:98
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition TSystem.cxx:1318
const Int_t n
Definition legend1.C:16
Namespace for ROOT features in testing.
Definition TROOT.h:100