OpenEnroth 4aaa0a0
Loading...
Searching...
No Matches
Functions
ItemGrid.h File Reference
#include "Library/Geometry/Point.h"
#include "Engine/Objects/Item.h"

Functions

int itemOffset (int dimension)
 Calculate offsets for placing items in inventory grid. More...
 
Pointi mapToInventoryGrid (Pointi mousePos, Pointi inventoryTopLeft, Item *heldItem=nullptr)
 
Pointi mapFromInventoryGrid (Pointi gridPos, Pointi inventoryTopLeft)
 

Function Documentation

◆ itemOffset()

int itemOffset ( int  dimension)

Calculate offsets for placing items in inventory grid.

Inventory grid have 32x32 pixels cells. Items don't exactly fit into the grid, but are slightly smaller or larger. The function calculates offsets for the item to be centered. Calculations are the same for height and width.

Parameters
dimensionWidth or height of the item.
Returns
Offset in pixels.

◆ mapFromInventoryGrid()

Pointi mapFromInventoryGrid ( Pointi  gridPos,
Pointi  inventoryTopLeft 
)

◆ mapToInventoryGrid()

Pointi mapToInventoryGrid ( Pointi  mousePos,
Pointi  inventoryTopLeft,
Item heldItem = nullptr 
)
Parameters
mousePosMouse position.
inventoryTopLeftTop left position of the inventory grid.
heldItemThe Item the player is holding (if exists). If there is an item here, the mouse position is adjusted to snap to the center of the grid cell rather than the edge. If not, ItemId = ITEM_NULL, then the mouse position will not be adjusted for items.
Returns
Inventory grid position, in grid coordinates. Might be out of grid if the mouse position is out of grid.