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.hpp:71
Represents an ARGB (alpha, red, green, blue) color.
Definition color.hpp:49
colors for all the standard colors. This class cannot be inherited.
Definition colors.hpp:26
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition pen.hpp:35
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition point.hpp:54
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
Implements a timer that raises an event at user-defined intervals. This timer is optimized for use in...
Definition timer.hpp:38
Represents a pseudo-random number generator, a device that produces a sequence of numbers that meet c...
Definition random.hpp: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.hpp:32
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:15
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition brush.hpp:18
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.hpp:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10