Skip to content

Commit

Permalink
Add MessageComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed Jan 12, 2024
1 parent 08bc778 commit 0262249
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/translates/zh-CN/main.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ countries: cn
"Recording" = "录制中"
"Ready" = "就绪"

"Play/Pause" = "播放/暂停"
"Play/Pause" = "播放/暂停"

"No notification" = "无通知"
77 changes: 77 additions & 0 deletions src/ui/component/MessageComponent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "MessageComponent.h"
#include "../lookAndFeel/LookAndFeelFactory.h"
#include "../Utils.h"
#include <IconManager.h>

MessageComponent::MessageComponent() {
/** Mouse Cursor */
this->setMouseCursor(juce::MouseCursor::PointingHandCursor);

/** Look And Feel */
this->setLookAndFeel(
LookAndFeelFactory::getInstance()->forMessage());

/** Icon */
this->mesIcon = flowUI::IconManager::getSVG(
utils::getIconFile("Media", "notification-3-line").getFullPathName());
this->mesIcon->replaceColour(juce::Colours::black,
this->getLookAndFeel().findColour(juce::Label::ColourIds::textColourId));

/** Message */
this->emptyMes = TRANS("No notification");
}

void MessageComponent::paint(juce::Graphics& g) {
auto& laf = this->getLookAndFeel();

/** Size */
int paddingWidth = this->getHeight() * 0.2;
int paddingHeight = this->getHeight() * 0.15;
int splitWidth = this->getHeight() * 0.2;

int iconHeight = this->getHeight() * 0.4;
float noticeHeight = this->getHeight() * 0.15;
int mesHeight = this->getHeight() - paddingHeight * 2;
int mesLines = 2;
float textHeight = mesHeight / (float)mesLines;

/** Color */
juce::Colour backgroundColor = laf.findColour(
juce::ResizableWindow::ColourIds::backgroundColourId);
juce::Colour textColor = laf.findColour(
juce::Label::ColourIds::textColourId);
juce::Colour noticeColor = juce::Colours::red;

/** Font */
juce::Font textFont(textHeight);

/** BackGround */
g.setColour(backgroundColor);
g.fillAll();

/** Icon */
g.setColour(textColor);
juce::Rectangle<float> iconRect(
paddingWidth, this->getHeight() / 2 - iconHeight / 2, iconHeight, iconHeight);
this->mesIcon->drawWithin(g, iconRect,
juce::RectanglePlacement::centred | juce::RectanglePlacement::fillDestination, 1.f);

/** Notice */
if (this->showNoticeDot) {
g.setColour(noticeColor);
juce::Point<float> centerPoint = iconRect.getTopRight();
juce::Rectangle<float> noticeRect(
centerPoint.getX() - noticeHeight / 2, centerPoint.getY() - noticeHeight / 2,
noticeHeight, noticeHeight);
g.fillEllipse(noticeRect);
}

/** Message */
g.setColour(textColor);
g.setFont(textFont);
juce::Rectangle<int> mesRect(
iconRect.getRight() + splitWidth, paddingHeight,
this->getWidth() - (iconRect.getRight() + splitWidth), mesHeight);
g.drawFittedText(this->mes.isEmpty() ? this->emptyMes : this->mes, mesRect,
juce::Justification::centredLeft, mesLines, 1.f);
}
17 changes: 17 additions & 0 deletions src/ui/component/MessageComponent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <JuceHeader.h>

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

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

private:
std::unique_ptr<juce::Drawable> mesIcon = nullptr;
bool showNoticeDot = false;
juce::String mes, emptyMes;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MessageComponent)
};
21 changes: 20 additions & 1 deletion src/ui/component/ToolBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ ToolBar::ToolBar()
/** Tools */
this->tools = std::make_unique<ToolComponent>();
this->addAndMakeVisible(this->tools.get());

/** Message */
this->message = std::make_unique<MessageComponent>();
this->addAndMakeVisible(this->message.get());
}

ToolBar::~ToolBar() {
Expand All @@ -56,6 +60,7 @@ void ToolBar::resized() {
int controllerWidth = this->getHeight() * 3.3;
int toolsHideWidth = this->getHeight() * 6;
int toolsWidth = this->getHeight() * 3.475;
int messageMaxWidth = this->getHeight() * 3;

bool sysStatusShown = this->getWidth() > sysStatusHideWidth;
bool timeShown = this->getWidth() > timeHideWidth;
Expand Down Expand Up @@ -103,10 +108,24 @@ void ToolBar::resized() {
this->mainMenuBar->setBounds(mainMenuBarRect);
totalArea.removeFromTop(mainMenuBarRect.getHeight());

/** Message */
int messageWidth = totalArea.getWidth();
if (toolsShown) {
messageWidth -= (toolsWidth + splitWidth);
}
messageWidth = std::min(messageMaxWidth, messageWidth);

juce::Rectangle<int> messageRect(
totalArea.getX(), totalArea.getY(),
messageWidth, totalArea.getHeight());
this->message->setBounds(messageRect);

totalArea.removeFromLeft(messageRect.getWidth() + splitWidth);

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

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 @@ -8,6 +8,7 @@
#include "TimeComponent.h"
#include "ControllerComponent.h"
#include "ToolComponent.h"
#include "MessageComponent.h"

class ToolBar final : public flowUI::FlowComponent {
public:
Expand All @@ -24,6 +25,7 @@ class ToolBar final : public flowUI::FlowComponent {
std::unique_ptr<TimeComponent> time = nullptr;
std::unique_ptr<ControllerComponent> controller = nullptr;
std::unique_ptr<ToolComponent> tools = nullptr;
std::unique_ptr<MessageComponent> message = nullptr;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ToolBar)
};
8 changes: 8 additions & 0 deletions src/ui/lookAndFeel/LookAndFeelFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "TimeLookAndFeel.h"
#include "ControllerLookAndFeel.h"
#include "ToolsLookAndFeel.h"
#include "MessageLookAndFeel.h"
#include "../misc/ColorMap.h"
#include <FlowUI.h>

Expand Down Expand Up @@ -58,6 +59,9 @@ void LookAndFeelFactory::initialise() {

/** Tools */
this->toolsLAF = std::make_unique<ToolsLookAndFeel>();

/** Message */
this->messageLAF = std::make_unique<MessageLookAndFeel>();
}

void LookAndFeelFactory::setDefaultSansSerifTypeface(juce::Typeface::Ptr typeface) {
Expand Down Expand Up @@ -89,6 +93,10 @@ juce::LookAndFeel_V4* LookAndFeelFactory::forTools() const {
return this->toolsLAF.get();
}

juce::LookAndFeel_V4* LookAndFeelFactory::forMessage() const {
return this->messageLAF.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 @@ -15,6 +15,7 @@ class LookAndFeelFactory final : private juce::DeletedAtShutdown {
juce::LookAndFeel_V4* forTime() const;
juce::LookAndFeel_V4* forController() const;
juce::LookAndFeel_V4* forTools() const;
juce::LookAndFeel_V4* forMessage() const;

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

public:
static LookAndFeelFactory* getInstance();
Expand Down
23 changes: 23 additions & 0 deletions src/ui/lookAndFeel/MessageLookAndFeel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "MessageLookAndFeel.h"
#include "../misc/ColorMap.h"

MessageLookAndFeel::MessageLookAndFeel()
: LookAndFeel_V4() {
/** Background */
this->setColour(juce::ResizableWindow::ColourIds::backgroundColourId,
ColorMap::getInstance()->get("ThemeColorB1"));

/** Text */
this->setColour(juce::Label::ColourIds::backgroundColourId,
ColorMap::getInstance()->get("ThemeColorB1"));
this->setColour(juce::Label::ColourIds::textColourId,
ColorMap::getInstance()->get("ThemeColorB10"));
this->setColour(juce::Label::ColourIds::outlineColourId,
ColorMap::getInstance()->get("ThemeColorB1"));
this->setColour(juce::Label::ColourIds::backgroundWhenEditingColourId,
ColorMap::getInstance()->get("ThemeColorB1"));
this->setColour(juce::Label::ColourIds::textWhenEditingColourId,
ColorMap::getInstance()->get("ThemeColorB10"));
this->setColour(juce::Label::ColourIds::outlineWhenEditingColourId,
ColorMap::getInstance()->get("ThemeColorB1"));
}
12 changes: 12 additions & 0 deletions src/ui/lookAndFeel/MessageLookAndFeel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <JuceHeader.h>

class MessageLookAndFeel : public juce::LookAndFeel_V4 {
public:
MessageLookAndFeel();

private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MessageLookAndFeel)
};

0 comments on commit 0262249

Please sign in to comment.