void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count, v2s32 offset) { const video::SColor color(255, 255, 255, 255); const video::SColor colors[] = {color, color, color, color}; video::ITexture *stat_texture = tsrc->getTexture(texture); if (!stat_texture) return; core::dimension2di srcd(stat_texture->getOriginalSize()); v2s32 p = pos; if (corner & HUD_CORNER_LOWER) p -= srcd.Height; p += offset; v2s32 steppos; switch (drawdir) { case HUD_DIR_RIGHT_LEFT: steppos = v2s32(-1, 0); break; case HUD_DIR_TOP_BOTTOM: steppos = v2s32(0, 1); break; case HUD_DIR_BOTTOM_TOP: steppos = v2s32(0, -1); break; default: steppos = v2s32(1, 0); } steppos.X *= srcd.Width; steppos.Y *= srcd.Height; for (s32 i = 0; i < count / 2; i++) { core::rect<s32> srcrect(0, 0, srcd.Width, srcd.Height); core::rect<s32> dstrect(srcrect); dstrect += p; driver->draw2DImage(stat_texture, dstrect, srcrect, NULL, colors, true); p += steppos; } if (count % 2 == 1) { core::rect<s32> srcrect(0, 0, srcd.Width / 2, srcd.Height); core::rect<s32> dstrect(srcrect); dstrect += p; driver->draw2DImage(stat_texture, dstrect, srcrect, NULL, colors, true); } }
void TileSet::DrawTile( unsigned short n, Surface *dest, short px, short py, const Rect &clip ) const { // set up destination Rect dstrect( px, py, TileWidth(), TileHeight() ); if ( dstrect.x + dstrect.w < clip.x ) return; if ( dstrect.y + dstrect.h < clip.y ) return; if ( dstrect.x >= clip.x + clip.w ) return; if ( dstrect.y >= clip.y + clip.h ) return; // set up source Rect srcrect; unsigned short gfx_per_line = tiles.Width() / TileWidth(); srcrect.x = (n % gfx_per_line) * TileWidth(); srcrect.y = (n / gfx_per_line) * TileHeight(); srcrect.w = dstrect.w; srcrect.h = dstrect.h; // clip and blit to surface dstrect.ClipBlit( srcrect, clip ); tiles.LowerBlit( dest, srcrect, dstrect.x, dstrect.y ); }
void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count, v2s32 offset, v2s32 size) { const video::SColor color(255, 255, 255, 255); const video::SColor colors[] = {color, color, color, color}; video::ITexture *stat_texture = tsrc->getTexture(texture); if (!stat_texture) return; core::dimension2di srcd(stat_texture->getOriginalSize()); core::dimension2di dstd; if (size == v2s32()) { dstd = srcd; } else { double size_factor = g_settings->getFloat("hud_scaling") * porting::getDisplayDensity(); dstd.Height = size.Y * size_factor; dstd.Width = size.X * size_factor; offset.X *= size_factor; offset.Y *= size_factor; } v2s32 p = pos; if (corner & HUD_CORNER_LOWER) p -= dstd.Height; p += offset; v2s32 steppos; switch (drawdir) { case HUD_DIR_RIGHT_LEFT: steppos = v2s32(-1, 0); break; case HUD_DIR_TOP_BOTTOM: steppos = v2s32(0, 1); break; case HUD_DIR_BOTTOM_TOP: steppos = v2s32(0, -1); break; default: steppos = v2s32(1, 0); } steppos.X *= dstd.Width; steppos.Y *= dstd.Height; for (s32 i = 0; i < count / 2; i++) { core::rect<s32> srcrect(0, 0, srcd.Width, srcd.Height); core::rect<s32> dstrect(0,0, dstd.Width, dstd.Height); dstrect += p; driver->draw2DImage(stat_texture, dstrect, srcrect, NULL, colors, true); p += steppos; } if (count % 2 == 1) { core::rect<s32> srcrect(0, 0, srcd.Width / 2, srcd.Height); core::rect<s32> dstrect(0,0, dstd.Width / 2, dstd.Height); dstrect += p; driver->draw2DImage(stat_texture, dstrect, srcrect, NULL, colors, true); } }
/////////////////////////////////////////////////////////// /// Draw /////////////////////////////////////////////////////////// void Window::Draw(long z) { if (!visible) return; if (width <= 0 || height <= 0) return; if (x < -width || x > Player::GetWidth() || y < -height || y > Player::GetHeight()) return; glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if (viewport != Qnil) { Rect rect = Viewport::Get(viewport)->GetViewportRect(); glEnable(GL_SCISSOR_TEST); glScissor(rect.x, Player::GetHeight() - (rect.y + rect.height), rect.width, rect.height); glTranslatef((float)rect.x, (float)rect.y, 0.0f); } glTranslatef((GLfloat)x, (GLfloat)y, 0.0f); if (windowskin != Qnil) { Bitmap* bmp = Bitmap::Get(windowskin); glPushMatrix(); bmp->Refresh(); bmp->BindBitmap(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); float bmpw = (float)bmp->GetWidth(); float bmph = (float)bmp->GetHeight(); float widthf = (float)width; float heightf = (float)height; // Background if (width > 4 && height > 4 && (back_opacity * opacity / 255 > 0)) { glColor4f(1.0f, 1.0f, 1.0f, (back_opacity * opacity / 255.0f) / 255.0f); if (stretch) { glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(2.0f, 2.0f); glTexCoord2f(128.0f / bmpw, 0.0f); glVertex2f(widthf - 4.0f, 2.0f); glTexCoord2f(128.0f / bmpw, 128.0f / bmph); glVertex2f(widthf - 4.0f, heightf - 4.0f); glTexCoord2f(0.0f, 128.0f / bmph); glVertex2f(2.0f, heightf - 4.0f); glEnd(); } else { glEnable(GL_SCISSOR_TEST); Rect dstrect(x + 2, y + 2, width - 4, height - 4); if (viewport != Qnil) { Rect rect = Viewport::Get(viewport)->GetViewportRect(); dstrect.x -= rect.x; dstrect.y -= rect.y; dstrect.Adjust(rect.width, rect.height); } //glScissor(x + 2, Player::GetHeight() - (y + 2 + height - 4), width - 4, height - 4); glScissor(dstrect.x, Player::GetHeight() - (dstrect.y + dstrect.height), dstrect.width, dstrect.height); float tilesx = ceil(widthf / 128.0f); float tilesy = ceil(heightf / 128.0f); for (float i = 0; i < tilesx; i++) { for (float j = 0; j < tilesy; j++) { glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(2.0f + i * 128.0f, 2.0f + j * 128.0f); glTexCoord2f(128.0f / bmpw, 0.0f); glVertex2f(2.0f + (i + 1) * 128.0f, 2.0f + j * 128.0f); glTexCoord2f(128.0f / bmpw, 128.0f / bmph); glVertex2f(2.0f + (i + 1) * 128.0f, 2.0f + (j + 1) * 128.0f); glTexCoord2f(0.0f, 128.0f / bmph); glVertex2f(2.0f + i * 128.0f, 2.0f + (j + 1) * 128.0f); glEnd(); } } if (viewport == Qnil) glDisable(GL_SCISSOR_TEST); } } // Frame if (width > 0 && height > 0 && opacity > 0) { glColor4f(1.0f, 1.0f, 1.0f, opacity / 255.0f); glBegin(GL_QUADS); // Corner upper left glTexCoord2f(128.0f / bmpw, 0.0f); glVertex2f(0.0f, 0.0f); glTexCoord2f(144.0f / bmpw, 0.0f); glVertex2f(16.0f, 0.0f); glTexCoord2f(144.0f / bmpw, 16.0f / bmph); glVertex2f(16.0f, 16.0f); glTexCoord2f(128.0f / bmpw, 16.0f / bmph); glVertex2f(0.0f, 16.0f); // Corner upper right glTexCoord2f(176.0f / bmpw, 0.0f); glVertex2f(widthf - 16.0f, 0.0f); glTexCoord2f(192.0f / bmpw, 0.0f); glVertex2f(widthf, 0.0f); glTexCoord2f(192.0f / bmpw, 16.0f / bmph); glVertex2f(widthf, 16.0f); glTexCoord2f(176.0f / bmpw, 16.0f / bmph); glVertex2f(widthf - 16.0f, 16.0f); // Corner lower right glTexCoord2f(176.0f / bmpw, 48.0f / bmph); glVertex2f(widthf - 16.0f, height - 16.0f); glTexCoord2f(192.0f / bmpw, 48.0f / bmph); glVertex2f(widthf, heightf - 16.0f); glTexCoord2f(192.0f / bmpw, 64.0f / bmph); glVertex2f(widthf, heightf); glTexCoord2f(176.0f / bmpw, 64.0f / bmph); glVertex2f(widthf - 16.0f, heightf); // Corner lower left glTexCoord2f(128.0f / bmpw, 48.0f / bmph); glVertex2f(0.0f, heightf - 16.0f); glTexCoord2f(144.0f / bmpw, 48.0f / bmph); glVertex2f(16.0f, heightf - 16.0f); glTexCoord2f(144.0f / bmpw, 64.0f / bmph); glVertex2f(16.0f, heightf); glTexCoord2f(128.0f / bmpw, 64.0f / bmph); glVertex2f(0.0f, heightf); // Border up glTexCoord2f(144.0f / bmpw, 0.0f); glVertex2f(16.0f, 0.0f); glTexCoord2f(176.0f / bmpw, 0.0f); glVertex2f(max(widthf - 16.0f, 1.0f), 0.0f); glTexCoord2f(176.0f / bmpw, 16.0f / bmph); glVertex2f(max(widthf - 16.0f, 1.0f), 16.0f); glTexCoord2f(144.0f / bmpw, 16.0f / bmph); glVertex2f(16.0f, 16.0f); // Border down glTexCoord2f(144.0f / bmpw, 48.0f / bmph); glVertex2f(16.0f, height - 16.0f); glTexCoord2f(176.0f / bmpw, 48.0f / bmph); glVertex2f(max(widthf - 16.0f, 1.0f), heightf - 16.0f); glTexCoord2f(176.0f / bmpw, 64.0f / bmph); glVertex2f(max(widthf - 16.0f, 1.0f), heightf); glTexCoord2f(144.0f / bmpw, 64.0f / bmph); glVertex2f(16.0f, heightf); // Border left glTexCoord2f(128.0f / bmpw, 16.0f / bmph); glVertex2f(0.0f, 16.0f); glTexCoord2f(144.0f / bmpw, 16.0f / bmph); glVertex2f(16.0f, 16.0f); glTexCoord2f(144.0f / bmpw, 48.0f / bmph); glVertex2f(16.0f, max(heightf - 16.0f, 1.0f)); glTexCoord2f(128.0f / bmpw, 48.0f / bmph); glVertex2f(0.0f, max(heightf - 16.0f, 1.0f)); // Border right glTexCoord2f(176.0f / bmpw, 16.0f / bmph); glVertex2f(widthf - 16.0f, 16.0f); glTexCoord2f(192.0f / bmpw, 16.0f / bmph); glVertex2f(widthf, 16.0f); glTexCoord2f(192.0f / bmpw, 48.0f / bmph); glVertex2f(widthf, max(heightf - 16.0f, 1.0f)); glTexCoord2f(176.0f / bmpw, 48.0f / bmph); glVertex2f(widthf - 16.0f, max(heightf - 16.0f, 1.0f)); glEnd(); } // Cursor if (width > 32 && height > 32) { Rect rect(cursor_rect); if (rect.width > 0 && rect.height > 0) { float cursor_opacity = 255.0f; if (cursor_frame <= 16) { cursor_opacity -= (92.0f / 16.0f) * cursor_frame; } else { cursor_opacity -= (92.0f / 16.0f) * (32 - cursor_frame); } glColor4f(1.0f, 1.0f, 1.0f, cursor_opacity / 255.0f); float left = (float)rect.x + 16; float top = (float)rect.y + 16; float rigth = left + rect.width; float bottom = top + rect.height; glBegin(GL_QUADS); // Background glTexCoord2f(130.0f / bmpw, 66.0f / bmph); glVertex2f(left + 2.0f, top + 2.0f); glTexCoord2f(158.0f / bmpw, 66.0f / bmph); glVertex2f(rigth - 2.0f, top + 2.0f); glTexCoord2f(158.0f / bmpw, 94.0f / bmph); glVertex2f(rigth - 2.0f, bottom - 2.0f); glTexCoord2f(130.0f / bmpw, 94.0f / bmph); glVertex2f(left + 2.0f, bottom - 2.0f); // Corner upper left glTexCoord2f(128.0f / bmpw, 64.0f / bmph); glVertex2f(left, top); glTexCoord2f(130.0f / bmpw, 64.0f / bmph); glVertex2f(left + 2.0f, top); glTexCoord2f(130.0f / bmpw, 66.0f / bmph); glVertex2f(left + 2.0f, top + 2.0f); glTexCoord2f(128.0f / bmpw, 66.0f / bmph); glVertex2f(left, top + 2.0f); // Corner upper right glTexCoord2f(158.0f / bmpw, 64.0f / bmph); glVertex2f(rigth - 2.0f, top); glTexCoord2f(160.0f / bmpw, 64.0f / bmph); glVertex2f(rigth, top); glTexCoord2f(160.0f / bmpw, 66.0f / bmph); glVertex2f(rigth, top + 2.0f); glTexCoord2f(158.0f / bmpw, 66.0f / bmph); glVertex2f(rigth - 2.0f, top + 2.0f); // Corner lower right glTexCoord2f(158.0f / bmpw, 94.0f / bmph); glVertex2f(rigth - 2.0f, bottom - 2.0f); glTexCoord2f(160.0f / bmpw, 94.0f / bmph); glVertex2f(rigth, bottom - 2.0f); glTexCoord2f(160.0f / bmpw, 96.0f / bmph); glVertex2f(rigth, bottom); glTexCoord2f(158.0f / bmpw, 96.0f / bmph); glVertex2f(rigth - 2.0f, bottom); // Corner lower left glTexCoord2f(128.0f / bmpw, 94.0f / bmph); glVertex2f(left, bottom - 2.0f); glTexCoord2f(130.0f / bmpw, 94.0f / bmph); glVertex2f(left + 2.0f, bottom - 2.0f); glTexCoord2f(130.0f / bmpw, 96.0f / bmph); glVertex2f(left + 2.0f, bottom); glTexCoord2f(128.0f / bmpw, 96.0f / bmph); glVertex2f(left, bottom); // Border up glTexCoord2f(130.0f / bmpw, 64.0f / bmph); glVertex2f(left + 2.0f, top); glTexCoord2f(158.0f / bmpw, 64.0f / bmph); glVertex2f(rigth - 2.0f, top); glTexCoord2f(158.0f / bmpw, 66.0f / bmph); glVertex2f(rigth - 2.0f, top + 2.0f); glTexCoord2f(130.0f / bmpw, 66.0f / bmph); glVertex2f(left + 2.0f, top + 2.0f); // Border down glTexCoord2f(130.0f / bmpw, 94.0f / bmph); glVertex2f(left + 2.0f, bottom - 2.0f); glTexCoord2f(158.0f / bmpw, 94.0f / bmph); glVertex2f(rigth - 2.0f, bottom - 2.0f); glTexCoord2f(158.0f / bmpw, 96.0f / bmph); glVertex2f(rigth - 2.0f, bottom); glTexCoord2f(130.0f / bmpw, 96.0f / bmph); glVertex2f(left + 2.0f, bottom); // Border left glTexCoord2f(128.0f / bmpw, 66.0f / bmph); glVertex2f(left, top + 2.0f); glTexCoord2f(130.0f / bmpw, 66.0f / bmph); glVertex2f(left + 2.0f, top + 2.0f); glTexCoord2f(130.0f / bmpw, 94.0f / bmph); glVertex2f(left + 2.0f, bottom - 2.0f); glTexCoord2f(128.0f / bmpw, 94.0f / bmph); glVertex2f(left, bottom - 2.0f); // Border right glTexCoord2f(158.0f / bmpw, 66.0f / bmph); glVertex2f(rigth - 2.0f, top + 2.0f); glTexCoord2f(160.0f / bmpw, 66.0f / bmph); glVertex2f(rigth, top + 2.0f); glTexCoord2f(160.0f / bmpw, 94.0f / bmph); glVertex2f(rigth, bottom - 2.0f); glTexCoord2f(158.0f / bmpw, 94.0f / bmph); glVertex2f(rigth - 2.0f, bottom - 2.0f); glEnd(); } } if (pause) { float dstx = (float)max(width / 2 - 8, 0); float dsty = (float)max(height - 16, 0); float w = (float)min(16, width); float h = (float)min(16, height); float srcx = 176.0f; float srcy = 64.0f; switch (pause_id) { case 0: glColor4f(1.0f, 1.0f, 1.0f, (255.0f / 8.0f) * pause_frame / 255.0f); case 4: srcx = 160.0f; srcy = 64.0f; break; case 1: srcx = 176.0f; srcy = 64.0f; break; case 2: srcx = 160.0f; srcy = 80.0f; break; case 3: srcx = 176.0f; srcy = 80.0f; } glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glBegin(GL_QUADS); glTexCoord2f(srcx / bmpw, srcy / bmph); glVertex2f(dstx, dsty); glTexCoord2f((srcx + w) / bmpw, srcy / bmph); glVertex2f(dstx + w, dsty); glTexCoord2f((srcx + w) / bmpw, (srcy + h) / bmph); glVertex2f(dstx + w, dsty + h); glTexCoord2f(srcx / bmpw, (srcy + h) / bmph); glVertex2f(dstx, dsty + h); glEnd(); } } if (contents != Qnil) { if (width > 32 && height > 32 && -ox < width - 32 && -oy < height - 32 && contents_opacity > 0) { Bitmap* bmp = Bitmap::Get(contents); glPushMatrix(); bmp->Refresh(); bmp->BindBitmap(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); Rect dstrect(x + 16, y + 16, width - 32, height - 32); glEnable(GL_SCISSOR_TEST); if (viewport != Qnil) { Rect rect = Viewport::Get(viewport)->GetViewportRect(); dstrect.x -= rect.x; dstrect.y -= rect.y; dstrect.Adjust(rect.width, rect.height); } glScissor(dstrect.x, Player::GetHeight() - (dstrect.y + dstrect.height), dstrect.width, dstrect.height); glColor4f(1.0f, 1.0f, 1.0f, contents_opacity / 255.0f); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(16.0f - ox, 16.0f - oy); glTexCoord2f(1.0f, 0.0f); glVertex2f(16.0f - ox + bmp->GetWidth(), 16.0f - oy); glTexCoord2f(1.0f, 1.0f); glVertex2f(16.0f - ox + bmp->GetWidth(), 16.0f - oy + bmp->GetHeight()); glTexCoord2f(0.0f, 1.0f); glVertex2f(16.0f - ox, 16.0f - oy + bmp->GetHeight()); glEnd(); glViewport(0, 0, Player::GetWidth(), Player::GetHeight()); if (viewport == Qnil) glDisable(GL_SCISSOR_TEST); } if (windowskin != Qnil) { Bitmap* bmp = Bitmap::Get(windowskin); float bmpw = (float)bmp->GetWidth(); float bmph = (float)bmp->GetHeight(); float widthf = (float)width; float heightf = (float)height; bmp->BindBitmap(); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glBegin(GL_QUADS); if (ox > 0) { glTexCoord2f(144.0f / bmpw, 24.0f / bmph); glVertex2f(4.0f, heightf / 2.0f - 8.0f); glTexCoord2f(152.0f / bmpw, 24.0f / bmph); glVertex2f(12.0f, heightf / 2.0f - 8.0f); glTexCoord2f(152.0f / bmpw, 40.0f / bmph); glVertex2f(12.0f, heightf / 2.0f + 8.0f); glTexCoord2f(144.0f / bmpw, 40.0f / bmph); glVertex2f(4.0f, heightf / 2.0f + 8.0f); } if (oy > 0) { glTexCoord2f(152.0f / bmpw, 16.0f / bmph); glVertex2f(widthf / 2.0f - 8.0f, 4.0f); glTexCoord2f(168.0f / bmpw, 16.0f / bmph); glVertex2f(widthf / 2.0f + 8.0f, 4.0f); glTexCoord2f(168.0f / bmpw, 24.0f / bmph); glVertex2f(widthf / 2.0f + 8.0f, 12.0f); glTexCoord2f(152.0f / bmpw, 24.0f / bmph); glVertex2f(widthf / 2.0f - 8.0f, 12.0f); } if (Bitmap::Get(contents)->GetWidth() - ox > width - 32) { glTexCoord2f(168.0f / bmpw, 24.0f / bmph); glVertex2f(widthf - 12.0f, heightf / 2.0f - 8.0f); glTexCoord2f(176.0f / bmpw, 24.0f / bmph); glVertex2f(widthf - 4.0f, heightf / 2.0f - 8.0f); glTexCoord2f(176.0f / bmpw, 40.0f / bmph); glVertex2f(widthf - 4.0f, heightf / 2.0f + 8.0f); glTexCoord2f(168.0f / bmpw, 40.0f / bmph); glVertex2f(widthf - 12.0f, heightf / 2.0f + 8.0f); } if (Bitmap::Get(contents)->GetHeight() - oy > height - 32) { glTexCoord2f(152.0f / bmpw, 40.0f / bmph); glVertex2f(widthf / 2.0f - 8.0f, heightf - 12.0f); glTexCoord2f(168.0f / bmpw, 40.0f / bmph); glVertex2f(widthf / 2.0f + 8.0f, heightf - 12.0f); glTexCoord2f(168.0f / bmpw, 48.0f / bmph); glVertex2f(widthf / 2.0f + 8.0f, heightf - 4.0f); glTexCoord2f(152.0f / bmpw, 48.0f / bmph); glVertex2f(widthf / 2.0f - 8.0f, heightf - 4.0f); } glEnd(); } } glDisable(GL_SCISSOR_TEST); }