Skip to content

Commit 7e7a552

Browse files
Fixed scroller preview total item num
1 parent 539645c commit 7e7a552

File tree

8 files changed

+19
-20
lines changed

8 files changed

+19
-20
lines changed

src/ui/component/base/Scroller.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ void Scroller::updatePos(double pos, double itemSize) {
3636
}
3737

3838
void Scroller::paintPreview(juce::Graphics& g,
39-
int width, int height, bool vertical) {
39+
int width, int height, bool vertical, double totalNum) {
4040
if (this->paintPreviewCallback) {
41-
this->paintPreviewCallback(g, width, height, vertical);
41+
this->paintPreviewCallback(g, width, height, vertical, totalNum);
4242
}
4343
}
4444

src/ui/component/base/Scroller.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Scroller : public ScrollerBase {
99
using ItemNumFunc = std::function<double(void)>;
1010
using ItemSizeLimitFunc = std::function<std::tuple<double, double>(void)>;
1111
using UpdatePosFunc = std::function<void(double, double)>;
12-
using PaintPreviewFunc = std::function<void(juce::Graphics&, int, int, bool)>;
12+
using PaintPreviewFunc = std::function<void(juce::Graphics&, int, int, bool, double)>;
1313
using PaintItemPreviewFunc = std::function<void(juce::Graphics&, int, int, int, bool)>;
1414
using PlayPosFunc = std::function<double(void)>;
1515

@@ -31,7 +31,7 @@ class Scroller : public ScrollerBase {
3131

3232
void updatePos(double pos, double itemSize) override;
3333

34-
void paintPreview(juce::Graphics& g, int width, int height, bool vertical) override;
34+
void paintPreview(juce::Graphics& g, int width, int height, bool vertical, double totalNum) override;
3535
void paintItemPreview(juce::Graphics& g, int itemIndex,
3636
int width, int height, bool vertical) override;
3737

src/ui/component/base/ScrollerBase.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ void ScrollerBase::updateBackTemp() {
566566

567567
/** Paint Preview */
568568
this->paintPreview(g,
569-
this->getWidth(), this->getHeight(), this->vertical);
569+
this->getWidth(), this->getHeight(),
570+
this->vertical, this->itemNum);
570571

571572
/** Paint Item Preview */
572573
double itemAreaSize = this->getTrackLength() / this->itemNum;

src/ui/component/base/ScrollerBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ScrollerBase : public juce::Component,
5050
virtual void updatePos(double pos, double itemSize) = 0;
5151

5252
virtual void paintPreview(juce::Graphics& g,
53-
int width, int height, bool vertical) {};
53+
int width, int height, bool vertical, double totalNum) {};
5454
virtual void paintItemPreview(juce::Graphics& g, int itemIndex,
5555
int width, int height, bool vertical) {};
5656

src/ui/component/editor/MIDISourceEditor.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ MIDISourceEditor::MIDISourceEditor() {
1212
[this] { return this->getTimeLength(); },
1313
[this] { return this->getTimeWidthLimit(); },
1414
[this](double pos, double itemSize) { this->updateHPos(pos, itemSize); },
15-
[this](juce::Graphics& g, int width, int height, bool vertical) {
16-
this->paintNotePreview(g, width, height, vertical); },
15+
[this](juce::Graphics& g, int width, int height, bool vertical, double totalNum) {
16+
this->paintNotePreview(g, width, height, vertical, totalNum); },
1717
Scroller::PaintItemPreviewFunc{},
1818
[this] { return this->getPlayPos(); });
1919
this->hScroller->setShouldShowPlayPos(true);
@@ -311,18 +311,17 @@ void MIDISourceEditor::updateHPos(double pos, double itemSize) {
311311
}
312312

313313
void MIDISourceEditor::paintNotePreview(juce::Graphics& g,
314-
int width, int height, bool /*vertical*/) {
314+
int width, int height, bool /*vertical*/, double totalNum) {
315315
/** Size */
316316
auto screenSize = utils::getScreenSize(this);
317317
float blockRectHeight = screenSize.getHeight() * 0.003;
318318

319319
/** Blocks */
320320
g.setColour(this->trackColor);
321-
double totalLength = this->getTimeLength();
322321
for (int i = 0; i < this->blockItemTemp.size(); i++) {
323322
auto [start, end] = this->blockItemTemp.getUnchecked(i);
324-
float startPos = start / totalLength * width;
325-
float endPos = end / totalLength * width;
323+
float startPos = start / totalNum * width;
324+
float endPos = end / totalNum * width;
326325

327326
juce::Rectangle<float> blockRect(
328327
startPos, 0, endPos - startPos, blockRectHeight);

src/ui/component/editor/MIDISourceEditor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class MIDISourceEditor final
5353

5454
void updateHPos(double pos, double itemSize);
5555
void paintNotePreview(juce::Graphics& g,
56-
int width, int height, bool vertical);
56+
int width, int height, bool vertical, double totalNum);
5757

5858
int getViewHeight() const;
5959
int getKeyNum() const;

src/ui/component/sequencer/SeqView.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ SeqView::SeqView()
260260
[this] { return this->getTimeLength(); },
261261
[this] { return this->getTimeWidthLimit(); },
262262
[this](double pos, double itemSize) { this->updateHPos(pos, itemSize); },
263-
[this](juce::Graphics& g, int width, int height, bool vertical) {
264-
this->paintBlockPreview(g, width, height, vertical); },
263+
[this](juce::Graphics& g, int width, int height, bool vertical, double totalNum) {
264+
this->paintBlockPreview(g, width, height, vertical, totalNum); },
265265
Scroller::PaintItemPreviewFunc{},
266266
[this] { return this->getPlayPos(); });
267267
this->hScroller->setShouldShowPlayPos(true);
@@ -891,7 +891,7 @@ void SeqView::updateHPos(double pos, double itemSize) {
891891
}
892892

893893
void SeqView::paintBlockPreview(juce::Graphics& g,
894-
int width, int height, bool /*vertical*/) {
894+
int width, int height, bool /*vertical*/, double totalNum) {
895895
/** Size */
896896
auto screenSize = utils::getScreenSize(this);
897897
int paddingHeight = screenSize.getHeight() * 0.0035;
@@ -901,11 +901,10 @@ void SeqView::paintBlockPreview(juce::Graphics& g,
901901
float trackHeight = (height - paddingHeight * 2) / (double)(trackNum);
902902
trackHeight = std::min(trackHeight, trackMaxHeight);
903903

904-
double totalLength = this->getTimeLength();
905904
for (auto [trackIndex, start, end] : this->blockTemp) {
906905
if (trackIndex < trackNum) {
907-
float startPos = start / totalLength * width;
908-
float endPos = end / totalLength * width;
906+
float startPos = start / totalNum * width;
907+
float endPos = end / totalNum * width;
909908

910909
juce::Rectangle<float> blockRect(
911910
startPos, paddingHeight + trackIndex * trackHeight,

src/ui/component/sequencer/SeqView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class SeqView final
138138

139139
void updateHPos(double pos, double itemSize);
140140
void paintBlockPreview(juce::Graphics& g,
141-
int width, int height, bool vertical);
141+
int width, int height, bool vertical, double totalNum);
142142

143143
int getViewHeight() const;
144144
int getTrackNum() const;

0 commit comments

Comments
 (0)