[Pkg] The Trunk: Morphic-kfr.1019.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Oct 29 12:09:34 UTC 2015


Karl Ramberg uploaded a new version of Morphic to project The Trunk:
http://source.squeak.org/trunk/Morphic-kfr.1019.mcz

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

Name: Morphic-kfr.1019
Author: kfr
Time: 27 October 2015, 5:21:35.825 pm
UUID: 440773d3-8bad-4232-b989-60c0a6dfb1f0
Ancestors: Morphic-mt.1018

Adds a GradientEditor for morphic

=============== Diff against Morphic-mt.1018 ===============

Item was added:
+ RectangleMorph subclass: #GradientDisplayMorph
+ 	instanceVariableNames: ''
+ 	classVariableNames: ''
+ 	poolDictionaries: ''
+ 	category: 'Morphic-Widgets'!

Item was added:
+ ----- Method: GradientDisplayMorph>>colorRamp (in category 'as yet unclassified') -----
+ colorRamp
+ 	^self fillStyle colorRamp!

Item was added:
+ ----- Method: GradientDisplayMorph>>colorRamp: (in category 'as yet unclassified') -----
+ colorRamp: aColorRamp
+ 	self fillStyle colorRamp: aColorRamp!

Item was added:
+ ----- Method: GradientDisplayMorph>>drawOn: (in category 'as yet unclassified') -----
+ drawOn: aCanvas 
+ 	"Draw a hatch pattern first."
+ 	aCanvas
+ 		fillRectangle: self innerBounds
+ 		fillStyle: (InfiniteForm with: ColorPresenterMorph hatchForm).
+ 	super drawOn: aCanvas!

Item was added:
+ ----- Method: GradientDisplayMorph>>initialize (in category 'as yet unclassified') -----
+ initialize
+ 	| fill colorRamp |
+ 	super initialize.
+ 	"self hResizing: #spaceFill. "
+ 	colorRamp := {0.0 -> Color green. 0.3 -> Color red. 0.7 -> Color black. 1.0 -> Color blue}.
+ 	fill := GradientFillStyle ramp: colorRamp.
+ 	fill origin: 0 at 0.
+ 	fill direction: self bounds extent x @ 0.
+ 	fill radial: false.
+ 	self fillStyle: fill!

Item was added:
+ RectangleMorph subclass: #GradientEditor
+ 	instanceVariableNames: 'gradientDisplay rampMorphs selectedSketch gradientMorph row text target selector morph'
+ 	classVariableNames: ''
+ 	poolDictionaries: ''
+ 	category: 'Morphic-Widgets'!

Item was added:
+ ----- Method: GradientEditor class>>on:selector:forMorph:colorRamp: (in category 'as yet unclassified') -----
+ on: aTarget selector: aSelector forMorph: aMorph colorRamp: aColorRamp
+ 	^self new 
+ 		setTarget: aTarget
+ 		selector: aSelector
+ 		forMorph: aMorph
+ 		colorRamp: aColorRamp.
+ 		
+ !

Item was added:
+ ----- Method: GradientEditor>>addButtonRow (in category 'initialization') -----
+ addButtonRow
+ 	| button button2 buttonRow button4 |
+ 	buttonRow := RectangleMorph new extent: self width @ 30;
+ 	borderWidth: 0; color: Color transparent.
+ 	buttonRow layoutPolicy: TableLayout new;
+ 		 cellPositioning: #center;
+ 		 listCentering: #topLeft;
+ 		 listDirection: #LeftToRight;
+ 		 reverseTableCells: true;
+ 		 cellInset: 20 @ 20.
+ 
+ 	button := SimpleButtonMorph new target: self;
+ 				 label: 'Add color';
+ 				 actionSelector: #addHandle.
+ 	buttonRow  addMorph: button.
+ 
+ 	button2 := SimpleButtonMorph new target: self;
+ 				 label: 'Remove color';
+ 				 actionSelector: #deleteHandle.
+ 	buttonRow addMorph: button2.
+ 
+ 	button4 := SimpleButtonMorph new target: self;
+ 				 label: 'Close';
+ 				 actionSelector: #delete.
+ 	buttonRow addMorph: button4.
+ 	
+ 	self addMorph: buttonRow!

Item was added:
+ ----- Method: GradientEditor>>addHandle (in category 'change reporting') -----
+ addHandle
+ 	| handleInstance colorIcon |
+ 	handleInstance := self handle.
+ 	colorIcon := SketchMorph
+ 						withForm: ((Color random value iconOrThumbnailOfSize: 20) borderWidth: 1 color: Color black)..
+ 	self eventHandler: colorIcon target: colorIcon.
+ 	self eventHandler: handleInstance target: self.
+ 	row addMorph: handleInstance.
+ 	handleInstance position: gradientDisplay left - 10 + (gradientDisplay width // 2) @ (gradientDisplay top - 18).
+ 	handleInstance addMorph: colorIcon.
+ 	rampMorphs addLast: handleInstance.
+ 	colorIcon position: gradientDisplay left - 10 + (gradientDisplay width // 2) @ (gradientDisplay bottom + 5).
+ 	self updateColorRamp!

Item was added:
+ ----- Method: GradientEditor>>addHandles (in category 'initialization') -----
+ addHandles
+ 	| handle handleInstance colorIcon colorRamp |
+ 	rampMorphs := OrderedCollection new.
+ 	colorRamp := self gradientDisplay colorRamp asOrderedCollection.
+ 	handle := self handle.
+ 	colorRamp
+ 		do: [:i | 
+ 			colorIcon := SketchMorph
+ 						withForm: ((i value iconOrThumbnailOfSize: 20) borderWidth: 1 color: Color black)..
+ 			self eventHandler: colorIcon target: colorIcon.
+ 			handleInstance := handle copy.
+ 			self eventHandler: handleInstance target: self.
+ 			row addMorph: handleInstance.
+ 			handleInstance position: gradientDisplay left - 10 + (gradientDisplay width * i key) @ (gradientDisplay top - 18).
+ 			handleInstance addMorph: colorIcon.
+ 			rampMorphs addLast: handleInstance.
+ 			colorIcon position: gradientDisplay left - 10 + (gradientDisplay width * i key) @ (gradientDisplay bottom + 5)].
+ 	self changed.!

Item was added:
+ ----- Method: GradientEditor>>changeColor:event:target: (in category 'change reporting') -----
+ changeColor: aSketchMorph event: evt target: aMorph
+ 	| newColor |
+ 	newColor := aSketchMorph rotatedForm colorAt: aSketchMorph rotatedForm center.
+ 	selectedSketch := aSketchMorph.
+  	self changeColorTarget: self selector: #updateColor: originalColor: newColor value hand: evt hand.
+ 	!

Item was added:
+ ----- Method: GradientEditor>>colorRamp (in category 'accessing') -----
+ colorRamp
+ 	| i string |
+ 	string := gradientDisplay fillStyle colorRamp asOrderedCollection printString.
+ 	i := string indexOf:$(.
+  	^string copyFrom: i to: string size!

Item was added:
+ ----- Method: GradientEditor>>colorRamp: (in category 'accessing') -----
+ colorRamp: aColorRamp
+ 	
+ 	"rampMorphs do:[ :i | rampMorphs remove:i.  row removeMorph: i . ].
+       self changed."
+ 	gradientDisplay colorRamp: aColorRamp.
+ 	self addHandles.
+ !

Item was added:
+ ----- Method: GradientEditor>>deleteHandle (in category 'change reporting') -----
+ deleteHandle
+ 	rampMorphs do:[ :i | (i color == Color red) ifTrue:[ rampMorphs remove: i. row removeMorph: i]].
+ 	self updateColorRamp
+ 	
+ !

Item was added:
+ ----- Method: GradientEditor>>eventHandler:target: (in category 'event handling') -----
+ eventHandler: anInstance target: aTarget
+ 		(anInstance isKindOf: SketchMorph)
+ 				ifTrue:[anInstance on: #mouseUp
+ 				send: #changeColor:event:target:
+ 				to: self withValue: aTarget]
+ 				ifFalse:[anInstance on: #mouseDown
+ 				send: #limitHandleMove:event:from:
+ 				to: self withValue: aTarget.
+ 		anInstance on: #mouseMove
+ 				send: #limitHandleMove:event:from:
+ 				to: self withValue: aTarget]!

Item was added:
+ ----- Method: GradientEditor>>gradientDisplay (in category 'accessing') -----
+ gradientDisplay
+ 	^gradientDisplay!

Item was added:
+ ----- Method: GradientEditor>>handle (in category 'initialization') -----
+ handle
+  | handle |
+ handle := PolygonMorph
+ 				vertices: (Array
+ 						with: 0 @ 0
+ 						with: 16 @ 0
+ 						with: 8 @ 16)
+ 				color: Color gray
+ 				borderWidth: 1
+ 				borderColor: Color black.
+ 	^handle
+ 		addMorph: ((RectangleMorph
+ 				newBounds: (8 @ 18 extent: 1 @ (gradientDisplay height - 2))
+ 				color: Color orange)
+ 				borderWidth: 0).!

Item was added:
+ ----- Method: GradientEditor>>initialize (in category 'initialization') -----
+ initialize
+ 	
+ 	super initialize.
+ 	self myLayout.
+ 	self extent: 600 @ 150.
+ 	row := RectangleMorph new extent: self width @ 100.
+ 
+ 	row addMorph: (gradientDisplay := GradientDisplayMorph new position: 20 @ 20;
+ 					 extent: self width - 40 @ 40).
+ 	gradientDisplay fillStyle direction: gradientDisplay width @ 0.
+ 	"self addHandles."
+ 	self addMorph: row.
+ 	self addButtonRow.
+ 	text := PluggableTextMorph
+ 				on: self
+ 				text: #colorRamp
+ 				accept: nil
+ 				readSelection: nil
+ 				menu: nil.
+ 	text color: Color white;
+ 		 width: self width;
+ 		 height: 50.
+ 	self addMorph: text.
+ 	!

Item was added:
+ ----- Method: GradientEditor>>limitHandleMove:event:from: (in category 'change reporting') -----
+ limitHandleMove: association event: evt from: handle
+ 	| p  newBounds |
+ 	rampMorphs do:[ : i | i color: Color gray].
+ 	newBounds := gradientDisplay bounds.
+ 	newBounds := (newBounds left: (newBounds left - 10)).
+ 	newBounds := (newBounds right: (newBounds right - 10)). 
+ 	p := evt cursorPoint adhereTo: newBounds.
+ 	handle position: (p x )@ (handle position y).
+ 	handle color: Color red.
+ 	self updateColorRamp!

Item was added:
+ ----- Method: GradientEditor>>morph: (in category 'accessing') -----
+ morph: aMorph
+ 	^morph := aMorph!

Item was added:
+ ----- Method: GradientEditor>>myLayout (in category 'initialization') -----
+ myLayout
+ 	self layoutPolicy: TableLayout new;
+ 		 hResizing: #shrinkWrap;
+ 		 vResizing: #shrinkWrap;
+ 		 cellPositioning: #center;
+ 		 listCentering: #topLeft;
+ 		 layoutInset: 10 at 10;
+ 		 listDirection: #topToBottom;
+ 		 reverseTableCells: true;
+ 		 wrapCentering: #topLeft;
+ 		 cellInset: 19 @ 10!

Item was added:
+ ----- Method: GradientEditor>>selector: (in category 'accessing') -----
+ selector: aSelector	
+ 	^selector := aSelector!

Item was added:
+ ----- Method: GradientEditor>>setTarget:selector:forMorph:colorRamp: (in category 'initialization') -----
+ setTarget: aTarget selector: aSelector forMorph:aMorph colorRamp: aColorRamp
+ 
+ 	self target: aTarget.
+ 	self selector: aSelector.
+ 	self morph: aMorph.
+ 	self colorRamp: aColorRamp.
+ 	
+ 		!

Item was added:
+ ----- Method: GradientEditor>>target: (in category 'accessing') -----
+ target: aTarget
+ 	^target := aTarget!

Item was added:
+ ----- Method: GradientEditor>>updateColor: (in category 'change reporting') -----
+ updateColor: aColor
+ 	selectedSketch rotatedForm  floodFill: aColor at: selectedSketch rotatedForm center.
+ 	self updateColorRamp
+ !

Item was added:
+ ----- Method: GradientEditor>>updateColorRamp (in category 'change reporting') -----
+ updateColorRamp
+ 	| newAssociation newKey newColor sketch colorRamp |
+ 	
+ 	self updateRampMorphs.
+ 	colorRamp := OrderedCollection new.
+ 	rampMorphs
+ 		do: [:i | 
+ 			newKey := ((i position x - gradientDisplay left / gradientDisplay width) asFloat roundUpTo: 0.01)
+ 						min: 1.0
+ 						max: 0.0.
+ 			sketch := i findA: SketchMorph.
+ 			newColor := sketch rotatedForm colorAt: sketch rotatedForm center.
+ 			newAssociation := newKey -> newColor.
+ 			colorRamp addLast: newAssociation].
+ 	colorRamp := colorRamp sorted.
+ 	gradientDisplay colorRamp: colorRamp.
+ 	gradientDisplay fillStyle direction: gradientDisplay extent x @ 0.
+ 	self changed.
+ 	target ifNotNil:[
+ 			target perform: selector
+ 			with: colorRamp 
+ 			with: morph].
+ 	text setText: self colorRamp!

Item was added:
+ ----- Method: GradientEditor>>updateRampMorphs (in category 'change reporting') -----
+ updateRampMorphs
+ 	rampMorphs do:[ :i | i isInWorld ifFalse:[ rampMorphs remove: i]]!

Item was changed:
  ----- Method: GradientFillStyle>>addFillStyleMenuItems:hand:from: (in category '*Morphic-Balloon') -----
  addFillStyleMenuItems: aMenu hand: aHand from: aMorph
  	"Add the items for changing the current fill style of the receiver"
  	self isRadialFill ifTrue:[
  		aMenu add: 'linear gradient' translated target: self selector: #beLinearGradientIn: argument: aMorph.
  	] ifFalse:[
  		aMenu add: 'radial gradient' translated target: self selector: #beRadialGradientIn: argument: aMorph.
  	].
  	aMenu addLine.
+ 	aMenu add: 'change color ramp' translated target: self selector: #changeColorRampIn:event: argument: aMorph.
- 	aMenu add: 'change first color' translated target: self selector: #changeFirstColorIn:event: argument: aMorph.
- 	aMenu add: 'change second color' translated target: self selector: #changeSecondColorIn:event: argument: aMorph.
  	aMenu addLine.
  	super addFillStyleMenuItems: aMenu hand: aHand from: aMorph.!

Item was added:
+ ----- Method: GradientFillStyle>>changeColorRampIn:event: (in category '*Morphic-Balloon') -----
+ changeColorRampIn: aMorph event: evt
+ 	^self changeColorSelector: #colorRamp:forMorph: hand: evt hand morph: aMorph originalColor:aMorph fillStyle colorRamp!

Item was changed:
  ----- Method: GradientFillStyle>>changeColorSelector:hand:morph:originalColor: (in category '*Morphic-Balloon') -----
  changeColorSelector: aSymbol hand: aHand morph: aMorph originalColor: originalColor 
  	"Change either the firstColor or the lastColor (depending on aSymbol).  Put up a color picker to hande it.  We always use a modal picker so that the user can adjust both colors concurrently."
+ 
+ ^(GradientEditor on: self selector: aSymbol forMorph: aMorph colorRamp: originalColor) openNear: aMorph fullBoundsInWorld. 
+ 
+ 
+ 	"NewColorPickerMorph useIt
- 	NewColorPickerMorph useIt
  		ifTrue:
  			[ (NewColorPickerMorph
  				on: self
  				originalColor: originalColor
  				setColorSelector: aSymbol) openNear: aMorph fullBoundsInWorld ]
  		ifFalse:
  			[ ColorPickerMorph new
  				 initializeModal: false ;
  				 sourceHand: aHand ;
  				 target: self ;
  				 selector: aSymbol ;
  				 argument: aMorph ;
  				 originalColor: originalColor ;
  				
  				putUpFor: aMorph
+ 				near: aMorph fullBoundsInWorld ]"!
- 				near: aMorph fullBoundsInWorld ]!

Item was added:
+ ----- Method: GradientFillStyle>>colorRamp:forMorph: (in category '*Morphic-Balloon') -----
+ colorRamp: aColorRamp forMorph: aMorph 
+ 	colorRamp :=aColorRamp.
+ 	isTranslucent := nil.
+ 	pixelRamp := nil. 
+ 	aMorph changed.!



More information about the Packages mailing list