The Wiggly example shows how to animate a user control using timer and timer::tick event. In addition, the example demonstrates how to use graphics::measure_string to determine the size of text on screen.
#include <xtd/drawing/system_colors>
#include <xtd/forms/application>
#include <xtd/forms/form>
#include <xtd/forms/text_box>
#include <xtd/forms/timer>
#include <xtd/forms/user_control>
namespace wiggly_example {
public:
wiggly() {
timer.
tick += event_handler(*
this, &wiggly::on_timer_tick);
}
protected:
static const auto sins =
list {0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38};
auto wiggly_text =
text().to_u32string();
for (
auto i = 0_z;
i < wiggly_text.length();
i++) {
auto index = (step +
i) % sins.size();
pos.x = pos.x +
as<int>(
e.graphics().measure_string(string::format(
"{}", wiggly_text[
i]),
font()).
width);
}
}
private:
void on_timer_tick(
object& sender,
const event_args&
e) {
step++;
invalidate();
}
int step = 0;
};
class form1 :
public form {
public:
form1() {
client_size({330, 130});
controls().push_back_range({wiggly,
text_box});
};
wiggly.bounds({20, 20, 290, 60});
}
private:
wiggly_example::wiggly wiggly;
};
}
auto main() -> int {
}
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:80
static xtd::drawing::color from_hsb(float hue, float saturation, float brightness) noexcept
Creates a xtd::drawing::color class from the three HSV component (hue, saturation,...
Defines a particular format for text, including font face, size, and style attributes....
Definition font.hpp:45
float size() const noexcept
Gets the em-size of this xtd::drawing::font measured in the units specified by the unit property.
Defines a xtd::drawing::brush of a single color. Brushes are used to fill graphics shapes,...
Definition solid_brush.hpp:29
static xtd::drawing::color window()
Gets a xtd::drawing::color structure that is the color of the background in the client area of a wind...
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition event_args.hpp:18
Represents a standard Windows text box.
Definition text_box.hpp:31
@ text_box
The system-defined color of the accent color (macos specific. On other platform is same as window).
Definition known_color.hpp:501
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
type_t as(any_object &o)
Casts a type into another type.
Definition __as_any_object.hpp:59
@ i
The I key.
Definition console_key.hpp:104
@ e
The E key.
Definition console_key.hpp:96
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:16
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition actions_system_images.hpp:10
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.hpp:16
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 point subtract(const point &pt, const size &sz) noexcept
Returns the result of subtracting specified xtd::drawing::size from the specified xtd::drawing::point...