object DrawSurface is components: Drawing*; operations: AddDrawing, RemoveDrawing; end DrawSurface; operation AddDrawing inputs: dr:Drawing, ds:DrawSurface; outputs: ds':DrawSurface; precondition: (* * *); postcondition: (* * The given Drawing is added to the end of the list of Drawings in the * given DrawSurface. The order of other items in the list is unchanged. *) ds' = ds + dr; description: (* AddDrawing adds the given Drawing to the given DrawSurface, producing an updated DrawSurface with the Drawing at the end of its Drawing list. When the DrawSurface is displayed on the screen, Drawing objects are drawn in the order they appear in the list, resulting in objects near the end of the list being drawn over objects near the beginning. *); end AddDrawing; operation RemoveDrawing inputs: dr:Drawing, ds:DrawSurface; outputs: ds':DrawSurface; precondition: (* * The given Drawing is in the DrawSurface *) dr in ds; postcondition: (* * The given Drawing is removed from the list of Drawings in the given * DrawSurface. The order of other items in the list is unchanged. *) ds' = ds - dr; description: (* RemoveDrawing removes the given drawing from the given DrawSurface, producing an updated DrawSurface. *); end RemoveDrawing; operation ClearDrawSurface inputs: ds:DrawSurface; outputs: ds':DrawSurface; precondition: (* * *); postcondition: (* * All Drawings are removed from the given DrawSurface. *) #ds' = 0; description: (* ClearDrawSurface removes all drawings from the given DrawSurface. *); end ClearDrawSurface; object Drawing is components: center:Point and bounds:Rect and col:Color and highlight:boolean and thick:Thickness and (Line* or Rect or Ellipse or Text) and User; operations: MoveDrawing, ResizeDrawing, ChangeDrawingThickness, ChangeDrawingColor, ChangeHighlight; description: (* A Drawing is composed of a color, thickness, and one of several shapes. It also contains a reference to the User who created it. *); end Drawing; operation MoveDrawing inputs: dr:Drawing, move:Point; outputs: dr':Drawing; precondition: (* * *); postcondition: (* * The Drawing's center has been moved by the given amount *) dr'.center.x = dr.center.x + move.x and dr'.center.y = dr.center.y + move.y; description: (* MoveDrawing moves the given drawing by the given move vector, producing an updated drawing. *); end MoveDrawing; operation ResizeDrawing inputs: dr:Drawing, w:integer, h:integer; outputs: dr':Drawing; precondition: (* * *); postcondition: (* * The Drawing's bounding box's width and height have been changed to the * given width and height *) dr'.bounds.w = w and dr'.bounds.h = h; description: (* MoveDrawing moves the given drawing by the given move vector, producing an updated drawing. *); end ResizeDrawing; operation ChangeDrawingThickness inputs: dr:Drawing, t:Thickness; outputs: dr':Drawing; precondition: (* * *); postcondition: (* * The Drawing's thickness has been changed to the given thickness *) dr'.thick = t; description: (* ChangeDrawingThickness changes the thickness of the given drawing, producing an updated drawing *); end ChangeDrawingThickness; operation ChangeDrawingColor inputs: dr:Drawing, c:Color; outputs: dr':Drawing; precondition: (* * *); postcondition: (* * The Drawing's color has been changed to the given color. *) dr'.col = c; description: (* ChangeDrawingColor changes the color of the given drawing, producing an updated drawing *); end ChangeDrawingColor; operation ChangeHighlight inputs: dr:Drawing, h:boolean; outputs: dr':Drawing; precondition: (* * *); postcondition: (* * The Drawing's Highlighter boolean will be set to the given highlighter * boolean. *) dr'.highlight = h; description: (* ChangeIsHighlighter changes whether the drawing is a "highlighter", meaning its color has a predefined alpha component less than 1. *); end ChangeHighlight; object Color is components: red:integer, green:integer, blue:integer, alpha:integer; end Color; object Thickness is integer; object Line is components: point1:Point, point2:Point; end Line; object Rect is components: diagonal:Line, w:integer, h:integer; end Rect; object Ellipse; object Text is string; object Point is components: x:integer, y:integer; end Point;