diff options
author | Vadim ProductEngine <vsavchuk@productengine.com> | 2011-04-06 01:48:07 +0300 |
---|---|---|
committer | Vadim ProductEngine <vsavchuk@productengine.com> | 2011-04-06 01:48:07 +0300 |
commit | 1218ffb000289954cbbbf7fc5c62e494c85f1ede (patch) | |
tree | 0c94630cfb1e66ef70f599a25f6471913599920d /indra | |
parent | 318752fe3df9ef86d3735fc0ef935d27ac3d5f7d (diff) |
STORM-1028 WIP Fixing bottom bar buttons reshaping, tier 3
* Rewritten some code for better readability. Behavior should not be affected.
* Debug prints and other minor changes.
Diffstat (limited to 'indra')
-rw-r--r-- | indra/newview/llbottomtray.cpp | 157 | ||||
-rw-r--r-- | indra/newview/llbottomtray.h | 11 |
2 files changed, 100 insertions, 68 deletions
diff --git a/indra/newview/llbottomtray.cpp b/indra/newview/llbottomtray.cpp index 838b072fd3..a206724cd0 100644 --- a/indra/newview/llbottomtray.cpp +++ b/indra/newview/llbottomtray.cpp @@ -917,7 +917,7 @@ void LLBottomTray::log(LLView* panel, const std::string& descr) << ", rect: " << panel->getRect() - << "layout: " << layout->getName() + << " layout: " << layout->getName() << ", rect: " << layout->getRect() << llendl ; @@ -1023,6 +1023,7 @@ void LLBottomTray::reshape(S32 width, S32 height, BOOL called_from_parent) { mDesiredNearbyChatWidth = new_width; processChatbarCustomization(new_width); + lldebugs << "Setting nearby chat bar width to " << new_width << " px" << llendl; mChatBarContainer->reshape(new_width, mChatBarContainer->getRect().getHeight()); } needs_restore_custom_state = false; @@ -1034,29 +1035,27 @@ S32 LLBottomTray::processWidthDecreased(S32 delta_width) { bool still_should_be_processed = true; - const S32 chiclet_panel_width = mChicletPanel->getParent()->getRect().getWidth(); - const S32 chiclet_panel_min_width = mChicletPanel->getMinWidth(); + const S32 chiclet_panel_shrink_headrom = getChicletPanelShrinkHeadroom(); // There are four steps of processing width decrease. If in one of them required width was reached, // further are not needed. // 1. Decreasing width of chiclet panel. - if (chiclet_panel_width > chiclet_panel_min_width) + if (chiclet_panel_shrink_headrom > 0) { // we have some space to decrease chiclet panel - S32 panel_delta_min = chiclet_panel_width - chiclet_panel_min_width; - - S32 delta_panel = llmin(-delta_width, panel_delta_min); + S32 delta_panel = llmin(-delta_width, chiclet_panel_shrink_headrom); lldebugs << "delta_width: " << delta_width - << ", panel_delta_min: " << panel_delta_min + << ", panel_delta_min: " << chiclet_panel_shrink_headrom << ", delta_panel: " << delta_panel << llendl; // is chiclet panel width enough to process resizing? - delta_width += panel_delta_min; + delta_width += chiclet_panel_shrink_headrom; still_should_be_processed = delta_width < 0; + lldebugs << "Shrinking chiclet panel by " << delta_panel << " px" << llendl; mChicletPanel->getParent()->reshape(mChicletPanel->getParent()->getRect().getWidth() - delta_panel, mChicletPanel->getParent()->getRect().getHeight()); log(mChicletPanel, "after processing panel decreasing via chiclet panel"); @@ -1089,6 +1088,7 @@ S32 LLBottomTray::processWidthDecreased(S32 delta_width) // chatbar should only be shrunk here, not stretched if(delta_panel > 0) { + lldebugs << "Shrinking nearby chat bar by " << delta_panel << " px " << llendl; mChatBarContainer->reshape(mNearbyChatBar->getRect().getWidth() - delta_panel, mChatBarContainer->getRect().getHeight()); } @@ -1120,6 +1120,7 @@ S32 LLBottomTray::processWidthDecreased(S32 delta_width) { S32 compensative_width = nearby_needed_width > buttons_freed_width ? buttons_freed_width : nearby_needed_width; log(mNearbyChatBar, "before applying compensative width"); + lldebugs << "Extending nearby chat bar by " << compensative_width << " px" << llendl; mChatBarContainer->reshape(mChatBarContainer->getRect().getWidth() + compensative_width, mChatBarContainer->getRect().getHeight() ); log(mNearbyChatBar, "after applying compensative width"); lldebugs << buttons_freed_width << llendl; @@ -1134,52 +1135,45 @@ void LLBottomTray::processWidthIncreased(S32 delta_width) { if (delta_width <= 0) return; - const S32 chiclet_panel_width = mChicletPanel->getParent()->getRect().getWidth(); - static const S32 chiclet_panel_min_width = mChicletPanel->getMinWidth(); - - const S32 available_width_chiclet = chiclet_panel_width - chiclet_panel_min_width; - - // how many room we have to show hidden buttons - S32 total_available_width = delta_width + available_width_chiclet; + // how much room we have to show hidden buttons + S32 available_width = delta_width + getChicletPanelShrinkHeadroom(); - lldebugs << "Processing extending, available width:" - << ", chiclets - " << available_width_chiclet - << ", total - " << total_available_width - << llendl; + lldebugs << "Distributing (" << getChicletPanelShrinkHeadroom() + << " + " << delta_width << ") = " << available_width << " px" << llendl; - S32 available_width = total_available_width; + S32 processed_width = processShowButtons(available_width); + lldebugs << "processed_width = " << processed_width << ", delta_width = " << delta_width << llendl; - processShowButtons(available_width); + lldebugs << "Available_width after showing buttons: " << available_width << llendl; // if we have to show/extend some buttons but resized delta width is not enough... - S32 processed_width = total_available_width - available_width; if (processed_width > delta_width) { // ... let's shrink nearby chat & chiclet panels - S32 required_to_process_width = processed_width; - // 1. use delta width of resizing - required_to_process_width -= delta_width; + S32 shrink_by = processed_width - delta_width; // 2. use width available via decreasing of chiclet panel - if (required_to_process_width > 0) + if (shrink_by > 0) { - mChicletPanel->getParent()->reshape(mChicletPanel->getParent()->getRect().getWidth() - required_to_process_width, mChicletPanel->getParent()->getRect().getHeight()); + lldebugs << "Shrinking chiclet panel by " << shrink_by << " px" << llendl; + mChicletPanel->getParent()->reshape(mChicletPanel->getParent()->getRect().getWidth() - shrink_by, mChicletPanel->getParent()->getRect().getHeight()); log(mChicletPanel, "after applying compensative width for chiclets: "); - lldebugs << required_to_process_width << llendl; + lldebugs << shrink_by << llendl; } - } // shown buttons take some space, rest should be processed by nearby chatbar & chiclet panels delta_width -= processed_width; - - // how many space can nearby chatbar take? - S32 chatbar_panel_width_ = mChatBarContainer->getRect().getWidth(); - if (delta_width > 0 && chatbar_panel_width_ < mDesiredNearbyChatWidth) + // how much space can nearby chatbar take? + S32 chatbar_panel_width = mChatBarContainer->getRect().getWidth(); + lldebugs << "delta_width = " << delta_width + << ", chatbar_panel_width = " << chatbar_panel_width + << ", mDesiredNearbyChatWidth = " << mDesiredNearbyChatWidth << llendl; + if (delta_width > 0 && chatbar_panel_width < mDesiredNearbyChatWidth) { - S32 delta_panel_max = mDesiredNearbyChatWidth - chatbar_panel_width_; + S32 delta_panel_max = mDesiredNearbyChatWidth - chatbar_panel_width; S32 delta_panel = llmin(delta_width, delta_panel_max); lldebugs << "Unprocesed delta width: " << delta_width << ", can be applied to chatbar: " << delta_panel_max @@ -1187,17 +1181,22 @@ void LLBottomTray::processWidthIncreased(S32 delta_width) << llendl; delta_width -= delta_panel_max; - mChatBarContainer->reshape(chatbar_panel_width_ + delta_panel, mChatBarContainer->getRect().getHeight()); + lldebugs << "Extending nearby chat bar by " << delta_panel << " px " << llendl; + mChatBarContainer->reshape(chatbar_panel_width + delta_panel, mChatBarContainer->getRect().getHeight()); log(mNearbyChatBar, "applied unprocessed delta width"); } + if (delta_width > 0) { processExtendButtons(delta_width); } } -void LLBottomTray::processShowButtons(S32& available_width) +S32 LLBottomTray::processShowButtons(S32& available_width) { + lldebugs << "Distributing " << available_width << " px" << llendl; + S32 original_available_width = available_width; + // process buttons from left to right resize_state_vec_t::const_iterator it = mButtonsProcessOrder.begin(); const resize_state_vec_t::const_iterator it_end = mButtonsProcessOrder.end(); @@ -1210,22 +1209,30 @@ void LLBottomTray::processShowButtons(S32& available_width) // try to show next button processShowButton(*it, available_width); } + + return original_available_width - available_width; } bool LLBottomTray::processShowButton(EResizeState shown_object_type, S32& available_width) { - lldebugs << "Trying to show object type: " << shown_object_type << llendl; - LLPanel* panel = getButtonPanel(shown_object_type); if (NULL == panel) { - lldebugs << "There is no object to process for state: " << shown_object_type << llendl; return false; } + + if (panel->getVisible()) + { + return false; + } + + // We can only show a button if it was previously hidden due to lack of space + // and all buttons to the left of it are not auto-hidden + // (we auto-show the buttons left to right). bool can_be_shown = canButtonBeShown(shown_object_type); if (can_be_shown) { - //validate if we have enough room to show this button + // Make sure we have enough room to show this button. const S32 required_width = panel->getRect().getWidth(); can_be_shown = available_width >= required_width; if (can_be_shown) @@ -1234,11 +1241,16 @@ bool LLBottomTray::processShowButton(EResizeState shown_object_type, S32& availa setTrayButtonVisible(shown_object_type, true); - lldebugs << "processed object type: " << shown_object_type - << ", rest available width: " << available_width + lldebugs << "Showing button " << resizeStateToString(shown_object_type) + << ", remaining available width: " << available_width << llendl; mResizeState &= ~shown_object_type; } + else + { + lldebugs << "Need " << (required_width - available_width) << " more px to show " + << resizeStateToString(shown_object_type) << llendl; + } } return can_be_shown; } @@ -1265,7 +1277,6 @@ void LLBottomTray::processHideButton(EResizeState processed_object_type, S32& re LLPanel* panel = getButtonPanel(processed_object_type); if (NULL == panel) { - lldebugs << "There is no object to process for state: " << processed_object_type << llendl; return; } @@ -1345,7 +1356,6 @@ void LLBottomTray::processShrinkButton(EResizeState processed_object_type, S32& LLPanel* panel = getButtonPanel(processed_object_type); if (NULL == panel) { - lldebugs << "There is no object to process for type: " << processed_object_type << llendl; return; } @@ -1470,38 +1480,32 @@ bool LLBottomTray::processExtendSpeakButton(S32& available_width) void LLBottomTray::processExtendButton(EResizeState processed_object_type, S32& available_width) { + llassert(available_width >= 0); + LLPanel* panel = getButtonPanel(processed_object_type); if (NULL == panel) { - lldebugs << "There is no object to process for type: " << processed_object_type << llendl; return; } if (!panel->getVisible()) return; + // Widen the button up to its maximum width, but by not more than <available_width> px. S32 panel_max_width = mObjectDefaultWidthMap[processed_object_type]; S32 panel_width = panel->getRect().getWidth(); - S32 possible_extend_width = panel_max_width - panel_width; + S32 required_headroom = panel_max_width - panel_width; - if (possible_extend_width > 0) + S32 extend_by = llmin(available_width, required_headroom); + if (extend_by > 0) { - // let calculate real width to extend - - // 1. apply all possible width - available_width -= possible_extend_width; + panel->reshape(panel_width + extend_by, panel->getRect().getHeight()); - // 2. it it is too much... - if (available_width < 0) - { - // reduce applied extended width to the excessive value. - possible_extend_width += available_width; - available_width = 0; - } - panel->reshape(panel_width + possible_extend_width, panel->getRect().getHeight()); + // Decrease amount of headroom available for other panels. + available_width -= extend_by; - lldebugs << "Extending panel: " << panel->getName() - << ", extended width: " << possible_extend_width - << ", rest width to process: " << available_width + lldebugs << "Extending " << panel->getName() + << " by " << extend_by + << " px; remaining available width: " << available_width << llendl; } } @@ -1510,6 +1514,13 @@ bool LLBottomTray::canButtonBeShown(EResizeState processed_object_type) const { // 0. Check if passed button was previously hidden on resize bool can_be_shown = mResizeState & processed_object_type; +#if 0 + if (!can_be_shown) + { + lldebugs << "Button " << resizeStateToString(processed_object_type) << " was not auto-hidden" << llendl; + } +#endif + if (can_be_shown) { // Yes, it was. Lets now check that all buttons before it (that can be hidden on resize) @@ -1531,6 +1542,15 @@ bool LLBottomTray::canButtonBeShown(EResizeState processed_object_type) const // 2. Check if some previous buttons are still hidden on resize can_be_shown = !(buttons_before_mask & mResizeState); +#if 0 + if (!can_be_shown) + { + lldebugs << llformat("mResizeState = 0x%4x, buttons_before_mask = 0x%4x", mResizeState, buttons_before_mask) << llendl; + lldebugs << "Auto-hidden: " << resizeStateMaskToString(mResizeState) << llendl; + lldebugs << "Must show the following buttons to the left of " << resizeStateToString(processed_object_type) << " first:" << llendl; + lldebugs << resizeStateMaskToString(buttons_before_mask & mResizeState) << llendl; + } +#endif } return can_be_shown; } @@ -1595,6 +1615,7 @@ void LLBottomTray::initButtonsVisibility() setVisibleAndFitWidths(RS_BUTTON_SEARCH, gSavedSettings.getBOOL("ShowSearchButton")); setVisibleAndFitWidths(RS_BUTTON_WORLD_MAP, gSavedSettings.getBOOL("ShowWorldMapButton")); setVisibleAndFitWidths(RS_BUTTON_MINI_MAP, gSavedSettings.getBOOL("ShowMiniMapButton")); + lldebugs << "mResizeState = " << resizeStateMaskToString(mResizeState) << llendl; } void LLBottomTray::setButtonsControlsAndListeners() @@ -1631,7 +1652,6 @@ void LLBottomTray::setTrayButtonVisible(EResizeState shown_object_type, bool vis LLPanel* panel = getButtonPanel(shown_object_type); if (NULL == panel) { - lldebugs << "There is no object to show for state: " << shown_object_type << llendl; return; } @@ -1662,7 +1682,6 @@ bool LLBottomTray::setVisibleAndFitWidths(EResizeState object_type, bool visible LLPanel* cur_panel = getButtonPanel(object_type); if (NULL == cur_panel) { - lldebugs << "There is no object to process for state: " << object_type << llendl; return false; } @@ -1671,8 +1690,7 @@ bool LLBottomTray::setVisibleAndFitWidths(EResizeState object_type, bool visible if (visible) { // Assume that only chiclet panel can be auto-resized - const S32 available_width = - mChicletPanel->getParent()->getRect().getWidth() - mChicletPanel->getMinWidth(); + const S32 available_width = getChicletPanelShrinkHeadroom(); S32 preferred_width = mObjectDefaultWidthMap[object_type]; S32 current_width = cur_panel->getRect().getWidth(); @@ -1812,6 +1830,11 @@ void LLBottomTray::processChatbarCustomization(S32 new_width) if (delta_width == 0) return; + { + static unsigned dbg_cnt = 0; + lldebugs << llformat("*** (%03d) ************************************* %d", delta_width, ++dbg_cnt) << llendl; + } + mDesiredNearbyChatWidth = new_width; const S32 available_chiclet_shrink_width = getChicletPanelShrinkHeadroom(); diff --git a/indra/newview/llbottomtray.h b/indra/newview/llbottomtray.h index f1c193ef16..7301551975 100644 --- a/indra/newview/llbottomtray.h +++ b/indra/newview/llbottomtray.h @@ -240,8 +240,9 @@ private: * * @params[in, out] available_width - reference to available width to be used to show buttons. * @see processShowButton() + * @return consumed pixels (difference in available width). */ - void processShowButtons(S32& available_width); + S32 processShowButtons(S32& available_width); /** * Tries to show panel with specified button using available width. @@ -431,9 +432,17 @@ private: */ void processChatbarCustomization(S32 new_width); + /** + * @return difference between current chiclet panel width and the minimum. + */ + S32 getChicletPanelShrinkHeadroom() const; + /// Get button name for debugging. static std::string resizeStateToString(EResizeState state); + /// Dump a mask for debugging + static std::string resizeStateMaskToString(MASK mask); + /// Buttons automatically hidden due to lack of space. MASK mResizeState; |