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.
graphics.h
Go to the documentation of this file.
1 #pragma once
5 #include <cstdint>
6 #include <limits>
7 #include <ostream>
8 #include <xtd/object.h>
9 #include <xtd/ustring.h>
10 #include "../drawing_export.h"
11 #include "brush.h"
12 #include "solid_brush.h"
13 #include "color.h"
14 #include "font.h"
15 #include "pen.h"
16 #include "point.h"
17 #include "point_f.h"
18 #include "rectangle.h"
19 #include "rectangle_f.h"
20 #include "size.h"
21 #include "string_format.h"
22 #include "size_f.h"
23 
25 namespace xtd {
26  namespace forms {
27  class control;
28  class control_paint;
29  class paint_event_args;
30  class screen;
31  }
32 }
34 
36 namespace xtd {
38  namespace drawing {
40  class image;
48  class drawing_export_ graphics : public object {
49  public:
51  graphics(const graphics& value);
52  graphics& operator=(const graphics& value);
53  ~graphics();
55 
57 
61  intptr_t handle() const {return data_->handle_;}
63 
65 
69  void clear(const color& color);
70 
77  void draw_arc(const xtd::drawing::pen& pen, const xtd::drawing::rectangle& rect, float start_angle, float sweep_angle) {draw_arc(pen, rect.x(), rect.y(), rect.width(), rect.height(), static_cast<int32_t>(start_angle), static_cast<int32_t>(sweep_angle));}
84  void draw_arc(const xtd::drawing::pen& pen, const xtd::drawing::rectangle_f& rect, float start_angle, float sweep_angle) {draw_arc(pen, rect.x(), rect.y(), rect.width(), rect.height(), start_angle, sweep_angle);}
93  void draw_arc(const xtd::drawing::pen& pen, int32_t x, int32_t y, int32_t width, int32_t height, int32_t start_angle, int32_t sweep_angle);
102  void draw_arc(const xtd::drawing::pen& pen, float x, float y, float width, float height, float start_angle, float sweep_angle) {draw_arc(pen, static_cast<int32_t>(x), static_cast<int32_t>(y), static_cast<int32_t>(width), static_cast<int32_t>(height), static_cast<int32_t>(start_angle), static_cast<int32_t>(sweep_angle));}
103 
111  void draw_bezier(const xtd::drawing::pen& pen, const xtd::drawing::point& pt1, const xtd::drawing::point& pt2, const xtd::drawing::point& pt3, const xtd::drawing::point& pt4) {draw_bezier(pen, pt1.x(), pt1.y(), pt2.x(), pt2.y(), pt3.x(), pt3.y(), pt4.x(), pt4.y());}
119  void draw_bezier(const xtd::drawing::pen& pen, const xtd::drawing::point_f& pt1, const xtd::drawing::point_f& pt2, const xtd::drawing::point_f& pt3, const xtd::drawing::point_f& pt4) {draw_bezier(pen, pt1.x(), pt1.y(), pt2.x(), pt2.y(), pt3.x(), pt3.y(), pt4.x(), pt4.y());}
131  void draw_bezier(const pen& pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {draw_bezier(pen, static_cast<int32_t>(x1), static_cast<int32_t>(y1), static_cast<int32_t>(x2), static_cast<int32_t>(y2), static_cast<int32_t>(x3), static_cast<int32_t>(y3), static_cast<int32_t>(x4), static_cast<int32_t>(y4));}
143  void draw_bezier(const pen& pen, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, int32_t x4, int32_t y4);
144 
149  void draw_ellipse(const xtd::drawing::pen& pen, const xtd::drawing::rectangle& rect) {draw_ellipse(pen, rect.x(), rect.y(), rect.width(), rect.height());}
154  void draw_ellipse(const xtd::drawing::pen& pen, const xtd::drawing::rectangle_f& rect) {draw_ellipse(pen, rect.x(), rect.y(), rect.width(), rect.height());}
162  void draw_ellipse(const xtd::drawing::pen& pen, int32_t x, int32_t y, int32_t width, int32_t height);
170  void draw_ellipse(const xtd::drawing::pen& pen, float x, float y, float width, float height) {draw_ellipse(pen, static_cast<int32_t>(x), static_cast<int32_t>(y), static_cast<int32_t>(width), static_cast<int32_t>(height));}
171 
172  void draw_image(const xtd::drawing::image& image, const xtd::drawing::rectangle& rect) {draw_image(image, rect.x(), rect.y(), rect.width(), rect.height());}
173  void draw_image(const xtd::drawing::image& image, const xtd::drawing::rectangle_f& rect) {draw_image(image, rect.x(), rect.y(), rect.width(), rect.height());}
174  void draw_image(const xtd::drawing::image& image, const xtd::drawing::point& point) {draw_image(image, point.x(), point.y());}
175  void draw_image(const xtd::drawing::image& image, const xtd::drawing::point_f& point) {draw_image(image, point.x(), point.y());}
176  void draw_image(const xtd::drawing::image& image, int32_t x, int32_t y, int32_t width, int32_t height);
177  void draw_image(const xtd::drawing::image& image, float x, float y, float width, float height) {draw_image(image, static_cast<int32_t>(x), static_cast<int32_t>(y), static_cast<int32_t>(width), static_cast<int32_t>(height));}
178  void draw_image(const xtd::drawing::image& image, int32_t x, int32_t y);
179  void draw_image(const xtd::drawing::image& image, float x, float y) {draw_image(image, static_cast<int32_t>(x), static_cast<int32_t>(y));}
180 
181  void draw_line(const xtd::drawing::pen& pen, const xtd::drawing::point& p1, const point& p2) {draw_line(pen, p1.x(), p1.y(), p2.x(), p2.y());}
182  void draw_line(const xtd::drawing::pen& pen, const xtd::drawing::point_f& p1, const point_f& p2) {draw_line(pen, p1.x(), p1.y(), p2.x(), p2.y());}
183  void draw_line(const xtd::drawing::pen& pen, int32_t x1, int32_t y1, int32_t x2, int32_t y2);
184  void draw_line(const xtd::drawing::pen& pen, float x1, float y1, float x2, float y2) {draw_line(pen, static_cast<int32_t>(x1), static_cast<int32_t>(y1), static_cast<int32_t>(x2), static_cast<int32_t>(y2));}
185 
186  void draw_point(const xtd::drawing::pen& pen, const xtd::drawing::point& p) {draw_point(pen, p.x(), p.y());}
187  void draw_point(const xtd::drawing::pen& pen, const xtd::drawing::point_f& p) {draw_point(pen, p.x(), p.y());}
188  void draw_point(const xtd::drawing::pen& pen, int32_t x, int32_t y) {draw_point(pen, static_cast<float>(x), static_cast<float>(y));}
189  void draw_point(const xtd::drawing::pen& pen, float x, float y) {fill_ellipse(solid_brush(pen.color()), x, y, pen.width(), pen.width());}
190 
191  void draw_rectangle(const xtd::drawing::pen& pen, const xtd::drawing::rectangle& rect) {draw_rectangle(pen, rect.x(), rect.y(), rect.width(), rect.height());}
192  void draw_rectangle(const xtd::drawing::pen& pen, const xtd::drawing::rectangle_f& rect) {draw_rectangle(pen, rect.x(), rect.y(), rect.width(), rect.height());}
193  void draw_rectangle(const xtd::drawing::pen& pen, int32_t x, int32_t y, int32_t width, int32_t height);
194  void draw_rectangle(const xtd::drawing::pen& pen, float x, float y, float width, float height) {draw_rectangle(pen, static_cast<int32_t>(x), static_cast<int32_t>(y), static_cast<int32_t>(width), static_cast<int32_t>(height));}
195 
196  void draw_rounded_rectangle(const xtd::drawing::pen& pen, const xtd::drawing::rectangle& rect, int32_t radius) {draw_rounded_rectangle(pen, rect.x(), rect.y(), rect.width(), rect.height(), radius);}
197  void draw_rounded_rectangle(const xtd::drawing::pen& pen, const xtd::drawing::rectangle_f& rect, float radius) {draw_rounded_rectangle(pen, rect.x(), rect.y(), rect.width(), rect.height(), radius);}
198  void draw_rounded_rectangle(const xtd::drawing::pen& pen, int32_t x, int32_t y, int32_t width, int32_t height, int32_t radius);
199  void draw_rounded_rectangle(const xtd::drawing::pen& pen, float x, float y, float width, float height, float radius) {draw_rounded_rectangle(pen, static_cast<int32_t>(x), static_cast<int32_t>(y), static_cast<int32_t>(width), static_cast<int32_t>(height), static_cast<int32_t>(radius));}
200 
201  void draw_string(const xtd::ustring& text, const xtd::drawing::font& font, const xtd::drawing::brush& brush, const xtd::drawing::rectangle_f& layout_rectangle, const string_format& format);
202  void draw_string(const xtd::ustring& text, const xtd::drawing::font& font, const xtd::drawing::brush& brush, const xtd::drawing::rectangle_f& layout_rectangle) {draw_string(text, font, brush, layout_rectangle, string_format());}
203  void draw_string(const xtd::ustring& text, const xtd::drawing::font& font, const xtd::drawing::brush& brush, const xtd::drawing::point_f& point, const string_format& format) {draw_string(text, font, brush, point.x(), point.y(), format);}
204  void draw_string(const xtd::ustring& text, const xtd::drawing::font& font, const xtd::drawing::brush& brush, const xtd::drawing::point_f& point) {draw_string(text, font, brush, point.x(), point.y(), string_format());}
205  void draw_string(const xtd::ustring& text, const xtd::drawing::font& font, const xtd::drawing::brush& brush, float x, float y, const string_format& format);
206  void draw_string(const xtd::ustring& text, const xtd::drawing::font& font, const xtd::drawing::brush& brush, float x, float y) {draw_string(text, font, brush, x, y, string_format());}
207 
208  void fill_ellipse(const xtd::drawing::brush& brush, const xtd::drawing::rectangle& rect) {fill_ellipse(brush, rect.x(), rect.y(), rect.width(), rect.height());}
209  void fill_ellipse(const xtd::drawing::brush& brush, const xtd::drawing::rectangle_f& rect) {fill_ellipse(brush, rect.x(), rect.y(), rect.width(), rect.height());}
210  void fill_ellipse(const xtd::drawing::brush& brush, int32_t x, int32_t y, int32_t width, int32_t height);
211  void fill_ellipse(const xtd::drawing::brush& brush, float x, float y, float width, float height) {fill_ellipse(brush, static_cast<int32_t>(x), static_cast<int32_t>(y), static_cast<int32_t>(width), static_cast<int32_t>(height));}
212 
213  void fill_pie(const xtd::drawing::brush& brush, const xtd::drawing::rectangle& rect, float start_angle, float sweep_angle) {fill_pie(brush, rect.x(), rect.y(), rect.width(), rect.height(), static_cast<int32_t>(start_angle), static_cast<int32_t>(sweep_angle));}
214  void fill_pie(const xtd::drawing::brush& brush, const xtd::drawing::rectangle_f& rect, float start_angle, float sweep_angle) {fill_pie(brush, rect.x(), rect.y(), rect.width(), rect.height(), start_angle, sweep_angle);}
215  void fill_pie(const xtd::drawing::brush& brush, int32_t x, int32_t y, int32_t width, int32_t height, int32_t start_angle, int32_t sweep_angle);
216  void fill_pie(const xtd::drawing::brush& brush, float x, float y, float width, float height, float start_angle, float sweep_angle) {fill_pie(brush, static_cast<int32_t>(x), static_cast<int32_t>(y), static_cast<int32_t>(width), static_cast<int32_t>(height), static_cast<int32_t>(start_angle), static_cast<int32_t>(sweep_angle));}
217 
218  void fill_rectangle(const xtd::drawing::brush& brush, const xtd::drawing::rectangle& rect) {fill_rectangle(brush, rect.x(), rect.y(), rect.width(), rect.height());}
219  void fill_rectangle(const xtd::drawing::brush& brush, const xtd::drawing::rectangle_f& rect) {fill_rectangle(brush, rect.x(), rect.y(), rect.width(), rect.height());}
220  void fill_rectangle(const xtd::drawing::brush& brush, int32_t x, int32_t y, int32_t width, int32_t height);
221  void fill_rectangle(const xtd::drawing::brush& brush, float x, float y, float width, float height) {fill_rectangle(brush, static_cast<int32_t>(x), static_cast<int32_t>(y), static_cast<int32_t>(width), static_cast<int32_t>(height));}
222 
223  void fill_rounded_rectangle(const xtd::drawing::brush& brush, const xtd::drawing::rectangle& rect, int32_t radius) {fill_rounded_rectangle(brush, rect.x(), rect.y(), rect.width(), rect.height(), radius);}
224  void fill_rounded_rectangle(const xtd::drawing::brush& brush, const xtd::drawing::rectangle_f& rect, float radius) {fill_rounded_rectangle(brush, rect.x(), rect.y(), rect.width(), rect.height(), radius);}
225  void fill_rounded_rectangle(const xtd::drawing::brush& brush, int32_t x, int32_t y, int32_t width, int32_t height, int32_t radius);
226  void fill_rounded_rectangle(const xtd::drawing::brush& brush, float x, float y, float width, float height, float radius) {fill_rounded_rectangle(brush, static_cast<int32_t>(x), static_cast<int32_t>(y), static_cast<int32_t>(width), static_cast<int32_t>(height), static_cast<int32_t>(radius));}
227 
228  static graphics from_image(const xtd::drawing::image& image);
229 
230  size_f measure_string(const xtd::ustring& text, const xtd::drawing::font& font);
231 
232  void rotate_transform(float angle);
233 
234  void translate_clip(int32_t dx, int32_t dy);
235 
236  void translate_clip(float dx, float dy) {translate_clip(static_cast<int32_t>(dx), static_cast<int32_t>(dy));}
237 
238  xtd::ustring to_string() const noexcept override {return ustring::full_class_name(*this);}
240 
242  friend std::ostream& operator<<(std::ostream& os, const xtd::drawing::graphics& graphics) noexcept {
243  return os << graphics.to_string();
244  }
246 
247  private:
248  friend xtd::drawing::font;
249  friend xtd::forms::control;
252  friend xtd::forms::screen;
253 
254  explicit graphics(intptr_t handle) {data_->handle_ = handle;}
255  void draw_image_disabled(const xtd::drawing::image& image, int32_t x, int32_t y, float brightness);
256 
257  struct data {
258  intptr_t handle_ = 0;
259  };
260  std::shared_ptr<data> data_ = std::make_shared<data>();
261  };
262  }
263 }
Contains xtd::drawing::string_format class.
Represents a display device or multiple display devices on a single system.
Definition: screen.h:29
void draw_ellipse(const xtd::drawing::pen &pen, float x, float y, float width, float height)
Draws an ellipse defined by a bounding rectangle specified by coordinates for the upper-left corner o...
Definition: graphics.h:170
Defines a particular format for text, including font face, size, and style attributes. This class cannot be inherited.
Definition: font.h:39
intptr_t handle() const
Gets the handle device context that the graphics is bound to.
Definition: graphics.h:61
Provides methods used to paint common Windows controls and their elements. This class cannot be inher...
Definition: control_paint.h:35
int32_t x() const
Gets the x-coordinate of this point.
Definition: point.h:170
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition: point.h:48
Contains xtd::drawing::point class.
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
Stores a set of four floating-points that represent the location and size of a rectangle.
Definition: rectangle_f.h:28
Contains xtd::drawing::solid_brush class.
Contains xtd::drawing::brush class.
Contains xtd::drawing::point_f class.
void draw_bezier(const xtd::drawing::pen &pen, const xtd::drawing::point_f &pt1, const xtd::drawing::point_f &pt2, const xtd::drawing::point_f &pt3, const xtd::drawing::point_f &pt4)
Draws a Bézier spline defined by four Point structures.
Definition: graphics.h:119
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:50
Specifies that the left edge of the control is defined.
void draw_bezier(const xtd::drawing::pen &pen, const xtd::drawing::point &pt1, const xtd::drawing::point &pt2, const xtd::drawing::point &pt3, const xtd::drawing::point &pt4)
Draws a Bézier spline defined by four Point structures.
Definition: graphics.h:111
void draw_bezier(const pen &pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
Draws a Bézier spline defined by four ordered pairs of coordinates that represent points...
Definition: graphics.h:131
Represents an ordered pair of floating-point x- and y-coordinates that defines a point in a two-dimen...
Definition: point_f.h:26
Stores an ordered pair of floating-point, which specify a height and width.
Definition: size_f.h:24
Contains xtd::drawing::rectangle_f class.
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
Defines a xtd::drawing::brush of a single color. Brushes are used to fill graphics shapes...
Definition: solid_brush.h:22
void draw_ellipse(const xtd::drawing::pen &pen, const xtd::drawing::rectangle &rect)
Draws an ellipse specified by a bounding xtd::drawing::rectangle structure.
Definition: graphics.h:149
Provides data for the paint event.
Definition: paint_event_args.h:27
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition: pen.h:29
Contains xtd::drawing::pen class.
Contains xtd::drawing::size class.
void draw_arc(const xtd::drawing::pen &pen, float x, float y, float width, float height, float start_angle, float sweep_angle)
Draws an arc representing a portion of an ellipse specified by a pair of coordinates, a width, and a height.
Definition: graphics.h:102
Specifies that the width of the control is defined.
Stores a set of four integers that represent the location and size of a rectangle.
Definition: rectangle.h:25
Contains xtd::ustring class.
Contains xtd::drawing::color class.
An abstract base class that provides functionality for the bitmap and metafile descended classes...
Definition: image.h:34
void draw_arc(const xtd::drawing::pen &pen, const xtd::drawing::rectangle_f &rect, float start_angle, float sweep_angle)
Draws an arc representing a portion of an ellipse specified by a Rectangle structure.
Definition: graphics.h:84
void draw_arc(const xtd::drawing::pen &pen, const xtd::drawing::rectangle &rect, float start_angle, float sweep_angle)
Draws an arc representing a portion of an ellipse specified by a Rectangle structure.
Definition: graphics.h:77
int32_t y() const
Gets the y-coordinate of this point.
Definition: point.h:216
Defines the base class for controls, which are components with visual representation.
Definition: control.h:69
Contains xtd::object class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:30
Contains xtd::drawing::size_f class.
xtd::ustring to_string() const noexcept override
Returns a std::string that represents the current object.
Definition: graphics.h:238
static ustring full_class_name()
Gets the fully qualified class name of the objec_t, including the namespace of the objec_t...
Definition: ustring.h:444
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
Draw line splitter style.
Defines objects used to fill the interiors of graphical shapes such as rectangles, ellipses, pies, polygons, and paths.
Definition: brush.h:27
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition: graphics.h:48
Contains xtd::drawing::font class.
void draw_ellipse(const xtd::drawing::pen &pen, const xtd::drawing::rectangle_f &rect)
Draws an ellipse specified by a bounding xtd::drawing::rectangle_f structure.
Definition: graphics.h:154
Encapsulates text layout information (such as alignment, orientation and tab stops) display manipulat...
Definition: string_format.h:25
The left or right CTRL modifier key.