diff options
author | Richard Nelson <richard@lindenlab.com> | 2007-04-05 00:59:55 +0000 |
---|---|---|
committer | Richard Nelson <richard@lindenlab.com> | 2007-04-05 00:59:55 +0000 |
commit | 2ce0fc5f185f22be79b9be5406b76c97ed91ee01 (patch) | |
tree | d70ea9faf02e4e1e7aeb14aa524644c23c703d55 /indra/newview | |
parent | fd5608a3e79397d4ebc8819dc9de75863f6fb9b3 (diff) |
svn merge -r 59234:60086 svn+ssh://svn/svn/linden/branches/live_lsl_help2 -> release
Diffstat (limited to 'indra/newview')
-rw-r--r-- | indra/newview/llfloatercolorpicker.cpp | 60 | ||||
-rw-r--r-- | indra/newview/llfloatercolorpicker.h | 1 | ||||
-rw-r--r-- | indra/newview/llpreviewscript.cpp | 249 | ||||
-rw-r--r-- | indra/newview/llpreviewscript.h | 14 |
4 files changed, 265 insertions, 59 deletions
diff --git a/indra/newview/llfloatercolorpicker.cpp b/indra/newview/llfloatercolorpicker.cpp index 8af0dd410f..c3962bffb8 100644 --- a/indra/newview/llfloatercolorpicker.cpp +++ b/indra/newview/llfloatercolorpicker.cpp @@ -275,59 +275,6 @@ destroyUI () } } -////////////////////////////////////////////////////////////////////////////// -// -void -LLFloaterColorPicker:: -rgbToHsl ( F32 rValIn, F32 gValIn, F32 bValIn, F32& hValOut, F32& sValOut, F32& lValOut ) -{ - F32 var_R = ( rValIn ); - F32 var_G = ( gValIn ); - F32 var_B = ( bValIn ); - - F32 var_Min = ( var_R < ( var_G < var_B ? var_G : var_B ) ? var_R : ( var_G < var_B ? var_G : var_B ) ); - F32 var_Max = ( var_R > ( var_G > var_B ? var_G : var_B ) ? var_R : ( var_G > var_B ? var_G : var_B ) ); - - F32 del_Max = var_Max - var_Min; - - F32 L = ( var_Max + var_Min ) / 2.0f; - F32 H = 0.0f; - F32 S = 0.0f; - - if ( del_Max == 0.0f ) - { - H = 0.0f; - S = 0.0f; - } - else - { - if ( L < 0.5 ) - S = del_Max / ( var_Max + var_Min ); - else - S = del_Max / ( 2.0f - var_Max - var_Min ); - - F32 del_R = ( ( ( var_Max - var_R ) / 6.0f ) + ( del_Max / 2.0f ) ) / del_Max; - F32 del_G = ( ( ( var_Max - var_G ) / 6.0f ) + ( del_Max / 2.0f ) ) / del_Max; - F32 del_B = ( ( ( var_Max - var_B ) / 6.0f ) + ( del_Max / 2.0f ) ) / del_Max; - - if ( var_R >= var_Max ) - H = del_B - del_G; - else - if ( var_G >= var_Max ) - H = ( 1.0f / 3.0f ) + del_R - del_B; - else - if ( var_B >= var_Max ) - H = ( 2.0f / 3.0f ) + del_G - del_R; - - if ( H < 0.0f ) H += 1.0f; - if ( H > 1.0f ) H -= 1.0f; - } - - // scale to meet calculation requirements - hValOut = H * 360.0f / 360.0f; - sValOut = S * 100.0f / 100.0f; - lValOut = L * 100.0f / 100.0f; -} ////////////////////////////////////////////////////////////////////////////// // @@ -407,7 +354,7 @@ setCurRgb ( F32 curRIn, F32 curGIn, F32 curBIn ) curB = curBIn; // update corresponding HSL values and - rgbToHsl ( curR, curG, curB, curH, curS, curL ); + LLColor3(curRIn, curGIn, curBIn).calcHSL(&curH, &curS, &curL); // color changed so update text fields (fixes SL-16968) // HACK: turn off the call back wilst we update the text or we recurse ourselves into oblivion @@ -706,7 +653,10 @@ getComplimentaryColor ( LLColor4& backgroundColor ) { // going to base calculation on luminance F32 hVal, sVal, lVal; - rgbToHsl ( backgroundColor [ 0 ], backgroundColor [ 1 ], backgroundColor [ 2 ], hVal, sVal, lVal ); + backgroundColor.calcHSL(&hVal, &sVal, &lVal); + hVal *= 360.f; + sVal *= 100.f; + lVal *= 100.f; // fairly simple heuristic for now...! if ( lVal < 0.5f ) diff --git a/indra/newview/llfloatercolorpicker.h b/indra/newview/llfloatercolorpicker.h index 7660aa8c2d..2a93c26501 100644 --- a/indra/newview/llfloatercolorpicker.h +++ b/indra/newview/llfloatercolorpicker.h @@ -91,7 +91,6 @@ class LLFloaterColorPicker // convert RGB to HSL and vice-versa void hslToRgb ( F32 hValIn, F32 sValIn, F32 lValIn, F32& rValOut, F32& gValOut, F32& bValOut ); - void rgbToHsl ( F32 rValIn, F32 gValIn, F32 bValIn, F32& hValOut, F32& sValOut, F32& lValOut ); F32 hueToRgb ( F32 val1In, F32 val2In, F32 valHUeIn ); void setActive(BOOL active); diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp index 97b4a982d2..6a9965dbfb 100644 --- a/indra/newview/llpreviewscript.cpp +++ b/indra/newview/llpreviewscript.cpp @@ -57,6 +57,7 @@ #include "llviewertexteditor.h" #include "llviewerwindow.h" #include "llvieweruictrlfactory.h" +#include "llwebbrowserctrl.h" #include "lluictrlfactory.h" #include "viewer.h" @@ -115,6 +116,9 @@ const S32 SCRIPT_SEARCH_HEIGHT = 120; const S32 SCRIPT_SEARCH_LABEL_WIDTH = 50; const S32 SCRIPT_SEARCH_BUTTON_WIDTH = 80; const S32 TEXT_EDIT_COLUMN_HEIGHT = 16; +const S32 MAX_HISTORY_COUNT = 10; +const F32 LIVE_HELP_REFRESH_TIME = 1.f; + /// --------------------------------------------------------------------------- /// LLFloaterScriptSearch /// --------------------------------------------------------------------------- @@ -254,6 +258,7 @@ void LLFloaterScriptSearch::open() /*Flawfinder: ignore*/ LLFloater::open(); /*Flawfinder: ignore*/ childSetFocus("search_text", TRUE); } + /// --------------------------------------------------------------------------- /// LLScriptEdCore /// --------------------------------------------------------------------------- @@ -276,7 +281,9 @@ LLScriptEdCore::LLScriptEdCore( mLoadCallback( load_callback ), mSaveCallback( save_callback ), mUserdata( userdata ), - mForceClose( FALSE ) + mForceClose( FALSE ), + mLastHelpToken(NULL), + mLiveHelpHistorySize(0) { setFollowsAll(); setBorderVisible(FALSE); @@ -336,14 +343,13 @@ LLScriptEdCore::LLScriptEdCore( initMenu(); - // Do the work that addTabPanel() normally does. //LLRect tab_panel_rect( 0, mRect.getHeight(), mRect.getWidth(), 0 ); //tab_panel_rect.stretch( -LLPANEL_BORDER_WIDTH ); //mCodePanel->setFollowsAll(); //mCodePanel->translate( tab_panel_rect.mLeft - mCodePanel->getRect().mLeft, tab_panel_rect.mBottom - mCodePanel->getRect().mBottom); //mCodePanel->reshape( tab_panel_rect.getWidth(), tab_panel_rect.getHeight(), TRUE ); - + } LLScriptEdCore::~LLScriptEdCore() @@ -402,6 +408,9 @@ void LLScriptEdCore::initMenu() menuItem->setMenuCallback(onBtnHelp, this); menuItem->setEnabledCallback(NULL); + menuItem = LLUICtrlFactory::getMenuItemCallByName(this, "LSL Wiki Help..."); + menuItem->setMenuCallback(onBtnDynamicHelp, this); + menuItem->setEnabledCallback(NULL); } BOOL LLScriptEdCore::hasChanged(void* userdata) @@ -431,9 +440,135 @@ void LLScriptEdCore::draw() childSetText("line_col", ""); } + updateDynamicHelp(); + LLPanel::draw(); } +void LLScriptEdCore::updateDynamicHelp(BOOL immediate) +{ + LLFloater* help_floater = LLFloater::getFloaterByHandle(mLiveHelpHandle); + if (!help_floater) return; + + // update back and forward buttons + LLButton* fwd_button = LLUICtrlFactory::getButtonByName(help_floater, "fwd_btn"); + LLButton* back_button = LLUICtrlFactory::getButtonByName(help_floater, "back_btn"); + LLWebBrowserCtrl* browser = LLUICtrlFactory::getWebBrowserCtrlByName(help_floater, "lsl_guide_html"); + back_button->setEnabled(browser->canNavigateBack()); + fwd_button->setEnabled(browser->canNavigateForward()); + + if (!immediate && !gSavedSettings.getBOOL("ScriptHelpFollowsCursor")) + { + return; + } + + LLTextSegment* segment = NULL; + std::vector<LLTextSegment*> selected_segments; + mEditor->getSelectedSegments(selected_segments); + + // try segments in selection range first + std::vector<LLTextSegment*>::iterator segment_iter; + for (segment_iter = selected_segments.begin(); segment_iter != selected_segments.end(); ++segment_iter) + { + if((*segment_iter)->getToken() && (*segment_iter)->getToken()->getType() == LLKeywordToken::WORD) + { + segment = *segment_iter; + break; + } + } + + // then try previous segment in case we just typed it + if (!segment) + { + LLTextSegment* test_segment = mEditor->getPreviousSegment(); + if(test_segment->getToken() && test_segment->getToken()->getType() == LLKeywordToken::WORD) + { + segment = test_segment; + } + } + + if (segment) + { + if (segment->getToken() != mLastHelpToken) + { + mLastHelpToken = segment->getToken(); + mLiveHelpTimer.start(); + } + if (immediate || (mLiveHelpTimer.getStarted() && mLiveHelpTimer.getElapsedTimeF32() > LIVE_HELP_REFRESH_TIME)) + { + LLString help_string = mEditor->getText().substr(segment->getStart(), segment->getEnd() - segment->getStart()); + setHelpPage(help_string); + mLiveHelpTimer.stop(); + } + } + else + { + setHelpPage(""); + } +} + +void LLScriptEdCore::setHelpPage(const LLString& help_string) +{ + LLFloater* help_floater = LLFloater::getFloaterByHandle(mLiveHelpHandle); + if (!help_floater) return; + + LLWebBrowserCtrl* web_browser = gUICtrlFactory->getWebBrowserCtrlByName(help_floater, "lsl_guide_html"); + if (!web_browser) return; + + LLComboBox* history_combo = gUICtrlFactory->getComboBoxByName(help_floater, "history_combo"); + if (!history_combo) return; + + LLUIString url_string = gSavedSettings.getString("LSLHelpURL"); + url_string.setArg("[APP_DIRECTORY]", gDirUtilp->getWorkingDir()); + url_string.setArg("[LSL_STRING]", help_string); + + addHelpItemToHistory(help_string); + web_browser->navigateTo(url_string); +} + +void LLScriptEdCore::addHelpItemToHistory(const LLString& help_string) +{ + if (help_string.empty()) return; + + LLFloater* help_floater = LLFloater::getFloaterByHandle(mLiveHelpHandle); + if (!help_floater) return; + + LLComboBox* history_combo = gUICtrlFactory->getComboBoxByName(help_floater, "history_combo"); + if (!history_combo) return; + + // separate history items from full item list + if (mLiveHelpHistorySize == 0) + { + LLSD row; + row["columns"][0]["type"] = "separator"; + history_combo->addElement(row, ADD_TOP); + } + // delete all history items over history limit + while(mLiveHelpHistorySize > MAX_HISTORY_COUNT - 1) + { + history_combo->remove(mLiveHelpHistorySize - 1); + mLiveHelpHistorySize--; + } + + history_combo->setSimple(help_string); + S32 index = history_combo->getCurrentIndex(); + + // if help string exists in the combo box + if (index >= 0) + { + S32 cur_index = history_combo->getCurrentIndex(); + if (cur_index < mLiveHelpHistorySize) + { + // item found in history, bubble up to top + history_combo->remove(history_combo->getCurrentIndex()); + mLiveHelpHistorySize--; + } + } + history_combo->add(help_string, LLSD(help_string), ADD_TOP); + history_combo->selectFirstItem(); + mLiveHelpHistorySize++; +} + BOOL LLScriptEdCore::canClose() { if(mForceClose || mEditor->isPristine()) @@ -498,6 +633,92 @@ void LLScriptEdCore::onBtnHelp(void* userdata) } // static +void LLScriptEdCore::onBtnDynamicHelp(void* userdata) +{ + LLScriptEdCore* corep = (LLScriptEdCore*)userdata; + + LLFloater* live_help_floater = LLFloater::getFloaterByHandle(corep->mLiveHelpHandle); + if (live_help_floater) + { + live_help_floater->setFocus(TRUE); + corep->updateDynamicHelp(TRUE); + + return; + } + + live_help_floater = new LLFloater("lsl_help"); + gUICtrlFactory->buildFloater(live_help_floater, "floater_lsl_guide.xml"); + ((LLFloater*)corep->getParent())->addDependentFloater(live_help_floater, TRUE); + live_help_floater->childSetCommitCallback("lock_check", onCheckLock, userdata); + live_help_floater->childSetValue("lock_check", gSavedSettings.getBOOL("ScriptHelpFollowsCursor")); + live_help_floater->childSetCommitCallback("history_combo", onHelpComboCommit, userdata); + live_help_floater->childSetAction("back_btn", onClickBack, userdata); + live_help_floater->childSetAction("fwd_btn", onClickForward, userdata); + + LLWebBrowserCtrl* browser = LLUICtrlFactory::getWebBrowserCtrlByName(live_help_floater, "lsl_guide_html"); + browser->setAlwaysRefresh(TRUE); + + LLComboBox* help_combo = LLUICtrlFactory::getComboBoxByName(live_help_floater, "history_combo"); + LLKeywordToken *token; + LLKeywords::word_token_map_t::iterator token_it; + for (token_it = corep->mEditor->mKeywords.mWordTokenMap.begin(); + token_it != corep->mEditor->mKeywords.mWordTokenMap.end(); + ++token_it) + { + token = token_it->second; + help_combo->add(wstring_to_utf8str(token->mToken)); + } + help_combo->sortByName(); + + // re-initialize help variables + corep->mLastHelpToken = NULL; + corep->mLiveHelpHandle = live_help_floater->getHandle(); + corep->mLiveHelpHistorySize = 0; + corep->updateDynamicHelp(TRUE); +} + +//static +void LLScriptEdCore::onClickBack(void* userdata) +{ + LLScriptEdCore* corep = (LLScriptEdCore*)userdata; + LLFloater* live_help_floater = LLFloater::getFloaterByHandle(corep->mLiveHelpHandle); + if (live_help_floater) + { + LLWebBrowserCtrl* browserp = LLUICtrlFactory::getWebBrowserCtrlByName(live_help_floater, "lsl_guide_html"); + if (browserp) + { + browserp->navigateBack(); + } + } +} + +//static +void LLScriptEdCore::onClickForward(void* userdata) +{ + LLScriptEdCore* corep = (LLScriptEdCore*)userdata; + LLFloater* live_help_floater = LLFloater::getFloaterByHandle(corep->mLiveHelpHandle); + if (live_help_floater) + { + LLWebBrowserCtrl* browserp = LLUICtrlFactory::getWebBrowserCtrlByName(live_help_floater, "lsl_guide_html"); + if (browserp) + { + browserp->navigateForward(); + } + } +} + +// static +void LLScriptEdCore::onCheckLock(LLUICtrl* ctrl, void* userdata) +{ + LLScriptEdCore* corep = (LLScriptEdCore*)userdata; + + // clear out token any time we lock the frame, so we will refresh web page immediately when unlocked + gSavedSettings.setBOOL("ScriptHelpFollowsCursor", ctrl->getValue().asBoolean()); + + corep->mLastHelpToken = NULL; +} + +// static void LLScriptEdCore::onBtnInsertSample(void* userdata) { LLScriptEdCore* self = (LLScriptEdCore*) userdata; @@ -509,6 +730,27 @@ void LLScriptEdCore::onBtnInsertSample(void* userdata) } // static +void LLScriptEdCore::onHelpComboCommit(LLUICtrl* ctrl, void* userdata) +{ + LLScriptEdCore* corep = (LLScriptEdCore*)userdata; + + LLFloater* live_help_floater = LLFloater::getFloaterByHandle(corep->mLiveHelpHandle); + if (live_help_floater) + { + LLWebBrowserCtrl* web_browser = gUICtrlFactory->getWebBrowserCtrlByName(live_help_floater, "lsl_guide_html"); + + LLString help_string = ctrl->getValue().asString(); + + corep->addHelpItemToHistory(help_string); + + LLUIString url_string = gSavedSettings.getString("LSLHelpURL"); + url_string.setArg("[APP_DIRECTORY]", gDirUtilp->getWorkingDir()); + url_string.setArg("[LSL_STRING]", help_string); + web_browser->navigateTo(url_string); + } +} + +// static void LLScriptEdCore::onBtnInsertFunction(LLUICtrl *ui, void* userdata) { LLScriptEdCore* self = (LLScriptEdCore*) userdata; @@ -519,6 +761,7 @@ void LLScriptEdCore::onBtnInsertFunction(LLUICtrl *ui, void* userdata) self->mEditor->insertText(self->mFunctions->getSimple()); } self->mEditor->setFocus(TRUE); + self->setHelpPage(self->mFunctions->getSimple()); } // static diff --git a/indra/newview/llpreviewscript.h b/indra/newview/llpreviewscript.h index 5b15fda222..54b27316f7 100644 --- a/indra/newview/llpreviewscript.h +++ b/indra/newview/llpreviewscript.h @@ -15,6 +15,7 @@ #include "llinventory.h" #include "llcombobox.h" #include "lliconctrl.h" +#include "llframetimer.h" class LLMessageSystem; @@ -26,6 +27,7 @@ class LLViewerObject; struct LLEntryAndEdCore; class LLMenuBarGL; class LLFloaterScriptSearch; +class LLKeywordToken; // Inner, implementation class. LLPreviewScript and LLLiveScriptEditor each own one of these. class LLScriptEdCore : public LLPanel @@ -60,6 +62,11 @@ public: static void onHelpWebDialog(S32 option, void* userdata); static void onBtnHelp(void* userdata); + static void onBtnDynamicHelp(void* userdata); + static void onCheckLock(LLUICtrl*, void*); + static void onHelpComboCommit(LLUICtrl* ctrl, void* userdata); + static void onClickBack(void* userdata); + static void onClickForward(void* userdata); static void onBtnInsertSample(void*); static void onBtnInsertFunction(LLUICtrl*, void*); static void doSave( void* userdata, BOOL close_after_save ); @@ -91,6 +98,9 @@ public: protected: void deleteBridges(); + void setHelpPage(const LLString& help_string); + void updateDynamicHelp(BOOL immediate = FALSE); + void addHelpItemToHistory(const LLString& help_string); static void onErrorList(LLUICtrl*, void* user_data); @@ -107,6 +117,10 @@ private: LLPanel* mCodePanel; LLScrollListCtrl* mErrorList; LLDynamicArray<LLEntryAndEdCore*> mBridges; + LLViewHandle mLiveHelpHandle; + LLKeywordToken* mLastHelpToken; + LLFrameTimer mLiveHelpTimer; + S32 mLiveHelpHistorySize; }; |