Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
Coding in Squeak Morphic
Coding with Squeak Mophic
- Hai Nguyen gtg623h
- Matt Manzel gtg722b
- Harrison Caudill gte042u
- Scott McRae gtg014g
There are several options available to make a decent Morphic GUI in Squeak.
- Hack existing components.
- Steal code from cases page.
- 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
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.
- drawOn: aCanvas - use the canvas object to paint your component, similar
to Java's paint(graphics) component.
- ownerChanged - use this to get your Morph to resize. To get the containing
component's size use "owner width".
Here's a list of useful methods in Canvas:
- drawImage:at: - draw an image
- drawString:at: - draw a given string
- line:to:color: - draw line
- frameRectangle:width:color: - draw a rectangle, useful for rollovers
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
- Andrew Sayman last edited on 24 January 2006 at 12:26 pm by utah-lnx.cc.gatech.edu
- Living the Dream last edited on 25 July 2004 at 10:46 pm by lawn-199-77-206-96.lawn.gatech.edu