void LLTextureCtrl::draw() { mBorder->setKeyboardFocusHighlight(hasFocus()); if (!mValid) { mTexturep = NULL; } else if (!mImageAssetID.isNull()) { LLPointer<LLViewerFetchedTexture> texture = LLViewerTextureManager::getFetchedTexture(mImageAssetID, MIPMAP_YES,LLViewerTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE); texture->setBoostLevel(LLViewerTexture::BOOST_PREVIEW); texture->forceToSaveRawImage(0) ; mTexturep = texture; } else//mImageAssetID == LLUUID::null { mTexturep = NULL; } // Border LLRect border( 0, getRect().getHeight(), getRect().getWidth(), BTN_HEIGHT_SMALL ); gl_rect_2d( border, mBorderColor.get(), FALSE ); // Interior LLRect interior = border; interior.stretch( -1 ); // If we're in a focused floater, don't apply the floater's alpha to the texture (STORM-677). const F32 alpha = getTransparencyType() == TT_ACTIVE ? 1.0f : getCurrentTransparency(); if( mTexturep ) { if( mTexturep->getComponents() == 4 ) { gl_rect_2d_checkerboard( interior, alpha ); } gl_draw_scaled_image( interior.mLeft, interior.mBottom, interior.getWidth(), interior.getHeight(), mTexturep, UI_VERTEX_COLOR % alpha); mTexturep->addTextureStats( (F32)(interior.getWidth() * interior.getHeight()) ); } else if (!mFallbackImage.isNull()) { mFallbackImage->draw(interior, UI_VERTEX_COLOR % alpha); } else { gl_rect_2d( interior, LLColor4::grey % alpha, TRUE ); // Draw X gl_draw_x( interior, LLColor4::black ); } mTentativeLabel->setVisible( !mTexturep.isNull() && getTentative() ); // Show "Loading..." string on the top left corner while this texture is loading. // Using the discard level, do not show the string if the texture is almost but not // fully loaded. if (mTexturep.notNull() && (!mTexturep->isFullyLoaded()) && (mShowLoadingPlaceholder == TRUE)) { U32 v_offset = 25; LLFontGL* font = LLFontGL::getFontSansSerif(); // Don't show as loaded if the texture is almost fully loaded (i.e. discard1) unless god if ((mTexturep->getDiscardLevel() > 1) || gAgent.isGodlike()) { font->renderUTF8( mLoadingPlaceholderString, 0, llfloor(interior.mLeft+3), llfloor(interior.mTop-v_offset), LLColor4::white, LLFontGL::LEFT, LLFontGL::BASELINE, LLFontGL::DROP_SHADOW); } // Optionally show more detailed information. if (gSavedSettings.getBOOL("DebugAvatarRezTime")) { LLFontGL* font = LLFontGL::getFontSansSerif(); std::string tdesc; // Show what % the texture has loaded (0 to 100%, 100 is highest), and what level of detail (5 to 0, 0 is best). v_offset += 12; tdesc = llformat(" PK : %d%%", U32(mTexturep->getDownloadProgress()*100.0)); font->renderUTF8(tdesc, 0, llfloor(interior.mLeft+3), llfloor(interior.mTop-v_offset), LLColor4::white, LLFontGL::LEFT, LLFontGL::BASELINE, LLFontGL::DROP_SHADOW); v_offset += 12; tdesc = llformat(" LVL: %d", mTexturep->getDiscardLevel()); font->renderUTF8(tdesc, 0, llfloor(interior.mLeft+3), llfloor(interior.mTop-v_offset), LLColor4::white, LLFontGL::LEFT, LLFontGL::BASELINE, LLFontGL::DROP_SHADOW); v_offset += 12; tdesc = llformat(" ID : %s...", (mImageAssetID.asString().substr(0,7)).c_str()); font->renderUTF8(tdesc, 0, llfloor(interior.mLeft+3), llfloor(interior.mTop-v_offset), LLColor4::white, LLFontGL::LEFT, LLFontGL::BASELINE, LLFontGL::DROP_SHADOW); } } LLUICtrl::draw(); }
void hud_render_text(const LLWString &wstr, const LLVector3 &pos_agent, const LLFontGL &font, const U8 style, const LLFontGL::ShadowType shadow, const F32 x_offset, const F32 y_offset, const LLColor4& color, const BOOL orthographic) { LLViewerCamera* camera = LLViewerCamera::getInstance(); // Do cheap plane culling LLVector3 dir_vec = pos_agent - camera->getOrigin(); dir_vec /= dir_vec.magVec(); if (wstr.empty() || (!orthographic && dir_vec * camera->getAtAxis() <= 0.f)) { return; } LLVector3 right_axis; LLVector3 up_axis; if (orthographic) { right_axis.setVec(0.f, -1.f / gViewerWindow->getWorldViewHeightScaled(), 0.f); up_axis.setVec(0.f, 0.f, 1.f / gViewerWindow->getWorldViewHeightScaled()); } else { camera->getPixelVectors(pos_agent, up_axis, right_axis); } LLCoordFrame render_frame = *camera; LLQuaternion rot; if (!orthographic) { rot = render_frame.getQuaternion(); rot = rot * LLQuaternion(-F_PI_BY_TWO, camera->getYAxis()); rot = rot * LLQuaternion(F_PI_BY_TWO, camera->getXAxis()); } else { rot = LLQuaternion(-F_PI_BY_TWO, LLVector3(0.f, 0.f, 1.f)); rot = rot * LLQuaternion(-F_PI_BY_TWO, LLVector3(0.f, 1.f, 0.f)); } F32 angle; LLVector3 axis; rot.getAngleAxis(&angle, axis); LLVector3 render_pos = pos_agent + (floorf(x_offset) * right_axis) + (floorf(y_offset) * up_axis); //get the render_pos in screen space LLVector3 window_coordinates; F32& winX = window_coordinates.mV[VX]; F32& winY = window_coordinates.mV[VY]; F32& winZ = window_coordinates.mV[VZ]; const LLRect& world_view_rect = gViewerWindow->getWorldViewRectRaw(); glProjectf(render_pos, gGLModelView, gGLProjection, world_view_rect, window_coordinates); //fonts all render orthographically, set up projection`` gGL.matrixMode(LLRender::MM_PROJECTION); gGL.pushMatrix(); gGL.matrixMode(LLRender::MM_MODELVIEW); gGL.pushMatrix(); LLUI::pushMatrix(); gl_state_for_2d(world_view_rect.getWidth(), world_view_rect.getHeight()); gViewerWindow->setup3DViewport(); winX -= world_view_rect.mLeft; winY -= world_view_rect.mBottom; LLUI::loadIdentity(); gGL.loadIdentity(); LLUI::translate((F32) winX*1.0f/LLFontGL::sScaleX, (F32) winY*1.0f/(LLFontGL::sScaleY), -(((F32) winZ*2.f)-1.f)); F32 right_x; font.render(wstr, 0, 0, 0, color, LLFontGL::LEFT, LLFontGL::BASELINE, style, shadow, wstr.length(), 1000, &right_x); LLUI::popMatrix(); gGL.popMatrix(); gGL.matrixMode(LLRender::MM_PROJECTION); gGL.popMatrix(); gGL.matrixMode(LLRender::MM_MODELVIEW); }
LLView* LLSliderCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory) { std::string name("slider"); node->getAttributeString("name", name); std::string label; node->getAttributeString("label", label); LLRect rect; createRect(node, rect, parent, LLRect()); LLFontGL* font = LLView::selectFont(node); // HACK: Font might not be specified. if (!font) { font = LLFontGL::getFontSansSerifSmall(); } S32 label_width = 0; node->getAttributeS32("label_width", label_width); BOOL show_text = TRUE; node->getAttributeBOOL("show_text", show_text); BOOL can_edit_text = FALSE; node->getAttributeBOOL("can_edit_text", can_edit_text); BOOL volume = FALSE; node->getAttributeBOOL("volume", volume); F32 initial_value = 0.f; node->getAttributeF32("initial_val", initial_value); F32 min_value = 0.f; node->getAttributeF32("min_val", min_value); F32 max_value = 1.f; node->getAttributeF32("max_val", max_value); F32 increment = 0.1f; node->getAttributeF32("increment", increment); U32 precision = 3; node->getAttributeU32("decimal_digits", precision); S32 text_left = 0; if (show_text) { // calculate the size of the text box (log max_value is number of digits - 1 so plus 1) if ( max_value ) text_left = font->getWidth(std::string("0")) * ( static_cast < S32 > ( log10 ( max_value ) ) + precision + 1 ); if ( increment < 1.0f ) text_left += font->getWidth(std::string(".")); // (mostly) take account of decimal point in value if ( min_value < 0.0f || max_value < 0.0f ) text_left += font->getWidth(std::string("-")); // (mostly) take account of minus sign // padding to make things look nicer text_left += 8; } LLUICtrlCallback callback = NULL; if (label.empty()) { label.assign(node->getTextContents()); } LLSliderCtrl* slider = new LLSliderCtrl(name, rect, label, font, label_width, rect.getWidth() - text_left, show_text, can_edit_text, volume, callback, NULL, initial_value, min_value, max_value, increment); slider->setPrecision(precision); slider->initFromXML(node, parent); slider->updateText(); return slider; }
void LLTextureCtrl::draw() { mBorder->setKeyboardFocusHighlight(hasFocus()); if (!mValid) { mTexturep = NULL; } else if (!mImageAssetID.isNull()) { mTexturep = LLViewerTextureManager::getFetchedTexture(mImageAssetID, MIPMAP_YES,LLViewerTexture::BOOST_PREVIEW, LLViewerTexture::LOD_TEXTURE); mTexturep->forceToSaveRawImage(0) ; } else if (!mFallbackImageName.empty()) { // Show fallback image. mTexturep = LLViewerTextureManager::getFetchedTextureFromFile(mFallbackImageName, MIPMAP_YES,LLViewerTexture::BOOST_PREVIEW, LLViewerTexture::LOD_TEXTURE); } else // mImageAssetID == LLUUID::null { mTexturep = NULL; } // Border LLRect border( 0, getRect().getHeight(), getRect().getWidth(), BTN_HEIGHT_SMALL ); gl_rect_2d( border, mBorderColor, FALSE ); // Interior LLRect interior = border; interior.stretch( -1 ); if( mTexturep ) { if( mTexturep->getComponents() == 4 ) { gl_rect_2d_checkerboard( interior ); } gl_draw_scaled_image( interior.mLeft, interior.mBottom, interior.getWidth(), interior.getHeight(), mTexturep); mTexturep->addTextureStats( (F32)(interior.getWidth() * interior.getHeight()) ); } else { gl_rect_2d( interior, LLColor4::grey, TRUE ); // Draw X gl_draw_x( interior, LLColor4::black ); } mTentativeLabel->setVisible( !mTexturep.isNull() && getTentative() ); // Show "Loading..." string on the top left corner while this texture is loading. // Using the discard level, do not show the string if the texture is almost but not // fully loaded. if (mTexturep.notNull() && (!mTexturep->isFullyLoaded()) && (mShowLoadingPlaceholder == TRUE)) { LLFontGL* font = LLFontGL::getFontSansSerifBig(); font->renderUTF8( mLoadingPlaceholderString, 0, llfloor(interior.mLeft+10), llfloor(interior.mTop-20), LLColor4::white, LLFontGL::LEFT, LLFontGL::BASELINE, LLFontGL::NORMAL, LLFontGL::DROP_SHADOW); } LLUICtrl::draw(); }
LLFontGL *LLFontRegistry::createFont(const LLFontDescriptor& desc) { // Name should hold a font name recognized as a setting; the value // of the setting should be a list of font files. // Size should be a recognized string value // Style should be a set of flags including any implied by the font name. // First decipher the requested size. LLFontDescriptor norm_desc = desc.normalize(); F32 point_size; bool found_size = nameToSize(norm_desc.getSize(),point_size); if (!found_size) { llwarns << "createFont unrecognized size " << norm_desc.getSize() << llendl; return NULL; } llinfos << "createFont " << norm_desc.getName() << " size " << norm_desc.getSize() << " style " << ((S32) norm_desc.getStyle()) << llendl; F32 fallback_scale = 1.0; // Find corresponding font template (based on same descriptor with no size specified) LLFontDescriptor template_desc(norm_desc); template_desc.setSize(s_template_string); const LLFontDescriptor *match_desc = getClosestFontTemplate(template_desc); if (!match_desc) { llwarns << "createFont failed, no template found for " << norm_desc.getName() << " style [" << ((S32)norm_desc.getStyle()) << "]" << llendl; return NULL; } // See whether this best-match font has already been instantiated in the requested size. LLFontDescriptor nearest_exact_desc = *match_desc; nearest_exact_desc.setSize(norm_desc.getSize()); font_reg_map_t::iterator it = mFontMap.find(nearest_exact_desc); // If we fail to find a font in the fonts directory, it->second might be NULL. // We shouldn't construcnt a font with a NULL mFontFreetype. // This may not be the best solution, but it at least prevents a crash. if (it != mFontMap.end() && it->second != NULL) { llinfos << "-- matching font exists: " << nearest_exact_desc.getName() << " size " << nearest_exact_desc.getSize() << " style " << ((S32) nearest_exact_desc.getStyle()) << llendl; // copying underlying Freetype font, and storing in LLFontGL with requested font descriptor LLFontGL *font = new LLFontGL; font->mFontDescriptor = desc; font->mFontFreetype = it->second->mFontFreetype; mFontMap[desc] = font; return font; } // Build list of font names to look for. // Files specified for this font come first, followed by those from the default descriptor. string_vec_t file_names = match_desc->getFileNames(); string_vec_t default_file_names; LLFontDescriptor default_desc("default",s_template_string,0); const LLFontDescriptor *match_default_desc = getMatchingFontDesc(default_desc); if (match_default_desc) { file_names.insert(file_names.end(), match_default_desc->getFileNames().begin(), match_default_desc->getFileNames().end()); } // Add ultimate fallback list - generated dynamically on linux, // null elsewhere. file_names.insert(file_names.end(), getUltimateFallbackList().begin(), getUltimateFallbackList().end()); // Load fonts based on names. if (file_names.empty()) { llwarns << "createFont failed, no file names specified" << llendl; return NULL; } LLFontFreetype::font_vector_t fontlist; LLFontGL *result = NULL; // Snarf all fonts we can into fontlist. First will get pulled // off the list and become the "head" font, set to non-fallback. // Rest will consitute the fallback list. BOOL is_first_found = TRUE; std::string local_path = LLFontGL::getFontPathLocal(); std::string sys_path = LLFontGL::getFontPathSystem(); // The fontname string may contain multiple font file names separated by semicolons. // Break it apart and try loading each one, in order. for(string_vec_t::iterator file_name_it = file_names.begin(); file_name_it != file_names.end(); ++file_name_it) { LLFontGL *fontp = new LLFontGL; std::string font_path = local_path + *file_name_it; // *HACK: Fallback fonts don't render, so we can use that to suppress // creation of OpenGL textures for test apps. JC BOOL is_fallback = !is_first_found || !mCreateGLTextures; F32 extra_scale = (is_fallback)?fallback_scale:1.0; if (!fontp->loadFace(font_path, extra_scale * point_size, LLFontGL::sVertDPI, LLFontGL::sHorizDPI, 2, is_fallback)) { font_path = sys_path + *file_name_it; if (!fontp->loadFace(font_path, extra_scale * point_size, LLFontGL::sVertDPI, LLFontGL::sHorizDPI, 2, is_fallback)) { LL_INFOS_ONCE("LLFontRegistry") << "Couldn't load font " << *file_name_it << LL_ENDL; delete fontp; fontp = NULL; } } if(fontp) { if (is_first_found) { result = fontp; is_first_found = false; } else { fontlist.push_back(fontp->mFontFreetype); delete fontp; fontp = NULL; } } } if (result && !fontlist.empty()) { result->mFontFreetype->setFallbackFonts(fontlist); } if (result) { result->mFontDescriptor = desc; } else { llwarns << "createFont failed in some way" << llendl; } mFontMap[desc] = result; return result; }
void hud_render_text(const LLWString &wstr, const LLVector3 &pos_agent, const LLFontGL &font, const U8 style, const F32 x_offset, const F32 y_offset, const LLColor4& color, const BOOL orthographic) { LLViewerCamera* camera = LLViewerCamera::getInstance(); // Do cheap plane culling LLVector3 dir_vec = pos_agent - camera->getOrigin(); dir_vec /= dir_vec.magVec(); if (wstr.empty() || (!orthographic && dir_vec * camera->getAtAxis() <= 0.f)) { return; } LLVector3 right_axis; LLVector3 up_axis; if (orthographic) { right_axis.setVec(0.f, -1.f / gViewerWindow->getWindowHeight(), 0.f); up_axis.setVec(0.f, 0.f, 1.f / gViewerWindow->getWindowHeight()); } else { camera->getPixelVectors(pos_agent, up_axis, right_axis); } LLCoordFrame render_frame = *camera; LLQuaternion rot; if (!orthographic) { rot = render_frame.getQuaternion(); rot = rot * LLQuaternion(-F_PI_BY_TWO, camera->getYAxis()); rot = rot * LLQuaternion(F_PI_BY_TWO, camera->getXAxis()); } else { rot = LLQuaternion(-F_PI_BY_TWO, LLVector3(0.f, 0.f, 1.f)); rot = rot * LLQuaternion(-F_PI_BY_TWO, LLVector3(0.f, 1.f, 0.f)); } F32 angle; LLVector3 axis; rot.getAngleAxis(&angle, axis); LLVector3 render_pos = pos_agent + (floorf(x_offset) * right_axis) + (floorf(y_offset) * up_axis); //get the render_pos in screen space F64 winX, winY, winZ; gluProject(render_pos.mV[0], render_pos.mV[1], render_pos.mV[2], gGLModelView, gGLProjection, (GLint*) gGLViewport, &winX, &winY, &winZ); //fonts all render orthographically, set up projection glMatrixMode(GL_PROJECTION); glPushMatrix(); glMatrixMode(GL_MODELVIEW); LLUI::pushMatrix(); gViewerWindow->setup2DRender(); LLUI::loadIdentity(); LLUI::translate((F32) winX*1.0f/LLFontGL::sScaleX, (F32) winY*1.0f/(LLFontGL::sScaleY), -(((F32) winZ*2.f)-1.f)); //glRotatef(angle * RAD_TO_DEG, axis.mV[VX], axis.mV[VY], axis.mV[VZ]); //glScalef(right_scale, up_scale, 1.f); F32 right_x; font.render(wstr, 0, 0, 0, color, LLFontGL::LEFT, LLFontGL::BASELINE, style, wstr.length(), 1000, &right_x); LLUI::popMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); }
void lggBeamColorMapFloater::draw() { //set the color of the preview thing LLColorSwatchCtrl* colorctrl = getChild<LLColorSwatchCtrl>("BeamColor_Preview"); LLColor4 bColor = LLColor4(lggBeamMaps::beamColorFromData(myData)); colorctrl->set(bColor,TRUE); //Try draw rectangle attach beam LLRect swatch_rect; LLButton* createButton = empanel->getChild<LLButton>("BeamColor_new"); createButton->localRectToOtherView(createButton->getLocalRect(), &swatch_rect, this); LLRect local_rect = getLocalRect(); if (gFocusMgr.childHasKeyboardFocus(this) && empanel->isInVisibleChain() && mContextConeOpacity > 0.001f) { gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); LLGLEnable(GL_CULL_FACE); gGL.begin(LLRender::QUADS); { F32 r = bColor.mV[0]; F32 g = bColor.mV[1]; F32 b = bColor.mV[2]; gGL.color4f(r, g, b, CONTEXT_CONE_IN_ALPHA * mContextConeOpacity); gGL.vertex2i(swatch_rect.mLeft, swatch_rect.mTop); gGL.vertex2i(swatch_rect.mRight, swatch_rect.mTop); gGL.color4f(r, g, b, CONTEXT_CONE_OUT_ALPHA * mContextConeOpacity); gGL.vertex2i(local_rect.mRight, local_rect.mTop); gGL.vertex2i(local_rect.mLeft, local_rect.mTop); gGL.color4f(r, g, b, CONTEXT_CONE_OUT_ALPHA * mContextConeOpacity); gGL.vertex2i(local_rect.mLeft, local_rect.mTop); gGL.vertex2i(local_rect.mLeft, local_rect.mBottom); gGL.color4f(r, g, b, CONTEXT_CONE_IN_ALPHA * mContextConeOpacity); gGL.vertex2i(swatch_rect.mLeft, swatch_rect.mBottom); gGL.vertex2i(swatch_rect.mLeft, swatch_rect.mTop); gGL.color4f(r, g, b, CONTEXT_CONE_OUT_ALPHA * mContextConeOpacity); gGL.vertex2i(local_rect.mRight, local_rect.mBottom); gGL.vertex2i(local_rect.mRight, local_rect.mTop); gGL.color4f(r, g, b, CONTEXT_CONE_IN_ALPHA * mContextConeOpacity); gGL.vertex2i(swatch_rect.mRight, swatch_rect.mTop); gGL.vertex2i(swatch_rect.mRight, swatch_rect.mBottom); gGL.color4f(r, g, b, CONTEXT_CONE_OUT_ALPHA * mContextConeOpacity); gGL.vertex2i(local_rect.mLeft, local_rect.mBottom); gGL.vertex2i(local_rect.mRight, local_rect.mBottom); gGL.color4f(r, g, b, CONTEXT_CONE_IN_ALPHA * mContextConeOpacity); gGL.vertex2i(swatch_rect.mRight, swatch_rect.mBottom); gGL.vertex2i(swatch_rect.mLeft, swatch_rect.mBottom); } gGL.end(); } static LLCachedControl<F32> opacity(gSavedSettings, "PickerContextOpacity"); mContextConeOpacity = lerp(mContextConeOpacity, opacity, LLCriticalDamp::getInterpolant(CONTEXT_FADE_TIME)); //Draw Base Stuff LLFloater::draw(); //Draw hues and pointers at color gGL.pushMatrix(); F32 r, g, b; LLColor4 output; for (int i = 0;i <= 720;i++) { int hi =i%360; hslToRgb1((hi/360.0f), 1.0f, 0.5f, r, g, b); output.set(r, g, b); gl_line_2d( convertHueToX(i),201, convertHueToX(i),277,output); } S32 X1 = convertHueToX(myData.startHue); S32 X2 = convertHueToX(myData.endHue); LLFontGL* font = LLFontGL::getFontSansSerifSmall(); gGL.color4fv(LLColor4::white.mV); gl_circle_2d(X1,238,9.0f,(S32)30,false); gGL.color4fv(LLColor4::black.mV); gl_circle_2d(X1,238,8.0f,(S32)30,false); gGL.color4fv(LLColor4::white.mV); gl_circle_2d(X1,238,7.0f,(S32)30,false); gl_line_2d(X1+1,210,X1+1,266,LLColor4::white); gl_line_2d(X1-1,210,X1-1,266,LLColor4::white); gl_line_2d(X1,210,X1,266,LLColor4::black); gl_line_2d(X1-25,238+1,X1+25,238+1,LLColor4::white); gl_line_2d(X1-25,238-1,X1+25,238-1,LLColor4::white); gl_line_2d(X1-25,238,X1+25,238,LLColor4::black); font->renderUTF8( "Start Hue", 0, X1, 212, LLColor4::white, LLFontGL::HCENTER, LLFontGL::BASELINE, LLFontGL::DROP_SHADOW); gGL.color4fv(LLColor4::white.mV); gl_circle_2d(X2,238,9.0f,(S32)30,false); gGL.color4fv(LLColor4::black.mV); gl_circle_2d(X2,238,8.0f,(S32)30,false); gGL.color4fv(LLColor4::white.mV); gl_circle_2d(X2,238,7.0f,(S32)30,false); gl_line_2d(X2+1,210,X2+1,266,LLColor4::white); gl_line_2d(X2-1,210,X2-1,266,LLColor4::white); gl_line_2d(X2,210,X2,266,LLColor4::black); gl_line_2d(X2-25,238+1,X2+25,238+1,LLColor4::white); gl_line_2d(X2-25,238-1,X2+25,238-1,LLColor4::white); gl_line_2d(X2-25,238,X2+25,238,LLColor4::black); font->renderUTF8( "End Hue", 0, X2, 212, LLColor4::white, LLFontGL::HCENTER, LLFontGL::BASELINE, LLFontGL::DROP_SHADOW); gGL.popMatrix(); }