scenepic 1.1.0
3D Visualization Made Easy
frame2d.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#ifndef _SCENEPIC_FRAME2D_H_
5#define _SCENEPIC_FRAME2D_H_
6
7#include "color.h"
8#include "json_value.h"
9#include "matrix.h"
10
11#include <map>
12#include <string>
13
14namespace scenepic
15{
18 class Frame2D
19 {
20 public:
30 const CoordinateBuffer& coordinates,
31 const Color& line_color = Colors::Black,
32 float line_width = 1.0f,
33 const Color& fill_color = Color::None(),
34 bool close_path = false,
35 const std::string& layer_id = "");
36
48 float x,
49 float y,
50 float w,
51 float h,
52 const Color& line_color = Colors::Black,
53 float line_width = 1.0f,
54 const Color& fill_color = Color::None(),
55 const std::string& layer_id = "");
56
67 float x,
68 float y,
69 float radius,
70 const Color& line_color = Colors::Black,
71 float line_width = 1.0f,
72 const Color& fill_color = Color::None(),
73 const std::string& layer_id = "");
74
86 const std::string& image_id,
87 const std::string& position_type = "fit",
88 float x = 0.0f,
89 float y = 0.0f,
90 float scale = 1.0f,
91 bool smoothed = false,
92 const std::string& layer_id = "");
93
108 const std::string& position_type = "fit",
109 float x = 0.0f,
110 float y = 0.0f,
111 float scale = 1.0f,
112 bool smoothed = false,
113 const std::string& layer_id = "");
114
125 const std::string& text,
126 float left,
127 float bottom,
128 const Color& color = Colors::White,
129 float size_in_pixels = 12.0f,
130 const std::string& font_family = "sans-serif",
131 const std::string& layer_id = "");
132
134 std::uint16_t num_coordinates() const;
135
137 std::string to_string() const;
138
143
144 private:
145 friend class Canvas2D;
146
150 Frame2D(const std::string& frame_id);
151
152 IndexVector
153 lookup_layer_ids(const std::vector<std::string>& layer_ids) const;
154 std::map<std::string, std::uint8_t> m_layer_lookup;
155
156 std::string m_frame_id;
157 CoordinateBuffer m_coord_buffer;
158
159 PolyLineBuffer m_line_buffer;
160 StyleBuffer m_line_style_buffer;
161 std::vector<std::string> m_line_layer_ids;
162 std::vector<float> m_line_width;
163
164 CircleBuffer m_circle_buffer;
165 std::vector<std::string> m_circle_layer_ids;
166 StyleBuffer m_circle_style_buffer;
167
168 std::vector<JsonValue> m_frame_commands;
169
170 class Text
171 {
172 public:
173 Text(
174 const std::string& text,
175 std::uint32_t index,
176 const Color& color,
177 float size_in_pixels,
178 const std::string& font_family,
179 const std::string& layer_id);
180
181 JsonValue to_json() const;
182
183 private:
184 std::string m_text;
185 std::uint32_t m_index;
186 std::string m_fill_style;
187 float m_size_in_pixels;
188 std::string m_font_family;
189 std::string m_layer_id;
190 };
191
192 class Image
193 {
194 public:
195 Image(
196 const std::string& image_id,
197 const std::string& position_type,
198 std::uint32_t index,
199 float scale,
200 bool smoothed,
201 const std::string& layer_id);
202
203 JsonValue to_json() const;
204
205 private:
206 std::string m_image_id;
207 std::string m_position_type;
208 std::uint32_t m_index;
209 float m_scale;
210 bool m_smoothed;
211 std::string m_layer_id;
212 };
213
214 class Video
215 {
216 public:
217 Video(
218 const std::string& position_type,
219 std::uint32_t index,
220 float scale,
221 bool smoothed,
222 const std::string& layer_id);
223
224 JsonValue to_json() const;
225
226 private:
227 std::string m_position_type;
228 std::uint32_t m_index;
229 float m_scale;
230 bool m_smoothed;
231 std::string m_layer_id;
232 };
233 };
234} // namespace scenepic
235
236#endif
A 2D canvas that can contain a number of Frame2Ds.
Definition: canvas2d.h:21
Class for representing color values.
Definition: color.h:19
static const Color None()
Constant value indicating "no color".
Represents a frame of a 2D animation.
Definition: frame2d.h:19
std::string to_string() const
Return a JSON string representing the object.
void add_rectangle(float x, float y, float w, float h, const Color &line_color=Colors::Black, float line_width=1.0f, const Color &fill_color=Color::None(), const std::string &layer_id="")
Add a rectangle to the frame.
void add_video(const std::string &position_type="fit", float x=0.0f, float y=0.0f, float scale=1.0f, bool smoothed=false, const std::string &layer_id="")
Add a video to the frame.
std::uint16_t num_coordinates() const
The number of coordinates in the buffer.
JsonValue to_json() const
Convert this object into ScenePic json.
void add_line(const CoordinateBuffer &coordinates, const Color &line_color=Colors::Black, float line_width=1.0f, const Color &fill_color=Color::None(), bool close_path=false, const std::string &layer_id="")
Add a line to the frame.
void add_image(const std::string &image_id, const std::string &position_type="fit", float x=0.0f, float y=0.0f, float scale=1.0f, bool smoothed=false, const std::string &layer_id="")
Add an image to the frame.
void add_circle(float x, float y, float radius, const Color &line_color=Colors::Black, float line_width=1.0f, const Color &fill_color=Color::None(), const std::string &layer_id="")
Add a circle to the frame.
void add_text(const std::string &text, float left, float bottom, const Color &color=Colors::White, float size_in_pixels=12.0f, const std::string &font_family="sans-serif", const std::string &layer_id="")
Add some text to the frame.
A ScenePic Image type.
Definition: image.h:17
Representation of a JSON value according to the specification at https://www.json....
Definition: json_value.h:30
const Color White
Definition: color.h:96
const Color Black
Definition: color.h:95
Transform scale(float scale)
Creates a 3D homogeneous scale matrix.
Definition: audio_track.h:14