[etoys-dev] Etoys Inbox: Morphic-wiz.31.mcz

commits at source.squeak.org commits at source.squeak.org
Tue Aug 10 02:28:53 EDT 2010


A new version of Morphic was added to project Etoys Inbox:
http://source.squeak.org/etoysinbox/Morphic-wiz.31.mcz

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

Name: Morphic-wiz.31
Author: wiz
Time: 10 August 2010, 2:27:13 am
UUID: 894f301a-0694-4dbe-9dd9-782a648fac1d
Ancestors: Morphic-bf.30

Okay. This is for the targeting changes.

This needs to be loaded second. 

This adds the underlying methods to allow aquiring targets by sighting them with the cursor.

It adds a targetPoint method to handMorph that is needed in some places that were mistakenly using handMorph targetOffset. 

It also patches up the set target methods for MenuMorph and SimpleButtonMorph

The addCustomMenuItems:toHand: method for the above classes was updated to include targetsighting.

for sketchMorph and movie morph the insertIntoMovieMethod is patched.

In all of these cases the patch is to substitute evt targetPoint for evt hand targetOffset. 

For Morph>>addPaintingItemsTo: aMenu hand: aHandMorph

Karl has already changed the method so I simply reverted to his method from the change set then reapplied the patch to use aHandMorph targetPoint instead of target offset.

The text of the changeset follows:
"Change Set:		targetOffsetFixes-wiz
Date:			5 June 2007
Author:			(wiz) Jerome Peace

wiz 6/6/2007 23:41 6/6/2007 23:41

filed in the button and menu targetsighting fixes. 
This stuff needs to be checked and fleshed out.
Todo: #sightWorldTargets: has no senders yet it is very important. (and possibly should replace #sightTargets:).
Check to see if Morph level #target: backup is in place. 



wiz 6/5/2007 22:44

added fix for tilted target.

wiz 6/5/2007 21:15

added target cursor in targeting


wiz 6/5/2007 20:53

adjusted #setTarget: to refer to evt targetPoint instead of evt hand targetPoint. 

wiz 6/5/2007 20:48

added target cursor to cursor class.

added Point class>>fromUserWithCursor:


wiz 6/5/2007 20:22

Compilation of fixes for 3.8 (as of update 0556)
This first is just the fixes from the changeset below. Mostly changes targetOffset (when misused) to targetPoint.





Change Set:		TargetOffsetFix-wiz
Date:			4 December 2006
Author:			(wiz) Jerome Peace

wiz 12/4/2006 00:43

Second fix up the offending senders.

wiz 12/4/2006 00:12

Start repairs for targetOffset misuse.
Mantis #5567.

First add targetPoint to HandMorph.

"


=============== Diff against Morphic-bf.30 ===============

Item was added:
+ ----- Method: SimpleButtonMorph>>addTargetingMenuItems:hand: (in category 'menu') -----
+ addTargetingMenuItems: aCustomMenu hand: aHandMorph 
+ 	"Add targeting menu items"
+ 	aCustomMenu addLine.
+ 
+ 	aCustomMenu add: 'set target' translated action: #targetWith:.
+ 	aCustomMenu add: 'sight target' translated action: #sightTargets:.
+ 	target
+ 		ifNotNil: [aCustomMenu add: 'clear target' translated action: #clearTarget]!

Item was added:
+ ----- Method: SimpleButtonMorph>>clearTarget (in category 'menu') -----
+ clearTarget
+ 
+ 	target _ nil.
+ !

Item was changed:
  ----- Method: MovieMorph>>addCustomMenuItems:hand: (in category 'menu') -----
  addCustomMenuItems: aCustomMenu hand: aHandMorph
  
  	| movies subMenu |
  	super addCustomMenuItems: aCustomMenu hand: aHandMorph.
  	aCustomMenu addLine.
  	subMenu _ MenuMorph new defaultTarget: self.
  	frameList size > 1 ifTrue: [
  		subMenu add: 'repaint' translated action: #editDrawing.
  		subMenu add: 'set rotation center' translated action: #setRotationCenter.
  		subMenu add: 'play once' translated action: #playOnce.
  		subMenu add: 'play loop' translated action: #playLoop.
  		subMenu add: 'stop playing' translated action: #stopPlaying.
  		currentFrameIndex > 1 ifTrue: [
  			subMenu add: 'previous frame' translated action: #previousFrame].
  		currentFrameIndex < frameList size ifTrue: [
  			subMenu add: 'next frame' translated action: #nextFrame]].
  	subMenu add: 'extract this frame' translated action: #extractFrame:.
  	movies _
+ 		(self world rootMorphsAt: aHandMorph targetPoint)
- 		(self world rootMorphsAt: aHandMorph targetOffset)
  			select: [:m | (m isKindOf: MovieMorph) or:
  						[m isSketchMorph]].
  	(movies size > 1) ifTrue:
  		[subMenu add: 'insert into movie' translated action: #insertIntoMovie:].
  	aCustomMenu add: 'movie...' translated subMenu: subMenu
  !

Item was added:
+ ----- Method: Morph>>sightWorldTargets: (in category 'meta-actions') -----
+ sightWorldTargets: event 
+ 	"Return the potential targets for the receiver.  
+ 	This is derived from Morph>>potentialEmbeddingTargets."
+ 	| bullseye myWorld |
+ 	myWorld := self world
+ 		ifNil: [^ #()].
+ 	bullseye := Point fromUserWithCursor: Cursor target.
+ 	self targetFromMenu: ( myWorld morphsAt: bullseye) asKnownNameMenu popupAt: bullseye!

Item was changed:
  ----- Method: MovieMorph>>insertIntoMovie: (in category 'menu') -----
  insertIntoMovie: evt
  
  	| movies aTarget |
  	movies _
+ 		(self world rootMorphsAt: evt  targetPoint)
- 		(self world rootMorphsAt: evt hand targetOffset)
  			select: [:m | ((m isKindOf: MovieMorph) or:
  						 [m isSketchMorph]) and: [m ~= self]].
  	movies isEmpty ifTrue: [^ self].
  	aTarget _ movies first.
  	(aTarget isSketchMorph) ifTrue:
  		[aTarget _ aTarget replaceSelfWithMovie].
  	movies first insertFrames: frameList.
  	self delete.
  !

Item was added:
+ ----- Method: HandMorph>>targetPoint (in category 'accessing') -----
+ targetPoint
+ 	"Return the new position of the target.
+ 	I.E. return the position of the hand less 
+ 	the original distance between hand and target position"
+ 
+ 	^ self position - targetOffset
+ !

Item was added:
+ ----- Method: MenuMorph>>updateItemsWithTarget:orWithHand: (in category 'menu') -----
+ updateItemsWithTarget: aTarget orWithHand: aHand
+ 	"re-target all existing items"
+ 	self items do: 
+ 			[:item | 
+ 			item target isHandMorph 
+ 				ifTrue: [item target: aHand]
+ 				ifFalse: [item target: aTarget]]!

Item was changed:
  ----- Method: PasteUpMorph>>paintArea (in category 'world state') -----
  paintArea
+ 	"What rectangle should the user be allowed to create a new painting in??
+ 	An area beside the paintBox. Allow playArea to override with its own
+ 	bounds!! "
- 	"What rectangle should the user be allowed to create a new painting in??  An area beside the paintBox.  Allow playArea to override with its own bounds!!  "
- 
  	| playfield paintBoxBounds |
+ 	playfield := self
+ 				submorphNamed: 'playfield'
+ 				ifNone: [].
+ 	playfield
+ 		ifNotNil: [^ playfield bounds].
+ 	paintBoxBounds := self paintBox bounds.
+ 	self firstHand targetPoint x < paintBoxBounds center x
+ 		ifTrue: [^ bounds topLeft corner: paintBoxBounds left @ bounds bottom"paint on left side"]
+ 		ifFalse: [^ paintBoxBounds right @ bounds top corner: bounds bottomRight]!
- 	playfield _ self submorphNamed: 'playfield' ifNone: [nil].
- 	playfield ifNotNil: [^ playfield bounds].
- 
- 	paintBoxBounds _ self paintBox bounds.
- 	self firstHand targetOffset x < paintBoxBounds center x
- 		ifTrue: [^ bounds topLeft corner: paintBoxBounds left at bounds bottom]   "paint on left side"
- 		ifFalse: [^ paintBoxBounds right at bounds top corner: bounds bottomRight].  "paint on right side"
- !

Item was added:
+ ----- Method: Morph>>targetWith: (in category 'meta-actions') -----
+ targetWith: evt
+ 	"Some other morph become target of the receiver"
+ 	|  menu newTarget |
+ 	menu _ CustomMenu new.
+ 	self potentialTargets  do: [:m | 
+ 		menu add: (m knownName ifNil:[m class name asString]) action: m].
+ 	newTarget _ menu startUpWithCaption: ( self externalName, ' targets...').
+ 	newTarget ifNil:[^self].
+ 	self target: newTarget.!

Item was changed:
  ----- Method: SketchMorph>>insertIntoMovie: (in category 'menu') -----
  insertIntoMovie: evt
  
  	| movies aTarget |
  	movies _
+ 		(self world rootMorphsAt: evt  targetPoint)
- 		(self world rootMorphsAt: evt hand targetOffset)
  			select: [:m | ((m isKindOf: MovieMorph) or:
  						 [m isSketchMorph]) and: [m ~= self]].
  	movies isEmpty ifTrue: [^ self].
  	aTarget _ movies first.
  	(aTarget isSketchMorph) ifTrue: [
  		aTarget _ aTarget replaceSelfWithMovie].
  	aTarget insertFrames: (Array with: self).
  	self delete.
  !

Item was added:
+ ----- Method: CustomMenu>>startUpWithCaption:at: (in category '*Morphic-invocation') -----
+ startUpWithCaption: caption at: aPoint 
+ 	"Build and invoke this menu with no initial selection. Answer the  
+ 	selection associated with the menu item chosen by the user or nil if  
+ 	none is chosen; use the provided caption"
+ 	^ self startUp: nil withCaption: caption at: aPoint!

Item was added:
+ ----- Method: MenuMorph>>target: (in category 'menu') -----
+ target: aMorph
+ "Set defaultTarget since thats what we got.
+ For the sake of targetSighting which assumes #target is a word we know."
+ 
+ defaultTarget := aMorph!

Item was changed:
  ----- Method: MenuMorph>>setTarget: (in category 'menu') -----
  setTarget: evt 
  	"Set the default target object to be used for add item commands, and re-target all existing items to the new target or the the invoking hand."
  
+ 	| oldDefaultTarget |
+ 	oldDefaultTarget := defaultTarget .
+ 	self sightTargets: evt. 
+ 	oldDefaultTarget ~~ defaultTarget 
+ 		ifTrue: [self updateItemsWithTarget: defaultTarget orWithHand: evt hand ].
+ 	!
- 	| rootMorphs old |
- 	rootMorphs := self world rootMorphsAt: evt hand targetOffset.
- 	rootMorphs size > 1 
- 		ifTrue: [defaultTarget := rootMorphs second]
- 		ifFalse: [^self].
- 	"re-target all existing items"
- 	self items do: 
- 			[:item | 
- 			old := item target.
- 			old isHandMorph 
- 				ifTrue: [item target: evt hand]
- 				ifFalse: [item target: defaultTarget]]!

Item was added:
+ ----- Method: CustomMenu>>startUp:withCaption:at: (in category '*Morphic-invocation') -----
+ startUp: initialSelection withCaption: caption at: aPoint 
+ 	"Build and invoke this menu with the given initial selection and caption. 
+ 	Answer the selection associated with the menu item chosen by the user 
+ 	or nil if none is chosen."
+ 	self build.
+ 	initialSelection notNil
+ 		ifTrue: [self preSelect: initialSelection].
+ 	^ super startUpWithCaption: caption at: aPoint!

Item was changed:
  ----- Method: SimpleButtonMorph>>addCustomMenuItems:hand: (in category 'menu') -----
  addCustomMenuItems: aCustomMenu hand: aHandMorph
  
  	super addCustomMenuItems: aCustomMenu hand: aHandMorph.
  	self addLabelItemsTo: aCustomMenu hand: aHandMorph.
  	(target isKindOf: BookMorph)
  		ifTrue:
  			[aCustomMenu add: 'set page sound' translated action: #setPageSound:.
  			aCustomMenu add: 'set page visual' translated action: #setPageVisual:]
  		ifFalse:
  			[aCustomMenu add: 'change action selector' translated action: #setActionSelector.
  			aCustomMenu add: 'change arguments' translated action: #setArguments.
  			aCustomMenu add: 'change when to act' translated action: #setActWhen.
+ 			self addTargetingMenuItems: aCustomMenu hand: aHandMorph .].
- 			aCustomMenu add: 'change target' translated action: #setTarget.
- 			((self world rootMorphsAt: aHandMorph targetOffset) size > 1) ifTrue:
- 				[aCustomMenu add: 'set target' translated action: #setTarget:]].
  !

Item was added:
+ ----- Method: Morph>>targetFromMenu: (in category 'meta-actions') -----
+ targetFromMenu: aMenu 
+ 	"Some other morph become target of the receiver"
+ 	| newTarget |
+ 	
+ 	newTarget := aMenu startUpWithCaption: self externalName , ' targets...'.
+ 	newTarget
+ 		ifNil: [^ self].
+ 	self target: newTarget!

Item was changed:
  ----- Method: SimpleButtonMorph>>setTarget: (in category 'menu') -----
  setTarget: evt 
  	| rootMorphs |
+ 	rootMorphs := self world rootMorphsAt: evt  targetPoint.
+ 	target := rootMorphs size > 1
+ 				ifTrue: [rootMorphs second]!
- 	rootMorphs := self world rootMorphsAt: evt hand targetOffset.
- 	target := rootMorphs size > 1 
- 		ifTrue: [rootMorphs second]
- 		ifFalse: [nil]!

Item was added:
+ ----- Method: Morph>>potentialTargets (in category 'meta-actions') -----
+ potentialTargets
+ 	"Return the potential targets for the receiver.
+ 	This is derived from Morph>>potentialEmbeddingTargets."
+ 	owner ifNil:[^#()].
+ 	^owner morphsAt: self referencePosition behind: self unlocked: true not!

Item was changed:
  ----- Method: Morph>>addPaintingItemsTo:hand: (in category 'menus') -----
  addPaintingItemsTo: aMenu hand: aHandMorph
  	"Add items relating to the painting subsystem to the given menu"
  
  	| subMenu movies |
  	subMenu _ MenuMorph new defaultTarget: self.
  
  	subMenu addTranslatedList: #(
  		('repaint' editDrawing)
  	"	('set form by grabbing from screen' setFormByGrabbingFromScreen)"
  		-
  		('set rotation center' setRotationCenter)
  		('reset forward-direction' resetForwardDirection)
  		('set rotation style' setRotationStyle)
  		-
  		('erase pixels of color' erasePixelsOfColor:)
  		('recolor pixels of color' recolorPixelsOfColor:)
  		('reduce color palette' reduceColorPalette:)
  		-
  		('add a border around this shape...' addBorderToShape:)
  		('restore original aspect ratio' restoreOriginalAspectRatio)) translatedNoop.
  
  	movies _
+ 		(self world rootMorphsAt: aHandMorph targetPoint)
- 		(self world rootMorphsAt: aHandMorph targetOffset)
  			select: [:m | (m isKindOf: MovieMorph) or:
  						[m isSketchMorph]].
  	(movies size > 1) ifTrue:
  		[subMenu add: 'insert into movie' translatedNoop action: #insertIntoMovie:].
  	aMenu add: 'painting...' translated subMenu: subMenu!

Item was added:
+ ----- Method: Morph>>targetFromMenu:popupAt: (in category 'meta-actions') -----
+ targetFromMenu: aMenu popupAt: aPoint 
+ 	"Some other morph become target of the receiver"
+ 	| newTarget |
+ 	newTarget := aMenu startUpWithCaption: self externalName , ' targets... '
+ 	at: aPoint .
+ 	"self halt ."
+ 	newTarget
+ 		ifNil: [^ self].
+ 	self target: newTarget!

Item was added:
+ ----- Method: Morph>>sightTargets: (in category 'meta-actions') -----
+ sightTargets: event 
+ 	"Return the potential targets for the receiver.  
+ 	This is derived from Morph>>potentialEmbeddingTargets."
+ 	| bullseye |
+ 	owner
+ 		ifNil: [^ #()].
+ 	bullseye := Point fromUserWithCursor: Cursor target.
+ 	self targetFromMenu: (self potentialTargetsAt: bullseye) asKnownNameMenu popupAt: bullseye!

Item was added:
+ ----- Method: Morph>>potentialTargetsAt: (in category 'meta-actions') -----
+ potentialTargetsAt: aPoint 
+ 	"Return the potential targets for the receiver.  
+ 	This is derived from Morph>>potentialEmbeddingTargets."
+ 	| realOwner |
+ 	realOwner := self topRendererOrSelf
+ 	owner
+ 		ifNil: [^ #()].
+ 	^ realOwner
+ 		morphsAt: aPoint
+ 		!

Item was added:
+ ----- Method: Collection>>asKnownNameMenu (in category '*Morphic-objectMenu') -----
+ asKnownNameMenu
+ 	"Return a menu to select an element of the collection.  
+ 	Menu uses the knownName or class name as only description of  
+ 	element."
+ 	| menu |
+ 	menu := CustomMenu new.
+ 	self
+ 		do: [:m | menu
+ 				add: (m knownName
+ 						ifNil: [m class name asString])
+ 				action: m].
+ 	^ menu!



More information about the etoys-dev mailing list