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

demonstrates the use of xtd::forms::animation control.

Windows

macOS

Gnome

#include <xtd/drawing/basic_colors>
#include <xtd/forms/animation>
#include <xtd/forms/application>
#include <xtd/forms/debug_form>
using namespace xtd;
using namespace xtd::collections::generic;
using namespace xtd::drawing;
using namespace xtd::diagnostics;
using namespace xtd::forms;
namespace animation_example {
class form1 : public form {
public:
form1() {
back_color(basic_colors::teal());
client_size({360, 280});
controls().push_back(fish_animation);
fore_color(basic_colors::aqua());
text("Animation example");
fish_animation.dock(dock_style::fill);
fish_animation.frames_per_second(60);
fish_animation.start();
fish_animation.click += event_handler {*this, &form1::on_fish_animation_click};
fish_animation.paint += paint_event_handler {*this, &form1::on_fish_animation_paint};
fish_animation.updated += animation_updated_event_handler {*this, &form1::on_fish_animation_updated};
}
private:
void on_fish_animation_click(object& sender, const event_args& e) {
fish_animation.running(!fish_animation.running());
}
void on_fish_animation_paint(object& sender, paint_event_args& e) {
e.graphics().clear(fish_animation.back_color());
static const auto fish_length = 16;
auto points = list<point_f> {};
for (auto i = 0; i < fish_length; ++i) {
auto radius = 100 + 10 * sin(as<float>(fish_animation.frame_counter()) * 0.1f + as<float>(i) * 0.5f);
auto point = point_f(as<float>(e.clip_rectangle().width()) / 2.0f + 1.5f * radius * sin(as<float>(fish_animation.frame_counter()) * 0.02f + as<float>(i) * 0.12f), as<float>(e.clip_rectangle().height()) / 2.0f + 1.0f * radius * cos(as<float>(fish_animation.frame_counter()) * 0.04f + as<float>(i) * 0.12f));
e.graphics().fill_ellipse(solid_brush(fish_animation.fore_color()), point.x() - as<float>(i), point.y() - as<float>(i), 2.0f + 2.0f * as<float>(i), 2.0f + 2.0f * as<float>(i));
points.push_back(point);
}
e.graphics().draw_lines(pen(fish_animation.fore_color(), 4), points);
}
void on_fish_animation_updated(object& sender, const animation_updated_event_args& e) {
debug::write_line(string::format("frame_counter={}, elapsed={}", e.frame_counter(), e.elapsed()));
}
animation fish_animation;
};
}
auto main() -> int {
auto df = debug_form {};
df.back_color(basic_colors::black());
df.fore_color(basic_colors::lime());
application::run(animation_example::form1 {});
}
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:71
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition pen.hpp:35
Represents an ordered pair of floating-point x- and y-coordinates that defines a point in a two-dimen...
Definition point_f.hpp:35
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition point.hpp:54
int32 y() const noexcept
Gets the y-coordinate of this xtd::drawing::point.
int32 x() const noexcept
Gets the x-coordinate of this xtd::drawing::point.
Defines a xtd::drawing::brush of a single color. Brushes are used to fill graphics shapes,...
Definition solid_brush.hpp:30
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition event_args.hpp:18
Provides data for the animation update event.
Definition animation_update_event_args.hpp:22
Represents an animation control.
Definition animation.hpp:27
virtual drawing::color back_color() const noexcept
Gets the background color for the control.
Represents a form that displays debug form. This class cannot be inherited.
Definition debug_form.hpp:36
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
generic_event_handler<> event_handler
Represents the method that will handle an event that has no event data.
Definition event_handler.hpp:32
delegate< void(object &sender, paint_event_args &e)> paint_event_handler
Represents the method that will handle the xtd::forms::control::paint event of a control.
Definition paint_event_handler.hpp:24
xtd::delegate< void(xtd::object &, const xtd::forms::animation_updated_event_args &)> animation_updated_event_handler
Represents the method that will handle the update of xtd::forms::animation.
Definition animation_update_event_handler.hpp:24
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:15
The xtd::diagnostics namespace provides classes that allow you to interact with system processes,...
Definition assert_dialog_result.hpp:10
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