From d49c92b6fe8f3f96323c73fe7127d5f2d74d72b3 Mon Sep 17 00:00:00 2001 From: Beeks Date: Thu, 16 Sep 2010 22:08:33 -0400 Subject: [PATCH] I got bored and put in the math functions from Imprudence. We need something to show the list - Preferably a bit better than the popup that they use, I'm thinking maybe an expanding sidebar on the build menu? Oh, minor changes - Texture repeats go up to 1000 now because it has numbers, and I tweaked the primitive params section so it doesn't fall off the window. Signed-off-by: Beeks --- indra/llui/lllineeditor.cpp | 41 +- indra/llui/lllineeditor.h | 4 + indra/llui/llspinctrl.cpp | 37 +- indra/llui/llspinctrl.h | 2 + indra/newview/llfloatertools.cpp | 4 +- indra/newview/llpanelobject.cpp | 16 +- indra/newview/llpanelobject.h | 2 +- .../skins/default/xui/en-us/floater_tools.xml | 407 +++++++++--------- .../skins/default/xui/en-us/notifications.xml | 55 +++ 9 files changed, 350 insertions(+), 218 deletions(-) diff --git a/indra/llui/lllineeditor.cpp b/indra/llui/lllineeditor.cpp index 3b47d5f1b..adf4c612e 100644 --- a/indra/llui/lllineeditor.cpp +++ b/indra/llui/lllineeditor.cpp @@ -42,6 +42,7 @@ #include "llgl.h" #include "lltimer.h" +#include "llcalc.h" //#include "llclipboard.h" #include "llcontrol.h" #include "llbutton.h" @@ -130,6 +131,7 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, mDrawAsterixes( FALSE ), mHandleEditKeysDirectly( FALSE ), mSelectAllonFocusReceived( FALSE ), + mSelectAllonCommit( TRUE ), mPassDelete(FALSE), mReadOnly(FALSE), mHaveHistory(FALSE), @@ -223,7 +225,10 @@ void LLLineEditor::onCommit() updateHistory(); LLUICtrl::onCommit(); - selectAll(); + + // Selection on commit needs to be turned off when evaluating maths + // expressions, to allow indication of the error position + if (mSelectAllonCommit) selectAll(); } @@ -2164,6 +2169,40 @@ BOOL LLLineEditor::prevalidateASCII(const LLWString &str) return rv; } +BOOL LLLineEditor::evaluateFloat() +{ + bool success = false; + std::string expr = getText(); + + // user deleted the contents, nothing to evaluate -- MC + if (expr.empty()) + { + return success; + } + else + { + F32 result = 0.f; + success = LLCalc::getInstance()->evalString(expr, result); + + if (!success) + { + // Move the cursor to near the error on failure + setCursor(LLCalc::getInstance()->getLastErrorPos()); + // *TODO: Translated error message indicating the type of error? Select error text? + } + else + { + // Replace the expression with the result + std::ostringstream result_str; + result_str << result; + setText(result_str.str()); + selectAll(); + } + + return success; + } +} + void LLLineEditor::onMouseCaptureLost() { endSelection(); diff --git a/indra/llui/lllineeditor.h b/indra/llui/lllineeditor.h index c7227da43..da6d57f0f 100644 --- a/indra/llui/lllineeditor.h +++ b/indra/llui/lllineeditor.h @@ -195,6 +195,7 @@ public: void setHandleEditKeysDirectly( BOOL b ) { mHandleEditKeysDirectly = b; } void setSelectAllonFocusReceived(BOOL b); + void setSelectAllonCommit(BOOL b) { mSelectAllonCommit = b; } void setKeystrokeCallback(void (*keystroke_callback)(LLLineEditor* caller, void* user_data)); @@ -214,6 +215,8 @@ public: static BOOL prevalidateASCII(const LLWString &str); static BOOL postvalidateFloat(const std::string &str); + + BOOL evaluateFloat(); // line history support: void setEnableLineHistory( BOOL enabled ) { mHaveHistory = enabled; } // switches line history on or off @@ -307,6 +310,7 @@ protected: BOOL mHandleEditKeysDirectly; // If true, the standard edit keys (Ctrl-X, Delete, etc,) are handled here instead of routed by the menu system BOOL mSelectAllonFocusReceived; + BOOL mSelectAllonCommit; BOOL mPassDelete; BOOL mReadOnly; diff --git a/indra/llui/llspinctrl.cpp b/indra/llui/llspinctrl.cpp index 09a82b25b..717604670 100644 --- a/indra/llui/llspinctrl.cpp +++ b/indra/llui/llspinctrl.cpp @@ -123,7 +123,7 @@ LLSpinCtrl::LLSpinCtrl( const std::string& name, const LLRect& rect, const std:: mEditor = new LLLineEditor( std::string("SpinCtrl Editor"), editor_rect, LLStringUtil::null, font, MAX_STRING_LENGTH, &LLSpinCtrl::onEditorCommit, NULL, NULL, this, - &LLLineEditor::prevalidateFloat ); + &LLLineEditor::prevalidateASCII ); mEditor->setFollowsLeft(); mEditor->setFollowsBottom(); mEditor->setFocusReceivedCallback( &LLSpinCtrl::onEditorGainFocus, this ); @@ -132,6 +132,7 @@ LLSpinCtrl::LLSpinCtrl( const std::string& name, const LLRect& rect, const std:: // it's easier to understand //mEditor->setSelectAllonFocusReceived(TRUE); mEditor->setIgnoreTab(TRUE); + mEditor->setSelectAllonCommit(FALSE); addChild(mEditor); updateEditor(); @@ -292,9 +293,10 @@ void LLSpinCtrl::onEditorCommit( LLUICtrl* caller, void *userdata ) LLSpinCtrl* self = (LLSpinCtrl*) userdata; llassert( caller == self->mEditor ); - std::string text = self->mEditor->getText(); - if( LLLineEditor::postvalidateFloat( text ) ) + if( self->mEditor->evaluateFloat() ) { + std::string text = self->mEditor->getText(); + LLLocale locale(LLLocale::USER_LOCALE); F32 val = (F32) atof(text.c_str()); @@ -322,9 +324,17 @@ void LLSpinCtrl::onEditorCommit( LLUICtrl* caller, void *userdata ) success = TRUE; } } - self->updateEditor(); + else + { + // We want to update the editor in case it fails while blanking -- MC + success = TRUE; + } - if( !success ) + if( success ) + { + self->updateEditor(); + } + else { self->reportInvalidData(); } @@ -396,6 +406,18 @@ void LLSpinCtrl::setLabel(const LLStringExplicit& label) } } +BOOL LLSpinCtrl::setLabelArg( const std::string& key, const LLStringExplicit& text ) +{ + if (mLabelBox) + { + BOOL res = mLabelBox->setTextArg(key, text); + reshape(getRect().getWidth(), getRect().getHeight(), FALSE); + return res; + } + return FALSE; +} + + void LLSpinCtrl::setAllowEdit(BOOL allow_edit) { mEditor->setEnabled(allow_edit); @@ -463,6 +485,11 @@ BOOL LLSpinCtrl::handleKeyHere(KEY key, MASK mask) LLSpinCtrl::onDownBtn(this); return TRUE; } + if(key == KEY_RETURN) + { + forceEditorCommit(); + return TRUE; + } } return FALSE; } diff --git a/indra/llui/llspinctrl.h b/indra/llui/llspinctrl.h index dfd0eb3ac..b9d94e57c 100644 --- a/indra/llui/llspinctrl.h +++ b/indra/llui/llspinctrl.h @@ -116,6 +116,8 @@ public: static void onUpBtn(void *userdata); static void onDownBtn(void *userdata); + virtual BOOL setLabelArg( const std::string& key, const LLStringExplicit& text ); + private: void updateEditor(); void reportInvalidData(); diff --git a/indra/newview/llfloatertools.cpp b/indra/newview/llfloatertools.cpp index 35d87e393..613c5001e 100644 --- a/indra/newview/llfloatertools.cpp +++ b/indra/newview/llfloatertools.cpp @@ -281,7 +281,9 @@ BOOL LLFloaterTools::postBuild() { found->setClickedCallback(setObjectType,toolData[t]); mButtons.push_back( found ); - }else{ + } + else + { llwarns << "Tool button not found! DOA Pending." << llendl; } } diff --git a/indra/newview/llpanelobject.cpp b/indra/newview/llpanelobject.cpp index eba90c89d..19b07ee09 100644 --- a/indra/newview/llpanelobject.cpp +++ b/indra/newview/llpanelobject.cpp @@ -143,6 +143,9 @@ BOOL LLPanelObject::postBuild() // Top //-------------------------------------------------------- + // Build constant tipsheet + childSetAction("build_math_constants",onClickBuildConstants,this); + // Lock checkbox mCheckLock = getChild("checkbox locked"); childSetCommitCallback("checkbox locked",onCommitLock,this); @@ -473,6 +476,7 @@ void LLPanelObject::getState( ) BOOL enable_scale = objectp->permMove() && objectp->permModify(); BOOL enable_rotate = objectp->permMove() && ( (objectp->permModify() && !objectp->isAttachment()) || !gSavedSettings.getBOOL("EditLinkedParts")); BOOL enable_link = objectp->permMove() && !objectp->isAttachment() && (objectp->permModify() || !gSavedSettings.getBOOL("EditLinkedParts")); + childSetEnabled("build_math_constants",true); S32 selected_count = LLSelectMgr::getInstance()->getSelection()->getObjectCount(); BOOL single_volume = (LLSelectMgr::getInstance()->selectionAllPCode( LL_PCODE_VOLUME )) && (selected_count == 1); @@ -901,8 +905,8 @@ void LLPanelObject::getState( ) F32 end_t = volume_params.getEndT(); // Hollowness - F32 hollow = volume_params.getHollow(); - mSpinHollow->set( 100.f * hollow ); + F32 hollow = 100.f * volume_params.getHollow(); + mSpinHollow->set( hollow ); calcp->setVar(LLCalc::HOLLOW, hollow); // All hollow objects allow a shape to be selected. if (hollow > 0.f) @@ -2382,6 +2386,8 @@ void LLPanelObject::clearCtrls() childSetEnabled("advanced_cut", FALSE); childSetEnabled("advanced_dimple", FALSE); childSetVisible("advanced_slice", FALSE); + + childSetEnabled("build_math_constants",false); } // @@ -2521,6 +2527,12 @@ void LLPanelObject::onCommitSculptType(LLUICtrl *ctrl, void* userdata) self->sendSculpt(); } +// static +void LLPanelObject::onClickBuildConstants(void *) +{ + LLNotifications::instance().add("ClickBuildConstants"); +} + std::string shortfloat(F32 in) { std::string out = llformat("%f", in); diff --git a/indra/newview/llpanelobject.h b/indra/newview/llpanelobject.h index daa13412b..05d339d3a 100644 --- a/indra/newview/llpanelobject.h +++ b/indra/newview/llpanelobject.h @@ -98,7 +98,7 @@ public: static BOOL onDropSculpt( LLUICtrl* ctrl, LLInventoryItem* item, void* ud); static void onCommitSculptType( LLUICtrl *ctrl, void* userdata); - + static void onClickBuildConstants(void *); static const LLUUID& findItemID(const LLUUID& asset_id); protected: diff --git a/indra/newview/skins/default/xui/en-us/floater_tools.xml b/indra/newview/skins/default/xui/en-us/floater_tools.xml index 080ae6477..560a6a214 100644 --- a/indra/newview/skins/default/xui/en-us/floater_tools.xml +++ b/indra/newview/skins/default/xui/en-us/floater_tools.xml @@ -8,89 +8,84 @@