Up: Java Kali Source Code and Documentation

Class KaliCanvas

Class KaliCanvas

java.lang.Object
   |
   +----KaliCanvas

class KaliCanvas
extends Object
An abstract canvas object which serves the purpose of insulating the mathematical part of the program (Panorama object below) from the graphics (DrawPanel object above). The Panorama object does its drawing by making calls to the KaliCanvas object, which in turn translates them into the appropriate graphics calls for drawing on the DrawPanel object.

(It might be more efficient to have the Panorama object make the graphics calls directly, but for now we try it this way.)

Coordinate systems:

Kali uses 3 different coordinate systems for the image in the DrawPanel:

Raw Screen Coordinates
This is the original screen coordinate system of the drawing area, which goes from (0,0) in the upper left to (screenWidth, screenHeight) in the lower right (in pixels). Y increases DOWN in this system.

Mouse events happen in this coordinate system.

Screen Coordinates
This system is the result of translating the raw screen system so that (0,0) is at the center of the screen; so it goes from (-screenWidth/2, -screenHeight/2) in the upper left to (screenWidth/2, screenHeight/2) in the lower right. Y increases DOWN in this system too.

Drawing happens in this coordinate system; the KaliCanvas.setGraphics() method calls g.translate() to move the Graphics object's origin from the upper left (the default) to the center of the screen. Also, the translation computations in the Panorama object happen in this system.

Internal Coordinates
This system goes from (-internalWidth, internalHeight) in the upper left to (internalWidth, -internalHeight) in the lower right; so (0,0) is at the center of the screen. Y increases UP in this system.

The coordinates of drawn segments are stored in this system. Also, the Panorama object does some of the group action math (reflection and rotation) in this system.

Also, in the future, scaling and translation may be implemented by transforming this system.

See Also:
Panorama, DrawPanel

Constructor Index

 o KaliCanvas()

Method Index

 o drawSegment(Segment, Color)
Draw a single line segment.
 o internalToScreen(DVector)
Convert internal coordinates to screen coordinates.
 o rawScreenToInternal(int, int)
Convert raw screen coordinates to internal coordinates.
 o setGraphics(Graphics)
Set the graphics context for future drawing; this results in a new screen coordinate system being computed based on the current size of this graphics context.

Constructors

 o KaliCanvas
  public KaliCanvas()

Methods

 o rawScreenToInternal
  public DVector rawScreenToInternal(int x,
                                     int y)
Convert raw screen coordinates to internal coordinates.
 o internalToScreen
  public DVector internalToScreen(DVector v)
Convert internal coordinates to screen coordinates.
 o setGraphics
  public void setGraphics(Graphics g)
Set the graphics context for future drawing; this results in a new screen coordinate system being computed based on the current size of this graphics context.
 o drawSegment
  public void drawSegment(Segment s,
                          Color c)
Draw a single line segment.


Up: Java Kali Source Code and Documentation

[HOME] The Geometry Center Home Page

Author: Mark Phillips
Comments to: webmaster@geom.umn.edu
Created: Sep 16 1996 --- Last modified: Sep 18 1996