-
Notifications
You must be signed in to change notification settings - Fork 11
/
juce_o_matic.py
97 lines (67 loc) · 2.13 KB
/
juce_o_matic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import juce_init
import popsicle as juce
class MainContentComponent(juce.Component, juce.Timer):
def __init__(self):
juce.Component.__init__(self)
juce.Timer.__init__(self)
self.setSize(600, 400)
self.setOpaque(True)
self.startTimerHz(60)
def paint(self, g: juce.Graphics):
g.fillAll(juce.Colours.black)
random = juce.Random.getSystemRandom()
rect = juce.Rectangle[int](0, 0, 20, 20)
for _ in range(100):
g.setColour(juce.Colour.fromRGBA(
random.nextInt(255),
random.nextInt(255),
random.nextInt(255),
255))
rect.setCentre(random.nextInt(self.getWidth()), random.nextInt(self.getHeight()))
g.drawRect(rect, 1)
def mouseDown(self, event: juce.MouseEvent):
print("mouseDown", event)
def mouseMove(self, event: juce.MouseEvent):
print("mouseMove", event.position.x, event.position.y)
def mouseUp(self, event: juce.MouseEvent):
print("mouseUp", event)
def timerCallback(self):
self.repaint()
class MainWindow(juce.DocumentWindow):
component = None
def __init__(self):
super().__init__(
juce.JUCEApplication.getInstance().getApplicationName(),
juce.Desktop.getInstance().getDefaultLookAndFeel()
.findColour(juce.ResizableWindow.backgroundColourId),
juce.DocumentWindow.allButtons,
True)
self.component = MainContentComponent()
self.setResizable(True, True)
self.setContentNonOwned(self.component, True)
self.centreWithSize(800, 600)
self.setVisible(True)
def __del__(self):
self.clearContentComponent()
if self.component:
del self.component
def closeButtonPressed(self):
juce.JUCEApplication.getInstance().systemRequestedQuit()
class Application(juce.JUCEApplication):
window = None
def __init__(self):
super().__init__()
def getApplicationName(self):
return "JUCE-o-matic"
def getApplicationVersion(self):
return "1.0"
def initialise(self, commandLineParameters: str):
self.window = MainWindow()
juce.MessageManager.callAsync(lambda: juce.Process.makeForegroundProcess())
def shutdown(self):
if self.window:
del self.window
def systemRequestedQuit(self):
self.quit()
if __name__ == "__main__":
juce.START_JUCE_APPLICATION(Application)