xtd 0.2.0
owner_button.cpp

demonstrates how to create a custom button with xtd::forms::button control.

Windows

macOS

Gnome

#include <xtd/drawing/drawing_2d/linear_gradient_brush>
#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/control_paint>
#include <xtd/forms/form>
using namespace xtd;
using namespace xtd::drawing;
using namespace xtd::forms;
namespace owner_button_example {
class owner_button : public button {
protected:
void on_paint(paint_event_args& e) override {
auto accentuate_color = [](const color & c, float percent) {
};
auto background_color = get_back_color().value_or(application::style_sheet().system_colors().control());
auto foreground_color = get_fore_color().value_or(application::style_sheet().system_colors().control_text());
auto button_color = accentuate_color(background_color, .05F);
auto border_color = accentuate_color(background_color, .15F);
auto text_color = foreground_color;
border_color = accentuate_color(border_color, .15F);
button_color = accentuate_color(background_color, .15F);
text_color = accentuate_color(foreground_color, .15F);
border_color = accentuate_color(border_color, .30F);
button_color = accentuate_color(background_color, .30F);
text_color = accentuate_color(foreground_color, .30F);
border_color = button_color = color::from_argb(85, 85, 55);
text_color = application::style_sheet().system_colors().gray_text();
}
e.graphics().fill_rounded_rectangle(drawing_2d::linear_gradient_brush(e.clip_rectangle(), control_paint::light(button_color, .2), control_paint::dark(button_color), drawing_2d::linear_gradient_mode::vertical), e.clip_rectangle().x, e.clip_rectangle().y, e.clip_rectangle().width, e.clip_rectangle().height, e.clip_rectangle().height / 2);
e.graphics().draw_rounded_rectangle(pen(border_color, 1), e.clip_rectangle().x, e.clip_rectangle().y, e.clip_rectangle().width - 1, e.clip_rectangle().height - 1, e.clip_rectangle().height / 2);
e.graphics().draw_string(text(), font(), solid_brush(text_color), rectangle(e.clip_rectangle().x + 5, e.clip_rectangle().y + 3, e.clip_rectangle().width - 10, e.clip_rectangle().height - 7), string_format().alignment(string_alignment::center).line_alignment(string_alignment::center));
}
};
class form1 : public form {
public:
form1() {
owner_button1.location({145, 25});
owner_button1.size({80, 25});
owner_button1.text("Button 1");
owner_button2.location({105, 70});
owner_button2.size({160, 50});
owner_button2.back_color(color::red);
owner_button2.fore_color(color::white);
owner_button2.text("Button 2");
owner_button3.location({25, 145});
owner_button3.size({320, 100});
owner_button3.back_color(color::blue);
owner_button3.fore_color(color::white);
owner_button3.text("Button 3");
text("Owner button example");
client_size({370, 270});
controls().push_back_range({owner_button1, owner_button2, owner_button3});
}
private:
owner_button owner_button1;
owner_button owner_button2;
owner_button owner_button3;
};
}
auto main() -> int {
application::run(owner_button_example::form1 {});
}
Represent background color output manipulator class.
Definition background_color.hpp:24
Represents an ARGB (alpha, red, green, blue) color.
Definition color.hpp:46
static const xtd::drawing::color white
Gets a system-defined color that has an ARGB value of 0xFFFFFFFF. This field is constant.
Definition color.hpp:470
static const xtd::drawing::color red
Gets a system-defined color that has an ARGB value of 0xFFFF0000. This field is constant.
Definition color.hpp:401
static const xtd::drawing::color blue
Gets a system-defined color that has an ARGB value of 0xFF0000FF. This field is constant.
Definition color.hpp:86
static xtd::drawing::color from_argb(uint32 argb) noexcept
Creates a xtd::drawing::color class from a 32-bit ARGB value.
Encapsulates a xtd::drawing::brush with a linear gradient. This class cannot be inherited.
Definition linear_gradient_brush.hpp:30
Defines a particular format for text, including font face, size, and style attributes....
Definition font.hpp:45
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition pen.hpp:32
Defines a xtd::drawing::brush of a single color. Brushes are used to fill graphics shapes,...
Definition solid_brush.hpp:29
Encapsulates text layout information (such as alignment, orientation and tab stops) display manipulat...
Definition string_format.hpp:30
Each property of the xtd::drawing::system_colors class is a xtd::drawing::color structure that is the...
Definition system_colors.hpp:25
Represent foreground color output manipulator class.
Definition foreground_color.hpp:20
static const xtd::forms::style_sheets::style_sheet & style_sheet() noexcept
Gets current xtd::forms::style_sheets::style_sheet style sheet.
static void run()
Begins running a standard application message loop on the current thread, without a form.
static bool dark_mode() noexcept
Gets a value indicating whether dark mode is enabled for the application.
Represents a Windows button control.
Definition button.hpp:49
static xtd::drawing::color dark(const xtd::drawing::color &base_color)
Creates a new dark color object for the control from the specified color.
static xtd::drawing::color light(const xtd::drawing::color &base_color)
Creates a new light color object for the control from the specified color.
virtual drawing::point location() const noexcept
Gets the coordinates of the upper-left corner of the control relative to the upper-left corner of its...
Represents a window or dialog box that makes up an application's user interface.
Definition form.hpp:54
Provides data for the xtd::forms::control::paint event.
Definition paint_event_args.hpp:30
@ control_text
The system-defined color of text in a 3-D element.
Definition known_color.hpp:461
@ center
Specifies that text is aligned in the center of the layout rectangle.
Definition string_alignment.hpp:27
@ control
The left or right CTRL modifier key.
Definition console_modifiers.hpp:28
@ c
The C key.
Definition console_key.hpp:92
@ e
The E key.
Definition console_key.hpp:96
@ vertical
Specifies a gradient from top to bottom.
Definition linear_gradient_mode.hpp:23
@ disabled
The button is disabled.
Definition push_button_state.hpp:34
@ hot
The button is hot.
Definition push_button_state.hpp:28
@ checked
The button is checked.
Definition push_button_state.hpp:32
@ pressed
The button is pressed.
Definition push_button_state.hpp:30
@ default_state
The button has the default appearance.
Definition push_button_state.hpp:36
@ percent
The control should be sized as a percentage of the parent container.
Definition size_type.hpp:28
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition actions_system_images.hpp:10
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition texts.hpp:217
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.hpp:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Stores a set of four integers that represent the location and size of a rectangle.
Definition rectangle.hpp:44