[GOODIE] selecting multiple morphs, kanji fun

Bolot Kerimbaev bolot at cc.gatech.edu
Wed Nov 17 06:15:10 UTC 1999


Have you ever needed to be able to select a bunch of morphs on your desktop?
I first created the functionality, then came up with the situation.
Situation first:

I wanted to import some images of kanji characters, but ones I got off the
web had white background (with exception of color words, which had the
corresponding color bg). So I wanted to mass convert them to be transparent.
I ran the following code:

| slash dir image transparent black dirName |
"read all gif images, make all colors, except black, transparent, open as a
SketchMorph - like from FileList menu"
slash _ FileDirectory slash.
black _ Color r:0 g:0 b: 0.
dirName _ (FileDirectory default pathName), slash, 'kanji', slash,
'matrix_kanji', slash.
dir _ FileDirectory on: dirName.
dir fileNames withIndexDo: [:fname :fid |
 (fname asLowercase endsWith: '.gif')
  ifTrue: [image _ GIFReadWriter formFromFileNamed: dirName, fname.
   transparent _ (image colors select: [:c | c isTransparent]) first.
   image colors withIndexDo: [:c :i |
    (c isTransparent not and: [(c = black) not])
     ifTrue: [image colors at: i put: transparent]].
   World addMorph: (image _ SketchMorph new form: image).
   image position: (fid*10)@(fid*10)]].

And it created a ton (about 30) of sketch morphs. It worked. But! Now I had
a bunch of morphs I had to delete one by one... Here came handy the "select
multiple morphs" utility.

It's available at:
http://fce.cc.gatech.edu/~bolot/squeak/productivity/DragNDropMorph.Nov11.st

Open a new morph, it'll prompt you to select a portion of the screen
(Rectangle fromUser), then all morphs within those bounds and that belong to
the PasteUpMorph will become children of this DragNDropMorph. You can move
it anywhere you want (or delete it), then from its menu "drop n paste",
which will delete it and leave its submorphs on the screen(*).

Bolot
(*) the paste up morph is determined by the position of the first click. The
paste up morph target is the owner of the DragNDrop morph.





More information about the Squeak-dev mailing list