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.
fourteen_segment_display.h
Go to the documentation of this file.
1 #pragma once
6 
7 namespace xtd {
8  namespace forms {
19  public:
21 
24  fourteen_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 {
60  }
61 
62  void draw_back_digit(drawing::graphics& graphics) override {
72  }
73 
77  virtual void draw_segment_g1(drawing::graphics& graphics, const drawing::color& color) {
79  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
80  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);
81  } else if (segment_style() == segment_style::modern) {
82  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
83  graphics.draw_line(drawing::pen(color), 2 + abs(2 * offset), size().height() / 2 + offset, size().width() / 2 - 1 - abs(offset), size().height() / 2 + offset);
84  } else if (segment_style() == segment_style::mixed) {
85  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
86  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);
87  } else if (segment_style() == segment_style::expanded) {
88  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
89  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);
90  } else if (segment_style() == segment_style::design) {
91  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
92  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);
93  } else if (segment_style() == segment_style::stick) {
94  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
95  graphics.draw_line(drawing::pen(color), 2 + thickness(), size().height() / 2 + offset, size().width() / 2 - 1 - abs(offset), size().height() / 2 + offset);
96  }
97  }
98 
102  virtual void draw_segment_g2(drawing::graphics& graphics, const drawing::color& color) {
104  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
105  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);
106  } else if (segment_style() == segment_style::modern) {
107  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
108  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);
109  } else if (segment_style() == segment_style::mixed) {
110  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
111  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);
112  } else if (segment_style() == segment_style::expanded) {
113  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
114  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);
115  } else if (segment_style() == segment_style::design) {
116  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
117  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);
118  } else if (segment_style() == segment_style::stick) {
119  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
120  graphics.draw_line(drawing::pen(color), size().width() / 2 + 1 + abs(offset), size().height() / 2 + offset, size().width() - 3 - thickness(), size().height() / 2 + offset);
121  }
122  }
123 
127  virtual void draw_segment_h(drawing::graphics& graphics, const drawing::color& color) {
128  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++) {
129  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));
130  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);
131  }
132  }
133 
137  virtual void draw_segment_i(drawing::graphics& graphics, const drawing::color& color) {
138  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
139  graphics.draw_line(drawing::pen(color), size().width() / 2 - offset, 2 + thickness(), size().width() / 2 - offset, size().height() / 2 - 1 - abs(offset));
140  }
141 
145  virtual void draw_segment_j(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() - 3 - thickness() - abs(offset), 2 + thickness(), size().width() /2 + 2 + thickness() / 2, size().height() / 2 - 2 - thickness() / 2 - abs(offset));
148  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);
149  }
150  }
151 
155  virtual void draw_segment_k(drawing::graphics& graphics, const drawing::color& color) {
156  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++) {
157  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));
158  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());
159  }
160  }
161 
165  virtual void draw_segment_l(drawing::graphics& graphics, const drawing::color& color) {
166  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++)
167  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());
168  }
169 
173  virtual void draw_segment_m(drawing::graphics& graphics, const drawing::color& color) {
174  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++) {
175  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));
176  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());
177  }
178  }
179 
180  void draw_segment_g(drawing::graphics& graphics, const drawing::color& color) override {}
182 
183  private:
184  std::optional<int32_t> thickness_;
185  };
186  }
187 }
Contains xtd::forms::seven_segment_display control.
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:102
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:77
virtual const drawing::size & size() const
Gets the height and width of the control.
void on_paint(paint_event_args &e) override
Raises the control::paint event.
Definition: seven_segment_display.h:160
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
seven_segment_display & thickness(int32_t value) override
Sets thickness of segment.
Definition: fourteen_segment_display.h:37
virtual forms::segment_style segment_style() const
Gets segment style.
Definition: seven_segment_display.h:88
fourteen_segment_display()=default
Initialize a new instance of fourteen_segment_display class.
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:173
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_i(drawing::graphics &graphics, const drawing::color &color)
Draw segment ion specified graphics with specified color.
Definition: fourteen_segment_display.h:137
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
Represents an ARGB (alpha, red, green, blue) color.
Definition: color.h:39
The g2 segment.
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.
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:180
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:155
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 void draw_back_digit(drawing::graphics &graphics)
Draw all background digit on specified graphics.
Definition: seven_segment_display.h:207
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.
Modern segment style.
Standard style dialog.
int32_t thickness() const override
Sets thickness of segment.
Definition: fourteen_segment_display.h:33
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:165
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 drawing::color back_segment_color()
Gets background segment color.
Definition: seven_segment_display.h:41
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
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
The g1 segment.
Mixed (mix between standard and modern) segment style.
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:145
size_t size
Represents a size of any object in bytes.
Definition: types.h:171
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:127