xtd 0.2.0
Loading...
Searching...
No Matches
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() {
form_border_style(forms::form_border_style::none);
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();
cursor(cursors::hand());
};
mouse_up += [&](object& sender, const mouse_event_args& e) {
mouse_location = point::empty;
cursor(cursors::default_cursor());
};
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);
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition graphics_path.h:35
Encapsulates a xtd::drawing::brush with a radial gradient. This class cannot be inherited.
Definition radial_gradient_brush.h:30
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition point.h:54
Describes the interior of a graphics shape composed of rectangles and paths. This class cannot be inh...
Definition region.h:32
Represents the image used to paint the mouse pointer.
Definition cursor.h:40
Represents a window or dialog box that makes up an application's user interface.
Definition form.h:54
Provides data for the xtd::forms::control::mouse_up, xtd::forms::control::mouse_down,...
Definition mouse_event_args.h:34
Provides data for the xtd::forms::control::paint event.
Definition paint_event_args.h:30
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.h:175
form_border_style
Specifies the border styles for a form.
Definition form_border_style.h:22
The xtd::drawing::drawing_2d namespace provides advanced two-dimensional and vector graphics function...
Definition compositing_mode.h:12
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition brush.h:18
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.h:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10