scistag.imagestag.anchor2d.Anchor2D

class Anchor2D(value)[source]

Bases: IntEnum

Defines how an origin (such as a position) is interpreted when a shape such as a rectangle, a circle or a multi-line text is painted just given a position and a size is painted.

Methods

get_position_shift

Gets the anchor caused position shifting at given object size

shift_position

Adjusts the position by the amount of pixels this anchor will shift the painting origin of the position caused through this anchor.

Attributes

TOP_LEFT

The origin is the shape's top left edge - everything is painted to the right and bottom of it.

TOP

The origin is the shape's top center edge - everything is painted equally to the left and right of it and to the bottom.

TOP_RIGHT

The origin is the shape's top right edge - everything is painted to the left and the bottom of it.

CENTER_LEFT

The origin is the shape's center left edge - everything is painted equally to the top and bottom of it and to the right.

CENTER

The origin is the shape's center - everything is painted equally to the left, right, top and bottom of it.

CENTER_RIGHT

The origin is the shape's center right - everything is painted equally to the top and bottom of it to the right.

BOTTOM_LEFT

The origin is the shape's bottom left - everything is painted to the right and to the top of it.

BOTTOM

The origin is the shape's bottom center - everything is painted equally to the left and right of it to the top.

BOTTOM_RIGHT

The origin is the shape's bottom right - everything is painted to the left and top of it.

__doc__

__members__

__module__

classmethod _missing_(value)[source]

Initializes an anchor using a string

Parameters

value (Anchor2D | str) – The integer enum value or an alternative string shortcode representation. Valid values are: - “tl” / “topLeft” - TOP_LEFT - “t” /”top” - TOP (center) - “tr” / “topRight” - TOP_RIGHT - “cl” / “centerLeft” - CENTER_LEFT - “c” / “center” - CENTER (horizontally and vertically) - “cr” / “centerRight” - CENTER_RIGHT - “bl” / “bottomLeft” - BOTTOM_LEFT - “b” / “bottom” - BOTTOM (center) - “br” / “bottomRight” - BOTTOM_RIGHT

Returns

The Anchor2D enum value

get_position_shift(size)[source]

Gets the anchor caused position shifting at given object size

E.g. a LEFT_TOP anchor will never modify the position at all, a CENTER anchor will be the position by half of size.width to the left and half of size.height to the right etc. so the painted object will be centered around the (original) pos effectively when being painted at the now (modified) pos.

Parameters

size (Union[tuple[float, float], Size2D]) – The object’s size (circle, rectangle, image etc.)

Return type

tuple[float, float]

Returns

The amount of pixels by which the output shall be shifted, to be added to the original position

shift_position(pos, size, round_shift=False)[source]

Adjusts the position by the amount of pixels this anchor will shift the painting origin of the position caused through this anchor.

E.g. a LEFT_TOP anchor will never modify the position at all, a CENTER anchor will be the position by half of size.width to the left and half of size.height to the right etc. so the painted object will be centered around the (original) pos effectively when being painted at the now (modified) pos.

Parameters
  • pos (Pos2D) – The position to modify. (this object will be modified)

  • size (Size2D) – The size of the object to be drawn

  • round_shift (bool) – If defined the shifting will be rounded

Return type

Pos2D

Returns

The modified position

BOTTOM = 7

The origin is the shape’s bottom center - everything is painted equally to the left and right of it to the top.

BOTTOM_LEFT = 6

The origin is the shape’s bottom left - everything is painted to the right and to the top of it.

BOTTOM_RIGHT = 8

The origin is the shape’s bottom right - everything is painted to the left and top of it.

CENTER = 4

The origin is the shape’s center - everything is painted equally to the left, right, top and bottom of it.

CENTER_LEFT = 3

The origin is the shape’s center left edge - everything is painted equally to the top and bottom of it and to the right.

CENTER_RIGHT = 5

The origin is the shape’s center right - everything is painted equally to the top and bottom of it to the right.

TOP = 1

The origin is the shape’s top center edge - everything is painted equally to the left and right of it and to the bottom.

TOP_LEFT = 0

The origin is the shape’s top left edge - everything is painted to the right and bottom of it.

TOP_RIGHT = 2

The origin is the shape’s top right edge - everything is painted to the left and the bottom of it.