mirror of https://github.com/odrling/Aegisub
Change AudioDisplay::style_ranges to a vector
This is faster in all cases except for repainting a very small part of the display with a very large number of range transitions and simplifies the code a bit.
This commit is contained in:
parent
f81736d461
commit
7a3110015e
|
@ -546,9 +546,8 @@ AudioDisplay::AudioDisplay(wxWindow *parent, AudioController *controller, agi::C
|
||||||
, controller(controller)
|
, controller(controller)
|
||||||
, scrollbar(agi::make_unique<AudioDisplayScrollbar>(this))
|
, scrollbar(agi::make_unique<AudioDisplayScrollbar>(this))
|
||||||
, timeline(agi::make_unique<AudioDisplayTimeline>(this))
|
, timeline(agi::make_unique<AudioDisplayTimeline>(this))
|
||||||
|
, style_ranges({{0, 0}})
|
||||||
{
|
{
|
||||||
style_ranges[0] = AudioStyle_Normal;
|
|
||||||
|
|
||||||
audio_renderer->SetAmplitudeScale(scale_amplitude);
|
audio_renderer->SetAmplitudeScale(scale_amplitude);
|
||||||
SetZoomLevel(0);
|
SetZoomLevel(0);
|
||||||
|
|
||||||
|
@ -819,22 +818,17 @@ void AudioDisplay::OnPaint(wxPaintEvent&)
|
||||||
|
|
||||||
void AudioDisplay::PaintAudio(wxDC &dc, TimeRange updtime, wxRect updrect)
|
void AudioDisplay::PaintAudio(wxDC &dc, TimeRange updtime, wxRect updrect)
|
||||||
{
|
{
|
||||||
auto pt = style_ranges.upper_bound(updtime.begin());
|
auto pt = begin(style_ranges), pe = end(style_ranges);
|
||||||
auto pe = style_ranges.upper_bound(updtime.end());
|
while (pt != pe && pt + 1 != pe && (pt + 1)->first < updtime.begin()) ++pt;
|
||||||
|
|
||||||
if (pt != style_ranges.begin())
|
while (pt != pe && pt->first < updtime.end())
|
||||||
--pt;
|
|
||||||
|
|
||||||
while (pt != pe)
|
|
||||||
{
|
{
|
||||||
AudioRenderingStyle range_style = static_cast<AudioRenderingStyle>(pt->second);
|
auto range_style = static_cast<AudioRenderingStyle>(pt->second);
|
||||||
int range_x1 = std::max(updrect.x, RelativeXFromTime(pt->first));
|
int range_x1 = std::max(updrect.x, RelativeXFromTime(pt->first));
|
||||||
int range_x2 = (++pt == pe) ? updrect.x + updrect.width : RelativeXFromTime(pt->first);
|
int range_x2 = (++pt == pe) ? updrect.x + updrect.width : RelativeXFromTime(pt->first);
|
||||||
|
|
||||||
if (range_x2 > range_x1)
|
if (range_x2 > range_x1)
|
||||||
{
|
|
||||||
audio_renderer->Render(dc, wxPoint(range_x1, audio_top), range_x1 + scroll_left, range_x2 - range_x1, range_style);
|
audio_renderer->Render(dc, wxPoint(range_x1, audio_top), range_x1 + scroll_left, range_x2 - range_x1, range_style);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1308,7 +1302,7 @@ void AudioDisplay::OnStyleRangesChanged()
|
||||||
controller->GetTimingController()->GetRenderingStyles(asrm);
|
controller->GetTimingController()->GetRenderingStyles(asrm);
|
||||||
|
|
||||||
style_ranges.clear();
|
style_ranges.clear();
|
||||||
style_ranges.insert(asrm.begin(), asrm.end());
|
for (auto pair : asrm) style_ranges.push_back(pair);
|
||||||
|
|
||||||
RefreshRect(wxRect(0, audio_top, GetClientSize().GetWidth(), audio_height), false);
|
RefreshRect(wxRect(0, audio_top, GetClientSize().GetWidth(), audio_height), false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <map>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <wx/gdicmn.h>
|
#include <wx/gdicmn.h>
|
||||||
|
@ -175,7 +174,7 @@ class AudioDisplay: public wxWindow {
|
||||||
void RemoveTrackCursor();
|
void RemoveTrackCursor();
|
||||||
|
|
||||||
/// Previous style ranges for optimizing redraw when ranges change
|
/// Previous style ranges for optimizing redraw when ranges change
|
||||||
std::map<int, int> style_ranges;
|
std::vector<std::pair<int, int>> style_ranges;
|
||||||
|
|
||||||
/// @brief Reload all rendering settings from Options and reset caches
|
/// @brief Reload all rendering settings from Options and reset caches
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in New Issue