+ if (m_screensize != porting::getWindowSize()) {
+ m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE * porting::getDisplayDensity() + 0.5);
+ m_hotbar_imagesize *= m_hud_scaling;
+ m_padding = m_hotbar_imagesize / 12;
+ m_screensize = porting::getWindowSize();
+ m_displaycenter = v2s32(m_screensize.X/2,m_screensize.Y/2);
+ }
+}
+
+struct MeshTimeInfo {
+ u64 time;
+ scene::IMesh *mesh;
+};
+
+void drawItemStack(video::IVideoDriver *driver,
+ gui::IGUIFont *font,
+ const ItemStack &item,
+ const core::rect<s32> &rect,
+ const core::rect<s32> *clip,
+ Client *client,
+ ItemRotationKind rotation_kind)
+{
+ static MeshTimeInfo rotation_time_infos[IT_ROT_NONE];
+ static bool enable_animations =
+ g_settings->getBool("inventory_items_animations");
+
+ if (item.empty()) {
+ if (rotation_kind < IT_ROT_NONE) {
+ rotation_time_infos[rotation_kind].mesh = NULL;
+ }
+ return;
+ }
+
+ const ItemDefinition &def = item.getDefinition(client->idef());
+ ItemMesh *imesh = client->idef()->getWieldMesh(def.name, client);
+
+ if (imesh && imesh->mesh) {
+ scene::IMesh *mesh = imesh->mesh;
+ driver->clearZBuffer();
+ s32 delta = 0;
+ if (rotation_kind < IT_ROT_NONE) {
+ MeshTimeInfo &ti = rotation_time_infos[rotation_kind];
+ if (mesh != ti.mesh) {
+ ti.mesh = mesh;
+ ti.time = porting::getTimeMs();
+ } else {
+ delta = porting::getDeltaMs(ti.time, porting::getTimeMs()) % 100000;
+ }
+ }
+ core::rect<s32> oldViewPort = driver->getViewPort();
+ core::matrix4 oldProjMat = driver->getTransform(video::ETS_PROJECTION);
+ core::matrix4 oldViewMat = driver->getTransform(video::ETS_VIEW);
+ core::matrix4 ProjMatrix;
+ ProjMatrix.buildProjectionMatrixOrthoLH(2, 2, -1, 100);
+ driver->setTransform(video::ETS_PROJECTION, ProjMatrix);
+ driver->setTransform(video::ETS_VIEW, ProjMatrix);
+ core::matrix4 matrix;
+ matrix.makeIdentity();
+
+ if (enable_animations) {
+ float timer_f = (float) delta / 5000.0;
+ matrix.setRotationDegrees(core::vector3df(0, 360 * timer_f, 0));
+ }
+
+ driver->setTransform(video::ETS_WORLD, matrix);
+ driver->setViewPort(rect);
+
+ video::SColor basecolor =
+ client->idef()->getItemstackColor(item, client);
+
+ u32 mc = mesh->getMeshBufferCount();
+ for (u32 j = 0; j < mc; ++j) {
+ scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
+ // we can modify vertices relatively fast,
+ // because these meshes are not buffered.
+ assert(buf->getHardwareMappingHint_Vertex() == scene::EHM_NEVER);
+ video::SColor c = basecolor;
+ if (imesh->buffer_colors.size() > j) {
+ ItemPartColor *p = &imesh->buffer_colors[j];
+ if (p->override_base)
+ c = p->color;
+ }
+ colorizeMeshBuffer(buf, &c);
+ video::SMaterial &material = buf->getMaterial();
+ material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+ material.Lighting = false;
+ driver->setMaterial(material);
+ driver->drawMeshBuffer(buf);
+ }
+
+ driver->setTransform(video::ETS_VIEW, oldViewMat);
+ driver->setTransform(video::ETS_PROJECTION, oldProjMat);
+ driver->setViewPort(oldViewPort);
+ }
+
+ if(def.type == ITEM_TOOL && item.wear != 0)
+ {
+ // Draw a progressbar
+ float barheight = rect.getHeight()/16;
+ float barpad_x = rect.getWidth()/16;
+ float barpad_y = rect.getHeight()/16;
+ core::rect<s32> progressrect(
+ rect.UpperLeftCorner.X + barpad_x,
+ rect.LowerRightCorner.Y - barpad_y - barheight,
+ rect.LowerRightCorner.X - barpad_x,
+ rect.LowerRightCorner.Y - barpad_y);
+
+ // Shrink progressrect by amount of tool damage
+ float wear = item.wear / 65535.0;
+ int progressmid =
+ wear * progressrect.UpperLeftCorner.X +
+ (1-wear) * progressrect.LowerRightCorner.X;
+
+ // Compute progressbar color
+ // wear = 0.0: green
+ // wear = 0.5: yellow
+ // wear = 1.0: red
+ video::SColor color(255,255,255,255);
+ int wear_i = MYMIN(floor(wear * 600), 511);
+ wear_i = MYMIN(wear_i + 10, 511);
+ if(wear_i <= 255)
+ color.set(255, wear_i, 255, 0);
+ else
+ color.set(255, 255, 511-wear_i, 0);
+
+ core::rect<s32> progressrect2 = progressrect;
+ progressrect2.LowerRightCorner.X = progressmid;
+ driver->draw2DRectangle(color, progressrect2, clip);
+
+ color = video::SColor(255,0,0,0);
+ progressrect2 = progressrect;
+ progressrect2.UpperLeftCorner.X = progressmid;
+ driver->draw2DRectangle(color, progressrect2, clip);
+ }
+
+ if(font != NULL && item.count >= 2)
+ {
+ // Get the item count as a string
+ std::string text = itos(item.count);
+ v2u32 dim = font->getDimension(utf8_to_wide(text).c_str());
+ v2s32 sdim(dim.X,dim.Y);
+
+ core::rect<s32> rect2(
+ /*rect.UpperLeftCorner,
+ core::dimension2d<u32>(rect.getWidth(), 15)*/
+ rect.LowerRightCorner - sdim,
+ sdim
+ );
+
+ video::SColor bgcolor(128,0,0,0);
+ driver->draw2DRectangle(bgcolor, rect2, clip);
+
+ video::SColor color(255,255,255,255);
+ font->draw(text.c_str(), rect2, color, false, false, clip);
+ }