GUI (Graphical User Interface)
GUI (Graphical User Interface)
The dimension/location for the window is expressed with another class called a Rect. More shortly.
Drawing On A Window
• The class Window has an instance method .drawFunc that is used when
the window is refreshed to draw objects on the screen.
• The objects are drawn with a class called Pen, which has numerous class
methods that can draw all sorts of figures (termed paths) on the window.
• Pen has two very important class methods: .fill and .stroke.
• .fill -> fills the object with the color specified by Pen.color (black, by default)
• .stroke -> outlines the object with a border specified by Pen.width
• If you fail to use either of these methods, then nothing will be displayed on your
screen!
• Note: there are some class methods which handle this for you. Be sure to read the
documentation.
• When objects are placed on a window or any subcontainer in a window,
coordinates are relative to the upper left corner of the window. Positive y-
coordinates go down.
Rect
• Rectangles are some of the simplest figures we can draw but also are
useful as a way of expressing dimensions for other GUI objects.
• Rectangles take four arguments:
• 1st argument: left -> expresses how far from the left the rectangle should be
placed.
• 2nd argument: top -> expresses how far from the top the rectangle should be
placed.
• 3rd argument: width
• 4th argument: height
• When placing rectangles in windows or other GUI objects, these
coordinates are relative to the upper-left corner.
Simple Drawing Code
// Draw a rectangle
// Coordinates are relative to the upperleft corner of the window
~r1 = Rect(100, 100, 80, 30);
w.drawFunc = {
Pen.addRect(~r1); // A path for a rectangle
Pen.width = 3;
Pen.stroke; // Add a stroke (i.e., border) to most recent path
};
w.refresh; // Need to redraw the window