xtd 0.2.0
Loading...
Searching...
No Matches
draw_point.cpp

shows how to draw point in paint event using xtd::drawing::graphics::draw_point.

Windows

macOS

Gnome

#include <xtd/drawing/basic_colors>
#include <xtd/forms/application>
#include <xtd/forms/form>
#include <xtd/random>
using namespace xtd;
using namespace xtd::collections::generic;
using namespace xtd::drawing;
using namespace xtd::forms;
namespace draw_point_example {
class form1 : public form {
struct colored_point {
point location;
int width = 0;
bool operator ==(const colored_point& rhs) const noexcept {return location == rhs.location && color == rhs.color && width == rhs.width;}
};
public:
form1() {
text("Draw point example");
generate_colored_points_timer.interval(200_ms);
generate_colored_points_timer.tick += event_handler {*this, &form1::generate_colored_points};
generate_colored_points_timer.start();
}
protected:
void on_paint(paint_event_args& e) override {
form::on_paint(e);
e.graphics().clear(color::black);
for (auto colored_point : colored_points)
e.graphics().draw_point(pen(colored_point.color, as<float>(colored_point.width)), colored_point.location);
}
private:
void generate_colored_points() {
static auto random = xtd::random {};
static auto colors = basic_colors::get_colors();
colored_points.resize(random.next(height() * width() / 800, height() * width() / 400));
for (auto& colored_point : colored_points)
colored_point = {{random.next(client_size().width()), random.next(client_size().height())}, colors[random.next(colors.size())], random.next(1, 10)};
invalidate();
}
list<colored_point> colored_points;
timer generate_colored_points_timer;
};
}
auto main() -> int {
application::run(draw_point_example::form1 {});
}
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.h:71
Represents an ARGB (alpha, red, green, blue) color.
Definition color.h:49
colors for all the standard colors. This class cannot be inherited.
Definition colors.h:26
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition pen.h:35
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition point.h:54
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::paint event.
Definition paint_event_args.h:30
Implements a timer that raises an event at user-defined intervals. This timer is optimized for use in...
Definition timer.h:38
Represents a pseudo-random number generator, a device that produces a sequence of numbers that meet c...
Definition random.h:40
virtual int32 next() const
Returns a nonnegative random number.
generic_event_handler<> event_handler
Represents the method that will handle an event that has no event data.
Definition event_handler.h:32
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.h:15
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