2323 * center, both useful for constructing artwork that should appear centered on
2424 * screen.
2525 */
26- var View = this . View = Base . extend ( /** @lends View# */ {
26+ var View = this . View = PaperScopeItem . extend ( /** @lends View# */ {
27+ _list : 'views' ,
28+ _reference : 'view' ,
29+
2730 /**
2831 * Creates a view object
2932 * @param {HTMLCanvasElement|String } canvas The canvas object that this
3033 * view should wrap, or the String id that represents it
3134 */
3235 initialize : function ( canvas ) {
33- // Associate this view with the active paper scope.
34- this . _scope = paper ;
35- // Push it onto project.views and set index:
36- this . _index = this . _scope . views . push ( this ) - 1 ;
36+ this . base ( ) ;
3737 // Handle canvas argument
3838 var size ;
3939 if ( typeof canvas === 'string' )
@@ -109,6 +109,32 @@ var View = this.View = Base.extend(/** @lends View# */{
109109 this . _scope . _redrawNotified = false ;
110110 } ,
111111
112+ /**
113+ * Makes this view the active one, meaning {@link PaperScope#view} will
114+ * point to it.
115+ *
116+ * @name View#activate
117+ * @function
118+ */
119+
120+ /**
121+ * Removes thsi view from the {@link PaperScope#views} list and frees the
122+ * associated canvas.
123+ */
124+ remove : function ( ) {
125+ if ( ! this . base ( ) )
126+ return false ;
127+ // Clear focus if removed view had it
128+ if ( View . _focused == this )
129+ View . _focused = null ;
130+ delete View . _views [ this . _id ] ;
131+ // Uninstall event handlers again for this view.
132+ DomEvent . remove ( this . _canvas , this . _events ) ;
133+ // Clearing _onFrame makes the frame handler stop automatically.
134+ this . _canvas = this . _events = this . _onFrame = null ;
135+ return true ;
136+ } ,
137+
112138 /**
113139 * The underlying native canvas element.
114140 *
@@ -239,6 +265,12 @@ var View = this.View = Base.extend(/** @lends View# */{
239265 this . _inverse = null ;
240266 } ,
241267
268+ /**
269+ * Draws the view.
270+ *
271+ * @name View#draw
272+ * @function
273+ */
242274 draw : function ( checkRedraw ) {
243275 if ( checkRedraw && ! this . _redrawNeeded )
244276 return false ;
@@ -264,25 +296,6 @@ var View = this.View = Base.extend(/** @lends View# */{
264296 return true ;
265297 } ,
266298
267- activate : function ( ) {
268- this . _scope . view = this ;
269- } ,
270-
271- remove : function ( ) {
272- if ( this . _index == null )
273- return false ;
274- // Clear focus if removed view had it
275- if ( View . _focused == this )
276- View . _focused = null ;
277- delete View . _views [ this . _id ] ;
278- Base . splice ( this . _scope . views , null , this . _index , 1 ) ;
279- // Uninstall event handlers again for this view.
280- DomEvent . remove ( this . _canvas , this . _events ) ;
281- // Clearing _onFrame makes the frame handler stop automatically.
282- this . _scope = this . _canvas = this . _events = this . _onFrame = null ;
283- return true ;
284- } ,
285-
286299 // TODO: getInvalidBounds
287300 // TODO: invalidate(rect)
288301 // TODO: style: artwork / preview / raster / opaque / ink
0 commit comments