xtd.forms - Reference Guide  0.1.0
Modern c++17 library containing classes for creating Windows-based applications that take full advantage of the rich user interface features available in the Microsoft Windows, Apple macOS and Linux like Ubuntu operating system.
sixteen_segment_display.h
1 #pragma once
2 #include "fourteen_segment_display.h"
3 
4 namespace xtd {
5  namespace forms {
8  public:
9  sixteen_segment_display() = default;
10 
11  using fourteen_segment_display::thickness;
12  int32_t thickness() const override {return thickness_.value_or(size_.height() < 20 ? 1 : (size_.height() / 20 + ((size_.height() / 20) % 2 ? 0 : 1)));}
13 
14  protected:
15  void on_paint(paint_event_args& e) override {
16  fourteen_segment_display::on_paint(e);
17  drawing::graphics graphics = e.graphics();
18  if ((value_ & forms::segments::a1) == forms::segments::a1) draw_segment_a1(graphics, fore_color());
19  if ((value_ & forms::segments::a2) == forms::segments::a2) draw_segment_a2(graphics, fore_color());
20  if ((value_ & forms::segments::d1) == forms::segments::d1) draw_segment_d1(graphics, fore_color());
21  if ((value_ & forms::segments::d2) == forms::segments::d2) draw_segment_d2(graphics, fore_color());
22  }
23 
24  void draw_background_digit(drawing::graphics& graphics) override {
25  fourteen_segment_display::draw_background_digit(graphics);
26  draw_segment_a1(graphics, background_segment_color());
27  draw_segment_a2(graphics, background_segment_color());
28  draw_segment_d1(graphics, background_segment_color());
29  draw_segment_d2(graphics, background_segment_color());
30  }
31 
32  virtual void draw_segment_a1(drawing::graphics& graphics, const drawing::color& color) {
33  if (segment_style_ == segment_style::standard) {
34  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
35  graphics.draw_line(drawing::pen(color), 2 + thickness() / 2 + abs(offset), 1 + thickness() / 2 + offset, size_.width() / 2 - 1 - abs(offset), 1 + thickness() / 2 + offset);
36  } else if (segment_style_ == segment_style::modern) {
37  for (int32_t offset = 0; offset < thickness(); offset++)
38  graphics.draw_line(drawing::pen(color), 2 + offset, 1 + offset, size_.width() / 2 - 1 - abs(offset / 2), 1 + offset);
39  } else if (segment_style_ == segment_style::mixed) {
40  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
41  graphics.draw_line(drawing::pen(color), 2 + offset + thickness() / 2, 1 + thickness() / 2 + offset, size_.width() / 2 - 1 - abs(offset), 1 + thickness() / 2 + offset);
42  } else if (segment_style_ == segment_style::expanded) {
43  for (int32_t offset = 0; offset < thickness(); offset++)
44  graphics.draw_line(drawing::pen(color), 2 + offset, 1 + offset, size_.width() / 2 + thickness() / 2 - 1 - (offset > thickness() / 2 ? offset : thickness() / 2), 1 + offset);
45  } else if (segment_style_ == segment_style::design) {
46  for (int32_t offset = 0; offset < thickness(); offset++)
47  graphics.draw_line(drawing::pen(color), 2 + thickness(), 1 + offset, size_.width() / 2 + thickness() / 2 - 1 - (offset > thickness() / 2 ? offset : thickness() / 2), 1 + offset);
48  } else if (segment_style_ == segment_style::stick) {
49  for (int32_t offset = 0; offset < thickness(); offset++)
50  graphics.draw_line(drawing::pen(color), 2 + thickness(), 1 + offset, size_.width() / 2 - 1, 1 + offset);
51  }
52  }
53 
54  virtual void draw_segment_a2(drawing::graphics& graphics, const drawing::color& color) {
55  if (segment_style_ == segment_style::standard) {
56  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
57  graphics.draw_line(drawing::pen(color), size_.width() / 2 + 1 + abs(offset), 1 + thickness() / 2 + offset, size_.width() - 3 - thickness() / 2 - abs(offset), 1 + thickness() / 2 + offset);
58  } else if (segment_style_ == segment_style::modern) {
59  for (int32_t offset = 0; offset < thickness(); offset++)
60  graphics.draw_line(drawing::pen(color), size_.width() / 2 + 1 + abs(offset / 2), 1 + offset, size_.width() - 3 - offset, 1 + offset);
61  } else if (segment_style_ == segment_style::mixed) {
62  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
63  graphics.draw_line(drawing::pen(color), size_.width() / 2 + 1 + abs(offset), 1 + thickness() / 2 + offset, size_.width() - 3 - thickness() / 2 - offset, 1 + thickness() / 2 + offset);
64  } else if (segment_style_ == segment_style::expanded) {
65  for (int32_t offset = 0; offset < thickness(); offset++)
66  graphics.draw_line(drawing::pen(color), size_.width() / 2 + 1 - thickness() / 2 + (offset > thickness() / 2 ? offset : thickness() / 2), 1 + offset, size_.width() - 3 - offset, 1 + offset);
67  } else if (segment_style_ == segment_style::design) {
68  for (int32_t offset = 0; offset < thickness(); offset++)
69  graphics.draw_line(drawing::pen(color), size_.width() / 2 + 1 - thickness() / 2 + (offset > thickness() / 2 ? offset : thickness() / 2), 1 + offset, size_.width() - 3 - thickness(), 1 + offset);
70  } else if (segment_style_ == segment_style::stick) {
71  for (int32_t offset = 0; offset < thickness(); offset++)
72  graphics.draw_line(drawing::pen(color), size_.width() / 2 + 1, 1 + offset, size_.width() - 3 - thickness(), 1 + offset);
73  }
74  }
75 
76  virtual void draw_segment_d1(drawing::graphics& graphics, const drawing::color& color) {
77  if (segment_style_ == segment_style::standard) {
78  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
79  graphics.draw_line(drawing::pen(color), 2 + thickness() / 2 + abs(offset), size_.height() - 2 - thickness() / 2 - offset, size_.width() / 2 - 1 - abs(offset), size_.height() - 2 - thickness() / 2 - offset);
80  } else if (segment_style_ == segment_style::modern) {
81  for (int32_t offset = 0; offset < thickness(); offset++)
82  graphics.draw_line(drawing::pen(color), 2 + offset, size_.height() - 2 - offset, size_.width() / 2 - 1 - abs(offset / 2), size_.height() - 2 - offset);
83  } else if (segment_style_ == segment_style::mixed) {
84  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
85  graphics.draw_line(drawing::pen(color), 2 + thickness() / 2 + offset, size_.height() - 2 - thickness() / 2 - offset, size_.width() / 2 - 1 - abs(offset), size_.height() - 2 - thickness() / 2 - offset);
86  } else if (segment_style_ == segment_style::expanded) {
87  for (int32_t offset = 0; offset < thickness(); offset++)
88  graphics.draw_line(drawing::pen(color), 2 + offset, size_.height() - 2 - offset, size_.width() / 2 + thickness() / 2 - 1 - (offset > thickness() / 2 ? offset : thickness() / 2), size_.height() - 2 - offset);
89  } else if (segment_style_ == segment_style::design) {
90  for (int32_t offset = 0; offset < thickness(); offset++)
91  graphics.draw_line(drawing::pen(color), 2 + thickness(), size_.height() - 2 - offset, size_.width() / 2 + thickness() / 2 - 1 - (offset > thickness() / 2 ? offset : thickness() / 2), size_.height() - 2 - offset);
92  } else if (segment_style_ == segment_style::stick) {
93  for (int32_t offset = 0; offset < thickness(); offset++)
94  graphics.draw_line(drawing::pen(color), 2 + thickness(), size_.height() - 2 - offset, size_.width() / 2 - 1, size_.height() - 2 - offset);
95  }
96  }
97 
98  virtual void draw_segment_d2(drawing::graphics& graphics, const drawing::color& color) {
99  if (segment_style_ == segment_style::standard) {
100  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
101  graphics.draw_line(drawing::pen(color), size_.width() / 2 + 1 + abs(offset), size_.height() - 2 - thickness() / 2 - offset, size_.width() - 3 - thickness() / 2 - abs(offset), size_.height() - 2 - thickness() / 2 - offset);
102  } else if (segment_style_ == segment_style::modern) {
103  for (int32_t offset = 0; offset < thickness(); offset++)
104  graphics.draw_line(drawing::pen(color), size_.width() / 2 + 1 + abs(offset / 2), size_.height() - 2 - offset, size_.width() - 3 - offset, size_.height() - 2 - offset);
105  } else if (segment_style_ == segment_style::mixed) {
106  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
107  graphics.draw_line(drawing::pen(color), size_.width() / 2 + 1 + abs(offset), size_.height() - 2 - thickness() / 2 - offset, size_.width() - 3 - thickness() / 2 - offset, size_.height() - 2 - thickness() / 2 - offset);
108  } else if (segment_style_ == segment_style::expanded) {
109  for (int32_t offset = 0; offset < thickness(); offset++)
110  graphics.draw_line(drawing::pen(color), size_.width() / 2 + 1 - thickness() / 2 + (offset > thickness() / 2 ? offset : thickness() / 2), size_.height() - 2 - offset, size_.width() - 3 - offset, size_.height() - 2 - offset);
111  } else if (segment_style_ == segment_style::design) {
112  for (int32_t offset = 0; offset < thickness(); offset++)
113  graphics.draw_line(drawing::pen(color), size_.width() / 2 + 1 - thickness() / 2 + (offset > thickness() / 2 ? offset : thickness() / 2), size_.height() - 2 - offset, size_.width() - 3 - thickness(), size_.height() - 2 - offset);
114  } else if (segment_style_ == segment_style::stick) {
115  for (int32_t offset = 0; offset < thickness(); offset++)
116  graphics.draw_line(drawing::pen(color), size_.width() / 2 + 1, size_.height() - 2 - offset, size_.width() - 3 - thickness(), size_.height() - 2 - offset);
117  }
118  }
119 
120  void draw_segment_i(drawing::graphics& graphics, const drawing::color& color) override {
121  if (segment_style_ == segment_style::standard) {
122  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
123  graphics.draw_line(drawing::pen(color), size_.width() / 2 - offset, 2 + thickness() / 2 + abs(offset), size_.width() / 2 - offset, size_.height() / 2 - 1 - abs(offset));
124  } else if (segment_style_ == segment_style::modern) {
125  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
126  graphics.draw_line(drawing::pen(color), size_.width() / 2 - offset, 2 + abs(2 * offset), size_.width() / 2 - offset, size_.height() / 2 - 1 - abs(offset));
127  } else if (segment_style_ == segment_style::mixed) {
128  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
129  graphics.draw_line(drawing::pen(color), size_.width() / 2 - offset, 2 + thickness() / 2 + abs(offset), size_.width() / 2 - offset, size_.height() / 2 - 1 - abs(offset));
130  } else if (segment_style_ == segment_style::expanded) {
131  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
132  graphics.draw_line(drawing::pen(color), size_.width() / 2 - offset, 2 + thickness() / 2 + abs(offset), size_.width() / 2 - offset, size_.height() / 2 - 1 - abs(offset));
133  } else if (segment_style_ == segment_style::design) {
134  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
135  graphics.draw_line(drawing::pen(color), size_.width() / 2 - offset, 2 + thickness() / 2 + abs(offset), size_.width() / 2 - offset, size_.height() / 2 - 1 - abs(offset));
136  } else if (segment_style_ == segment_style::stick) {
137  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
138  graphics.draw_line(drawing::pen(color), size_.width() / 2 - offset, 2 + thickness(), size_.width() / 2 - offset, size_.height() / 2 - 1 - abs(offset));
139  }
140  }
141 
142  void draw_segment_l(drawing::graphics& graphics, const drawing::color& color) override {
143  if (segment_style_ == segment_style::standard) {
144  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
145  graphics.draw_line(drawing::pen(color), size_.width() / 2 - offset, size_.height() / 2 + 1 - thickness() / 2 + thickness() / 2 + abs(offset), size_.width() / 2 - offset, size_.height() - 3 - thickness() / 2 - abs(offset));
146  } else if (segment_style_ == segment_style::modern) {
147  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
148  graphics.draw_line(drawing::pen(color), size_.width() / 2 - offset, size_.height() / 2 + 1 - thickness() / 2 + thickness() / 2 + abs(offset), size_.width() / 2 - offset, size_.height() - 3 - abs(2 * offset));
149  } else if (segment_style_ == segment_style::mixed) {
150  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
151  graphics.draw_line(drawing::pen(color), size_.width() / 2 - offset, size_.height() / 2 + 1 - thickness() / 2 + thickness() / 2 + abs(offset), size_.width() / 2 - offset, size_.height() - 3 - thickness() / 2 - abs(offset));
152  } else if (segment_style_ == segment_style::expanded) {
153  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
154  graphics.draw_line(drawing::pen(color), size_.width() / 2 - offset, size_.height() / 2 + 1 - thickness() / 2 + thickness() / 2 + abs(offset), size_.width() / 2 - offset, size_.height() - 3 - thickness() / 2 - abs(offset));
155  } else if (segment_style_ == segment_style::design) {
156  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
157  graphics.draw_line(drawing::pen(color), size_.width() / 2 - offset, size_.height() / 2 + 1 - thickness() / 2 + thickness() / 2 + abs(offset), size_.width() / 2 - offset, size_.height() - 3 - thickness() / 2 - abs(offset));
158  } else if (segment_style_ == segment_style::stick) {
159  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
160  graphics.draw_line(drawing::pen(color), size_.width() / 2 - offset, size_.height() / 2 + 1 - thickness() / 2 + thickness() / 2 + abs(offset), size_.width() / 2 - offset, size_.height() - 3 - thickness());
161  }
162  }
163 
164  protected:
165  void draw_segment_a(drawing::graphics& graphics, const drawing::color& color) override {}
166  void draw_segment_d(drawing::graphics& graphics, const drawing::color& color) override {}
167  };
168  }
169 }
represent a nine segment display class
Definition: sixteen_segment_display.h:7
represent a nine segment display class
Definition: fourteen_segment_display.h:7
The a1 segment.
The a2 segment.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: paint_event_args.h:15