-
Notifications
You must be signed in to change notification settings - Fork 385
/
PanelScreen.as
489 lines (445 loc) · 15.1 KB
/
PanelScreen.as
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
/*
Feathers
Copyright 2012-2015 Bowler Hat LLC. All Rights Reserved.
This program is free software. You can redistribute and/or modify it in
accordance with the terms of the accompanying license agreement.
*/
package feathers.controls
{
import feathers.skins.IStyleProvider;
import feathers.utils.display.getDisplayObjectDepthFromStage;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import starling.core.Starling;
import starling.events.Event;
/**
* Dispatched when the transition animation begins as the screen is shown
* by the screen navigator.
*
* <p>The properties of the event object have the following values:</p>
* <table class="innertable">
* <tr><th>Property</th><th>Value</th></tr>
* <tr><td><code>bubbles</code></td><td>false</td></tr>
* <tr><td><code>currentTarget</code></td><td>The Object that defines the
* event listener that handles the event. For example, if you use
* <code>myButton.addEventListener()</code> to register an event listener,
* myButton is the value of the <code>currentTarget</code>.</td></tr>
* <tr><td><code>data</code></td><td>null</td></tr>
* <tr><td><code>target</code></td><td>The Object that dispatched the event;
* it is not always the Object listening for the event. Use the
* <code>currentTarget</code> property to always access the Object
* listening for the event.</td></tr>
* </table>
*
* @eventType feathers.events.FeathersEventType.TRANSITION_IN_START
*/
[Event(name="transitionInStart",type="starling.events.Event")]
/**
* Dispatched when the transition animation finishes as the screen is shown
* by the screen navigator.
*
* <p>The properties of the event object have the following values:</p>
* <table class="innertable">
* <tr><th>Property</th><th>Value</th></tr>
* <tr><td><code>bubbles</code></td><td>false</td></tr>
* <tr><td><code>currentTarget</code></td><td>The Object that defines the
* event listener that handles the event. For example, if you use
* <code>myButton.addEventListener()</code> to register an event listener,
* myButton is the value of the <code>currentTarget</code>.</td></tr>
* <tr><td><code>data</code></td><td>null</td></tr>
* <tr><td><code>target</code></td><td>The Object that dispatched the event;
* it is not always the Object listening for the event. Use the
* <code>currentTarget</code> property to always access the Object
* listening for the event.</td></tr>
* </table>
*
* @eventType feathers.events.FeathersEventType.TRANSITION_IN_COMPLETE
*/
[Event(name="transitionInComplete",type="starling.events.Event")]
/**
* Dispatched when the transition animation begins as a different screen is
* shown by the screen navigator and this screen is hidden.
*
* <p>The properties of the event object have the following values:</p>
* <table class="innertable">
* <tr><th>Property</th><th>Value</th></tr>
* <tr><td><code>bubbles</code></td><td>false</td></tr>
* <tr><td><code>currentTarget</code></td><td>The Object that defines the
* event listener that handles the event. For example, if you use
* <code>myButton.addEventListener()</code> to register an event listener,
* myButton is the value of the <code>currentTarget</code>.</td></tr>
* <tr><td><code>data</code></td><td>null</td></tr>
* <tr><td><code>target</code></td><td>The Object that dispatched the event;
* it is not always the Object listening for the event. Use the
* <code>currentTarget</code> property to always access the Object
* listening for the event.</td></tr>
* </table>
*
* @eventType feathers.events.FeathersEventType.TRANSITION_OUT_START
*/
[Event(name="transitionOutStart",type="starling.events.Event")]
/**
* Dispatched when the transition animation finishes as a different screen
* is shown by the screen navigator and this screen is hidden.
*
* <p>The properties of the event object have the following values:</p>
* <table class="innertable">
* <tr><th>Property</th><th>Value</th></tr>
* <tr><td><code>bubbles</code></td><td>false</td></tr>
* <tr><td><code>currentTarget</code></td><td>The Object that defines the
* event listener that handles the event. For example, if you use
* <code>myButton.addEventListener()</code> to register an event listener,
* myButton is the value of the <code>currentTarget</code>.</td></tr>
* <tr><td><code>data</code></td><td>null</td></tr>
* <tr><td><code>target</code></td><td>The Object that dispatched the event;
* it is not always the Object listening for the event. Use the
* <code>currentTarget</code> property to always access the Object
* listening for the event.</td></tr>
* </table>
*
* @eventType feathers.events.FeathersEventType.TRANSITION_OUT_COMPLETE
*/
[Event(name="transitionOutComplete",type="starling.events.Event")]
/**
* A screen for use with <code>ScreenNavigator</code>, based on <code>Panel</code>
* in order to provide a header and layout.
*
* <p>This component is generally not instantiated directly. Instead it is
* typically used as a super class for concrete implementations of screens.
* With that in mind, no code example is included here.</p>
*
* <p>The following example provides a basic framework for a new panel screen:</p>
*
* <listing version="3.0">
* package
* {
* import feathers.controls.PanelScreen;
*
* public class CustomScreen extends PanelScreen
* {
* public function CustomScreen()
* {
* super();
* }
*
* override protected function initialize():void
* {
* //runs once when screen is first added to the stage
* //a good place to add children and customize the layout
*
* //don't forget to call this!
* super.initialize()
* }
* }
* }</listing>
*
* @see ../../../panel-screen.html How to use the Feathers PanelScreen component
* @see feathers.controls.StackScreenNavigator
* @see feathers.controls.ScreenNavigator
*/
public class PanelScreen extends Panel implements IScreen
{
/**
* The default value added to the <code>styleNameList</code> of the header.
*
* @see feathers.core.FeathersControl#styleNameList
*/
public static const DEFAULT_CHILD_STYLE_NAME_HEADER:String = "feathers-panel-screen-header";
/**
* DEPRECATED: Replaced by <code>PanelScreen.DEFAULT_CHILD_STYLE_NAME_HEADER</code>.
*
* <p><strong>DEPRECATION WARNING:</strong> This property is deprecated
* starting with Feathers 2.1. It will be removed in a future version of
* Feathers according to the standard
* <a target="_top" href="../../../help/deprecation-policy.html">Feathers deprecation policy</a>.</p>
*
* @see PanelScreen#DEFAULT_CHILD_STYLE_NAME_HEADER
*/
public static const DEFAULT_CHILD_NAME_HEADER:String = DEFAULT_CHILD_STYLE_NAME_HEADER;
/**
* The default value added to the <code>styleNameList</code> of the footer.
*
* @see feathers.core.FeathersControl#styleNameList
*/
public static const DEFAULT_CHILD_STYLE_NAME_FOOTER:String = "feathers-panel-screen-footer";
/**
* @copy feathers.controls.Scroller#SCROLL_POLICY_AUTO
*
* @see feathers.controls.Scroller#horizontalScrollPolicy
* @see feathers.controls.Scroller#verticalScrollPolicy
*/
public static const SCROLL_POLICY_AUTO:String = "auto";
/**
* @copy feathers.controls.Scroller#SCROLL_POLICY_ON
*
* @see feathers.controls.Scroller#horizontalScrollPolicy
* @see feathers.controls.Scroller#verticalScrollPolicy
*/
public static const SCROLL_POLICY_ON:String = "on";
/**
* @copy feathers.controls.Scroller#SCROLL_POLICY_OFF
*
* @see feathers.controls.Scroller#horizontalScrollPolicy
* @see feathers.controls.Scroller#verticalScrollPolicy
*/
public static const SCROLL_POLICY_OFF:String = "off";
/**
* @copy feathers.controls.Scroller#SCROLL_BAR_DISPLAY_MODE_FLOAT
*
* @see feathers.controls.Scroller#scrollBarDisplayMode
*/
public static const SCROLL_BAR_DISPLAY_MODE_FLOAT:String = "float";
/**
* @copy feathers.controls.Scroller#SCROLL_BAR_DISPLAY_MODE_FIXED
*
* @see feathers.controls.Scroller#scrollBarDisplayMode
*/
public static const SCROLL_BAR_DISPLAY_MODE_FIXED:String = "fixed";
/**
* @copy feathers.controls.Scroller#SCROLL_BAR_DISPLAY_MODE_NONE
*
* @see feathers.controls.Scroller#scrollBarDisplayMode
*/
public static const SCROLL_BAR_DISPLAY_MODE_NONE:String = "none";
/**
* The vertical scroll bar will be positioned on the right.
*
* @see feathers.controls.Scroller#verticalScrollBarPosition
*/
public static const VERTICAL_SCROLL_BAR_POSITION_RIGHT:String = "right";
/**
* The vertical scroll bar will be positioned on the left.
*
* @see feathers.controls.Scroller#verticalScrollBarPosition
*/
public static const VERTICAL_SCROLL_BAR_POSITION_LEFT:String = "left";
/**
* @copy feathers.controls.Scroller#INTERACTION_MODE_TOUCH
*
* @see feathers.controls.Scroller#interactionMode
*/
public static const INTERACTION_MODE_TOUCH:String = "touch";
/**
* @copy feathers.controls.Scroller#INTERACTION_MODE_MOUSE
*
* @see feathers.controls.Scroller#interactionMode
*/
public static const INTERACTION_MODE_MOUSE:String = "mouse";
/**
* @copy feathers.controls.Scroller#INTERACTION_MODE_TOUCH_AND_SCROLL_BARS
*
* @see feathers.controls.Scroller#interactionMode
*/
public static const INTERACTION_MODE_TOUCH_AND_SCROLL_BARS:String = "touchAndScrollBars";
/**
* @copy feathers.controls.Scroller#MOUSE_WHEEL_SCROLL_DIRECTION_VERTICAL
*
* @see feathers.controls.Scroller#verticalMouseWheelScrollDirection
*/
public static const MOUSE_WHEEL_SCROLL_DIRECTION_VERTICAL:String = "vertical";
/**
* @copy feathers.controls.Scroller#MOUSE_WHEEL_SCROLL_DIRECTION_HORIZONTAL
*
* @see feathers.controls.Scroller#verticalMouseWheelScrollDirection
*/
public static const MOUSE_WHEEL_SCROLL_DIRECTION_HORIZONTAL:String = "horizontal";
/**
* @copy feathers.controls.Scroller#DECELERATION_RATE_NORMAL
*
* @see feathers.controls.Scroller#decelerationRate
*/
public static const DECELERATION_RATE_NORMAL:Number = 0.998;
/**
* @copy feathers.controls.Scroller#DECELERATION_RATE_FAST
*
* @see feathers.controls.Scroller#decelerationRate
*/
public static const DECELERATION_RATE_FAST:Number = 0.99;
/**
* @copy feathers.controls.ScrollContainer#AUTO_SIZE_MODE_STAGE
*
* @see feathers.controls.ScrollContainer#autoSizeMode
*/
public static const AUTO_SIZE_MODE_STAGE:String = "stage";
/**
* @copy feathers.controls.ScrollContainer#AUTO_SIZE_MODE_CONTENT
*
* @see feathers.controls.ScrollContainer#autoSizeMode
*/
public static const AUTO_SIZE_MODE_CONTENT:String = "content";
/**
* The default <code>IStyleProvider</code> for all <code>PanelScreen</code>
* components.
*
* @default null
* @see feathers.core.FeathersControl#styleProvider
*/
public static var globalStyleProvider:IStyleProvider;
/**
* Constructor.
*/
public function PanelScreen()
{
this.addEventListener(Event.ADDED_TO_STAGE, panelScreen_addedToStageHandler);
super();
this.headerStyleName = DEFAULT_CHILD_STYLE_NAME_HEADER;
}
/**
* @private
*/
override protected function get defaultStyleProvider():IStyleProvider
{
return PanelScreen.globalStyleProvider;
}
/**
* @private
*/
protected var _screenID:String;
/**
* @inheritDoc
*/
public function get screenID():String
{
return this._screenID;
}
/**
* @private
*/
public function set screenID(value:String):void
{
this._screenID = value;
}
/**
* @private
*/
protected var _owner:Object;
/**
* @inheritDoc
*/
public function get owner():Object
{
return this._owner;
}
/**
* @private
*/
public function set owner(value:Object):void
{
this._owner = value;
}
/**
* Optional callback for the back hardware key. Automatically handles
* keyboard events to cancel the default behavior.
*
* <p>This function has the following signature:</p>
*
* <pre>function():void</pre>
*
* <p>In the following example, a function will dispatch <code>Event.COMPLETE</code>
* when the back button is pressed:</p>
*
* <listing version="3.0">
* this.backButtonHandler = onBackButton;
*
* private function onBackButton():void
* {
* this.dispatchEvent( Event.COMPLETE );
* };</listing>
*
* @default null
*/
protected var backButtonHandler:Function;
/**
* Optional callback for the menu hardware key. Automatically handles
* keyboard events to cancel the default behavior.
*
* <p>This function has the following signature:</p>
*
* <pre>function():void</pre>
*
* <p>In the following example, a function will be called when the menu
* button is pressed:</p>
*
* <listing version="3.0">
* this.menuButtonHandler = onMenuButton;
*
* private function onMenuButton():void
* {
* //do something with the menu button
* };</listing>
*
* @default null
*/
protected var menuButtonHandler:Function;
/**
* Optional callback for the search hardware key. Automatically handles
* keyboard events to cancel the default behavior.
*
* <p>This function has the following signature:</p>
*
* <pre>function():void</pre>
*
* <p>In the following example, a function will be called when the search
* button is pressed:</p>
*
* <listing version="3.0">
* this.searchButtonHandler = onSearchButton;
*
* private function onSearchButton():void
* {
* //do something with the search button
* };</listing>
*
* @default null
*/
protected var searchButtonHandler:Function;
/**
* @private
*/
protected function panelScreen_addedToStageHandler(event:Event):void
{
this.addEventListener(Event.REMOVED_FROM_STAGE, panelScreen_removedFromStageHandler);
//using priority here is a hack so that objects higher up in the
//display list have a chance to cancel the event first.
var priority:int = -getDisplayObjectDepthFromStage(this);
Starling.current.nativeStage.addEventListener(KeyboardEvent.KEY_DOWN, panelScreen_nativeStage_keyDownHandler, false, priority, true);
}
/**
* @private
*/
protected function panelScreen_removedFromStageHandler(event:Event):void
{
this.removeEventListener(Event.REMOVED_FROM_STAGE, panelScreen_removedFromStageHandler);
Starling.current.nativeStage.removeEventListener(KeyboardEvent.KEY_DOWN, panelScreen_nativeStage_keyDownHandler);
}
/**
* @private
*/
protected function panelScreen_nativeStage_keyDownHandler(event:KeyboardEvent):void
{
if(event.isDefaultPrevented())
{
//someone else already handled this one
return;
}
if(this.backButtonHandler != null &&
event.keyCode == Keyboard.BACK)
{
event.preventDefault();
this.backButtonHandler();
}
if(this.menuButtonHandler != null &&
event.keyCode == Keyboard.MENU)
{
event.preventDefault();
this.menuButtonHandler();
}
if(this.searchButtonHandler != null &&
event.keyCode == Keyboard.SEARCH)
{
event.preventDefault();
this.searchButtonHandler();
}
}
}
}