| @@ -390,33 +390,10 @@ static const std::string sortNames[] = { | |||||
| }; | }; | ||||
| struct SortItem : ui::MenuItem { | |||||
| Browser* browser; | |||||
| settings::BrowserSort sort; | |||||
| void onAction(const ActionEvent& e) override; | |||||
| void step() override { | |||||
| rightText = CHECKMARK(settings::browserSort == sort); | |||||
| MenuItem::step(); | |||||
| } | |||||
| }; | |||||
| struct SortButton : ui::ChoiceButton { | struct SortButton : ui::ChoiceButton { | ||||
| Browser* browser; | Browser* browser; | ||||
| void onAction(const ActionEvent& e) override { | |||||
| ui::Menu* menu = createMenu(); | |||||
| menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y)); | |||||
| menu->box.size.x = box.size.x; | |||||
| for (int sortId = 0; sortId <= settings::BROWSER_SORT_RANDOM; sortId++) { | |||||
| SortItem* sortItem = new SortItem; | |||||
| sortItem->text = sortNames[sortId]; | |||||
| sortItem->sort = (settings::BrowserSort) sortId; | |||||
| sortItem->browser = browser; | |||||
| menu->addChild(sortItem); | |||||
| } | |||||
| } | |||||
| void onAction(const ActionEvent& e) override; | |||||
| void step() override { | void step() override { | ||||
| text = "Sort: "; | text = "Sort: "; | ||||
| @@ -426,33 +403,10 @@ struct SortButton : ui::ChoiceButton { | |||||
| }; | }; | ||||
| struct ZoomItem : ui::MenuItem { | |||||
| Browser* browser; | |||||
| float zoom; | |||||
| void onAction(const ActionEvent& e) override; | |||||
| void step() override { | |||||
| rightText = CHECKMARK(settings::browserZoom == zoom); | |||||
| MenuItem::step(); | |||||
| } | |||||
| }; | |||||
| struct ZoomButton : ui::ChoiceButton { | struct ZoomButton : ui::ChoiceButton { | ||||
| Browser* browser; | Browser* browser; | ||||
| void onAction(const ActionEvent& e) override { | |||||
| ui::Menu* menu = createMenu(); | |||||
| menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y)); | |||||
| menu->box.size.x = box.size.x; | |||||
| for (float zoom = 1.f; zoom >= -2.f; zoom -= 0.5f) { | |||||
| ZoomItem* sortItem = new ZoomItem; | |||||
| sortItem->text = string::f("%.0f%%", std::pow(2.f, zoom) * 100.f); | |||||
| sortItem->zoom = zoom; | |||||
| sortItem->browser = browser; | |||||
| menu->addChild(sortItem); | |||||
| } | |||||
| } | |||||
| void onAction(const ActionEvent& e) override; | |||||
| void step() override { | void step() override { | ||||
| text = "Zoom: "; | text = "Zoom: "; | ||||
| @@ -994,15 +948,37 @@ inline void TagButton::step() { | |||||
| ChoiceButton::step(); | ChoiceButton::step(); | ||||
| } | } | ||||
| inline void SortItem::onAction(const ActionEvent& e) { | |||||
| settings::browserSort = sort; | |||||
| browser->refresh(); | |||||
| inline void SortButton::onAction(const ActionEvent& e) { | |||||
| ui::Menu* menu = createMenu(); | |||||
| menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y)); | |||||
| menu->box.size.x = box.size.x; | |||||
| for (int sortId = 0; sortId <= settings::BROWSER_SORT_RANDOM; sortId++) { | |||||
| menu->addChild(createCheckMenuItem(sortNames[sortId], "", | |||||
| [=]() {return settings::browserSort == sortId;}, | |||||
| [=]() { | |||||
| settings::browserSort = (settings::BrowserSort) sortId; | |||||
| browser->refresh(); | |||||
| } | |||||
| )); | |||||
| } | |||||
| } | } | ||||
| inline void ZoomItem::onAction(const ActionEvent& e) { | |||||
| if (zoom != settings::browserZoom) { | |||||
| settings::browserZoom = zoom; | |||||
| browser->updateZoom(); | |||||
| inline void ZoomButton::onAction(const ActionEvent& e) { | |||||
| ui::Menu* menu = createMenu(); | |||||
| menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y)); | |||||
| menu->box.size.x = box.size.x; | |||||
| for (float zoom = 1.f; zoom >= -2.f; zoom -= 0.5f) { | |||||
| menu->addChild(createCheckMenuItem(string::f("%.0f%%", std::pow(2.f, zoom) * 100.f), "", | |||||
| [=]() {return settings::browserZoom == zoom;}, | |||||
| [=]() { | |||||
| if (zoom == settings::browserZoom) | |||||
| return; | |||||
| settings::browserZoom = zoom; | |||||
| browser->updateZoom(); | |||||
| } | |||||
| )); | |||||
| } | } | ||||
| } | } | ||||
| @@ -469,11 +469,11 @@ struct SampleRateItem : ui::MenuItem { | |||||
| if (settings::sampleRate == 0) { | if (settings::sampleRate == 0) { | ||||
| float sampleRate = APP->engine->getSampleRate(); | float sampleRate = APP->engine->getSampleRate(); | ||||
| rightText += string::f("(%g kHz) ", sampleRate / 1000.f); | rightText += string::f("(%g kHz) ", sampleRate / 1000.f); | ||||
| rightText += CHECKMARK_STRING; | |||||
| } | } | ||||
| menu->addChild(createMenuItem("Auto", rightText, [=]() { | |||||
| settings::sampleRate = 0; | |||||
| })); | |||||
| menu->addChild(createCheckMenuItem("Auto", rightText, | |||||
| [=]() {return settings::sampleRate == 0;}, | |||||
| [=]() {settings::sampleRate = 0;} | |||||
| )); | |||||
| // Power-of-2 oversample times 44.1kHz or 48kHz | // Power-of-2 oversample times 44.1kHz or 48kHz | ||||
| for (int i = -2; i <= 4; i++) { | for (int i = -2; i <= 4; i++) { | ||||
| @@ -490,11 +490,10 @@ struct SampleRateItem : ui::MenuItem { | |||||
| else if (oversample < 1.f) { | else if (oversample < 1.f) { | ||||
| rightText += string::f("(1/%.0fx)", 1.f / oversample); | rightText += string::f("(1/%.0fx)", 1.f / oversample); | ||||
| } | } | ||||
| rightText += " "; | |||||
| rightText += CHECKMARK(settings::sampleRate == sampleRate); | |||||
| menu->addChild(createMenuItem(text, rightText, [=]() { | |||||
| settings::sampleRate = sampleRate; | |||||
| })); | |||||
| menu->addChild(createCheckMenuItem(text, rightText, | |||||
| [=]() {return settings::sampleRate == sampleRate;}, | |||||
| [=]() {settings::sampleRate = sampleRate;} | |||||
| )); | |||||
| } | } | ||||
| } | } | ||||
| return menu; | return menu; | ||||
| @@ -515,10 +514,7 @@ struct EngineButton : MenuButton { | |||||
| settings::cpuMeter ^= true; | settings::cpuMeter ^= true; | ||||
| })); | })); | ||||
| SampleRateItem* sampleRateItem = new SampleRateItem; | |||||
| sampleRateItem->text = "Sample rate"; | |||||
| sampleRateItem->rightText = RIGHT_ARROW; | |||||
| menu->addChild(sampleRateItem); | |||||
| menu->addChild(createMenuItem<SampleRateItem>("Sample rate", RIGHT_ARROW)); | |||||
| menu->addChild(createSubmenuItem("Threads", string::f("%d", settings::threadCount), [=](ui::Menu* menu) { | menu->addChild(createSubmenuItem("Threads", string::f("%d", settings::threadCount), [=](ui::Menu* menu) { | ||||
| // BUG This assumes SMT is enabled. | // BUG This assumes SMT is enabled. | ||||
| @@ -530,11 +526,10 @@ struct EngineButton : MenuButton { | |||||
| rightText += "(most modules)"; | rightText += "(most modules)"; | ||||
| else if (i == 1) | else if (i == 1) | ||||
| rightText += "(lowest CPU usage)"; | rightText += "(lowest CPU usage)"; | ||||
| if (settings::threadCount == i) | |||||
| rightText += " " CHECKMARK_STRING; | |||||
| menu->addChild(createMenuItem(string::f("%d", i), rightText, [=]() { | |||||
| settings::threadCount = i; | |||||
| })); | |||||
| menu->addChild(createCheckMenuItem(string::f("%d", i), rightText, | |||||
| [=]() {return settings::threadCount == i;}, | |||||
| [=]() {settings::threadCount = i;} | |||||
| )); | |||||
| } | } | ||||
| })); | })); | ||||
| } | } | ||||