StrokeView.st
changeset 2668 fa1ac72a7a8f
parent 2666 7f3c3d9ffe4b
child 4770 6634b540fea2
equal deleted inserted replaced
2667:bcaa8849c028 2668:fa1ac72a7a8f
     1 "{ Package: 'stx:libwidg2' }"
     1 "{ Package: 'stx:libwidg2' }"
     2 
     2 
     3 View subclass:#StrokeView
     3 View subclass:#StrokeView
     4 	instanceVariableNames:'strokes currentStroke lastPoint clearButton clearLastButton'
     4 	instanceVariableNames:'strokes currentStroke lastPoint clearButton clearLastButton
       
     5 		strokeAction'
     5 	classVariableNames:''
     6 	classVariableNames:''
     6 	poolDictionaries:''
     7 	poolDictionaries:''
     7 	category:'Views-Special'
     8 	category:'Views-Special'
     8 !
     9 !
     9 
    10 
    31         v := StrokeView openOnXScreenNamed:'bitsy:0'.    ' my pda !!!! '.
    32         v := StrokeView openOnXScreenNamed:'bitsy:0'.    ' my pda !!!! '.
    32         v inspect.
    33         v inspect.
    33 "
    34 "
    34 ! !
    35 ! !
    35 
    36 
       
    37 !StrokeView methodsFor:'accessing'!
       
    38 
       
    39 strokeAction:something
       
    40     strokeAction := something.
       
    41 ! !
       
    42 
    36 !StrokeView methodsFor:'button actions'!
    43 !StrokeView methodsFor:'button actions'!
    37 
    44 
    38 newStrokeSequence
    45 newStrokeSequence
    39     strokes removeAll.
    46     strokes removeAll.
    40     currentStroke := lastPoint := nil.
    47     currentStroke := lastPoint := nil.
    41     self updateButtonStates.
    48     self updateButtonStates.
    42     self redraw
    49     self redraw.
       
    50 
       
    51     strokeAction notNil ifTrue:[
       
    52         strokeAction value:strokes.
       
    53     ]
    43 !
    54 !
    44 
    55 
    45 removeLastStroke
    56 removeLastStroke
    46     strokes size > 0 ifTrue:[
    57     strokes size > 0 ifTrue:[
    47         strokes removeLast.
    58         strokes removeLast.
    48     ].
    59     ].
    49 
    60 
    50     currentStroke := lastPoint := nil.
    61     currentStroke := lastPoint := nil.
    51     self updateButtonStates.
    62     self updateButtonStates.
    52     self redraw
    63     self redraw.
       
    64 
       
    65     strokeAction notNil ifTrue:[
       
    66         strokeAction value:strokes.
       
    67     ]
    53 !
    68 !
    54 
    69 
    55 updateButtonStates
    70 updateButtonStates
    56     strokes isEmpty ifTrue:[
    71     strokes isEmpty ifTrue:[
    57         clearButton disable.
    72         clearButton disable.
    70     state == 0 ifTrue:[^ self].
    85     state == 0 ifTrue:[^ self].
    71 
    86 
    72     thisPoint := x@y.
    87     thisPoint := x@y.
    73     currentStroke add:(LineSegment from:lastPoint to:thisPoint).
    88     currentStroke add:(LineSegment from:lastPoint to:thisPoint).
    74 
    89 
       
    90     self paint:Color yellow.
    75     self displayLineFrom:lastPoint to:thisPoint.
    91     self displayLineFrom:lastPoint to:thisPoint.
    76 
    92 
    77     lastPoint := thisPoint.
    93     lastPoint := thisPoint.
    78 !
    94 !
    79 
    95 
    87 buttonRelease:state x:x y:y
   103 buttonRelease:state x:x y:y
    88     currentStroke notNil ifTrue:[
   104     currentStroke notNil ifTrue:[
    89         strokes add:currentStroke.
   105         strokes add:currentStroke.
    90         currentStroke := nil.
   106         currentStroke := nil.
    91         self updateButtonStates.
   107         self updateButtonStates.
       
   108         self redrawStrokes.
       
   109         strokeAction notNil ifTrue:[
       
   110             strokeAction value:strokes.
       
   111         ]
    92     ].
   112     ].
    93 ! !
   113 ! !
    94 
   114 
    95 !StrokeView methodsFor:'initialization'!
   115 !StrokeView methodsFor:'initialization'!
    96 
   116 
   100     ].
   120     ].
   101 !
   121 !
   102 
   122 
   103 initialize
   123 initialize
   104     super initialize.
   124     super initialize.
       
   125 
       
   126     self viewBackground:Color black.
   105 
   127 
   106     strokes := OrderedCollection new.
   128     strokes := OrderedCollection new.
   107 
   129 
   108     clearButton := self newButton2D.
   130     clearButton := self newButton2D.
   109     clearButton label:'Clear'.
   131     clearButton label:'Clear'.
   146     ^ button
   168     ^ button
   147 !
   169 !
   148 
   170 
   149 redraw
   171 redraw
   150     self clear.
   172     self clear.
       
   173     self redrawStrokes.
       
   174 !
       
   175 
       
   176 redrawStrokes
       
   177     self paint:Color cyan.
   151     strokes do:[:eachStroke |
   178     strokes do:[:eachStroke |
   152         self drawStroke:eachStroke
   179         self drawStroke:eachStroke
   153     ].
   180     ].
       
   181 
       
   182     self paint:Color yellow.
   154     currentStroke notNil ifTrue:[
   183     currentStroke notNil ifTrue:[
   155         self drawStroke:currentStroke
   184         self drawStroke:currentStroke
   156     ].
   185     ].
   157 ! !
   186 ! !
   158 
   187 
   159 !StrokeView class methodsFor:'documentation'!
   188 !StrokeView class methodsFor:'documentation'!
   160 
   189 
   161 version
   190 version
   162     ^ '$Header: /cvs/stx/stx/libwidg2/StrokeView.st,v 1.2 2004-02-27 17:24:31 cg Exp $'
   191     ^ '$Header: /cvs/stx/stx/libwidg2/StrokeView.st,v 1.3 2004-03-02 08:44:45 cg Exp $'
   163 ! !
   192 ! !