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 | "use strict" ;
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | const Element = require( './Element.js' ) ;
|
37 | const ScreenBuffer = require( '../ScreenBuffer.js' ) ;
|
38 |
|
39 |
|
40 |
|
41 | function Container( options ) {
|
42 |
|
43 | options = ! options ? {} : options.internal ? options : Object.create( options ) ;
|
44 | options.internal = true ;
|
45 |
|
46 | Element.call( this , options ) ;
|
47 |
|
48 |
|
49 | this.inputX = options.inputX || this.outputX ;
|
50 | this.inputY = options.inputY || this.outputY ;
|
51 | this.inputWidth = options.inputWidth || this.outputWidth ;
|
52 | this.inputHeight = options.inputHeight || this.outputHeight ;
|
53 |
|
54 |
|
55 | this.palette = options.palette || ( this.document && this.document.palette ) ;
|
56 | this.object2attr = object => ScreenBuffer.object2attr( object , this.palette && this.palette.colorNameToIndex ) ;
|
57 |
|
58 | this.inputDst = new ScreenBuffer( {
|
59 | dst: this.outputDst ,
|
60 | x: this.inputX ,
|
61 | y: this.inputY ,
|
62 | width: this.inputWidth ,
|
63 | height: this.inputHeight ,
|
64 | palette: this.palette
|
65 | } ) ;
|
66 |
|
67 | this.deltaDraw = false ;
|
68 | this.backgroundAttr = options.backgroundAttr || { bgColor: 'default' } ;
|
69 |
|
70 |
|
71 | if ( this.elementType === 'Container' && ! options.noDraw ) { this.draw() ; }
|
72 | }
|
73 |
|
74 | module.exports = Container ;
|
75 |
|
76 | Container.prototype = Object.create( Element.prototype ) ;
|
77 | Container.prototype.constructor = Container ;
|
78 | Container.prototype.elementType = 'Container' ;
|
79 |
|
80 | Container.prototype.isContainer = true ;
|
81 |
|
82 |
|
83 |
|
84 | Container.prototype.destroy = function( isSubDestroy ) {
|
85 | Element.prototype.destroy.call( this , isSubDestroy ) ;
|
86 | } ;
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | Container.prototype.resize =
|
96 | Container.prototype.resizeInput = function( to ) {
|
97 | if ( ! to.x ) { to.x = 0 ; }
|
98 | if ( ! to.y ) { to.y = 0 ; }
|
99 |
|
100 | this.inputDst.resize( to ) ;
|
101 | } ;
|
102 |
|
103 |
|
104 |
|
105 | Container.prototype.moveTo = function( x , y ) {
|
106 | this.outputX = this.inputDst.x = x ;
|
107 | this.outputY = this.inputDst.y = y ;
|
108 | } ;
|
109 |
|
110 |
|
111 |
|
112 | Container.prototype.preDrawSelf = function() {
|
113 | this.inputDst.fill( { char: ' ' , attr: this.backgroundAttr } ) ;
|
114 | } ;
|
115 |
|
116 |
|
117 |
|
118 | Container.prototype.postDrawSelf = function() {
|
119 |
|
120 |
|
121 |
|
122 |
|
123 | this.inputDst.draw( {
|
124 | delta: this.deltaDraw ,
|
125 | inline: this.strictInline
|
126 | } ) ;
|
127 | } ;
|
128 |
|
129 |
|
130 |
|
131 | Container.prototype.drawSelfCursor = function( elementTargeted ) {
|
132 | if ( elementTargeted ) { this.restoreCursor() ; }
|
133 | else { this.inputDst.drawCursor() ; }
|
134 | } ;
|
135 |
|
136 |
|
137 |
|
138 | Container.prototype.onOutputDstResize = function( data ) {
|
139 | } ;
|
140 |
|