home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / smalltk / src / graphics.st < prev    next >
Text File  |  1991-10-12  |  2KB  |  103 lines

  1. *
  2. *    graphics support routines
  3. *    used by the standard windows version
  4. *    requires basic routines
  5. *    written by tim budd, January 1989
  6. *
  7. Class Point Magnitude x y
  8. Class Rectangle Object top left bottom right
  9. Class Circle Object center radius
  10. *
  11. Methods Number 'point'
  12.     @ v
  13.         ^ Point new; x: self; y: v
  14. ]
  15. Methods Object 'testing'
  16.     isPoint
  17.         ^ false
  18. ]
  19. Methods Point 'all'
  20.     <= aPoint
  21.         ^ (x <= aPoint x) and: [y <= aPoint y]
  22. |
  23.     = aPoint
  24.         aPoint isPoint
  25.             ifTrue: [ ^ (x = aPoint x) and: [y = aPoint y] ]
  26.             ifFalse: [ ^ false ]
  27. |
  28.     + v
  29.         v isPoint
  30.             ifTrue: [ ^ Point new; x: x + v x; y: y + v y ]
  31.             ifFalse: [ ^ Point new; x: x + v; y: y + v]
  32. |
  33.     - v
  34.         v isPoint
  35.             ifTrue: [ ^ Point new; x: x - v x; y: y - v y ]
  36.             ifFalse: [ ^ Point new; x: x - v; y: y - v]
  37. |
  38.     * v
  39.         ^ Point new; x: x * v; y: y * v
  40. |
  41.     printString
  42.         ^ x printString , '@', y printString
  43. |
  44.     isPoint
  45.         ^ true
  46. |
  47.     size: aPoint
  48.         ^ self to: self + aPoint
  49. |
  50.     to: aPoint
  51.         " return a rectangle with the given dimensions "
  52.         ^ Rectangle new; upperLeft: self; bottomRight: aPoint
  53. |
  54.     radius: n
  55.         ^ Circle new; center: self; radius: n
  56. |
  57.     x: v
  58.         x <- v
  59. |
  60.     y: v
  61.         y <- v
  62. |
  63.     x
  64.         ^ x
  65. |
  66.     y
  67.         ^ y
  68. ]
  69. Methods Rectangle 'all'
  70.     + v
  71.         ^ Rectangle new; bottomRight: right@bottom + v;
  72.             upperLeft: left@top + v
  73. |
  74.     - v
  75.         ^ Rectangle new; bottomRight: right@bottom - v;
  76.             upperLeft: left@top - v
  77. |
  78.     bottomRight: aPoint
  79.         right <- aPoint x.
  80.         bottom <- aPoint y.
  81. |
  82.     contains: aPoint
  83.         ^ aPoint between: left@top and: right@bottom
  84. |
  85.     upperLeft: aPoint
  86.         left <- aPoint x.
  87.         top <- aPoint y.
  88. |
  89.     inset: aPoint
  90.         self upperLeft: left@top + aPoint.
  91.         self bottomRight: right@bottom - aPoint
  92. |
  93.     printString
  94.         ^ ((left@top) printString) , ':', ((right@bottom) printString)
  95. ]
  96. Methods Circle 'all'
  97.     center: c
  98.         center <- c
  99. |
  100.     radius: r
  101.         radius <- r
  102. ]
  103.