xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
lcd_label.h
Go to the documentation of this file.
1 #pragma once
6 #include <xtd/as.h>
7 #include <xtd/interface.h>
8 #include "control.h"
9 #include "dot_matrix_display.h"
10 #include "lcd_style.h"
11 #include "nine_segment_display.h"
12 #include "seven_segment_display.h"
15 
16 namespace xtd {
17  namespace forms {
30  class lcd_label : public control {
31  class idigit interface_ {
32  public:
33  virtual wchar_t get_character() const = 0;
34  virtual xtd::ustring get_valid_characters() const = 0;
35  virtual int32_t get_thickness() const = 0;
36 
37  virtual void set_back_digit_color(const xtd::drawing::color& value) = 0;
38  virtual void set_back_digit_opacity(double value) = 0;
39  virtual void set_character(wchar_t value) = 0;
40  virtual void set_segment_style(forms::segment_style value) = 0;
41  virtual void set_dot_matrix_style(forms::dot_matrix_style value) = 0;
42  virtual void set_show_back_digit(bool value) = 0;
43  virtual void set_thickness(int32_t value) = 0;
44  };
45 
46  class dot_matrix_display_digit : public dot_matrix_display, public idigit {
47  public:
48  dot_matrix_display_digit() = default;
49 
50  wchar_t get_character() const override {return character_;}
51  xtd::ustring get_valid_characters() const override {return "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=+-*/%\\_°\"'[](){}<>| .,:;!?&$€";}
52  int32_t get_thickness() const override {return dot_matrix_display::thickness();}
53 
54  void set_back_digit_color(const xtd::drawing::color& value) override {dot_matrix_display::back_dot_color(value);}
55  void set_back_digit_opacity(double value) override {dot_matrix_display::back_dot_opacity(value);}
56  void set_character(wchar_t value) override {
57  static std::map<wchar_t, dot_matrix_display::points_collection> characters {
58  {'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}}},
59  {'1', {{3, 0}, {2, 1}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}}},
60  {'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}}},
61  {'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}}},
62  {'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}}},
63  {'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}}},
64  {'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}}},
65  {'7', {{1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {5, 1}, {5, 2}, {4, 3}, {4, 4}, {3, 5}, {3, 6}}},
66  {'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}}},
67  {'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}}},
68  {'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}}},
69  {'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}}},
70  {'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}}},
71  {'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}}},
72  {'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}}},
73  {'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}}},
74  {'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}}},
75  {'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}}},
76  {'I', {{3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}}},
77  {'J', {{5, 0}, {5, 1}, {5, 2}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {2, 6}, {3, 6}, {4, 6}}},
78  {'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}}},
79  {'L', {{1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {2, 6}, {3, 6}, {4, 6}, {5, 6}}},
80  {'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}}},
81  {'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}}},
82  {'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}}},
83  {'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}}},
84  {'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}}},
85  {'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}}},
86  {'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}}},
87  {'T', {{1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}}},
88  {'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}}},
89  {'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}}},
90  {'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}}},
91  {'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}}},
92  {'Y', {{1, 0}, {5, 0}, {1, 1}, {5, 1}, {2, 2}, {4, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}}},
93  {'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}}},
94  {'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}}},
95  {'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}}},
96  {'c', {{2, 2}, {3, 2}, {4, 2}, {5, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 6}, {3, 6}, {4, 6}, {5, 6}}},
97  {'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}}},
98  {'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}}},
99  {'f', {{3, 0}, {4, 0}, {2, 1}, {2, 2}, {3, 2}, {2, 3}, {2, 4}, {2, 5}, {2, 6}}},
100  {'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}}},
101  {'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}}},
102  {'i', {{3, 0}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}}},
103  {'j', {{4, 0}, {4, 2}, {4, 3}, {4, 4}, {4, 5}, {2, 6}, {3, 6}}},
104  {'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}}},
105  {'l', {{3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {4, 6}}},
106  {'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}}},
107  {'n', {{2, 2}, {3, 2}, {4, 2}, {1, 3}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {1, 6}, {5, 6}}},
108  {'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}}},
109  {'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}}},
110  {'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}}},
111  {'r', {{2, 2}, {3, 2}, {4, 2}, {5, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}}},
112  {'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}}},
113  {'t', {{3, 0}, {3, 1}, {2, 2}, {3, 2}, {4, 2}, {3, 3}, {3, 4}, {3, 5}, {4, 6}, {5, 6}}},
114  {'u', {{1, 2}, {5, 2}, {1, 3}, {5, 3}, {1, 4}, {5, 4}, {1, 5}, {5, 5}, {2, 6}, {3, 6}, {4, 6}}},
115  {'v', {{1, 2}, {5, 2}, {1, 3}, {5, 3}, {2, 4}, {4, 4}, {2, 5}, {4, 5}, {3, 6}}},
116  {'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}}},
117  {'x', {{1, 2}, {5, 2}, {2, 3}, {4, 3}, {3, 4}, {2, 5}, {4, 5}, {1, 6}, {5, 6}}},
118  {'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}}},
119  {'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}}},
120  {'=', {{1, 2}, {2, 2}, {3, 2}, {4, 2}, {5, 2}, {1, 4}, {2, 4}, {3, 4}, {4, 4}, {5, 4}}},
121  {'+', {{3, 1}, {3, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {5, 3}, {3, 4}, {3, 5}}},
122  {'-', {{1, 3}, {2, 3}, {3, 3}, {4, 3}, {5, 3}}},
123  {'*', {{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}}},
124  {'/', {{5, 1}, {4, 2}, {3, 3}, {2, 4}, {1, 5}}},
125  {'%', {{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}}},
126  {'\\', {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}}},
127  {'_', {{1, 6}, {2, 6}, {3, 6}, {4, 6}, {5, 6}}},
128  {L'\u00B0', {{2, 0}, {3, 0}, {1, 1}, {4, 1}, {1, 2}, {4, 2}, {2, 3}, {3, 3}}},
129  {'"', {{2, 0}, {5, 0}, {2, 1}, {5, 1}, {1, 2}, {4, 2}}},
130  {'\'', {{3, 0}, {3, 1}, {2, 2}}},
131  {'[', {{3, 0}, {4, 0}, {5, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}, {4, 6}, {5, 6}}},
132  {']', {{1, 0}, {2, 0}, {3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {1, 6}, {2, 6}, {3, 6}}},
133  {'(', {{4, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {4, 6}}},
134  {')', {{2, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {2, 6}}},
135  {'{', {{4, 0}, {5, 0}, {3, 1}, {3, 2}, {2, 3}, {3, 4}, {3, 5}, {4, 6}, {5, 6}}},
136  {'}', {{1, 0}, {2, 0}, {3, 1}, {3, 2}, {4, 3}, {3, 4}, {3, 5}, {1, 6}, {2, 6}}},
137  {'<', {{4, 1}, {3, 2}, {2, 3}, {3, 4}, {4, 5}}},
138  {'>', {{2, 1}, {3, 2}, {4, 3}, {3, 4}, {2, 5}}},
139  {'|', {{3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}}},
140  {' ', {}},
141  {'.', {{3, 6}}},
142  {',', {{3, 5}, {2, 6}}},
143  {':', {{3, 1}, {3, 5}}},
144  {';', {{3, 2}, {3, 5}, {2, 6}}},
145  {'!', {{3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 6}}},
146  {'?', {{2, 0}, {3, 0}, {4, 0}, {1, 1}, {5, 1}, {5, 2}, {4, 3}, {3, 4}, {3, 6}}},
147  {'&', {{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}}},
148  {'$', {{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}}},
149  {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}}},
150  };
151  if (character_ != value) {
152  auto it = characters.find(value);
153  if (it == characters.end()) throw argument_exception(ustring::format("Only characters : \"{}\" are valid"_t, get_valid_characters()), current_stack_frame_);
154  character_ = value;
155  dot_matrix_display::set_dots(it->second);
156  }
157  }
158  void set_segment_style(forms::segment_style value) override {}
159  void set_dot_matrix_style(forms::dot_matrix_style value) override {dot_matrix_display::dot_matrix_style(value);}
160  void set_show_back_digit(bool value) override {dot_matrix_display::show_back_dot(value);}
161  void set_thickness(int32_t value) override {dot_matrix_display::thickness(value);}
162 
163  private:
164  wchar_t character_ = ' ';
165  };
166 
167  class fourteen_segment_display_digit : public fourteen_segment_display, public idigit {
168  public:
169  fourteen_segment_display_digit() = default;
170 
171  wchar_t get_character() const override {return character_;}
172  xtd::ustring get_valid_characters() const override {return "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=+-*/\\_°\"'[]()| .,:";}
173  int32_t get_thickness() const override {return fourteen_segment_display::thickness();}
174 
175  void set_back_digit_color(const xtd::drawing::color& value) override {fourteen_segment_display::back_segment_color(value);}
176  void set_back_digit_opacity(double value) override {fourteen_segment_display::back_segment_opacity(value);}
177  void set_character(wchar_t value) override {
178  static std::map<wchar_t, forms::segments> characters {
223  {'i', forms::segments::l},
247  {'_', forms::segments::d},
250  {'\'', forms::segments::f},
256  {' ', forms::segments::none},
257  {'.', forms::segments::dp},
258  {',', forms::segments::k},
259  {':', forms::segments::pc}
260  };
261  if (character_ != value) {
262  auto it = characters.find(value);
263  if (it == characters.end()) throw argument_exception(ustring::format("Only characters : \"{}\" are valid"_t, get_valid_characters()), current_stack_frame_);
264  character_ = value;
266  }
267  }
268  void set_segment_style(forms::segment_style value) override {fourteen_segment_display::segment_style(value);}
269  void set_dot_matrix_style(forms::dot_matrix_style value) override {}
270  void set_show_back_digit(bool value) override {fourteen_segment_display::show_back_segment(value);}
271  void set_thickness(int32_t value) override {seven_segment_display::thickness(value);}
272 
273  private:
274  wchar_t character_ = ' ';
275  };
276 
277  class nine_segment_display_digit : public nine_segment_display, public idigit {
278  public:
279  nine_segment_display_digit() = default;
280 
281  wchar_t get_character() const override {return character_;}
282  xtd::ustring get_valid_characters() const override {return "0123456789ABCDEFGHIJLNOPQRSTUYabcdefghijlnopqrstuy=-_°\"'[]| .,:";}
283  int32_t get_thickness() const override {return nine_segment_display::thickness();}
284 
285  void set_back_digit_color(const xtd::drawing::color& value) override {nine_segment_display::back_segment_color(value);}
286  void set_back_digit_opacity(double value) override {nine_segment_display::back_segment_opacity(value);}
287  void set_character(wchar_t value) override {
288  static std::map<wchar_t, forms::segments> characters {
316  {'i', forms::segments::c},
340  {'_', forms::segments::d},
343  {'\'', forms::segments::f},
347  {'.', forms::segments::dp},
348  {',', forms::segments::dp},
349  {':', forms::segments::pc}
350  };
351  if (character_ != value) {
352  auto it = characters.find(value);
353  if (it == characters.end()) throw argument_exception(ustring::format("Only characters : \"{}\" are valid"_t, get_valid_characters()), current_stack_frame_);
354  character_ = value;
355  nine_segment_display::value(it->second);
356  }
357  }
358  void set_segment_style(forms::segment_style value) override {nine_segment_display::segment_style(value);}
359  void set_dot_matrix_style(forms::dot_matrix_style value) override {}
360  void set_show_back_digit(bool value) override {nine_segment_display::show_back_segment(value);}
361  void set_thickness(int32_t value) override {seven_segment_display::thickness(value);}
362 
363  private:
364  wchar_t character_ = ' ';
365  };
366 
367  class seven_segment_display_digit : public seven_segment_display, public idigit {
368  public:
369  seven_segment_display_digit() = default;
370 
371  wchar_t get_character() const override {return character_;}
372  xtd::ustring get_valid_characters() const override {return "0123456789ABCDEFGHIJLNOPQRSTUYabcdefghijlnopqrstuy=-_°\"'[]| .,:";}
373  int32_t get_thickness() const override {return seven_segment_display::thickness();}
374 
375  void set_back_digit_color(const xtd::drawing::color& value) override {seven_segment_display::back_segment_color(value);}
376  void set_back_digit_opacity(double value) override {seven_segment_display::back_segment_opacity(value);}
377  void set_character(wchar_t value) override {
378  static std::map<wchar_t, forms::segments> characters {
406  {'i', forms::segments::c},
430  {'-', forms::segments::g},
431  {'_', forms::segments::d},
434  {'\'', forms::segments::f},
438  {'.', forms::segments::dp},
439  {',', forms::segments::dp},
440  {':', forms::segments::pc}};
441  if (character_ != value) {
442  auto it = characters.find(value);
443  if (it == characters.end()) throw argument_exception(ustring::format("Only characters : \"{}\" are valid"_t, get_valid_characters()), current_stack_frame_);
444  character_ = value;
445  seven_segment_display::value(it->second);
446  }
447  }
448  void set_segment_style(forms::segment_style value) override {seven_segment_display::segment_style(value);}
449  void set_dot_matrix_style(forms::dot_matrix_style value) override {}
450  void set_show_back_digit(bool value) override {seven_segment_display::show_back_segment(value);}
451  void set_thickness(int32_t value) override {seven_segment_display::thickness(value);}
452 
453  private:
454  wchar_t character_ = ' ';
455  };
456 
457  class sixteen_segment_display_digit : public sixteen_segment_display, public idigit {
458  public:
459  sixteen_segment_display_digit() = default;
460 
461  wchar_t get_character() const override {return character_;}
462  xtd::ustring get_valid_characters() const override {return "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=+-*/\\_°\"'[]()| .,:";}
463  int32_t get_thickness() const override {return sixteen_segment_display::thickness();}
464 
465  void set_back_digit_color(const xtd::drawing::color& value) override {sixteen_segment_display::back_segment_color(value);}
466  void set_back_digit_opacity(double value) override {sixteen_segment_display::back_segment_opacity(value);}
467  void set_character(wchar_t value) override {
468  static std::map<wchar_t, forms::segments> characters {
514  {'i', forms::segments::l},
540  {'\'', forms::segments::f},
546  {' ', forms::segments::none},
547  {'.', forms::segments::dp},
548  {',', forms::segments::k},
549  {':', forms::segments::pc}
550  };
551  if (character_ != value) {
552  auto it = characters.find(value);
553  if (it == characters.end()) throw argument_exception(ustring::format("Only characters : \"{}\" are valid"_t, get_valid_characters()), current_stack_frame_);
554  character_ = value;
555  sixteen_segment_display::value(it->second);
556  }
557  }
558  void set_segment_style(forms::segment_style value) override {sixteen_segment_display::segment_style(value);}
559  void set_dot_matrix_style(forms::dot_matrix_style value) override {}
560  void set_show_back_digit(bool value) override {sixteen_segment_display::show_back_segment(value);}
561  void set_thickness(int32_t value) override {sixteen_segment_display::thickness(value);}
562 
563  private:
564  wchar_t character_ = ' ';
565  };
566 
567  public:
570  auto_size_mode_ = forms::auto_size_mode::grow_and_shrink;
571  size_ = default_size();
572  }
573 
577  xtd::drawing::color back_digit_color() const {return back_digit_color_.value_or(fore_color());}
583  if (!back_digit_color_.has_value() || back_digit_color_.value() != value) {
584  back_digit_color_ = value;
585  set_digits_params();
586  }
587  return *this;
588  }
589 
592  double back_digit_opacity() const {return back_digit_opacity_;}
597  lcd_label& back_digit_opacity(double value) {
598  if (value < 0.0 || value > 1.0) throw argument_out_of_range_exception("value must be between 0.0 and 1.0."_t, current_stack_frame_);
599  if (back_digit_opacity_ != value) {
600  back_digit_opacity_ = value;
601  set_digits_params();
602  }
603  return *this;
604  }
605 
608  bool show_back_digit() const {return show_back_digit_;}
612  lcd_label& show_back_digit(bool value) {
613  if (show_back_digit_ != value) {
614  show_back_digit_ = value;
615  set_digits_params();
616  }
617  return *this;
618  }
619 
622  int32_t digit_spacing() const {return digit_spacing_.value_or(lcd_style_ == lcd_style::dot_matrix_display ? 0 : thickness());}
627  lcd_label& digit_spacing(int32_t value) {
628  if (value < 0) throw argument_out_of_range_exception("value must be positive"_t, current_stack_frame_);
629  if (digit_spacing_ != value) {
630  digit_spacing_ = value;
631  set_digits_params();
632  }
633  return *this;
634  }
635 
638  forms::lcd_style lcd_style() const {return lcd_style_;}
643  if (lcd_style_ != value) {
644  lcd_style_ = value;
645  xtd::ustring current_text = text();
646  text("");
647  text(current_text);
648  }
649  return *this;
650  }
651 
654  forms::segment_style segment_style() const {return segment_style_;}
659  if (segment_style_ != value) {
660  segment_style_ = value;
661  for (auto& digit : digits_)
662  digit->set_segment_style(value);
663  }
664  return *this;
665  }
666 
669  forms::dot_matrix_style dot_matrix_style() const {return dot_matrix_style_;}
674  if (dot_matrix_style_ != value) {
675  dot_matrix_style_ = value;
676  for (auto& digit : digits_)
677  digit->set_dot_matrix_style(value);
678  }
679  return *this;
680  }
681 
684  int32_t thickness() const {return thickness_.value_or(digits_.size() ? digits_[0]->get_thickness() : 1);}
688  lcd_label& thickness(int32_t value) {
689  if (thickness_ != value) {
690  thickness_ = value;
691  set_digits_params();
692  }
693  return *this;
694  }
695 
696  using control::text;
700  control& text(const xtd::ustring& value) override {
701  if (text_ != value) {
702  suspend_layout();
703  std::wstring str = to_wstring(value.c_str());
704  if (str.size() < digits_.size())
705  digits_.erase(digits_.begin() + value.size(), digits_.end());
706  if (str.size() > digits_.size())
707  for (size_t index = digits_.size(); index < str.size(); index++) {
708  switch (lcd_style_) {
709  case lcd_style::seven_segment_display: digits_.push_back(std::make_shared<seven_segment_display_digit>()); break;
710  case lcd_style::nine_segment_display: digits_.push_back(std::make_shared<nine_segment_display_digit>()); break;
711  case lcd_style::fourteen_segment_display: digits_.push_back(std::make_shared<fourteen_segment_display_digit>()); break;
712  case lcd_style::sixteen_segment_display: digits_.push_back(std::make_shared<sixteen_segment_display_digit>()); break;
713  case lcd_style::dot_matrix_display: digits_.push_back(std::make_shared<dot_matrix_display_digit>()); break;
714  default: throw argument_exception("lcd_style invalid", current_stack_frame_);
715  }
716  dynamic_cast<control*>(digits_[digits_.size() - 1].get())->parent(*this);
717  dynamic_cast<control*>(digits_[digits_.size() - 1].get())->click += [this] {on_click(event_args::empty);};
718  dynamic_cast<control*>(digits_[digits_.size() - 1].get())->mouse_down += [this](object& sender, const mouse_event_args& e) {on_mouse_down(mouse_event_args(e.button(), e.clicks(), e.location() + drawing::size(as<control>(sender).location()), e.delta()));};
719  dynamic_cast<control*>(digits_[digits_.size() - 1].get())->mouse_move += [this](object& sender, const mouse_event_args& e) {on_mouse_move(mouse_event_args(e.button(), e.clicks(), e.location() + drawing::size(as<control>(sender).location()), e.delta()));};
720  dynamic_cast<control*>(digits_[digits_.size() - 1].get())->mouse_up += [this](object& sender, const mouse_event_args& e) {on_mouse_up(mouse_event_args(e.button(), e.clicks(), e.location() + drawing::size(as<control>(sender).location()), e.delta()));};
721  }
722  for (size_t index = 0; index < str.size(); index++)
723  digits_[index]->set_character(str[index]);
724  set_digits_params();
725  control::text(value);
726  resume_layout();
727  }
728  return *this;
729  }
730 
735  switch (lcd_style_) {
736  case lcd_style::seven_segment_display: return std::make_shared<seven_segment_display_digit>()->get_valid_characters();
737  case lcd_style::nine_segment_display: return std::make_shared<nine_segment_display_digit>()->get_valid_characters();
738  case lcd_style::fourteen_segment_display: return std::make_shared<fourteen_segment_display_digit>()->get_valid_characters();
739  case lcd_style::sixteen_segment_display: return std::make_shared<sixteen_segment_display_digit>()->get_valid_characters();
740  case lcd_style::dot_matrix_display: return std::make_shared<dot_matrix_display_digit>()->get_valid_characters();
741  default: throw argument_exception("lcd_style invalid", current_stack_frame_);
742  }
743  }
744 
745  protected:
746  drawing::size default_size() const override {return {100, 25};}
747 
748  void on_back_color_changed(const event_args& e) override {
750  invalidate();
751  }
752 
753  void on_fore_color_changed(const event_args& e) override {
755  invalidate();
756  }
757 
758  void on_handle_created(const event_args& e) override {
760  set_digits_params();
761  }
762 
763  void on_size_changed(const event_args& e) override {
764  set_digits_params();
766  }
767 
768  void on_resize(const event_args& e) override {
769  set_digits_params();
771  }
772 
773  drawing::size measure_control() const override {
774  if (digits_.size() == 0) return {0, size_.height()};
775  return drawing::size((dynamic_cast<control*>(digits_[0].get())->width() - 2 + digit_spacing()) * static_cast<int32_t>(digits_.size()) - digit_spacing() + 2, size_.height());
776  }
777 
778  private:
779  static std::wstring to_wstring(const char* str) noexcept {
780  std::wstring out;
781  int32 codepoint = 0;
782  while (*str != 0) {
783  unsigned char ch = static_cast<unsigned char>(*str);
784  if (ch <= 0x7f) codepoint = ch;
785  else if (ch <= 0xbf) codepoint = (codepoint << 6) | (ch & 0x3f);
786  else if (ch <= 0xdf) codepoint = ch & 0x1f;
787  else if (ch <= 0xef) codepoint = ch & 0x0f;
788  else codepoint = ch & 0x07;
789  ++str;
790  if (((*str & 0xc0) != 0x80) && (codepoint <= 0x10ffff)) {
791  if (sizeof(wchar) > 2)
792  out.append(1, static_cast<wchar>(codepoint));
793  else if (codepoint > 0xffff) {
794  out.append(1, static_cast<wchar>(0xd800 + (static_cast<wchar>(codepoint) >> 10)));
795  out.append(1, static_cast<wchar>(0xdc00 + (static_cast<wchar>(codepoint) & 0x03ff)));
796  } else if (codepoint < 0xd800 || codepoint >= 0xe000)
797  out.append(1, static_cast<wchar>(codepoint));
798  }
799  }
800  return out;
801  }
802 
803  void set_digits_params() {
804  int32_t offset_left = 0;
805  for (auto& digit : digits_) {
806  dynamic_cast<control*>(digit.get())->height(size_.height());
807  dynamic_cast<control*>(digit.get())->left(offset_left);
808  digit->set_back_digit_color(back_digit_color());
809  digit->set_back_digit_opacity(back_digit_opacity_);
810  digit->set_show_back_digit(show_back_digit_);
811  digit->set_segment_style(segment_style_);
812  digit->set_dot_matrix_style(dot_matrix_style_);
813  if (thickness_.has_value()) digit->set_thickness(thickness());
814  offset_left += dynamic_cast<control*>(digit.get())->width() - 2 + digit_spacing();
815  }
816  }
817 
818  bool show_back_digit_ = true;
819  std::optional<xtd::drawing::color> back_digit_color_;
820  double back_digit_opacity_ = 0.95;
821  std::optional<int32_t> digit_spacing_;
825  std::vector<std::shared_ptr<idigit>> digits_;
826  std::optional<int32_t> thickness_;
827  };
828  }
829 }
Contains xtd::argument_out_of_range_exception exception.
Contains xtd::as method.
The exception that is thrown when one of the arguments provided to a method is not valid.
Definition: argument_exception.h:19
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:18
Represents an ARGB (alpha, red, green, blue) color.
Definition: color.h:39
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:25
int32_t height() const
Gets he vertical component of this Size Class.
Definition: size.h:57
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
static const event_args empty
Provides a value to use with events that do not have event data.
Definition: event_args.h:31
Defines the base class for controls, which are components with visual representation.
Definition: control.h:67
virtual std::optional< control_ref > parent() const
Gets the parent container of the control.
Definition: control.h:596
void suspend_layout()
Temporarily suspends the layout logic for the control.
Definition: control.h:996
virtual const xtd::ustring & text() const
Gets the text associated with this control.
Definition: control.h:650
virtual drawing::color fore_color() const
Gets the foreground color of the control.
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:503
control()
Initializes a new instance of the control class with default settings.
void resume_layout()
Resumes usual layout logic.
Definition: control.h:947
virtual void invalidate() const
Invalidates the entire surface of the control and causes the control to be redrawn.
Definition: control.h:883
virtual int32_t height() const
Gets the height of the control.
Definition: control.h:486
virtual int32_t width() const
Gets the width of the control.
Definition: control.h:682
Represents a dot matrix display class.
Definition: dot_matrix_display.h:23
virtual forms::dot_matrix_style dot_matrix_style() const
Gets dot matrix style.
Definition: dot_matrix_display.h:74
virtual drawing::color back_dot_color()
Gets background dot color.
Definition: dot_matrix_display.h:41
virtual void set_dots(const points_collection &points)
Sets specified dots to on.
Definition: dot_matrix_display.h:184
virtual bool show_back_dot() const
Gets a value indicate if background dots are shown.
Definition: dot_matrix_display.h:133
virtual double back_dot_opacity() const
Gets the background dot opacity.
Definition: dot_matrix_display.h:56
virtual int32_t thickness() const
Gets thickness of dot.
Definition: dot_matrix_display.h:147
Represents a nine segment display class.
Definition: fourteen_segment_display.h:18
int32_t thickness() const override
Sets thickness of segment.
Definition: fourteen_segment_display.h:27
Represents a lcd label.
Definition: lcd_label.h:30
lcd_label & back_digit_opacity(double value)
Sets the background digit opacity.
Definition: lcd_label.h:597
void on_size_changed(const event_args &e) override
Raises the control::size_changed event.
Definition: lcd_label.h:763
forms::dot_matrix_style dot_matrix_style() const
Gets dot matrix style.
Definition: lcd_label.h:669
drawing::size default_size() const override
Gets the default size of the control.
Definition: lcd_label.h:746
xtd::drawing::color back_digit_color() const
Gets background digit color.
Definition: lcd_label.h:577
void on_handle_created(const event_args &e) override
Raises the control::handle_created event.
Definition: lcd_label.h:758
lcd_label & show_back_digit(bool value)
Sets a value indicate if background digits are shown.
Definition: lcd_label.h:612
lcd_label & lcd_style(forms::lcd_style value)
Sets lcd style.
Definition: lcd_label.h:642
virtual const xtd::ustring & text() const
Gets the text associated with this control.
Definition: control.h:650
xtd::ustring valid_characters()
Gets valid characters.
Definition: lcd_label.h:734
forms::lcd_style lcd_style() const
Gets lcd style.
Definition: lcd_label.h:638
void on_back_color_changed(const event_args &e) override
Raises the control::back_color_changed event.
Definition: lcd_label.h:748
drawing::size measure_control() const override
Measure this control.
Definition: lcd_label.h:773
lcd_label & digit_spacing(int32_t value)
Sets the digit spacing.
Definition: lcd_label.h:627
lcd_label & thickness(int32_t value)
Sets thickness of lcd.
Definition: lcd_label.h:688
forms::segment_style segment_style() const
Gets segment style.
Definition: lcd_label.h:654
double back_digit_opacity() const
Gets the background digit opacity.
Definition: lcd_label.h:592
lcd_label & dot_matrix_style(forms::dot_matrix_style value)
Sets dot matrix style.
Definition: lcd_label.h:673
lcd_label()
Initialise a new lcd_label class.
Definition: lcd_label.h:569
lcd_label & segment_style(forms::segment_style value)
Sets segment style.
Definition: lcd_label.h:658
void on_fore_color_changed(const event_args &e) override
Raises the control::fore_color_changed event.
Definition: lcd_label.h:753
void on_resize(const event_args &e) override
Raises the control::resize event.
Definition: lcd_label.h:768
int32_t digit_spacing() const
Gets the digit spacing.
Definition: lcd_label.h:622
bool show_back_digit() const
Gets a value indicate if background digits are shown.
Definition: lcd_label.h:608
control & text(const xtd::ustring &value) override
Sets the text associated with this control.
Definition: lcd_label.h:700
int32_t thickness() const
Gets thickness of lcd.
Definition: lcd_label.h:684
lcd_label & back_digit_color(const xtd::drawing::color &value)
Sets background digit color.
Definition: lcd_label.h:582
Provides data for the xtd::forms::control::mouse_up, xtd::forms::control::mouse_down,...
Definition: mouse_event_args.h:29
Represents a nine segment display class.
Definition: nine_segment_display.h:18
int32_t thickness() const override
Sets thickness of segment.
Definition: nine_segment_display.h:27
Represents a seven segment display class.
Definition: seven_segment_display.h:22
virtual drawing::color back_segment_color()
Gets background segment color.
Definition: seven_segment_display.h:33
virtual double back_segment_opacity() const
Gets the background segment opacity.
Definition: seven_segment_display.h:48
virtual forms::segments value() const
Gets seven_segment_display value.
Definition: seven_segment_display.h:106
virtual forms::segment_style segment_style() const
Gets segment style.
Definition: seven_segment_display.h:78
virtual bool show_back_segment() const
Gets a value indicate if background segments are shown.
Definition: seven_segment_display.h:64
virtual int32_t thickness() const
Gets thickness of segment.
Definition: seven_segment_display.h:92
Represents a sixteen segment display class.
Definition: sixteen_segment_display.h:18
int32_t thickness() const override
Sets thickness of segment.
Definition: sixteen_segment_display.h:27
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
Contains xtd::forms::control control.
Contains xtd::forms::dot_matrix_display control.
Contains xtd::forms::fourteen_segment_display control.
virtual void on_click(const event_args &e)
Raises the control::click event.
virtual void on_back_color_changed(const event_args &e)
Raises the control::back_color_changed event.
virtual void on_size_changed(const event_args &e)
Raises the control::size_changed event.
virtual void on_mouse_up(const mouse_event_args &e)
Raises the control::mouse_up event.
virtual void on_handle_created(const event_args &e)
Raises the control::handle_created event.
event< control, event_handler > click
Occurs when the control is clicked.
Definition: control.h:1065
event< control, mouse_event_handler > mouse_down
Occurs when the mouse pointer is over the control and a mouse button is pressed.
Definition: control.h:1278
virtual void on_resize(const event_args &e)
Raises the control::resize event.
virtual void on_fore_color_changed(const event_args &e)
Raises the control::fore_color_changed event.
event< control, mouse_event_handler > mouse_move
Occurs when the mouse pointer is moved over the control.
Definition: control.h:1335
virtual void on_mouse_down(const mouse_event_args &e)
Raises the control::mouse_down event.
event< control, mouse_event_handler > mouse_up
Occurs when the mouse pointer is over the control and a mouse button is released.
Definition: control.h:1349
virtual void on_mouse_move(const mouse_event_args &e)
Raises the control::mouse_move event.
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: ustring.h:689
#define interface_
This keyword is use to represent an interface.
Definition: interface.h:55
#define current_stack_frame_
Provides information about the current stack frame.
Definition: stack_frame.h:201
wchar_t wchar
Represents a wide character.
Definition: types.h:251
int32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
@ e
The E key.
segment_style
Represent segment style used by seven_segment_display, fourteen_segment_display, nine_segment_display...
Definition: segment_style.h:17
lcd_style
Represent lcd label style used by lcd_label control.
Definition: lcd_style.h:17
dot_matrix_style
Represent dot matrix style used by dot_matrix_display control.
Definition: dot_matrix_style.h:17
@ standard
Standard segment style.
@ grow_and_shrink
The control grows or shrinks to fit its contents. The control cannot be resized manually.
@ g1
The g1 segment.
@ a
The a segment.
@ h
The h segment.
@ l
The l segment.
@ j
The j segment.
@ c
The c segment.
@ a2
The a2 segment.
@ m
The m segment.
@ d
The d segment.
@ i
The i segment.
@ a1
The a1 segment.
@ k
The k segment.
@ f
The f segment.
@ b
The b segment.
@ dp
The dp segment (dot point).
@ d1
The d1 segment.
@ d2
The d2 segment.
@ g
The g segment.
@ pc
The cp segment (punctuation colon).
@ e
The e segment.
@ g2
The g2 segment.
@ nine_segment_display
Nine segment display style.
@ dot_matrix_display
Dot matrix display style.
@ sixteen_segment_display
Sixteen segment display style.
@ seven_segment_display
Seven segment display style.
@ fourteen_segment_display
Fourteen segment display style.
@ standard
Standard (or round) dot matrix style.
Contains xtd::interface interface.
Contains xtd::forms::lcd_style enum class.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17
Contains xtd::forms::nine_segment_display control.
Contains xtd::forms::seven_segment_display control.
Contains xtd::forms::sixteen_segment_display control.