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.
linear_gradient_brush.h
Go to the documentation of this file.
1 #pragma once
5 #include <array>
6 #include "../../drawing_export.h"
7 #include "../brush.h"
8 #include "../color.h"
9 #include "../point.h"
10 #include "../rectangle.h"
11 #include "linear_gradient_mode.h"
12 
14 namespace xtd {
16  namespace drawing {
18  namespace drawing2d {
28  class drawing_export_ linear_gradient_brush final : public brush {
29  public:
35  linear_gradient_brush(const xtd::drawing::point& point1, const xtd::drawing::point& point2, const xtd::drawing::color& color1, const xtd::drawing::color& color2) {
36  data_->point1_ = point1;
37  data_->point2_ = point2;
38  data_->linear_colors_ = {color1, color2};
39  recreate_handle();
40  }
47  data_->point1_ = point1;
48  data_->point2_ = point2;
49  data_->linear_colors_ = {color1, color2};
50  recreate_handle();
51  }
56  linear_gradient_brush(const xtd::drawing::rectangle_f& rect, const xtd::drawing::color& color1, const xtd::drawing::color& color2) : linear_gradient_brush(rect, color1, color2, xtd::drawing::drawing2d::linear_gradient_mode::horizontal) {}
63  data_->point1_ = rect.location();
64  data_->point2_ = xtd::drawing::point_f(rect.right(), rect.bottom());
65  if (linear_gradient_mode == xtd::drawing::drawing2d::linear_gradient_mode::horizontal) data_->point2_.y(.0);
66  if (linear_gradient_mode == xtd::drawing::drawing2d::linear_gradient_mode::vertical) data_->point2_.x(.0);
68  auto x = data_->point1_.x();
69  data_->point1_.x(data_->point2_.x());
70  data_->point2_.x(x);
71  }
72  data_->linear_colors_ = {color1, color2};
73  recreate_handle();
74  }
79  linear_gradient_brush(const xtd::drawing::rectangle& rect, const xtd::drawing::color& color1, const xtd::drawing::color& color2) : linear_gradient_brush(rect, color1, color2, xtd::drawing::drawing2d::linear_gradient_mode::horizontal) {}
86  data_->point1_ = rect.location();
87  data_->point2_ = xtd::drawing::point(rect.right(), rect.bottom());
88  if (linear_gradient_mode == xtd::drawing::drawing2d::linear_gradient_mode::horizontal) data_->point2_.y(data_->point1_.y());
89  if (linear_gradient_mode == xtd::drawing::drawing2d::linear_gradient_mode::vertical) data_->point2_.x(data_->point1_.x());
91  auto x = data_->point1_.x();
92  data_->point1_.x(data_->point2_.x());
93  data_->point2_.x(x);
94  }
95  data_->linear_colors_ = {color1, color2};
96  recreate_handle();
97  }
98 
101  linear_gradient_brush& operator=(const linear_gradient_brush& value);
102  bool operator==(const linear_gradient_brush& value) const {return data_->point1_ == value.data_->point1_ && data_->point2_ == value.data_->point2_ && data_->linear_colors_[0] == value.data_->linear_colors_[0] && data_->linear_colors_[1] == value.data_->linear_colors_[1];}
103  bool operator!=(const linear_gradient_brush& value) const {return !operator==(value);}
105 
108  const std::array<xtd::drawing::color, 2>& linear_colors() const {return data_->linear_colors_;}
111  std::array<xtd::drawing::color, 2>& linear_colors() {return data_->linear_colors_;}
115  xtd::drawing::drawing2d::linear_gradient_brush& linear_colors(const std::array<xtd::drawing::color, 2>& linear_colors);
116 
120 
121  private:
123  void recreate_handle();
124  struct data {
125  xtd::drawing::point_f point1_;
126  xtd::drawing::point_f point2_;
127  std::array<xtd::drawing::color, 2> linear_colors_;
128  };
129  std::shared_ptr<data> data_ = std::make_shared<data>();
130  };
131  }
132  }
133 }
Encapsulates a xtd::drawing::brush with a linear gradient. This class cannot be inherited.
Definition: linear_gradient_brush.h:28
linear_gradient_brush(const xtd::drawing::rectangle &rect, const xtd::drawing::color &color1, const xtd::drawing::color &color2, xtd::drawing::drawing2d::linear_gradient_mode linear_gradient_mode)
Initializes a new instance of the linear_gradient_brush class with the specified rectangle, colors, and orientation.
Definition: linear_gradient_brush.h:85
linear_gradient_brush(const xtd::drawing::point &point1, const xtd::drawing::point &point2, const xtd::drawing::color &color1, const xtd::drawing::color &color2)
Initializes a new instance of the linear_gradient_brush class with the specified points and colors...
Definition: linear_gradient_brush.h:35
const std::array< xtd::drawing::color, 2 > & linear_colors() const
Gets the starting and ending colors of the gradient.
Definition: linear_gradient_brush.h:108
Specifies a gradient from left to right.
std::array< xtd::drawing::color, 2 > & linear_colors()
Gets the starting and ending colors of the gradient.
Definition: linear_gradient_brush.h:111
Contains xtd::drawing::drawing2d::linear_gradient_mode enum class.
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition: point.h:48
linear_gradient_brush(const xtd::drawing::rectangle &rect, const xtd::drawing::color &color1, const xtd::drawing::color &color2)
Initializes a new instance of the linear_gradient_brush class with the specified rectangle and colors...
Definition: linear_gradient_brush.h:79
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Stores a set of four floating-points that represent the location and size of a rectangle.
Definition: rectangle_f.h:28
linear_gradient_brush(const xtd::drawing::rectangle_f &rect, const xtd::drawing::color &color1, const xtd::drawing::color &color2, xtd::drawing::drawing2d::linear_gradient_mode linear_gradient_mode)
Initializes a new instance of the linear_gradient_brush class with the specified rectangle, colors, and orientation.
Definition: linear_gradient_brush.h:62
Represents an ordered pair of floating-point x- and y-coordinates that defines a point in a two-dimen...
Definition: point_f.h:26
Represents an ARGB (alpha, red, green, blue) color.
Definition: color.h:39
A pattern of lines on a diagonal from upper right to lower left.
linear_gradient_mode
Specifies the direction of a linear gradient.
Definition: linear_gradient_mode.h:19
Stores a set of four integers that represent the location and size of a rectangle.
Definition: rectangle.h:25
int32_t y() const
Gets the y-coordinate of this point.
Definition: point.h:205
linear_gradient_brush(const xtd::drawing::rectangle_f &rect, const xtd::drawing::color &color1, const xtd::drawing::color &color2)
Initializes a new instance of the linear_gradient_brush class with the specified rectangle and colors...
Definition: linear_gradient_brush.h:56
linear_gradient_brush(const xtd::drawing::point_f &point1, const xtd::drawing::point_f &point2, const xtd::drawing::color &color1, const xtd::drawing::color &color2)
Initializes a new instance of the linear_gradient_brush class with the specified points and colors...
Definition: linear_gradient_brush.h:46
Defines objects used to fill the interiors of graphical shapes such as rectangles, ellipses, pies, polygons, and paths.
Definition: brush.h:27
Specifies a gradient from top to bottom.