1 #include "button_base.h" 2 #include "control_paint.h" 10 virtual bool auto_check()
const {
return auto_check_;}
12 if (auto_check_ != auto_check)
13 auto_check_ = auto_check;
17 virtual bool rounded()
const {
return rounded_;}
19 if (rounded_ != value) {
26 virtual bool checked()
const {
return checked_;}
28 if (checked_ != checked) {
39 virtual void on_checked_changed(
const event_args&
e) {checked_changed(*
this, e);}
42 button_base::on_mouse_down(e);
43 if (auto_check_) checked(!checked());
46 void on_handle_created(
const event_args& e)
override {
47 button_base::on_handle_created(e);
52 button_base::on_resize(e);
57 button_base::on_paint(e);
59 drawing::color button_back_color = checked_ ? xtd::forms::theme_colors::current_theme().accent() : xtd::forms::theme_colors::current_theme().gray_text();
70 float height =
static_cast<float>(e.clip_rectangle().height() - e.clip_rectangle().height() % 2);
71 float offset = (e.clip_rectangle().width() -
height) / 2.0
f - 0.5
f;
74 e.graphics().fill_pie(
drawing::solid_brush(button_back_color), offset / 2.0
f, .0
f, static_cast<float>(height), static_cast<float>(height), 90.0
f, 180.0
f);
75 e.graphics().fill_pie(
drawing::solid_brush(button_back_color), e.clip_rectangle().width() - height - offset / 2.0f - 0.5f, .0f,
static_cast<float>(
height), static_cast<float>(height), 270.0f, 180.0f);
76 e.graphics().fill_rectangle(
drawing::solid_brush(button_back_color), height / 2.0
f + offset / 2.0
f, .0
f, static_cast<float>(e.clip_rectangle().width() -
height) - offset, static_cast<float>(height));
77 e.graphics().fill_ellipse(
drawing::solid_brush(slider_color), slider_location.x(), slider_location.y(),
static_cast<float>(height - 4), static_cast<float>(height - 4));
79 drawing::size_f slider_size(static_cast<float>((e.clip_rectangle().width() - 6) / 2),
static_cast<float>(e.clip_rectangle().height() - 6));
82 std::string
text = checked_ ?
"ON" :
"OFF";
86 e.graphics().clear(button_back_color);
88 e.graphics().draw_line(drawing::pen(
control_paint::dark(button_back_color), 2), e.clip_rectangle().left(), e.clip_rectangle().top(), e.clip_rectangle().right(), e.clip_rectangle().top());
89 e.graphics().draw_line(drawing::pen(
control_paint::dark(button_back_color), 2), e.clip_rectangle().left(), e.clip_rectangle().top(), e.clip_rectangle().left(), e.clip_rectangle().bottom());
90 e.graphics().draw_line(drawing::pen(
control_paint::light(button_back_color), 2), e.clip_rectangle().left(), e.clip_rectangle().bottom(), e.clip_rectangle().right(), e.clip_rectangle().bottom());
91 e.graphics().draw_line(drawing::pen(
control_paint::light(button_back_color), 2), e.clip_rectangle().right(), e.clip_rectangle().top() + 2, e.clip_rectangle().right(), e.clip_rectangle().bottom());
94 e.graphics().draw_line(drawing::pen(
control_paint::light(slider_color)), slider_location.x(), slider_location.y(), slider_location.x() + slider_size.
width(), slider_location.y());
95 e.graphics().draw_line(drawing::pen(
control_paint::light(slider_color)), slider_location.x(), slider_location.y(), slider_location.x(), slider_location.y() + slider_size.
height() - 2);
96 e.graphics().draw_line(drawing::pen(
control_paint::dark(slider_color)), slider_location.x(), slider_location.y() + slider_size.
height() - 1, slider_location.x() + slider_size.
width(), slider_location.y() + slider_size.
height() - 1);
97 e.graphics().draw_line(drawing::pen(
control_paint::dark(slider_color)), slider_location.x() + slider_size.
width(), slider_location.y(), slider_location.x() + slider_size.
width(), slider_location.y() + slider_size.
height() - 1);
102 bool rounded_ =
true;
103 bool auto_check_ =
true;
104 bool checked_ =
false;
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:9
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:15
Stores an ordered pair of integers, which specify a height and width.
Definition: size_f.h:15
Represents an ARGB (alpha, red, green, blue) color.
Definition: color.h:29
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition: solid_brush.h:11
static const event_args empty
Provides a value to use with events that do not have event data.
Definition: event_args.h:23
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:582
float height() const
Gets he vertical component of this Size Class.
Definition: size_f.h:46
float width() const
Gets the horizontal component of this Size class.
Definition: size_f.h:56