Home Segments Index Top Previous Next

673: Mainline

With those instance variables in place, you can incorporate their values into the meter, taking care to draw the pointer and to display the title only if the necessary values have been set. Note that drawMeter now includes an erase message, which ensures that previously drawn lines and text are erased before new lines and text are drawn.

MeterGraphPane method definition • instance 
drawMeter 
  | thePen meterWidth xLft yBot pointer | 
  self erase. 
  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. 
  min notNil & max notNil & value notNil 
    ifTrue: 
      [pointer :=  
        (value - min) * meterWidth // (max - min). 
       thePen lineFrom: (xLft + pointer) @ yBot 
                    to: (xLft + pointer) @ (yBot - 10)]. 
  title notNil 
    ifTrue: 
      [thePen centerText: title 
                      at: ((self width) // 2)  
                            @ ((self height // 2) 
                               + (2 * thePen font height))].