OpenMiner/source/gui/ItemWidget.cpp

40 lines
994 B
C++
Raw Normal View History

/*
* =====================================================================================
*
* Filename: ItemWidget.cpp
*
* Description:
*
* Created: 21/06/2018 01:11:11
*
* Author: Quentin Bazin, <quent42340@gmail.com>
*
* =====================================================================================
*/
#include "ItemWidget.hpp"
ItemWidget::ItemWidget(Inventory &inventory, u16 x, u16 y, Widget *parent)
: Widget(16, 16, parent), m_inventory(inventory), m_x(x), m_y(y)
{
m_image.load("texture-blocks");
m_image.setScale(2.0f / 3.0f, 2.0f / 3.0f, 1.0f);
m_image.setPosition(3, 3, 0);
m_image.setClipRect(0, 0, 0, 0);
}
void ItemWidget::update() {
2018-06-23 03:50:02 +02:00
m_image.setClipRect(item() * 16, item() / 16 * 16, 16, 16);
}
2018-06-23 00:34:02 +02:00
void ItemWidget::setItem(unsigned int id) {
2018-06-24 01:42:06 +02:00
m_inventory.setStack(m_x, m_y, id);
update();
}
void ItemWidget::draw(RenderTarget &target, RenderStates states) const {
applyTransform(states);
target.draw(m_image, states);
}