Home Segments Index Top Previous Next

683: Mainline

All Smalltalk environments provide many drawing messages. Two of the most useful are the polygon: and the polygonFilled: messages. Both are sent to graphics contexts; both take an array of points, which collectively defines a polygon. In the following, polygon: draws an open rectangle and polygonFilled: draws a filled rectangle.

MeterGraphPane method definition • instance 
drawMeter 
  | thePen rectangleWidth rectangleHeight array1 array2 | 
  rectangleWidth := self width * 1 // 4. 
  rectangleHeight := self height * 1 // 3. 
  array1 := Array with: rectangleWidth @ rectangleHeight 
                  with: (rectangleWidth * 2) @ rectangleHeight 
                  with: (rectangleWidth * 2) @ (rectangleHeight * 2) 
                  with: rectangleWidth @ (rectangleHeight * 2). 
  array2 := Array with: (rectangleWidth * 2) @ rectangleHeight 
                  with: (rectangleWidth * 3) @ rectangleHeight 
                  with: (rectangleWidth * 3) @ (rectangleHeight * 2) 
                  with: (rectangleWidth * 2) @ (rectangleHeight * 2). 
  thePen := self pen. 
  thePen setFillColor: ClrBlack. 
  thePen polygon: array1. 
  thePen polygonFilled: array2. 

The setFillColor: message is essential—it changes the fill color from white to black: