|
| 1 | +#include "ImGui_UI.hpp" |
| 2 | +#include "DistrhoPluginInfo.h" |
| 3 | + |
| 4 | +#include "Structures.h" |
| 5 | +#include "Defines.h" |
| 6 | + |
| 7 | +#include "CetoneUI.hpp" // For class CCetoneUI |
| 8 | + |
| 9 | +void ImGuiUI::onImGuiDisplay() |
| 10 | +{ |
| 11 | + double scaleFactor = getScaleFactor() * userScaling; |
| 12 | + const double initialSize = 800 * scaleFactor; |
| 13 | + |
| 14 | + // |
| 15 | + // "About" Window |
| 16 | + // |
| 17 | + { |
| 18 | + ImGui::SetNextWindowPos(ImVec2(initialSize / 4, initialSize / 16), ImGuiCond_Once); |
| 19 | + ImGui::SetNextWindowSize(ImVec2(600, 230), ImGuiCond_Once); |
| 20 | + |
| 21 | + if (isAboutWindowOpen) |
| 22 | + { |
| 23 | + ImGui::Begin("About " DISTRHO_PLUGIN_NAME, &isAboutWindowOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize); |
| 24 | + { |
| 25 | + ImGui::SeparatorText(DISTRHO_PLUGIN_NAME); |
| 26 | + ImGui::Text("Light-weight monophonic analogue-style synthesizer, by Neotec Software.\n"); |
| 27 | + |
| 28 | + ImGui::SeparatorText("Authors"); |
| 29 | + ImGui::BulletText("René 'Neotec' Jeschke - Original developer"); |
| 30 | + ImGui::BulletText( "AnClark Liu <[email protected]> - Ported to DPF, Further developments"); |
| 31 | + |
| 32 | + ImGui::SeparatorText("License"); |
| 33 | + ImGui::BulletText("This project is licensed under GNU General Public License, version 3."); |
| 34 | + |
| 35 | + ImGui::Text("\n\n"); |
| 36 | + ImGui::Dummy(ImVec2(490, 0)); |
| 37 | + ImGui::SameLine(); |
| 38 | + if (ImGui::Button("OK", ImVec2(80, 0))) |
| 39 | + isAboutWindowOpen = false; |
| 40 | + } |
| 41 | + ImGui::End(); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + |
| 46 | + // Specify menu position |
| 47 | + ImGui::SetNextWindowPos(menuPos); // 指定屏幕坐标位置 |
| 48 | + |
| 49 | + // Here, variable `requestTestMenuOpen` acts as an "event flag" to request ImGui to show the menu. |
| 50 | + // |
| 51 | + // Dear ImGui has its own mechanism to show popup menus, which does not require a flag to control its exisitance. |
| 52 | + // This is quite different from window (ImGui::Begin()). |
| 53 | + // So just call this function once, your popup will stick on the screen unless you do some operations. |
| 54 | + // |
| 55 | + switch (requestMenuId) |
| 56 | + { |
| 57 | + case pOsc1Wave: |
| 58 | + ImGui::OpenPopup("menu_osc1_wave"); |
| 59 | + |
| 60 | + default: |
| 61 | + requestMenuId = 0; // Reset flag state after EACH menu popup |
| 62 | + } |
| 63 | + |
| 64 | + // Create popup menu |
| 65 | + // [NOTICE] ImGui::BeginPopup() MUST be put after ImGui::OpenPopup(), otherwise popup won't show! |
| 66 | + if (ImGui::BeginPopup("menu_osc1_wave")) |
| 67 | + { |
| 68 | + ImGui::SeparatorText("Waveform"); |
| 69 | + if (ImGui::MenuItem("Saw")) { _triggerParamUpdate(pOsc1Wave, ui->_pi2f(OWAVE_SAW, OWAVE_MAX)); } |
| 70 | + if (ImGui::MenuItem("Pulse")) { _triggerParamUpdate(pOsc1Wave, ui->_pi2f(OWAVE_PULSE, OWAVE_MAX)); } |
| 71 | + if (ImGui::MenuItem("Triangle")) { _triggerParamUpdate(pOsc1Wave, ui->_pi2f(OWAVE_TRI, OWAVE_MAX)); } |
| 72 | + if (ImGui::MenuItem("Sine")) { _triggerParamUpdate(pOsc1Wave, ui->_pi2f(OWAVE_SINE, OWAVE_MAX)); } |
| 73 | + if (ImGui::MenuItem("Noise")) { _triggerParamUpdate(pOsc1Wave, ui->_pi2f(OWAVE_C64NOISE, OWAVE_MAX)); } |
| 74 | + ImGui::EndPopup(); |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +void ImGuiUI::_triggerParamUpdate(uint32_t paramId, float newValue) |
| 79 | +{ |
| 80 | + ui->setParameterValue(paramId, newValue); // Tell the DSP to update parameter value |
| 81 | + ui->parameterChanged(paramId, newValue); // Request UI refresh |
| 82 | +} |
0 commit comments