xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
control_paint.h
Go to the documentation of this file.
1 #pragma once
5 #include <optional>
6 #include <string>
7 #include <xtd/drawing/color.h>
8 #include <xtd/drawing/font.h>
9 #include <xtd/drawing/graphics.h>
10 #include <xtd/drawing/image.h>
11 #include <xtd/drawing/rectangle.h>
14 #include "../forms_export.h"
15 #include "button_state.h"
16 #include "image_layout.h"
17 #include "text_format_flags.h"
18 
20 namespace xtd {
22  namespace forms {
29  class forms_export_ control_paint final static_ {
30  public:
42  static xtd::drawing::color average(const xtd::drawing::color& color1, const xtd::drawing::color& color2, double weight, bool average_alpha) {return xtd::drawing::color::average(color1, color2, weight, average_alpha);}
43 
54  //static xtd::drawing::color average(const xtd::drawing::color& color1, const xtd::drawing::color& color2, double weight) {return xtd::drawing::color::from_argb(static_cast<uint8_t>(color1.a() * weight + color2.a() * (1 - weight)), static_cast<uint8_t>(color1.r() * weight + color2.r() * (1 - weight)), static_cast<uint8_t>(color1.g() * weight + color2.g() * (1 - weight)), static_cast<uint8_t>(color1.b() * weight + color2.b() * (1 - weight)));}
55  static xtd::drawing::color average(const xtd::drawing::color& color1, const xtd::drawing::color& color2, double weight) {return average(color1, color2, weight, false);}
56 
61  static xtd::drawing::color dark(const xtd::drawing::color& base_color) {return dark(base_color, 1.0/3);}
66  static xtd::drawing::color dark(const xtd::drawing::color& base_color, double perc_of_dark_dark) {return xtd::drawing::color::dark(base_color, perc_of_dark_dark);}
67 
72  static xtd::drawing::color dark_dark(const xtd::drawing::color& base_color) {return dark(base_color, 1.0);}
73 
74  static void draw_button(xtd::drawing::graphics& graphics, const xtd::drawing::rectangle& rectangle, xtd::forms::button_state state) {draw_button(graphics, rectangle.x(), rectangle.y(), rectangle.width(), rectangle.height(), state);}
75  static void draw_button(xtd::drawing::graphics& graphics, int32_t x, int32_t y, int32_t width, int32_t height, xtd::forms::button_state state);
76 
82  static void draw_image(xtd::drawing::graphics& graphics, const xtd::drawing::image& image, const xtd::drawing::rectangle& rectangle, xtd::forms::image_layout image_layout) {draw_image(graphics, image, rectangle.x(), rectangle.y(), rectangle.width(), rectangle.height(), image_layout);}
91  static void draw_image(xtd::drawing::graphics& graphics, const xtd::drawing::image& image, int32_t x, int32_t y, int32_t width, int32_t height, xtd::forms::image_layout image_layout);
92 
100  static void draw_image_disabled(xtd::drawing::graphics& graphics, const xtd::drawing::image& image, int32_t x, int32_t y, float brightness);
108  static void draw_image_disabled(xtd::drawing::graphics& graphics, const xtd::drawing::image& image, int32_t x, int32_t y, const xtd::drawing::color& background) {draw_image_disabled(graphics, image, x, y, background.get_brightness());}
115  static void draw_image_disabled(xtd::drawing::graphics& graphics, const xtd::drawing::image& image, const xtd::drawing::point& location, float brightness) {draw_image_disabled(graphics, image, location.x(), location.y(), brightness);}
122  static void draw_image_disabled(xtd::drawing::graphics& graphics, const xtd::drawing::image& image, const xtd::drawing::point& location, const xtd::drawing::color& background) {draw_image_disabled(graphics, image, location.x(), location.y(), background.get_brightness());}
123 
128  static xtd::drawing::color light(const xtd::drawing::color& base_color) {return light(base_color, 1.0/3);}
133  static xtd::drawing::color light(const xtd::drawing::color& base_color, double perc_of_light_light) {return xtd::drawing::color::light(base_color, perc_of_light_light);}
134 
139  static xtd::drawing::color light_light(const xtd::drawing::color& base_color) {return light(base_color, 1.0);}
140 
145  xtd::drawing::string_format string_format;
148 
149  if ((flags & text_format_flags::horizontal_center) == text_format_flags::horizontal_center) string_format.alignment(xtd::drawing::string_alignment::center);
150  else if ((flags & text_format_flags::right) == text_format_flags::right) string_format.alignment(xtd::drawing::string_alignment::far);
152 
153  if ((flags & text_format_flags::vertical_center) == text_format_flags::vertical_center) string_format.line_alignment(xtd::drawing::string_alignment::center);
154  else if ((flags & text_format_flags::bottom) == text_format_flags::bottom) string_format.line_alignment(xtd::drawing::string_alignment::far);
156 
157  if ((flags & text_format_flags::no_prefix) == text_format_flags::no_prefix) string_format.hotkey_prefix(xtd::drawing::hotkey_prefix::none);
158  else if ((flags & text_format_flags::hide_prefix) == text_format_flags::hide_prefix) string_format.hotkey_prefix(xtd::drawing::hotkey_prefix::hide);
160 
161  return string_format;
162  }
163  };
164  }
165 }
Specifies the text be aligned near the layout. In a left-to-right layout, the near position is left...
Contains xtd::drawing::string_format class.
Centers the text horizontally within the bounding rectangle.
float get_brightness() const
Gets the hue-saturation-brightness (HSB) brightness value for this xtd::drawing::color structure...
xtd::drawing::string_alignment alignment() const
Gets horizontal alignment of the string.
Definition: string_format.h:74
Aligns the text on the bottom of the bounding rectangle. Applied only when the text is a single line...
Contains xtd::forms::button_state enum class. Copyright (c) 2021 Gammasoft. All flats reserved...
static void draw_image_disabled(xtd::drawing::graphics &graphics, const xtd::drawing::image &image, int32_t x, int32_t y, const xtd::drawing::color &background)
Draws the specified image in a disabled state.
Definition: control_paint.h:108
static color average(const color &color1, const color &color2, double weight, bool average_alpha)
Returns the weighted average color between the two given colors.
Definition: color.h:592
#define static_
This keyword is use to represent a static object. A static object can&#39;t be instantiated (constructors...
Definition: static.h:38
Provides methods used to paint common Windows controls and their elements. This class cannot be inher...
Definition: control_paint.h:29
int32_t x() const
Gets the x-coordinate of this point.
Definition: point.h:159
Contains xtd::drawing::system_fonts factory.
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition: point.h:48
static xtd::drawing::color dark(const xtd::drawing::color &base_color, double perc_of_dark_dark)
Creates a new dark color object for the control from the specified color and darkens it by the specif...
Definition: control_paint.h:66
Specifies that the top edge of the control is defined.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
static xtd::drawing::color dark_dark(const xtd::drawing::color &base_color)
Creates a new dark color object for the control from the specified color.
Definition: control_paint.h:72
Do not display the hot-key prefix.
Ignores the ampersand (&) prefix character in the text, so that the letter that follows won&#39;t be underlin...
Contains xtd::forms::text_format_flags enum class.
Specifies that the left edge of the control is defined.
static color light(const color &color, double weight)
Returns a lighter version of the specified color.
Definition: color.h:620
static xtd::drawing::color average(const xtd::drawing::color &color1, const xtd::drawing::color &color2, double weight, bool average_alpha)
Returns the weighted average color between the two given colors.
Definition: control_paint.h:42
Contains xtd::drawing::image class.
Specifies that text is aligned in the center of the layout rectangle.
Contains xtd::forms::image_layout enum class.
static void draw_image_disabled(xtd::drawing::graphics &graphics, const xtd::drawing::image &image, const xtd::drawing::point &location, float brightness)
Draws the specified image in a disabled state.
Definition: control_paint.h:115
static xtd::drawing::string_format string_format(xtd::forms::text_format_flags flags)
Convert xtd::forms::text_format_flags to xtd::drawing::string_format.
Definition: control_paint.h:144
static color dark(const color &color, double weight)
Returns a darker version of the specified color.
Definition: color.h:610
Turns off processing of prefix characters. Typically, the ampersand (&) mnemonic-prefix character is ...
Specifies that the height of the control is defined.
Contains xtd::drawing::rectangle class.
Represents an ARGB (alpha, red, green, blue) color.
Definition: color.h:39
Specifies that text is aligned far from the origin position of the layout rectangle. In a left-to-right layout, the far position is right. In a right-to-left layout, the far position is left.
static void draw_image_disabled(xtd::drawing::graphics &graphics, const xtd::drawing::image &image, const xtd::drawing::point &location, const xtd::drawing::color &background)
Draws the specified image in a disabled state.
Definition: control_paint.h:122
Specifies that the width of the control is defined.
xtd::drawing::string_alignment line_alignment() const
Gets vertical alignment of the string.
Definition: string_format.h:108
Stores a set of four integers that represent the location and size of a rectangle.
Definition: rectangle.h:25
static xtd::drawing::color light(const xtd::drawing::color &base_color)
Creates a new light color object for the control from the specified color.
Definition: control_paint.h:128
Contains xtd::drawing::color class.
An abstract base class that provides functionality for the bitmap and metafile descended classes...
Definition: image.h:34
int32_t y() const
Gets the y-coordinate of this point.
Definition: point.h:205
static xtd::drawing::color dark(const xtd::drawing::color &base_color)
Creates a new dark color object for the control from the specified color.
Definition: control_paint.h:61
Aligns the text on the right side of the clipping area.
static void draw_image(xtd::drawing::graphics &graphics, const xtd::drawing::image &image, const xtd::drawing::rectangle &rectangle, xtd::forms::image_layout image_layout)
Draws the specified image in a specified rectangle with specified layout.
Definition: control_paint.h:82
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
text_format_flags
Specifies the display and layout information for text strings.
Definition: text_format_flags.h:18
button_state
Specifies the appearance of a button.
Definition: button_state.h:19
Specifies that both the x and y coordinates of the control are defined.
static xtd::drawing::color light_light(const xtd::drawing::color &base_color)
Creates a new light color object for the control from the specified color.
Definition: control_paint.h:139
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition: graphics.h:48
static xtd::drawing::color average(const xtd::drawing::color &color1, const xtd::drawing::color &color2, double weight)
Returns the weighted average color between the two given colors.
Definition: control_paint.h:55
image_layout
Specifies the position of the image on the control.
Definition: image_layout.h:17
static xtd::drawing::color light(const xtd::drawing::color &base_color, double perc_of_light_light)
Creates a new light color object for the control from the specified color and lightens it by the spec...
Definition: control_paint.h:133
Contains xtd::drawing::graphics class.
Contains xtd::drawing::font class.
Centers the text vertically, within the bounding rectangle.
xtd::drawing::hotkey_prefix hotkey_prefix() const
Gets the HotkeyPrefix object for this string_format object.
Definition: string_format.h:96
Encapsulates text layout information (such as alignment, orientation and tab stops) display manipulat...
Definition: string_format.h:25
Display the hot-key prefix.