Home Segments Index Top Previous Next

669: Mainline

Now, it is time for you to learn how to take advantage of the information provided by various methods inherited by Window instances, so that you can produce more sophisticated drawings.

For example, you can obtain the width and height values of a MeterGraphPane instance by sending the width and height messages.

With the width and height variable values in hand, you can arrange for the horizontal line to fill out the window and stay centered, even as you move, or change the size of, the window. And while you are at it, you can add a short, pointerlike vertical line, 10 pixels long, emerging from the middle of the horizontal line:

MeterGraphPane method definition • instance 
drawMeter 
  | thePen meterWidth xLft yBot | 
  meterWidth := self width * 3 // 4. 
  xLft := self width - meterWidth // 2. 
  yBot := self height // 2. 
  thePen := self pen. 
  thePen lineFrom: xLft @ yBot to: (xLft + meterWidth) @ yBot. 
  thePen lineFrom: (xLft + (meterWidth // 2)) @ yBot 
               to: (xLft + (meterWidth // 2)) @ (yBot - 10).