Skip to content

Commit ffceb21

Browse files
committed
Upate documentation
1 parent 41c1fe4 commit ffceb21

1 file changed

Lines changed: 143 additions & 92 deletions

File tree

ScreenManager.lua

Lines changed: 143 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@ end
5252
-- ------------------------------------------------
5353

5454
---
55-
-- Initialise the ScreenManager. This pushes the first
56-
-- screen to the stack.
57-
-- @param nscreens - The list of possible screens.
58-
-- @param screen - The first screen to push to the stack.
55+
-- Initialise the ScreenManager.
56+
-- Sets up the ScreenManager and pushes the first screen.
57+
-- @param nscreens (table) A table containing pointers to the different screen
58+
-- classes. The keys will are used to call a specific
59+
-- screen.
60+
-- @param screen (string) The key of the first screen to push to the stack.
61+
-- Use the key under which the screen in question is
62+
-- stored in the nscreens table.
5963
--
6064
function ScreenManager.init( nscreens, screen )
6165
stack = {};
@@ -64,22 +68,24 @@ function ScreenManager.init( nscreens, screen )
6468
end
6569

6670
---
67-
-- Clears the ScreenManager, creates a new screen and switches
68-
-- to it. Use this if you don't want to stack onto other screens.
69-
--
70-
-- @param nscreen
71+
-- Switches to a screen.
72+
-- Removes all screens from the stack, creates a new screen and switches to it.
73+
-- Use this if you don't want to stack onto other screens.
74+
-- @param screen (string) The key of the screen to switch to.
75+
-- @param ... (vararg) One or multiple arguments passed to the new screen.
7176
--
7277
function ScreenManager.switch( screen, ... )
7378
clear();
7479
ScreenManager.push( screen, ... );
7580
end
7681

7782
---
78-
-- Creates a new screen and pushes it on the screen stack, where
79-
-- it will overlay all the other screens.
80-
-- Screens below the this new screen will be set inactive.
81-
--
82-
-- @param screen - The name of the screen to push on the stack.
83+
-- Pushes a new screen to the stack.
84+
-- Creates a new screen and pushes it on the screen stack, where it will overlay
85+
-- the other screens below it. Screens below the this new screen will be set
86+
-- inactive.
87+
-- @param screen (string) The key of the screen to push to the stack.
88+
-- @param ... (vararg) One or multiple arguments passed to the new screen.
8389
--
8490
function ScreenManager.push( screen, ... )
8591
-- Deactivate the previous screen if there is one.
@@ -105,13 +111,15 @@ end
105111

106112
---
107113
-- Returns the screen on top of the screen stack without removing it.
114+
-- @return (table) The screen on top of the stack.
108115
--
109116
function ScreenManager.peek()
110117
return stack[#stack];
111118
end
112119

113120
---
114-
-- Removes the topmost screen of the stack.
121+
-- Removes and returns the topmost screen of the stack.
122+
-- @return (table) The screen on top of the stack.
115123
--
116124
function ScreenManager.pop()
117125
if #stack > 1 then
@@ -136,16 +144,20 @@ end
136144
-- ------------------------------------------------
137145

138146
---
139-
-- Callback function triggered when a directory is dragged and dropped onto the window.
140-
-- @param file - The full platform-dependent path to the directory.
147+
-- Reroute the directorydropped callback to the currently active screen.
148+
-- @param path (string) The full platform-dependent path to the directory.
149+
-- It can be used as an argument to love.filesystem.mount,
150+
-- in order to gain read access to the directory with
151+
-- love.filesystem.
141152
--
142153
function ScreenManager.directorydropped( path )
143154
ScreenManager.peek():directorydropped( path );
144155
end
145156

146157
---
147-
-- Draw all screens on the stack. Screens that are higher on the stack
148-
-- will overlay screens that are on the bottom.
158+
-- Reroute the draw callback to all screens on the stack.
159+
-- Screens that are higher on the stack will overlay screens that are below
160+
-- them.
149161
--
150162
function ScreenManager.draw()
151163
for i = 1, #stack do
@@ -154,104 +166,116 @@ function ScreenManager.draw()
154166
end
155167

156168
---
157-
-- Callback function triggered when a file is dragged and dropped onto the window.
158-
-- @param file - The unopened File object representing the file that was dropped.
169+
-- Reroute the filedropped callback to the currently active screen.
170+
-- @param file (File) The unopened File object representing the file that was
171+
-- dropped.
159172
--
160173
function ScreenManager.filedropped( file )
161174
ScreenManager.peek():filedropped( file );
162175
end
163176

164177
---
165-
-- Update all screens on the stack whenever the game window gains or
166-
-- loses focus.
167-
-- @param nfocus
178+
-- Reroute the focus callback to all screens on the stack.
179+
-- @param focus (boolean) True if the window gains focus, false if it loses focus.
168180
--
169-
function ScreenManager.focus( nfocus )
181+
function ScreenManager.focus( focus )
170182
for i = 1, #stack do
171-
stack[i]:focus( nfocus );
183+
stack[i]:focus( focus );
172184
end
173185
end
174186

175187
---
176-
-- Callback function triggered when a key is pressed.
177-
-- @param key - Character of the pressed key.
178-
-- @param scancode - The scancode representing the pressed key.
179-
-- @param isrepeat - Whether this keypress event is a repeat. The delay between key repeats depends on the user's system settings.
188+
-- Reroute the keypressed callback to the currently active screen.
189+
-- @param key (KeyConstant) Character of the pressed key.
190+
-- @param scancode (Scancode) The scancode representing the pressed key.
191+
-- @param isrepeat (boolean) Whether this keypress event is a repeat. The
192+
-- delay between key repeats depends on the
193+
-- user's system settings.
180194
--
181195
function ScreenManager.keypressed( key, scancode, isrepeat )
182-
ScreenManager.peek():keypressed( key, scancode, isrepeat);
196+
ScreenManager.peek():keypressed( key, scancode, isrepeat );
183197
end
184198

185199
---
186-
-- Callback function triggered when a keyboard key is released.
187-
-- @param key - Character of the released key.
188-
-- @param scancode - The scancode representing the released key.
200+
-- Reroute the keyreleased callback to the currently active screen.
201+
-- @param key (KeyConstant) Character of the released key.
202+
-- @param scancode (Scancode) The scancode representing the released key.
189203
--
190204
function ScreenManager.keyreleased( key, scancode )
191205
ScreenManager.peek():keyreleased( key, scancode );
192206
end
193207

194208
---
195-
-- Callback function triggered when the system is running out of memory on mobile devices.
209+
-- Reroute the lowmemory callback to the currently active screen.
210+
-- mobile devices.
196211
--
197212
function ScreenManager.lowmemory()
198213
ScreenManager.peek():lowmemory();
199214
end
200215

201216
---
202217
-- Reroute the mousefocus callback to the currently active screen.
203-
-- @param focus - Wether the window has mouse focus or not.
218+
-- @param focus (boolean) Wether the window has mouse focus or not.
204219
--
205220
function ScreenManager.mousefocus( focus )
206221
ScreenManager.peek():mousefocus( focus );
207222
end
208223

209224
---
210-
-- Callback function triggered when the mouse is moved.
211-
-- @param x - Mouse x position.
212-
-- @param y - Mouse y position.
213-
-- @param dx - The amount moved along the x-axis since the last time love.mousemoved was called.
214-
-- @param dy - The amount moved along the y-axis since the last time love.mousemoved was called.
225+
-- Reroute the mousemoved callback to the currently active screen.
226+
-- @param x (number) Mouse x position.
227+
-- @param y (number) Mouse y position.
228+
-- @param dx (number) The amount moved along the x-axis since the last time
229+
-- love.mousemoved was called.
230+
-- @param dy (number) The amount moved along the y-axis since the last time
231+
-- love.mousemoved was called.
215232
--
216233
function ScreenManager.mousemoved( x, y, dx, dy )
217234
ScreenManager.peek():mousemoved( x, y, dx, dy );
218235
end
219236

220237
---
221-
-- Callback function triggered when a mouse button is pressed.
222-
-- @param x - Mouse x position, in pixels.
223-
-- @param y - Mouse y position, in pixels.
224-
-- @param button - The button index that was pressed. 1 is the primary mouse button, 2 is the secondary mouse button and 3 is the middle button. Further buttons are mouse dependant.
225-
-- @param istouch - True if the mouse button press originated from a touchscreen touch-press.
238+
-- Reroute the mousepressed callback to the currently active screen.
239+
-- @param x (number) Mouse x position, in pixels.
240+
-- @param y (number) Mouse y position, in pixels.
241+
-- @param button (number) The button index that was pressed. 1 is the primary
242+
-- mouse button, 2 is the secondary mouse button and 3
243+
-- is the middle button. Further buttons are mouse
244+
-- dependent.
245+
-- @param istouch (boolean) True if the mouse button press originated from a
246+
-- touchscreen touch-press.
226247
--
227248
function ScreenManager.mousepressed( x, y, button, istouch )
228249
ScreenManager.peek():mousepressed( x, y, button, istouch );
229250
end
230251

231252
---
232-
-- Callback function triggered when a mouse button is released.
233-
-- @param x - Mouse x position, in pixels.
234-
-- @param y - Mouse y position, in pixels.
235-
-- @param button - The button index that was released. 1 is the primary mouse button, 2 is the secondary mouse button and 3 is the middle button. Further buttons are mouse dependant.
236-
-- @param istouch - True if the mouse button release originated from a touchscreen touch-release.
253+
-- Reroute the mousereleased callback to the currently active screen.
254+
-- @param x (number) Mouse x position, in pixels.
255+
-- @param y (number) Mouse y position, in pixels.
256+
-- @param button (number) The button index that was released. 1 is the primary
257+
-- mouse button, 2 is the secondary mouse button and 3
258+
-- is the middle button. Further buttons are mouse
259+
-- dependent.
260+
-- @param istouch (boolean) True if the mouse button release originated from a
261+
-- touchscreen touch-release.
237262
--
238263
function ScreenManager.mousereleased( x, y, button, istouch )
239264
ScreenManager.peek():mousereleased( x, y, button, istouch );
240265
end
241266

242267
---
243268
-- Reroute the quit callback to the currently active screen.
244-
-- @param dquit - Abort quitting. If true, do not close the game.
269+
-- @return quit (boolean) Abort quitting. If true, do not close the game.
245270
--
246-
function ScreenManager.quit( dquit )
247-
ScreenManager.peek():quit( dquit );
271+
function ScreenManager.quit()
272+
ScreenManager.peek():quit();
248273
end
249274

250275
---
251-
-- Called when the window is resized, for example if the user resizes the window, or if love.window.setMode is called with an unsupported width or height in fullscreen and the window chooses the closest appropriate size.
252-
--
253-
-- @param w - The new width, in pixels.
254-
-- @param h - The new height, in pixels.
276+
-- Reroute the resize callback to all screens on the stack.
277+
-- @param w (number) The new width, in pixels.
278+
-- @param h (number) The new height, in pixels.
255279
--
256280
function ScreenManager.resize( w, h )
257281
for i = 1, #stack do
@@ -260,19 +284,18 @@ function ScreenManager.resize( w, h )
260284
end
261285

262286
---
263-
-- Called when the candidate text for an IME (Input Method Editor) has changed.
264-
-- The candidate text is not the final text that the user will eventually choose. Use love.textinput for that.
265-
-- @param text - The UTF-8 encoded unicode candidate text.
266-
-- @param start - The start cursor of the selected candidate text.
267-
-- @param length - The length of the selected candidate text. May be 0.
287+
-- Reroute the textedited callback to the currently active screen.
288+
-- @param text (string) The UTF-8 encoded unicode candidate text.
289+
-- @param start (number) The start cursor of the selected candidate text.
290+
-- @param length (number) The length of the selected candidate text. May be 0.
268291
--
269292
function ScreenManager.textedited( text, start, length )
270293
ScreenManager.peek():textedited( text, start, length );
271294
end
272295

273296
---
274297
-- Reroute the textinput callback to the currently active screen.
275-
-- @param input
298+
-- @param input (string) The UTF-8 encoded unicode text.
276299
--
277300
function ScreenManager.textinput( input )
278301
ScreenManager.peek():textinput( input );
@@ -291,40 +314,65 @@ end
291314

292315

293316
---
294-
-- Callback function triggered when a touch press moves inside the touch screen.
295-
-- @param id - The identifier for the touch press.
296-
-- @param x - The x-axis position of the touch press inside the window, in pixels.
297-
-- @param y - The y-axis position of the touch press inside the window, in pixels.
298-
-- @param pressure - The amount of pressure being applied. Most touch screens aren't pressure sensitive, in which case the pressure will be 1.
317+
-- Reroute the touchmoved callback to the currently active screen.
318+
-- @param id (light userdata) The identifier for the touch press.
319+
-- @param x (number) The x-axis position of the touch press inside the
320+
-- window, in pixels.
321+
-- @param y (number) The y-axis position of the touch press inside the
322+
-- window, in pixels.
323+
-- @param dx (number) The x-axis movement of the touch inside the
324+
-- window, in pixels.
325+
-- @param dy (number) The y-axis movement of the touch inside the
326+
-- window, in pixels.
327+
-- @param pressure (number) The amount of pressure being applied. Most
328+
-- touch screens aren't pressure sensitive,
329+
-- in which case the pressure will be 1.
299330
--
300-
function ScreenManager.touchmoved( id, x, y, pressure )
301-
ScreenManager.peek():touchmoved( id, x, y, pressure );
331+
function ScreenManager.touchmoved( id, x, y, dx, dy, pressure )
332+
ScreenManager.peek():touchmoved( id, x, y, dx, dy, pressure );
302333
end
303334

304335
---
305-
-- Callback function triggered when the touch screen is touched.
306-
-- @param id - The identifier for the touch press.
307-
-- @param x - The x-axis position of the touch press inside the window, in pixels.
308-
-- @param y - The y-axis position of the touch press inside the window, in pixels.
309-
-- @param pressure - The amount of pressure being applied. Most touch screens aren't pressure sensitive, in which case the pressure will be 1.
336+
-- Reroute the touchpressed callback to the currently active screen.
337+
-- @param id (light userdata) The identifier for the touch press.
338+
-- @param x (number) The x-axis position of the touch press inside the
339+
-- window, in pixels.
340+
-- @param y (number) The y-axis position of the touch press inside the
341+
-- window, in pixels.
342+
-- @param dx (number) The x-axis movement of the touch inside the
343+
-- window, in pixels.
344+
-- @param dy (number) The y-axis movement of the touch inside the
345+
-- window, in pixels.
346+
-- @param pressure (number) The amount of pressure being applied. Most
347+
-- touch screens aren't pressure sensitive,
348+
-- in which case the pressure will be 1.
310349
--
311-
function ScreenManager.touchpressed( id, x, y, pressure )
312-
ScreenManager.peek():touchpressed( id, x, y, pressure );
350+
function ScreenManager.touchpressed( id, x, y, dx, dy, pressure )
351+
ScreenManager.peek():touchpressed( id, x, y, dx, dy, pressure );
313352
end
314353

315354
---
316-
-- Callback function triggered when the touch screen stops being touched.
317-
-- @param id - The identifier for the touch press.
318-
-- @param x - The x-axis position of the touch press inside the window, in pixels.
319-
-- @param y - The y-axis position of the touch press inside the window, in pixels.
320-
-- @param pressure - The amount of pressure being applied. Most touch screens aren't pressure sensitive, in which case the pressure will be 1.
355+
-- Reroute the touchreleased callback to the currently active screen.
356+
-- @param id (light userdata) The identifier for the touch press.
357+
-- @param x (number) The x-axis position of the touch press inside the
358+
-- window, in pixels.
359+
-- @param y (number) The y-axis position of the touch press inside the
360+
-- window, in pixels.
361+
-- @param dx (number) The x-axis movement of the touch inside the
362+
-- window, in pixels.
363+
-- @param dy (number) The y-axis movement of the touch inside the
364+
-- window, in pixels.
365+
-- @param pressure (number) The amount of pressure being applied. Most
366+
-- touch screens aren't pressure sensitive,
367+
-- in which case the pressure will be 1.
321368
--
322-
function ScreenManager.touchreleased( id, x, y, pressure )
323-
ScreenManager.peek():touchreleased( id, x, y, pressure );
369+
function ScreenManager.touchreleased( id, x, y, dx, dy, pressure )
370+
ScreenManager.peek():touchreleased( id, x, y, dx, dy, pressure );
324371
end
325372

326373
---
327-
-- Update all screens on the stack.
374+
-- Reroute the update callback to all screens.
375+
-- @param dt (number) Time since the last update in seconds.
328376
--
329377
function ScreenManager.update( dt )
330378
for i = 1, #stack do
@@ -333,19 +381,22 @@ function ScreenManager.update( dt )
333381
end
334382

335383
---
336-
-- Update all screens on the stack whenever the game window is minimized.
337-
-- @param nvisible
384+
-- Reroute the visible callback to all screens.
385+
-- @param visible (boolean) True if the window is visible, false if it isn't.
338386
--
339-
function ScreenManager.visible( nvisible )
387+
function ScreenManager.visible( visible )
340388
for i = 1, #stack do
341-
stack[i]:visible( nvisible );
389+
stack[i]:visible( visible );
342390
end
343391
end
344392

345393
---
346-
-- Callback function triggered when the mouse wheel is moved.
347-
-- @param x - Amount of horizontal mouse wheel movement. Positive values indicate movement to the right.
348-
-- @param y - Amount of vertical mouse wheel movement. Positive values indicate upward movement.
394+
-- Reroute the wheelmoved callback to the currently active screen.
395+
-- @param x (number) Amount of horizontal mouse wheel movement. Positive values
396+
-- indicate movement to the right.
397+
-- @param y (number) Amount of vertical mouse wheel movement. Positive values
398+
-- indicate upward movement.
399+
--
349400
function ScreenManager.wheelmoved( x, y )
350401
ScreenManager.peek():wheelmoved( x, y );
351402
end

0 commit comments

Comments
 (0)