| Version: 3.3.1

Public Member Functions | List of all members
wxSize Class Reference
Class List by Category » Data Structures

`#include <wx/gdicmn.h>`

## Detailed Description

A wxSize is a useful data structure for graphics operations.

It simply contains integer x and y members.

Note that the width and height stored inside a wxSize object may be negative and that wxSize functions do not perform any check against negative values (this is used to e.g. store the special -1 value in wxDefaultSize instance). See also IsFullySpecified() and SetDefaults() for utility functions regarding the special -1 value.

wxSize is used throughout wxWidgets as well as wxPoint which, although almost equivalent to wxSize, has a different meaning: wxPoint represents a position while wxSize represents the size.

##

Library: wxCore
Category: Data Structures

Predefined objects/pointers: wxDefaultSize

See also
  wxPoint, wxRealPoint

## Miscellaneous operators
Sizes can be added to or subtracted from each other or divided or multiplied by a number. Note that binary operators are defined as friend functions inside this class, making them accessible via argument-dependent lookup, but hidden otherwise. Also note that using `double` factor may result in rounding errors, as wxSize always stores `int` coordinates and the result is always rounded.
wxSize & | operator= (const wxSize &sz)
wxSize & | operator+= (const wxSize &sz)
wxSize & | operator-= (const wxSize &sz)
wxSize & | operator/= (int factor)
wxSize & | operator/= (double factor)
wxSize & | operator*= (int factor)
wxSize & | operator*= (double factor)
bool | operator== (const wxSize &s1, const wxSize &s2)
bool | operator!= (const wxSize &s1, const wxSize &s2)
wxSize | operator+ (const wxSize &s1, const wxSize &s2)
wxSize | operator- (const wxSize &s1, const wxSize &s2)
wxSize | operator/ (const wxSize &sz, int factor)
wxSize | operator/ (const wxSize &sz, double factor)
wxSize | operator* (const wxSize &sz, int factor)
wxSize | operator* (const wxSize &sz, double factor)
wxSize | operator* (int factor, const wxSize &sz)
wxSize | operator* (double factor, const wxSize &sz)

## Public Member Functions
| wxSize ()
| Initializes this size object with zero width and height. More...
| wxSize (int width, int height)
| Initializes this size object with the given width and height. More...
void | DecTo (const wxSize &size)
| Decrements this object so that both of its dimensions are not greater than the corresponding dimensions of the size. More...
void | DecToIfSpecified (const wxSize &size)
| Decrements this object to be not bigger than the given size ignoring non-specified components. More...
int | GetHeight () const
| Gets the height member. More...
int | GetWidth () const
| Gets the width member. More...
void | IncTo (const wxSize &size)
| Increments this object so that both of its dimensions are not less than the corresponding dimensions of the size. More...
bool | IsAtLeast (const wxSize &size) const
| Returns true if this size is at least as big as the other one in both directions. More...
bool | IsEmpty () const
| Returns true if either of the size object components is 0 or -1/. More...
bool | IsFullySpecified () const
| Returns true if neither of the size object components is equal to -1, which is used as default for the size values in wxWidgets (hence the predefined wxDefaultSize has both of its components equal to -1). More...
wxSize & | Scale (double xscale, double yscale)
| Scales the dimensions of this object by the given factors. More...
void | Set (int width, int height)
| Sets the width and height members. More...
void | SetDefaults (const wxSize &sizeDefault)
| Combine this size object with another one replacing the default (i.e. equal to -1) components of this object with those of the other. More...
void | SetHeight (int height)
| Sets the height. More...
void | SetWidth (int width)
| Sets the width. More...
void | DecBy (const wxPoint &pt)
| Decreases the size in both x and y directions. More...
void | DecBy (const wxSize &size)
| Decreases the size in both x and y directions. More...
void | DecBy (int dx, int dy)
| Decreases the size in both x and y directions. More...
void | DecBy (int d)
| Decreases the size in both x and y directions. More...
void | IncBy (const wxPoint &pt)
| Increases the size in both x and y directions. More...
void | IncBy (const wxSize &size)
| Increases the size in both x and y directions. More...
void | IncBy (int dx, int dy)
| Increases the size in both x and y directions. More...
void | IncBy (int d)
| Increases the size in both x and y directions. More...

## Constructor & Destructor Documentation

## ◆ wxSize() [1/2]

wxSize::wxSize | ( |  | ) |

Initializes this size object with zero width and height.

## ◆ wxSize() [2/2]

wxSize::wxSize | ( | int | width,
|  | int | height
| ) |  |

Initializes this size object with the given width and height.

## Member Function Documentation

## ◆ DecBy() [1/4]

void wxSize::DecBy | ( | const wxPoint & | pt | ) |

Decreases the size in both x and y directions.

See also
  IncBy()

## ◆ DecBy() [2/4]

void wxSize::DecBy | ( | const wxSize & | size | ) |

Decreases the size in both x and y directions.

See also
  IncBy()

## ◆ DecBy() [3/4]

void wxSize::DecBy | ( | int | d | ) |

Decreases the size in both x and y directions.

See also
  IncBy()

## ◆ DecBy() [4/4]

void wxSize::DecBy | ( | int | dx,
|  | int | dy
| ) |  |

Decreases the size in both x and y directions.

See also
  IncBy()

## ◆ DecTo()

void wxSize::DecTo | ( | const wxSize & | size | ) |

Decrements this object so that both of its dimensions are not greater than the corresponding dimensions of the size.

See also
  IncTo()

## ◆ DecToIfSpecified()

void wxSize::DecToIfSpecified | ( | const wxSize & | size | ) |

Decrements this object to be not bigger than the given size ignoring non-specified components.

This is similar to DecTo() but doesn't do anything for x or y component if the same component of size is not specified, i.e. set to wxDefaultCoord.

Since
  2.9.5

## ◆ GetHeight()

int wxSize::GetHeight | ( |  | ) | const

Gets the height member.

## ◆ GetWidth()

int wxSize::GetWidth | ( |  | ) | const

Gets the width member.

## ◆ IncBy() [1/4]

void wxSize::IncBy | ( | const wxPoint & | pt | ) |

Increases the size in both x and y directions.

See also
  DecBy()

## ◆ IncBy() [2/4]

void wxSize::IncBy | ( | const wxSize & | size | ) |

Increases the size in both x and y directions.

See also
  DecBy()

## ◆ IncBy() [3/4]

void wxSize::IncBy | ( | int | d | ) |

Increases the size in both x and y directions.

See also
  DecBy()

## ◆ IncBy() [4/4]

void wxSize::IncBy | ( | int | dx,
|  | int | dy
| ) |  |

Increases the size in both x and y directions.

See also
  DecBy()

## ◆ IncTo()

void wxSize::IncTo | ( | const wxSize & | size | ) |

Increments this object so that both of its dimensions are not less than the corresponding dimensions of the size.

See also
  DecTo()

## ◆ IsAtLeast()

bool wxSize::IsAtLeast | ( | const wxSize & | size | ) | const

Returns true if this size is at least as big as the other one in both directions.

Since
  3.3.0

## ◆ IsEmpty()

bool wxSize::IsEmpty | ( |  | ) | const

Returns true if either of the size object components is 0 or -1/.

Empty wxSize objects don't define a valid size in the geometric sense.

See also
  wxRect::IsEmpty()

Since
  3.3.1

## ◆ IsFullySpecified()

bool wxSize::IsFullySpecified | ( |  | ) | const

Returns true if neither of the size object components is equal to -1, which is used as default for the size values in wxWidgets (hence the predefined wxDefaultSize has both of its components equal to -1).

This method is typically used before calling SetDefaults().

## ◆ operator*=() [1/2]

wxSize& wxSize::operator*= | ( | double | factor | ) |

## ◆ operator*=() [2/2]

wxSize& wxSize::operator*= | ( | int | factor | ) |

## ◆ operator+=()

wxSize& wxSize::operator+= | ( | const wxSize & | sz | ) |

## ◆ operator-=()

wxSize& wxSize::operator-= | ( | const wxSize & | sz | ) |

## ◆ operator/=() [1/2]

wxSize& wxSize::operator/= | ( | double | factor | ) |

## ◆ operator/=() [2/2]

wxSize& wxSize::operator/= | ( | int | factor | ) |

## ◆ operator=()

wxSize& wxSize::operator= | ( | const wxSize & | sz | ) |

## ◆ Scale()

wxSize& wxSize::Scale | ( | double | xscale,
|  | double | yscale
| ) |  |

Scales the dimensions of this object by the given factors.

If you want to scale both dimensions by the same factor you can also use operator*=().

Returns
  A reference to this object (so that you can concatenate other operations in the same line).

## ◆ Set()

void wxSize::Set | ( | int | width,
|  | int | height
| ) |  |

Sets the width and height members.

## ◆ SetDefaults()

void wxSize::SetDefaults | ( | const wxSize & | sizeDefault | ) |

Combine this size object with another one replacing the default (i.e. equal to -1) components of this object with those of the other.

It is typically used like this:

if ( !size.IsFullySpecified() )
{
size.SetDefaults(GetDefaultSize());
}

See also
  IsFullySpecified()

## ◆ SetHeight()

void wxSize::SetHeight | ( | int | height | ) |

Sets the height.

## ◆ SetWidth()

void wxSize::SetWidth | ( | int | width | ) |

Sets the width.

## Friends And Related Function Documentation

## ◆ operator!=

bool operator!= | ( | const wxSize & | s1,
|  | const wxSize & | s2
| ) |  |
| friend

## ◆ operator* [1/4]

wxSize operator* | ( | const wxSize & | sz,
|  | double | factor
| ) |  |
| friend

## ◆ operator* [2/4]

wxSize operator* | ( | const wxSize & | sz,
|  | int | factor
| ) |  |
| friend

## ◆ operator* [3/4]

wxSize operator* | ( | double | factor,
|  | const wxSize & | sz
| ) |  |
| friend

## ◆ operator* [4/4]

wxSize operator* | ( | int | factor,
|  | const wxSize & | sz
| ) |  |
| friend

## ◆ operator+

wxSize operator+ | ( | const wxSize & | s1,
|  | const wxSize & | s2
| ) |  |
| friend

## ◆ operator-

wxSize operator- | ( | const wxSize & | s1,
|  | const wxSize & | s2
| ) |  |
| friend

## ◆ operator/ [1/2]

wxSize operator/ | ( | const wxSize & | sz,
|  | double | factor
| ) |  |
| friend

## ◆ operator/ [2/2]

wxSize operator/ | ( | const wxSize & | sz,
|  | int | factor
| ) |  |
| friend

## ◆ operator==

bool operator== | ( | const wxSize & | s1,
|  | const wxSize & | s2
| ) |  |
| friend