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. + ! |
Hi,
In preparing this, I noticed that #addPaintingItemsTo:hand: lives in Morph but is only sent by SketchMorph. I thought about moving it to SketchMorph, but didn't want to step to far out of what this contribution is meant to achieve. Thanks, Tim ps - thanks to Eliot and Karl for encouragement! > On Mar 2, 2019, at 3:35 PM, [hidden email] 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. > + ! > > > |
In reply to this post by commits-2
On Sat, 2 Mar 2019, [hidden email] 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 > + ! |
Free forum by Nabble | Edit this page |