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.
fourteen_segment_display.h
Go to the documentation of this file.
1 #pragma once
6 
7 namespace xtd {
8  namespace forms {
19  public:
22 
27  int32_t thickness() const override {return thickness_.value_or(size_.height() < 20 ? 1 : (size_.height() / 20 + ((size_.height() / 20) % 2 ? 0 : 1)));}
28 
29  protected:
30  void on_paint(paint_event_args& e) override {
32  if ((value_ & forms::segments::g1) == forms::segments::g1) draw_segment_g1(e.graphics(), fore_color());
33  if ((value_ & forms::segments::g2) == forms::segments::g2) draw_segment_g2(e.graphics(), fore_color());
34  if ((value_ & forms::segments::h) == forms::segments::h) draw_segment_h(e.graphics(), fore_color());
35  if ((value_ & forms::segments::i) == forms::segments::i) draw_segment_i(e.graphics(), fore_color());
36  if ((value_ & forms::segments::j) == forms::segments::j) draw_segment_j(e.graphics(), fore_color());
37  if ((value_ & forms::segments::k) == forms::segments::k) draw_segment_k(e.graphics(), fore_color());
38  if ((value_ & forms::segments::l) == forms::segments::l) draw_segment_l(e.graphics(), fore_color());
39  if ((value_ & forms::segments::m) == forms::segments::m) draw_segment_m(e.graphics(), fore_color());
40  }
41 
42  void draw_back_digit(drawing::graphics& graphics) override {
52  }
53 
57  virtual void draw_segment_g1(drawing::graphics& graphics, const drawing::color& color) {
58  if (segment_style_ == segment_style::standard) {
59  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
60  graphics.draw_line(drawing::pen(color), 2 + thickness() / 2 + abs(offset), size_.height() / 2 + offset, size_.width() / 2 - 1 - abs(offset), size_.height() / 2 + offset);
61  } else if (segment_style_ == segment_style::modern) {
62  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
63  graphics.draw_line(drawing::pen(color), 2 + abs(2 * offset), size_.height() / 2 + offset, size_.width() / 2 - 1 - abs(offset), size_.height() / 2 + offset);
64  } else if (segment_style_ == segment_style::mixed) {
65  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
66  graphics.draw_line(drawing::pen(color), 2 + thickness() / 2 + abs(offset), size_.height() / 2 + offset, size_.width() / 2 - 1 - abs(offset), size_.height() / 2 + offset);
67  } else if (segment_style_ == segment_style::expanded) {
68  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
69  graphics.draw_line(drawing::pen(color), 2 + thickness() / 2 + abs(offset), size_.height() / 2 + offset, size_.width() /2 - 1 - abs(offset), size_.height() / 2 + offset);
70  } else if (segment_style_ == segment_style::design) {
71  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
72  graphics.draw_line(drawing::pen(color), 2 + thickness() / 2 + abs(offset), size_.height() / 2 + offset, size_.width() /2 - 1 - abs(offset), size_.height() / 2 + offset);
73  } else if (segment_style_ == segment_style::stick) {
74  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
75  graphics.draw_line(drawing::pen(color), 2 + thickness(), size_.height() / 2 + offset, size_.width() / 2 - 1 - abs(offset), size_.height() / 2 + offset);
76  }
77  }
78 
82  virtual void draw_segment_g2(drawing::graphics& graphics, const drawing::color& color) {
83  if (segment_style_ == segment_style::standard) {
84  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
85  graphics.draw_line(drawing::pen(color), size_.width() / 2 + 1 + abs(offset), size_.height() / 2 + offset, size_.width() - 3 - thickness() / 2 - abs(offset), size_.height() / 2 + offset);
86  } else if (segment_style_ == segment_style::modern) {
87  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
88  graphics.draw_line(drawing::pen(color), size_.width() / 2 + 1 + abs(offset), size_.height() / 2 + offset, size_.width() - 3 - abs(2 * offset), size_.height() / 2 + offset);
89  } else if (segment_style_ == segment_style::mixed) {
90  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
91  graphics.draw_line(drawing::pen(color), size_.width() / 2 + 1 + abs(offset), size_.height() / 2 + offset, size_.width() - 3 - thickness() / 2 - abs(offset), size_.height() / 2 + offset);
92  } else if (segment_style_ == segment_style::expanded) {
93  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
94  graphics.draw_line(drawing::pen(color), size_.width() / 2 + 1 + abs(offset), size_.height() / 2 + offset, size_.width() - 3 - thickness() / 2 - abs(offset), size_.height() / 2 + offset);
95  } else if (segment_style_ == segment_style::design) {
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), size_.height() / 2 + offset, size_.width() - 3 - thickness() / 2 - abs(offset), size_.height() / 2 + offset);
98  } else if (segment_style_ == segment_style::stick) {
99  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
100  graphics.draw_line(drawing::pen(color), size_.width() / 2 + 1 + abs(offset), size_.height() / 2 + offset, size_.width() - 3 - thickness(), size_.height() / 2 + offset);
101  }
102  }
103 
107  virtual void draw_segment_h(drawing::graphics& graphics, const drawing::color& color) {
108  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++) {
109  graphics.draw_line(drawing::pen(color), 2 + thickness() + abs(offset), 2 + thickness(), size_.width() / 2 - thickness() / 2 - 2, size_.height() / 2 - 2 - thickness() / 2 - abs(offset));
110  graphics.draw_line(drawing::pen(color), 2 + thickness(), 2 + thickness() + abs(offset), size_.width() / 2 - 2 - thickness() / 2 - abs(offset), size_.height() / 2 - 2 - thickness() / 2);
111  }
112  }
113 
117  virtual void draw_segment_i(drawing::graphics& graphics, const drawing::color& color) {
118  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
119  graphics.draw_line(drawing::pen(color), size_.width() / 2 - offset, 2 + thickness(), size_.width() / 2 - offset, size_.height() / 2 - 1 - abs(offset));
120  }
121 
125  virtual void draw_segment_j(drawing::graphics& graphics, const drawing::color& color) {
126  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++) {
127  graphics.draw_line(drawing::pen(color), size_.width() - 3 - thickness() - abs(offset), 2 + thickness(), size_.width() /2 + 2 + thickness() / 2, size_.height() / 2 - 2 - thickness() / 2 - abs(offset));
128  graphics.draw_line(drawing::pen(color), size_.width() - 3 - thickness(), 2 + thickness() + abs(offset), size_.width() /2 + 2 + thickness() / 2 + abs(offset), size_.height() / 2 - 2 - thickness() / 2);
129  }
130  }
131 
135  virtual void draw_segment_k(drawing::graphics& graphics, const drawing::color& color) {
136  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++) {
137  graphics.draw_line(drawing::pen(color), size_.width() / 2 - 2 - thickness() / 2 - abs(offset), size_.height() / 2 + 2 + thickness() / 2, 2 + thickness(), size_.height() - 3 - thickness() - abs(offset));
138  graphics.draw_line(drawing::pen(color), size_.width() / 2 - 2 - thickness() / 2, size_.height() / 2 + 2 + thickness() / 2 + abs(offset), 2 + thickness() + abs(offset), size_.height() - 3 - thickness());
139  }
140  }
141 
145  virtual void draw_segment_l(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 - offset, size_.height() / 2 + 1 - thickness() / 2 + thickness() / 2 + abs(offset), size_.width() / 2 - offset, size_.height() - 3 - thickness());
148  }
149 
153  virtual void draw_segment_m(drawing::graphics& graphics, const drawing::color& color) {
154  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++) {
155  graphics.draw_line(drawing::pen(color), size_.width() /2 + 2 + thickness() / 2 + abs(offset), size_.height() / 2 + 2 + thickness() / 2, size_.width() - 3 - thickness(), size_.height() - 3 - thickness() - abs(offset));
156  graphics.draw_line(drawing::pen(color), size_.width() /2 + 2 + thickness() / 2, size_.height() / 2 + 2 + thickness() / 2 + abs(offset), size_.width() - 3 - thickness() - abs(offset), size_.height() - 3 - thickness());
157  }
158  }
159 
160  protected:
161  void draw_segment_g(drawing::graphics& graphics, const drawing::color& color) override {}
162  };
163  }
164 }
Represents an ARGB (alpha, red, green, blue) color.
Definition: color.h:39
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
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition: graphics.h:48
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition: pen.h:29
virtual drawing::color fore_color() const
Gets the foreground color of the control.
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
virtual void draw_segment_l(drawing::graphics &graphics, const drawing::color &color)
Draw segment l on specified graphics with specified color.
Definition: fourteen_segment_display.h:145
void draw_back_digit(drawing::graphics &graphics) override
Draw all background digit on specified graphics.
Definition: fourteen_segment_display.h:42
virtual void draw_segment_k(drawing::graphics &graphics, const drawing::color &color)
Draw segment k on specified graphics with specified color.
Definition: fourteen_segment_display.h:135
fourteen_segment_display()=default
Initialize a new instance of fourteen_segment_display class.
virtual void draw_segment_h(drawing::graphics &graphics, const drawing::color &color)
Draw segment h on specified graphics with specified color.
Definition: fourteen_segment_display.h:107
int32_t thickness() const override
Sets thickness of segment.
Definition: fourteen_segment_display.h:27
virtual void draw_segment_m(drawing::graphics &graphics, const drawing::color &color)
Draw segment m on specified graphics with specified color.
Definition: fourteen_segment_display.h:153
virtual void draw_segment_g2(drawing::graphics &graphics, const drawing::color &color)
Draw segment g2 on specified graphics with specified color.
Definition: fourteen_segment_display.h:82
virtual void draw_segment_i(drawing::graphics &graphics, const drawing::color &color)
Draw segment ion specified graphics with specified color.
Definition: fourteen_segment_display.h:117
virtual void draw_segment_j(drawing::graphics &graphics, const drawing::color &color)
Draw segment j on specified graphics with specified color.
Definition: fourteen_segment_display.h:125
virtual void draw_segment_g1(drawing::graphics &graphics, const drawing::color &color)
Draw segment g1 on specified graphics with specified color.
Definition: fourteen_segment_display.h:57
void on_paint(paint_event_args &e) override
Raises the control::paint event.
Definition: fourteen_segment_display.h:30
void draw_segment_g(drawing::graphics &graphics, const drawing::color &color) override
Draw segment g on specified graphics with specified color.
Definition: fourteen_segment_display.h:161
Provides data for the paint event.
Definition: paint_event_args.h:26
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
void on_paint(paint_event_args &e) override
Raises the control::paint event.
Definition: seven_segment_display.h:144
virtual void draw_back_digit(drawing::graphics &graphics)
Draw all background digit on specified graphics.
Definition: seven_segment_display.h:191
virtual int32_t thickness() const
Gets thickness of segment.
Definition: seven_segment_display.h:92
@ e
The E key.
@ expanded
Expanded segment style.
@ mixed
Mixed (mix between standard and modern) segment style.
@ design
Design segment style.
@ stick
Stick segment style.
@ modern
Modern segment style.
@ standard
Standard segment style.
@ g1
The g1 segment.
@ h
The h segment.
@ l
The l segment.
@ j
The j segment.
@ m
The m segment.
@ i
The i segment.
@ k
The k segment.
@ g2
The g2 segment.
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::seven_segment_display control.