From 6a49f2947f05963c577a1644c16a8affc779da63 Mon Sep 17 00:00:00 2001 From: Richard Nelson Date: Wed, 28 Sep 2011 16:25:32 -0700 Subject: EXP-1234 WIP experimental drag and drop --- indra/llui/lltoolbar.cpp | 93 ++++++++++++++++++++++++++++++-------------- indra/llui/lltoolbar.h | 16 +++++++- indra/llui/lltoolbarview.cpp | 41 ++++++++++++++++++- indra/llui/lltoolbarview.h | 9 ++++- indra/llui/llview.h | 14 +++++++ 5 files changed, 140 insertions(+), 33 deletions(-) (limited to 'indra/llui') diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp index c5219b11e8..fe989cee22 100644 --- a/indra/llui/lltoolbar.cpp +++ b/indra/llui/lltoolbar.cpp @@ -33,6 +33,7 @@ #include "llcommandmanager.h" #include "llmenugl.h" #include "lltrans.h" +#include "lltoolbarview.h" // uncomment this and remove the one in llui.cpp when there is an external reference to this translation unit // thanks, MSVC! @@ -201,35 +202,27 @@ void LLToolBar::initFromParams(const LLToolBar::Params& p) bool LLToolBar::addCommand(const LLCommandId& commandId) { LLCommand * command = LLCommandManager::instance().getCommand(commandId); + if (!command) return false; - bool add_command = (command != NULL); - - if (add_command) - { - mButtonCommands.push_back(commandId); - createButton(commandId); - } + mButtonCommands.push_back(commandId); + LLToolBarButton* button = createButton(commandId); + mButtons.push_back(button); + mButtonPanel->addChild(button); + mButtonMap.insert(std::make_pair(commandId, button)); + mNeedsLayout = true; - return add_command; + return true; } bool LLToolBar::hasCommand(const LLCommandId& commandId) const { - bool has_command = false; - if (commandId != LLCommandId::null) { - BOOST_FOREACH(LLCommandId cmd, mButtonCommands) - { - if (cmd == commandId) - { - has_command = true; - break; - } - } + command_id_map::const_iterator it = mButtonMap.find(commandId); + return (it != mButtonMap.end()); } - return has_command; + return false; } bool LLToolBar::enableCommand(const LLCommandId& commandId, bool enabled) @@ -238,11 +231,10 @@ bool LLToolBar::enableCommand(const LLCommandId& commandId, bool enabled) if (commandId != LLCommandId::null) { - command_button = mButtonPanel->findChild(commandId.name()); - - if (command_button) + command_id_map::iterator it = mButtonMap.find(commandId); + if (it != mButtonMap.end()) { - command_button->setEnabled(enabled); + it->second->setEnabled(enabled); } } @@ -498,15 +490,19 @@ void LLToolBar::createButtons() BOOST_FOREACH(LLCommandId& command_id, mButtonCommands) { - createButton(command_id); + LLToolBarButton* button = createButton(command_id); + mButtons.push_back(button); + mButtonPanel->addChild(button); + mButtonMap.insert(std::make_pair(command_id, button)); } + mNeedsLayout = true; } -void LLToolBar::createButton(const LLCommandId& id) +LLToolBarButton* LLToolBar::createButton(const LLCommandId& id) { LLCommand* commandp = LLCommandManager::instance().getCommand(id); - if (!commandp) return; + if (!commandp) return NULL; LLToolBarButton::Params button_p; button_p.label = LLTrans::getString(commandp->labelRef()); @@ -515,8 +511,47 @@ void LLToolBar::createButton(const LLCommandId& id) button_p.overwriteFrom(mButtonParams[mButtonType]); LLToolBarButton* button = LLUICtrlFactory::create(button_p); - mButtons.push_back(button); - mButtonPanel->addChild(button); + button->setCommandId(id); + return button; +} - mNeedsLayout = true; +// +// LLToolBarButton +// + +LLToolBarButton::LLToolBarButton(const Params& p) +: LLButton(p), + mMouseDownX(0), + mMouseDownY(0), + mId("") +{} + + +BOOL LLToolBarButton::handleMouseDown(S32 x, S32 y, MASK mask) +{ + mMouseDownX = x; + mMouseDownY = y; + return LLButton::handleMouseDown(x, y, mask); +} + +BOOL LLToolBarButton::handleHover(S32 x, S32 y, MASK mask) +{ + if (hasMouseCapture()) + { + S32 dist_squared = (x - mMouseDownX) * (x - mMouseDownX) + (y - mMouseDownY) * (y - mMouseDownY); + S32 threshold = LLUI::sSettingGroups["config"]->getS32("DragAndDropDistanceThreshold"); + S32 threshold_squared = threshold * threshold; + if (dist_squared > threshold_squared) + { + // start drag and drop + LLToolBarView* view = getParentByType(); + LLToolBar* bar = getParentByType(); + if (view) + { + view->startDrag(bar->createButton(mId)); + setVisible(FALSE); + } + } + } + return LLButton::handleHover(x, y, mask); } diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h index 8e484c7e13..77bac87dbc 100644 --- a/indra/llui/lltoolbar.h +++ b/indra/llui/lltoolbar.h @@ -42,7 +42,15 @@ public: { }; - LLToolBarButton(const Params& p) : LLButton(p) {} + LLToolBarButton(const Params& p); + + BOOL handleMouseDown(S32 x, S32 y, MASK mask); + BOOL handleHover(S32 x, S32 y, MASK mask); + void setCommandId(const LLCommandId& id) { mId = id; } +private: + LLCommandId mId; + S32 mMouseDownX; + S32 mMouseDownY; }; @@ -125,6 +133,8 @@ public: bool enableCommand(const LLCommandId& commandId, bool enabled); command_id_list_t& getCommandsList() { return mButtonCommands; } + LLToolBarButton* createButton(const LLCommandId& id); + protected: friend class LLUICtrlFactory; LLToolBar(const Params&); @@ -136,7 +146,6 @@ private: void createContextMenu(); void updateLayoutAsNeeded(); void createButtons(); - void createButton(const LLCommandId& id); void resizeButtonsInRow(std::vector& buttons_in_row, S32 max_row_girth); BOOL isSettingChecked(const LLSD& userdata); void onSettingEnable(const LLSD& userdata); @@ -145,6 +154,9 @@ private: std::list mButtons; command_id_list_t mButtonCommands; + typedef std::map command_id_map; + command_id_map mButtonMap; + LLToolBarEnums::ButtonType mButtonType; LLLayoutStack* mCenteringStack; LLLayoutStack* mWrapStack; diff --git a/indra/llui/lltoolbarview.cpp b/indra/llui/lltoolbarview.cpp index b374a0bfc4..0c3a6bd0ac 100644 --- a/indra/llui/lltoolbarview.cpp +++ b/indra/llui/lltoolbarview.cpp @@ -55,7 +55,10 @@ LLToolBarView::LLToolBarView(const LLToolBarView::Params& p) : LLUICtrl(p), mToolbarLeft(NULL), mToolbarRight(NULL), - mToolbarBottom(NULL) + mToolbarBottom(NULL), + mDragButton(NULL), + mMouseX(0), + mMouseY(0) { } @@ -283,4 +286,40 @@ void LLToolBarView::draw() //gl_rect_2d(right_rect, back_color_vert, TRUE); LLUICtrl::draw(); + + if (mDragButton) + { + S32 cursor_x, cursor_y; + mDragButton->setOrigin(mMouseX - mDragButton->getRect().getWidth(), mMouseY - mDragButton->getRect().getHeight()); + drawChild(mDragButton); + } +} + +void LLToolBarView::startDrag(LLToolBarButton* button) +{ + mDragButton = button; + addChild(mDragButton); + gFocusMgr.setMouseCapture(this); +} + +BOOL LLToolBarView::handleHover(S32 x, S32 y, MASK mask) +{ + mMouseX = x; + mMouseY = y; + return LLUICtrl::handleHover(x, y, mask); +} + +BOOL LLToolBarView::handleMouseUp(S32 x, S32 y, MASK mask) +{ + if (hasMouseCapture()) + { + gFocusMgr.setMouseCapture(NULL); + } + return LLUICtrl::handleMouseUp(x, y, mask); +} + +void LLToolBarView::onMouseCaptureLost() +{ + delete mDragButton; + mDragButton = NULL; } diff --git a/indra/llui/lltoolbarview.h b/indra/llui/lltoolbarview.h index 646a1fd636..cbe3d6c083 100644 --- a/indra/llui/lltoolbarview.h +++ b/indra/llui/lltoolbarview.h @@ -65,7 +65,10 @@ public: virtual ~LLToolBarView(); virtual BOOL postBuild(); virtual void draw(); - + virtual BOOL handleHover(S32 x, S32 y, MASK mask); + virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask); + virtual void onMouseCaptureLost(); + void startDrag(LLToolBarButton*); // Toolbar view interface with the rest of the world bool hasCommand(const LLCommandId& commandId) const; @@ -85,6 +88,10 @@ private: LLToolBar* mToolbarLeft; LLToolBar* mToolbarRight; LLToolBar* mToolbarBottom; + bool mDragging; + LLToolBarButton* mDragButton; + S32 mMouseX; + S32 mMouseY; }; extern LLToolBarView* gToolBarView; diff --git a/indra/llui/llview.h b/indra/llui/llview.h index 9039366e7e..f4e31b109a 100644 --- a/indra/llui/llview.h +++ b/indra/llui/llview.h @@ -465,6 +465,20 @@ public: return dynamic_cast(widgetp); } + template T* getParentByType() const + { + LLView* parent = getParent(); + while(parent) + { + if (dynamic_cast(parent)) + { + return static_cast(parent); + } + parent = parent->getParent(); + } + return NULL; + } + ////////////////////////////////////////////// // statics ////////////////////////////////////////////// -- cgit v1.2.3 From 09e179b2381a4db03309839babae664feb9b0886 Mon Sep 17 00:00:00 2001 From: Richard Nelson Date: Fri, 30 Sep 2011 16:57:08 -0700 Subject: param block cleanup added Flag as value type moved Batch to BatchBlock renamed Choice to ChoiceBlock made merging of parameters for ValueParams consistent (fillFrom and overwriteFrom are inverses of each other now) made iteration over Multiple type params easier initial schema param blocks --- indra/llui/lllineeditor.h | 2 +- indra/llui/llloadingindicator.cpp | 7 +++---- indra/llui/llloadingindicator.h | 4 ++-- indra/llui/llnotifications.h | 4 ++-- indra/llui/llnotificationtemplate.h | 4 ++-- indra/llui/llnotificationvisibilityrule.h | 2 +- indra/llui/llscrolllistcolumn.h | 4 ++-- indra/llui/llsdparam.cpp | 6 +++--- indra/llui/llsdparam.h | 4 ++-- indra/llui/lltextbase.h | 2 +- indra/llui/lltoolbar.cpp | 6 +++--- indra/llui/lltoolbarview.h | 4 ---- indra/llui/llui.cpp | 4 +++- indra/llui/llui.h | 2 +- indra/llui/lluicolortable.h | 2 +- indra/llui/lluictrl.h | 4 ++-- indra/llui/lluictrlfactory.h | 6 +++--- indra/llui/llview.h | 2 +- 18 files changed, 33 insertions(+), 36 deletions(-) (limited to 'indra/llui') diff --git a/indra/llui/lllineeditor.h b/indra/llui/lllineeditor.h index 583bde360a..2518dbe3c7 100644 --- a/indra/llui/lllineeditor.h +++ b/indra/llui/lllineeditor.h @@ -60,7 +60,7 @@ public: typedef boost::function keystroke_callback_t; - struct MaxLength : public LLInitParam::Choice + struct MaxLength : public LLInitParam::ChoiceBlock { Alternative bytes, chars; diff --git a/indra/llui/llloadingindicator.cpp b/indra/llui/llloadingindicator.cpp index c4eec1835c..6ac38f5ad4 100644 --- a/indra/llui/llloadingindicator.cpp +++ b/indra/llui/llloadingindicator.cpp @@ -34,6 +34,7 @@ // Project includes #include "lluictrlfactory.h" #include "lluiimage.h" +#include "boost/foreach.hpp" // registered in llui.cpp to avoid being left out by MS linker //static LLDefaultChildRegistry::Register r("loading_indicator"); @@ -51,11 +52,9 @@ LLLoadingIndicator::LLLoadingIndicator(const Params& p) void LLLoadingIndicator::initFromParams(const Params& p) { - for (LLInitParam::ParamIterator::const_iterator it = p.images().image.begin(), end_it = p.images().image.end(); - it != end_it; - ++it) + BOOST_FOREACH(LLUIImage* image, p.images.image) { - mImages.push_back(it->getValue()); + mImages.push_back(image); } // Start timer for switching images. diff --git a/indra/llui/llloadingindicator.h b/indra/llui/llloadingindicator.h index 7c44478848..c1f979c111 100644 --- a/indra/llui/llloadingindicator.h +++ b/indra/llui/llloadingindicator.h @@ -51,7 +51,7 @@ class LLLoadingIndicator LOG_CLASS(LLLoadingIndicator); public: - struct Images : public LLInitParam::Block + struct Images : public LLInitParam::BatchBlock { Multiple image; @@ -63,7 +63,7 @@ public: struct Params : public LLInitParam::Block { Optional images_per_sec; - Batch images; + Optional images; Params() : images_per_sec("images_per_sec", 1.0f), diff --git a/indra/llui/llnotifications.h b/indra/llui/llnotifications.h index 0c4d4fc897..462d69be2e 100644 --- a/indra/llui/llnotifications.h +++ b/indra/llui/llnotifications.h @@ -201,7 +201,7 @@ public: FormInput(); }; - struct FormElement : public LLInitParam::Choice + struct FormElement : public LLInitParam::ChoiceBlock { Alternative button; Alternative input; @@ -312,7 +312,7 @@ public: Optional context; Optional responder; - struct Functor : public LLInitParam::Choice + struct Functor : public LLInitParam::ChoiceBlock { Alternative name; Alternative function; diff --git a/indra/llui/llnotificationtemplate.h b/indra/llui/llnotificationtemplate.h index ab777d37a5..fb50c9c123 100644 --- a/indra/llui/llnotificationtemplate.h +++ b/indra/llui/llnotificationtemplate.h @@ -91,7 +91,7 @@ struct LLNotificationTemplate // // as well as // ... - Flag dummy_val; + Optional dummy_val; public: Multiple contexts; @@ -147,7 +147,7 @@ struct LLNotificationTemplate {} }; - struct FormRef : public LLInitParam::Choice + struct FormRef : public LLInitParam::ChoiceBlock { Alternative form; Alternative form_template; diff --git a/indra/llui/llnotificationvisibilityrule.h b/indra/llui/llnotificationvisibilityrule.h index 78bdec2a8f..78788a275c 100644 --- a/indra/llui/llnotificationvisibilityrule.h +++ b/indra/llui/llnotificationvisibilityrule.h @@ -59,7 +59,7 @@ struct LLNotificationVisibilityRule {} }; - struct Rule : public LLInitParam::Choice + struct Rule : public LLInitParam::ChoiceBlock { Alternative show; Alternative hide; diff --git a/indra/llui/llscrolllistcolumn.h b/indra/llui/llscrolllistcolumn.h index 12baea8e0c..b4d4a6d05e 100644 --- a/indra/llui/llscrolllistcolumn.h +++ b/indra/llui/llscrolllistcolumn.h @@ -95,7 +95,7 @@ public: Optional sort_direction; Optional sort_ascending; - struct Width : public LLInitParam::Choice + struct Width : public LLInitParam::ChoiceBlock { Alternative dynamic_width; Alternative pixel_width; @@ -112,7 +112,7 @@ public: Optional width; // either an image or label is used in column header - struct Header : public LLInitParam::Choice
+ struct Header : public LLInitParam::ChoiceBlock
{ Alternative label; Alternative image; diff --git a/indra/llui/llsdparam.cpp b/indra/llui/llsdparam.cpp index 04919e6991..4b69360e33 100644 --- a/indra/llui/llsdparam.cpp +++ b/indra/llui/llsdparam.cpp @@ -45,7 +45,7 @@ LLParamSDParser::LLParamSDParser() if (sReadFuncs.empty()) { - registerParserFuncs(readNoValue, &LLParamSDParser::writeNoValue); + registerParserFuncs(readFlag, &LLParamSDParser::writeFlag); registerParserFuncs(readS32, &LLParamSDParser::writeTypedValue); registerParserFuncs(readU32, &LLParamSDParser::writeU32Param); registerParserFuncs(readF32, &LLParamSDParser::writeTypedValue); @@ -72,7 +72,7 @@ bool LLParamSDParser::writeU32Param(LLParamSDParser::parser_t& parser, const voi return true; } -bool LLParamSDParser::writeNoValue(LLParamSDParser::parser_t& parser, const void* val_ptr, const parser_t::name_stack_t& name_stack) +bool LLParamSDParser::writeFlag(LLParamSDParser::parser_t& parser, const void* val_ptr, const parser_t::name_stack_t& name_stack) { LLParamSDParser& sdparser = static_cast(parser); if (!sdparser.mWriteRootSD) return false; @@ -226,7 +226,7 @@ LLSD* LLParamSDParser::getSDWriteNode(const parser_t::name_stack_t& name_stack) return sd_to_write; } -bool LLParamSDParser::readNoValue(Parser& parser, void* val_ptr) +bool LLParamSDParser::readFlag(Parser& parser, void* val_ptr) { LLParamSDParser& self = static_cast(parser); return self.mCurReadSD == &NO_VALUE_MARKER; diff --git a/indra/llui/llsdparam.h b/indra/llui/llsdparam.h index f776c781b3..a371c28f68 100644 --- a/indra/llui/llsdparam.h +++ b/indra/llui/llsdparam.h @@ -63,9 +63,9 @@ private: LLSD* getSDWriteNode(const parser_t::name_stack_t& name_stack); static bool writeU32Param(Parser& parser, const void* value_ptr, const parser_t::name_stack_t& name_stack); - static bool writeNoValue(Parser& parser, const void* value_ptr, const parser_t::name_stack_t& name_stack); + static bool writeFlag(Parser& parser, const void* value_ptr, const parser_t::name_stack_t& name_stack); - static bool readNoValue(Parser& parser, void* val_ptr); + static bool readFlag(Parser& parser, void* val_ptr); static bool readS32(Parser& parser, void* val_ptr); static bool readU32(Parser& parser, void* val_ptr); static bool readF32(Parser& parser, void* val_ptr); diff --git a/indra/llui/lltextbase.h b/indra/llui/lltextbase.h index 7d545a1ba6..384d9116fc 100644 --- a/indra/llui/lltextbase.h +++ b/indra/llui/lltextbase.h @@ -237,7 +237,7 @@ public: friend class LLNormalTextSegment; friend class LLUICtrlFactory; - struct LineSpacingParams : public LLInitParam::Choice + struct LineSpacingParams : public LLInitParam::ChoiceBlock { Alternative multiple; Alternative pixels; diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp index caad896a06..d940bed905 100644 --- a/indra/llui/lltoolbar.cpp +++ b/indra/llui/lltoolbar.cpp @@ -185,7 +185,7 @@ void LLToolBar::initFromParams(const LLToolBar::Params& p) LLPanel::Params button_panel_p(p.button_panel); button_panel_p.rect = center_panel->getLocalRect(); - button_panel_p.follows.flags = FOLLOWS_BOTTOM|FOLLOWS_LEFT; + button_panel_p.follows.flags = FOLLOWS_BOTTOM|FOLLOWS_LEFT; mButtonPanel = LLUICtrlFactory::create(button_panel_p); center_panel->addChild(mButtonPanel); @@ -558,8 +558,8 @@ BOOL LLToolBarButton::handleHover(S32 x, S32 y, MASK mask) LLToolBar* bar = getParentByType(); if (view) { - view->startDrag(bar->createButton(mId)); - setVisible(FALSE); + //view->startDrag(bar->createButton(mId)); + //setVisible(FALSE); } } } diff --git a/indra/llui/lltoolbarview.h b/indra/llui/lltoolbarview.h index ea3422f04e..dd2bbf0e49 100644 --- a/indra/llui/lltoolbarview.h +++ b/indra/llui/lltoolbarview.h @@ -65,10 +65,6 @@ public: virtual ~LLToolBarView(); virtual BOOL postBuild(); virtual void draw(); - virtual BOOL handleHover(S32 x, S32 y, MASK mask); - virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask); - virtual void onMouseCaptureLost(); - void startDrag(LLToolBarButton*); // Toolbar view interface with the rest of the world // Checks if the commandId is being used somewhere in one of the toolbars bool hasCommand(const LLCommandId& commandId) const; diff --git a/indra/llui/llui.cpp b/indra/llui/llui.cpp index 4f129ccfba..76a12e649b 100644 --- a/indra/llui/llui.cpp +++ b/indra/llui/llui.cpp @@ -2107,7 +2107,7 @@ namespace LLInitParam void ParamValue >::updateValueFromBlock() { - if (control.isProvided()) + if (control.isProvided() && !control().empty()) { updateValue(LLUIColorTable::instance().getColor(control)); } @@ -2264,9 +2264,11 @@ namespace LLInitParam // in this case, that is left+width and bottom+height LLRect& value = getValue(); + right.set(value.mRight, false); left.set(value.mLeft, make_block_authoritative); width.set(value.getWidth(), make_block_authoritative); + top.set(value.mTop, false); bottom.set(value.mBottom, make_block_authoritative); height.set(value.getHeight(), make_block_authoritative); } diff --git a/indra/llui/llui.h b/indra/llui/llui.h index 7801a01ace..3afb7c65a9 100644 --- a/indra/llui/llui.h +++ b/indra/llui/llui.h @@ -365,7 +365,7 @@ template LLRegisterWith LLInitClass::sRegister( template LLRegisterWith LLDestroyClass::sRegister(&T::destroyClass); // useful parameter blocks -struct TimeIntervalParam : public LLInitParam::Choice +struct TimeIntervalParam : public LLInitParam::ChoiceBlock { Alternative seconds; Alternative frames; diff --git a/indra/llui/lluicolortable.h b/indra/llui/lluicolortable.h index 76518789ec..6a7a681d57 100644 --- a/indra/llui/lluicolortable.h +++ b/indra/llui/lluicolortable.h @@ -44,7 +44,7 @@ LOG_CLASS(LLUIColorTable); typedef std::map string_color_map_t; public: - struct ColorParams : LLInitParam::Choice + struct ColorParams : LLInitParam::ChoiceBlock { Alternative value; Alternative reference; diff --git a/indra/llui/lluictrl.h b/indra/llui/lluictrl.h index fc56e5fc35..a8a4e3191d 100644 --- a/indra/llui/lluictrl.h +++ b/indra/llui/lluictrl.h @@ -76,14 +76,14 @@ public: Optional function; }; - struct EnableControls : public LLInitParam::Choice + struct EnableControls : public LLInitParam::ChoiceBlock { Alternative enabled; Alternative disabled; EnableControls(); }; - struct ControlVisibility : public LLInitParam::Choice + struct ControlVisibility : public LLInitParam::ChoiceBlock { Alternative visible; Alternative invisible; diff --git a/indra/llui/lluictrlfactory.h b/indra/llui/lluictrlfactory.h index 71c38237c1..d612ad5005 100644 --- a/indra/llui/lluictrlfactory.h +++ b/indra/llui/lluictrlfactory.h @@ -125,12 +125,12 @@ private: // base case for recursion, there are NO base classes of LLInitParam::BaseBlock template - class ParamDefaults : public LLSingleton > + class ParamDefaults : public LLSingleton > { public: - const LLInitParam::BaseBlockWithFlags& get() { return mBaseBlock; } + const LLInitParam::BaseBlock& get() { return mBaseBlock; } private: - LLInitParam::BaseBlockWithFlags mBaseBlock; + LLInitParam::BaseBlock mBaseBlock; }; public: diff --git a/indra/llui/llview.h b/indra/llui/llview.h index f4e31b109a..a1c46f3bf3 100644 --- a/indra/llui/llview.h +++ b/indra/llui/llview.h @@ -98,7 +98,7 @@ private: class LLView : public LLMouseHandler, public LLMortician, public LLFocusableElement { public: - struct Follows : public LLInitParam::Choice + struct Follows : public LLInitParam::ChoiceBlock { Alternative string; Alternative flags; -- cgit v1.2.3