Skip to content

Commit

Permalink
Add SeqView And Update Scroller item num
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed Mar 9, 2024
1 parent 9048e9c commit 1d92d2c
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "ui/component/CompManager.h"
#include "ui/component/PluginView.h"
#include "ui/component/MixerView.h"
#include "ui/component/SeqView.h"
#include "ui/menuAndCommand/CommandManager.h"
#include "ui/menuAndCommand/CoreCommandTarget.h"
#include "ui/menuAndCommand/GUICommandTarget.h"
Expand Down Expand Up @@ -297,7 +298,7 @@ class MainApplication : public juce::JUCEApplication {
CompManager::getInstance()->set(CompManager::CompType::PluginView,
std::unique_ptr<flowUI::FlowComponent>(new PluginView));
CompManager::getInstance()->set(CompManager::CompType::TrackView,
std::make_unique<flowUI::FlowComponent>(TRANS("Track")));
std::unique_ptr<flowUI::FlowComponent>(new SeqView));
CompManager::getInstance()->set(CompManager::CompType::MixerView,
std::unique_ptr<flowUI::FlowComponent>(new MixerView));
CompManager::getInstance()->set(CompManager::CompType::ResourceEditView,
Expand Down
2 changes: 1 addition & 1 deletion src/ui/component/MixerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ MixerView::MixerView()
/** Scroller */
this->hScroller = std::make_unique<Scroller>(false,
[this] { return this->getViewWidth(); },
[this] { return this->getTrackNum(); },
[this] { return (double)(this->getTrackNum()); },
[this] { return this->getTrackWidthLimit(); },
[this](int pos, int itemSize) { this->updatePos(pos, itemSize); },
Scroller::PaintPreviewFunc{},
Expand Down
2 changes: 1 addition & 1 deletion src/ui/component/Scroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int Scroller::createViewSize() {
return this->viewSizeCallback();
}

int Scroller::createItemNum() {
double Scroller::createItemNum() {
return this->itemNumCallback();
}

Expand Down
4 changes: 2 additions & 2 deletions src/ui/component/Scroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Scroller : public ScrollerBase {
public:
using ViewSizeFunc = std::function<int(void)>;
using ItemNumFunc = std::function<int(void)>;
using ItemNumFunc = std::function<double(void)>;
using ItemSizeLimitFunc = std::function<std::tuple<int, int>(void)>;
using UpdatePosFunc = std::function<void(int, int)>;
using PaintPreviewFunc = std::function<void(juce::Graphics&, bool)>;
Expand All @@ -24,7 +24,7 @@ class Scroller : public ScrollerBase {

protected:
int createViewSize() override;
int createItemNum() override;
double createItemNum() override;
std::tuple<int, int> createItemSizeLimit() override;

void updatePos(int pos, int itemSize) override;
Expand Down
6 changes: 3 additions & 3 deletions src/ui/component/ScrollerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ int ScrollerBase::getItemSize() const {
return this->itemSize;
}

int ScrollerBase::getItemNum() const {
double ScrollerBase::getItemNum() const {
return this->itemNum;
}

Expand Down Expand Up @@ -364,8 +364,8 @@ int ScrollerBase::limitItemSize(int size) const {
return size;
}

int ScrollerBase::limitItemNum(int num) const {
return std::max(num, (int)std::ceil(this->viewSize / (double)this->itemMinSize));
double ScrollerBase::limitItemNum(double num) const {
return std::max(num, std::ceil(this->viewSize / (double)this->itemMinSize));
}

int ScrollerBase::getJudgeSize() const {
Expand Down
9 changes: 5 additions & 4 deletions src/ui/component/ScrollerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ScrollerBase : public juce::Component {
int getViewPos() const;
int getViewSize() const;
int getItemSize() const;
int getItemNum() const;
double getItemNum() const;
int getItemMinSize() const;
int getItemMaxSize() const;

Expand All @@ -33,7 +33,7 @@ class ScrollerBase : public juce::Component {

protected:
virtual int createViewSize() = 0;
virtual int createItemNum() = 0;
virtual double createItemNum() = 0;
virtual std::tuple<int, int> createItemSizeLimit() = 0;

virtual void updatePos(int pos, int itemSize) = 0;
Expand All @@ -46,7 +46,8 @@ class ScrollerBase : public juce::Component {
const bool vertical;

int viewPos = 0, viewSize = 0;
int itemSize = 0, itemNum = 0;
int itemSize = 0;
double itemNum = 0;
int itemMinSize = 0, itemMaxSize = 0;

enum class State {
Expand All @@ -63,7 +64,7 @@ class ScrollerBase : public juce::Component {

int limitPos(int pos) const;
int limitItemSize(int size) const;
int limitItemNum(int num) const;
double limitItemNum(double num) const;

int getJudgeSize() const;
int getTrackLength() const;
Expand Down
88 changes: 88 additions & 0 deletions src/ui/component/SeqView.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include "SeqView.h"
#include "../lookAndFeel/LookAndFeelFactory.h"
#include "../Utils.h"

SeqView::SeqView()
: FlowComponent(TRANS("Track")) {
/** Look And Feel */
this->setLookAndFeel(
LookAndFeelFactory::getInstance()->forSeq());

/** Scroller */
this->hScroller = std::make_unique<Scroller>(false,
[this] { return this->getViewWidth(); },
[this] { return this->getTimeLength(); },
[this] { return this->getTimeWidthLimit(); },
[this](int pos, int itemSize) { this->updateHPos(pos, itemSize); },
Scroller::PaintPreviewFunc{},
Scroller::PaintItemPreviewFunc{});
this->addAndMakeVisible(this->hScroller.get());

this->vScroller = std::make_unique<Scroller>(true,
[this] { return this->getViewHeight(); },
[this] { return (double)this->getTrackNum(); },
[this] { return this->getTrackHeightLimit(); },
[this](int pos, int itemSize) { this->updateVPos(pos, itemSize); },
Scroller::PaintPreviewFunc{},
Scroller::PaintItemPreviewFunc{});
this->addAndMakeVisible(this->vScroller.get());
}

void SeqView::resized() {
/** Size */
auto screenSize = utils::getScreenSize(this);
int scrollerHeight = screenSize.getHeight() * 0.0275;
int scrollerWidth = screenSize.getWidth() * 0.015;
int rulerHeight = screenSize.getHeight() * 0.025;
int headWidth = screenSize.getWidth() * 0.1;

/** Scroller */
juce::Rectangle<int> hScrollerRect(
headWidth, this->getHeight() - scrollerHeight,
this->getWidth() - headWidth - scrollerWidth, scrollerHeight);
this->hScroller->setBounds(hScrollerRect);
juce::Rectangle<int> vScrollerRect(
this->getWidth() - scrollerWidth, rulerHeight,
scrollerWidth, this->getHeight() - rulerHeight - scrollerHeight);
this->vScroller->setBounds(vScrollerRect);

/** Update View Pos */
this->hScroller->update();
this->vScroller->update();
}

int SeqView::getViewWidth() const {
return this->hScroller->getWidth();
}

double SeqView::getTimeLength() const {
/** TODO */
return 0;
}

std::tuple<int, int> SeqView::getTimeWidthLimit() const {
auto screenSize = utils::getScreenSize(this);
return { (int)(screenSize.getWidth() * 0.02), (int)(screenSize.getWidth() * 0.2) };
}

void SeqView::updateHPos(int pos, int itemSize) {
/** TODO */
}

int SeqView::getViewHeight() const {
return this->vScroller->getHeight();
}

int SeqView::getTrackNum() const {
/** TODO */
return 0;
}

std::tuple<int, int> SeqView::getTrackHeightLimit() const {
auto screenSize = utils::getScreenSize(this);
return { (int)(screenSize.getHeight() * 0.025), (int)(screenSize.getWidth() * 0.4) };
}

void SeqView::updateVPos(int pos, int itemSize) {
/** TODO */
}
32 changes: 32 additions & 0 deletions src/ui/component/SeqView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include <JuceHeader.h>
#include <FlowUI.h>
#include "Scroller.h"

class SeqView final
: public flowUI::FlowComponent,
public juce::DragAndDropContainer {
public:
SeqView();

void resized() override;

private:
std::unique_ptr<Scroller> hScroller = nullptr;
std::unique_ptr<Scroller> vScroller = nullptr;

int getViewWidth() const;
double getTimeLength() const;
std::tuple<int, int> getTimeWidthLimit() const;

void updateHPos(int pos, int itemSize);

int getViewHeight() const;
int getTrackNum() const;
std::tuple<int, int> getTrackHeightLimit() const;

void updateVPos(int pos, int itemSize);

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SeqView)
};
8 changes: 8 additions & 0 deletions src/ui/lookAndFeel/LookAndFeelFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "LevelMeterLookAndFeel.h"
#include "MuteButtonLookAndFeel.h"
#include "EffectLookAndFeel.h"
#include "SeqLookAndFeel.h"
#include "../misc/ColorMap.h"
#include <FlowUI.h>

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

/** Effect */
this->effectLAF = std::make_unique<EffectLookAndFeel>();

/** Sequencer */
this->seqLAF = std::make_unique<SeqLookAndFeel>();
}

void LookAndFeelFactory::setDefaultSansSerifTypeface(juce::Typeface::Ptr typeface) {
Expand Down Expand Up @@ -185,6 +189,10 @@ juce::LookAndFeel_V4* LookAndFeelFactory::forEffect() const {
return this->effectLAF.get();
}

juce::LookAndFeel_V4* LookAndFeelFactory::forSeq() const {
return this->seqLAF.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 @@ -27,6 +27,7 @@ class LookAndFeelFactory final : private juce::DeletedAtShutdown {
juce::LookAndFeel_V4* forLevelMeter() const;
juce::LookAndFeel_V4* forMuteButton() const;
juce::LookAndFeel_V4* forEffect() const;
juce::LookAndFeel_V4* forSeq() const;

private:
std::unique_ptr<juce::LookAndFeel> mainLAF = nullptr;
Expand All @@ -48,6 +49,7 @@ class LookAndFeelFactory final : private juce::DeletedAtShutdown {
std::unique_ptr<juce::LookAndFeel_V4> levelMeterLAF = nullptr;
std::unique_ptr<juce::LookAndFeel_V4> muteButtonLAF = nullptr;
std::unique_ptr<juce::LookAndFeel_V4> effectLAF = nullptr;
std::unique_ptr<juce::LookAndFeel_V4> seqLAF = nullptr;

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

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

/** Track */
this->setColour(juce::Label::ColourIds::backgroundColourId,
ColorMap::getInstance()->get("ThemeColorB2"));/**< Track Background */
this->setColour(juce::Label::ColourIds::textColourId,
ColorMap::getInstance()->get("ThemeColorB10"));/**< Item Name Light */
this->setColour(juce::Label::ColourIds::outlineColourId,
ColorMap::getInstance()->get("ThemeColorB1"));/**< Track Outline */
this->setColour(juce::Label::ColourIds::backgroundWhenEditingColourId,
ColorMap::getInstance()->get("ThemeColorB2"));
this->setColour(juce::Label::ColourIds::textWhenEditingColourId,
ColorMap::getInstance()->get("ThemeColorB0"));/**< Item Name Dark */
this->setColour(juce::Label::ColourIds::outlineWhenEditingColourId,
ColorMap::getInstance()->get("ThemeColorA2"));/**< Track Hovered Outline */
}
12 changes: 12 additions & 0 deletions src/ui/lookAndFeel/SeqLookAndFeel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <JuceHeader.h>
#include "MainLookAndFeel.h"

class SeqLookAndFeel : public MainLookAndFeel {
public:
SeqLookAndFeel();

private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SeqLookAndFeel)
};

0 comments on commit 1d92d2c

Please sign in to comment.