Version 15 (modified by 9 years ago) ( diff ) | ,
---|
Squeak FAQ - New Version
Documentation
Where do I find good documentation and introductory literature for Squeak/Smalltalk?
In most cases, you do not necessarily need a documentation, because you can search and browse through the entire source code within your Squeak image. Just use the search on the top right to find what you are looking for. The majority of classes also come with class comments that you might find helpful. You can access these by clicking the ?
button between instance
and class
in your browser.
Furthermore, we recommend the following websites:
- Squeak by Example (for more free books visit Stephane Ducasse: Free Books)
Smalltalk Syntax
How do I leave a method without returning a value, e.g. early return?
In Smalltalk ^
behaves similar to return in other languages. If a method in Smalltalk should return nothing, typically you return self
. You should avoid to return nil
.
How do I break inside a loop?
A way to do so is to put the loop into its own method and to add another return. However, you should consider the collection protocol. Usually, there already is a method, that solves your problem. Possible methods could be: #detect:ifFound:ifNone:
or #detect:thenDo:ifNone:
.
Are there abstract classes in Smalltalk and how should I name them?
In Smalltalk a class is abstract when a method is implemented with "self subclassResponsibility". However, you can still create objects of this class, but this method cannot be called. A typically idiom is to extend the name with the word "Abstract". Examples in the image are: AbstractEvent, AbstractFont, or AbstractSound.
Idioms and Patterns
How to I access class variables or methods? Via classname or self class?
I/O
Graphic (Morphic)
How do I repeat an image in the background?
An image can be repeated in the Background using an InfiniteMorph as a morph's fill-style:
aForm := Form fromFileNamed: 'picture.png'. anInfiniteForm := InfiniteForm with: aForm. Morph new extent: 500@500; fillStyle: anInfiniteForm; openInHand.
How do I react on deleting morphs using halos?
If a morph is deleted using the X in the halo menu, Morph>>dismissViaHalo
, Morph>>dismissMorph
, Morph>>delete
are called. If your morph is a subclass of Morph, you can overwrite one of these. Do not forget to call the super implementation.
How do I prevent a Morph from stepping directly after opening?
Morph>>wantsStep
can be overwritten returning false. As a result the morph will not start stepping immediately. Nevertheless, you can start stepping with Morph>>startStepping
later on.
How do I implement a parallax scrolling for background images?
How do I change the size of an image independent from the aspect ratio?
A Form can be scaled using Form>>#magnify:by:smoothing:
. The scale factor can either by a single value or a point to define the scale factor for both height and width.
The following examples shows how to change the size to 100@50 independent from the original aspect ratio:
MenuIcons helpIcon in: [:form | (form magnify: form boundingBox by: (100@50) / form extent smoothing: 1) asMorph openInHand].
How do I insert morphs in the background?
Instead of using addMorph:
you can use the following methods to influence the z-level of morphs:
#addMorph
, addMorphFront:
, #addMorph:behind:
, and #addMorph:inFrontOf:
.
How do I rotate a morph?
To rotate a morph you can create a TransformationMorph around your morph and change the angle using: TransformationMorph>>angle:
aForm := Form fromFileNamed: 'picture.png'. anImageMorph := aForm asMorph. aTransformMorph := TransformationMorph new asFlexOf: anImageMorph. aTransformMorph openInHand. aTransformMorph angle: Float pi/4 negated.
If you want to rotate a local Resource only once at the beginning, you can create a From and rotate it using From>>rotateBy:
You can rotate it later on by creating another rotated copy and exchanging the from of the ImageMorph. However, this is inperformant if used often.
aForm := Form fromFileNamed: 'picture.png'. anImageMorph := aForm asMorph. anImageMorph image: (aForm rotateBy:45 smoothing:10). anImageMorph openInHand. anImageMorph image: (aForm rotateBy:90 smoothing:1).
Sound
Image Concept
Squeak
How do I change the author initials?
For future code changes you can change your author initials via menu as shown in the picture below.