// PlaySound.swift
class PlaySound {
private var meter: Int = 4
public func printMeter() {
print(meter)
}
public func getMeter() -> Int {
return meter
}
}
int a = 5;
int* ptr = &a;
std::cout << *a << std::endl; // prints 5 (value of a)
int& ref = a; // ref is now an alias of a
ref = 2;
std::cout << a << std::endl; // prints 2
class Entity {
public:
// a constructor without parameter
Entity {
}
// a constructor with initializer lists
Entity(float x, float y)
: X(x), Y(y) // it needs to be in the same order as you declared
{
}
// a constructor with parameters
Entity(float x, float y) {
X = x;
Y = y;
}
float X, Y;
}
class Log {
public:
// by assigning delete, can disable default constructor
Log() = delete;
}
const int MAX_AGE = 90;
int* a = new int; // a is a pointer
*a = 2; // you can dereference a and assign 2
a = (int*)&MAX_AGE // you can reassign pointer
const int* a = new int; // add "const" keyword to a pointer
// you can also write it as "int const* a"
*a = 2; // error, you can't modify the contents of the pointer
a = (int*)&MAX_AGE; // no error
std::cout << *a << std::endl; // reading a works
int* const a = new int;
*a = 2; // this works
a = (int*)&MAX_AGE; // error
a = nullptr; // error
class Entity {
private:
int m_X, m_Y;
public:
int GetX() const { // it means the function can't modify the value
// read only method
// good for getters
m_X = 2; // can't do this
return m_X;
}
void SetX(int x) { // can't have const here...
m_X = x;
}
}
void PrintEntity(const Entity& e) {
std::cout << e.GetX() << std::end; // if I remove const from
// the above GetX(), it won't work
}
int i = 5;
int& a = 10; // this does not work, because 10 is a rvalue
int& b = i; // this works, because i is a lvalue
const int& c = 10; // this works
// it creates a temporary behind the scenes as in the below pseudo code
int temp = 10;
int& c = temp;
// 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'
// background.js
function setListenerOnMenus() {
chrome.contextMenus.onClicked.addListener( async (info, tab) => {
chrome.tabs.sendMessage(tab.id, {
// some message. can be blank
something: "some message",
somethingElse: "another message"
}, (response) => {
// receiver of the message (content.js) can return a respond
// in a callback
// background.js can respond to that response here...
let context = response.context;
let url = response.url;
// do something with it!...
}
}
}
// content.js
chrome.runtime.onMessage.addListener( (request, sender, sendResponse) => {
// request contains messages sent from background.js. Can retrieve as below...
let something = request.something;
let somethingElse = request.somethingElse;
// also, content.js can interact/manipulate DOM element and communicate it back to background.js
let url = window.location.href;
let context = window.getSelection().anchorNode.data;
// can communicate back in the callback below...
sendResponse({
context: context,
url: url
});
}