xtd 0.2.0
images2.cpp

demonstrates the use of xtd::forms::images component.

Windows

macOS

Gnome

#include <xtd/drawing/system_colors>
#include <xtd/drawing/texts>
#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/button_images>
#include <xtd/forms/form>
#include <xtd/forms/images>
#include <xtd/forms/label>
#include <xtd/forms/picture_box>
using namespace xtd;
using namespace xtd::drawing;
using namespace xtd::forms;
namespace example {
class form1 : public form {
public:
form1() {
text("Images 2 example");
client_size({880, 820});
controls().push_back_range({label_picture_kde_theme, label_picture_gnome_theme, label_picture_macos_theme, label_picture_symbolic_theme, label_picture_windows_theme, label_picture_xtd_theme, picture_kde_theme, picture_gnome_theme, picture_macos_theme, picture_symbolic_theme, picture_windows_theme, picture_xtd_theme, panel_separator_line, label_picture_context, label_picture_name, label_picture_size, button_context_previous, button_context_next, button_name_previous, button_name_next, button_decrease, button_increase});
label_picture_kde_theme.text_align(content_alignment::middle_center);
label_picture_kde_theme.bounds({10, 25, 280, label_picture_name.height()});
label_picture_kde_theme.text("kde");
label_picture_kde_theme.border_style(forms::border_style::fixed_3d);
label_picture_kde_theme.back_color(label_picture_kde_theme.text() == application::system_style_sheet().theme().name() ? system_colors::accent() : system_colors::window());
label_picture_kde_theme.fore_color(label_picture_kde_theme.text() == application::system_style_sheet().theme().name() ? system_colors::accent() : system_colors::window_text());
label_picture_gnome_theme.text_align(content_alignment::middle_center);
label_picture_gnome_theme.bounds({300, 25, 280, label_picture_name.height()});
label_picture_gnome_theme.text("gnome");
label_picture_gnome_theme.border_style(forms::border_style::fixed_3d);
label_picture_gnome_theme.back_color(application::system_style_sheet().theme().name().to_lower().contains(label_picture_gnome_theme.text()) ? system_colors::accent() : system_colors::window());
label_picture_gnome_theme.fore_color(application::system_style_sheet().theme().name().to_lower().contains(label_picture_gnome_theme.text()) ? system_colors::accent_text() : system_colors::window_text());
label_picture_macos_theme.text_align(content_alignment::middle_center);
label_picture_macos_theme.bounds({590, 25, 280, label_picture_name.height()});
label_picture_macos_theme.text("macos");
label_picture_macos_theme.border_style(forms::border_style::fixed_3d);
label_picture_macos_theme.back_color(application::system_style_sheet().theme().name().to_lower().contains(label_picture_macos_theme.text()) ? system_colors::accent() : system_colors::window());
label_picture_macos_theme.fore_color(application::system_style_sheet().theme().name().to_lower().contains(label_picture_macos_theme.text()) ? system_colors::accent_text() : system_colors::window_text());
label_picture_symbolic_theme.text_align(content_alignment::middle_center);
label_picture_symbolic_theme.bounds({10, 360, 280, label_picture_name.height()});
label_picture_symbolic_theme.text("symbolic");
label_picture_symbolic_theme.border_style(forms::border_style::fixed_3d);
label_picture_symbolic_theme.back_color(application::system_style_sheet().theme().name().to_lower().contains(label_picture_symbolic_theme.text()) ? system_colors::accent() : system_colors::window());
label_picture_symbolic_theme.fore_color(application::system_style_sheet().theme().name().to_lower().contains(label_picture_symbolic_theme.text()) ? system_colors::accent_text() : system_colors::window_text());
label_picture_windows_theme.text_align(content_alignment::middle_center);
label_picture_windows_theme.bounds({300, 360, 280, label_picture_name.height()});
label_picture_windows_theme.text("windows");
label_picture_windows_theme.border_style(forms::border_style::fixed_3d);
label_picture_windows_theme.back_color(application::system_style_sheet().theme().name().to_lower().contains(label_picture_windows_theme.text()) ? system_colors::accent() : system_colors::window());
label_picture_windows_theme.fore_color(application::system_style_sheet().theme().name().to_lower().contains(label_picture_windows_theme.text()) ? system_colors::accent_text() : system_colors::window_text());
label_picture_xtd_theme.text_align(content_alignment::middle_center);
label_picture_xtd_theme.bounds({590, 360, 280, label_picture_name.height()});
label_picture_xtd_theme.text("xtd");
label_picture_xtd_theme.border_style(forms::border_style::fixed_3d);
label_picture_xtd_theme.back_color(application::system_style_sheet().theme().name().to_lower().contains(label_picture_xtd_theme.text()) ? system_colors::accent() : system_colors::window());
label_picture_xtd_theme.fore_color(application::system_style_sheet().theme().name().to_lower().contains(label_picture_xtd_theme.text()) ? system_colors::accent_text() : system_colors::window_text());
picture_kde_theme.back_color(system_colors::window());
picture_kde_theme.border_style(forms::border_style::fixed_3d);
picture_kde_theme.bounds({10, 65, 280, 280});
picture_kde_theme.size_mode(picture_box_size_mode::center_image);
picture_gnome_theme.back_color(system_colors::window());
picture_gnome_theme.border_style(forms::border_style::fixed_3d);
picture_gnome_theme.bounds({300, 65, 280, 280});
picture_gnome_theme.size_mode(picture_box_size_mode::center_image);
picture_macos_theme.back_color(system_colors::window());
picture_macos_theme.border_style(forms::border_style::fixed_3d);
picture_macos_theme.bounds({590, 65, 280, 280});
picture_macos_theme.size_mode(picture_box_size_mode::center_image);
picture_symbolic_theme.back_color(system_colors::window());
picture_symbolic_theme.border_style(forms::border_style::fixed_3d);
picture_symbolic_theme.bounds({10, 400, 280, 280});
picture_symbolic_theme.size_mode(picture_box_size_mode::center_image);
picture_windows_theme.back_color(system_colors::window());
picture_windows_theme.border_style(forms::border_style::fixed_3d);
picture_windows_theme.bounds({300, 400, 280, 280});
picture_windows_theme.size_mode(picture_box_size_mode::center_image);
picture_xtd_theme.back_color(system_colors::window());
picture_xtd_theme.border_style(forms::border_style::fixed_3d);
picture_xtd_theme.bounds({590, 400, 280, 280});
picture_xtd_theme.size_mode(picture_box_size_mode::center_image);
panel_separator_line.back_color(system_colors::control_text());
panel_separator_line.bounds({10, 695, 860, 1});
label_picture_context.text_align(content_alignment::middle_center);
label_picture_context.border_style(forms::border_style::fixed_3d);
label_picture_context.back_color(system_colors::window());
label_picture_context.bounds({10, 710, 280, label_picture_name.height()});
label_picture_name.text_align(content_alignment::middle_center);
label_picture_name.border_style(forms::border_style::fixed_3d);
label_picture_name.back_color(system_colors::window());
label_picture_name.bounds({300, 710, 280, label_picture_name.height()});
label_picture_size.text_align(content_alignment::middle_center);
label_picture_size.border_style(forms::border_style::fixed_3d);
label_picture_size.back_color(system_colors::window());
label_picture_size.bounds({590, 710, 280, label_picture_name.height()});
button_context_previous.auto_repeat(true);
button_context_previous.enabled(false);
button_context_previous.image(button_images::previous(drawing::size {32, 32}));
button_context_previous.image_align(content_alignment::middle_left);
button_context_previous.text(texts::previous());
button_context_previous.bounds({10, 750, 125, 40});
button_context_previous.click += [&] {
current_context_index--;
current_name_index = 0;
update_form();
};
button_context_next.auto_repeat(true);
button_context_next.image(button_images::next(drawing::size {32, 32}));
button_context_next.image_align(content_alignment::middle_right);
button_context_next.text(texts::next());
button_context_next.bounds({165, 750, 125, 40});
button_context_next.click += [&] {
current_context_index++;
current_name_index = 0;
update_form();
};
button_name_previous.auto_repeat(true);
button_name_previous.enabled(false);
button_name_previous.image(button_images::previous(drawing::size {32, 32}));
button_name_previous.image_align(content_alignment::middle_left);
button_name_previous.text("P&revious");
button_name_previous.bounds({300, 750, 125, 40});
button_name_previous.click += [&] {
current_name_index--;
update_form();
};
button_name_next.auto_repeat(true);
button_name_next.image(button_images::next(drawing::size {32, 32}));
button_name_next.image_align(content_alignment::middle_right);
button_name_next.text("N&ext");
button_name_next.bounds({455, 750, 125, 40});
button_name_next.click += [&] {
current_name_index++;
update_form();
};
button_decrease.auto_repeat(true);
button_decrease.enabled(false);
button_decrease.image(button_images::remove(drawing::size {32, 32}));
button_decrease.image_align(content_alignment::middle_left);
button_decrease.text("&Decrease");
button_decrease.bounds({590, 750, 125, 40});
button_decrease.click += [&] {
current_size_index--;
update_form();
};
button_increase.auto_repeat(true);
button_increase.image(button_images::add(drawing::size {32, 32}));
button_increase.image_align(content_alignment::middle_right);
button_increase.text("&Increase");
button_increase.bounds({745, 750, 125, 40});
button_increase.click += [&] {
current_size_index++;
update_form();
};
update_form();
}
private:
void update_form() {
picture_kde_theme.image(images::from_name("kde", images::names(images::contexts()[current_context_index])[current_name_index], images::sizes()[current_size_index]) != image::empty ? images::from_name("kde", images::names(images::contexts()[current_context_index])[current_name_index], images::sizes()[current_size_index]) : images::image_missing({256, 256}));
picture_gnome_theme.image(images::from_name("gnome", images::names(images::contexts()[current_context_index])[current_name_index], images::sizes()[current_size_index]) != image::empty ? images::from_name("gnome", images::names(images::contexts()[current_context_index])[current_name_index], images::sizes()[current_size_index]) : images::image_missing({256, 256}));
picture_macos_theme.image(images::from_name("macos", images::names(images::contexts()[current_context_index])[current_name_index], images::sizes()[current_size_index]) != image::empty ? images::from_name("macos", images::names(images::contexts()[current_context_index])[current_name_index], images::sizes()[current_size_index]) : images::image_missing({256, 256}));
picture_symbolic_theme.image(images::from_name("symbolic", images::names(images::contexts()[current_context_index])[current_name_index], images::sizes()[current_size_index]) != image::empty ? images::from_name("symbolic", images::names(images::contexts()[current_context_index])[current_name_index], images::sizes()[current_size_index]) : images::image_missing({256, 256}));
picture_windows_theme.image(images::from_name("windows", images::names(images::contexts()[current_context_index])[current_name_index], images::sizes()[current_size_index]) != image::empty ? images::from_name("windows", images::names(images::contexts()[current_context_index])[current_name_index], images::sizes()[current_size_index]) : images::image_missing({256, 256}));
picture_xtd_theme.image(images::from_name("xtd", images::names(images::contexts()[current_context_index])[current_name_index], images::sizes()[current_size_index]) != image::empty ? images::from_name("xtd", images::names(images::contexts()[current_context_index])[current_name_index], images::sizes()[current_size_index]) : images::image_missing({256, 256}));
label_picture_context.text(images::contexts()[current_context_index]);
label_picture_name.text(images::names(images::contexts()[current_context_index])[current_name_index]);
label_picture_size.text(string::format("{}x{} pixels", images::sizes()[current_size_index].width, images::sizes()[current_size_index].height));
button_context_previous.enabled(current_context_index > 0);
button_context_next.enabled(current_context_index < images::contexts().size() - 1);
button_name_previous.enabled(current_name_index > 0);
button_name_next.enabled(current_name_index < images::names(images::contexts()[current_context_index]).size() - 1);
button_decrease.enabled(current_size_index > 0);
button_increase.enabled(current_size_index < images::sizes().size() - 1);
}
size_t current_context_index = 0;
size_t current_name_index = 0;
size_t current_size_index = 7;
label label_picture_kde_theme;
label label_picture_gnome_theme;
label label_picture_macos_theme;
label label_picture_symbolic_theme;
label label_picture_windows_theme;
label label_picture_xtd_theme;
picture_box picture_kde_theme;
picture_box picture_gnome_theme;
picture_box picture_macos_theme;
picture_box picture_symbolic_theme;
picture_box picture_windows_theme;
picture_box picture_xtd_theme;
panel panel_separator_line;
label label_picture_context;
label label_picture_name;
label label_picture_size;
button button_context_previous;
button button_context_next;
button button_name_previous;
button button_name_next;
button button_decrease;
button button_increase;
};
}
auto main() -> int {
//application::enable_dark_mode();
//application::enable_light_mode();
application::run(example::form1 {});
}
static image empty
Represent an empty xtd::drawing::image.
Definition image.hpp:65
static xtd::drawing::color window_text()
Gets a xtd::drawing::color structure that is the color of the text in the client area of a window.
static xtd::drawing::color control_text()
Gets a xtd::drawing::color structure that is the color of text in a 3-D element.
static xtd::drawing::color accent()
Gets a xtd::drawing::color structure that is the color used to accent a control.
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...
static xtd::drawing::color accent_text()
Gets a xtd::drawing::color structure that is the color of the text used to accent a control.
static xtd::string previous()
Gets a system-defined text that has a string value of "&Previous". This field is constant.
static xtd::string next()
Gets a system-defined text that has a string value of "&Next". This field is constant.
static void run()
Begins running a standard application message loop on the current thread, without a form.
static const xtd::forms::style_sheets::style_sheet & system_style_sheet() noexcept
Gets system xtd::forms::style_sheets::style_sheet style sheet.
static xtd::drawing::image next()
Next image object.
Definition button_images.hpp:98
static xtd::drawing::image previous()
Previous image object.
Definition button_images.hpp:132
static xtd::drawing::image add()
Add image object.
Definition button_images.hpp:30
static xtd::drawing::image remove()
Remove image object.
Definition button_images.hpp:149
Represents a Windows button control.
Definition button.hpp:49
Represents a window or dialog box that makes up an application's user interface.
Definition form.hpp:54
static xtd::array< xtd::string > names() noexcept
Gets the image names.
Definition images.hpp:856
static xtd::array< xtd::string > contexts() noexcept
Gets the image contexts.
Definition images.hpp:69
static xtd::array< xtd::drawing::size > sizes() noexcept
Gets standard sizes for image.
Definition images.hpp:1258
static xtd::drawing::image from_name(const xtd::string &name)
Gets image object with specified name.
Definition images.hpp:1268
static xtd::drawing::image image_missing() noexcept
Gets the image missing.
Definition images.hpp:43
Represents a standard Windows label.
Definition label.hpp:38
Used to group collections of controls.
Definition panel.hpp:32
Represents a standard Windows picture box.
Definition picture_box.hpp:34
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
@ center_image
The image is displayed in the center if the picture_box is larger than the image. If the image is lar...
Definition picture_box_size_mode.hpp:30
@ height
Specifies that the height of the control is defined.
Definition bounds_specified.hpp:34
@ width
Specifies that the width of the control is defined.
Definition bounds_specified.hpp:32
@ fixed_3d
A three-dimensional border. Same as xtd::forms::border_style::inset.
Definition border_style.hpp:58
@ theme
Defines a 3D themed border. The effect depends on the border color value.
Definition border_style.hpp:38
@ middle_left
Content is vertically aligned in the middle, and horizontally aligned on the left.
Definition content_alignment.hpp:29
@ middle_center
Content is vertically aligned at the middle, and horizontally aligned at the center.
Definition content_alignment.hpp:31
@ middle_right
Content is vertically aligned at the middle, and horizontally aligned on the right.
Definition content_alignment.hpp:33
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition actions_system_images.hpp:10
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition texts.hpp:217
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
Stores an ordered pair of integers, which specify a height and width.
Definition size.hpp:31