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 "TSystem.h"
17
18#include <nlohmann/json.hpp>
19
20using namespace ROOT::Experimental;
21
22/** \class REveLogo
23\ingroup REve
24A screen-space image for an overlay scene, such as an experiment logo or a
25watermark.
26
27The client draws it as a RenderCore ZLogo, a screen-space ZSprite. The size is
28in CSS pixels and does not change with the camera, and the outline comes from
29the image alpha. The logo can be moved, and resized from its corner grip, in
30the client only. Nothing is sent back, so each client places its own copy.
31
32Images are served from a directory registered with SetImageDir() and mapped
33under "eve-images/", as REveText maps its SDF fonts. ROOT does not ship any
34images.
35*/
36
37std::string REveLogo::sImageDir;
38
39////////////////////////////////////////////////////////////////////////////////
40/// Constructor. A `file` that IsRemote() accepts selects kRemote.
41
42REveLogo::REveLogo(std::string_view file, const Text_t *n, const Text_t *t) : REveElement(n, t), fFile(file)
43{
44 SetPickable(kTRUE); // otherwise it cannot be moved
45
46 if (IsRemote(fFile))
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Is the file an absolute URL, to be fetched by the client directly?
52
53bool REveLogo::IsRemote(const std::string &f)
54{
55 return f.compare(0, 7, "http://") == 0 || f.compare(0, 8, "https://") == 0 || f.compare(0, 2, "//") == 0;
56}
57
58////////////////////////////////////////////////////////////////////////////////
59/// Register the directory images are served from, mapped under "eve-images/".
60/// Mirrors REveText::SetSdfFontDir; must run after REveManager::Create().
61
62bool REveLogo::SetImageDir(std::string_view dir)
63{
64 static const char *tpfx = "REveLogo::SetImageDir";
65
66 if (!gEve) {
67 ::Error(tpfx, "REveManager needs to be initialized before the image dir can be set.");
68 return false;
69 }
70
71 std::string sanitized(dir);
72 if (sanitized.empty()) {
73 ::Error(tpfx, "Empty directory given.");
74 return false;
75 }
76 if (sanitized.back() != '/')
77 sanitized += '/';
78
79 if (gSystem->AccessPathName(sanitized.c_str(), kReadPermission)) {
80 ::Error(tpfx, "Image directory '%s' does not exist or is not readable.", sanitized.c_str());
81 return false;
82 }
83
84 sImageDir = sanitized;
85 gEve->AddLocation("eve-images/", sImageDir);
86 return true;
87}
88
89////////////////////////////////////////////////////////////////////////////////
90/// Stream the file, source, position, size, opacity and resizability.
91
92Int_t REveLogo::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
93{
94 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
95
96 j["fFile"] = fFile;
97 j["fSource"] = (int)fSource;
98 j["fPosX"] = fPosX;
99 j["fPosY"] = fPosY;
100 j["fSize"] = fSize;
101 j["fOpacity"] = fOpacity;
102 j["fResizable"] = fResizable;
103
104 return ret;
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Name the client factory makeLogo. No geometry is sent.
109
111{
112 fRenderData = std::make_unique<REveRenderData>("makeLogo");
114 fRenderData->PushV(0.f, 0.f, 0.f); // keep the buffer non-empty
115}
#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
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()
Write transformation Matrix to render data.
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
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:53
void BuildRenderData() override
Name the client factory makeLogo. No geometry is sent.
Definition REveLogo.cxx:110
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Stream the file, source, position, size, opacity and resizability.
Definition REveLogo.cxx:92
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:62
void AddLocation(const std::string &name, const std::string &path)
Register new directory to THttpServer.
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
R__EXTERN REveManager * gEve