From a4000c3744e42fcbb638e742f3b63fa31a0dee15 Mon Sep 17 00:00:00 2001 From: Steven Bennetts Date: Fri, 8 May 2009 07:43:08 +0000 Subject: merge trunk@116587 skinning-7@119389 -> viewer-2.0.0-skinning-7 --- indra/llui/llui.cpp | 386 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 263 insertions(+), 123 deletions(-) (limited to 'indra/llui/llui.cpp') diff --git a/indra/llui/llui.cpp b/indra/llui/llui.cpp index 57ce13c9c6..dfe435d2e3 100644 --- a/indra/llui/llui.cpp +++ b/indra/llui/llui.cpp @@ -52,8 +52,15 @@ #include "llui.h" #include "llview.h" #include "lllineeditor.h" +#include "llfloater.h" +#include "llfloaterreg.h" +#include "llmenugl.h" #include "llwindow.h" +// for XUIParse +#include "llquaternion.h" +#include + // // Globals // @@ -65,18 +72,18 @@ BOOL gShowTextEditCursor = TRUE; // Language for UI construction std::map gTranslation; std::list gUntranslated; +/*static*/ LLUI::settings_map_t LLUI::sSettingGroups; +/*static*/ LLImageProviderInterface* LLUI::sImageProvider = NULL; +/*static*/ LLUIAudioCallback LLUI::sAudioCallback = NULL; +/*static*/ LLVector2 LLUI::sGLScaleFactor(1.f, 1.f); +/*static*/ LLWindow* LLUI::sWindow = NULL; +/*static*/ LLHtmlHelp* LLUI::sHtmlHelp = NULL; +/*static*/ LLView* LLUI::sRootView = NULL; +/*static*/ BOOL LLUI::sShowXUINames = FALSE; +/*static*/ std::stack LLScreenClipRect::sClipRectStack; + +/*static*/ std::vector LLUI::sXUIPaths; -LLControlGroup* LLUI::sConfigGroup = NULL; -LLControlGroup* LLUI::sIgnoresGroup = NULL; -LLControlGroup* LLUI::sColorsGroup = NULL; -LLImageProviderInterface* LLUI::sImageProvider = NULL; -LLUIAudioCallback LLUI::sAudioCallback = NULL; -LLVector2 LLUI::sGLScaleFactor(1.f, 1.f); -LLWindow* LLUI::sWindow = NULL; -LLHtmlHelp* LLUI::sHtmlHelp = NULL; -BOOL LLUI::sShowXUINames = FALSE; -std::stack LLScreenClipRect::sClipRectStack; -BOOL LLUI::sQAMode = FALSE; // // Functions @@ -84,18 +91,18 @@ BOOL LLUI::sQAMode = FALSE; void make_ui_sound(const char* namep) { std::string name = ll_safe_string(namep); - if (!LLUI::sConfigGroup->controlExists(name)) + if (!LLUI::sSettingGroups["config"]->controlExists(name)) { llwarns << "tried to make ui sound for unknown sound name: " << name << llendl; } else { - LLUUID uuid(LLUI::sConfigGroup->getString(name)); + LLUUID uuid(LLUI::sSettingGroups["config"]->getString(name)); if (uuid.isNull()) { - if (LLUI::sConfigGroup->getString(name) == LLUUID::null.asString()) + if (LLUI::sSettingGroups["config"]->getString(name) == LLUUID::null.asString()) { - if (LLUI::sConfigGroup->getBOOL("UISndDebugSpamToggle")) + if (LLUI::sSettingGroups["config"]->getBOOL("UISndDebugSpamToggle")) { llinfos << "ui sound name: " << name << " triggered but silent (null uuid)" << llendl; } @@ -108,7 +115,7 @@ void make_ui_sound(const char* namep) } else if (LLUI::sAudioCallback != NULL) { - if (LLUI::sConfigGroup->getBOOL("UISndDebugSpamToggle")) + if (LLUI::sSettingGroups["config"]->getBOOL("UISndDebugSpamToggle")) { llinfos << "ui sound name: " << name << llendl; } @@ -1554,21 +1561,18 @@ bool handleShowXUINamesChanged(const LLSD& newvalue) return true; } -void LLUI::initClass(LLControlGroup* config, - LLControlGroup* ignores, - LLControlGroup* colors, +void LLUI::initClass(const settings_map_t& settings, LLImageProviderInterface* image_provider, LLUIAudioCallback audio_callback, const LLVector2* scale_factor, const std::string& language) { - sConfigGroup = config; - sIgnoresGroup = ignores; - sColorsGroup = colors; + sSettingGroups = settings; - if (sConfigGroup == NULL - || sIgnoresGroup == NULL - || sColorsGroup == NULL) + if ((get_ptr_in_map(sSettingGroups, std::string("config")) == NULL) || + (get_ptr_in_map(sSettingGroups, std::string("color")) == NULL) || + (get_ptr_in_map(sSettingGroups, std::string("floater")) == NULL) || + (get_ptr_in_map(sSettingGroups, std::string("ignores")) == NULL)) { llerrs << "Failure to initialize configuration groups" << llendl; } @@ -1577,16 +1581,31 @@ void LLUI::initClass(LLControlGroup* config, sAudioCallback = audio_callback; sGLScaleFactor = (scale_factor == NULL) ? LLVector2(1.f, 1.f) : *scale_factor; sWindow = NULL; // set later in startup - LLFontGL::sShadowColor = colors->getColor("ColorDropShadow"); + LLFontGL::sShadowColor = LLUI::sSettingGroups["color"]->getColor("ColorDropShadow"); - LLUI::sShowXUINames = LLUI::sConfigGroup->getBOOL("ShowXUINames"); - LLUI::sConfigGroup->getControl("ShowXUINames")->getSignal()->connect(&handleShowXUINamesChanged); + static LLUICachedControl show_xui_names ("ShowXUINames", false); + LLUI::sShowXUINames = show_xui_names; + LLUI::sSettingGroups["config"]->getControl("ShowXUINames")->getSignal()->connect(boost::bind(&handleShowXUINamesChanged, _2)); + + // Callbacks for associating controls with floater visibilty: + LLUICtrl::CommitCallbackRegistry::defaultRegistrar().add("Floater.Toggle", boost::bind(&LLFloaterReg::toggleFloaterInstance, _2)); + LLUICtrl::CommitCallbackRegistry::defaultRegistrar().add("Floater.Show", boost::bind(&LLFloaterReg::showFloaterInstance, _2)); + LLUICtrl::CommitCallbackRegistry::defaultRegistrar().add("Floater.Hide", boost::bind(&LLFloaterReg::hideFloaterInstance, _2)); + LLUICtrl::CommitCallbackRegistry::defaultRegistrar().add("Floater.InitToVisibilityControl", boost::bind(&LLFloaterReg::initUICtrlToFloaterVisibilityControl, _1, _2)); + + // Button initialization callback for toggle buttons + LLUICtrl::CommitCallbackRegistry::defaultRegistrar().add("Button.SetFloaterToggle", boost::bind(&LLButton::setFloaterToggle, _1, _2)); + + // Currently unused, but kept for reference: + LLUICtrl::CommitCallbackRegistry::defaultRegistrar().add("Button.ToggleFloater", boost::bind(&LLButton::toggleFloaterAndSetToggleState, _1, _2)); + + // Used by menus along with Floater.Toggle to display visibility as a checkmark + LLUICtrl::EnableCallbackRegistry::defaultRegistrar().add("Floater.Visible", boost::bind(&LLFloaterReg::floaterInstanceVisible, _2)); } void LLUI::cleanupClass() { sImageProvider->cleanUp(); - LLLineEditor::cleanupLineEditor(); } @@ -1679,16 +1698,16 @@ void LLUI::getCursorPositionLocal(const LLView* viewp, S32 *x, S32 *y) std::string LLUI::getLanguage() { std::string language = "en-us"; - if (sConfigGroup) + if (sSettingGroups["config"]) { - language = sConfigGroup->getString("Language"); + language = sSettingGroups["config"]->getString("Language"); if (language.empty() || language == "default") { - language = sConfigGroup->getString("InstallLanguage"); + language = sSettingGroups["config"]->getString("InstallLanguage"); } if (language.empty() || language == "default") { - language = sConfigGroup->getString("SystemLanguage"); + language = sSettingGroups["config"]->getString("SystemLanguage"); } if (language.empty() || language == "default") { @@ -1698,6 +1717,40 @@ std::string LLUI::getLanguage() return language; } +//static +void LLUI::setupPaths() +{ + std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_SKINS, "paths.xml"); + + LLXMLNodePtr root; + BOOL success = LLXMLNode::parseFile(filename, root, NULL); + sXUIPaths.clear(); + + if (success) + { + LLStringUtil::format_map_t path_args; + path_args["[LANGUAGE]"] = LLUI::getLanguage(); + + for (LLXMLNodePtr path = root->getFirstChild(); path.notNull(); path = path->getNextSibling()) + { + std::string path_val_ui(path->getValue()); + LLStringUtil::format(path_val_ui, path_args); + if (std::find(sXUIPaths.begin(), sXUIPaths.end(), path_val_ui) == sXUIPaths.end()) + { + sXUIPaths.push_back(path_val_ui); + } + } + } + else // parsing failed + { + std::string slash = gDirUtilp->getDirDelimiter(); + std::string dir = "xui" + slash + "en-us"; + llwarns << "XUI::config file unable to open: " << filename << llendl; + sXUIPaths.push_back(dir); + } +} + + //static std::string LLUI::locateSkin(const std::string& filename) { @@ -1707,7 +1760,7 @@ std::string LLUI::locateSkin(const std::string& filename) { found_file = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, filename); // Should be CUSTOM_SKINS? } - if (sConfigGroup && sConfigGroup->controlExists("Language")) + if (sSettingGroups["config"] && sSettingGroups["config"]->controlExists("Language")) { if (!gDirUtilp->fileExists(found_file)) { @@ -1765,10 +1818,23 @@ void LLUI::glRectToScreen(const LLRect& gl, LLRect *screen) glPointToScreen(gl.mRight, gl.mBottom, &screen->mRight, &screen->mBottom); } +//static +LLPointer LLUI::getUIImageByID(const LLUUID& image_id) +{ + if (sImageProvider) + { + return sImageProvider->getUIImageByID(image_id); + } + else + { + return NULL; + } +} + //static -LLUIImage* LLUI::getUIImage(const std::string& name) +LLPointer LLUI::getUIImage(const std::string& name) { - if (!name.empty()) + if (!name.empty() && sImageProvider) return sImageProvider->getUIImage(name); else return NULL; @@ -1780,10 +1846,23 @@ void LLUI::setHtmlHelp(LLHtmlHelp* html_help) LLUI::sHtmlHelp = html_help; } -//static -void LLUI::setQAMode(BOOL b) +// static +boost::function LLUI::getCachedColorFunctor(const std::string& color_name) +{ + return LLCachedControl(*sSettingGroups["color"], color_name, LLColor4::magenta); +} + +// static +LLControlGroup& LLUI::getControlControlGroup (const std::string& controlname) { - LLUI::sQAMode = b; + for (settings_map_t::iterator itor = sSettingGroups.begin(); + itor != sSettingGroups.end(); ++itor) + { + if (sSettingGroups[(itor->first)]->controlExists(controlname)) + return *sSettingGroups[(itor->first)]; + } + + return *sSettingGroups["config"]; // default group } LLScreenClipRect::LLScreenClipRect(const LLRect& rect, BOOL enabled) : mScissorState(GL_SCISSOR_TEST), mEnabled(enabled) @@ -1849,102 +1928,163 @@ LLLocalClipRect::LLLocalClipRect(const LLRect &rect, BOOL enabled) { } - -// -// LLUIImage -// - -LLUIImage::LLUIImage(const std::string& name, LLPointer image) : - mName(name), - mImage(image), - mScaleRegion(0.f, 1.f, 1.f, 0.f), - mClipRegion(0.f, 1.f, 1.f, 0.f), - mUniformScaling(TRUE), - mNoClip(TRUE) +namespace LLInitParam { -} + TypedParam::TypedParam(BlockDescriptor& descriptor, const std::string& name, const LLUIColor& value, ParamDescriptor::validation_func_t func) + : super_t(descriptor, name, value, func), + red("red"), + green("green"), + blue("blue"), + alpha("alpha"), + control("") + {} -void LLUIImage::setClipRegion(const LLRectf& region) -{ - mClipRegion = region; - mNoClip = mClipRegion.mLeft == 0.f - && mClipRegion.mRight == 1.f - && mClipRegion.mBottom == 0.f - && mClipRegion.mTop == 1.f; -} + LLUIColor TypedParam::getValueFromBlock() const + { + if (control.isProvided()) + { + return LLUI::getCachedColorFunctor(control); + } + else + { + return LLColor4(red, green, blue, alpha); + } + } -void LLUIImage::setScaleRegion(const LLRectf& region) -{ - mScaleRegion = region; - mUniformScaling = mScaleRegion.mLeft == 0.f - && mScaleRegion.mRight == 1.f - && mScaleRegion.mBottom == 0.f - && mScaleRegion.mTop == 1.f; -} + void TypeValues::declareValues() + { + declare("white", LLColor4::white); + declare("black", LLColor4::black); + declare("red", LLColor4::red); + declare("green", LLColor4::green); + declare("blue", LLColor4::blue); + } -//TODO: move drawing implementation inside class -void LLUIImage::draw(S32 x, S32 y, const LLColor4& color) const -{ - gl_draw_image(x, y, mImage, color, mClipRegion); -} + TypedParam::TypedParam(BlockDescriptor& descriptor, const std::string& name, const LLFontGL*const value, ParamDescriptor::validation_func_t func) + : super_t(descriptor, name, value, func), + name("", std::string("")), + size("size", std::string("")), + style("style", std::string("")) + {} -void LLUIImage::draw(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const -{ - if (mUniformScaling) + const LLFontGL* TypedParam::getValueFromBlock() const { - gl_draw_scaled_image(x, y, width, height, mImage, color, mClipRegion); + if (name.isProvided()) + { + const LLFontGL* res_fontp = LLFontGL::getFontByName(name); + if (res_fontp) + { + return res_fontp; + } + + U8 fontstyle = 0; + fontstyle = LLFontGL::getStyleFromString(style()); + LLFontDescriptor desc(name(), size(), fontstyle); + const LLFontGL* fontp = LLFontGL::getFont(desc); + if (fontp) + { + return fontp; + } + } + + // default to current value + return mData.mValue; } - else + + TypedParam::TypedParam(BlockDescriptor& descriptor, const std::string& name, const LLRect& value, ParamDescriptor::validation_func_t func) + : super_t(descriptor, name, value, func), + left("left"), + top("top"), + right("right"), + bottom("bottom"), + width("width"), + height("height") + {} + + LLRect TypedParam::getValueFromBlock() const { - gl_draw_scaled_image_with_border( - x, y, - width, height, - mImage, - color, - FALSE, - mClipRegion, - mScaleRegion); - } -} + LLRect rect; -void LLUIImage::drawSolid(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const -{ - gl_draw_scaled_image_with_border( - x, y, - width, height, - mImage, - color, - TRUE, - mClipRegion, - mScaleRegion); -} + //calculate from params + // prefer explicit left and right + if (left.isProvided() && right.isProvided()) + { + rect.mLeft = left; + rect.mRight = right; + } + // otherwise use width along with specified side, if any + else if (width.isProvided()) + { + // only right + width provided + if (right.isProvided()) + { + rect.mRight = right; + rect.mLeft = right - width; + } + else // left + width, or just width + { + rect.mLeft = left; + rect.mRight = left + width; + } + } + // just left, just right, or none + else + { + rect.mLeft = left; + rect.mRight = right; + } -void LLUIImage::drawBorder(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, S32 border_width) const -{ - LLRect border_rect; - border_rect.setOriginAndSize(x, y, width, height); - border_rect.stretch(border_width, border_width); - drawSolid(border_rect, color); -} + // prefer explicit bottom and top + if (bottom.isProvided() && top.isProvided()) + { + rect.mBottom = bottom; + rect.mTop = top; + } + // otherwise height along with specified side, if any + else if (height.isProvided()) + { + // top + height provided + if (top.isProvided()) + { + rect.mTop = top; + rect.mBottom = top - height; + } + // bottom + height or just height + else + { + rect.mBottom = bottom; + rect.mTop = bottom + height; + } + } + // just bottom, just top, or none + else + { + rect.mBottom = bottom; + rect.mTop = top; + } + return rect; + } -S32 LLUIImage::getWidth() const -{ - // return clipped dimensions of actual image area - return llround((F32)mImage->getWidth(0) * mClipRegion.getWidth()); -} + void TypeValues::declareValues() + { + declare("left", LLFontGL::LEFT); + declare("right", LLFontGL::RIGHT); + declare("center", LLFontGL::HCENTER); + } -S32 LLUIImage::getHeight() const -{ - // return clipped dimensions of actual image area - return llround((F32)mImage->getHeight(0) * mClipRegion.getHeight()); -} + void TypeValues::declareValues() + { + declare("top", LLFontGL::TOP); + declare("center", LLFontGL::VCENTER); + declare("baseline", LLFontGL::BASELINE); + declare("bottom", LLFontGL::BOTTOM); + } -S32 LLUIImage::getTextureWidth() const -{ - return mImage->getWidth(0); + void TypeValues::declareValues() + { + declare("none", LLFontGL::NO_SHADOW); + declare("hard", LLFontGL::DROP_SHADOW); + declare("soft", LLFontGL::DROP_SHADOW_SOFT); + } } -S32 LLUIImage::getTextureHeight() const -{ - return mImage->getHeight(0); -} -- cgit v1.2.3