Questions on scrolling FormViews, etc.

ssadams at us.ibm.com ssadams at us.ibm.com
Tue Dec 8 20:09:36 UTC 1998




Mike Wirth wrote:
<<
Hey, this is fun.  I'm finally getting around to writing some Squeak code
for some visual UI experiments I've been threatening to do for ages.  But I
have a few questions for the group. Here's what I want to do:

Goal:  I have a large image/drawing (larger than screen size) that I want
to pan around and overlay with some alpha-blended annotations.  I want to
present it in a window and scroll by using scroll bars and (for extra
credit :-) by using a "hand grabber" (as in Adobe Illustrator).

Currently, (using MVC :-) I've created a TestView class, descending from
ColorSystemView, into which I put a FormView, which contains the Form
holding (a portion of) my image.  Using the Form object, I can do the
annotations I want (copying shamelessly from the BitBlt alphaBlendDemo
code).  But I need to do more:

1. Presuming my image will fit in a Form which I can hold in memory, how do
I scroll this large Form around in a smaller viewport?  There are scrolling
view classes for lists, etc., but I haven't found anything I can use for a
Form.  Do I need to build my own, basing it on scrolling lists, for
example?  Can I just embed a FormView in a scrolling list?  Are there some
transformation settings on a FormView that I can use?  (By default, if I
put a larger Form into a smaller FormView>>ColorSystemView, the Form gets
scaled to fit, not clipped.)

2. (This question is probably for Sam Adams)  If I succeed in creating a
scrolling view of my Form, with scrollbars, what do I need to do to insure
that Windoze-style scrollbars will work with it?

(((snip)))
>>

Mike,
Here is an example of MVC form scrolling with both a hand and a vertical
scrollbar.
This example assumes you already have Windoze loaded, but the hand
scrolling code is plain MVC.
I also threw in some handy cursors.  (Ain't Smalltalk great!)
The horizontal scrollbar and the alpha blend annotation is all yours.
Regards,
Sam


Sam S. Adams, Distinguished Engineer, IBM Network Computing Software
Division
tie line 444-0736, outside 919-254-0736, email: ssadams at us.ibm.com
<<Hebrews 11:6, Proverbs 3:5-6, Romans 1:16-17, I Corinthians 1:10>>

-----code follows-----------

View subclass: #SimpleFormView
     instanceVariableNames: ''
     classVariableNames: ''
     poolDictionaries: ''
     category: 'Scrolling Forms'!
!SimpleFormView commentStamp: 'ssa 12/8/1998 13:43' prior: 0!
My model is assumed to be a Form.

Try this example:

SimpleFormView example!


!SimpleFormView methodsFor: 'displaying' stamp: 'ssa 12/8/1998 13:47'!
display

     Display fill: self insetDisplayBox fillColor: Color white.
     self model
          displayOn: Display
          at: self insetDisplayBox origin
          clippingBox: self insetDisplayBox
          rule: Form over
          fillColor: nil! !


!SimpleFormView methodsFor: 'model access' stamp: 'ssa 12/8/1998 14:01'!
model

     super model isNil ifTrue:[self model: Display].
     ^super model! !


!SimpleFormView methodsFor: 'controller access' stamp: 'ssa 12/8/1998
13:42'!
defaultControllerClass

     ^NoController  "for a simple, non-interactive view"! !


!SimpleFormView methodsFor: 'scheduling' stamp: 'ssa 12/8/1998 14:40'!
open

     | topView |
     topView _ ColorSystemView new.
     topView label:'Example of SimpleFormView'.
     topView addSubView: self.
     topView controller open! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

SimpleFormView class
     instanceVariableNames: ''!

!SimpleFormView class methodsFor: 'examples' stamp: 'ssa 12/8/1998 13:44'!
example
     "SimpleFormView example"

     self new open! !


MouseMenuController subclass: #SimpleScrollingFormController
     instanceVariableNames: ''
     classVariableNames: ''
     poolDictionaries: ''
     category: 'Scrolling Forms'!

!SimpleScrollingFormController methodsFor: 'cursor access' stamp: 'ssa
12/8/1998 14:53'!
closedHandCursor
     "do this to prevent the modification of base class Cursor"
     ^(Cursor
     extent: 16 at 16
     depth: 1
     fromArray: #(
          2r0
          2r0
          2r0
          2r1101101100000000000000000000
          2r10010010011000000000000000000
          2r10010010010110000000000000000
          2r1000000010010000000000000000
          2r11000000000010000000000000000
          2r101000000000100000000000000000
          2r100000000000100000000000000000
          2r100000000000100000000000000000
          2r10000000001000000000000000000
          2r10000000001000000000000000000
          2r1000000010000000000000000000
          2r100000010000000000000000000
          2r100000010000000000000000000)
     offset: 0 at 0)! !

!SimpleScrollingFormController methodsFor: 'cursor access' stamp: 'ssa
12/8/1998 14:50'!
openHandCursor
     "do this to prevent the modification of base class Cursor"
     ^(Cursor
               extent: 16 @ 16
               fromArray: #(
          2r110000000
          2r1101001110000
          2r10011001001000
          2r10011001001010
          2r1001001001101
          2r1001001001001
          2r110100000001001
          2r1001100000000001
          2r1000100000000010
          2r100000000000010
          2r10000000000010
          2r1000000000100
          2r1000000000100
          2r100000001000
          2r10000001000
          2r10000001000)
               offset: 0 @ 0)! !


!SimpleScrollingFormController methodsFor: 'basic control sequence' stamp:
'ssa 12/8/1998 14:53'!
controlInitialize
     "just change the cursor"

     self openHandCursor show! !

!SimpleScrollingFormController methodsFor: 'basic control sequence' stamp:
'ssa 12/8/1998 13:54'!
controlTerminate
     "just change the cursor back"

     Cursor normal show! !


!SimpleScrollingFormController methodsFor: 'menu messages' stamp: 'ssa
12/8/1998 14:54'!
redButtonActivity
     "adjust the offset of the view while the redButton is pressed and
update the view for dynamic scrolling."

     | lastPoint nextPoint |
     lastPoint _ Sensor cursorPoint.
     self closedHandCursor show.
     [Sensor redButtonPressed] whileTrue:
          [nextPoint _ Sensor cursorPoint.
          self view offset: self view offset + (nextPoint - lastPoint).
          self view display.
          lastPoint _ nextPoint].
     self openHandCursor show! !


!SimpleScrollingFormController methodsFor: 'scrollbar support' stamp: 'ssa
12/8/1998 14:39'!
scrollView: aNumber
     "Scroll my view's offset by this delta"
     self view offset: self view offset + (0 at aNumber).
"    aNumber positive ifTrue:[self halt]."
     self view display! !


SimpleFormView subclass: #SimpleScrollingFormView
     instanceVariableNames: 'offset '
     classVariableNames: ''
     poolDictionaries: ''
     category: 'Scrolling Forms'!

!SimpleScrollingFormView methodsFor: 'accessing' stamp: 'ssa 12/8/1998
13:48'!
offset
     "Use this offset instead of changing the offset in my model."

     offset isNil ifTrue:[self offset: 0 at 0].
     ^offset! !

!SimpleScrollingFormView methodsFor: 'accessing' stamp: 'ssa 12/8/1998
14:33'!
offset: aPoint

     offset _ (aPoint min: 0 at 0) max: (self model extent - self
insetDisplayBox extent) negated.
! !


!SimpleScrollingFormView methodsFor: 'displaying' stamp: 'ssa 12/8/1998
14:27'!
display

     Display fill: self insetDisplayBox fillColor: Color white.
     self model
          displayOn: Display
          at: self insetDisplayBox origin + self offset
          clippingBox: self insetDisplayBox
          rule: Form over
          fillColor: nil.

                "A hack to notify the MSWScrollBarController"
        (self superView isKindOf: MSWScrollBarView)
                ifTrue:[self superView updateElevator]! !


!SimpleScrollingFormView methodsFor: 'controller access' stamp: 'ssa
12/8/1998 13:59'!
defaultControllerClass

     ^SimpleScrollingFormController! !


!SimpleScrollingFormView methodsFor: 'scrollbar support' stamp: 'ssa
12/8/1998 14:33'!
percentPreceedingContent
        "Answer the percent of my content that not visible since it has
been scrolled of the top of the screen.  ssa 12/5/97 15:37"

        ^(self offset y abs / self model height) asFloat! !

!SimpleScrollingFormView methodsFor: 'scrollbar support' stamp: 'ssa
12/8/1998 14:11'!
totalContentHeight
        "Answer the total height of my contents. ssa 12/5/97 15:16"
        ^ self model height! !

!SimpleScrollingFormView methodsFor: 'scrollbar support' stamp: 'ssa
12/8/1998 14:38'!
unitContentHeight
        "Answer the unit height of my contents. ssa 12/5/97 15:16"
        ^ 1! !

!SimpleScrollingFormView methodsFor: 'scrollbar support' stamp: 'ssa
12/8/1998 14:30'!
visibleContentHeight
        "Answer the height of my visible content.  ssa 12/5/97 15:04"

        ^self insetDisplayBox height! !


!SimpleScrollingFormView methodsFor: 'scheduling' stamp: 'ssa 12/8/1998
14:41'!
open

     | topView |
     topView _ ColorSystemView new.
     topView label:'Example of SimpleScrollingFormView'.
     topView addSubView: self.
     topView controller open! !

!SimpleScrollingFormView methodsFor: 'scheduling' stamp: 'ssa 12/8/1998
14:39'!
openWithScrollBars

     | topView |
     topView _ ColorSystemView new.
     topView label:'Scrolling Form View example with Scrollbar'.
     topView addSubView: (MSWScrollBarView on: self).
     topView controller open! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

SimpleScrollingFormView class
     instanceVariableNames: ''!

!SimpleScrollingFormView class methodsFor: 'examples' stamp: 'ssa 12/8/1998
 13:58'!
example
     "SimpleScrollingFormView example"

     self new open! !

!SimpleScrollingFormView class methodsFor: 'examples' stamp: 'ssa 12/8/1998
 14:04'!
exampleWithScrollBars
     "SimpleScrollingFormView exampleWithScrollBars"

     self new openWithScrollBars! !





More information about the Squeak-dev mailing list