Difference between views, viewports, forms, canvases and windows

Tim Olson tim at jumpnet.com
Tue Feb 3 16:29:46 UTC 1998


>The difference between views, viewports, forms, canvases, and windows is not
>too clear in my mind and the Squeak online documentation does not make it
>clearer. Could someone please enlighten me on the matter?
>
>Would you use a view, a viewport, a form, a canvas, or a window, if you 
>simply
>wanted to draw a shape in a window (separate from the Workspace) using a Pen?

Definition Summary:

--- MVC architecture ---
     Form:     basic display medium
     View:     structured picture that can contain other views
               part of "Model, View, Control" (MVC) architecture.

     viewport: not a basic object; it is the rectangle of a subview
               in the superview's coordinate system.
     window:   not a basic object; it is the rectangle of a view in
               its coordinate system.

--- Morphic Architecture ---
     Canvas:   part of the new Morphic display architecture; FormCanvas is
               used as the background on which to draw Morphs.  Morphic
               is a newer display architecture which will slowly replace
               the older MVC architecture in Squeak.


In the MVC display architecture, the basic display medium is a Form, 
which can be used as a source or destination for displaying on other 
Forms using a BitBlt object.  The DisplayScreen "Display" is a kind of 
form, so you can draw directly on it like you can any other form:

| pen |
pen := Pen newOnForm: Display.
pen defaultNib: 4.
1 to: 50 do: [:i | pen go: i*4. pen turn: 89].

will draw a black spiral in the center of the Display.  Note that since 
you are drawing directly to the display, it draws over any existing views 
("windows"), and will be erased as views are moved over it.

You can draw the spiral on another form to "retain it", then draw that 
form on the Display:

| form pen |
form := Form extent: 300 at 300 depth: Display depth.
form fillColor: Color green.
pen := Pen newOnForm: form.
pen defaultNib: 4.
1 to: 50 do: [:i | pen go: i*4. pen turn: 89].
form display.
form displayAt: Display center - form center.

Here the pen draws on the form, which in turn is then drawn on the 
Display at two locations.  However, this is still drawing directly to the 
display, so it again draws over existing views and will be erased as 
views are moved over it.

To put the form in its own "window" (view) that interacts correctly with 
the other system views, you need to use the View classes.  a View is a 
structured picture which can contain subviews, and is part of the "Model, 
View, Control" (MVC) architecture.  Here we will put our form in a 
FormView (which knows how to display forms, and can edit them as well), 
and add the FormView as a subview of a ColorSystemView (which adds the 
standard title bar, close and grow boxes, and other standard window 
controls):

| form pen view topView |
form := Form extent: 300 at 300 depth: Display depth.
form fillColor: Color green.
pen := Pen newOnForm: form.
pen defaultNib: 4.
1 to: 50 do: [:i | pen go: i*4. pen turn: 89].
view := FormView new.
view model: form.
view borderWidth: 2.
topView := ColorSystemView new.
topView model: form.  "to set the correct window size"
topView addSubView: view.
topView controller open.

Now the picture can be moved, resized, edited, etc.




     -- tim





More information about the Squeak-dev mailing list