From db193a07a200bc7e47c0d80dfcb859a536276c46 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 30 Mar 2013 21:31:34 -0300 Subject: [PATCH] Add fields to modify spray options in ContextBar --- src/widgets/context_bar.cpp | 56 +++++++++++++++++++++++++++++++++++-- src/widgets/context_bar.h | 6 ++++ 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/widgets/context_bar.cpp b/src/widgets/context_bar.cpp index 0cf3371ee..a8f0bae42 100644 --- a/src/widgets/context_bar.cpp +++ b/src/widgets/context_bar.cpp @@ -35,6 +35,7 @@ #include "ui/popup_window.h" #include "ui/preferred_size_event.h" #include "ui/theme.h" +#include "ui/tooltips.h" #include "ui_context.h" #include "widgets/button_set.h" #include "widgets/context_bar.h" @@ -281,6 +282,40 @@ protected: } }; +class ContextBar::SprayWidthField : public IntEntry +{ +public: + SprayWidthField() : IntEntry(1, 32) { + } + +protected: + void onValueChange() OVERRIDE { + IntEntry::onValueChange(); + + ISettings* settings = UIContext::instance()->getSettings(); + Tool* currentTool = settings->getCurrentTool(); + settings->getToolSettings(currentTool) + ->setSprayWidth(getValue()); + } +}; + +class ContextBar::SpraySpeedField : public IntEntry +{ +public: + SpraySpeedField() : IntEntry(1, 100) { + } + +protected: + void onValueChange() OVERRIDE { + IntEntry::onValueChange(); + + ISettings* settings = UIContext::instance()->getSettings(); + Tool* currentTool = settings->getCurrentTool(); + settings->getToolSettings(currentTool) + ->setSpraySpeed(getValue()); + } +}; + ContextBar::ContextBar() : Box(JI_HORIZONTAL) { @@ -306,6 +341,21 @@ ContextBar::ContextBar() // addChild(new InkShadeField()); // addChild(new InkSelectionField()); + addChild(m_sprayBox = new HBox()); + m_sprayBox->addChild(new Label("Spray:")); + m_sprayBox->addChild(m_sprayWidth = new SprayWidthField()); + m_sprayBox->addChild(m_spraySpeed = new SpraySpeedField()); + + TooltipManager* tooltipManager = new TooltipManager(); + addChild(tooltipManager); + + tooltipManager->addTooltipFor(m_brushType, "Brush Type", JI_CENTER | JI_BOTTOM); + tooltipManager->addTooltipFor(m_brushSize, "Brush Size (in pixels)", JI_CENTER | JI_BOTTOM); + tooltipManager->addTooltipFor(m_brushAngle, "Brush Angle (in degrees)", JI_CENTER | JI_BOTTOM); + tooltipManager->addTooltipFor(m_inkOpacity, "Opacity (Alpha value in RGBA)", JI_CENTER | JI_BOTTOM); + tooltipManager->addTooltipFor(m_sprayWidth, "Spray Width", JI_CENTER | JI_BOTTOM); + tooltipManager->addTooltipFor(m_spraySpeed, "Spray Speed", JI_CENTER | JI_BOTTOM); + App::instance()->PenSizeAfterChange.connect(&ContextBar::onPenSizeAfterChange, this); App::instance()->CurrentToolChange.connect(&ContextBar::onCurrentToolChange, this); @@ -349,6 +399,9 @@ void ContextBar::onCurrentToolChange() m_inkType->updateSelectedInk(ink); m_inkOpacity->setTextf("%d", toolSettings->getOpacity()); + m_sprayWidth->setValue(toolSettings->getSprayWidth()); + m_spraySpeed->setValue(toolSettings->getSpraySpeed()); + // True if the current tool needs opacity options bool hasOpacity = (currentTool->getInk(0)->isPaint() || currentTool->getInk(0)->isEffect() || @@ -372,8 +425,7 @@ void ContextBar::onCurrentToolChange() m_inkOpacity->setVisible(hasOpacity); m_toleranceLabel->setVisible(hasTolerance); m_tolerance->setVisible(hasTolerance); - - //m_sprayBox->setVisible(hasSprayOptions); + m_sprayBox->setVisible(hasSprayOptions); layout(); } diff --git a/src/widgets/context_bar.h b/src/widgets/context_bar.h index 9c5f441d8..93221371f 100644 --- a/src/widgets/context_bar.h +++ b/src/widgets/context_bar.h @@ -23,6 +23,7 @@ #include "ui/box.h" namespace ui { + class Box; class Label; } @@ -45,6 +46,8 @@ private: class ToleranceField; class InkTypeField; class InkOpacityField; + class SprayWidthField; + class SpraySpeedField; ui::Label* m_brushLabel; BrushTypeField* m_brushType; @@ -55,6 +58,9 @@ private: InkTypeField* m_inkType; ui::Label* m_opacityLabel; InkOpacityField* m_inkOpacity; + ui::Box* m_sprayBox; + SprayWidthField* m_sprayWidth; + SpraySpeedField* m_spraySpeed; }; #endif