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.
seven_segment_display.h
Go to the documentation of this file.
1 #pragma once
7 #include "application.h"
8 #include "control.h"
9 #include "segments.h"
10 #include "segment_style.h"
11 
12 namespace xtd {
13  namespace forms {
23  class seven_segment_display : public control {
24  public:
27  double_buffered(true);
28  size_ = default_size();
29  }
30 
34  virtual drawing::color back_segment_color() {return back_segment_color_.value_or(fore_color());}
40  if (!back_segment_color_.has_value() || back_segment_color_.value() != value) {
41  back_segment_color_ = value;
42  invalidate();
43  }
44  return *this;
45  }
46 
49  virtual double back_segment_opacity() const {return back_segment_opacity_;}
55  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_);
56  if (back_segment_opacity_ != value) {
57  back_segment_opacity_ = value;
58  invalidate();
59  }
60  return *this;
61  }
62 
65  virtual bool show_back_segment() const {return show_back_segment_;}
70  if (show_back_segment_ != value) {
71  show_back_segment_ = value;
72  invalidate();
73  }
74  return *this;
75  }
76 
79  virtual forms::segment_style segment_style() const {return segment_style_;}
84  if (segment_style_ != value) {
85  segment_style_ = value;
86  invalidate();
87  }
88  return *this;
89  }
90 
93  virtual int32_t thickness() const {return thickness_.value_or(size_.height() < 10 ? 1 : (size_.height() / 10 + ((size_.height() / 10) % 2 ? 0 : 1)));}
98  if (!thickness_.has_value() || thickness_.value() != value) {
99  thickness_ = value;
100  invalidate();
101  }
102  return *this;
103  }
104 
107  virtual forms::segments value() const {return value_;}
112  if (value_ != value) {
113  value_ = value;
114  invalidate();
115  }
116  return *this;
117  }
118 
121  virtual bool get_segments(forms::segments segment) const {return (value_ & segment) == segment;}
125  virtual void set_segments(forms::segments segment, bool value) { value_ = value ? (value_ | segment) : (value_ & ~segment); }
126 
127  protected:
128  drawing::size default_size() const override {return {13, 25};}
129 
130  void on_back_color_changed(const event_args& e) override {
132  invalidate();
133  }
134 
135  void on_enabled_changed(const event_args& e) override {
137  invalidate();
138  }
139 
140  void on_fore_color_changed(const event_args& e) override {
142  invalidate();
143  }
144 
145  void on_paint(paint_event_args& e) override {
148  if (show_back_segment_) draw_back_digit(e.graphics());
149  auto color = enabled() ? fore_color() : application::theme().theme_colors().gray_text();
150  if ((value_ & forms::segments::dp) == forms::segments::dp) draw_dp(e.graphics(), color);
151  if ((value_ & forms::segments::pc) == forms::segments::pc) draw_pc(e.graphics(), color);
152  if ((value_ & forms::segments::a) == forms::segments::a) draw_segment_a(e.graphics(), color);
153  if ((value_ & forms::segments::b) == forms::segments::b) draw_segment_b(e.graphics(), color);
154  if ((value_ & forms::segments::c) == forms::segments::c) draw_segment_c(e.graphics(), color);
155  if ((value_ & forms::segments::d) == forms::segments::d) draw_segment_d(e.graphics(), color);
156  if ((value_ & forms::segments::e) == forms::segments::e) draw_segment_e(e.graphics(), color);
157  if ((value_ & forms::segments::f) == forms::segments::f) draw_segment_f(e.graphics(), color);
158  if ((value_ & forms::segments::g) == forms::segments::g) draw_segment_g(e.graphics(), color);
159  }
160 
161  void on_parent_enabled_changed(const event_args& e) override {
163  invalidate();
164  }
165 
166  drawing::size measure_control() const override {
167  return drawing::size((height() - 3) / 2 + 2, height());
168  }
169 
170  void set_bounds_core(int32_t x, int32_t y, int32_t width, int32_t height, bounds_specified specified) override {
172  height = (width - 2) * 2 + 3;
173  specified |= bounds_specified::height;
174  }
175  if ((specified & bounds_specified::height) == forms::bounds_specified::height) {
176  width = (height - 3) / 2 + 2;
177  specified |= bounds_specified::width;
178  }
179  control::set_bounds_core(x, y, width, height, specified);
180  }
181 
182  void set_client_size_core(int32_t width, int32_t height) override {
183  if (client_size_.height() != height)
184  width = (height - 3) / 2 + 2;
185  if (client_size_.width() != width)
186  height = (width - 2) * 2 + 3;
187  control::set_client_size_core(width, height);
188  }
189 
192  virtual void draw_back_digit(drawing::graphics& graphics) {
194  draw_segment_a(graphics, color);
195  draw_segment_b(graphics, color);
196  draw_segment_c(graphics, color);
197  draw_segment_d(graphics, color);
198  draw_segment_e(graphics, color);
199  draw_segment_f(graphics, color);
200  draw_segment_g(graphics, color);
201  }
202 
206  virtual void draw_segment_a(drawing::graphics& graphics, const drawing::color& color) {
207  if (segment_style_ == segment_style::standard) {
208  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
209  graphics.draw_line(drawing::pen(color), 2 + thickness() / 2 + abs(offset), 1 + thickness() / 2 + offset, size_.width() - 3 - thickness() / 2 - abs(offset), 1 + thickness() / 2 + offset);
210  } else if (segment_style_ == segment_style::modern) {
211  for (int32_t offset = 0; offset < thickness(); offset++)
212  graphics.draw_line(drawing::pen(color), 2 + offset, 1 + offset, size_.width() - 3 - offset, 1 + offset);
213  } else if (segment_style_ == segment_style::mixed) {
214  for (int32_t offset = 0; offset < thickness(); offset++)
215  graphics.draw_line(drawing::pen(color), 2 + offset, 1 + offset, size_.width() - 3 - offset, 1 + offset);
216  } else if (segment_style_ == segment_style::expanded) {
217  for (int32_t offset = 0; offset < thickness(); offset++)
218  graphics.draw_line(drawing::pen(color), 2 + offset, 1 + offset, size_.width() - 3 - offset, 1 + offset);
219  } else if (segment_style_ == segment_style::design) {
220  for (int32_t offset = 0; offset < thickness(); offset++)
221  graphics.draw_line(drawing::pen(color), 2 + thickness(), 1 + offset, size_.width() - 3 - thickness(), 1 + offset);
222  } else if (segment_style_ == segment_style::stick) {
223  for (int32_t offset = 0; offset < thickness(); offset++)
224  graphics.draw_line(drawing::pen(color), 2 + thickness(), 1 + offset, size_.width() - 3 - thickness(), 1 + offset);
225  }
226  }
227 
231  virtual void draw_segment_b(drawing::graphics& graphics, const drawing::color& color) {
232  if (segment_style_ == segment_style::standard) {
233  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
234  graphics.draw_line(drawing::pen(color), size_.width() - 2 - thickness() / 2 - offset, 2 + thickness() / 2 + abs(offset), size_.width() - 2 - thickness() / 2 - offset, size_.height() / 2 - 1 - abs(offset));
235  } else if (segment_style_ == segment_style::modern) {
236  for (int32_t offset = 0; offset < thickness(); offset++)
237  graphics.draw_line(drawing::pen(color), size_.width() - 2 - offset, 2 + offset, size_.width() - 2 - offset, size_.height() / 2 - 1 - offset / 2);
238  } else if (segment_style_ == segment_style::mixed) {
239  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
240  graphics.draw_line(drawing::pen(color), size_.width() - 2 - thickness() / 2 - offset, 2 + offset + thickness() / 2, size_.width() - 2 - thickness() / 2 - offset, size_.height() / 2 - 1 - abs(offset));
241  } else if (segment_style_ == segment_style::expanded) {
242  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
243  graphics.draw_line(drawing::pen(color), size_.width() - 2 - thickness() / 2 - offset, 2 + offset + thickness() / 2, size_.width() - 2 - thickness() / 2 - offset, size_.height() / 2 - 1 - (offset > 0 ? offset : 0));
244  } else if (segment_style_ == segment_style::design) {
245  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
246  graphics.draw_line(drawing::pen(color), size_.width() - 2 - thickness() / 2 - offset, 1, size_.width() - 2 - thickness() / 2 - offset, size_.height() / 2 - 1 - (offset > 0 ? offset : 0));
247  } else if (segment_style_ == segment_style::stick) {
248  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
249  graphics.draw_line(drawing::pen(color), size_.width() - 2 - thickness() / 2 - offset, 1, size_.width() - 2 - thickness() / 2 - offset, size_.height() / 2 - 1);
250  }
251  }
252 
256  virtual void draw_segment_c(drawing::graphics& graphics, const drawing::color& color) {
257  if (segment_style_ == segment_style::standard) {
258  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
259  graphics.draw_line(drawing::pen(color), size_.width() - 2 - thickness() / 2 - offset, size_.height() / 2 + 1 - thickness() / 2 + thickness() / 2 + abs(offset), size_.width() - 2 - thickness() / 2 - offset, size_.height() - 3 - thickness() / 2 - abs(offset));
260  } else if (segment_style_ == segment_style::modern) {
261  for (int32_t offset = 0; offset < thickness(); offset++)
262  graphics.draw_line(drawing::pen(color), size_.width() - 2 - offset, size_.height() / 2 + 1 + offset / 2, size_.width() - 2 - offset, size_.height() - 3 - offset);
263  } else if (segment_style_ == segment_style::mixed) {
264  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
265  graphics.draw_line(drawing::pen(color), size_.width() - 2 - thickness() / 2 - offset, size_.height() / 2 + 1 - thickness() / 2 + thickness() / 2 + abs(offset), size_.width() - 2 - thickness() / 2 - offset, size_.height() - 3 - thickness() / 2 - offset);
266  } else if (segment_style_ == segment_style::expanded) {
267  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
268  graphics.draw_line(drawing::pen(color), size_.width() - 2 - thickness() / 2 - offset, size_.height() / 2 + 1 - thickness() / 2 + thickness() / 2 + (offset > 0 ? offset : 0), size_.width() - 2 - thickness() / 2 - offset, size_.height() - 3 - thickness() / 2 - offset);
269  } else if (segment_style_ == segment_style::design) {
270  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
271  graphics.draw_line(drawing::pen(color), size_.width() - 2 - thickness() / 2 - offset, size_.height() / 2 + 1 - thickness() / 2 + thickness() / 2 + (offset > 0 ? offset : 0), size_.width() - 2 - thickness() / 2 - offset, size_.height() - 2);
272  } else if (segment_style_ == segment_style::stick) {
273  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
274  graphics.draw_line(drawing::pen(color), size_.width() - 2 - thickness() / 2 - offset, size_.height() / 2 + 1, size_.width() - 2 - thickness() / 2 - offset, size_.height() - 2);
275  }
276  }
277 
281  virtual void draw_segment_d(drawing::graphics& graphics, const drawing::color& color) {
282  if (segment_style_ == segment_style::standard) {
283  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
284  graphics.draw_line(drawing::pen(color), 2 + thickness() / 2 + abs(offset), size_.height() - 2 - thickness() / 2 - offset, size_.width() - 3 - thickness() / 2 - abs(offset), size_.height() - 2 - thickness() / 2 - offset);
285  } else if (segment_style_ == segment_style::modern) {
286  for (int32_t offset = 0; offset < thickness(); offset++)
287  graphics.draw_line(drawing::pen(color), 2 + offset, size_.height() - 2 - offset, size_.width() - 3 - offset, size_.height() - 2 - offset);
288  } else if (segment_style_ == segment_style::mixed) {
289  for (int32_t offset = 0; offset < thickness(); offset++)
290  graphics.draw_line(drawing::pen(color), 2 + offset, size_.height() - 2 - offset, size_.width() - 3 - offset, size_.height() - 2 - offset);
291  } else if (segment_style_ == segment_style::expanded) {
292  for (int32_t offset = 0; offset < thickness(); offset++)
293  graphics.draw_line(drawing::pen(color), 2 + offset, size_.height() - 2 - offset, size_.width() - 3 - offset, size_.height() - 2 - offset);
294  } else if (segment_style_ == segment_style::design) {
295  for (int32_t offset = 0; offset < thickness(); offset++)
296  graphics.draw_line(drawing::pen(color), 2 + thickness(), size_.height() - 2 - offset, size_.width() - 3 - thickness(), size_.height() - 2 - offset);
297  } else if (segment_style_ == segment_style::stick) {
298  for (int32_t offset = 0; offset < thickness(); offset++)
299  graphics.draw_line(drawing::pen(color), 2 + thickness(), size_.height() - 2 - offset, size_.width() - 3 - thickness(), size_.height() - 2 - offset);
300  }
301  }
302 
306  virtual void draw_segment_e(drawing::graphics& graphics, const drawing::color& color) {
307  if (segment_style_ == segment_style::standard) {
308  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
309  graphics.draw_line(drawing::pen(color), 1 + thickness() / 2 + offset, size_.height() / 2 + 1 - thickness() / 2 + thickness() / 2 + abs(offset), 1 + thickness() / 2 + offset, size_.height() - 3 - thickness() / 2 - abs(offset));
310  } else if (segment_style_ == segment_style::modern) {
311  for (int32_t offset = 0; offset < thickness(); offset++)
312  graphics.draw_line(drawing::pen(color), 1 + offset, size_.height() / 2 + 1 + offset / 2, 1 + offset, size_.height() - 3 - offset);
313  } else if (segment_style_ == segment_style::mixed) {
314  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
315  graphics.draw_line(drawing::pen(color), 1 + thickness() / 2 + offset, size_.height() / 2 + 1 - thickness() / 2 + thickness() / 2 + abs(offset), 1 + thickness() / 2 + offset, size_.height() - 3 - thickness() / 2 - offset);
316  } else if (segment_style_ == segment_style::expanded) {
317  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
318  graphics.draw_line(drawing::pen(color), 1 + thickness() / 2 + offset, size_.height() / 2 + 1 - thickness() / 2 + thickness() / 2 + (offset > 0 ? offset : 0), 1 + thickness() / 2 + offset, size_.height() - 3 - thickness() / 2 - offset);
319  } else if (segment_style_ == segment_style::design) {
320  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
321  graphics.draw_line(drawing::pen(color), 1 + thickness() / 2 + offset, size_.height() / 2 + 1 - thickness() / 2 + thickness() / 2 + (offset > 0 ? offset : 0), 1 + thickness() / 2 + offset, size_.height() - 2);
322  } else if (segment_style_ == segment_style::stick) {
323  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
324  graphics.draw_line(drawing::pen(color), 1 + thickness() / 2 + offset, size_.height() / 2 + 1, 1 + thickness() / 2 + offset, size_.height() - 2);
325  }
326  }
327 
331  virtual void draw_segment_f(drawing::graphics& graphics, const drawing::color& color) {
332  if (segment_style_ == segment_style::standard) {
333  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
334  graphics.draw_line(drawing::pen(color), 1 + thickness() / 2 + offset, 2 + thickness() / 2 + abs(offset), 1 + thickness() / 2 + offset, size_.height() / 2 - 1 - abs(offset));
335  } else if (segment_style_ == segment_style::modern) {
336  for (int32_t offset = 0; offset < thickness(); offset++)
337  graphics.draw_line(drawing::pen(color), 1 + offset, 2 + offset, 1 + offset, size_.height() / 2 - 1 - offset / 2);
338  } else if (segment_style_ == segment_style::mixed) {
339  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
340  graphics.draw_line(drawing::pen(color), 1 + thickness() / 2 + offset, 2 + thickness() / 2 + offset, 1 + thickness() / 2 + offset, size_.height() / 2 - 1 - abs(offset));
341  } else if (segment_style_ == segment_style::expanded) {
342  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
343  graphics.draw_line(drawing::pen(color), 1 + thickness() / 2 + offset, 2 + thickness() / 2 + offset, 1 + thickness() / 2 + offset, size_.height() / 2 - 1 - (offset > 0 ? offset : 0));
344  } else if (segment_style_ == segment_style::design) {
345  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
346  graphics.draw_line(drawing::pen(color), 1 + thickness() / 2 + offset, 1, 1 + thickness() / 2 + offset, size_.height() / 2 - 1 - (offset > 0 ? offset : 0));
347  } else if (segment_style_ == segment_style::stick) {
348  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
349  graphics.draw_line(drawing::pen(color), 1 + thickness() / 2 + offset, 1, 1 + thickness() / 2 + offset, size_.height() / 2 - 1);
350  }
351  }
352 
356  virtual void draw_segment_g(drawing::graphics& graphics, const drawing::color& color) {
357  if (segment_style_ == segment_style::standard) {
358  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
359  graphics.draw_line(drawing::pen(color), 2 + thickness() / 2 + abs(offset), size_.height() / 2 + offset, size_.width() - 3 - thickness() / 2 - abs(offset), size_.height() / 2 + offset);
360  } else if (segment_style_ == segment_style::modern) {
361  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
362  graphics.draw_line(drawing::pen(color), 2 + abs(2 * offset), size_.height() / 2 + offset, size_.width() - 3 - abs(2 * offset), size_.height() / 2 + offset);
363  } else if (segment_style_ == segment_style::mixed) {
364  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
365  graphics.draw_line(drawing::pen(color), 2 + thickness() / 2 + abs(offset), size_.height() / 2 + offset, size_.width() - 3 - thickness() / 2 - abs(offset), size_.height() / 2 + offset);
366  } else if (segment_style_ == segment_style::expanded) {
367  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
368  graphics.draw_line(drawing::pen(color), 2 + thickness() / 2 + abs(offset), size_.height() / 2 + offset, size_.width() - 3 - thickness() / 2 - abs(offset), size_.height() / 2 + offset);
369  } else if (segment_style_ == segment_style::design) {
370  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
371  graphics.draw_line(drawing::pen(color), 2 + thickness() / 2 + abs(offset), size_.height() / 2 + offset, size_.width() - 3 - thickness() / 2 - abs(offset), size_.height() / 2 + offset);
372  } else if (segment_style_ == segment_style::stick) {
373  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
374  graphics.draw_line(drawing::pen(color), 2 + thickness(), size_.height() / 2 + offset, size_.width() - 3 - thickness(), size_.height() / 2 + offset);
375  }
376  }
377 
381  virtual void draw_dp(drawing::graphics& graphics, const drawing::color& color) {
382  if (segment_style_ == segment_style::standard) {
383  graphics.fill_ellipse(drawing::solid_brush(color), size_.width() / 2 - thickness() / 2, size_.height() - 1 - thickness(), thickness(), thickness());
384  } else if (segment_style_ == segment_style::modern) {
385  for (int32_t offset = 0; offset < thickness(); offset++)
386  graphics.draw_line(drawing::pen(color), size_.width() / 2 - thickness() / 2, size_.height() - 2 - offset, size_.width() / 2 + thickness() / 2, size_.height() - 2 - offset);
387  } else if (segment_style_ == segment_style::mixed) {
388  graphics.fill_ellipse(drawing::solid_brush(color), size_.width() / 2 - thickness() / 2, size_.height() - 1 - thickness(), thickness(), thickness());
389  } else if (segment_style_ == segment_style::expanded) {
390  graphics.fill_ellipse(drawing::solid_brush(color), size_.width() / 2 - thickness() / 2, size_.height() - 1 - thickness(), thickness(), thickness());
391  } else if (segment_style_ == segment_style::design) {
392  graphics.fill_ellipse(drawing::solid_brush(color), size_.width() / 2 - thickness() / 2, size_.height() - 1 - thickness(), thickness(), thickness());
393  } else if (segment_style_ == segment_style::stick) {
394  for (int32_t offset = 0; offset < thickness(); offset++)
395  graphics.draw_line(drawing::pen(color), size_.width() / 2 - thickness() / 2, size_.height() - 2 - offset, size_.width() / 2 + thickness() / 2, size_.height() - 2 - offset);
396  }
397  }
398 
402  virtual void draw_pc(drawing::graphics& graphics, const drawing::color& color) {
403  if (segment_style_ == segment_style::standard) {
404  graphics.fill_ellipse(drawing::solid_brush(color), size_.width() / 2 - thickness() / 2, size_.height() / 3 - thickness() / 2, thickness(), thickness());
405  graphics.fill_ellipse(drawing::solid_brush(color), size_.width() / 2 - thickness() / 2, size_.height() / 3 * 2 - thickness() / 2, thickness(), thickness());
406  } else if (segment_style_ == segment_style::modern) {
407  for (int32_t offset = 0; offset < thickness(); offset++) {
408  graphics.draw_line(drawing::pen(color), size_.width() / 2 - thickness() / 2, size_.height() / 3 - thickness() / 2 + offset, size_.width() / 2 + thickness() / 2, size_.height() / 3 - thickness() / 2 + offset);
409  graphics.draw_line(drawing::pen(color), size_.width() / 2 - thickness() / 2, size_.height() /3 * 2 - thickness() / 2 + offset, size_.width() / 2 + thickness() / 2, size_.height() / 3 * 2 - thickness() / 2 + offset);
410  }
411  } else if (segment_style_ == segment_style::mixed) {
412  graphics.fill_ellipse(drawing::solid_brush(color), size_.width() / 2 - thickness() / 2, size_.height() / 3 - thickness() / 2, thickness(), thickness());
413  graphics.fill_ellipse(drawing::solid_brush(color), size_.width() / 2 - thickness() / 2, size_.height() / 3 * 2 - thickness() / 2, thickness(), thickness());
414  } else if (segment_style_ == segment_style::expanded) {
415  graphics.fill_ellipse(drawing::solid_brush(color), size_.width() / 2 - thickness() / 2, size_.height() / 3 - thickness() / 2, thickness(), thickness());
416  graphics.fill_ellipse(drawing::solid_brush(color), size_.width() / 2 - thickness() / 2, size_.height() / 3 * 2 - thickness() / 2, thickness(), thickness());
417  } else if (segment_style_ == segment_style::design) {
418  graphics.fill_ellipse(drawing::solid_brush(color), size_.width() / 2 - thickness() / 2, size_.height() / 3 - thickness() / 2, thickness(), thickness());
419  graphics.fill_ellipse(drawing::solid_brush(color), size_.width() / 2 - thickness() / 2, size_.height() / 3 * 2 - thickness() / 2, thickness(), thickness());
420  } else if (segment_style_ == segment_style::stick) {
421  for (int32_t offset = 0; offset < thickness(); offset++) {
422  graphics.draw_line(drawing::pen(color), size_.width() / 2 - thickness() / 2, size_.height() / 3 - thickness() / 2 + offset, size_.width() / 2 + thickness() / 2, size_.height() / 3 - thickness() / 2 + offset);
423  graphics.draw_line(drawing::pen(color), size_.width() / 2 - thickness() / 2, size_.height() /3 * 2 - thickness() / 2 + offset, size_.width() / 2 + thickness() / 2, size_.height() / 3 * 2 - thickness() / 2 + offset);
424  }
425  }
426  }
427 
430  bool show_back_segment_ = true;
431  std::optional<drawing::color> back_segment_color_;
432  double back_segment_opacity_ = 0.95;
434  std::optional<int32_t> thickness_;
436  };
437  }
438 }
Contains xtd::argument_out_of_range_exception exception.
virtual bool enabled() const
Gets a value indicating whether the control can respond to user interaction.
Definition: control.h:472
void on_paint(paint_event_args &e) override
Raises the control::paint event.
Definition: seven_segment_display.h:145
virtual void draw_segment_a(drawing::graphics &graphics, const drawing::color &color)
Draw segment a on specified graphics with specified color.
Definition: seven_segment_display.h:206
void on_parent_enabled_changed(const event_args &e) override
Raises the xtd::control::enabled_changed event when the xtd::control::enabled property value of the c...
Definition: seven_segment_display.h:161
virtual drawing::color back_color() const
Gets the background color for the control.
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:592
Contains xtd::forms::application class.
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
segment_style
Represent segment style used by seven_segment_display, fourteen_segment_display, nine_segment_display...
Definition: segment_style.h:17
virtual void draw_pc(drawing::graphics &graphics, const drawing::color &color)
Draw segment punctuation colon on specified graphics with specified color.
Definition: seven_segment_display.h:402
virtual void draw_segment_f(drawing::graphics &graphics, const drawing::color &color)
Draw segment f on specified graphics with specified color.
Definition: seven_segment_display.h:331
virtual void set_segments(forms::segments segment, bool value)
Sets specified xtd::forms::segments combination to on.
Definition: seven_segment_display.h:125
virtual forms::segment_style segment_style() const
Gets segment style.
Definition: seven_segment_display.h:79
virtual void on_paint(paint_event_args &e)
Raises the control::paint event.
virtual seven_segment_display & back_segment_color(const drawing::color &value)
Sets background segment color.
Definition: seven_segment_display.h:39
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:25
Specifies that the top edge of the control is defined.
void on_back_color_changed(const event_args &e) override
Raises the control::back_color_changed event.
Definition: seven_segment_display.h:130
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.
Definition: control.h:510
virtual seven_segment_display & value(forms::segments value)
Sets seven_segment_display value.
Definition: seven_segment_display.h:111
Contains xtd::forms::segments enum class.
virtual seven_segment_display & show_back_segment(bool value)
Sets a value indicate if background segments are shown.
Definition: seven_segment_display.h:69
virtual seven_segment_display & segment_style(forms::segment_style value)
Sets segment style.
Definition: seven_segment_display.h:83
void on_fore_color_changed(const event_args &e) override
Raises the control::fore_color_changed event.
Definition: seven_segment_display.h:140
Specifies that the left edge of the control is defined.
void set_bounds_core(int32_t x, int32_t y, int32_t width, int32_t height, bounds_specified specified) override
Performs the work of setting the specified bounds of this control.
Definition: seven_segment_display.h:170
#define current_stack_frame_
Provides information about the current stack frame.
Definition: stack_frame.h:201
segments
Specifies how a control anchors to the edges of its container.
Definition: segments.h:19
virtual int32_t thickness() const
Gets thickness of segment.
Definition: seven_segment_display.h:93
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:49
virtual void set_client_size_core(int32_t width, int32_t height)
Sets the size of the client area of the control.
virtual void on_parent_enabled_changed(const event_args &e)
Raises the xtd::control::enabled_changed event when the xtd::control::enabled property value of the c...
virtual drawing::color default_back_color() const
Gets the default background color of the control.
Definition: control.h:417
virtual void on_fore_color_changed(const event_args &e)
Raises the control::fore_color_changed event.
virtual void draw_segment_c(drawing::graphics &graphics, const drawing::color &color)
Draw segment c on specified graphics with specified color.
Definition: seven_segment_display.h:256
Specifies that the height of the control is defined.
Represents an ARGB (alpha, red, green, blue) color.
Definition: color.h:39
Defines a xtd::drawing::brush of a single color. Brushes are used to fill graphics shapes...
Definition: solid_brush.h:22
Provides data for the paint event.
Definition: paint_event_args.h:26
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.
Definition: control.h:911
Specifies that both the width and height property values of the control are defined.
virtual seven_segment_display & thickness(int32_t value)
Sets thickness of segment.
Definition: seven_segment_display.h:97
virtual forms::segments value() const
Gets seven_segment_display value.
Definition: seven_segment_display.h:107
virtual void draw_segment_e(drawing::graphics &graphics, const drawing::color &color)
Draw segment e on specified graphics with specified color.
Definition: seven_segment_display.h:306
virtual bool get_segments(forms::segments segment) const
Gets if specified xtd::forms::segments combination is on.
Definition: seven_segment_display.h:121
virtual int32_t width() const
Gets the width of the control.
Definition: control.h:710
virtual void draw_back_digit(drawing::graphics &graphics)
Draw all background digit on specified graphics.
Definition: seven_segment_display.h:192
virtual drawing::color fore_color() const
Gets the foreground color of the control.
Design segment style.
void on_enabled_changed(const event_args &e) override
Raises the control::enabled_changed event.
Definition: seven_segment_display.h:135
void clear(const color &color)
Clears the entire drawing surface and fills it with the specified background color.
Specifies that the width of the control is defined.
void set_client_size_core(int32_t width, int32_t height) override
Sets the size of the client area of the control.
Definition: seven_segment_display.h:182
Modern segment style.
Standard style dialog.
virtual void on_enabled_changed(const event_args &e)
Raises the control::enabled_changed event.
The dp segment (dot point).
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
drawing::size measure_control() const override
Measure this control.
Definition: seven_segment_display.h:166
drawing::size default_size() const override
Gets the default size of the control.
Definition: seven_segment_display.h:128
Defines the base class for controls, which are components with visual representation.
Definition: control.h:68
Contains xtd::forms::segment_style enum class.
virtual void draw_segment_g(drawing::graphics &graphics, const drawing::color &color)
Draw segment g on specified graphics with specified color.
Definition: seven_segment_display.h:356
virtual bool show_back_segment() const
Gets a value indicate if background segments are shown.
Definition: seven_segment_display.h:65
virtual void draw_dp(drawing::graphics &graphics, const drawing::color &color)
Draw segment dot point on specified graphics with specified color.
Definition: seven_segment_display.h:381
Expanded segment style.
virtual seven_segment_display & back_segment_opacity(double value)
Sets the background segment opacity.
Definition: seven_segment_display.h:54
Contains xtd::forms::control control.
virtual drawing::color back_segment_color()
Gets background segment color.
Definition: seven_segment_display.h:34
Contains xtd::drawing::system_colors factory.
virtual bool double_buffered() const
Gets a value indicating whether this control should redraw its surface using a secondary buffer to re...
Definition: control.h:461
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
virtual void on_back_color_changed(const event_args &e)
Raises the control::back_color_changed event.
bounds_specified
Specifies the bounds of the control to use when defining a control&#39;s size and position. This enumeration has a flags attribute that allows a bitwise combination of its member values.
Definition: bounds_specified.h:18
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
virtual void set_bounds_core(int32_t x, int32_t y, int32_t width, int32_t height, bounds_specified specified)
Performs the work of setting the specified bounds of this control.
seven_segment_display()
Initialize a new instance of seven_segment_display class.
Definition: seven_segment_display.h:26
Mixed (mix between standard and modern) segment style.
virtual void draw_segment_b(drawing::graphics &graphics, const drawing::color &color)
Draw segment b on specified graphics with specified color.
Definition: seven_segment_display.h:231
The cp segment (punctuation colon).
virtual void draw_segment_d(drawing::graphics &graphics, const drawing::color &color)
Draw segment d on specified graphics with specified color.
Definition: seven_segment_display.h:281