3 summary:: Top-level container of views
8 The Window is the most fundamental element of the GUI. It occupies a rectangular space on the screen within which other GUI elements (Views) are displayed.
10 A child view is added into a window by passing the window to the view's constructor. See link::Classes/View#*new::.
13 In strong::Qt GUI:: there is no distinction between windows, views, and containers; a View can be displayed directly on screen, and can contain other views. Therefore, visual descriptions of Window and most of the methods that are specific to Window in other GUI kits, also apply to and make part of View in Qt, and are thus shared by all its subclasses.
15 The Window class is provided in Qt GUI for compatibility as well as convenience: e.g. unlike View, Window will be created by default in the center of the screen, and various aspects can be conveniently controlled using its constructor arguments.
18 The Window is usually drawn with a bar on its top edge that displays the window's title which you can set in the link::#*new#constructor::, or using link::#-name::.
28 Creates a new Window instance. You will need to call link::#-front:: on it to become visible.
31 A String for the text that will be displayed in the title bar. The default is 'panel'.
33 A Rect specifying position and size of the window. The size does not include the border and title bar. Position is measured from the bottom-left corner of the screen (this is different than link::Classes/View#-bounds::). The default is size 400x400 at position 128x64, but in Qt the window is centered on the screen by default.
35 A Boolean indicating whether this window is resizable by the user. The default is code::true::.
37 A Boolean indicating whether this window has a border. Borderless windows have no title bar and thus can only be closed in code. The default is code::true::.
39 This is a dummy argument which is here to provide compatibility with SwingOSC and has no effect.
41 A Boolean indicating whether this window will add scrollbars if its contents exceed its bounds. If this is set to code::true::, then link::Classes/View#-resize:: settings will be ignored for contained views. The default is false.
45 An array of all existing Window instances.
49 Calls link::#-close:: an all existing Window instances.
53 The default action object to be evaluated whenever a new Window is instantiated.
57 Returns a Rect with the size of the screen in pixels
59 METHOD:: availableBounds
61 Returns a Rect describing the area of the screen that windows can actually occupy (i.e. excluding the Mac dock, the task bar, or similar).
68 SUBSECTION:: View hierarchy
71 When a Window is created, it creates a container view, accessible using this method, that occupies the whole area of the window, and which will be used as the actual parent of the child widgets.
77 Equivalent to link::#-view::
80 note:: Only in Cocoa GUI ::
82 The current modal sheet attached to this window, if it exists. See link::Classes/SCModalSheet::.
87 SUBSECTION:: Visibility
90 Displays the window on the screen (In Qt GUI this has the same effect as setting link::#-visible:: to true).
93 Hides the window, only keeping its representation in the dock, taskbar, etc..
96 Restores the window's previous state after being minimized.
99 Displays the window full-screen.
101 METHOD:: endFullScreen
102 Restores the window's previous state after being displayed full-screen.
105 Whether the window should always stay on top of other windows, even when it is not the active one.
111 note:: only in Qt GUI ::
113 Whether the window is visible.
115 Setting this to code::true:: has the same effect as link::#-front::, and setting it to false closes the window without destroying it.
122 Closes and destroys the window.
125 returns:: A Boolean stating whether the view has been closed.
130 SUBSECTION:: Geometry
134 The position and size of the window. The position is relative to the bottom-left corner of the screen.
137 A Rect or a Point interpreted link::Classes/Point#-asRect#as Rect::.
141 METHOD:: setTopLeftBounds
143 A convenience method that, unlike link::#-bounds::, sets the bounds by measuring position from the top-left corner of the screen, and vertically offset by code::menuSpacer::.
147 argument:: menuSpacer
148 An Integer amount of pixels.
150 METHOD:: setInnerExtent
152 Resizes the window, keeping its position intact.
154 In strong:: Qt GUI ::, this is equivalent to link::Classes/View#-resizeTo:: called on the link::#-view::.
157 An Integer width in pixels.
159 An Integer height in pixels.
162 note:: only in Qt GUI ::
163 Redirects to link::Classes/View#-sizeHint:: of the link::#-view::.
166 note:: only in Qt GUI ::
167 Redirects to link::Classes/View#-minSizeHint:: of the link::#-view::.
169 METHOD:: addFlowLayout
171 A convenience method which sets code::decorator:: of the link::#-view:: to a new instance of FlowLayout. See link::Classes/FlowLayout:: for examples.
174 A Point describing the link::Classes/FlowLayout#-margin#margin:: of the FlowLayout.
177 A Point describing the link::Classes/FlowLayout#-gap#gap:: of the FlowLayout.
179 returns:: The new FlowLayout instance.
182 note:: only in Qt GUI ::
183 Redirects to link::Classes/View#-layout:: of the link::#-view::.
187 SUBSECTION:: Appearance
190 The title of the window.
196 The background color of the window.
202 The transparancy of the window.
205 A Float between 0.0 (invisible) and 1.0 (opaque).
208 Redraws the window and all its children.
212 SUBSECTION:: Interaction
214 METHOD:: userCanClose
215 Whether the user can close the window. The default is code::true::.
220 METHOD:: acceptsClickThrough
221 Whether the window receives clicks when it is not front-most. The default is code::true::.
226 METHOD:: acceptsMouseOver
227 Whether the window and all its children receive mouse-over events. The default is code::false::.
229 See also: link::Classes/View#-acceptsMouseOver:: and link::Classes/View#-mouseOverAction::.
236 SUBSECTION:: Actions and hooks
239 Just like the link::Classes/UserView::, the window can be given a Function to evalute whenever it is asked to redraw itself, so you can use the link::Classes/Pen:: class to draw on the window. See link::Classes/UserView#-drawFunc:: for explanation.
244 METHOD:: toFrontAction
246 The action object to be evaluated whenever the window becomes the active one.
248 METHOD:: endFrontAction
250 The action object to be evaluated whenever the window ceases to be the active one.
254 The action object to be evaluated when the window is closed.
256 METHOD:: addToOnClose
258 Adds an object to link::#-onClose::, wrapping the current value into an Array, if it is not yet.
260 METHOD:: removeFromOnClose
262 Removes an object from link::#-onClose::, if the latter is an Array.
268 subsection:: Adding Views
273 w = Window("my name is... panel", Rect(128, 64, 340, 360));
276 b = Button(w, Rect(rrand(20,300),rrand(20,300), 75, 24));
277 b.states = [["Start "++i, Color.black, Color.rand],
278 ["Stop "++i, Color.white, Color.red]];
285 subsection:: Using Decorator
290 w = Window("my name is... panel", Rect(128, 64, 340, 360));
292 w.view.decorator = FlowLayout(w.view.bounds);
293 // w.addFlowLayout; // you can als write this instead of the line above
295 w.view.background = Color(0.6,0.8,0.8);
297 b = Button(w, Rect(rrand(20,300),rrand(20,300), 75, 24));
298 b.states = [["Start "++i, Color.black, Color.rand],
299 ["Stop "++i, Color.white, Color.red]];
307 subsection:: Setting Bounds
310 // use screenbounds for precise placement from the top
312 x = Window.new("test", Rect(100,Window.screenBounds.height-180,300,100));x.front;
315 // bounds.top refers to the bottom edge of the window,
316 // measured from the bottom of the screen. Different than in View.
317 x.bounds_(Rect(100,400,300,300));
321 subsection:: Borderless Window
324 w = Window.new(border:false).front; // can't be manually closed
325 w.close; // so close it in code
329 subsection:: Window with Scrollers
333 w = Window(scroll: true); // you must set this when the window is created
334 c = Slider2D(w, Rect(0, 0, 1500, 300));
335 d = Slider(w, Rect(0, 310, 20, 300));
336 c.background = Color.grey.alpha = 0.6;
337 d.background = Color.grey.alpha = 0.6;
347 x = Window.new.front;
349 x.onClose_({ y = Synth.new(\default) }); //close the window and the synth plays
356 subsection:: Drawing on Window with Pen
360 var w, much = 0.02, string, synth;
362 w = Window.new("gui", Rect(100, 100, 300, 500)).front;
363 w.view.background_(Color.new255(153, 255, 102).vary);
365 string = "gui ".dup(24).join;
367 w.drawFunc = Routine {
370 var func = { |i, j| sin(i * 0.07 + (j * 0.0023) + 1.5pi) * much + 1 };
372 var font = Font("Helvetica", 40).boldVariant;
376 string.do { |char, j|
378 scale = func.value(i, j).dup(6);
380 Pen.fillColor = Color.new255(0, 120, 120).vary;
381 Pen.matrix = scale * #[1, 0, 0, 1, 1, 0];
382 Pen.stringAtPoint(char.asString,
383 ((size * (j % 9)) - 10) @ (size * (j div: 9))
386 0.yield // stop here, return something unimportant
390 { while { w.isClosed.not } { w.refresh; 0.04.wait; } }.fork(AppClock);