├── LICENSE ├── README.md └── feathers └── extensions └── FadeImageSkin.as /LICENSE: -------------------------------------------------------------------------------- 1 | Original work Copyright 2012-2016 Bowler Hat LLC. All rights reserved. 2 | Modified work Copyright 2016 Marcel Piestansky 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | The views and conclusions contained in the software and documentation are those 26 | of the authors and should not be interpreted as representing official policies, 27 | either expressed or implied, of the copyright holders. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FadeImageSkin for Feathers 2 | 3 | Extension for Feathers library that enables alpha transition between different component state skins. 4 | 5 | ## Overview 6 | 7 | Usage is identical to the original [ImageSkin](https://github.com/BowlerHatLLC/feathers/blob/master/source/feathers/skins/ImageSkin.as): 8 | 9 | ```as3 10 | import feathers.extensions.FadeImageSkin; 11 | ... 12 | var skin:FadeImageSkin = new FadeImageSkin( upTexture ); 13 | skin.setTextureForState( ButtonState.DOWN, downTexture ); 14 | skin.setTextureForState( ButtonState.DISABLED, disabledTexture ); 15 | skin.scale9Grid = scale9Grid; 16 | button.defaultSkin = skin; 17 | ``` 18 | 19 | You can specify duration and transition for fade in and fade out Tweens. 20 | 21 | ```as3 22 | // These are all default values 23 | skin.fadeInDuration = 0.5; 24 | skin.fadeInTransition = Transitions.EASE_OUT; 25 | skin.fadeOutDuration = 0.5; 26 | skin.fadeOutTransition = Transitions.EASE_IN; 27 | ``` 28 | 29 | As with the original ImageSkin, you can set a color for each state: 30 | 31 | ```as3 32 | skin.setColorForState( ButtonState.UP, 0x0000FF ); 33 | skin.setColorForState( ButtonState.DOWN, 0xFF0000 ); 34 | ``` 35 | 36 | Furthermore, you can enable tweening of the color between each state which is useful if you are using a single texture. 37 | 38 | ```as3 39 | var skin:FadeImageSkin = new FadeImageSkin( defaultTexture ); 40 | skin.setColorForState( ButtonState.UP, 0x0000FF ); 41 | skin.setColorForState( ButtonState.DOWN, 0xFF0000 ); 42 | skin.tweenColorChange = true; 43 | skin.colorTweenDuration = 0.5; 44 | skin.colorTweenTransition = Transitions.EASE_OUT; 45 | button.defaultSkin = skin; 46 | ``` 47 | 48 | ## Requirements 49 | 50 | * [Starling Framework 2.0+](https://github.com/Gamua/Starling-Framework) 51 | * [Feathers 3.0+](https://github.com/BowlerHatLLC/feathers) 52 | 53 | ## Author 54 | [Marcel Piestansky](https://twitter.com/marpies) 55 | -------------------------------------------------------------------------------- /feathers/extensions/FadeImageSkin.as: -------------------------------------------------------------------------------- 1 | /* 2 | Original work Copyright 2012-2016 Bowler Hat LLC. All rights reserved. 3 | Modified work Copyright 2016 Marcel Piestansky 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 19 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | The views and conclusions contained in the software and documentation are those 27 | of the authors and should not be interpreted as representing official policies, 28 | either expressed or implied, of the copyright holders. 29 | */ 30 | package feathers.extensions { 31 | 32 | import feathers.controls.ButtonState; 33 | import feathers.controls.ToggleButton; 34 | import feathers.core.IFeathersControl; 35 | import feathers.core.IMeasureDisplayObject; 36 | import feathers.core.IStateContext; 37 | import feathers.core.IStateObserver; 38 | import feathers.core.IToggle; 39 | import feathers.events.FeathersEventType; 40 | 41 | import flash.geom.Rectangle; 42 | 43 | import starling.animation.Juggler; 44 | import starling.animation.Transitions; 45 | import starling.core.Starling; 46 | import starling.display.DisplayObjectContainer; 47 | import starling.display.Image; 48 | import starling.events.Event; 49 | import starling.textures.Texture; 50 | 51 | /** 52 | * A skin for Feathers components that displays a texture. Has the ability 53 | * to change its texture based on the current state of the Feathers 54 | * component that is being skinned. Uses two Image objects to achieve 55 | * a fading effect when the state skin changes. 56 | * 57 | *
currentState
property matches the specified state value.
135 | *
136 | * If a texture is not defined for a specific state, returns
137 | * null
.
currentState
property matches the specified state value.
148 | *
149 | * If a texture is not defined for a specific state, the value of the
150 | * defaultTexture
property will be used instead.
currentState
property matches the specified state value.
166 | *
167 | * If a color is not defined for a specific state, returns
168 | * uint.MAX_VALUE
.
currentState
property matches the specified state value.
182 | *
183 | * If a color is not defined for a specific state, the value of the
184 | * defaultTexture
property will be used instead.
To clear a state's color, pass in uint.MAX_VALUE
.
Texture
based on the current state of that context.
409 | * Typically, a relevant component will automatically assign itself as
410 | * the state context of its skin, so this property is considered to be
411 | * for internal use only.
412 | *
413 | * @default null
414 | *
415 | * @see #setTextureForState()
416 | */
417 | public function get stateContext():IStateContext {
418 | return mStateContext;
419 | }
420 |
421 | public function set stateContext( value:IStateContext ):void {
422 | if( mStateContext === value ) {
423 | return;
424 | }
425 | if( mStateContext ) {
426 | mStateContext.removeEventListener( FeathersEventType.STATE_CHANGE, onStateContextChanged );
427 | }
428 | mStateContext = value;
429 | if( mStateContext ) {
430 | mStateContext.addEventListener( FeathersEventType.STATE_CHANGE, onStateContextChanged );
431 | }
432 | updateTextureFromContext();
433 | updateColorFromContext();
434 | }
435 |
436 | /**
437 | * The value passed to the width
property setter. If the
438 | * width
property has not be set, returns NaN
.
439 | *
440 | * @see #width
441 | */
442 | public function get explicitWidth():Number {
443 | return mExplicitWidth;
444 | }
445 |
446 | override public function set width( value:Number ):void {
447 | if( mExplicitWidth === value ) {
448 | return;
449 | }
450 | if( value !== value && mExplicitWidth !== mExplicitWidth ) {
451 | return;
452 | }
453 | mExplicitWidth = value;
454 | if( mActiveSkin !== null ) {
455 | if( value === value ) { //!isNaN
456 | mActiveSkin.width = value;
457 | } else { // return to the original width of the texture
458 | mActiveSkin.readjustSize();
459 | }
460 | }
461 | dispatchEventWith( Event.RESIZE );
462 | }
463 |
464 | override public function get width():Number {
465 | return mActiveSkin ? mActiveSkin.width : NaN;
466 | }
467 |
468 | /**
469 | * The value passed to the height
property setter. If the
470 | * height
property has not be set, returns
471 | * NaN
.
472 | *
473 | * @see #height
474 | */
475 | public function get explicitHeight():Number {
476 | return mExplicitHeight;
477 | }
478 |
479 | override public function set height( value:Number ):void {
480 | if( mExplicitHeight === value ) {
481 | return;
482 | }
483 | if( value !== value && mExplicitHeight !== mExplicitHeight ) {
484 | return;
485 | }
486 | mExplicitHeight = value;
487 | if( mActiveSkin !== null ) {
488 | if( value === value ) { //!isNaN
489 | mActiveSkin.height = value;
490 | } else { //return to the original height of the texture
491 | mActiveSkin.readjustSize();
492 | }
493 | }
494 | dispatchEventWith( Event.RESIZE );
495 | }
496 |
497 | override public function get height():Number {
498 | return mActiveSkin ? mActiveSkin.height : NaN;
499 | }
500 |
501 | /**
502 | * The value passed to the minWidth
property setter. If the
503 | * minWidth
property has not be set, returns
504 | * NaN
.
505 | *
506 | * @see #minWidth
507 | */
508 | public function get explicitMinWidth():Number {
509 | return mExplicitMinWidth;
510 | }
511 |
512 | public function get minWidth():Number {
513 | if( mExplicitMinWidth === mExplicitMinWidth ) { //!isNaN
514 | return mExplicitMinWidth;
515 | }
516 | return 0;
517 | }
518 |
519 | public function set minWidth( value:Number ):void {
520 | if( mExplicitMinWidth === value ) {
521 | return;
522 | }
523 | if( value !== value && mExplicitMinWidth !== mExplicitMinWidth ) {
524 | return;
525 | }
526 | mExplicitMinWidth = value;
527 | dispatchEventWith( Event.RESIZE );
528 | }
529 |
530 | /**
531 | * The value passed to the maxWidth
property setter. If the
532 | * maxWidth
property has not be set, returns
533 | * NaN
.
534 | *
535 | * @see #maxWidth
536 | */
537 | public function get explicitMaxWidth():Number {
538 | return mExplicitMaxWidth;
539 | }
540 |
541 | /**
542 | * The maximum width of the component.
543 | */
544 | public function get maxWidth():Number {
545 | return mExplicitMaxWidth;
546 | }
547 |
548 | /**
549 | * @private
550 | */
551 | public function set maxWidth(value:Number):void {
552 | if( mExplicitMaxWidth === value ) {
553 | return;
554 | }
555 | if( value !== value && mExplicitMaxWidth !== mExplicitMaxWidth ) {
556 | return;
557 | }
558 | mExplicitMaxWidth = value;
559 | dispatchEventWith( Event.RESIZE );
560 | }
561 |
562 | /**
563 | * The value passed to the minHeight
property setter. If
564 | * the minHeight
property has not be set, returns
565 | * NaN
.
566 | *
567 | * @see #minHeight
568 | */
569 | public function get explicitMinHeight():Number {
570 | return mExplicitMinHeight;
571 | }
572 |
573 | public function get minHeight():Number {
574 | if( mExplicitMinHeight === mExplicitMinHeight ) { //!isNaN
575 | return mExplicitMinHeight;
576 | }
577 | return 0;
578 | }
579 |
580 | public function set minHeight( value:Number ):void {
581 | if( mExplicitMinHeight === value ) {
582 | return;
583 | }
584 | if( value !== value && mExplicitMinHeight !== mExplicitMinHeight ) {
585 | return;
586 | }
587 | mExplicitMinHeight = value;
588 | dispatchEventWith( Event.RESIZE );
589 | }
590 |
591 | /**
592 | * The value passed to the maxHeight
property setter. If
593 | * the maxHeight
property has not be set, returns
594 | * NaN
.
595 | *
596 | * @see #maxHeight
597 | */
598 | public function get explicitMaxHeight():Number {
599 | return mExplicitMaxHeight;
600 | }
601 |
602 | /**
603 | * The maximum height of the component.
604 | */
605 | public function get maxHeight():Number {
606 | return mExplicitMaxHeight;
607 | }
608 |
609 | /**
610 | * @private
611 | */
612 | public function set maxHeight(value:Number):void {
613 | if( mExplicitMaxHeight === value ) {
614 | return;
615 | }
616 | if( value !== value && mExplicitMaxHeight !== mExplicitMaxHeight ) {
617 | return;
618 | }
619 | mExplicitMaxHeight = value;
620 | dispatchEventWith( Event.RESIZE );
621 | }
622 |
623 | /**
624 | * The default texture that the skin will display. If the component
625 | * being skinned supports states, the texture for a specific state may
626 | * be specified using the setTextureForState()
method. If
627 | * no texture has been specified for the current state, the default
628 | * texture will be used.
629 | *
630 | * In the following example, the default texture is specified in the 631 | * constructor:
632 | * 633 | *In the following example, the default texture is specified by 637 | * setting the property:
638 | * 639 | *stateContext
is
667 | * an IFeathersControl
and its isEnabled
668 | * property is false
. If a texture has been specified for
669 | * the context's current state with setTextureForState()
,
670 | * it will take precedence over the disabledTexture
.
671 | *
672 | * In the following example, the disabled texture is changed:
673 | * 674 | *stateContext
is
700 | * an IToggle
instance and its isSelected
701 | * property is true
. If a texture has been specified for
702 | * the context's current state with setTextureForState()
,
703 | * it will take precedence over the selectedTexture
.
704 | *
705 | * In the following example, the selected texture is changed:
706 | * 707 | *setColorForState()
method. If
874 | * no color has been specified for the current state, the default
875 | * color will be used.
876 | *
877 | * A value of uint.MAX_VALUE
means that the
878 | * color
property will not be changed when the context's
879 | * state changes.
In the following example, the default color is specified:
882 | * 883 | *stateContext
is
910 | * an IFeathersControl
and its isEnabled
911 | * property is false
. If a color has been specified for
912 | * the context's current state with setColorForState()
,
913 | * it will take precedence over the disabledColor
.
914 | *
915 | * A value of uint.MAX_VALUE
means that the
916 | * disabledColor
property cannot affect the tint when the
917 | * context's state changes.
In the following example, the disabled color is changed:
920 | * 921 | *stateContext
is
951 | * an IToggle
instance and its isSelected
952 | * property is true
. If a color has been specified for
953 | * the context's current state with setColorForState()
,
954 | * it will take precedence over the selectedColor
.
955 | *
956 | * In the following example, the selected color is changed:
957 | * 958 | *