Add some help text in ContextBar when SelectBoxState is running

This commit is contained in:
David Capello 2015-05-07 13:11:44 -03:00
parent 18b067ee77
commit 35c8cc893b
7 changed files with 106 additions and 28 deletions

View File

@ -100,6 +100,10 @@ protected:
updateIcons();
}
std::string onGetContextBarHelp() override {
return "Select new canvas size";
}
void onSizeChange() {
updateBorderFromSize();
updateRectFromBorder();

View File

@ -158,6 +158,10 @@ protected:
height()->setTextf("%d", m_rect.h);
}
std::string onGetContextBarHelp() override {
return "Select bounds to identify sprite frames";
}
private:
void selectActiveDocument() {
Document* oldDocument = m_document;

View File

@ -46,6 +46,10 @@ protected:
void onQuickboxEnd(const gfx::Rect& rect, ui::MouseButtons buttons) override;
void onQuickboxCancel() override;
std::string onGetContextBarHelp() override {
return "Select brush bounds | Right-click to cut";
}
private:
void createBrush(const Mask* mask);
};

View File

@ -819,6 +819,8 @@ ContextBar::ContextBar()
m_sprayBox->addChild(m_sprayWidth = new SprayWidthField());
m_sprayBox->addChild(m_spraySpeed = new SpraySpeedField());
addChild(m_selectBoxHelp = new Label(""));
setup_mini_font(m_sprayLabel);
addChild(m_freehandBox = new HBox());
@ -914,49 +916,66 @@ void ContextBar::updateForTool(tools::Tool* tool)
base::ScopedValue<bool> lockFlag(g_updatingFromTool, true, false);
ISettings* settings = UIContext::instance()->settings();
IToolSettings* toolSettings = settings->getToolSettings(tool);
IBrushSettings* brushSettings = toolSettings->getBrush();
IToolSettings* toolSettings = nullptr;
IBrushSettings* brushSettings = nullptr;
if (tool) {
toolSettings = settings->getToolSettings(tool);
brushSettings = toolSettings->getBrush();
}
if (m_toolSettings)
m_toolSettings->removeObserver(this);
m_toolSettings = toolSettings;
m_toolSettings->addObserver(this);
if (m_toolSettings)
m_toolSettings->addObserver(this);
if (tool)
m_brushType->updateBrush(tool);
if (brushSettings) {
m_brushSize->setTextf("%d", brushSettings->getSize());
m_brushAngle->setTextf("%d", brushSettings->getAngle());
}
m_brushType->updateBrush(tool);
m_brushSize->setTextf("%d", brushSettings->getSize());
m_brushAngle->setTextf("%d", brushSettings->getAngle());
m_brushPatternField->setBrushPattern(
App::instance()->preferences().brush.pattern());
m_tolerance->setTextf("%d", toolSettings->getTolerance());
m_contiguous->setSelected(toolSettings->getContiguous());
if (toolSettings) {
m_tolerance->setTextf("%d", toolSettings->getTolerance());
m_contiguous->setSelected(toolSettings->getContiguous());
m_inkType->setInkType(toolSettings->getInkType());
m_inkOpacity->setTextf("%d", toolSettings->getOpacity());
m_inkType->setInkType(toolSettings->getInkType());
m_inkOpacity->setTextf("%d", toolSettings->getOpacity());
m_grabAlpha->setSelected(settings->getGrabAlpha());
m_autoSelectLayer->setSelected(settings->getAutoSelectLayer());
m_freehandAlgo->setFreehandAlgorithm(toolSettings->getFreehandAlgorithm());
m_freehandAlgo->setFreehandAlgorithm(toolSettings->getFreehandAlgorithm());
m_sprayWidth->setValue(toolSettings->getSprayWidth());
m_spraySpeed->setValue(toolSettings->getSpraySpeed());
m_sprayWidth->setValue(toolSettings->getSprayWidth());
m_spraySpeed->setValue(toolSettings->getSpraySpeed());
}
if (settings) {
m_grabAlpha->setSelected(settings->getGrabAlpha());
m_autoSelectLayer->setSelected(settings->getAutoSelectLayer());
}
// True if the current tool needs opacity options
bool hasOpacity = (tool->getInk(0)->isPaint() ||
tool->getInk(0)->isEffect() ||
tool->getInk(1)->isPaint() ||
tool->getInk(1)->isEffect());
bool hasOpacity = tool &&
(tool->getInk(0)->isPaint() ||
tool->getInk(0)->isEffect() ||
tool->getInk(1)->isPaint() ||
tool->getInk(1)->isEffect());
// True if we have an image as brush
bool hasImageBrush = (activeBrush()->type() == kImageBrushType);
// True if the current tool is eyedropper.
bool isEyedropper =
bool isEyedropper = tool &&
(tool->getInk(0)->isEyedropper() ||
tool->getInk(1)->isEyedropper());
// True if the current tool is move tool.
bool isMove =
bool isMove = tool &&
(tool->getInk(0)->isCelMovement() ||
tool->getInk(1)->isCelMovement());
@ -965,17 +984,20 @@ void ContextBar::updateForTool(tools::Tool* tool)
bool hasInk = hasOpacity;
// True if the current tool needs tolerance options
bool hasTolerance = (tool->getPointShape(0)->isFloodFill() ||
tool->getPointShape(1)->isFloodFill());
bool hasTolerance = tool &&
(tool->getPointShape(0)->isFloodFill() ||
tool->getPointShape(1)->isFloodFill());
// True if the current tool needs spray options
bool hasSprayOptions = (tool->getPointShape(0)->isSpray() ||
tool->getPointShape(1)->isSpray());
bool hasSprayOptions = tool &&
(tool->getPointShape(0)->isSpray() ||
tool->getPointShape(1)->isSpray());
bool hasSelectOptions = (tool->getInk(0)->isSelection() ||
tool->getInk(1)->isSelection());
bool hasSelectOptions = tool &&
(tool->getInk(0)->isSelection() ||
tool->getInk(1)->isSelection());
bool isFreehand =
bool isFreehand = tool &&
(tool->getController(0)->isFreehand() ||
tool->getController(1)->isFreehand());
@ -997,6 +1019,7 @@ void ContextBar::updateForTool(tools::Tool* tool)
m_selectionOptionsBox->setVisible(hasSelectOptions);
m_selectionMode->setVisible(true);
m_dropPixels->setVisible(false);
m_selectBoxHelp->setVisible(false);
layout();
}
@ -1014,6 +1037,17 @@ void ContextBar::updateForMovingPixels()
layout();
}
void ContextBar::updateForSelectingBox(const std::string& text)
{
if (m_selectBoxHelp->isVisible() && m_selectBoxHelp->getText() == text)
return;
updateForTool(nullptr);
m_selectBoxHelp->setText(text);
m_selectBoxHelp->setVisible(true);
layout();
}
void ContextBar::updateSelectionMode(SelectionMode mode)
{
if (!m_selectionMode->isVisible())

View File

@ -43,6 +43,7 @@ namespace app {
void updateForCurrentTool();
void updateForTool(tools::Tool* tool);
void updateForMovingPixels();
void updateForSelectingBox(const std::string& text);
void updateSelectionMode(SelectionMode mode);
void updateAutoSelectLayer(bool state);
@ -136,6 +137,7 @@ namespace app {
DropPixelsField* m_dropPixels;
doc::BrushRef m_activeBrush;
BrushSlots m_brushes;
ui::Label* m_selectBoxHelp;
};
} // namespace app

View File

@ -12,6 +12,8 @@
#include "app/ui/editor/select_box_state.h"
#include "app/app.h"
#include "app/ui/main_window.h"
#include "app/ui/context_bar.h"
#include "app/tools/tool_box.h"
#include "app/ui/editor/editor.h"
#include "doc/image.h"
@ -35,6 +37,12 @@ SelectBoxState::SelectBoxState(SelectBoxDelegate* delegate, const gfx::Rect& rc,
setBoxBounds(rc);
}
SelectBoxState::~SelectBoxState()
{
ContextBar* contextBar = App::instance()->getMainWindow()->getContextBar();
contextBar->updateForCurrentTool();
}
gfx::Rect SelectBoxState::getBoxBounds() const
{
int x1 = std::min(m_rulers[V1].getPosition(), m_rulers[V2].getPosition());
@ -54,6 +62,8 @@ void SelectBoxState::setBoxBounds(const gfx::Rect& box)
void SelectBoxState::onAfterChangeState(Editor* editor)
{
updateContextBar();
editor->setDecorator(this);
editor->invalidate();
}
@ -113,6 +123,8 @@ bool SelectBoxState::onMouseMove(Editor* editor, MouseMessage* msg)
{
bool used = false;
updateContextBar();
if (hasFlag(RULERS) && m_movingRuler >= 0) {
gfx::Point pt = editor->screenToEditor(msg->position());
@ -182,6 +194,11 @@ bool SelectBoxState::onSetCursor(Editor* editor)
return StandbyState::onSetCursor(editor);
}
bool SelectBoxState::acceptQuickTool(tools::Tool* tool)
{
return false;
}
bool SelectBoxState::requireBrushPreview()
{
if (hasFlag(QUICKBOX))
@ -275,6 +292,12 @@ void SelectBoxState::postRenderDecorator(EditorPostRender* render)
}
}
void SelectBoxState::updateContextBar()
{
ContextBar* contextBar = App::instance()->getMainWindow()->getContextBar();
contextBar->updateForSelectingBox(m_delegate->onGetContextBarHelp());
}
bool SelectBoxState::touchRuler(Editor* editor, Ruler& ruler, int x, int y)
{
gfx::Point pt = editor->editorToScreen(

View File

@ -30,6 +30,9 @@ namespace app {
// button.
virtual void onQuickboxEnd(const gfx::Rect& rect, ui::MouseButtons buttons) { }
virtual void onQuickboxCancel() { }
// Help text to be shown in the ContextBar
virtual std::string onGetContextBarHelp() { return ""; }
};
class SelectBoxState : public StandbyState
@ -46,6 +49,7 @@ namespace app {
SelectBoxState(SelectBoxDelegate* delegate,
const gfx::Rect& rc,
Flags flags);
~SelectBoxState();
// Returns the bounding box arranged by the rulers.
gfx::Rect getBoxBounds() const;
@ -58,6 +62,7 @@ namespace app {
virtual bool onMouseUp(Editor* editor, ui::MouseMessage* msg) override;
virtual bool onMouseMove(Editor* editor, ui::MouseMessage* msg) override;
virtual bool onSetCursor(Editor* editor) override;
virtual bool acceptQuickTool(tools::Tool* tool) override;
virtual bool requireBrushPreview() override;
virtual tools::Ink* getStateInk() override;
@ -68,6 +73,8 @@ namespace app {
private:
typedef std::vector<Ruler> Rulers;
void updateContextBar();
// Returns true if the position screen position (x, y) is touching
// the given ruler.
bool touchRuler(Editor* editor, Ruler& ruler, int x, int y);