// Main.cpp
#include "MainComponent.h"
// MainWindow constructor
MainWindow(juce::String name): DocumentWindow(name,
juce::Colours::lightgrey,
DocumentWindow::allButtons)
{
setUsingNativeTitleBar(true);
// assigning MainComponent instance in setContentOwned()
setContentOwned(new MainComponent(), true);
// [6 ] in order for getWidth() and getHeight() to work,
// MainComponent needs to have setSize() set in it's constructor
centreWithSize(getWidth(), getHeight());
setVisible(true);
}
paint(juce::Graphics& g) にはGraphicsクラスのインスタンスのアドレス g が渡されています。この g を使って色々なUIエレメントを描画出来ます。ほぼ全ての場合、Graphicsクラスはpaint()内でのみ使用されます。
Fontの設定
g.setFont(20.0f); // set size of the font
juce::Font mainComponentFont ("Times New Roman", 20.0f, juce::Font::italic);
// font styles can be used as a bitmask
juce::Font mainComponentFont ("Times New Roman", 20.0f, juce::Font::bold | juce::Font::italic);
g.setFont(mainComponentFont); // can pass a Font object
// using getLocalBounds()
g.drawText(currentSizeAsString, getLocalBounds(), juce::Justification::centred, true);
// using Justification::Flags
g.drawText(currentSizeAsString, getLocalBounds(), juce::Justification::topLeft, true);
// using explicit size and position
g.drawText(currentSizeAsString, 20, 40, 200, 40, juce::Justification::centred, true);
// draws a line with 5 pixels width from (10, 300) to (590, 300),
g.drawLine (10, 300, 590, 300, 5);
// draws a rectangle with origin (300, 120), width 200, height 170
g.drawRect (300, 120, 200, 170);
// draws a ellipse inside a rectangle with origin (530, 120), width and height 60 pixels
g.drawEllipse (530, 120, 60, 60, 3);
git clone https://github.com/juce-framework/JUCE.git JUCE_dev
cd ./JUCE_dev
git checkout develop
// branch 'develop' set up to track 'origin/develop'.
// Switched to a new branch 'develop'