int TextureHooks::LoadTexture(int textureId, TigTextureRegistryEntry* textureOut) { // Only one tig buffer can be returned at a time by this function, // Since we don't want to memory manage static TigBuffer buffer { 0, }; auto texture = gfx::textureManager->GetById(textureId); if (!texture->IsValid()) { return 17; } auto deviceTexture = texture->GetDeviceTexture(); if (!deviceTexture) { // Loading failed... return 17; } textureOut->comes_from_mdf = false; // Irrelevant textureOut->textureId = textureId; textureOut->name[0] = 0; // Never read auto size = texture->GetSize(); textureOut->width = size.width; textureOut->height = size.height; const auto &rect = texture->GetContentRect(); textureOut->rect.x = rect.x; textureOut->rect.y = rect.y; textureOut->rect.width = rect.width; textureOut->rect.height = rect.height; textureOut->buffer = &buffer; if (buffer.d3dtexture) { // DeleteTextureAdapter(buffer.d3dtexture); // TODO: Ownership semantics... } buffer.d3dtexture = CreateTextureAdapter(deviceTexture); buffer.texturewidth = size.width; buffer.textureheight = size.height; return 0; }
void RatingsButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) { int rating = static_cast<int>(GetRating() * NUM_STARS); // FIXME: 9/26/2011 // We should probably support an API for saying whether the ratings // should or shouldn't support half stars...but our only consumer at // the moment is the applications scope which according to design // (Bug #839759) shouldn't. So for now just force rounding. // int total_half_stars = rating % 2; // int total_full_stars = rating / 2; int total_full_stars = rating; nux::Geometry const& geo = GetGeometry(); nux::Geometry geo_star(geo); geo_star.width = star_size_.CP(scale); geo_star.height = star_size_.CP(scale); gPainter.PaintBackground(GfxContext, geo); // set up our texture mode nux::TexCoordXForm texxform; texxform.SetWrap(nux::TEXWRAP_CLAMP_TO_BORDER, nux::TEXWRAP_CLAMP_TO_BORDER); texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_SCALE_COORD); texxform.SetFilter(nux::TEXFILTER_LINEAR, nux::TEXFILTER_LINEAR); // clear what is behind us unsigned int alpha = 0, src = 0, dest = 0; GfxContext.GetRenderStates().GetBlend(alpha, src, dest); GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); nux::Color col = nux::color::Black; col.alpha = 0; GfxContext.QRP_Color(geo.x, geo.y, geo.width, geo.height, col); for (int index = 0; index < NUM_STARS; ++index) { dash::Style& style = dash::Style::Instance(); auto texture = style.GetStarSelectedIcon(); if (index < total_full_stars) { if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_NORMAL) texture = style.GetStarSelectedIcon(); else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT) texture = style.GetStarSelectedIcon(); else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED) texture = style.GetStarSelectedIcon(); } else { if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_NORMAL) texture = style.GetStarDeselectedIcon(); else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT) texture = style.GetStarDeselectedIcon(); else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED) texture = style.GetStarDeselectedIcon(); } GfxContext.QRP_1Tex(geo_star.x, geo_star.y, geo_star.width, geo_star.height, texture->GetDeviceTexture(), texxform, nux::Color(1.0f, 1.0f, 1.0f, 1.0f)); if (focused_star_ == index) { GfxContext.QRP_1Tex(geo_star.x, geo_star.y, geo_star.width, geo_star.height, style.GetStarHighlightIcon()->GetDeviceTexture(), texxform, nux::Color(1.0f, 1.0f, 1.0f, 0.5f)); } geo_star.x += geo_star.width + star_gap_.CP(scale); } GfxContext.GetRenderStates().SetBlend(alpha, src, dest); }