home *** CD-ROM | disk | FTP | other *** search
/ Chestnut's Multimedia Mania / MM_MANIA.ISO / graphics / paintoop / paint.pas < prev    next >
Pascal/Delphi Source File  |  1989-11-16  |  5KB  |  104 lines

  1. {$B-,F-,I+,R+}
  2.  
  3. program Paint;
  4.  
  5. { Turbo Paint graphics and object demonstration program }
  6.  
  7. { Copyright 1989
  8.   Scott Bussinger
  9.   110 South 131st Street
  10.   Tacoma, WA  98444
  11.   (206)531-8944
  12.   Compuserve 72247,2671 }
  13.  
  14. { Here's the complete object hierarchy:
  15.  
  16.   TObject - Ancestor of all object types
  17.     ├── TMouse - Access to mouse hardware
  18.     └── TWindow - A rectangular window on screen
  19.           ├── TDrawingWindow - A window scaled to coordinates of 0.00 to 1.00
  20.           │     └── TPaneWindow - A window with an icon
  21.           │           ├── TColorPane - A pane showing a selectable drawing color
  22.           │           ├── TFillPane - A pane showing a selectable fill mask
  23.           │           ├── TLinePane - A pane showing a selectable line style
  24.           │           ├── TFontPane - A pane showing a selectable text font
  25.           │           ├── TColorStylePane - A pane showing the current drawing color
  26.           │           ├── TFillStylePane - A pane showing the current fill mask
  27.           │           ├── TLineStylePane - A pane showing the current line style
  28.           │           ├── TFontStylePane - A pane showing the current text font
  29.           │           └── TToolPane - A pane showing a selectable drawing tool
  30.           │                 ├── TEraserTool - A tool to clear the drawing window
  31.           │                 ├── TQuitTool - A tool to quit the program
  32.           │                 └── TModalToolPane - Tools that change the current drawing tool
  33.           │                       ├── TPenTool - A freehand drawing tool
  34.           │                       ├── TPaintBucketTool - An area fill tool
  35.           │                       └── TRubberBandToolPane - A tool that shows a rubberband cursor
  36.           │                             ├── TLineTool - A straight line drawing tool
  37.           │                             ├── TCircleTool - A circle drawing tool
  38.           │                             ├── TFilledCircleTool - A circle drawing tool with area fill
  39.           │                             └── TRectangularRubberBandToolPane - A tool that shows a rectangular rubberband cursor
  40.           │                                   ├── TBoxTool - A rectangle drawing tool
  41.           │                                   ├── TFilledBoxTool - A rectangle drawing tool with area fill
  42.           │                                   ├── TEllipseTool - An ellipse drawing tool
  43.           │                                   ├── TFilledEllipseTool - An ellipse drawing tool with area fill
  44.           │                                   └── TTextTool - A text entry tool
  45.           └── TMultipanedWindow - A window made up of an array of smaller panes
  46.                 ├── TColorWindow - A window for choosing the drawing color
  47.                 ├── TFillWindow - A window for choosing the fill mask
  48.                 ├── TLineWindow - A window for choosing the line style
  49.                 ├── TFontWindow - A window for choosing the current font
  50.                 ├── TStyleWindow - A window for showing the current styles
  51.                 └── TToolWindow - A window for choosing the current drawing tool
  52.   }
  53.  
  54. uses Graph,Dos,CObject,CMouse,CWindow,CStyle,CTool;
  55.  
  56. var DrawingWindow: TDrawingWindow;
  57.     StyleWindow: TStyleWindow;
  58.     Tool: TToolPanePtr;
  59.     ToolWindow: TToolWindow;
  60.  
  61. procedure CreateAllWindows;
  62.   { Create all of the windows on the screen }
  63.   begin
  64.   DrawingWindow.Init(true,0.11,0.06,0.99,0.84);
  65.   CurrentCanvas := @DrawingWindow;
  66.   CurrentCanvas^.Clear;                          { Start drawing window in black }
  67.  
  68.   ToolWindow.Init(true,0.005,0.06,0.105,0.66);
  69.  
  70.   StyleWindow.Init(true,0.005,0.70,0.99,0.99);
  71.  
  72.   SetViewport(round(0.11*GetMaxX),0,GetMaxX,round(0.05*GetMaxY),ClipOn); { Display a screen title }
  73.   FitText(Triplex,'Turbo Paint')
  74.   end;
  75.  
  76. begin
  77. CreateAllWindows;                                { Initialize all of the windows for the display }
  78. repeat
  79.   Mouse.Show;                                    { A tight polling loop to keep track of mouse }
  80.   Mouse.Update;
  81.   Tool := TToolPanePtr(ToolWindow.CurrentPane);  { Get current painting tool so we can send messages based on mouse action }
  82.   if Mouse.GetButton(Left) = Idle then           { Let a text tool look at keyboard at every opportunity }
  83.     Tool^.Idle;
  84.   if DrawingWindow.CheckMouse                    { Are we in the big drawing window? }
  85.    then
  86.     begin
  87.     Tool^.SetCursor;                             { Have the tool change to the appropriate cursor shape }
  88.     case Mouse.GetButton(Left) of
  89.       Pressed: Tool^.Anchor;                     { Anchor a tool when the button is first pressed }
  90.       Held: Tool^.Track;                         { Some tools leave a trace after the mouse, or have a rubberband cursor }
  91.       Released: Tool^.Draw                       { Letting go of the mouse button is the final trigger }
  92.       else
  93.       end
  94.     end
  95.    else
  96.     begin
  97.     Tool^.ClearAnchor;                           { We moved outside of the drawing window, so disable any pending tool }
  98.     if not ToolWindow.CheckMouse and             { Check the tool window }
  99.        not StyleWindow.CheckMouse then           { Check the drawing style window }
  100.       Mouse.SetCursor(DefaultCursor)             { Change back to the normal cursor if not in any other window }
  101.     end
  102. until false                                      { Repeat forever (actually until HALT in QuitTool) }
  103. end.
  104.