mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-04 03:40:07 +00:00
This commit is contained in:
parent
b85f154b4a
commit
94cfda5062
1033 changed files with 413256 additions and 0 deletions
160
extras/example projects/common/Main.cpp
Normal file
160
extras/example projects/common/Main.cpp
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
/*
|
||||
==============================================================================
|
||||
|
||||
Demonstration "Hello World" application in JUCE
|
||||
Copyright 2004 by Julian Storer.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#include "../../../juce.h"
|
||||
|
||||
//==============================================================================
|
||||
/** This is the component that sits inside the "hello world" window, filling its
|
||||
content area. In this example, we'll just write "hello world" inside it.
|
||||
*/
|
||||
class HelloWorldContentComponent : public Component
|
||||
{
|
||||
public:
|
||||
HelloWorldContentComponent()
|
||||
{
|
||||
}
|
||||
|
||||
~HelloWorldContentComponent()
|
||||
{
|
||||
}
|
||||
|
||||
void paint (Graphics& g)
|
||||
{
|
||||
g.fillAll (Colours::white);
|
||||
|
||||
g.setColour (Colours::black);
|
||||
g.setFont (20.0f, Font::bold);
|
||||
g.drawText (T("Hello World!"),
|
||||
0, 0, getWidth(), getHeight(),
|
||||
Justification::centred, false);
|
||||
}
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
/** This is the top-level window that we'll pop up. Inside it, we'll create and
|
||||
show a HelloWorldContentComponent component.
|
||||
*/
|
||||
class HelloWorldWindow : public DocumentWindow
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
HelloWorldWindow()
|
||||
: DocumentWindow (T("Hello World"),
|
||||
Colours::lightgrey,
|
||||
DocumentWindow::allButtons,
|
||||
true)
|
||||
{
|
||||
setContentComponent (new HelloWorldContentComponent());
|
||||
|
||||
setVisible (true);
|
||||
centreWithSize (400, 200);
|
||||
}
|
||||
|
||||
~HelloWorldWindow()
|
||||
{
|
||||
// (the content component will be deleted automatically, so no need to do it here)
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void closeButtonPressed()
|
||||
{
|
||||
// When the user presses the close button, we'll tell the app to quit. This
|
||||
// window will be deleted by the app object as it closes down.
|
||||
JUCEApplication::quit();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/** This is the application object that is started up when Juce starts. It handles
|
||||
the initialisation and shutdown of the whole application.
|
||||
*/
|
||||
class JUCEHelloWorldApplication : public JUCEApplication
|
||||
{
|
||||
/* Important! NEVER embed objects directly inside your JUCEApplication class! Use
|
||||
ONLY pointers to objects, which you should create during the initialise() method
|
||||
(NOT in the constructor!) and delete in the shutdown() method (NOT in the
|
||||
destructor!)
|
||||
|
||||
This is because the application object gets created before Juce has been properly
|
||||
initialised, so any embedded objects would also get constructed too soon.
|
||||
*/
|
||||
HelloWorldWindow* helloWorldWindow;
|
||||
ShinyLookAndFeel shinyLookAndFeel;
|
||||
|
||||
public:
|
||||
//==============================================================================
|
||||
JUCEHelloWorldApplication()
|
||||
: helloWorldWindow (0)
|
||||
{
|
||||
// NEVER do anything in here that could involve any Juce function being called
|
||||
// - leave all your startup tasks until the initialise() method.
|
||||
}
|
||||
|
||||
~JUCEHelloWorldApplication()
|
||||
{
|
||||
// Your shutdown() method should already have done all the things necessary to
|
||||
// clean up this app object, so you should never need to put anything in
|
||||
// the destructor.
|
||||
|
||||
// Making any Juce calls in here could be very dangerous...
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void initialise (const String& commandLine)
|
||||
{
|
||||
LookAndFeel::setDefaultLookAndFeel (&shinyLookAndFeel);
|
||||
|
||||
// just create the main window...
|
||||
helloWorldWindow = new HelloWorldWindow();
|
||||
|
||||
/* ..and now return, which will fall into to the main event
|
||||
dispatch loop, and this will run until something calls
|
||||
JUCEAppliction::quit().
|
||||
|
||||
In this case, JUCEAppliction::quit() will be called by the
|
||||
hello world window being clicked.
|
||||
*/
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
// clear up..
|
||||
|
||||
if (helloWorldWindow != 0)
|
||||
delete helloWorldWindow;
|
||||
|
||||
LookAndFeel::setDefaultLookAndFeel (0);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
const String getApplicationName()
|
||||
{
|
||||
return T("Hello World for JUCE");
|
||||
}
|
||||
|
||||
const String getApplicationVersion()
|
||||
{
|
||||
return T("1.0");
|
||||
}
|
||||
|
||||
bool moreThanOneInstanceAllowed()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void anotherInstanceStarted (const String& commandLine)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//==============================================================================
|
||||
// This macro creates the application's main() function..
|
||||
START_JUCE_APPLICATION (JUCEHelloWorldApplication)
|
||||
Loading…
Add table
Add a link
Reference in a new issue