summaryrefslogtreecommitdiff
path: root/indra/llui
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llui')
-rw-r--r--indra/llui/llbutton.cpp27
-rw-r--r--indra/llui/llbutton.h1
-rw-r--r--indra/llui/llcommandmanager.h2
-rw-r--r--indra/llui/lllayoutstack.cpp256
-rw-r--r--indra/llui/lllayoutstack.h18
-rw-r--r--indra/llui/llpanel.h3
-rw-r--r--indra/llui/lltoolbar.cpp71
-rw-r--r--indra/llui/lltoolbar.h4
-rw-r--r--indra/llui/lltoolbarview.cpp221
-rw-r--r--indra/llui/lltoolbarview.h4
-rw-r--r--indra/llui/llview.h6
11 files changed, 313 insertions, 300 deletions
diff --git a/indra/llui/llbutton.cpp b/indra/llui/llbutton.cpp
index 06781f1bdf..f259e8027e 100644
--- a/indra/llui/llbutton.cpp
+++ b/indra/llui/llbutton.cpp
@@ -554,6 +554,16 @@ BOOL LLButton::handleHover(S32 x, S32 y, MASK mask)
return TRUE;
}
+void LLButton::getOverlayImageSize(S32& overlay_width, S32& overlay_height)
+{
+ overlay_width = mImageOverlay->getWidth();
+ overlay_height = mImageOverlay->getHeight();
+
+ F32 scale_factor = llmin((F32)getRect().getWidth() / (F32)overlay_width, (F32)getRect().getHeight() / (F32)overlay_height, 1.f);
+ overlay_width = llround((F32)overlay_width * scale_factor);
+ overlay_height = llround((F32)overlay_height * scale_factor);
+}
+
// virtual
void LLButton::draw()
@@ -781,12 +791,10 @@ void LLButton::draw()
if (mImageOverlay.notNull())
{
// get max width and height (discard level 0)
- S32 overlay_width = mImageOverlay->getWidth();
- S32 overlay_height = mImageOverlay->getHeight();
+ S32 overlay_width;
+ S32 overlay_height;
- F32 scale_factor = llmin((F32)getRect().getWidth() / (F32)overlay_width, (F32)getRect().getHeight() / (F32)overlay_height, 1.f);
- overlay_width = llround((F32)overlay_width * scale_factor);
- overlay_height = llround((F32)overlay_height * scale_factor);
+ getOverlayImageSize(overlay_width, overlay_height);
S32 center_x = getLocalRect().getCenterX();
S32 center_y = getLocalRect().getCenterY();
@@ -811,6 +819,7 @@ void LLButton::draw()
{
case LLFontGL::LEFT:
text_left += overlay_width + mImgOverlayLabelSpace;
+ text_width -= overlay_width + mImgOverlayLabelSpace;
mImageOverlay->draw(
mLeftHPad,
center_y - (overlay_height / 2),
@@ -828,6 +837,7 @@ void LLButton::draw()
break;
case LLFontGL::RIGHT:
text_right -= overlay_width + mImgOverlayLabelSpace;
+ text_width -= overlay_width + mImgOverlayLabelSpace;
mImageOverlay->draw(
getRect().getWidth() - mRightHPad - overlay_width,
center_y - (overlay_height / 2),
@@ -994,13 +1004,18 @@ void LLButton::resize(LLUIString label)
S32 min_width = label_width + mLeftHPad + mRightHPad;
if (mImageOverlay)
{
+ S32 overlay_width = mImageOverlay->getWidth();
+ F32 scale_factor = getRect().getHeight() / (F32)mImageOverlay->getHeight();
+ overlay_width = llround((F32)overlay_width * scale_factor);
+
switch(mImageOverlayAlignment)
{
case LLFontGL::LEFT:
case LLFontGL::RIGHT:
- min_width += mImageOverlay->getWidth() + mImgOverlayLabelSpace;
+ min_width += overlay_width + mImgOverlayLabelSpace;
break;
case LLFontGL::HCENTER:
+ min_width = llmax(min_width, overlay_width + mLeftHPad + mRightHPad);
break;
default:
// draw nothing
diff --git a/indra/llui/llbutton.h b/indra/llui/llbutton.h
index bc5e69fad5..08b45e01b3 100644
--- a/indra/llui/llbutton.h
+++ b/indra/llui/llbutton.h
@@ -270,6 +270,7 @@ public:
protected:
LLPointer<LLUIImage> getImageUnselected() const { return mImageUnselected; }
LLPointer<LLUIImage> getImageSelected() const { return mImageSelected; }
+ void getOverlayImageSize(S32& overlay_width, S32& overlay_height);
LLFrameTimer mMouseDownTimer;
diff --git a/indra/llui/llcommandmanager.h b/indra/llui/llcommandmanager.h
index 8435d915f3..4781f77177 100644
--- a/indra/llui/llcommandmanager.h
+++ b/indra/llui/llcommandmanager.h
@@ -81,6 +81,8 @@ private:
std::string mName;
};
+typedef std::list<LLCommandId> command_id_list_t;
+
class LLCommand
{
public:
diff --git a/indra/llui/lllayoutstack.cpp b/indra/llui/lllayoutstack.cpp
index 0d1f608e61..4991c4afa6 100644
--- a/indra/llui/lllayoutstack.cpp
+++ b/indra/llui/lllayoutstack.cpp
@@ -55,11 +55,12 @@ LLLayoutPanel::LLLayoutPanel(const Params& p)
mMaxDim(p.max_dim),
mAutoResize(p.auto_resize),
mUserResize(p.user_resize),
- mFitContent(p.fit_content),
mCollapsed(FALSE),
mCollapseAmt(0.f),
mVisibleAmt(1.f), // default to fully visible
- mResizeBar(NULL)
+ mResizeBar(NULL),
+ mFractionalSize(0.f),
+ mOrientation(LLLayoutStack::HORIZONTAL)
{
// Set the expanded min dim if it is provided, otherwise it gets the p.min_dim value
if (p.expanded_min_dim.isProvided())
@@ -89,9 +90,22 @@ LLLayoutPanel::~LLLayoutPanel()
mResizeBar = NULL;
}
-F32 LLLayoutPanel::getCollapseFactor(LLLayoutStack::ELayoutOrientation orientation)
+void LLLayoutPanel::reshape(S32 width, S32 height, BOOL called_from_parent)
{
- if (orientation == LLLayoutStack::HORIZONTAL)
+ if (mOrientation == LLLayoutStack::HORIZONTAL)
+ {
+ mFractionalSize += width - llround(mFractionalSize);
+ }
+ else
+ {
+ mFractionalSize += height - llround(mFractionalSize);
+ }
+ LLPanel::reshape(width, height, called_from_parent);
+}
+
+F32 LLLayoutPanel::getCollapseFactor()
+{
+ if (mOrientation == LLLayoutStack::HORIZONTAL)
{
F32 collapse_amt =
clamp_rescale(mCollapseAmt, 0.f, 1.f, 1.f, (F32)getRelevantMinDim() / (F32)llmax(1, getRect().getWidth()));
@@ -105,14 +119,6 @@ F32 LLLayoutPanel::getCollapseFactor(LLLayoutStack::ELayoutOrientation orientati
}
}
-void LLLayoutPanel::fitToContent()
-{
- if (mFitContent)
- {
- setShape(calcBoundingRect());
- }
-}
-
//
// LLLayoutStack
//
@@ -158,11 +164,11 @@ void LLLayoutStack::draw()
// scale clipping rectangle by visible amount
if (mOrientation == HORIZONTAL)
{
- clip_rect.mRight = clip_rect.mLeft + llround((F32)clip_rect.getWidth() * (*panel_it)->getCollapseFactor(mOrientation));
+ clip_rect.mRight = clip_rect.mLeft + llround((F32)clip_rect.getWidth() * (*panel_it)->getCollapseFactor());
}
else
{
- clip_rect.mBottom = clip_rect.mTop - llround((F32)clip_rect.getHeight() * (*panel_it)->getCollapseFactor(mOrientation));
+ clip_rect.mBottom = clip_rect.mTop - llround((F32)clip_rect.getHeight() * (*panel_it)->getCollapseFactor());
}
LLPanel* panelp = (*panel_it);
@@ -202,36 +208,15 @@ bool LLLayoutStack::addChild(LLView* child, S32 tab_group)
LLLayoutPanel* panelp = dynamic_cast<LLLayoutPanel*>(child);
if (panelp)
{
+ panelp->mFractionalSize = (mOrientation == HORIZONTAL)
+ ? panelp->getRect().getWidth()
+ : panelp->getRect().getHeight();
+ panelp->setOrientation(mOrientation);
mPanels.push_back(panelp);
}
return LLView::addChild(child, tab_group);
}
-
-S32 LLLayoutStack::getDefaultHeight(S32 cur_height)
-{
- // if we are spanning our children (crude upward propagation of size)
- // then don't enforce our size on our children
- if (mOrientation == HORIZONTAL)
- {
- cur_height = llmax(mMinHeight, getRect().getHeight());
- }
-
- return cur_height;
-}
-
-S32 LLLayoutStack::getDefaultWidth(S32 cur_width)
-{
- // if we are spanning our children (crude upward propagation of size)
- // then don't enforce our size on our children
- if (mOrientation == VERTICAL)
- {
- cur_width = llmax(mMinWidth, getRect().getWidth());
- }
-
- return cur_width;
-}
-
void LLLayoutStack::movePanel(LLPanel* panel_to_move, LLPanel* target_panel, bool move_to_front)
{
LLLayoutPanel* embedded_panel_to_move = findEmbeddedPanel(panel_to_move);
@@ -326,14 +311,15 @@ void LLLayoutStack::updateLayout(BOOL force_resize)
createResizeBars();
// calculate current extents
- S32 total_width = 0;
- S32 total_height = 0;
+ F32 total_size = 0.f;
+ //
+ // animate visibility
+ //
e_panel_list_t::iterator panel_it;
for (panel_it = mPanels.begin(); panel_it != mPanels.end(); ++panel_it)
{
LLLayoutPanel* panelp = (*panel_it);
- panelp->fitToContent();
if (panelp->getVisible())
{
if (mAnimate)
@@ -371,181 +357,110 @@ void LLLayoutStack::updateLayout(BOOL force_resize)
}
}
- if (panelp->mCollapsed)
- {
- panelp->mCollapseAmt = lerp(panelp->mCollapseAmt, 1.f, LLCriticalDamp::getInterpolant(mCloseTimeConstant));
- }
- else
- {
- panelp->mCollapseAmt = lerp(panelp->mCollapseAmt, 0.f, LLCriticalDamp::getInterpolant(mCloseTimeConstant));
- }
+ F32 collapse_state = panelp->mCollapsed ? 1.f : 0.f;
+ panelp->mCollapseAmt = lerp(panelp->mCollapseAmt, collapse_state, LLCriticalDamp::getInterpolant(mCloseTimeConstant));
- if (mOrientation == HORIZONTAL)
+ total_size += panelp->mFractionalSize * panelp->getCollapseFactor();
+ // want n-1 panel gaps for n panels
+ if (panel_it != mPanels.begin())
{
- // enforce minimize size constraint by default
- if (panelp->getRect().getWidth() < panelp->getRelevantMinDim())
- {
- panelp->reshape(panelp->getRelevantMinDim(), panelp->getRect().getHeight());
- }
- total_width += llround(panelp->getRect().getWidth() * panelp->getCollapseFactor(mOrientation));
- // want n-1 panel gaps for n panels
- if (panel_it != mPanels.begin())
- {
- total_width += mPanelSpacing;
- }
- }
- else //VERTICAL
- {
- // enforce minimize size constraint by default
- if (panelp->getRect().getHeight() < panelp->getRelevantMinDim())
- {
- panelp->reshape(panelp->getRect().getWidth(), panelp->getRelevantMinDim());
- }
- total_height += llround(panelp->getRect().getHeight() * panelp->getCollapseFactor(mOrientation));
- if (panel_it != mPanels.begin())
- {
- total_height += mPanelSpacing;
- }
+ total_size += mPanelSpacing;
}
}
S32 num_resizable_panels = 0;
- S32 shrink_headroom_available = 0;
- S32 shrink_headroom_total = 0;
+ F32 shrink_headroom_available = 0.f;
+ F32 shrink_headroom_total = 0.f;
for (panel_it = mPanels.begin(); panel_it != mPanels.end(); ++panel_it)
{
+ LLLayoutPanel* panelp = (*panel_it);
+
// panels that are not fully visible do not count towards shrink headroom
- if ((*panel_it)->getCollapseFactor(mOrientation) < 1.f)
+ if (panelp->getCollapseFactor() < 1.f)
{
continue;
}
- S32 relevant_dimension = (mOrientation == HORIZONTAL) ? (*panel_it)->getRect().getWidth() : (*panel_it)->getRect().getHeight();
- S32 relevant_min = (*panel_it)->getRelevantMinDim();
+ F32 cur_size = panelp->mFractionalSize;
+ F32 min_size = (F32)panelp->getRelevantMinDim();
// if currently resizing a panel or the panel is flagged as not automatically resizing
// only track total available headroom, but don't use it for automatic resize logic
- if ((*panel_it)->mResizeBar->hasMouseCapture()
- || (!(*panel_it)->mAutoResize
+ if (panelp->mResizeBar->hasMouseCapture()
+ || (!panelp->mAutoResize
&& !force_resize))
{
- shrink_headroom_total += relevant_dimension - relevant_min;
+ shrink_headroom_total += cur_size - min_size;
}
else
{
num_resizable_panels++;
- shrink_headroom_available += relevant_dimension - relevant_min;
- shrink_headroom_total += relevant_dimension - relevant_min;
+ shrink_headroom_available += cur_size - min_size;
+ shrink_headroom_total += cur_size - min_size;
}
}
// calculate how many pixels need to be distributed among layout panels
// positive means panels need to grow, negative means shrink
- S32 pixels_to_distribute;
- if (mOrientation == HORIZONTAL)
- {
- pixels_to_distribute = getRect().getWidth() - total_width;
- }
- else //VERTICAL
- {
- pixels_to_distribute = getRect().getHeight() - total_height;
- }
+ F32 pixels_to_distribute = (mOrientation == HORIZONTAL)
+ ? getRect().getWidth() - total_size
+ : getRect().getHeight() - total_size;
// now we distribute the pixels...
- S32 cur_x = 0;
- S32 cur_y = getRect().getHeight();
+ F32 cur_x = 0.f;
+ F32 cur_y = (F32)getRect().getHeight();
for (panel_it = mPanels.begin(); panel_it != mPanels.end(); ++panel_it)
{
LLLayoutPanel* panelp = (*panel_it);
- S32 cur_width = panelp->getRect().getWidth();
- S32 cur_height = panelp->getRect().getHeight();
- S32 new_width = cur_width;
- S32 new_height = cur_height;
- S32 relevant_min = panelp->getRelevantMinDim();
-
- if (mOrientation == HORIZONTAL)
- {
- new_width = llmax(relevant_min, new_width);
- }
- else
- {
- new_height = llmax(relevant_min, new_height);
- }
- S32 delta_size = 0;
+ F32 min_size = panelp->getRelevantMinDim();
+ F32 delta_size = 0.f;
// if panel can automatically resize (not animating, and resize flag set)...
- if (panelp->getCollapseFactor(mOrientation) == 1.f
+ if (panelp->getCollapseFactor() == 1.f
&& (force_resize || panelp->mAutoResize)
&& !panelp->mResizeBar->hasMouseCapture())
{
- if (mOrientation == HORIZONTAL)
+ if (pixels_to_distribute < 0.f)
{
- // if we're shrinking
- if (pixels_to_distribute < 0)
- {
- // shrink proportionally to amount over minimum
- // so we can do this in one pass
- delta_size = (shrink_headroom_available > 0)
- ? llround((F32)pixels_to_distribute * ((F32)(cur_width - relevant_min) / (F32)shrink_headroom_available))
- : 0;
- shrink_headroom_available -= (cur_width - relevant_min);
- }
- else
- {
- // grow all elements equally
- delta_size = llround((F32)pixels_to_distribute / (F32)num_resizable_panels);
- num_resizable_panels--;
- }
- pixels_to_distribute -= delta_size;
- new_width = llmax(relevant_min, cur_width + delta_size);
+ // shrink proportionally to amount over minimum
+ // so we can do this in one pass
+ delta_size = (shrink_headroom_available > 0.f)
+ ? pixels_to_distribute * ((F32)(panelp->mFractionalSize - min_size) / shrink_headroom_available)
+ : 0.f;
+ shrink_headroom_available -= (panelp->mFractionalSize - min_size);
}
else
{
- new_width = getDefaultWidth(new_width);
- }
-
- if (mOrientation == VERTICAL)
- {
- if (pixels_to_distribute < 0)
- {
- // shrink proportionally to amount over minimum
- // so we can do this in one pass
- delta_size = (shrink_headroom_available > 0) ? llround((F32)pixels_to_distribute * ((F32)(cur_height - relevant_min) / (F32)shrink_headroom_available)) : 0;
- shrink_headroom_available -= (cur_height - relevant_min);
- }
- else
- {
- delta_size = llround((F32)pixels_to_distribute / (F32)num_resizable_panels);
- num_resizable_panels--;
- }
- pixels_to_distribute -= delta_size;
- new_height = llmax(relevant_min, cur_height + delta_size);
- }
- else
- {
- new_height = getDefaultHeight(new_height);
- }
- }
- else
- {
- if (mOrientation == HORIZONTAL)
- {
- new_height = getDefaultHeight(new_height);
- }
- else // VERTICAL
- {
- new_width = getDefaultWidth(new_width);
+ // grow all elements equally
+ delta_size = pixels_to_distribute / (F32)num_resizable_panels;
+ num_resizable_panels--;
}
+
+ panelp->mFractionalSize = llmax(min_size, panelp->mFractionalSize + delta_size);
+ pixels_to_distribute -= delta_size;
}
// adjust running headroom count based on new sizes
shrink_headroom_total += delta_size;
LLRect panel_rect;
- panel_rect.setLeftTopAndSize(cur_x, cur_y, new_width, new_height);
+ if (mOrientation == HORIZONTAL)
+ {
+ panel_rect.setLeftTopAndSize(llround(cur_x),
+ llround(cur_y),
+ llround(panelp->mFractionalSize),
+ getRect().getHeight());
+ }
+ else
+ {
+ panel_rect.setLeftTopAndSize(llround(cur_x),
+ llround(cur_y),
+ getRect().getWidth(),
+ llround(panelp->mFractionalSize));
+ }
panelp->setShape(panel_rect);
LLRect resize_bar_rect = panel_rect;
@@ -561,13 +476,14 @@ void LLLayoutStack::updateLayout(BOOL force_resize)
}
(*panel_it)->mResizeBar->setRect(resize_bar_rect);
+ F32 size = ((*panel_it)->mFractionalSize * (*panel_it)->getCollapseFactor()) + (F32)mPanelSpacing;
if (mOrientation == HORIZONTAL)
{
- cur_x += llround(new_width * (*panel_it)->getCollapseFactor(mOrientation)) + mPanelSpacing;
+ cur_x += size;
}
else //VERTICAL
{
- cur_y -= llround(new_height * (*panel_it)->getCollapseFactor(mOrientation)) + mPanelSpacing;
+ cur_y -= size;
}
}
@@ -582,13 +498,13 @@ void LLLayoutStack::updateLayout(BOOL force_resize)
{
(*panel_it)->mResizeBar->setResizeLimits(
relevant_min,
- relevant_min + shrink_headroom_total);
+ relevant_min + llround(shrink_headroom_total));
}
else //VERTICAL
{
(*panel_it)->mResizeBar->setResizeLimits(
relevant_min,
- relevant_min + shrink_headroom_total);
+ relevant_min + llround(shrink_headroom_total));
}
// toggle resize bars based on panel visibility, resizability, etc
diff --git a/indra/llui/lllayoutstack.h b/indra/llui/lllayoutstack.h
index 2ed32a2fa9..5d79505fc3 100644
--- a/indra/llui/lllayoutstack.h
+++ b/indra/llui/lllayoutstack.h
@@ -126,8 +126,6 @@ protected:
private:
void createResizeBars();
void calcMinExtents();
- S32 getDefaultHeight(S32 cur_height);
- S32 getDefaultWidth(S32 cur_width);
const ELayoutOrientation mOrientation;
@@ -161,16 +159,14 @@ public:
min_dim,
max_dim;
Optional<bool> user_resize,
- auto_resize,
- fit_content;
+ auto_resize;
Params()
: expanded_min_dim("expanded_min_dim", 0),
min_dim("min_dim", 0),
max_dim("max_dim", 0),
user_resize("user_resize", true),
- auto_resize("auto_resize", true),
- fit_content("fit_content", false)
+ auto_resize("auto_resize", true)
{
addSynonym(min_dim, "min_width");
addSynonym(min_dim, "min_height");
@@ -183,6 +179,8 @@ public:
void initFromParams(const Params& p);
+ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
+
S32 getMinDim() const { return mMinDim; }
void setMinDim(S32 value) { mMinDim = value; if (!mExpandedMinDimSpecified) mExpandedMinDim = value; }
@@ -204,11 +202,12 @@ public:
return min_dim;
}
+ void setOrientation(LLLayoutStack::ELayoutOrientation orientation) { mOrientation = orientation; }
+
protected:
LLLayoutPanel(const Params& p);
- F32 getCollapseFactor(LLLayoutStack::ELayoutOrientation orientation);
- void fitToContent();
+ F32 getCollapseFactor();
bool mExpandedMinDimSpecified;
S32 mExpandedMinDim;
@@ -218,9 +217,10 @@ protected:
bool mAutoResize;
bool mUserResize;
bool mCollapsed;
- bool mFitContent;
F32 mVisibleAmt;
F32 mCollapseAmt;
+ F32 mFractionalSize;
+ LLLayoutStack::ELayoutOrientation mOrientation;
class LLResizeBar* mResizeBar;
};
diff --git a/indra/llui/llpanel.h b/indra/llui/llpanel.h
index 790025cb2d..ab1c87caff 100644
--- a/indra/llui/llpanel.h
+++ b/indra/llui/llpanel.h
@@ -96,9 +96,6 @@ public:
Params();
};
- // valid children for LLPanel are stored in this registry
- typedef LLDefaultChildRegistry child_registry_t;
-
protected:
friend class LLUICtrlFactory;
// RN: for some reason you can't just use LLUICtrlFactory::getDefaultParams as a default argument in VC8
diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp
index 8249df3e9d..c5219b11e8 100644
--- a/indra/llui/lltoolbar.cpp
+++ b/indra/llui/lltoolbar.cpp
@@ -30,6 +30,7 @@
#include <boost/foreach.hpp>
#include "lltoolbar.h"
+#include "llcommandmanager.h"
#include "llmenugl.h"
#include "lltrans.h"
@@ -125,14 +126,13 @@ void LLToolBar::createContextMenu()
{
// Setup bindings specific to this instance for the context menu options
- LLUICtrl::CommitCallbackRegistry::Registrar& commit_reg = LLUICtrl::CommitCallbackRegistry::defaultRegistrar();
+ LLUICtrl::CommitCallbackRegistry::ScopedRegistrar commit_reg;
commit_reg.add("Toolbars.EnableSetting", boost::bind(&LLToolBar::onSettingEnable, this, _2));
- LLUICtrl::EnableCallbackRegistry::Registrar& enable_reg = LLUICtrl::EnableCallbackRegistry::defaultRegistrar();
+ LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_reg;
enable_reg.add("Toolbars.CheckSetting", boost::bind(&LLToolBar::isSettingChecked, this, _2));
// Create the context menu
-
LLContextMenu* menu = LLUICtrlFactory::instance().createFromFile<LLContextMenu>("menu_toolbars.xml", LLMenuGL::sMenuContainer, LLMenuHolderGL::child_registry_t::instance());
if (menu)
@@ -145,10 +145,6 @@ void LLToolBar::createContextMenu()
{
llwarns << "Unable to load toolbars context menu." << llendl;
}
-
- // Remove this instance's bindings
- commit_reg.remove("Toolbars.EnableSetting");
- enable_reg.remove("Toolbars.CheckSetting");
}
}
@@ -183,7 +179,6 @@ void LLToolBar::initFromParams(const LLToolBar::Params& p)
center_panel_p.rect = getLocalRect();
center_panel_p.auto_resize = false;
center_panel_p.user_resize = false;
- center_panel_p.fit_content = true;
LLLayoutPanel* center_panel = LLUICtrlFactory::create<LLLayoutPanel>(center_panel_p);
mCenteringStack->addChild(center_panel);
@@ -195,6 +190,11 @@ void LLToolBar::initFromParams(const LLToolBar::Params& p)
mCenteringStack->addChild(LLUICtrlFactory::create<LLLayoutPanel>(border_panel_p));
+ BOOST_FOREACH(LLCommandId::Params params, p.commands)
+ {
+ addCommand(params);
+ }
+
mNeedsLayout = true;
}
@@ -207,7 +207,7 @@ bool LLToolBar::addCommand(const LLCommandId& commandId)
if (add_command)
{
mButtonCommands.push_back(commandId);
- createButtons();
+ createButton(commandId);
}
return add_command;
@@ -219,9 +219,9 @@ bool LLToolBar::hasCommand(const LLCommandId& commandId) const
if (commandId != LLCommandId::null)
{
- for (std::list<LLCommandId>::const_iterator cmd = mButtonCommands.begin(); cmd != mButtonCommands.end(); ++cmd)
+ BOOST_FOREACH(LLCommandId cmd, mButtonCommands)
{
- if ((*cmd) == commandId)
+ if (cmd == commandId)
{
has_command = true;
break;
@@ -251,7 +251,9 @@ bool LLToolBar::enableCommand(const LLCommandId& commandId, bool enabled)
BOOL LLToolBar::handleRightMouseDown(S32 x, S32 y, MASK mask)
{
- BOOL handle_it_here = !mReadOnly;
+ LLRect button_panel_rect;
+ mButtonPanel->localRectToOtherView(mButtonPanel->getLocalRect(), &button_panel_rect, this);
+ BOOL handle_it_here = !mReadOnly && button_panel_rect.pointInRect(x, y);
if (handle_it_here)
{
@@ -407,11 +409,11 @@ void LLToolBar::updateLayoutAsNeeded()
cur_start = row_pad_start;
cur_row += max_row_girth + mPadBetween;
max_row_girth = 0;
- }
+ }
- LLRect button_rect;
- if (orientation == LLLayoutStack::HORIZONTAL)
- {
+ LLRect button_rect;
+ if (orientation == LLLayoutStack::HORIZONTAL)
+ {
button_rect.setLeftTopAndSize(cur_start, panel_rect.mTop - cur_row, button_clamped_width, button->getRect().getHeight());
}
else // VERTICAL
@@ -457,6 +459,9 @@ void LLToolBar::updateLayoutAsNeeded()
mButtonPanel->reshape(total_girth, max_row_length);
}
+ // make parent fit button panel
+ mButtonPanel->getParent()->setShape(mButtonPanel->getLocalRect());
+
// re-center toolbar buttons
mCenteringStack->updateLayout();
@@ -467,7 +472,13 @@ void LLToolBar::updateLayoutAsNeeded()
void LLToolBar::draw()
{
+ if (mButtons.empty()) return;
updateLayoutAsNeeded();
+ // rect may have shifted during layout
+ LLUI::popMatrix();
+ LLUI::pushMatrix();
+ LLUI::translate((F32)getRect().mLeft, (F32)getRect().mBottom, 0.f);
+
LLUICtrl::draw();
}
@@ -487,19 +498,25 @@ void LLToolBar::createButtons()
BOOST_FOREACH(LLCommandId& command_id, mButtonCommands)
{
- LLCommand* commandp = LLCommandManager::instance().getCommand(command_id);
- if (!commandp) continue;
+ createButton(command_id);
+ }
+
+}
- LLToolBarButton::Params button_p;
- button_p.label = LLTrans::getString(commandp->labelRef());
- button_p.image_overlay = LLUI::getUIImage(commandp->icon());
- button_p.overwriteFrom(mButtonParams[mButtonType]);
- LLToolBarButton* button = LLUICtrlFactory::create<LLToolBarButton>(button_p);
+void LLToolBar::createButton(const LLCommandId& id)
+{
+ LLCommand* commandp = LLCommandManager::instance().getCommand(id);
+ if (!commandp) return;
- mButtons.push_back(button);
- mButtonPanel->addChild(button);
- }
+ LLToolBarButton::Params button_p;
+ button_p.label = LLTrans::getString(commandp->labelRef());
+ button_p.tool_tip = button_p.label();
+ button_p.image_overlay = LLUI::getUIImage(commandp->icon());
+ button_p.overwriteFrom(mButtonParams[mButtonType]);
+ LLToolBarButton* button = LLUICtrlFactory::create<LLToolBarButton>(button_p);
+
+ mButtons.push_back(button);
+ mButtonPanel->addChild(button);
mNeedsLayout = true;
}
-
diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h
index 75ae499a3d..8e484c7e13 100644
--- a/indra/llui/lltoolbar.h
+++ b/indra/llui/lltoolbar.h
@@ -123,6 +123,7 @@ public:
bool addCommand(const LLCommandId& commandId);
bool hasCommand(const LLCommandId& commandId) const;
bool enableCommand(const LLCommandId& commandId, bool enabled);
+ command_id_list_t& getCommandsList() { return mButtonCommands; }
protected:
friend class LLUICtrlFactory;
@@ -135,6 +136,7 @@ private:
void createContextMenu();
void updateLayoutAsNeeded();
void createButtons();
+ void createButton(const LLCommandId& id);
void resizeButtonsInRow(std::vector<LLToolBarButton*>& buttons_in_row, S32 max_row_girth);
BOOL isSettingChecked(const LLSD& userdata);
void onSettingEnable(const LLSD& userdata);
@@ -142,7 +144,7 @@ private:
const bool mReadOnly;
std::list<LLToolBarButton*> mButtons;
- std::list<LLCommandId> mButtonCommands;
+ command_id_list_t mButtonCommands;
LLToolBarEnums::ButtonType mButtonType;
LLLayoutStack* mCenteringStack;
LLLayoutStack* mWrapStack;
diff --git a/indra/llui/lltoolbarview.cpp b/indra/llui/lltoolbarview.cpp
index 7047cca948..b374a0bfc4 100644
--- a/indra/llui/lltoolbarview.cpp
+++ b/indra/llui/lltoolbarview.cpp
@@ -50,14 +50,79 @@ LLToolBarView::ToolbarSet::ToolbarSet()
bottom_toolbar("bottom_toolbar")
{}
-bool LLToolBarView::load()
+
+LLToolBarView::LLToolBarView(const LLToolBarView::Params& p)
+: LLUICtrl(p),
+ mToolbarLeft(NULL),
+ mToolbarRight(NULL),
+ mToolbarBottom(NULL)
+{
+}
+
+void LLToolBarView::initFromParams(const LLToolBarView::Params& p)
+{
+ // Initialize the base object
+ LLUICtrl::initFromParams(p);
+}
+
+LLToolBarView::~LLToolBarView()
+{
+ saveToolbars();
+}
+
+BOOL LLToolBarView::postBuild()
+{
+ mToolbarLeft = getChild<LLToolBar>("toolbar_left");
+ mToolbarRight = getChild<LLToolBar>("toolbar_right");
+ mToolbarBottom = getChild<LLToolBar>("toolbar_bottom");
+
+ // Load the toolbars from the settings
+ loadToolbars();
+
+ return TRUE;
+}
+
+bool LLToolBarView::hasCommand(const LLCommandId& commandId) const
+{
+ bool has_command = false;
+ if (mToolbarLeft && !has_command)
+ {
+ has_command = mToolbarLeft->hasCommand(commandId);
+ }
+ if (mToolbarRight && !has_command)
+ {
+ has_command = mToolbarRight->hasCommand(commandId);
+ }
+ if (mToolbarBottom && !has_command)
+ {
+ has_command = mToolbarBottom->hasCommand(commandId);
+ }
+ return has_command;
+}
+
+bool LLToolBarView::addCommand(const LLCommandId& command, LLToolBar* toolbar)
+{
+ LLCommandManager& mgr = LLCommandManager::instance();
+ if (mgr.getCommand(command))
+ {
+ toolbar->addCommand(command);
+ }
+ else
+ {
+ llwarns << "Toolbars creation : the command " << command.name() << " cannot be found in the command manager" << llendl;
+ return false;
+ }
+ return true;
+}
+
+bool LLToolBarView::loadToolbars()
{
LLToolBarView::ToolbarSet toolbar_set;
-
+
// Load the default toolbars.xml file
// *TODO : pick up the user's toolbar setting if existing
std::string toolbar_file = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "toolbars.xml");
-
+
LLXMLNodePtr root;
if(!LLXMLNode::parseFile(toolbar_file, root, NULL))
{
@@ -69,7 +134,7 @@ bool LLToolBarView::load()
llwarns << toolbar_file << " is not a valid toolbars definition file" << llendl;
return false;
}
-
+
// Parse the toolbar settings
LLXUIParser parser;
parser.readXUI(root, toolbar_set, toolbar_file);
@@ -80,103 +145,90 @@ bool LLToolBarView::load()
}
// Add commands to each toolbar
- // *TODO: factorize that code : tricky with Blocks though, simple lexical approach fails
- LLCommandManager& mgr = LLCommandManager::instance();
-
if (toolbar_set.left_toolbar.isProvided() && mToolbarLeft)
{
BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.left_toolbar.commands)
{
- LLCommandId* commandId = new LLCommandId(command);
- if (mgr.getCommand(*commandId))
- {
- mToolbarLeft->addCommand(*commandId);
- }
- else
- {
- llwarns << "Toolbars creation : the command " << commandId->name() << " cannot be found in the command manager" << llendl;
- }
+ addCommand(LLCommandId(command),mToolbarLeft);
}
}
if (toolbar_set.right_toolbar.isProvided() && mToolbarRight)
{
BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.right_toolbar.commands)
{
- LLCommandId* commandId = new LLCommandId(command);
- if (mgr.getCommand(*commandId))
- {
- mToolbarRight->addCommand(*commandId);
- }
- else
- {
- llwarns << "Toolbars creation : the command " << commandId->name() << " cannot be found in the command manager" << llendl;
- }
+ addCommand(LLCommandId(command),mToolbarRight);
}
}
if (toolbar_set.bottom_toolbar.isProvided() && mToolbarBottom)
{
BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.bottom_toolbar.commands)
{
- LLCommandId* commandId = new LLCommandId(command);
- if (mgr.getCommand(*commandId))
- {
- mToolbarBottom->addCommand(*commandId);
- }
- else
- {
- llwarns << "Toolbars creation : the command " << commandId->name() << " cannot be found in the command manager" << llendl;
- }
+ addCommand(LLCommandId(command),mToolbarBottom);
}
}
return true;
}
-LLToolBarView::LLToolBarView(const LLToolBarView::Params& p)
-: LLUICtrl(p),
- mToolbarLeft(NULL),
- mToolbarRight(NULL),
- mToolbarBottom(NULL)
-{
-}
-
-void LLToolBarView::initFromParams(const LLToolBarView::Params& p)
+void LLToolBarView::saveToolbars() const
{
- // Initialize the base object
- LLUICtrl::initFromParams(p);
-}
-
-LLToolBarView::~LLToolBarView()
-{
-}
-
-BOOL LLToolBarView::postBuild()
-{
- mToolbarLeft = getChild<LLToolBar>("toolbar_left");
- mToolbarRight = getChild<LLToolBar>("toolbar_right");
- mToolbarBottom = getChild<LLToolBar>("toolbar_bottom");
-
- // Load the toolbars from the settings
- load();
+ // Build the parameter tree from the toolbar data
+ LLToolBarView::ToolbarSet toolbar_set;
- return TRUE;
-}
-
-bool LLToolBarView::hasCommand(const LLCommandId& commandId) const
-{
- bool has_command = false;
- if (mToolbarLeft && !has_command)
+ // *TODO : factorize that code a bit...
+ if (mToolbarLeft)
{
- has_command = mToolbarLeft->hasCommand(commandId);
+ command_id_list_t& command_list = mToolbarLeft->getCommandsList();
+ for (command_id_list_t::const_iterator it = command_list.begin();
+ it != command_list.end();
+ ++it)
+ {
+ LLCommandId::Params command;
+ command.name = it->name();
+ toolbar_set.left_toolbar.commands.add(command);
+ }
}
- if (mToolbarRight && !has_command)
+ if (mToolbarRight)
{
- has_command = mToolbarRight->hasCommand(commandId);
+ command_id_list_t& command_list = mToolbarRight->getCommandsList();
+ for (command_id_list_t::const_iterator it = command_list.begin();
+ it != command_list.end();
+ ++it)
+ {
+ LLCommandId::Params command;
+ command.name = it->name();
+ toolbar_set.right_toolbar.commands.add(command);
+ }
}
- if (mToolbarBottom && !has_command)
+ if (mToolbarBottom)
{
- has_command = mToolbarBottom->hasCommand(commandId);
+ command_id_list_t& command_list = mToolbarBottom->getCommandsList();
+ for (command_id_list_t::const_iterator it = command_list.begin();
+ it != command_list.end();
+ ++it)
+ {
+ LLCommandId::Params command;
+ command.name = it->name();
+ toolbar_set.bottom_toolbar.commands.add(command);
+ }
+ }
+
+ // Serialize the parameter tree
+ LLXMLNodePtr output_node = new LLXMLNode("toolbars", false);
+ LLXUIParser parser;
+ parser.writeXUI(output_node, toolbar_set);
+
+ // Write the resulting XML to file
+ if(!output_node->isNull())
+ {
+ const std::string& filename = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, "toolbars.xml");
+ LLFILE *fp = LLFile::fopen(filename, "w");
+ if (fp != NULL)
+ {
+ LLXMLNode::writeHeaderToFile(fp);
+ output_node->writeToFile(fp);
+ fclose(fp);
+ }
}
- return has_command;
}
void LLToolBarView::draw()
@@ -189,10 +241,21 @@ void LLToolBarView::draw()
LLRect bottom_rect, left_rect, right_rect;
- if (mToolbarBottom) mToolbarBottom->localRectToOtherView(mToolbarBottom->getLocalRect(), &bottom_rect, this);
- if (mToolbarLeft) mToolbarLeft->localRectToOtherView(mToolbarLeft->getLocalRect(), &left_rect, this);
- if (mToolbarRight) mToolbarRight->localRectToOtherView(mToolbarRight->getLocalRect(), &right_rect, this);
-
+ if (mToolbarBottom)
+ {
+ mToolbarBottom->getParent()->reshape(mToolbarBottom->getParent()->getRect().getWidth(), mToolbarBottom->getRect().getHeight());
+ mToolbarBottom->localRectToOtherView(mToolbarBottom->getLocalRect(), &bottom_rect, this);
+ }
+ if (mToolbarLeft)
+ {
+ mToolbarLeft->getParent()->reshape(mToolbarLeft->getRect().getWidth(), mToolbarLeft->getParent()->getRect().getHeight());
+ mToolbarLeft->localRectToOtherView(mToolbarLeft->getLocalRect(), &left_rect, this);
+ }
+ if (mToolbarRight)
+ {
+ mToolbarRight->getParent()->reshape(mToolbarRight->getRect().getWidth(), mToolbarRight->getParent()->getRect().getHeight());
+ mToolbarRight->localRectToOtherView(mToolbarRight->getLocalRect(), &right_rect, this);
+ }
if ((old_width != getRect().getWidth()) || (old_height != getRect().getHeight()))
debug_print = true;
@@ -215,9 +278,9 @@ void LLToolBarView::draw()
back_color_hori[VALPHA] = 0.5f;
back_color_vert[VALPHA] = 0.5f;
//gl_rect_2d(getLocalRect(), back_color, TRUE);
- gl_rect_2d(bottom_rect, back_color_hori, TRUE);
- gl_rect_2d(left_rect, back_color_vert, TRUE);
- gl_rect_2d(right_rect, back_color_vert, TRUE);
+ //gl_rect_2d(bottom_rect, back_color_hori, TRUE);
+ //gl_rect_2d(left_rect, back_color_vert, TRUE);
+ //gl_rect_2d(right_rect, back_color_vert, TRUE);
LLUICtrl::draw();
}
diff --git a/indra/llui/lltoolbarview.h b/indra/llui/lltoolbarview.h
index 0f16b89ecc..646a1fd636 100644
--- a/indra/llui/lltoolbarview.h
+++ b/indra/llui/lltoolbarview.h
@@ -77,7 +77,9 @@ protected:
private:
// Loads the toolbars from the existing user or default settings
- bool load(); // return false if load fails
+ bool loadToolbars(); // return false if load fails
+ void saveToolbars() const;
+ bool addCommand(const LLCommandId& commandId, LLToolBar* toolbar);
// Pointers to the toolbars handled by the toolbar view
LLToolBar* mToolbarLeft;
diff --git a/indra/llui/llview.h b/indra/llui/llview.h
index 7a1b2e4ba0..9039366e7e 100644
--- a/indra/llui/llview.h
+++ b/indra/llui/llview.h
@@ -95,9 +95,6 @@ private:
static std::vector<LLViewDrawContext*> sDrawContextStack;
};
-class LLViewWidgetRegistry : public LLChildRegistry<LLViewWidgetRegistry>
-{};
-
class LLView : public LLMouseHandler, public LLMortician, public LLFocusableElement
{
public:
@@ -150,7 +147,8 @@ public:
Params();
};
- typedef LLViewWidgetRegistry child_registry_t;
+ // most widgets are valid children of LLView
+ typedef LLDefaultChildRegistry child_registry_t;
void initFromParams(const LLView::Params&);