View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Coding in Squeak Morphic

Coding with Squeak Mophic


Your Options

There are several options available to make a decent Morphic GUI in Squeak.

  1. Hack existing components.

  2. Steal code from cases page.

  3. Use Prefab or a similar package.

Option one is great for custom components. Option two is great if you're lucky and can find decent code from the cases page. The slideshow projects from Summer 2003 is good starting place to do this. Option three should be used for applications that will be fine with standard GUI components.

I assume that most people taking 2340 can probably steal reuse code from the cases page and/or Prefab, this guide will mostly focus on building Morphic components manually.

How Morphic Works

Everything you see in morphic is a morph. To illustrate, invoke halos by right clicking anything you see on screen. Do this the to mouse that stares at you when you start Squeak. Click on the pink X and watches gratifyingly as the it disappears from view. Better yet do this to a random scrollbar on your browser/transcript/workspace window. Once you're tired of random destruction, notice that the pink X is not the only action that you can take. You can also pick up, resize, and move any components. Furthermore you can click on the teal eye and display a scripting box. This is part of the etoys system, drag the objects's properties out to start a script. With enough clicking you can get these things to do just about anything. It's fun to play with if you're bored.

Building Something Useful

Uploaded Image: calendar.jpg

Start by making a copy of your current Squeak image folder. Squeak has a habit of messing itself up once in a while.

To build a GUI, like other languages, you make the individual components of your GUI and add them to a container (usually an instance of SystemWindow, for a window or RectangleMorph for an inner component). Normally, a RectangleMorph is all that you need to subclass from to get most of the benefits of being a morph but without the extra bloat.


Next, override the following methods to get your component to useful things like draw itself and resize.

Here's a list of useful methods in Canvas:


Layouts with Morphic


To tell squeak that your morph accepts keyboard/mouse input override the appropriate "handlesEVENT" method. All this method should really do is return true. Then implement the appropriate method, the method signature is usually EVENT: where the only parameter is an instance of MorphicEvent.

For example, if you want to handle mouse clicks. You'd implement handlesMouseDown and mouseDown:

Links to this Page