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
33#ifndef RACK_GRAPHICS
34#define RACK_GRAPHICS
35
36
37#include "resources-image.h"
38#include "resources.h"
39
40// Notice: role of graphics.cpp and fileio-svg.cpp is currently equivalent
41
42namespace rack {
43
44
45
47class RackSVG {
48
49
50public:
51
52 //typedef drain::StyleSelectorXML<NodeSVG> Select;
53
54 // Identifier for the anchor background
55 static const std::string BACKGROUND_RECT; // = "mainRect";
56
57
59
62 static
63 drain::image::TreeSVG & getStyle(RackContext & ctx);
64
66 static
67 const std::string & guessFormat(const std::string & key);
68
70
74 static
75 drain::image::TreeSVG & getMainGroup(RackContext & ctx);
76
77 static
78 drain::image::TreeSVG & getCurrentAlignedGroup(RackContext & ctx);
79
80 static
81 drain::image::TreeSVG & getImagePanelGroup(RackContext & ctx, const drain::FilePath & filepath);
82
83 static
84 drain::image::TreeSVG & getImagePanelGroup(RackContext & ctx);
85
86
87 static
88 //void applyAlignment(RackContext & ctx, drain::image::TreeSVG & group);
90
91 static
92 bool applyInclusion(RackContext & cxt, const drain::FilePath & filepath); // , SvgInclude fileFormat);
93
94 static
95 // drain::image::TreeSVG &
96 void addImage(RackContext & ctx, const drain::image::Image & src, const drain::FilePath & filepath);
97
99 static
100 // drain::image::TreeSVG &
101 void addImage(RackContext & ctx, const drain::image::TreeSVG & svg, const drain::FilePath & filepath);
102
104
107 static
108 // drain::image::TreeSVG &
109 void addImage(RackContext & ctx, const drain::Frame2D<drain::image::svg::coord_t> & frame, const drain::FilePath & filepath, const std::string & styleClass = "");
110
111
113
116 static
117 drain::image::TreeSVG & addTitleBox(const PanelConfSVG & conf, drain::image::TreeSVG & object, PanelConfSVG::ElemClass elemClass);
118
119 // TODO: title area "filling order", by group class.
121 static
122 drain::image::TreeSVG & appendTitleElements(const PanelConfSVG &conf, drain::image::TreeSVG &group, const std::string &anchor, PanelConfSVG::ElemClass elemClass);
123
125 static
126 drain::image::TreeSVG & addRectangleGroup(RackContext & ctx, const drain::Frame2D<double> & frame = {200,200});
127
128
130
133 static
134 drain::image::TreeSVG & addImageBorder(drain::image::TreeSVG & imagePanel); // , const drain::Frame2D<double> & frame = {200,200});
135
136
137protected:
138
139
140};
141
142} // rack
143
144namespace drain {
145
146//
147/*
148template <> // for T (Tree class)
149template <> // for K (path elem arg)
150image::TreeSVG & image::TreeSVG::operator[](const rack::GraphicsContext::ElemClass &x);
151*/
152
154
162//template <>
163//const drain::EnumDict<RackSVG::TitleClass>::dict_t drain::EnumDict<RackSVG::TitleClass>::dict;
164
165/*
166template <>
167const std::string std::static_cast<std::string>(const RackSVG::ElemClass & e){
168 return drain::EnumDict<RackSVG::ElemClass>::dict.getKey(e);
169}
170*/
171
172}
173
174
175namespace rack {
176
177
178
179
181
186class TitleCreatorSVG : public drain::TreeVisitor<TreeSVG> {
187
188public:
189
190
191 inline
192 TitleCreatorSVG(const PanelConfSVG & svgConf) : svgConf(svgConf) {
193 //titles.set(0xff);
194 /*
195 if (!svgConf.mainTitle.empty()){
196 titles.set(PanelConfSVG::ElemClass::MAIN_TITLE);
197 }
198
199 if (!svgConf.groupTitleSyntax.empty()){
200 titles.set(PanelConfSVG::ElemClass::GROUP_TITLE);
201 }
202
203 titles.set(PanelConfSVG::ElemClass::IMAGE_TITLE);
204 */
205 /*
206 if (!svgConf.groupNameSyntax.empty()){
207 titles.set(RackSVG::ElemClass::GROUP_TITLE);
208 }
209 */
210
211 };
212
215 int visitPostfix(TreeSVG &root, const TreeSVG::path_t &path) override;
216
220 //static
221 void formatTitle(TreeSVG & group, const NodeSVG::map_t & attributes) const;
222
223 const PanelConfSVG & svgConf;
224
225 // Conf
226 // int mainHeaderHeight;
227
228protected:
229 // RackSVG::TitleFlagger::ivalue_t titles;
230
231 // Conf
232 // RackSVG::TitleFlagger titles;
233
234
235};
236
237
238} // rack::
239
240
241#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:138
Resources provided separately for each thread.
Definition resources.h:77
SVG support for creating aligned image panels.
Definition graphics.h:47
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:644
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:471
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:338
static const std::string BACKGROUND_RECT
Group identifiers for elements which be automatically aligned (stacked horizontally or vertically)
Definition graphics.h:55
static drain::image::TreeSVG & addImageBorder(drain::image::TreeSVG &imagePanel)
Add.
Definition graphics.cpp:602
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:613
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:225
static void addImage(RackContext &ctx, const drain::image::Image &src, const drain::FilePath &filepath)
Add pixel image (PNG).
Definition graphics.cpp:505
static void consumeAlignRequest(RackContext &ctx, drain::image::NodeSVG &node)
Apply an alignment, to next object only.
Definition graphics.cpp:255
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:86
Formats titles from metadata. Invoked by drain::TreeUtils::traverse()
Definition graphics.h:186
void formatTitle(TreeSVG &group, const NodeSVG::map_t &attributes) const
Definition graphics.cpp:739
Definition DataSelector.cpp:1277
Definition DataSelector.cpp:44
Definition TreeSVG.h:61
Definition resources-image.h:86