• C++ 跨平台UI框架 JUCE


    GitHub - juce-framework/JUCE: JUCE is an open-source cross-platform C++ application framework for desktop and mobile applications, including VST, VST3, AU, AUv3, LV2 and AAX audio plug-ins.

    Home - JUCE 

    1. #define JUCE_GLOBAL_MODULE_SETTINGS_INCLUDED
    2. #include
    3. #define JUCE_APPLICATION_NAME_STRING "test"
    4. #define JUCE_APPLICATION_VERSION_STRING "1.0"
    5. class MainComponent final : public juce::Component
    6. {
    7. public:
    8. //==============================================================================
    9. MainComponent();
    10. //==============================================================================
    11. void paint(juce::Graphics&) override;
    12. void resized() override;
    13. private:
    14. //==============================================================================
    15. // Your private member variables go here...
    16. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MainComponent)
    17. };
    18. //==============================================================================
    19. MainComponent::MainComponent()
    20. {
    21. setSize(600, 400);
    22. }
    23. //==============================================================================
    24. void MainComponent::paint(juce::Graphics& g)
    25. {
    26. // (Our component is opaque, so we must completely fill the background with a solid colour)
    27. g.fillAll(getLookAndFeel().findColour(juce::ResizableWindow::backgroundColourId));
    28. //g.setFont(juce::FontOptions(16.0f));
    29. g.setColour(juce::Colours::white);
    30. g.drawText("Hello World!", getLocalBounds(), juce::Justification::centred, true);
    31. }
    32. void MainComponent::resized()
    33. {
    34. // This is called when the MainComponent is resized.
    35. // If you add any child components, this is where you should
    36. // update their positions.
    37. }
    38. //==============================================================================
    39. class GuiAppApplication final : public juce::JUCEApplication
    40. {
    41. public:
    42. //==============================================================================
    43. GuiAppApplication() {}
    44. // We inject these as compile definitions from the CMakeLists.txt
    45. // If you've enabled the juce header with `juce_generate_juce_header()`
    46. // you could `#include ` and use `ProjectInfo::projectName` etc. instead.
    47. const juce::String getApplicationName() override { return JUCE_APPLICATION_NAME_STRING; }
    48. const juce::String getApplicationVersion() override { return JUCE_APPLICATION_VERSION_STRING; }
    49. bool moreThanOneInstanceAllowed() override { return true; }
    50. //==============================================================================
    51. void initialise(const juce::String& commandLine) override
    52. {
    53. // This method is where you should put your application's initialisation code..
    54. juce::ignoreUnused(commandLine);
    55. mainWindow.reset(new MainWindow(getApplicationName()));
    56. }
    57. void shutdown() override
    58. {
    59. // Add your application's shutdown code here..
    60. mainWindow = nullptr; // (deletes our window)
    61. }
    62. //==============================================================================
    63. void systemRequestedQuit() override
    64. {
    65. // This is called when the app is being asked to quit: you can ignore this
    66. // request and let the app carry on running, or call quit() to allow the app to close.
    67. quit();
    68. }
    69. void anotherInstanceStarted(const juce::String& commandLine) override
    70. {
    71. // When another instance of the app is launched while this one is running,
    72. // this method is invoked, and the commandLine parameter tells you what
    73. // the other instance's command-line arguments were.
    74. juce::ignoreUnused(commandLine);
    75. }
    76. //==============================================================================
    77. /*
    78. This class implements the desktop window that contains an instance of
    79. our MainComponent class.
    80. */
    81. class MainWindow final : public juce::DocumentWindow
    82. {
    83. public:
    84. explicit MainWindow(juce::String name)
    85. : DocumentWindow(name,
    86. juce::Desktop::getInstance().getDefaultLookAndFeel()
    87. .findColour(ResizableWindow::backgroundColourId),
    88. DocumentWindow::allButtons)
    89. {
    90. setUsingNativeTitleBar(true);
    91. setContentOwned(new MainComponent(), true);
    92. #if JUCE_IOS || JUCE_ANDROID
    93. setFullScreen(true);
    94. #else
    95. setResizable(true, true);
    96. centreWithSize(getWidth(), getHeight());
    97. #endif
    98. setVisible(true);
    99. }
    100. void closeButtonPressed() override
    101. {
    102. // This is called when the user tries to close this window. Here, we'll just
    103. // ask the app to quit when this happens, but you can change this to do
    104. // whatever you need.
    105. JUCEApplication::getInstance()->systemRequestedQuit();
    106. }
    107. /* Note: Be careful if you override any DocumentWindow methods - the base
    108. class uses a lot of them, so by overriding you might break its functionality.
    109. It's best to do all your work in your content component instead, but if
    110. you really have to override any DocumentWindow methods, make sure your
    111. subclass also calls the superclass's method.
    112. */
    113. private:
    114. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MainWindow)
    115. };
    116. private:
    117. std::unique_ptr mainWindow;
    118. };
    119. juce::JUCEApplicationBase* juce_CreateApplication() {
    120. return new GuiAppApplication();
    121. }
    122. void test() {
    123. juce::JUCEApplicationBase::createInstance = &juce_CreateApplication;
    124. GuiAppApplication::main();
    125. }


    创作不易,小小的支持一下吧!

  • 相关阅读:
    网络编程5----初识http
    jupyter notebook在base和其他虚拟环境下打开异常的问题
    分库分表真实案例,扩容10倍容量
    JavaScript 笔记 初识JavaScript(变量)
    专注效率提升「GitHub 热点速览 v.22.36」
    python过滤非法字符
    J-Tech Talk|以型搜型:3D模型表征助力3D神经搜索!
    Android Ble蓝牙App(七)扫描过滤
    使用nginx代理nacos导致nacos登录界面无法显示问题
    趋动云模型--猫狗识别
  • 原文地址:https://blog.csdn.net/qq_30220519/article/details/139690240