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.
nine_segment_display.h
Go to the documentation of this file.
1 #pragma once
6 
7 namespace xtd {
8  namespace forms {
19  public:
21 
24  nine_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 {
54  }
55 
56  void draw_back_digit(drawing::graphics& graphics) override {
60  }
61 
65  virtual void draw_segment_h(drawing::graphics& graphics, const drawing::color& color) {
66  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++) {
67  graphics.draw_line(drawing::pen(color), size().width() - 3 - thickness() - abs(offset), 2 + thickness(), 2 + thickness(), size().height() / 2 - 2 - thickness() / 2 - abs(offset));
68  graphics.draw_line(drawing::pen(color), size().width() - 3 - thickness(), 2 + thickness() + abs(offset), 2 + thickness() + abs(offset), size().height() / 2 - 2 - thickness() / 2);
69  }
70  }
71 
75  virtual void draw_segment_i(drawing::graphics& graphics, const drawing::color& color) {
76  for (int32_t offset = -thickness() / 2; offset < thickness() - thickness() / 2; offset++) {
77  graphics.draw_line(drawing::pen(color), size().width() - 3 - thickness() - abs(offset), size().height() / 2 + 2 + thickness() / 2, 2 + thickness(), size().height() - 3 - thickness() - abs(offset));
78  graphics.draw_line(drawing::pen(color), size().width() - 3 - thickness(), size().height() / 2 + 2 + thickness() / 2 + abs(offset), 2 + thickness() + abs(offset), size().height() - 3 - thickness());
79  }
80  }
82 
83  private:
84  std::optional<int32_t> thickness_;
85  };
86  }
87 }
88 
void draw_back_digit(drawing::graphics &graphics) override
Draw all background digit on specified graphics.
Definition: nine_segment_display.h:56
Contains xtd::forms::seven_segment_display control.
Represents a nine segment display class.
Definition: nine_segment_display.h:18
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.
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: nine_segment_display.h:37
virtual void draw_segment_i(drawing::graphics &graphics, const drawing::color &color)
Draw segment ion specified graphics with specified color.
Definition: nine_segment_display.h:75
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.
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
int32_t thickness() const override
Sets thickness of segment.
Definition: nine_segment_display.h:33
Represents an ARGB (alpha, red, green, blue) color.
Definition: color.h:39
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 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.
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
nine_segment_display()=default
Initialize a new instance of nine_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: nine_segment_display.h:65
void on_paint(paint_event_args &e) override
Raises the control::paint event.
Definition: nine_segment_display.h:50