Re: [Pharo-project] Strange logic in PolygonMorph>>fromHand: hand
Indeed is weird. I think it has to explicitly call runStepMethods, because it's not forking , thus taking control of the ui process, does it make sense? I would remove the method (and all the similar ones found in the image, that explicitly reference Sensor and while doing "true whileTrue:[ ...]", if needed it would be have to re-done using the new event model with announcements. Fernando On Sun, May 13, 2012 at 10:20 AM, Stéphane Ducasse <stephane.ducasse@inria.fr> wrote:
Hi
I'm cleaning Sensor use so that we end up with a better layered system. Now I see this method and I wonder (replacing Sensor by hand does not work. But I do not understand why this methods has to explicitly invoke runStepMethods⦠to me it looks like a broken behavior due probably to the lack of a functionality or ticking behavior.
What do you think?
fromHand: hand     "Let the user draw a polygon, clicking at each vertex, and ending         by clicking within 5 of the first point..."     "self fromHand: ActiveHand"
    | p1 poly oldVerts pN opposite |     Cursor crossHair showWhile:         [[Sensor anyButtonPressed] whileFalse:             [self currentWorld displayWorldSafely; runStepMethods].         p1 := Sensor cursorPoint].     opposite := (Display colorAt: p1) negated.     opposite = Color transparent ifTrue: [opposite := Color red].     (poly := LineMorph from: p1 to: p1 color: opposite width: 2) openInWorld.     oldVerts := {p1}.     self currentWorld displayWorldSafely; runStepMethods.     [true] whileTrue:         [[Sensor anyButtonPressed] whileTrue:             [pN := Sensor cursorPoint.             poly setVertices: (oldVerts copyWith: pN).             self currentWorld displayWorldSafely; runStepMethods].         (oldVerts size > 1 and: [(pN dist: p1) < 5]) ifTrue:             [hand position: Sensor cursorPoint.  "Done -- update hand pos"             ^ (poly setVertices: (poly vertices copyWith: p1)) delete].         oldVerts := poly vertices.         [Sensor anyButtonPressed] whileFalse:             [pN := Sensor cursorPoint.             poly setVertices: (oldVerts copyWith: pN).             self currentWorld displayWorldSafely; runStepMethods]].
On May 13, 2012, at 8:32 PM, Fernando Olivero wrote:
Indeed is weird. I think it has to explicitly call runStepMethods, because it's not forking , thus taking control of the ui process, does it make sense?
I would remove the method (and all the similar ones found in the image, that explicitly reference Sensor and while doing "true whileTrue:[ ...]", if needed it would be have to re-done using the new event model with announcements.
:) We completely rewrote it with Igor and there is no runStepMethods and other uglies like that. We should remove the duplicated code :). fromHand: hand "Let the user draw a polygon, clicking at each vertex, and ending by clicking within 5 of the first point..." "self fromHand: ActiveHand" | p1 poly oldVerts pN opposite stop | "wait till guy will press the mouse button" hand captureEventsUntil: [:evt | evt isMouse ifTrue: [ p1 := evt cursorPoint]. (evt isMouse and: [ evt anyButtonPressed ]) not ]. opposite := (Display colorAt: p1) negated. opposite = Color transparent ifTrue: [opposite := Color red]. (poly := LineMorph from: p1 to: p1 color: opposite width: 2) openInWorld. oldVerts := {p1}. [true] whileTrue: [ "wait till button release" hand captureEventsWhile: [:evt | evt isMouse ifTrue: [ pN := evt cursorPoint. poly setVertices: (oldVerts copyWith: pN). evt anyButtonPressed ] ifFalse: [ true ] ]. (oldVerts size > 1 and: [(pN dist: p1) < 5]) ifFalse: [ oldVerts := poly vertices. "loop till button will be pressed" hand captureEventsUntil: [:evt | evt isMouse ifTrue: [ pN := evt cursorPoint. poly setVertices: (oldVerts copyWith: pN). evt anyButtonPressed ] ifFalse: [ false ]]] ifTrue: [ ^ (poly setVertices: (poly vertices copyWith: p1)) delete]. ]
Fernando
On Sun, May 13, 2012 at 10:20 AM, Stéphane Ducasse <stephane.ducasse@inria.fr> wrote:
Hi
I'm cleaning Sensor use so that we end up with a better layered system. Now I see this method and I wonder (replacing Sensor by hand does not work. But I do not understand why this methods has to explicitly invoke runStepMethods⦠to me it looks like a broken behavior due probably to the lack of a functionality or ticking behavior.
What do you think?
fromHand: hand "Let the user draw a polygon, clicking at each vertex, and ending by clicking within 5 of the first point..." "self fromHand: ActiveHand"
| p1 poly oldVerts pN opposite | Cursor crossHair showWhile: [[Sensor anyButtonPressed] whileFalse: [self currentWorld displayWorldSafely; runStepMethods]. p1 := Sensor cursorPoint]. opposite := (Display colorAt: p1) negated. opposite = Color transparent ifTrue: [opposite := Color red]. (poly := LineMorph from: p1 to: p1 color: opposite width: 2) openInWorld. oldVerts := {p1}. self currentWorld displayWorldSafely; runStepMethods. [true] whileTrue: [[Sensor anyButtonPressed] whileTrue: [pN := Sensor cursorPoint. poly setVertices: (oldVerts copyWith: pN). self currentWorld displayWorldSafely; runStepMethods]. (oldVerts size > 1 and: [(pN dist: p1) < 5]) ifTrue: [hand position: Sensor cursorPoint. "Done -- update hand pos" ^ (poly setVertices: (poly vertices copyWith: p1)) delete]. oldVerts := poly vertices. [Sensor anyButtonPressed] whileFalse: [pN := Sensor cursorPoint. poly setVertices: (oldVerts copyWith: pN). self currentWorld displayWorldSafely; runStepMethods]].
participants (2)
-
Fernando Olivero -
Stéphane Ducasse