[squeak-dev] The Inbox: Morphic-tcj.1482.mcz

Levente Uzonyi leves at caesar.elte.hu
Sun Mar 3 03:03:13 UTC 2019


On Sat, 2 Mar 2019, commits at source.squeak.org wrote:

> A new version of Morphic was added to project The Inbox:
> http://source.squeak.org/inbox/Morphic-tcj.1482.mcz
>
> ==================== Summary ====================
>
> Name: Morphic-tcj.1482
> Author: tcj
> Time: 2 March 2019, 3:35:41.130915 pm
> UUID: 78f4a7bc-b74c-408c-bbd9-4729d1d8404e
> Ancestors: Morphic-ul.1481
>
> Add a menu item to copy a SketchMorph's form as code, thus allowing it to be easily reproduced elsewhere.
>
> =============== Diff against Morphic-ul.1481 ===============
>
> Item was changed:
>  ----- Method: Morph>>addPaintingItemsTo:hand: (in category 'menus') -----
>  addPaintingItemsTo: aMenu hand: aHandMorph
>  	| subMenu movies |
>  	subMenu := MenuMorph new defaultTarget: self.
>  	subMenu
>  		add: 'repaint' translated action: #editDrawing;
>  		add: 'set rotation center' translated action: #setRotationCenter;
>  		add: 'reset forward-direction' translated action: #resetForwardDirection;
>  		add: 'set rotation style' translated action: #setRotationStyle;
>  		add: 'erase pixels of color' translated action: #erasePixelsUsing:;
>  		add: 'recolor pixels of color' translated action: #recolorPixelsUsing:;
> + 		add: 'copy as code' translated action: #copyAsCode;
>  		add: 'reduce color palette' translated action: #reduceColorPalette:;
>  		add: 'detect edges' translated action: #edgeDetect;
>  		add: 'sharpen' translated action: #sharpen;
>  		add: 'blur' translated action: #blur;
>  		add: 'emboss' translated action: #emboss;
>  		add: 'add a border around this shape...' translated action: #addBorderToShape:.
>  	movies := (self world rootMorphsAt: aHandMorph targetPoint)
>  				select: [:m | (m isKindOf: MovieMorph) or: [m isSketchMorph]].
>  	movies size > 1
>  		ifTrue:
>  			[subMenu add: 'insert into movie' translated action: #insertIntoMovie:].
>  	aMenu add: 'painting...' translated subMenu: subMenu!
>
> Item was added:
> + ----- Method: SketchMorph>>copyAsCode (in category 'menu') -----
> + copyAsCode
> + 	| s | 
> + 	"Copy a textual representation of my form to the clipboard, which can be used to easily recreate it. 
> + 	Choosing to reduce colors can create a much smaller string."
> + 	s := String new writeStream.
> + 	( ( self confirm: 'reduce colors?' )
> + 		ifTrue: [ self form colorReduced ]
> + 		ifFalse: [ self form ] ) storeOn: s.
> + 	Clipboard clipboardText: s close contents.

There's no need to handle streaming here. Using #storeString directly is 
probably more legible:

| form |
form := self form.
(self confirm: 'reduce colors?') ifTrue: [
 	form := form colorReduced ].
Clipboard clipboardText: form storeString

I would even remove the question and always send #colorReduced as it will 
return the original form if there are more than 256 colors in use. That 
way the method body can be written as:

Clipboard clipboardText: self form colorReduced storeString


Levente

> + 	!


More information about the Squeak-dev mailing list