Loading...
Searching...
No Matches
graphics.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31
32// Vector graphics (mainly SVG) – EXPERIMENTAL
33
34#ifndef RACK_GRAPHICS
35#define RACK_GRAPHICS
36
37// #include <drain/prog/CommandInstaller.h>
38
39
40//#include <drain/util/TreeUtilsXML.h>
41
42#include "resources-image.h"
43#include "resources.h"
44
45// Notice: role of graphics.cpp and fileio-svg.cpp is currently equivalent
46
47namespace rack {
48
49
50
52class RackSVG { // : public drain::BasicCommand {
53
54
55public:
56
57 //typedef drain::StyleSelectorXML<NodeSVG> Select;
58
59 // Identifier for the anchor background
60 static const std::string BACKGROUND_RECT; // = "mainRect";
61
62
64
67 static
68 drain::image::TreeSVG & getStyle(RackContext & ctx);
69
71 static
72 const std::string & guessFormat(const std::string & key);
73
75
79 static
80 drain::image::TreeSVG & getMainGroup(RackContext & ctx);
81
82 //drain::image::TreeSVG & getCurrentAlignedGroup();
83
84 // virtual
85 // std::string getFormattedStatus(RackContext & ctx, const std::string & format) const = 0;
86
87 static
88 drain::image::TreeSVG & getCurrentAlignedGroup(RackContext & ctx);
89
90 static
91 drain::image::TreeSVG & getImagePanelGroup(RackContext & ctx, const drain::FilePath & filepath);
92
93 static
94 drain::image::TreeSVG & getImagePanelGroup(RackContext & ctx);
95
96
97 static
98 //void applyAlignment(RackContext & ctx, drain::image::TreeSVG & group);
100
101 static
102 bool applyInclusion(RackContext & cxt, const drain::FilePath & filepath); // , SvgInclude fileFormat);
103
104 static
105 // drain::image::TreeSVG &
106 void addImage(RackContext & ctx, const drain::image::Image & src, const drain::FilePath & filepath);
107
109 static
110 // drain::image::TreeSVG &
111 void addImage(RackContext & ctx, const drain::image::TreeSVG & svg, const drain::FilePath & filepath);
112
114
117 static
118 // drain::image::TreeSVG &
119 void addImage(RackContext & ctx, const drain::Frame2D<drain::image::svg::coord_t> & frame, const drain::FilePath & filepath, const std::string & styleClass = "");
120
121
123
126 static
127 drain::image::TreeSVG & addTitleBox(const PanelConfSVG & conf, drain::image::TreeSVG & object, PanelConfSVG::ElemClass elemClass);
128
129 // TODO: title area "filling order", by group class.
131 static
132 drain::image::TreeSVG & appendTitleElements(const PanelConfSVG &conf, drain::image::TreeSVG &group, const std::string &anchor, PanelConfSVG::ElemClass elemClass);
133
135 static
136 drain::image::TreeSVG & addRectangleGroup(RackContext & ctx, const drain::Frame2D<double> & frame = {200,200});
137
138
140
143 static
144 drain::image::TreeSVG & addImageBorder(drain::image::TreeSVG & imagePanel); // , const drain::Frame2D<double> & frame = {200,200});
145
146
147 // static
148 // void generateTitles(RackContext & ctx);
149
151 // Re-align elements etc
152 // static
153 // void completeSVG(RackContext & ctx); // , const drain::FilePath & filepath);
154
156 // static
157 // const std::string & getTextClass(const std::string & key, const std::string & defaultClass = "");
158
159protected:
160
161 // Under construction...
162 // static
163 // void createTitleBox(TreeSVG & tree);
164
165};
166
167//DRAIN_ENUM_OSTREAM(RackSVG::ElemClass);
168
169}
170
171namespace drain {
172
173//
174/*
175template <> // for T (Tree class)
176template <> // for K (path elem arg)
177image::TreeSVG & image::TreeSVG::operator[](const rack::GraphicsContext::ElemClass &x);
178*/
179
181
189//template <>
190//const drain::EnumDict<RackSVG::TitleClass>::dict_t drain::EnumDict<RackSVG::TitleClass>::dict;
191
192/*
193template <>
194const std::string std::static_cast<std::string>(const RackSVG::ElemClass & e){
195 return drain::EnumDict<RackSVG::ElemClass>::dict.getKey(e);
196}
197*/
198
199}
200
201
202namespace rack {
203
204
224
229class TitleCreatorSVG : public drain::TreeVisitor<TreeSVG> {
230
231public:
232
233
234 inline
235 TitleCreatorSVG(const PanelConfSVG & svgConf) : svgConf(svgConf) {
236 //titles.set(0xff);
237 /*
238 if (!svgConf.mainTitle.empty()){
239 titles.set(PanelConfSVG::ElemClass::MAIN_TITLE);
240 }
241
242 if (!svgConf.groupTitleSyntax.empty()){
243 titles.set(PanelConfSVG::ElemClass::GROUP_TITLE);
244 }
245
246 titles.set(PanelConfSVG::ElemClass::IMAGE_TITLE);
247 */
248 /*
249 if (!svgConf.groupNameSyntax.empty()){
250 titles.set(RackSVG::ElemClass::GROUP_TITLE);
251 }
252 */
253
254 };
255
258 int visitPostfix(TreeSVG &root, const TreeSVG::path_t &path) override;
259
263 //static
264 void formatTitle(TreeSVG & group, const NodeSVG::map_t & attributes) const;
265
266 const PanelConfSVG & svgConf;
267
268 // Conf
269 // int mainHeaderHeight;
270
271protected:
272 // RackSVG::TitleFlagger::ivalue_t titles;
273
274 // Conf
275 // RackSVG::TitleFlagger titles;
276
277
278};
279
280
281} // rack::
282
283
284#endif
Extracts and stores directory path, base filename and extension.
Definition FilePath.h:58
Something that has width and height.
Definition Frame.h:55
Default implementation of a tree visitor (concept) compatible TreeUtils::traverser()
Definition TreeUtils.h:270
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:193
Definition TreeSVG.h:129
Resources provided separately for each thread.
Definition resources.h:77
SVG panel utils.
Definition graphics.h:52
static drain::image::TreeSVG & appendTitleElements(const PanelConfSVG &conf, drain::image::TreeSVG &group, const std::string &anchor, PanelConfSVG::ElemClass elemClass)
Add title elements in given group, to "reserve slots" for actual text content to be added later.
Definition graphics.cpp:584
static drain::image::TreeSVG & getImagePanelGroup(RackContext &ctx, const drain::FilePath &filepath)
For each image an own group is created (for clarity, to contain also title TEXT's etc)
Definition graphics.cpp:405
static drain::image::TreeSVG & getMainGroup(RackContext &ctx)
Top-level GROUP used by Rack. All the graphic elements will be created inside this element.
Definition graphics.cpp:212
static const std::string BACKGROUND_RECT
Group identifiers for elements which be automatically aligned (stacked horizontally or vertically)
Definition graphics.h:60
static drain::image::TreeSVG & addImageBorder(drain::image::TreeSVG &imagePanel)
Add.
Definition graphics.cpp:542
static drain::image::TreeSVG & addTitleBox(const PanelConfSVG &conf, drain::image::TreeSVG &object, PanelConfSVG::ElemClass elemClass)
Create a title from background rectangle and TEXT elements (MAINTITLE, LOCATION, TIME,...
Definition graphics.cpp:553
static drain::image::TreeSVG & addRectangleGroup(RackContext &ctx, const drain::Frame2D< double > &frame={200, 200})
Add rectangle.
static const std::string & guessFormat(const std::string &key)
returns timeformat
Definition graphics.cpp:189
static void addImage(RackContext &ctx, const drain::image::Image &src, const drain::FilePath &filepath)
Add pixel image (PNG).
Definition graphics.cpp:445
static void consumeAlignRequest(RackContext &ctx, drain::image::NodeSVG &node)
Apply an alignment, to next object only.
Definition graphics.cpp:242
static drain::image::TreeSVG & getStyle(RackContext &ctx)
Some SVG style classes. Identifiers for IMAGE and RECT elements over which TEXT elements will be alig...
Definition graphics.cpp:85
Formats titles from metadata. Invoked by drain::TreeUtils::traverse()
Definition graphics.h:229
void formatTitle(TreeSVG &group, const NodeSVG::map_t &attributes) const
Definition graphics.cpp:679
Definition DataSelector.cpp:1277
Definition DataSelector.cpp:44
Definition TreeSVG.h:58
Definition resources-image.h:86