xtd.drawing - Reference Guide  0.1.0
Modern c++17 library providing access to GDI+ basic graphics functionality. More advanced functionality is provided in the drawing 2D, imaging, and text.
xtd::drawing::point Class Reference

Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional plane. More...

#include <point.h>

Public Member Functions

 point ()=default
 Initializes a new instance of the point class. More...
 
 point (int32_t dw)
 nitializes a new instance of the point class using coordinates specified by an integer value. More...
 
 point (int32_t x, int32_t y)
 Initializes a new instance of the point class with the specified coordinates. More...
 
 point (const size &sz)
 Initializes a new instance of the point class from a size. More...
 
bool is_empty () const
 Gets a value indicating whether this point is empty. More...
 
void offset (int dx, int dy)
 Translates this point by the specified amount. More...
 
void offset (const point &p)
 Translates this point by the specified point. More...
 
std::string to_string () const
 Converts this point to a human-readable string. More...
 
int32_t x () const
 Gets the x-coordinate of this point. More...
 
void x (int32_t x)
 Sets the x-coordinate of this point. More...
 
int32_t y () const
 Gets the y-coordinate of this point. More...
 
void y (int32_t y)
 Sets the y-coordinate of this point. More...
 

Static Public Member Functions

static point add (const point &pt, const size &sz)
 Adds the specified size to the specified point. More...
 
static point ceiling (const point_f &value)
 Converts the specified point_f to a point by rounding the values of the point_f to the next higher integer values. More...
 
static point round (const point_f &value)
 Converts the specified point_f to a point object by rounding the point_f values to the nearest integer. More...
 
static point subtract (const point &pt, const size &sz)
 Returns the result of subtracting specified Size from the specified point. More...
 
static point truncate (const point_f &value)
 Converts the specified point_f to a point by truncating the values of the point_f. More...
 

Static Public Attributes

static const point empty
 Represents a point that has x and y values set to zero. More...
 

Detailed Description

Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional plane.

Remarks
To convert a point to a point_f, use Implicit cast operator.
Examples
void create_points_and_sizes(paint_event_args& e) {
// Create the starting point.
point start_point = subtract_button.size();
// Use the addition operator to get the end point.
point end_point = start_point + size(140, 150);
// Draw a line between the points.
e.graphics().draw_line(system_pens::highlight, start_point, end_point);
// Convert the starting point to a size and compare it to the subtractButton size.
size button_size(start_point);
if (button_size == subtract_button.size()) {
// If the sizes are equal, tell the user.
e.graphics().draw_string("The sizes are equal.", font(this->font, font_style.italic), brushes::indigo, 10.0F, 65.0F);
}
}

Constructor & Destructor Documentation

§ point() [1/4]

xtd::drawing::point::point ( )
default

Initializes a new instance of the point class.

Remarks
x and y values are set to zero.

§ point() [2/4]

xtd::drawing::point::point ( int32_t  dw)
inlineexplicit

nitializes a new instance of the point class using coordinates specified by an integer value.

Parameters
dxA 32-bit integer that specifies the coordinates for the new point.
Remarks
The low-order 16 bits of the dw parameter specify the horizontal x-coordinate and the higher 16 bits specify the vertical y-coordinate for the new point.
Examples
The following code example demonstrates how to use the point and size. size constructors and the xtd::drawing::content_alignment enumeration. To run this example, paste this code into a Windows Form (xtd::forms) that contains a label named label1, and call the initialize_label1 method in the form's constructor.
void initialize_label1() {
// Set a border.
label1.border_style = border_style::fixed_single;
// Set the size, constructing a size from two integers.
label1.size(drawing::size(100, 50));
// Set the location, constructing a point from a 32-bit integer
// (using hexadecimal).
label1.location(point(0x280028));
// Set and align the text on the lower-right side of the label.
label1.text_align = content_alignment::bottom_right;
label1.text = "Bottom Right Alignment";
}

§ point() [3/4]

xtd::drawing::point::point ( int32_t  x,
int32_t  y 
)
inline

Initializes a new instance of the point class with the specified coordinates.

Parameters
xThe horizontal position of the point.
yThe vertical position of the point.
Examples
The following code example demonstrates how to use the Equality operator and how to construct a point from a size or two integers. It also demonstrates how to use the x and y properties. This example is designed to be used with Windows Forms (xtd.forms). Paste the code into a form that contains a button named button1, and associate the button1_click method with the button's click event.
void button1_Click(const control& sender, const event_args& e) {
// Construct a new point with integers.
point point1(100, 100);
// Create a Graphics object.
graphics form_graphics = this->create_graphics();
// Construct another point, this time using a Size.
point point2(size(100, 100));
// Call the equality operator to see if the points are equal, and if so print out their x and y values.
if (point1 == point2) {
form_graphics.draw_string(strings::format("point1.x: {}, point2.x: {}, point1.y: {}, point2.y {}", point1.x(), point2.x(), point1.y(), point2.y()), this->font(), brushes::black, point_f(10, 70));
}
}

§ point() [4/4]

xtd::drawing::point::point ( const size sz)

Initializes a new instance of the point class from a size.

Parameters
szA size that specifies the coordinates for the new point.
Examples
The following code example demonstrates how to use the Equality operator and how to construct a point from a size or two integers. It also demonstrates how to use the x and y properties. This example is designed to be used with Windows Forms (xtd.forms). Paste the code into a form that contains a button named button1, and associate the button1_click method with the button's click event.
void button1_Click(const control& sender, const event_args& e) {
// Construct a new point with integers.
point point1(100, 100);
// Create a Graphics object.
graphics form_graphics = this->create_graphics();
// Construct another point, this time using a Size.
point point2(size(100, 100));
// Call the equality operator to see if the points are equal, and if so print out their x and y values.
if (point1 == point2) {
form_graphics.draw_string(strings::format("point1.x: {}, point2.x: {}, point1.y: {}, point2.y {}", point1.x(), point2.x(), point1.y(), point2.y()), this->font(), brushes::black, point_f(10, 70));
}
}

Member Function Documentation

§ add()

static point xtd::drawing::point::add ( const point pt,
const size sz 
)
static

Adds the specified size to the specified point.

Parameters
ptThe point to add.
szThe size to add.
Returns
The point that is the result of the addition operation.
Remarks
The add adds the width and height of the specified size to the y and y values of the specified point.
Examples
The following example shows how to use the add method. To run this example, paste it into a Windows Form (xtd::formsà. Handle the form's paint event and call the add_point method from the paint event-handling method, passing e as paint_event_args.
void add_point(paint_event_args& e) {
point point1(10, 10);
point point2 = point::add(point1, drawing::size(250,0));
e.graphics().draw_line(pens::red, point1, point2);
}

§ ceiling()

static point xtd::drawing::point::ceiling ( const point_f value)
static

Converts the specified point_f to a point by rounding the values of the point_f to the next higher integer values.

Parameters
valueThe point_f to convert.
Returns
The point this method converts to.

§ is_empty()

bool xtd::drawing::point::is_empty ( ) const
inline

Gets a value indicating whether this point is empty.

Returns
true if both X and Y are 0; otherwise, false.

§ offset() [1/2]

void xtd::drawing::point::offset ( int  dx,
int  dy 
)
inline

Translates this point by the specified amount.

Parameters
dxThe amount to offset the x-coordinate.
dyThe amount to offset the y-coordinate.

§ offset() [2/2]

void xtd::drawing::point::offset ( const point p)
inline

Translates this point by the specified point.

Parameters
pThe point used offset this point.
Remarks
This method adjusts the x and y values of this point to the sum of the x and y values of this point and p.
Examples
The following example shows how to use the Offset method. To run this example, paste it into a Windows Form. Handle the form's Paint event and call the Offsetpoint method from the Paint event-handling method, passing e as PaintEventArgs.
void offset_point(paint_event_args& e) {
point point1(10, 10);
point1.offset(50, 0);
point point2(250, 10);
e.eraphics().draw_line(pens::red, point1, point2);
}

§ round()

static point xtd::drawing::point::round ( const point_f value)
static

Converts the specified point_f to a point object by rounding the point_f values to the nearest integer.

Parameters
valueThe point_f to convert.
Returns
The point this method converts to.

§ subtract()

static point xtd::drawing::point::subtract ( const point pt,
const size sz 
)
static

Returns the result of subtracting specified Size from the specified point.

Parameters
ptThe point to be subtracted from.
szThe size to subtract from the point.
Returns
The point that is the result of the subtraction operation.
Remarks
The subtract subtracts the width and height of the specified size from the x and y values of the specified point.

§ to_string()

std::string xtd::drawing::point::to_string ( ) const
inline

Converts this point to a human-readable string.

Returns
A string that represents this point.

§ truncate()

static point xtd::drawing::point::truncate ( const point_f value)
static

Converts the specified point_f to a point by truncating the values of the point_f.

Parameters
valueThe point_f to convert.
Returns
The point this method converts to.

§ x() [1/2]

int32_t xtd::drawing::point::x ( ) const
inline

Gets the x-coordinate of this point.

Returns
The x-coordinate of this point.
Examples
The following code example demonstrates how to use the Equality operator and how to construct a point from a size or two integers. It also demonstrates how to use the x and y properties. This example is designed to be used with Windows Forms (xtd.forms). Paste the code into a form that contains a button named button1, and associate the button1_click method with the button's click event.
void button1_Click(const control& sender, const event_args& e) {
// Construct a new point with integers.
point point1(100, 100);
// Create a Graphics object.
graphics form_graphics = this->create_graphics();
// Construct another point, this time using a Size.
point point2(size(100, 100));
// Call the equality operator to see if the points are equal, and if so print out their x and y values.
if (point1 == point2) {
form_graphics.draw_string(strings::format("point1.x: {}, point2.x: {}, point1.y: {}, point2.y {}", point1.x(), point2.x(), point1.y(), point2.y()), this->font(), brushes::black, point_f(10, 70));
}
}

§ x() [2/2]

void xtd::drawing::point::x ( int32_t  x)
inline

Sets the x-coordinate of this point.

Parameters
xThe x-coordinate of this point.
Examples
The following code example demonstrates how to use the Equality operator and how to construct a point from a size or two integers. It also demonstrates how to use the x and y properties. This example is designed to be used with Windows Forms (xtd.forms). Paste the code into a form that contains a button named button1, and associate the button1_click method with the button's click event.
void button1_Click(const control& sender, const event_args& e) {
// Construct a new point with integers.
point point1(100, 100);
// Create a Graphics object.
graphics form_graphics = this->create_graphics();
// Construct another point, this time using a Size.
point point2(size(100, 100));
// Call the equality operator to see if the points are equal, and if so print out their x and y values.
if (point1 == point2) {
form_graphics.draw_string(strings::format("point1.x: {}, point2.x: {}, point1.y: {}, point2.y {}", point1.x(), point2.x(), point1.y(), point2.y()), this->font(), brushes::black, point_f(10, 70));
}
}

§ y() [1/2]

int32_t xtd::drawing::point::y ( ) const
inline

Gets the y-coordinate of this point.

Returns
The y-coordinate of this point.
Examples
The following code example demonstrates how to use the Equality operator and how to construct a point from a size or two integers. It also demonstrates how to use the x and y properties. This example is designed to be used with Windows Forms (xtd.forms). Paste the code into a form that contains a button named button1, and associate the button1_click method with the button's click event.
void button1_Click(const control& sender, const event_args& e) {
// Construct a new point with integers.
point point1(100, 100);
// Create a Graphics object.
graphics form_graphics = this->create_graphics();
// Construct another point, this time using a Size.
point point2(size(100, 100));
// Call the equality operator to see if the points are equal, and if so print out their x and y values.
if (point1 == point2) {
form_graphics.draw_string(strings::format("point1.x: {}, point2.x: {}, point1.y: {}, point2.y {}", point1.x(), point2.x(), point1.y(), point2.y()), this->font(), brushes::black, point_f(10, 70));
}
}

§ y() [2/2]

void xtd::drawing::point::y ( int32_t  y)
inline

Sets the y-coordinate of this point.

Parameters
yThe x-coordinate of this point.
Examples
The following code example demonstrates how to use the Equality operator and how to construct a point from a size or two integers. It also demonstrates how to use the x and y properties. This example is designed to be used with Windows Forms (xtd.forms). Paste the code into a form that contains a button named button1, and associate the button1_click method with the button's click event.
void button1_Click(const control& sender, const event_args& e) {
// Construct a new point with integers.
point point1(100, 100);
// Create a Graphics object.
graphics form_graphics = this->create_graphics();
// Construct another point, this time using a Size.
point point2(size(100, 100));
// Call the equality operator to see if the points are equal, and if so print out their x and y values.
if (point1 == point2) {
form_graphics.draw_string(strings::format("point1.x: {}, point2.x: {}, point1.y: {}, point2.y {}", point1.x(), point2.x(), point1.y(), point2.y()), this->font(), brushes::black, point_f(10, 70));
}
}

Member Data Documentation

§ empty

const point xtd::drawing::point::empty
static

Represents a point that has x and y values set to zero.


The documentation for this class was generated from the following file: