LLToolBarView

From Second Life Wiki
Jump to navigation Jump to search

Objectives

The LLToolbarView class is designed to handle and orchestrate the simultaneous use of the 3 toolbars on the main view: left, bottom and right.

Design

LLToolbarView exists as a single global (gToolBarView) instantiated by LLViewerWindow.

In order to have the toolbars always drawn on top of all floaters, a toolbar_view_holder is defined in main_view.xml and is placed immediately above the floater_view.

In LLViewerWindow::initBase(), this toolbar_view_holder panel is acquired and passed to the LLToolbarView constructor to instantiate gToolBarView. This requirement is why gToolBarView is handled as a global instead of using the LLSingleton pattern: it's easier to control its exact creation moment in the application initialization.

General Layout

The toolbars view layout is specified in panel_toolbar_view.xml.

It is made of a horizontal layout stack containing 2 regions:

  • The top region contains a vertical layout stack itself containing:
    • the left toolbar
    • a filler panel
    • the right toolbar
    • the chiclet container
  • The bottom region contains the bottom toolbar

The carets, used to indicate drop position on Drag and Drop, are specified icon xui so each toolbar can have its own xui driven caret.

Toolbars Layout

The LLToolbarView maintains pointers to each individual LLToolBar. When the LLToolbarView is instantiated, the toolbars are not immediately loaded. This is because the content of each toolbar is set on a per user account basis and, therefore, the application needs to wait till after login to know which toolbars to load.

The toolbar content is saved as user specific settings in toolbars.xml. If the user specific toolbars.xml cannot be found or opened, the default toolbars.xml is loaded. This default is also the one loaded when hitting the "Restore default" button in the toybox (see toybox wiki).

When changing the toolbars and when quitting the application, a toolbars.xml is saved in the user's settings.

For more information on the toolbar specific layout design (view option, etc...), see the toolbar wiki.

Relevant Code:

  • LLToolBarView::loadToolbars()
  • LLToolBarView::loadDefaultToolbars()
  • LLToolBarView::saveToolbars()

Drag and Drop

Each tool can be individually dragged and dropped from any toolbar or toybox to any other. The LLToolbarView orchestrate 2 main functions here:

  • It displays the blue background drop display when a tool is in the process of being dropped
  • It maintains the consistency of the various toolbars on drop

When starting to drag, the handleDragTool() is called and creates the various data to be passed as payload to the general LLToolDragAndDrop::beginMultiDrag() call. This general Drag and Drop framework though is meant to move around in a general way any kind of asset that can be identified with a unique UUID and a type. In order to latch the tool drag and drop action to the general drag and drop framework, we had to create a set of specific types:

  • LLAssetType::AT_WIDGET : a new type to indicate that the object being DaD is a widget and not any other kind of asset
  • EDragAndDropType::DAD_WIDGET : to denotate a DaD action for a widget
  • LLToolDragAndDrop::SOURCE_VIEWER : to indicate that the source of the asset is the viewer itself, as opposed to something existing on the asset servers.

That being defined, the LLToolbarView can discriminate between a legit widget asset being dragged and other assets. When it detects such a drag event as happening, LLToolbarView::draw() displays the background drop zone for each toolbar. The color of this is specified as ToolbarDropZoneColor in colors.xml.

Also all other viewer drop target can react correctly to a dragged widget and display the "no" cursor.

In the future, we'll be able to use the same mechanism so that other viewer widget can become draggable or declare themselves as accepting droppable widgets. This should help making the viewer UI fully customizable.

On drop, the LLToolBarView::handleDropTool() method makes sure that the tool is added to the correct toolbar in the right place and also removed from other toolbars so to avoid duplication of tools and, in effect, moving tools from a toolbar to another.

Relevant Code:

  • LLToolBarView::startDragTool()
  • LLToolBarView::handleDragTool()
  • LLToolBarView::handleDropTool()
  • LLToolBarView::draw()