QcSpriteShape Class
The opaque texels of an item sprite (decisions E-831, E-991): a held or dropped item is drawn as its sprite with sides one texel thick around these texels, and the hand grips it where they say. More...
| Header: | #include <clientcore/entitymeshes/QcSpriteShape.h> |
Public Types
| struct | FormCorner |
| struct | FormQuad |
| struct | Side |
| enum class | Facing { Left, Right, Up, Down } |
Public Functions
| QcSpriteShape() | |
| QRect | bounds() const |
| QPointF | centroid() const |
| const QList<QcSpriteShape::FormQuad> & | form() const |
| QPoint | handle() const |
| QPointF | handlePoint() const |
| bool | isEmpty() const |
| bool | opaque(int x, int y) const |
| const QList<QcSpriteShape::Side> & | sides() const |
| int | size() const |
| double | texelsPerBase() const |
Static Public Members
| const int | baseTexels |
| QcSpriteShape | fromImage(const QImage &tile) |
| QcSpriteShape | fromRows(const QStringList &rows) |
| const int | minOpaqueAlpha |
Detailed Description
Texel x runs from the left, y from the top, as in the image.
Member Type Documentation
enum class QcSpriteShape::Facing
The side of an opaque texel next to a clear one (or the outside), seen from the texel.
| Constant | Value | Description |
|---|---|---|
QcSpriteShape::Facing::Left | 0 | Towards smaller x |
QcSpriteShape::Facing::Right | 1 | Towards larger x |
QcSpriteShape::Facing::Up | 2 | Towards the top of the image |
QcSpriteShape::Facing::Down | 3 | Towards the bottom of the image |
Member Function Documentation
[constexpr noexcept default] QcSpriteShape::QcSpriteShape()
Default-constructs an instance of QcSpriteShape.
QRect QcSpriteShape::bounds() const
Returns the smallest rectangle around the opaque texels.
QPointF QcSpriteShape::centroid() const
Returns the middle of the opaque texels (their mean centre), in texels; (0, 0) when empty.
const QList<QcSpriteShape::FormQuad> &QcSpriteShape::form() const
Returns the sprite as a solid one base texel thick (one texel in smaller sprites): its front and back as whole quads (clear texels fall to the alpha test), then one quad on every straight run of sides, stretched along the middle of the run's texels so that each texel's side keeps that texel's colour. Found once per shape: held and dropped items only place these corners (decision E-991).
[static] QcSpriteShape QcSpriteShape::fromImage(const QImage &tile)
Returns the shape of tile: texels with at least minOpaqueAlpha are opaque; a tile that is not square is empty.
[static] QcSpriteShape QcSpriteShape::fromRows(const QStringList &rows)
Returns the shape of rows: '#' opaque and anything else clear, all as long as there are rows (tests).
QPoint QcSpriteShape::handle() const
Returns the texel a fist holds a tool by: from the end of the handle up along opaque texels, up and to the right first, to the lowest row of the base texel two base texels above the one the end lies in. The end is the lowest opaque texel (the leftmost of its row, a handle drawn from the lower left); when a pommel sits there instead (a row among the lowest three base texels whose leftmost run is at least two base texels wide and half a base texel wider than the handle line above them), it is the right end of the pommel's top row, so the pommel counts as the handle's last base texel (decision E-991). The end of the handle stays below the fist. (0, 0) when empty.
QPointF QcSpriteShape::handlePoint() const
Returns the point a fist holds a tool by, in texels: across the middle of handle(), up the middle of the base texel whose lowest row handle() is in, so the fist sits as high on the handle in every resolution. (0, 0) when empty.
bool QcSpriteShape::isEmpty() const
Returns whether the shape has no opaque texel.
bool QcSpriteShape::opaque(int x, int y) const
Returns whether texel (x, y) is opaque; false outside the shape.
const QList<QcSpriteShape::Side> &QcSpriteShape::sides() const
Returns every edge between an opaque texel and a clear one, row by row, found once per shape; form() joins each straight run of them into one quad.
int QcSpriteShape::size() const
Returns the texels along each edge.
double QcSpriteShape::texelsPerBase() const
Returns how many texels of this shape make one base texel (baseTexels across the sprite): 1 in sprites of baseTexels or fewer.
Member Variable Documentation
const int QcSpriteShape::baseTexels
Texels along an edge of the game's own sprites: a texel of this size is how thick a solid sprite is and how far a fist climbs a handle, in sprites of every resolution.
const int QcSpriteShape::minOpaqueAlpha
A texel's alpha (0..255) from which it counts as opaque: the alpha test of entity.frag discards below 0.1, so every texel the GPU draws gets sides.