xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
lcd_label.h
1 #include <codecvt>
2 #include <xtd/argument_out_of_range_exception.h>
3 #include "control.h"
4 #include "dot_matrix_display.h"
5 #include "lcd_style.h"
6 #include "nine_segment_display.h"
7 #include "seven_segment_display.h"
8 #include "fourteen_segment_display.h"
9 #include "sixteen_segment_display.h"
10 
11 namespace xtd {
12  namespace forms {
13  class lcd_label : public control {
14  class idigit {
15  public:
16  ~idigit() = default;
17 
18  virtual wchar_t get_character() const = 0;
19  virtual std::string get_valid_characters() const = 0;
20  virtual int32_t get_thickness() const = 0;
21 
22  virtual void set_background_digit_transparency(double value) = 0;
23  virtual void set_character(wchar_t value) = 0;
24  virtual void set_segment_style(forms::segment_style value) = 0;
25  virtual void set_dot_matrix_style(forms::dot_matrix_style value) = 0;
26  virtual void set_show_background_digit(bool value) = 0;
27  virtual void set_thickness(int32_t value) = 0;
28  };
29 
30  class dot_matrix_display_digit : public dot_matrix_display, public idigit {
31  public:
32  dot_matrix_display_digit() = default;
33 
34  wchar_t get_character() const override {return character_;}
35  std::string get_valid_characters() const override {return "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=+-*/%\\_°\"'[](){}<>| .,:;!?&$€";}
36  int32_t get_thickness() const override {return dot_matrix_display::thickness();}
37 
38  void set_background_digit_transparency(double value) override {dot_matrix_display::background_dot_transparency(value);}
39  void set_character(wchar_t value) override {
40  static std::map<wchar_t, dot_matrix_display::dot_collection> characters {
41  {'0', {{2, 0}, {3, 0}, {4, 0}, {1, 1}, {5, 1}, {1, 2}, {4, 2}, {5, 2}, {1, 3}, {3, 3}, {5, 3}, {1, 4}, {2, 4}, {5, 4}, {1, 5}, {5, 5}, {2, 6}, {3, 6}, {4, 6}}},
42  {'1', {{3, 0}, {2, 1}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}}},
43  {'2', {{2, 0}, {3, 0}, {4, 0}, {1, 1}, {5, 1}, {5, 2}, {4, 3}, {3, 4}, {2, 5}, {1, 6}, {2, 6}, {3, 6}, {4, 6}, {5, 6}}},
44  {'3', {{2, 0}, {3, 0}, {4, 0}, {1, 1}, {5, 1}, {5, 2}, {2, 3}, {3, 3}, {4, 3}, {5, 4}, {1, 5}, {5, 5}, {2, 6}, {3, 6}, {4, 6}}},
45  {'4', {{1, 0}, {5, 0}, {1, 1}, {5, 1}, {1, 2}, {5, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {5, 3}, {5, 4}, {5, 5}, {5, 6}}},
46  {'5', {{1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {1, 1}, {1, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {5, 4}, {5, 5}, {1, 6}, {2, 6}, {3, 6}, {4, 6}}},
47  {'6', {{2, 0}, {3, 0}, {4, 0}, {1, 1}, {1, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {2, 6}, {3, 6}, {4, 6}}},
48  {'7', {{1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {5, 1}, {5, 2}, {4, 3}, {4, 4}, {3, 5}, {3, 6}}},
49  {'8', {{2, 0}, {3, 0}, {4, 0}, {1, 1}, {5, 1}, {1, 2}, {5, 2}, {2, 3}, {3, 3}, {4, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {2, 6}, {3, 6}, {4, 6}}},
50  {'9', {{2, 0}, {3, 0}, {4, 0}, {1, 1}, {5, 1}, {1, 2}, {5, 2}, {2, 3}, {3, 3}, {4, 3}, {5, 4}, {5, 5}, {2, 6}, {3, 6}, {4, 6}}},
51  {'A', {{2, 0}, {3, 0}, {4, 0}, {1, 1}, {5, 1}, {1, 2}, {5, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {1, 6}, {5, 6}}},
52  {'B', {{1, 0}, {2, 0}, {3, 0}, {4, 0}, {1, 1}, {5, 1}, {1, 2}, {5, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {1, 6}, {2, 6}, {3, 6}, {4, 6}}},
53  {'C', {{2, 0}, {3, 0}, {4, 0}, {1, 1}, {5, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 6}, {3, 6}, {5, 5}, {4, 6}}},
54  {'D', {{1, 0}, {2, 0}, {3, 0}, {4, 0}, {1, 1}, {5, 1}, {1, 2}, {5, 2}, {1, 3}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {1, 6}, {2, 6}, {3, 6}, {4, 6}}},
55  {'E', {{1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {1, 1}, {1, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {1, 4}, {1, 5}, {1, 6}, {2, 6}, {3, 6}, {4, 6}, {5, 6}}},
56  {'F', {{1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {1, 1}, {1, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {1, 4}, {1, 5}, {1, 6}}},
57  {'G', {{2, 0}, {3, 0}, {4, 0}, {1, 1}, {1, 2}, {1, 3}, {4, 3}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {2, 6}, {3, 6}, {4, 6}}},
58  {'H', {{1, 0}, {5, 0}, {1, 1}, {5, 1}, {1, 2}, {5, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {1, 6}, {5, 6}}},
59  {'I', {{3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}}},
60  {'J', {{5, 0}, {5, 1}, {5, 2}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {2, 6}, {3, 6}, {4, 6}}},
61  {'K', {{1, 0}, {5, 0}, {1, 1}, {4, 1}, {1, 2}, {3, 2}, {1, 3}, {2, 3}, {1, 4}, {3, 4}, {1, 5}, {4, 5}, {1, 6}, {5, 6}}},
62  {'L', {{1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {2, 6}, {3, 6}, {4, 6}, {5, 6}}},
63  {'M', {{1, 0}, {5, 0}, {1, 1}, {2, 1}, {4, 1}, {5, 1}, {1, 2}, {3, 2}, {5, 2}, {1, 3}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {1, 6}, {5, 6}}},
64  {'N', {{1, 0}, {5, 0}, {1, 1}, {2, 1}, {5, 1}, {1, 2}, {3, 2}, {5, 2}, {1, 3}, {4, 3}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {1, 6}, {5, 6}}},
65  {'O', {{2, 0}, {3, 0}, {4, 0}, {1, 1}, {5, 1}, {1, 2}, {5, 2}, {1, 3}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {2, 6}, {3, 6}, {4, 6}}},
66  {'P', {{1, 0}, {2, 0}, {3, 0}, {4, 0}, {1, 1}, {5, 1}, {1, 2}, {5, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {1, 4}, {1, 5}, {1, 6}}},
67  {'Q', {{2, 0}, {3, 0}, {4, 0}, {1, 1}, {5, 1}, {1, 2}, {5, 2}, {1, 3}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {4, 5}, {2, 6}, {3, 6}, {5, 6}}},
68  {'R', {{1, 0}, {2, 0}, {3, 0}, {4, 0}, {1, 1}, {5, 1}, {1, 2}, {5, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {1, 4}, {3, 4}, {1, 5}, {4, 5}, {1, 6}, {5, 6}}},
69  {'S', {{2, 0}, {3, 0}, {4, 0}, {1, 1}, {5, 1}, {1, 2}, {2, 3}, {3, 3}, {4, 3}, {5, 4}, {1, 5}, {5, 5}, {2, 6}, {3, 6}, {4, 6}}},
70  {'T', {{1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}}},
71  {'U', {{1, 0}, {5, 0}, {1, 1}, {5, 1}, {1, 2}, {5, 2}, {1, 3}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {2, 6}, {3, 6}, {4, 6}}},
72  {'V', {{1, 0}, {5, 0}, {1, 1}, {5, 1}, {1, 2}, {5, 2}, {2, 3}, {4, 3}, {2, 4}, {4, 4}, {3, 5}, {3, 6}}},
73  {'W', {{1, 0}, {5, 0}, {1, 1}, {5, 1}, {1, 2}, {3, 2}, {5, 2}, {1, 3}, {3, 3}, {5, 3}, {1, 4}, {3, 4}, {5, 4}, {1, 5}, {2, 5}, {4, 5}, {5, 5}, {1, 6}, {5, 6}}},
74  {'X', {{1, 0}, {5, 0}, {1, 1}, {5, 1}, {2, 2}, {4, 2}, {3, 3}, {2, 4}, {4, 4}, {1, 5}, {5, 5}, {1, 6}, {5, 6}}},
75  {'Y', {{1, 0}, {5, 0}, {1, 1}, {5, 1}, {2, 2}, {4, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}}},
76  {'Z', {{1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {5, 1}, {4, 2}, {3, 3}, {2, 4}, {1, 5}, {1, 6}, {2, 6}, {3, 6}, {4, 6}, {5, 6}}},
77  {'a', {{2, 2}, {3, 2}, {4, 2}, {5, 3}, {2, 4}, {3, 4}, {4, 4}, {5, 4}, {1, 5}, {5, 5}, {2, 6}, {3, 6}, {4, 6}, {5, 6}}},
78  {'b', {{1, 0}, {1, 1}, {1, 2}, {2, 2}, {3, 2}, {4, 2}, {1, 3}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {1, 6}, {2, 6}, {3, 6}, {4, 6}}},
79  {'c', {{2, 2}, {3, 2}, {4, 2}, {5, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 6}, {3, 6}, {4, 6}, {5, 6}}},
80  {'d', {{5, 0}, {5, 1}, {2, 2}, {3, 2}, {4, 2}, {5, 2}, {1, 3}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {2, 6}, {3, 6}, {4, 6}, {5, 6}}},
81  {'e', {{2, 2}, {3, 2}, {4, 2}, {1, 3}, {5, 3}, {1, 4}, {2, 4}, {3, 4}, {4, 4}, {5, 4}, {1, 5}, {2, 6}, {3, 6}, {4, 6}}},
82  {'f', {{3, 0}, {4, 0}, {2, 1}, {2, 2}, {3, 2}, {2, 3}, {2, 4}, {2, 5}, {2, 6}}},
83  {'g', {{2, 0}, {3, 0}, {4, 0}, {1, 1}, {5, 1}, {1, 2}, {5, 2}, {1, 3}, {5, 3}, {2, 4}, {3, 4}, {4, 4}, {5, 4}, {5, 5}, {2, 6}, {3, 6}, {4, 6}}},
84  {'h', {{1, 0}, {1, 1}, {1, 2}, {2, 2}, {3, 2}, {4, 2}, {1, 3}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {1, 6}, {5, 6}}},
85  {'i', {{3, 0}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}}},
86  {'j', {{4, 0}, {4, 2}, {4, 3}, {4, 4}, {4, 5}, {2, 6}, {3, 6}}},
87  {'k', {{1, 0}, {1, 1}, {1, 2}, {5, 2}, {1, 3}, {4, 3}, {1, 4}, {2, 4}, {3, 4}, {1, 5}, {4, 5}, {1, 6}, {5, 6}}},
88  {'l', {{3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {4, 6}}},
89  {'m', {{2, 2}, {4, 2}, {1, 3}, {3, 3}, {5, 3}, {1, 4}, {3, 4}, {5, 4}, {1, 5}, {3, 5}, {5, 5}, {1, 6}, {3, 6}, {5, 6}}},
90  {'n', {{2, 2}, {3, 2}, {4, 2}, {1, 3}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {1, 6}, {5, 6}}},
91  {'o', {{2, 2}, {3, 2}, {4, 2}, {1, 3}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {2, 6}, {3, 6}, {4, 6}}},
92  {'p', {{1, 1}, {2, 1}, {3, 1}, {4, 1}, {1, 2}, {5, 2}, {1, 3}, {5, 3}, {1, 4}, {2, 4}, {3, 4}, {4, 4}, {1, 5}, {1, 6}}},
93  {'q', {{2, 1}, {3, 1}, {4, 1}, {5, 1}, {1, 2}, {5, 2}, {1, 3}, {5, 3}, {2, 4}, {3, 4}, {4, 4}, {5, 4}, {5, 5}, {5, 6}}},
94  {'r', {{2, 2}, {3, 2}, {4, 2}, {5, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}}},
95  {'s', {{2, 2}, {3, 2}, {4, 2}, {5, 2}, {1, 3}, {2, 4}, {3, 4}, {4, 4}, {5, 5}, {1, 6}, {2, 6}, {3, 6}, {4, 6}}},
96  {'t', {{3, 0}, {3, 1}, {2, 2}, {3, 2}, {4, 2}, {3, 3}, {3, 4}, {3, 5}, {4, 6}, {5, 6}}},
97  {'u', {{1, 2}, {5, 2}, {1, 3}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {2, 6}, {3, 6}, {4, 6}}},
98  {'v', {{1, 2}, {5, 2}, {1, 3}, {5, 3}, {2, 4}, {4, 4}, {2, 5}, {4, 5}, {3, 6}}},
99  {'w', {{1, 2}, {3, 2}, {5, 2}, {1, 3}, {3, 3}, {5, 3}, {1, 4}, {3, 4}, {5, 4}, {1, 5}, {3, 5}, {5, 5}, {2, 6}, {4, 6}}},
100  {'x', {{1, 2}, {5, 2}, {2, 3}, {4, 3}, {3, 4}, {2, 5}, {4, 5}, {1, 6}, {5, 6}}},
101  {'y', {{1, 1}, {5, 1}, {1, 2}, {5, 2}, {1, 3}, {5, 3}, {2, 4}, {3, 4}, {4, 4}, {5, 4}, {5, 5}, {2, 6}, {3, 6}, {4, 6}}},
102  {'z', {{1, 2}, {2, 2}, {3, 2}, {4, 2}, {5, 2}, {4, 3}, {3, 4}, {2, 5}, {1, 6}, {2, 6}, {3, 6}, {4, 6}, {5, 6}}},
103  {'=', {{1, 2}, {2, 2}, {3, 2}, {4, 2}, {5, 2}, {1, 4}, {2, 4}, {3, 4}, {4, 4}, {5, 4}}},
104  {'+', {{3, 1}, {3, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {5, 3}, {3, 4}, {3, 5}}},
105  {'-', {{1, 3}, {2, 3}, {3, 3}, {4, 3}, {5, 3}}},
106  {'*', {{3, 0}, {1, 1}, {3, 1}, {5, 1}, {2, 2}, {3, 2}, {4, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {5, 3}, {2, 4}, {3, 4}, {4, 4}, {1, 5}, {3, 5}, {5, 5}, {3, 6}}},
107  {'/', {{5, 1}, {4, 2}, {3, 3}, {2, 4}, {1, 5}}},
108  {'%', {{1, 0}, {2, 0}, {1, 1}, {2, 1}, {5, 1}, {4, 2}, {3, 3}, {2, 4}, {1, 5}, {4, 5}, {5, 5}, {4, 6}, {5, 6}}},
109  {'\\', {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}}},
110  {'_', {{1, 6}, {2, 6}, {3, 6}, {4, 6}, {5, 6}}},
111  {L'\u00B0', {{2, 0}, {3, 0}, {1, 1}, {4, 1}, {1, 2}, {4, 2}, {2, 3}, {3, 3}}},
112  {'"', {{2, 0}, {5, 0}, {2, 1}, {5, 1}, {1, 2}, {4, 2}}},
113  {'\'', {{3, 0}, {3, 1}, {2, 2}}},
114  {'[', {{3, 0}, {4, 0}, {5, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}, {4, 6}, {5, 6}}},
115  {']', {{1, 0}, {2, 0}, {3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {1, 6}, {2, 6}, {3, 6}}},
116  {'(', {{4, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {4, 6}}},
117  {')', {{2, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {2, 6}}},
118  {'{', {{4, 0}, {5, 0}, {3, 1}, {3, 2}, {2, 3}, {3, 4}, {3, 5}, {4, 6}, {5, 6}}},
119  {'}', {{1, 0}, {2, 0}, {3, 1}, {3, 2}, {4, 3}, {3, 4}, {3, 5}, {1, 6}, {2, 6}}},
120  {'<', {{4, 1}, {3, 2}, {2, 3}, {3, 4}, {4, 5}}},
121  {'>', {{2, 1}, {3, 2}, {4, 3}, {3, 4}, {2, 5}}},
122  {'|', {{3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}}},
123  {' ', {}},
124  {'.', {{3, 6}}},
125  {',', {{3, 5}, {2, 6}}},
126  {':', {{3, 1}, {3, 5}}},
127  {';', {{3, 2}, {3, 5}, {2, 6}}},
128  {'!', {{3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 6}}},
129  {'?', {{2, 0}, {3, 0}, {4, 0}, {1, 1}, {5, 1}, {5, 2}, {4, 3}, {3, 4}, {3, 6}}},
130  {'&', {{2, 0}, {3, 0}, {1, 1}, {4, 1}, {1, 2}, {4, 2}, {2, 3}, {3, 3}, {5, 3}, {1, 4}, {4, 4}, {1, 5}, {4, 5}, {2, 6}, {3, 6}, {5, 6}}},
131  {'$', {{3, 0}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {1, 2}, {3, 2}, {2, 3}, {3, 3}, {4, 3}, {3, 4}, {5, 4}, {1, 5}, {2, 5}, {3, 5}, {4, 5}, {3, 6}}},
132  {L'\u20AC', {{3, 0}, {4, 0}, {5, 0}, {2, 1}, {1, 2}, {2, 2}, {3, 2}, {4, 2}, {5, 2}, {2, 3}, {1, 4}, {2, 4}, {3, 4}, {4, 4}, {5, 4}, {2, 5}, {3, 6}, {4, 6}, {5, 6}}},
133  };
134  if (character_ != value) {
135  if (characters.find(value) == characters.end()) throw argument_exception(strings::format("Only characters : \"{}\" are valid"_t, get_valid_characters()), caller_info_);
136  character_ = value;
137  dot_matrix_display::dots(characters[value]);
138  }
139  }
140  void set_segment_style(forms::segment_style value) override {}
141  void set_dot_matrix_style(forms::dot_matrix_style value) override {dot_matrix_display::dot_matrix_style(value);}
142  void set_show_background_digit(bool value) override {dot_matrix_display::show_background_dot(value);}
143  void set_thickness(int32_t value) override {dot_matrix_display::thickness(value);}
144 
145  private:
146  wchar_t character_ = ' ';
147  };
148 
149  class fourteen_segment_display_digit : public fourteen_segment_display, public idigit {
150  public:
151  fourteen_segment_display_digit() = default;
152 
153  wchar_t get_character() const override {return character_;}
154  std::string get_valid_characters() const override {return "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=+-*/\\_°\"'[]()| .,:";}
155  int32_t get_thickness() const override {return fourteen_segment_display::thickness();}
156 
157  void set_background_digit_transparency(double value) override {fourteen_segment_display::background_segment_transparency(value);}
158  void set_character(wchar_t value) override {
159  static std::map<wchar_t, forms::segments> characters {
204  {'i', forms::segments::l},
228  {'_', forms::segments::d},
231  {'\'', forms::segments::f},
237  {' ', forms::segments::none},
238  {'.', forms::segments::dp},
239  {',', forms::segments::k},
240  {':', forms::segments::pc}
241  };
242  if (character_ != value) {
243  if (characters.find(value) == characters.end()) throw argument_exception(strings::format("Only characters : \"{}\" are valid"_t, get_valid_characters()), caller_info_);
244  character_ = value;
245  fourteen_segment_display::value(characters[value]);
246  }
247  }
248  void set_segment_style(forms::segment_style value) override {fourteen_segment_display::segment_style(value);}
249  void set_dot_matrix_style(forms::dot_matrix_style value) override {}
250  void set_show_background_digit(bool value) override {fourteen_segment_display::show_background_segment(value);}
251  void set_thickness(int32_t value) override {seven_segment_display::thickness(value);}
252 
253  private:
254  wchar_t character_ = ' ';
255  };
256 
257  class nine_segment_display_digit : public nine_segment_display, public idigit {
258  public:
259  nine_segment_display_digit() = default;
260 
261  wchar_t get_character() const override {return character_;}
262  std::string get_valid_characters() const override {return "0123456789ABCDEFGHIJLNOPQRSTUYabcdefghijlnopqrstuy=-_°\"'[]| .,:";}
263  int32_t get_thickness() const override {return nine_segment_display::thickness();}
264 
265  void set_background_digit_transparency(double value) override {nine_segment_display::background_segment_transparency(value);}
266  void set_character(wchar_t value) override {
267  static std::map<wchar_t, forms::segments> characters {
295  {'i', forms::segments::c},
319  {'_', forms::segments::d},
322  {'\'', forms::segments::f},
326  {'.', forms::segments::dp},
327  {',', forms::segments::dp},
328  {':', forms::segments::pc}
329  };
330  if (character_ != value) {
331  if (characters.find(value) == characters.end()) throw argument_exception(strings::format("Only characters : \"{}\" are valid"_t, get_valid_characters()), caller_info_);
332  character_ = value;
333  nine_segment_display::value(characters[value]);
334  }
335  }
336  void set_segment_style(forms::segment_style value) override {nine_segment_display::segment_style(value);}
337  void set_dot_matrix_style(forms::dot_matrix_style value) override {}
338  void set_show_background_digit(bool value) override {nine_segment_display::show_background_segment(value);}
339  void set_thickness(int32_t value) override {seven_segment_display::thickness(value);}
340 
341  private:
342  wchar_t character_ = ' ';
343  };
344 
345  class seven_segment_display_digit : public seven_segment_display, public idigit {
346  public:
347  seven_segment_display_digit() = default;
348 
349  wchar_t get_character() const override {return character_;}
350  std::string get_valid_characters() const override {return "0123456789ABCDEFGHIJLNOPQRSTUYabcdefghijlnopqrstuy=-_°\"'[]| .,:";}
351  int32_t get_thickness() const override {return seven_segment_display::thickness();}
352 
353  void set_background_digit_transparency(double value) override {seven_segment_display::background_segment_transparency(value);}
354  void set_character(wchar_t value) override {
355  static std::map<wchar_t, forms::segments> characters {
383  {'i', forms::segments::c},
407  {'-', forms::segments::g},
408  {'_', forms::segments::d},
411  {'\'', forms::segments::f},
415  {'.', forms::segments::dp},
416  {',', forms::segments::dp},
417  {':', forms::segments::pc}};
418  if (character_ != value) {
419  if (characters.find(value) == characters.end()) throw argument_exception(strings::format("Only characters : \"{}\" are valid"_t, get_valid_characters()), caller_info_);
420  character_ = value;
421  seven_segment_display::value(characters[value]);
422  }
423  }
424  void set_segment_style(forms::segment_style value) override {seven_segment_display::segment_style(value);}
425  void set_dot_matrix_style(forms::dot_matrix_style value) override {}
426  void set_show_background_digit(bool value) override {seven_segment_display::show_background_segment(value);}
427  void set_thickness(int32_t value) override {seven_segment_display::thickness(value);}
428 
429  private:
430  wchar_t character_ = ' ';
431  };
432 
433  class sixteen_segment_display_digit : public sixteen_segment_display, public idigit {
434  public:
435  sixteen_segment_display_digit() = default;
436 
437  wchar_t get_character() const override {return character_;}
438  std::string get_valid_characters() const override {return "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=+-*/\\_°\"'[]()| .,:";}
439  int32_t get_thickness() const override {return sixteen_segment_display::thickness();}
440 
441  void set_background_digit_transparency(double value) override {sixteen_segment_display::background_segment_transparency(value);}
442  void set_character(wchar_t value) override {
443  static std::map<wchar_t, forms::segments> characters {
489  {'i', forms::segments::l},
515  {'\'', forms::segments::f},
521  {' ', forms::segments::none},
522  {'.', forms::segments::dp},
523  {',', forms::segments::k},
524  {':', forms::segments::pc}
525  };
526  if (character_ != value) {
527  if (characters.find(value) == characters.end()) throw argument_exception(strings::format("Only characters : \"{}\" are valid"_t, get_valid_characters()), caller_info_);
528  character_ = value;
529  sixteen_segment_display::value(characters[value]);
530  }
531  }
532  void set_segment_style(forms::segment_style value) override {sixteen_segment_display::segment_style(value);}
533  void set_dot_matrix_style(forms::dot_matrix_style value) override {}
534  void set_show_background_digit(bool value) override {sixteen_segment_display::show_background_segment(value);}
535  void set_thickness(int32_t value) override {sixteen_segment_display::thickness(value);}
536 
537  private:
538  wchar_t character_ = ' ';
539  };
540 
541  public:
542  lcd_label() {
543  auto_size_mode_ = forms::auto_size_mode::grow_and_shrink;
544  size_ = default_size();
545  }
546 
547  double background_digit_transparency() const {return background_digit_transparency_;}
548  lcd_label& background_digit_transparency(double value) {
549  if (value < 0.0 && value > 1.0) throw argument_out_of_range_exception("value must be between 0.0 and 1.0."_t, caller_info_);
550  if (background_digit_transparency_ != value) {
551  background_digit_transparency_ = value;
552  set_digits_params();
553  }
554  return *this;
555  }
556 
557  bool show_background_digit() const {return show_background_digit_;}
558  lcd_label& show_background_digit(bool value) {
559  if (show_background_digit_ != value) {
560  show_background_digit_ = value;
561  set_digits_params();
562  }
563  return *this;
564  }
565 
566  int32_t digit_spacing() const {return digit_spacing_.value_or(lcd_style_ == lcd_style::dot_matrix_display ? 0 : thickness());}
567  lcd_label& digit_spacing(int32_t value) {
568  if (value < 0) throw argument_out_of_range_exception("value must be positive"_t, caller_info_);
569  if (digit_spacing_ != value) {
570  digit_spacing_ = value;
571  set_digits_params();
572  }
573  return *this;
574  }
575 
576  forms::lcd_style lcd_style() const {return lcd_style_;}
577  lcd_label& lcd_style(forms::lcd_style value) {
578  if (lcd_style_ != value) {
579  lcd_style_ = value;
580  std::string current_text = text();
581  text("");
582  text(current_text);
583  }
584  return *this;
585  }
586 
587  forms::segment_style segment_style() const {return segment_style_;}
588  lcd_label& segment_style(forms::segment_style value) {
589  if (segment_style_ != value) {
590  segment_style_ = value;
591  for (auto& digit : digits_)
592  digit->set_segment_style(value);
593  }
594  return *this;
595  }
596 
597  forms::dot_matrix_style dot_matrix_style() const {return dot_matrix_style_;}
598  lcd_label& dot_matrix_style(forms::dot_matrix_style value) {
599  if (dot_matrix_style_ != value) {
600  dot_matrix_style_ = value;
601  for (auto& digit : digits_)
602  digit->set_dot_matrix_style(value);
603  }
604  return *this;
605  }
606 
607  int32_t thickness() const {return thickness_.value_or(digits_.size() ? digits_[0]->get_thickness() : 1);}
608  lcd_label& thickness(int32_t value) {
609  if (thickness_ != value) {
610  thickness_ = value;
611  set_digits_params();
612  }
613  return *this;
614  }
615 
616  using control::text;
617  control& text(const std::string& value) override {
618  if (text_ != value) {
619  suspend_layout();
620  std::wstring str = std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>().from_bytes(value.c_str());
621  if (str.size() < digits_.size())
622  digits_.erase(digits_.begin() + value.size(), digits_.end());
623  if (str.size() > digits_.size())
624  for (size_t index = digits_.size(); index < str.size(); index++) {
625  switch (lcd_style_) {
626  case lcd_style::seven_segment_display: digits_.push_back(std::make_shared<seven_segment_display_digit>()); break;
627  case lcd_style::nine_segment_display: digits_.push_back(std::make_shared<nine_segment_display_digit>()); break;
628  case lcd_style::fourteen_segment_display: digits_.push_back(std::make_shared<fourteen_segment_display_digit>()); break;
629  case lcd_style::sixteen_segment_display: digits_.push_back(std::make_shared<sixteen_segment_display_digit>()); break;
630  case lcd_style::dot_matrix_display: digits_.push_back(std::make_shared<dot_matrix_display_digit>()); break;
631  default: throw argument_exception("lcd_style invalid", caller_info_);
632  }
633  dynamic_cast<control*>(digits_[digits_.size() - 1].get())->parent(*this);
634  dynamic_cast<control*>(digits_[digits_.size() - 1].get())->click += [this] {on_click(event_args::empty);};
635  dynamic_cast<control*>(digits_[digits_.size() - 1].get())->mouse_down += [this](control& sender, const mouse_event_args& e) {on_mouse_down(mouse_event_args(e.button(), e.location() + drawing::size(sender.location()), e.clicks(), e.delta()));};
636  dynamic_cast<control*>(digits_[digits_.size() - 1].get())->mouse_move += [this](control& sender, const mouse_event_args& e) {on_mouse_move(mouse_event_args(e.button(), e.location() + drawing::size(sender.location()), e.clicks(), e.delta()));};
637  dynamic_cast<control*>(digits_[digits_.size() - 1].get())->mouse_up += [this](control& sender, const mouse_event_args& e) {on_mouse_up(mouse_event_args(e.button(), e.location() + drawing::size(sender.location()), e.clicks(), e.delta()));};
638  }
639  for (size_t index = 0; index < str.size(); index++)
640  digits_[index]->set_character(str[index]);
641  set_digits_params();
642  control::text(value);
643  resume_layout();
644  }
645  return *this;
646  }
647 
648  std::string valid_characters() {
649  switch (lcd_style_) {
650  case lcd_style::seven_segment_display: return std::make_shared<seven_segment_display_digit>()->get_valid_characters();
651  case lcd_style::nine_segment_display: return std::make_shared<nine_segment_display_digit>()->get_valid_characters();
652  case lcd_style::fourteen_segment_display: return std::make_shared<fourteen_segment_display_digit>()->get_valid_characters();
653  case lcd_style::sixteen_segment_display: return std::make_shared<sixteen_segment_display_digit>()->get_valid_characters();
654  case lcd_style::dot_matrix_display: return std::make_shared<dot_matrix_display_digit>()->get_valid_characters();
655  default: throw argument_exception("lcd_style invalid", caller_info_);
656  }
657  }
658 
659  protected:
660  drawing::size default_size() const override {return {100, 25};}
661 
662  void set_digits_params() {
663  int32_t offset_left = 0;
664  for (auto& digit : digits_) {
665  dynamic_cast<control*>(digit.get())->height(size_.height());
666  dynamic_cast<control*>(digit.get())->left(offset_left);
667  digit->set_background_digit_transparency(background_digit_transparency_);
668  digit->set_show_background_digit(show_background_digit_);
669  digit->set_segment_style(segment_style_);
670  digit->set_dot_matrix_style(dot_matrix_style_);
671  if (thickness_.has_value()) digit->set_thickness(thickness());
672  offset_left += dynamic_cast<control*>(digit.get())->width() - 2 + digit_spacing();
673  }
674  }
675 
676  void on_handle_created(const event_args& e) override {
677  control::on_handle_created(e);
678  set_digits_params();
679  }
680 
681  void on_size_changed(const event_args& e) override {
682  set_digits_params();
683  control::on_size_changed(e);
684  }
685 
686  void on_resize(const event_args& e) override {
687  set_digits_params();
688  control::on_resize(e);
689  }
690 
691  drawing::size measure_control() const override {
692  if (digits_.size() == 0) return {0, size_.height()};
693  return drawing::size((dynamic_cast<control*>(digits_[0].get())->width() - 2 + digit_spacing()) * static_cast<int32_t>(digits_.size()) - digit_spacing() + 2, size_.height());
694  }
695 
696  private:
697  bool show_background_digit_ = true;
698  double background_digit_transparency_ = 0.05;
699  std::optional<int32_t> digit_spacing_;
700  forms::lcd_style lcd_style_ = forms::lcd_style::seven_segment_display;
701  forms::segment_style segment_style_ = forms::segment_style::standard;
702  forms::dot_matrix_style dot_matrix_style_ = forms::dot_matrix_style::standard;
703  std::vector<std::shared_ptr<idigit>> digits_;
704  std::optional<int32_t> thickness_;
705  };
706  }
707 }
virtual std::optional< control_ref > parent() const
Gets the parent container of the control.
Definition: control.h:488
represent a nine segment display class
Definition: nine_segment_display.h:7
The dp segment (dot point).
virtual int32_t width() const
Gets the width of the control.
Definition: control.h:563
represent a nine segment display class
Definition: sixteen_segment_display.h:7
represent a dot matrix display class
Definition: dot_matrix_display.h:11
The a1 segment.
represent a nine segment display class
Definition: fourteen_segment_display.h:7
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:9
Specifies that both the width and height property values of the control are defined.
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:16
Definition: lcd_label.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:15
The g2 segment.
void resume_layout()
Resumes usual layout logic.
Definition: control.h:699
virtual drawing::point location() const
Gets the coordinates of the upper-left corner of the control relative to the upper-left corner of its...
Definition: control.h:437
#define caller_info_
Get xtd::tunit::caller_info informations.
Definition: caller_info.h:82
The g1 segment.
The control grows or shrinks to fit its contents. The control cannot be resized manually.
The a2 segment.
void suspend_layout()
Temporarily suspends the layout logic for the control.
Definition: control.h:727
drawing::size measure_control() const override
Measure this control.
Definition: lcd_label.h:691
virtual int32_t height() const
Gets the height of the control.
Definition: control.h:415
int32_t height() const
Gets he vertical component of this Size Class.
Definition: size.h:48
virtual int32_t left() const
Gets the distance, in pixels, between the left edge of the control and the left edge of its container...
Definition: control.h:426
The cp segment (punctuation colon).
static std::basic_string< char_t > format(const std::basic_string< char_t > &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: strings.h:612
The exception that is thrown when one of the arguments provided to a method is not valid...
Definition: argument_exception.h:12
control & text(const std::string &value) override
Sets the text associated with this control.
Definition: lcd_label.h:617
drawing::size default_size() const override
Gets the default size of the control.
Definition: lcd_label.h:660
static const event_args empty
Provides a value to use with events that do not have event data.
Definition: event_args.h:23
The exception that is thrown when one of the arguments provided to a method is out of range...
Definition: argument_out_of_range_exception.h:12
virtual const std::string & text() const
Gets the text associated with this control.
Definition: control.h:534
Defines the base class for controls, which are components with visual representation.
Definition: control.h:61
Definition: mouse_event_args.h:20
represent a seven segment display class
Definition: seven_segment_display.h:9