xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
sixteen_segment_display.h
Go to the documentation of this file.
1 #pragma once
6 
7 namespace xtd {
8  namespace forms {
19  public:
21 
24  sixteen_segment_display() = default;
26 
28 
33  int32_t thickness() const override {return thickness_.value_or(size().height() < 20 ? 1 : (size().height() / 20 + ((size().height() / 20) % 2 ? 0 : 1)));}
37  seven_segment_display& thickness(int32_t value) override {
38  if (!thickness_.has_value() || thickness_.value() != value) {
39  thickness_ = value;
40  invalidate();
41  }
42  return *this;
43  }
45 
46  protected:
48 
50  void on_paint(paint_event_args& e) override {
56  }
57 
58  void draw_back_digit(drawing::graphics& graphics) override {
64  }
65 
69  virtual void draw_segment_a1(drawing::graphics& graphics, const drawing::color& color) {
71  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
72  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);
73  } else if (segment_style() == segment_style::modern) {
74  for (int32_t offset = 0; offset < thickness(); offset++)
75  graphics.draw_line(drawing::pen(color), 2 + offset, 1 + offset, size().width() / 2 - 1 - abs(offset / 2), 1 + offset);
76  } else if (segment_style() == segment_style::mixed) {
77  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
78  graphics.draw_line(drawing::pen(color), 2 + offset + thickness() / 2, 1 + thickness() / 2 + offset, size().width() / 2 - 1 - abs(offset), 1 + thickness() / 2 + offset);
79  } else if (segment_style() == segment_style::expanded) {
80  for (int32_t offset = 0; offset < thickness(); offset++)
81  graphics.draw_line(drawing::pen(color), 2 + offset, 1 + offset, size().width() / 2 + thickness() / 2 - 1 - (offset > thickness() / 2 ? offset : thickness() / 2), 1 + offset);
82  } else if (segment_style() == segment_style::design) {
83  for (int32_t offset = 0; offset < thickness(); offset++)
84  graphics.draw_line(drawing::pen(color), 2 + thickness(), 1 + offset, size().width() / 2 + thickness() / 2 - 1 - (offset > thickness() / 2 ? offset : thickness() / 2), 1 + offset);
85  } else if (segment_style() == segment_style::stick) {
86  for (int32_t offset = 0; offset < thickness(); offset++)
87  graphics.draw_line(drawing::pen(color), 2 + thickness(), 1 + offset, size().width() / 2 - 1, 1 + offset);
88  }
89  }
90 
94  virtual void draw_segment_a2(drawing::graphics& graphics, const drawing::color& color) {
96  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
97  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);
98  } else if (segment_style() == segment_style::modern) {
99  for (int32_t offset = 0; offset < thickness(); offset++)
100  graphics.draw_line(drawing::pen(color), size().width() / 2 + 1 + abs(offset / 2), 1 + offset, size().width() - 3 - offset, 1 + offset);
101  } else if (segment_style() == segment_style::mixed) {
102  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
103  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);
104  } else if (segment_style() == segment_style::expanded) {
105  for (int32_t offset = 0; offset < thickness(); offset++)
106  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);
107  } else if (segment_style() == segment_style::design) {
108  for (int32_t offset = 0; offset < thickness(); offset++)
109  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);
110  } else if (segment_style() == segment_style::stick) {
111  for (int32_t offset = 0; offset < thickness(); offset++)
112  graphics.draw_line(drawing::pen(color), size().width() / 2 + 1, 1 + offset, size().width() - 3 - thickness(), 1 + offset);
113  }
114  }
115 
119  virtual void draw_segment_d1(drawing::graphics& graphics, const drawing::color& color) {
121  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
122  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);
123  } else if (segment_style() == segment_style::modern) {
124  for (int32_t offset = 0; offset < thickness(); offset++)
125  graphics.draw_line(drawing::pen(color), 2 + offset, size().height() - 2 - offset, size().width() / 2 - 1 - abs(offset / 2), size().height() - 2 - offset);
126  } else if (segment_style() == segment_style::mixed) {
127  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
128  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);
129  } else if (segment_style() == segment_style::expanded) {
130  for (int32_t offset = 0; offset < thickness(); offset++)
131  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);
132  } else if (segment_style() == segment_style::design) {
133  for (int32_t offset = 0; offset < thickness(); offset++)
134  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);
135  } else if (segment_style() == segment_style::stick) {
136  for (int32_t offset = 0; offset < thickness(); offset++)
137  graphics.draw_line(drawing::pen(color), 2 + thickness(), size().height() - 2 - offset, size().width() / 2 - 1, size().height() - 2 - offset);
138  }
139  }
140 
144  virtual void draw_segment_d2(drawing::graphics& graphics, const drawing::color& color) {
146  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
147  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);
148  } else if (segment_style() == segment_style::modern) {
149  for (int32_t offset = 0; offset < thickness(); offset++)
150  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);
151  } else if (segment_style() == segment_style::mixed) {
152  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
153  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);
154  } else if (segment_style() == segment_style::expanded) {
155  for (int32_t offset = 0; offset < thickness(); offset++)
156  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);
157  } else if (segment_style() == segment_style::design) {
158  for (int32_t offset = 0; offset < thickness(); offset++)
159  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);
160  } else if (segment_style() == segment_style::stick) {
161  for (int32_t offset = 0; offset < thickness(); offset++)
162  graphics.draw_line(drawing::pen(color), size().width() / 2 + 1, size().height() - 2 - offset, size().width() - 3 - thickness(), size().height() - 2 - offset);
163  }
164  }
165 
169  void draw_segment_i(drawing::graphics& graphics, const drawing::color& color) override {
171  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
172  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));
173  } else if (segment_style() == segment_style::modern) {
174  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
175  graphics.draw_line(drawing::pen(color), size().width() / 2 - offset, 2 + abs(2 * offset), size().width() / 2 - offset, size().height() / 2 - 1 - abs(offset));
176  } else if (segment_style() == segment_style::mixed) {
177  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
178  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));
179  } else if (segment_style() == segment_style::expanded) {
180  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
181  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));
182  } else if (segment_style() == segment_style::design) {
183  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
184  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));
185  } else if (segment_style() == segment_style::stick) {
186  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
187  graphics.draw_line(drawing::pen(color), size().width() / 2 - offset, 2 + thickness(), size().width() / 2 - offset, size().height() / 2 - 1 - abs(offset));
188  }
189  }
190 
194  void draw_segment_l(drawing::graphics& graphics, const drawing::color& color) override {
196  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
197  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));
198  } else if (segment_style() == segment_style::modern) {
199  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
200  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));
201  } else if (segment_style() == segment_style::mixed) {
202  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
203  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));
204  } else if (segment_style() == segment_style::expanded) {
205  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
206  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));
207  } else if (segment_style() == segment_style::design) {
208  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
209  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));
210  } else if (segment_style() == segment_style::stick) {
211  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
212  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());
213  }
214  }
216 
217  protected:
219 
221  void draw_segment_a(drawing::graphics& graphics, const drawing::color& color) override {}
222  void draw_segment_d(drawing::graphics& graphics, const drawing::color& color) override {}
224 
225  private:
226  std::optional<int32_t> thickness_;
227  };
228  }
229 }
void draw_segment_d(drawing::graphics &graphics, const drawing::color &color) override
Draw segment d on specified graphics with specified color.
Definition: sixteen_segment_display.h:222
Represents a sixteen segment display class.
Definition: sixteen_segment_display.h:18
virtual const drawing::size & size() const
Gets the height and width of the control.
void draw_segment_i(drawing::graphics &graphics, const drawing::color &color) override
Draw segment i on specified graphics with specified color.
Definition: sixteen_segment_display.h:169
virtual drawing::color back_color() const
Gets the background color for the control.
Represents a nine segment display class.
Definition: fourteen_segment_display.h:18
static color average(const color &color1, const color &color2, double weight, bool average_alpha)
Returns the weighted average color between the two given colors.
Definition: color.h:607
virtual forms::segment_style segment_style() const
Gets segment style.
Definition: seven_segment_display.h:88
virtual void draw_segment_a2(drawing::graphics &graphics, const drawing::color &color)
Draw segment a2 on specified graphics with specified color.
Definition: sixteen_segment_display.h:94
virtual void draw_segment_d1(drawing::graphics &graphics, const drawing::color &color)
Draw segment d1 on specified graphics with specified color.
Definition: sixteen_segment_display.h:119
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
virtual int32_t height() const
Gets the height of the control.
virtual void draw_segment_a1(drawing::graphics &graphics, const drawing::color &color)
Draw segment a1 on specified graphics with specified color.
Definition: sixteen_segment_display.h:69
drawing::graphics & graphics()
Gets the graphics used to paint.
virtual double back_segment_opacity() const
Gets the background segment opacity.
Definition: seven_segment_display.h:56
Contains xtd::forms::fourteen_segment_display control.
Represents an ARGB (alpha, red, green, blue) color.
Definition: color.h:39
int32_t thickness() const override
Sets thickness of segment.
Definition: sixteen_segment_display.h:33
Provides data for the paint event.
Definition: paint_event_args.h:27
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition: pen.h:29
virtual void invalidate() const
Invalidates the entire surface of the control and causes the control to be redrawn.
virtual forms::segments value() const
Gets seven_segment_display value.
Definition: seven_segment_display.h:116
virtual int32_t width() const
Gets the width of the control.
virtual drawing::color fore_color() const
Gets the foreground color of the control.
void on_paint(paint_event_args &e) override
Raises the control::paint event.
Definition: fourteen_segment_display.h:50
Design segment style.
The a1 segment.
Modern segment style.
Standard style dialog.
void draw_back_digit(drawing::graphics &graphics) override
Draw all background digit on specified graphics.
Definition: fourteen_segment_display.h:62
Expanded segment style.
virtual void draw_segment_d2(drawing::graphics &graphics, const drawing::color &color)
Draw segment d2 on specified graphics with specified color.
Definition: sixteen_segment_display.h:144
virtual drawing::color back_segment_color()
Gets background segment color.
Definition: seven_segment_display.h:41
void draw_back_digit(drawing::graphics &graphics) override
Draw all background digit on specified graphics.
Definition: sixteen_segment_display.h:58
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
void on_paint(paint_event_args &e) override
Raises the control::paint event.
Definition: sixteen_segment_display.h:50
seven_segment_display & thickness(int32_t value) override
Sets thickness of segment.
Definition: sixteen_segment_display.h:37
sixteen_segment_display()=default
Initialize a new instance of nine_segment_display class.
Represents a seven segment display class.
Definition: seven_segment_display.h:23
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition: graphics.h:48
Mixed (mix between standard and modern) segment style.
void draw_segment_l(drawing::graphics &graphics, const drawing::color &color) override
Draw segment l on specified graphics with specified color.
Definition: sixteen_segment_display.h:194
void draw_segment_a(drawing::graphics &graphics, const drawing::color &color) override
Draw segment a on specified graphics with specified color.
Definition: sixteen_segment_display.h:221
size_t size
Represents a size of any object in bytes.
Definition: types.h:171
The a2 segment.