@@ -17,32 +17,31 @@ const DEFAULT_BACKGROUND_OPACITY = 0.2;
17
17
const DEFAULT_PADDING = 0 ;
18
18
19
19
const withBackground = ( {
20
+ background,
20
21
backgroundColor,
21
- backgroundGraphics,
22
22
backgroundOpacity
23
23
} ) => self =>
24
24
assign ( self , {
25
25
get backgroundColor ( ) {
26
- return backgroundGraphics . fill . color ;
26
+ return background . tint ;
27
+ } ,
28
+ setBackgroundColor ( color = backgroundColor ) {
29
+ background . tint = color ;
27
30
} ,
28
31
get backgroundOpacity ( ) {
29
- return backgroundGraphics . fill . alpha ;
32
+ return background . alpha ;
30
33
} ,
31
- clearBackground ( ) {
32
- backgroundGraphics . clear ( ) ;
34
+ setBackgroundOpacity ( opacity = backgroundOpacity ) {
35
+ background . alpha = opacity ;
33
36
} ,
34
- drawBackground (
35
- color = backgroundColor ,
36
- opacity = backgroundOpacity ,
37
- withPadding = false
38
- ) {
37
+ rescaleBackground ( withPadding = false ) {
39
38
const width = self . width + self . padding * withPadding ;
40
39
const height = self . height + self . padding * withPadding ;
41
40
42
- backgroundGraphics . clear ( ) ;
43
- backgroundGraphics . beginFill ( color , opacity ) ;
44
- backgroundGraphics . drawRect ( - width / 2 , - height / 2 , width , height ) ;
45
- backgroundGraphics . endFill ( ) ;
41
+ background . x = - width / 2 ;
42
+ background . y = - height / 2 ;
43
+ background . width = width ;
44
+ background . height = height ;
46
45
}
47
46
} ) ;
48
47
@@ -67,7 +66,8 @@ const createImageWithBackground = (
67
66
padding = DEFAULT_PADDING
68
67
} = { }
69
68
) => {
70
- const backgroundGraphics = new PIXI . Graphics ( ) ;
69
+ const container = new PIXI . Container ( ) ;
70
+ const background = new PIXI . Sprite ( PIXI . Texture . WHITE ) ;
71
71
const displayObject = toDisplayObject ( source ) ;
72
72
73
73
let sprite ;
@@ -79,29 +79,24 @@ const createImageWithBackground = (
79
79
sprite = displayObject ;
80
80
}
81
81
82
- const init = self => {
83
- backgroundGraphics . addChild ( sprite ) ;
84
-
85
- return self ;
86
- } ;
82
+ container . addChild ( background ) ;
83
+ container . addChild ( sprite ) ;
87
84
88
- return init (
89
- pipe (
90
- withStaticProperty ( 'displayObject' , backgroundGraphics ) ,
91
- withStaticProperty ( 'sprite' , sprite ) ,
92
- withColorFilters ( sprite ) ,
93
- withScale ( sprite , displayObject . width , displayObject . height ) ,
94
- withSize ( sprite , displayObject . width , displayObject . height ) ,
95
- withPadding ( padding ) ,
96
- withBackground ( {
97
- backgroundColor,
98
- backgroundGraphics,
99
- backgroundOpacity
100
- } ) ,
101
- withDestroy ( backgroundGraphics ) ,
102
- withConstructor ( createImageWithBackground )
103
- ) ( { } )
104
- ) ;
85
+ return pipe (
86
+ withStaticProperty ( 'displayObject' , container ) ,
87
+ withStaticProperty ( 'sprite' , sprite ) ,
88
+ withColorFilters ( sprite ) ,
89
+ withScale ( sprite , displayObject . width , displayObject . height ) ,
90
+ withSize ( sprite , displayObject . width , displayObject . height ) ,
91
+ withPadding ( padding ) ,
92
+ withBackground ( {
93
+ background,
94
+ backgroundColor,
95
+ backgroundOpacity
96
+ } ) ,
97
+ withDestroy ( sprite ) ,
98
+ withConstructor ( createImageWithBackground )
99
+ ) ( { } ) ;
105
100
} ;
106
101
107
102
export default createImageWithBackground ;
0 commit comments