Skip to content

Commit

Permalink
Add ToolComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed Jan 11, 2024
1 parent e2868cb commit e18fa1b
Show file tree
Hide file tree
Showing 12 changed files with 391 additions and 11 deletions.
14 changes: 14 additions & 0 deletions app/translates/zh-CN/menu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ countries: cn

"Follow" = "跟随"

"Arrow" = "箭头"
"Hand" = "手"
"Pencil" = "铅笔"
"Magic" = "魔棒"
"Scissors" = "剪刀"
"Eraser" = "橡皮"

"Startup Config" = "启动配置"
"Function Config" = "功能配置"
"Audio Config" = "音频配置"
Expand Down Expand Up @@ -102,6 +109,13 @@ countries: cn

"Follow playing position in editor." = "在编辑器中跟随播放位置。"

"Arrow tool." = "箭头工具。"
"Hand tool." = "手工具。"
"Pencil tool." = "铅笔工具。"
"Magic tool." = "魔棒工具。"
"Scissors tool." = "剪刀工具。"
"Eraser tool." = "橡皮工具。"

"Open startup config page." = "打开启动配置页面。"
"Open the function config page." = "打开功能配置页面。"
"Open the audio config page." = "打开音频配置界面。"
Expand Down
40 changes: 29 additions & 11 deletions src/ui/component/ToolBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ ToolBar::ToolBar()
/** Controller */
this->controller = std::make_unique<ControllerComponent>();
this->addAndMakeVisible(this->controller.get());

/** Tools */
this->tools = std::make_unique<ToolComponent>();
this->addAndMakeVisible(this->tools.get());
}

ToolBar::~ToolBar() {
Expand All @@ -44,25 +48,28 @@ void ToolBar::resized() {
/** Size */
int splitWidth = this->getHeight() * 0.075;
int mainMenuBarHeight = this->getHeight() * 0.4;
int sysStatusHideWidth = this->getHeight() * 14;
int sysStatusHideWidth = this->getHeight() * 15;
int sysStatusWidth = this->getHeight() * 4;
int timeHideWidth = this->getHeight() * 7;
int timeHideWidth = this->getHeight() * 8;
int timeWidth = this->getHeight() * 2.75;
int controllerHideWidth = this->getHeight() * 10;
int controllerHideWidth = this->getHeight() * 11;
int controllerWidth = this->getHeight() * 3.3;
int toolsHideWidth = this->getHeight() * 6;
int toolsWidth = this->getHeight() * 3.475;

bool sysStatusShown = this->getWidth() > sysStatusHideWidth;
bool timeShown = this->getWidth() > timeHideWidth;
bool controllerShown = this->getWidth() > controllerHideWidth;
bool toolsShown = this->getWidth() > toolsHideWidth;

/** Total Area */
auto totalArea = this->getLocalBounds();

/** System Status */
if (sysStatusShown) {
juce::Rectangle<int> sysStatusRect(
totalArea.getRight() - sysStatusWidth, 0,
sysStatusWidth, this->getHeight());
totalArea.getRight() - sysStatusWidth, totalArea.getY(),
sysStatusWidth, totalArea.getHeight());
this->sysStatus->setBounds(sysStatusRect);

totalArea.removeFromRight(sysStatusRect.getWidth() + splitWidth);
Expand All @@ -72,8 +79,8 @@ void ToolBar::resized() {
/** Time */
if (timeShown) {
juce::Rectangle<int> timeRect(
totalArea.getRight() - timeWidth, 0,
timeWidth, this->getHeight());
totalArea.getRight() - timeWidth, totalArea.getY(),
timeWidth, totalArea.getHeight());
this->time->setBounds(timeRect);

totalArea.removeFromRight(timeRect.getWidth() + splitWidth);
Expand All @@ -83,18 +90,29 @@ void ToolBar::resized() {
/** Controller */
if (controllerShown) {
juce::Rectangle<int> controllerRect(
totalArea.getRight() - controllerWidth, 0,
controllerWidth, this->getHeight());
totalArea.getRight() - controllerWidth, totalArea.getY(),
controllerWidth, totalArea.getHeight());
this->controller->setBounds(controllerRect);

totalArea.removeFromRight(controllerRect.getWidth() + splitWidth);
}
this->controller->setVisible(controllerShown);

/** Main Menu Bar */
juce::Rectangle<int> mainMenuBarRect(
0, 0, totalArea.getRight(), mainMenuBarHeight);
juce::Rectangle<int> mainMenuBarRect = totalArea.withHeight(mainMenuBarHeight);
this->mainMenuBar->setBounds(mainMenuBarRect);
totalArea.removeFromTop(mainMenuBarRect.getHeight());

/** Tools */
if (toolsShown) {
juce::Rectangle<int> toolsRect(
0, totalArea.getY(),
toolsWidth, totalArea.getHeight());
this->tools->setBounds(toolsRect);

totalArea.removeFromLeft(toolsRect.getWidth() + splitWidth);
}
this->tools->setVisible(toolsShown);
}

void ToolBar::paint(juce::Graphics& g) {
Expand Down
2 changes: 2 additions & 0 deletions src/ui/component/ToolBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "SysStatusComponent.h"
#include "TimeComponent.h"
#include "ControllerComponent.h"
#include "ToolComponent.h"

class ToolBar final : public flowUI::FlowComponent {
public:
Expand All @@ -22,6 +23,7 @@ class ToolBar final : public flowUI::FlowComponent {
std::unique_ptr<SysStatusComponent> sysStatus = nullptr;
std::unique_ptr<TimeComponent> time = nullptr;
std::unique_ptr<ControllerComponent> controller = nullptr;
std::unique_ptr<ToolComponent> tools = nullptr;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ToolBar)
};
183 changes: 183 additions & 0 deletions src/ui/component/ToolComponent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
#include "ToolComponent.h"
#include "../lookAndFeel/LookAndFeelFactory.h"
#include "../menuAndCommand/CommandManager.h"
#include "../menuAndCommand/CommandTypes.h"
#include "../Utils.h"
#include <IconManager.h>

ToolComponent::ToolComponent() {
/** Look And Feel */
this->setLookAndFeel(
LookAndFeelFactory::getInstance()->forTools());

/** Icons */
auto arrowIcon = flowUI::IconManager::getSVG(
utils::getIconFile("Development", "cursor-line").getFullPathName());
arrowIcon->replaceColour(juce::Colours::black,
this->getLookAndFeel().findColour(juce::TextButton::ColourIds::textColourOffId));
this->icons.add(std::move(arrowIcon));

auto arrowIconOn = flowUI::IconManager::getSVG(
utils::getIconFile("Development", "cursor-line").getFullPathName());
arrowIconOn->replaceColour(juce::Colours::black,
this->getLookAndFeel().findColour(juce::TextButton::ColourIds::textColourOnId));
this->icons.add(std::move(arrowIconOn));

auto handIcon = flowUI::IconManager::getSVG(
utils::getIconFile("Editor", "hand").getFullPathName());
handIcon->replaceColour(juce::Colours::black,
this->getLookAndFeel().findColour(juce::TextButton::ColourIds::textColourOffId));
this->icons.add(std::move(handIcon));

auto handIconOn = flowUI::IconManager::getSVG(
utils::getIconFile("Editor", "hand").getFullPathName());
handIconOn->replaceColour(juce::Colours::black,
this->getLookAndFeel().findColour(juce::TextButton::ColourIds::textColourOnId));
this->icons.add(std::move(handIconOn));

auto pencilIcon = flowUI::IconManager::getSVG(
utils::getIconFile("Design", "pencil-line").getFullPathName());
pencilIcon->replaceColour(juce::Colours::black,
this->getLookAndFeel().findColour(juce::TextButton::ColourIds::textColourOffId));
this->icons.add(std::move(pencilIcon));

auto pencilIconOn = flowUI::IconManager::getSVG(
utils::getIconFile("Design", "pencil-line").getFullPathName());
pencilIconOn->replaceColour(juce::Colours::black,
this->getLookAndFeel().findColour(juce::TextButton::ColourIds::textColourOnId));
this->icons.add(std::move(pencilIconOn));

auto magicIcon = flowUI::IconManager::getSVG(
utils::getIconFile("Design", "magic-line").getFullPathName());
magicIcon->replaceColour(juce::Colours::black,
this->getLookAndFeel().findColour(juce::TextButton::ColourIds::textColourOffId));
this->icons.add(std::move(magicIcon));

auto magicIconOn = flowUI::IconManager::getSVG(
utils::getIconFile("Design", "magic-line").getFullPathName());
magicIconOn->replaceColour(juce::Colours::black,
this->getLookAndFeel().findColour(juce::TextButton::ColourIds::textColourOnId));
this->icons.add(std::move(magicIconOn));

auto scissorsIcon = flowUI::IconManager::getSVG(
utils::getIconFile("Design", "scissors-2-line").getFullPathName());
scissorsIcon->replaceColour(juce::Colours::black,
this->getLookAndFeel().findColour(juce::TextButton::ColourIds::textColourOffId));
this->icons.add(std::move(scissorsIcon));

auto scissorsIconOn = flowUI::IconManager::getSVG(
utils::getIconFile("Design", "scissors-2-line").getFullPathName());
scissorsIconOn->replaceColour(juce::Colours::black,
this->getLookAndFeel().findColour(juce::TextButton::ColourIds::textColourOnId));
this->icons.add(std::move(scissorsIconOn));

auto eraserIcon = flowUI::IconManager::getSVG(
utils::getIconFile("Design", "eraser-line").getFullPathName());
eraserIcon->replaceColour(juce::Colours::black,
this->getLookAndFeel().findColour(juce::TextButton::ColourIds::textColourOffId));
this->icons.add(std::move(eraserIcon));

auto eraserIconOn = flowUI::IconManager::getSVG(
utils::getIconFile("Design", "eraser-line").getFullPathName());
eraserIconOn->replaceColour(juce::Colours::black,
this->getLookAndFeel().findColour(juce::TextButton::ColourIds::textColourOnId));
this->icons.add(std::move(eraserIconOn));

/** Buttons */
auto arrowButton = std::make_unique<juce::DrawableButton>(
TRANS("Arrow"), juce::DrawableButton::ButtonStyle::ImageOnButtonBackground);
arrowButton->setImages(
this->icons[0], nullptr, nullptr, nullptr,
this->icons[1], nullptr, nullptr, nullptr);
arrowButton->setWantsKeyboardFocus(false);
arrowButton->setMouseCursor(juce::MouseCursor::PointingHandCursor);
arrowButton->setCommandToTrigger(
CommandManager::getInstance(), (juce::CommandID)GUICommandType::Arrow, true);
this->addAndMakeVisible(arrowButton.get());
this->buttons.add(std::move(arrowButton));

auto handButton = std::make_unique<juce::DrawableButton>(
TRANS("Hand"), juce::DrawableButton::ButtonStyle::ImageOnButtonBackground);
handButton->setImages(
this->icons[2], nullptr, nullptr, nullptr,
this->icons[3], nullptr, nullptr, nullptr);
handButton->setWantsKeyboardFocus(false);
handButton->setMouseCursor(juce::MouseCursor::PointingHandCursor);
handButton->setCommandToTrigger(
CommandManager::getInstance(), (juce::CommandID)GUICommandType::Hand, true);
this->addAndMakeVisible(handButton.get());
this->buttons.add(std::move(handButton));

auto pencilButton = std::make_unique<juce::DrawableButton>(
TRANS("Pencil"), juce::DrawableButton::ButtonStyle::ImageOnButtonBackground);
pencilButton->setImages(
this->icons[4], nullptr, nullptr, nullptr,
this->icons[5], nullptr, nullptr, nullptr);
pencilButton->setWantsKeyboardFocus(false);
pencilButton->setMouseCursor(juce::MouseCursor::PointingHandCursor);
pencilButton->setCommandToTrigger(
CommandManager::getInstance(), (juce::CommandID)GUICommandType::Pencil, true);
this->addAndMakeVisible(pencilButton.get());
this->buttons.add(std::move(pencilButton));

auto magicButton = std::make_unique<juce::DrawableButton>(
TRANS("Magic"), juce::DrawableButton::ButtonStyle::ImageOnButtonBackground);
magicButton->setImages(
this->icons[6], nullptr, nullptr, nullptr,
this->icons[7], nullptr, nullptr, nullptr);
magicButton->setWantsKeyboardFocus(false);
magicButton->setMouseCursor(juce::MouseCursor::PointingHandCursor);
magicButton->setCommandToTrigger(
CommandManager::getInstance(), (juce::CommandID)GUICommandType::Magic, true);
this->addAndMakeVisible(magicButton.get());
this->buttons.add(std::move(magicButton));

auto scissorsButton = std::make_unique<juce::DrawableButton>(
TRANS("Scissors"), juce::DrawableButton::ButtonStyle::ImageOnButtonBackground);
scissorsButton->setImages(
this->icons[8], nullptr, nullptr, nullptr,
this->icons[9], nullptr, nullptr, nullptr);
scissorsButton->setWantsKeyboardFocus(false);
scissorsButton->setMouseCursor(juce::MouseCursor::PointingHandCursor);
scissorsButton->setCommandToTrigger(
CommandManager::getInstance(), (juce::CommandID)GUICommandType::Scissors, true);
this->addAndMakeVisible(scissorsButton.get());
this->buttons.add(std::move(scissorsButton));

auto eraserButton = std::make_unique<juce::DrawableButton>(
TRANS("Eraser"), juce::DrawableButton::ButtonStyle::ImageOnButtonBackground);
eraserButton->setImages(
this->icons[10], nullptr, nullptr, nullptr,
this->icons[11], nullptr, nullptr, nullptr);
eraserButton->setWantsKeyboardFocus(false);
eraserButton->setMouseCursor(juce::MouseCursor::PointingHandCursor);
eraserButton->setCommandToTrigger(
CommandManager::getInstance(), (juce::CommandID)GUICommandType::Eraser, true);
this->addAndMakeVisible(eraserButton.get());
this->buttons.add(std::move(eraserButton));
}

void ToolComponent::resized() {
auto screenSize = utils::getScreenSize(this);

/** Size */
int paddingHeight = this->getHeight() * 0.1;
int paddingWidth = this->getHeight() * 0.1;
int splitHeight = this->getHeight() * 0.05;
int splitWidth = this->getHeight() * 0.05;

int leftPos = paddingWidth;
int buttonHeight = this->getHeight() * 0.9;

/** Buttons */
for (auto i : this->buttons) {
i->setBounds(leftPos, this->getHeight() / 2 - buttonHeight / 2,
buttonHeight, buttonHeight);
leftPos += buttonHeight;
leftPos += splitWidth;
}
}

void ToolComponent::paint(juce::Graphics& g) {
/** Nothing To Do */
}
17 changes: 17 additions & 0 deletions src/ui/component/ToolComponent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <JuceHeader.h>

class ToolComponent final : public juce::Component {
public:
ToolComponent();

void resized() override;
void paint(juce::Graphics& g) override;

private:
juce::OwnedArray<juce::DrawableButton> buttons;
juce::OwnedArray<juce::Drawable> icons;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ToolComponent)
};
7 changes: 7 additions & 0 deletions src/ui/dataModel/MainMenuModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ juce::PopupMenu MainMenuModel::createControl() const {
menu.addCommandItem(CommandManager::getInstance(), (juce::CommandID)CoreCommandType::Rewind);
menu.addSeparator();
menu.addCommandItem(CommandManager::getInstance(), (juce::CommandID)GUICommandType::Follow);
menu.addSeparator();
menu.addCommandItem(CommandManager::getInstance(), (juce::CommandID)GUICommandType::Arrow);
menu.addCommandItem(CommandManager::getInstance(), (juce::CommandID)GUICommandType::Hand);
menu.addCommandItem(CommandManager::getInstance(), (juce::CommandID)GUICommandType::Pencil);
menu.addCommandItem(CommandManager::getInstance(), (juce::CommandID)GUICommandType::Magic);
menu.addCommandItem(CommandManager::getInstance(), (juce::CommandID)GUICommandType::Scissors);
menu.addCommandItem(CommandManager::getInstance(), (juce::CommandID)GUICommandType::Eraser);

return menu;
}
Expand Down
17 changes: 17 additions & 0 deletions src/ui/lookAndFeel/LookAndFeelFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ void LookAndFeelFactory::initialise() {
ColorMap::getInstance()->get("ThemeColorB10"));
this->controllerLAF->setColour(juce::ComboBox::ColourIds::outlineColourId,
ColorMap::getInstance()->get("ThemeColorB2"));

/** Tools */
this->toolsLAF = std::make_unique<juce::LookAndFeel_V4>();
this->toolsLAF->setColour(juce::TextButton::ColourIds::buttonColourId,
ColorMap::getInstance()->get("ThemeColorB2"));
this->toolsLAF->setColour(juce::TextButton::ColourIds::buttonOnColourId,
ColorMap::getInstance()->get("ThemeColorB1"));
this->toolsLAF->setColour(juce::TextButton::ColourIds::textColourOffId,
ColorMap::getInstance()->get("ThemeColorB8"));
this->toolsLAF->setColour(juce::TextButton::ColourIds::textColourOnId,
ColorMap::getInstance()->get("ThemeColorB10"));
this->toolsLAF->setColour(juce::ComboBox::ColourIds::outlineColourId,
ColorMap::getInstance()->get("ThemeColorB2"));
}

void LookAndFeelFactory::setDefaultSansSerifTypeface(juce::Typeface::Ptr typeface) {
Expand Down Expand Up @@ -128,6 +141,10 @@ juce::LookAndFeel_V4* LookAndFeelFactory::forController() const {
return this->controllerLAF.get();
}

juce::LookAndFeel_V4* LookAndFeelFactory::forTools() const {
return this->toolsLAF.get();
}

LookAndFeelFactory* LookAndFeelFactory::getInstance() {
return LookAndFeelFactory::instance ? LookAndFeelFactory::instance
: (LookAndFeelFactory::instance = new LookAndFeelFactory{});
Expand Down
2 changes: 2 additions & 0 deletions src/ui/lookAndFeel/LookAndFeelFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class LookAndFeelFactory final : private juce::DeletedAtShutdown {
juce::LookAndFeel_V4* forSysStatus() const;
juce::LookAndFeel_V4* forTime() const;
juce::LookAndFeel_V4* forController() const;
juce::LookAndFeel_V4* forTools() const;

private:
std::unique_ptr<juce::LookAndFeel> mainLAF = nullptr;
Expand All @@ -22,6 +23,7 @@ class LookAndFeelFactory final : private juce::DeletedAtShutdown {
std::unique_ptr<juce::LookAndFeel_V4> sysStatusLAF = nullptr;
std::unique_ptr<juce::LookAndFeel_V4> timeLAF = nullptr;
std::unique_ptr<juce::LookAndFeel_V4> controllerLAF = nullptr;
std::unique_ptr<juce::LookAndFeel_V4> toolsLAF = nullptr;

public:
static LookAndFeelFactory* getInstance();
Expand Down
Loading

0 comments on commit e18fa1b

Please sign in to comment.