xtd 0.2.0
circular_form.cpp

demonstrates the use of xtd::forms::control::region property for create a circular form.

Windows

macOS

Gnome

#include <xtd/drawing/drawing_2d/radial_gradient_brush>
#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::drawing;
using namespace xtd::drawing::drawing_2d;
using namespace xtd::forms;
class form_main : public form {
public:
static auto main() {
application::run(form_main());
}
form_main() {
start_position(form_start_position::manual);
client_size({200, 200});
double_buffered(true);
location({screen::from_control(*this).working_area().left() + screen::from_control(*this).working_area().width / 2 - client_size().width / 2, screen::from_control(*this).working_area().bottom() - client_size().height});
top_most(true);
// Create a circular region for the form
path.add_ellipse(client_rectangle());
paint += [&](object& sender, paint_event_args& e) {
auto gradient_color1 = color::from_argb(0xBC, 0, 0);
auto gradient_color2 = color::from_argb(0xFF, 0xAA, 0x7E);
e.graphics().fill_rectangle(radial_gradient_brush {point {80, 70}, {gradient_color2, gradient_color1}, 110}, e.clip_rectangle());
};
mouse_down += [&](object& sender, const mouse_event_args& e) {
mouse_location = e.location();
};
mouse_up += [&](object& sender, const mouse_event_args& e) {
mouse_location = point::empty;
};
mouse_move += [&](object& sender, const mouse_event_args& e) {
if (mouse_location == point::empty) return;
auto working_area = screen::from_control(*this).working_area();
auto new_bounds = bounds();
new_bounds.location(new_bounds.location() + e.location() - mouse_location);
if (new_bounds.left() < working_area.left()) new_bounds.location({working_area.left(), new_bounds.top()});
if (new_bounds.top() < working_area.top()) new_bounds.location({new_bounds.left(), working_area.top()});
if (new_bounds.left() + new_bounds.width > working_area.right()) new_bounds.location({working_area.right() - new_bounds.width, new_bounds.top()});
if (new_bounds.top() + new_bounds.height > working_area.bottom()) new_bounds.location({new_bounds.left(), working_area.bottom() - new_bounds.height});
bounds(new_bounds);
};
}
private:
point mouse_location = point::empty;
};
startup_(form_main::main);
static xtd::drawing::color from_argb(uint32 argb) noexcept
Creates a xtd::drawing::color class from a 32-bit ARGB value.
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition graphics_path.hpp:33
Encapsulates a xtd::drawing::brush with a radial gradient. This class cannot be inherited.
Definition radial_gradient_brush.hpp:29
Describes the interior of a graphics shape composed of rectangles and paths. This class cannot be inh...
Definition region.hpp:32
static void run()
Begins running a standard application message loop on the current thread, without a form.
Represents the image used to paint the mouse pointer.
Definition cursor.hpp:40
static cursor default_cursor()
Gets the default cursor, which is usually an arrow cursor.
static cursor hand()
Gets the hand cursor, typically used when hovering over a Web link.
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::mouse_up, xtd::forms::control::mouse_down,...
Definition mouse_event_args.hpp:34
Provides data for the xtd::forms::control::paint event.
Definition paint_event_args.hpp:30
static screen from_control(const control &control)
Retrieves a screen for the display that contains the largest portion of the specified control.
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:167
@ path
The xtd::uri::local_path data.
Definition uri_components.hpp:27
@ e
The E key.
Definition console_key.hpp:96
form_border_style
Specifies the border styles for a form.
Definition form_border_style.hpp:22
@ location
Specifies that both the x and y coordinates of the control are defined.
Definition bounds_specified.hpp:30
@ manual
The position of the form is determined by the Location property.
Definition form_start_position.hpp:24
@ none
No border.
Definition form_border_style.hpp:24
The xtd::drawing::drawing_2d namespace provides advanced two-dimensional and vector graphics function...
Definition compositing_mode.hpp:12
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
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition point.hpp:54
static const point empty
Represents a xtd::drawing::point that has xtd::drawing::point::x and xtd::drawing::point::y values se...
Definition point.hpp:59