The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
5.1KB

  1. /*
  2. ==============================================================================
  3. Demonstration "Hello World" application in JUCE
  4. Copyright 2004 by Julian Storer.
  5. ==============================================================================
  6. */
  7. #include "../../../juce.h"
  8. //==============================================================================
  9. /** This is the component that sits inside the "hello world" window, filling its
  10. content area. In this example, we'll just write "hello world" inside it.
  11. */
  12. class HelloWorldContentComponent : public Component
  13. {
  14. public:
  15. HelloWorldContentComponent()
  16. {
  17. }
  18. ~HelloWorldContentComponent()
  19. {
  20. }
  21. void paint (Graphics& g)
  22. {
  23. // clear the background with solid white
  24. g.fillAll (Colours::white);
  25. // set our drawing colour to black..
  26. g.setColour (Colours::black);
  27. // choose a suitably sized font
  28. g.setFont (20.0f, Font::bold);
  29. // and draw the text, centred in this component
  30. g.drawText (T("Hello World!"),
  31. 0, 0, getWidth(), getHeight(),
  32. Justification::centred, false);
  33. }
  34. };
  35. //==============================================================================
  36. /** This is the top-level window that we'll pop up. Inside it, we'll create and
  37. show a HelloWorldContentComponent component.
  38. */
  39. class HelloWorldWindow : public DocumentWindow
  40. {
  41. public:
  42. //==============================================================================
  43. HelloWorldWindow()
  44. : DocumentWindow (T("Hello World"),
  45. Colours::lightgrey,
  46. DocumentWindow::allButtons,
  47. true)
  48. {
  49. setContentComponent (new HelloWorldContentComponent());
  50. setVisible (true);
  51. // centre the window on the desktop with this size
  52. centreWithSize (400, 200);
  53. }
  54. ~HelloWorldWindow()
  55. {
  56. // (the content component will be deleted automatically, so no need to do it here)
  57. }
  58. //==============================================================================
  59. void closeButtonPressed()
  60. {
  61. // When the user presses the close button, we'll tell the app to quit. This
  62. // window will be deleted by the app object as it closes down.
  63. JUCEApplication::quit();
  64. }
  65. };
  66. //==============================================================================
  67. /** This is the application object that is started up when Juce starts. It handles
  68. the initialisation and shutdown of the whole application.
  69. */
  70. class JUCEHelloWorldApplication : public JUCEApplication
  71. {
  72. /* Important! NEVER embed objects directly inside your JUCEApplication class! Use
  73. ONLY pointers to objects, which you should create during the initialise() method
  74. (NOT in the constructor!) and delete in the shutdown() method (NOT in the
  75. destructor!)
  76. This is because the application object gets created before Juce has been properly
  77. initialised, so any embedded objects would also get constructed too soon.
  78. */
  79. HelloWorldWindow* helloWorldWindow;
  80. public:
  81. //==============================================================================
  82. JUCEHelloWorldApplication()
  83. : helloWorldWindow (0)
  84. {
  85. // NEVER do anything in here that could involve any Juce function being called
  86. // - leave all your startup tasks until the initialise() method.
  87. }
  88. ~JUCEHelloWorldApplication()
  89. {
  90. // Your shutdown() method should already have done all the things necessary to
  91. // clean up this app object, so you should never need to put anything in
  92. // the destructor.
  93. // Making any Juce calls in here could be very dangerous...
  94. }
  95. //==============================================================================
  96. void initialise (const String& commandLine)
  97. {
  98. // just create the main window...
  99. helloWorldWindow = new HelloWorldWindow();
  100. /* ..and now return, which will fall into to the main event
  101. dispatch loop, and this will run until something calls
  102. JUCEAppliction::quit().
  103. In this case, JUCEAppliction::quit() will be called by the
  104. hello world window being clicked.
  105. */
  106. }
  107. void shutdown()
  108. {
  109. // clear up..
  110. if (helloWorldWindow != 0)
  111. delete helloWorldWindow;
  112. }
  113. //==============================================================================
  114. const String getApplicationName()
  115. {
  116. return T("Hello World for JUCE");
  117. }
  118. const String getApplicationVersion()
  119. {
  120. return T("1.0");
  121. }
  122. bool moreThanOneInstanceAllowed()
  123. {
  124. return true;
  125. }
  126. void anotherInstanceStarted (const String& commandLine)
  127. {
  128. }
  129. };
  130. //==============================================================================
  131. // This macro creates the application's main() function..
  132. START_JUCE_APPLICATION (JUCEHelloWorldApplication)