File: QWindow.sc

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,292 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (225 lines) | stat: -rw-r--r-- 5,614 bytes parent folder | download | duplicates (3)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
TopScrollWidget : ScrollCanvas {
	var <>win;
	doDrawFunc { win.drawFunc.value(win); }
}

ScrollTopView : ScrollView {
	var >window;

	*qtClass {^'QcScrollWindow'}

	*new { arg win, name, bounds, resizable, border;
		^super.newCustom([name, bounds, resizable, border])
		.initScrollTopView(win);
	}

	initScrollTopView { arg win;
		var cnv;
		window = win;
		// NOTE: The canvas widget must not be a View, so that asking its
		// children for parent will skip it and hit this view instead.
		cnv = TopScrollWidget.new;
		cnv.win = win;
		this.canvas = cnv;
	}

	bounds {
		var r;
		r = this.getProperty( \geometry );
		^r.moveTo(0,0);
	}

	bounds_ { arg rect;
		var rNew = rect.asRect;
		var rOld = this.getProperty( \geometry );
		this.setProperty( \geometry, rOld.resizeTo( rNew.width, rNew.height ) );
	}

	drawingEnabled_ { arg bool; canvas.setProperty( \drawingEnabled, bool ); }

	findWindow { ^window; }
}

TopView : View {
	var >window;

	*qtClass {^'QcWindow'}

	*new { arg win, name, bounds, resizable, border;
		^super.newCustom([name, bounds, resizable, border])
		.initTopView(win);
	}

	initTopView { arg win; window = win; }

	bounds {
		var r;
		r = this.getProperty( \geometry );
		^r.moveTo(0,0);
	}

	bounds_ { arg rect;
		var rNew = rect.asRect;
		var rOld = this.getProperty( \geometry );
		this.setProperty( \geometry, rOld.resizeTo( rNew.width, rNew.height ) );
	}

	drawingEnabled_ { arg bool; this.setProperty( \drawingEnabled, bool ); }

	findWindow { ^window; }

	doDrawFunc { window.drawFunc.value(window) }
}

Window {
	classvar <allWindows, <>initAction;

	var resizable, <drawFunc;
	var <view;

	//TODO
	var <>acceptsClickThrough=false;
	var <currentSheet;

	*screenBounds {
		_QWindow_ScreenBounds
		^this.primitiveFailed;
	}

	*availableBounds {
		_QWindow_AvailableGeometry
		^this.primitiveFailed;
	}

	*closeAll {
		allWindows.copy.do { |win| win.close };
	}

	/* NOTE:
	- all args have to be of correct type for Widget constructor to match!
	*/
	*new { arg name="",
		bounds,
		resizable = true,
		border = true,
		deprecatedServerArgument,
		scroll = false;

		if(deprecatedServerArgument.notNil) {
			// see https://github.com/supercollider/supercollider/pull/5312#discussion_r553546303
			"this argument is deprecated, it was kept for SwingOSC compatibility, but will be removed".warn;
		};

		if( bounds.isNil ) {
			bounds = Rect(0,0,400,400).center_( Window.availableBounds.center );
		}{
			bounds = Window.flipY( bounds.asRect );
		};
		^super.new.initWindow( name, bounds, resizable, border, scroll );
	}

	//------------------------ Window specific  -----------------------//

	initWindow { arg name, bounds, resize, border, scroll;
		if( scroll )
		{ view = ScrollTopView.new(this,name,bounds,resize,border); }
		{ view = TopView.new(this,name,bounds,resize,border); };

		// set some necessary object vars
		resizable = resize == true;

		// allWindows array management
		Window.addWindow( this );
		view.connectFunction( 'destroyed()', { Window.removeWindow(this); }, false );

		// action to call whenever a window is created
		Window.initAction.value( this );
	}

	asView {
		^view;
	}

	bounds_ { arg aRect;
		var r = Window.flipY( aRect.asRect );
		view.setProperty( \geometry, r );
		if( resizable.not ) { view.fixedSize = r.size }
	}

	bounds {
		^Window.flipY( view.getProperty( \geometry ) );
	}

	setInnerExtent { arg w, h;
		// bypass this.bounds, to avoid Window flipping the y coordinate
		var r = view.getProperty(\geometry );
		view.setProperty(\geometry, r.resizeTo( w, h ); )
	}

	background { ^view.background; }

	background_ { arg aColor; view.background = aColor; }

	drawFunc_ { arg aFunction;
		view.drawingEnabled = aFunction.notNil;
		drawFunc = aFunction;
	}

	setTopLeftBounds{ arg rect, menuSpacer=45;
		view.setProperty( \geometry, rect.moveBy( 0, menuSpacer ) );
	}

	onClose { ^view.onClose }
	onClose_ { arg func; view.onClose_(func) }

	// TODO
	addToOnClose{ arg function; }
	removeFromOnClose{ arg function; }

	//------------------- simply redirected to View ---------------------//

	sizeHint { ^view.sizeHint }
	minSizeHint { ^view.minSizeHint }
	resizeToHint { ^view.resizeToHint }
	alpha_ { arg value; view.alpha_(value); }
	addFlowLayout { arg margin, gap; ^view.addFlowLayout( margin, gap ); }
	close { view.close; }
	isClosed { ^view.isClosed; }
	visible { ^view.visible; }
	visible_ { arg boolean; view.visible_(boolean); }
	front { view.front; }
	fullScreen { view.fullScreen; }
	endFullScreen { view.endFullScreen; }
	minimize { view.minimize; }
	unminimize { view.unminimize; }
	name { ^view.name; }
	name_ { arg string; view.name_(string); }
	refresh { view.refresh; }
	userCanClose { ^view.userCanClose; }
	userCanClose_ { arg boolean; view.userCanClose_( boolean ); }
	alwaysOnTop { ^view.alwaysOnTop; }
	alwaysOnTop_ { arg boolean; view.alwaysOnTop_(boolean); }
	layout { ^view.layout; }
	layout_ { arg layout; view.layout_(layout); }
	toFrontAction_ { arg action; view.toFrontAction_(action) }
	toFrontAction { ^view.toFrontAction }
	endFrontAction_ { arg action; view.endFrontAction_(action) }
	endFrontAction { ^view.endFrontAction }
	acceptsMouseOver { ^view.acceptsMouseOver }
	acceptsMouseOver_ { arg flag; view.acceptsMouseOver_(flag) }

	// ---------------------- private ------------------------------------

	*flipY { arg aRect;
		var flippedTop = Window.screenBounds.height - aRect.top - aRect.height;
		^Rect( aRect.left, flippedTop, aRect.width, aRect.height );
	}

	*addWindow { arg window;
		allWindows = allWindows.add( window );
	}

	*removeWindow { arg window;
		allWindows.remove( window );
	}
}