NDEVR
API Documentation
Text.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Design
28File: Text
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#if NDEVR_TEXT_MODEL
35#include <NDEVR/Model.h>
36#include <NDEVR/TextConstructor.h>
37#include <NDEVR/Font.h>
38#include <NDEVR/StringEnum.h>
39namespace NDEVR
40{
47 enum TextControlSequence
48 {
49 e_set_font = 'f'
50 , e_set_color = 'c'
51 , e_set_bold = 'b'
52 , e_set_italic = 'i'
53 , e_set_underline = '_'
54 , e_set_overstrike = '-'
55 , e_set_alignment = 'a'
56 , e_set_font_size = 's'
57 , e_set_fixed_width = 'w'
58 , e_set_tab_advance = 't'
59 };
60 class TextConstructor;
71 class NDEVR_DESIGN_API Text : public Model
72 {
73 public:
77 Text();
82 Text(const Model& model);
88 void setText(const TranslatedString& text, bool update_now = false);
94 void setText(const StringView& text, bool update_now = false);
100 void setText(const Buffer<TextBlock>& text, bool update_now = false);
111 void setAlignment(uint01 alignment, bool update_now = false);
112
117 uint01 alignment() const { return m_alignment; }
127 void setInsertionAlignment(uint01 alignment, bool update_now = false);
132 Model textLayer();
137 Model textObject() const;
142 void setCursor(uint04 cursor_position);
146 void updateText();
151 bool needsUpdate() const;
156 void updateTranslation();
162 void setConstrainedSize(const Vector<2, fltp08>& size);
167 void setMaximumSize(const Vector<2, fltp08>& size);
172 void setReferenceSize(const Vector<2, fltp08>& size);
173
178 Vector<2, fltp08> getConstrainedSize();
183 Vector<2, fltp08> getMaximumSize();
188 Vector<2, fltp08> getReferenceSize();
189
196 void setForwardBias(fltp08 forward_bias);
201 void setLineSpaceFactor(fltp08 line_space);
206 fltp08 lineSpaceFactor() const;
211 StringView plainText() const;
216 const Buffer<TextBlock>& blocks() const { return m_text_blocks; };
222 Buffer<TextBlock> autoInsertNewLines() const;
228 void autoReserveLines(Buffer<TextBlock>& blocks);
234 void setFont(const Font& font, bool repaint_now = false);
239 Font font() const;
243 void saveBlockMetaData();
248 void readMetaData();
254 Model getLine(uint04 index);
260 Model getLetterAt(uint04 string_position) const;
268 Model getLetterAt(uint04 string_position, const Buffer<TextBlock>& blocks) const;
273 static constexpr StringView TypeName() { return "text"; }
278 void setFaceCamera(bool face_camera);
284 void setScaleToCamera(bool face_camera);
289 void setFillBackground(bool fill_background);
294 static fltp04 DefaultScaler() { return .01f; }
295 private:
299 void init();
310 bool setupLetter(const ConstPointer<TextConstructor>& printer, Model& letter, wchar value, fltp08 hor_advance, fltp08 scale, const Font& font);
317 void setupCursor(const Matrix<fltp08>& matrix, const Vector<2, fltp08>& cursor_location, const Font& font);
322 void findCursor(bool create_if_not_exists);
326 void updateBackground();
330 void createCursor();
331 private:
332 Buffer<TextBlock> m_text_blocks;
333 Vector<2, fltp08> m_constrained_size;
334 Vector<2, fltp08> m_maximum_size;
335 Vector<2, fltp08> m_reference_size;
336 Model m_text_model;
337 uint04 m_cursor_index;
338 uint04 m_cursor_position;
339 uint01 m_alignment;
340 uint01 m_insertion_alignment;
341 mutable fltp08 m_line_space_factor;
342 fltp08 m_forward_bias = 0.0;
343 bool m_has_background = false;
344 bool m_has_read_metadata = false;
345 };
346
352#define TEXT_MODEL_PARAMS(X) \
353 X(e_constrained_size) \
354 X(e_maximum_size) \
355 X(e_reference_size) \
356 X(e_translated_text) \
357 X(e_text_blocks) \
358 X(e_font) \
359 X(e_line_space_factor) \
360 X(e_text)
361 NDEVR_DEFINE_STRING_STREAM(TextProperty, TEXT_MODEL_PARAMS)
362
363
364 template<> struct PropertySpec<TextProperty::e_constrained_size> { using type = Vector<2, fltp08>; };
365 template<> struct PropertySpec<TextProperty::e_maximum_size> { using type = Vector<2, fltp08>; };
366 template<> struct PropertySpec<TextProperty::e_reference_size> { using type = Vector<2, fltp08>; };
367 template<> struct PropertySpec<TextProperty::e_translated_text> { using type = TranslatedString; };
368 template<> struct PropertySpec<TextProperty::e_text> { using type = String; };
369 template<> struct PropertySpec<TextProperty::e_line_space_factor> { using type = fltp08; };
370 template<> struct PropertySpec<TextProperty::e_text_blocks> { using type = Buffer<TextBlock>; };
371 template<> struct PropertySpec<TextProperty::e_font> { using type = Font; };
379 template<>
380 class PropertyInterface<TextProperty>
381 {
382 public:
383
392 template<TextProperty t_property, class t_value_type>
393 static void Set(DesignInfo* object, const t_value_type& value)
394 {
395 Text text = Text(Model(*object));
396 if constexpr (t_property == TextProperty::e_constrained_size)
397 text.setConstrainedSize(value);
398 if constexpr (t_property == TextProperty::e_font)
399 text.setFont(value);
400 if constexpr (t_property == TextProperty::e_line_space_factor)
401 text.setLineSpaceFactor(value);
402 if constexpr (t_property == TextProperty::e_maximum_size)
403 text.setMaximumSize(value);
404 if constexpr (t_property == TextProperty::e_reference_size)
405 text.setSize(value);
406 if constexpr (t_property == TextProperty::e_translated_text)
407 text.setText(value);
408 if constexpr (t_property == TextProperty::e_text_blocks)
409 text.setText(value);
410 if constexpr (t_property == TextProperty::e_text)
411 text.setText(value);
412 text.updateText();
413 text.saveBlockMetaData();
414 }
423 template<TextProperty t_property>
424 static decltype(auto) Get(const DesignInfo* object)
425 {
426 Text text = Text(Model(*object));
427 text.readMetaData();
428 if constexpr (t_property == TextProperty::e_constrained_size)
429 return text.getConstrainedSize();
430 if constexpr (t_property == TextProperty::e_font)
431 return text.font();
432 if constexpr (t_property == TextProperty::e_line_space_factor)
433 return text.lineSpaceFactor();
434 if constexpr (t_property == TextProperty::e_maximum_size)
435 return text.getMaximumSize();
436 if constexpr (t_property == TextProperty::e_reference_size)
437 return text.getReferenceSize();
438 if constexpr (t_property == TextProperty::e_translated_text)
439 return TranslatedString(text.plainText());
440 if constexpr (t_property == TextProperty::e_text_blocks)
441 return text.blocks();
442 if constexpr (t_property == TextProperty::e_text)
443 return text.plainText();
444 }
453 template<TextProperty t_property, class t_value_type>
454 static decltype(auto) Get(const DesignInfo* object)
455 {
456 return Get<t_property>(object);
457 }
458 };
459}
460#endif
461
A core class that represents a node on model hierarchy.
Definition Model.h:292
Typed interface for getting and setting design object properties by enum.
static decltype(auto) Get(const DesignInfo *object, t_property_enum property)
Gets the value of a property from a design object using a runtime property enum.
static void Set(DesignInfo *object, t_property_enum property, const t_value_type &value)
Sets the value of a property on a design object using a runtime property enum.
The primary namespace for the NDEVR SDK.
@ type
The type identifier string for this model node.
Definition Model.h:58
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
@ e_text
Open in text mode.
Definition Connection.h:71
Maps a compile-time property enum value to its corresponding C++ storage type.