xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
graphics.h
Go to the documentation of this file.
1
4#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
25namespace xtd {
26 namespace forms {
27 class control;
28 class control_paint;
29 class paint_event_args;
30 class screen;
31 }
32}
34
36namespace xtd {
38 namespace drawing {
40 class image;
49 public:
51 graphics(const graphics& value);
52 graphics& operator=(const graphics& value);
53 ~graphics();
55
58 intptr_t handle() const {return data_->handle_;}
59
62 void clear(const color& color);
63
70 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));}
77 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);}
86 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);
95 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));}
96
104 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());}
112 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());}
124 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));}
136 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);
137
142 void draw_ellipse(const xtd::drawing::pen& pen, const xtd::drawing::rectangle& rect) {draw_ellipse(pen, rect.x(), rect.y(), rect.width(), rect.height());}
147 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());}
155 void draw_ellipse(const xtd::drawing::pen& pen, int32_t x, int32_t y, int32_t width, int32_t height);
163 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));}
164
165 void draw_image(const xtd::drawing::image& image, const xtd::drawing::rectangle& rect) {draw_image(image, rect.x(), rect.y(), rect.width(), rect.height());}
166 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());}
167 void draw_image(const xtd::drawing::image& image, const xtd::drawing::point& point) {draw_image(image, point.x(), point.y());}
168 void draw_image(const xtd::drawing::image& image, const xtd::drawing::point_f& point) {draw_image(image, point.x(), point.y());}
169 void draw_image(const xtd::drawing::image& image, int32_t x, int32_t y, int32_t width, int32_t height);
170 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));}
171 void draw_image(const xtd::drawing::image& image, int32_t x, int32_t y);
172 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));}
173
174 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());}
175 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());}
176 void draw_line(const xtd::drawing::pen& pen, int32_t x1, int32_t y1, int32_t x2, int32_t y2);
177 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));}
178
179 void draw_point(const xtd::drawing::pen& pen, const xtd::drawing::point& p) {draw_point(pen, p.x(), p.y());}
180 void draw_point(const xtd::drawing::pen& pen, const xtd::drawing::point_f& p) {draw_point(pen, p.x(), p.y());}
181 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));}
182 void draw_point(const xtd::drawing::pen& pen, float x, float y) {fill_ellipse(solid_brush(pen.color()), x, y, pen.width(), pen.width());}
183
184 void draw_rectangle(const xtd::drawing::pen& pen, const xtd::drawing::rectangle& rect) {draw_rectangle(pen, rect.x(), rect.y(), rect.width(), rect.height());}
185 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());}
186 void draw_rectangle(const xtd::drawing::pen& pen, int32_t x, int32_t y, int32_t width, int32_t height);
187 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));}
188
189 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);}
190 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);}
191 void draw_rounded_rectangle(const xtd::drawing::pen& pen, int32_t x, int32_t y, int32_t width, int32_t height, int32_t radius);
192 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));}
193
194 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);
195 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());}
196 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);}
197 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());}
198 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);
199 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());}
200
201 void fill_ellipse(const xtd::drawing::brush& brush, const xtd::drawing::rectangle& rect) {fill_ellipse(brush, rect.x(), rect.y(), rect.width(), rect.height());}
202 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());}
203 void fill_ellipse(const xtd::drawing::brush& brush, int32_t x, int32_t y, int32_t width, int32_t height);
204 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));}
205
206 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));}
207 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);}
208 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);
209 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));}
210
211 void fill_rectangle(const xtd::drawing::brush& brush, const xtd::drawing::rectangle& rect) {fill_rectangle(brush, rect.x(), rect.y(), rect.width(), rect.height());}
212 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());}
213 void fill_rectangle(const xtd::drawing::brush& brush, int32_t x, int32_t y, int32_t width, int32_t height);
214 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));}
215
216 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);}
217 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);}
218 void fill_rounded_rectangle(const xtd::drawing::brush& brush, int32_t x, int32_t y, int32_t width, int32_t height, int32_t radius);
219 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));}
220
221 static graphics from_image(const xtd::drawing::image& image);
222
223 size_f measure_string(const xtd::ustring& text, const xtd::drawing::font& font);
224
225 void rotate_transform(float angle);
226
227 void translate_clip(int32_t dx, int32_t dy);
228
229 void translate_clip(float dx, float dy) {translate_clip(static_cast<int32_t>(dx), static_cast<int32_t>(dy));}
230
231 xtd::ustring to_string() const noexcept override {return ustring::full_class_name(*this);}
232
234 friend std::ostream& operator<<(std::ostream& os, const xtd::drawing::graphics& graphics) noexcept {
235 return os << graphics.to_string();
236 }
238
239 private:
240 friend xtd::drawing::font;
241 friend xtd::forms::control;
244 friend xtd::forms::screen;
245
246 graphics(intptr_t handle) {data_->handle_ = handle;}
247 void draw_image_disabled(const xtd::drawing::image& image, int32_t x, int32_t y, float brightness);
248
249 struct data {
250 intptr_t handle_ = 0;
251 };
252 std::shared_ptr<data> data_ = std::make_shared<data>();
253 };
254 }
255}
Contains xtd::drawing::brush class.
Defines objects used to fill the interiors of graphical shapes such as rectangles,...
Definition: brush.h:27
Represents an ARGB (alpha, red, green, blue) color.
Definition: color.h:39
Defines a particular format for text, including font face, size, and style attributes....
Definition: font.h:39
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition: graphics.h:48
void draw_ellipse(const xtd::drawing::pen &pen, int32_t x, int32_t y, int32_t width, int32_t height)
Draws an ellipse defined by a bounding rectangle specified by coordinates for the upper-left corner o...
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)
Draws an arc representing a portion of an ellipse specified by a pair of coordinates,...
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)
Draws a Bézier spline defined by four ordered pairs of coordinates that represent points.
void clear(const color &color)
Clears the entire drawing surface and fills it with the specified background color.
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:77
xtd::ustring to_string() const noexcept override
Returns a std::string that represents the current object.
Definition: graphics.h:231
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,...
Definition: graphics.h:95
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:147
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:142
intptr_t handle() const
Gets the handle device context that the graphics is bound to.
Definition: graphics.h:58
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:70
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:104
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:124
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:112
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:163
An abstract base class that provides functionality for the bitmap and metafile descended classes.
Definition: image.h:34
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition: pen.h:29
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 ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition: point.h:48
int32_t y() const
Gets the y-coordinate of this point.
Definition: point.h:205
int32_t x() const
Gets the x-coordinate of this point.
Definition: point.h:159
Stores a set of four floating-points that represent the location and size of a rectangle.
Definition: rectangle_f.h:28
Stores a set of four integers that represent the location and size of a rectangle.
Definition: rectangle.h:25
Provides methods used to paint common Windows controls and their elements. This class cannot be inher...
Definition: control_paint.h:29
Defines the base class for controls, which are components with visual representation.
Definition: control.h:67
Provides data for the paint event.
Definition: paint_event_args.h:26
Represents a display device or multiple display devices on a single system.
Definition: screen.h:29
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition: object.h:26
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
Contains xtd::drawing::color class.
Contains xtd::drawing::font class.
#define drawing_export_
Define shared library export.
Definition: drawing_export.h:13
@ control
The left or right CTRL modifier key.
@ y
The Y key.
@ p
The P key.
@ x
The X key.
@ point
Specifies a printer's point (1/72 inch) as the unit of measure.
@ draw_line
Draw line splitter style.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17
Contains xtd::object class.
Contains xtd::drawing::pen class.
Contains xtd::drawing::point class.
Contains xtd::drawing::point_f class.
Contains xtd::drawing::rectangle class.
Contains xtd::drawing::rectangle_f class.
Contains xtd::drawing::size class.
Contains xtd::drawing::size_f class.
Contains xtd::drawing::solid_brush class.
Contains xtd::drawing::string_format class.
Contains xtd::ustring class.