The Inbox: Morphic-tpr.1057.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Morphic-tpr.1057.mcz

commits-2
tim Rowledge uploaded a new version of Morphic to project The Inbox:
http://source.squeak.org/inbox/Morphic-tpr.1057.mcz

==================== Summary ====================

Name: Morphic-tpr.1057
Author: tpr
Time: 7 December 2015, 8:24:53.359 pm
UUID: c685257b-5ee7-49b3-a6b7-5255f28cd47f
Ancestors: Morphic-dtl.1056

Add the STWCPW version of cursor gridding to HandMorph.
It may very well be better to add two instance variables rather than use a couple of properties to hold the state.
There may well be other methods needing changes.
To use:
start by sending gridTo: grid origin: origin to the hand
any subsequent temporaryCursor... will be forced to screeen co-ordinates that are on grid sized steps with an offset of the origin.
gridPointRaw provides the frid limited position of the current hand. Older events are *not* gridded - this is one of the places where there may be more to do.

=============== Diff against Morphic-dtl.1056 ===============

Item was added:
+ ----- Method: HandMorph>>gridPointRaw (in category 'gridded cursor') -----
+ gridPointRaw
+ "return my latest position gridded"
+ ^self griddedPoint: self currentEvent position!

Item was added:
+ ----- Method: HandMorph>>gridTo:origin: (in category 'gridded cursor') -----
+ gridTo: grid origin: offset
+ "set a couple of properties to specify gridding for the temporaryCursor; instvars would be nicer"
+ self setProperty: #gridStep toValue: grid;
+ setProperty: #gridOffset toValue: offset!

Item was added:
+ ----- Method: HandMorph>>griddedPoint: (in category 'gridded cursor') -----
+ griddedPoint: aPoint
+ "return the equivalent point snapped to the grid, if indeed any gridding is set"
+ self valueOfProperty: #gridStep ifPresentDo: [:grid| |offset|
+ offset := self valueOfProperty: #gridOffset ifAbsent: [0@0].
+ ^ offset + (aPoint + (grid //2) - offset truncateTo: grid)].
+ ^aPoint!

Item was changed:
  ----- Method: HandMorph>>position: (in category 'geometry') -----
  position: aPoint
  "Overridden to align submorph origins to the grid if gridding is on."
  | adjustedPosition delta box |
  adjustedPosition := aPoint.
+ temporaryCursor ifNotNil: [adjustedPosition := (self griddedPoint: adjustedPosition) + temporaryCursorOffset].
- temporaryCursor ifNotNil: [adjustedPosition := adjustedPosition + temporaryCursorOffset].
 
  "Copied from Morph to avoid owner layoutChanged"
  "Change the position of this morph and and all of its submorphs."
  delta := adjustedPosition - bounds topLeft.
  delta isZero ifTrue: [^ self].  "Null change"
  box := self fullBounds.
  (delta dotProduct: delta) > 100 ifTrue:[
  "e.g., more than 10 pixels moved"
  self invalidRect: box.
  self invalidRect: (box translateBy: delta).
  ] ifFalse:[
  self invalidRect: (box merge: (box translateBy: delta)).
  ].
  self privateFullMoveBy: delta.
  !

Item was added:
+ ----- Method: HandMorph>>turnOffGridding (in category 'gridded cursor') -----
+ turnOffGridding
+ "remove the gridding properties to stop gridding"
+ self removeProperty: #gridStep; removeProperty: #gridOffset!