home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / progrmng / mcbrntls.sit / Draw.Txt (.txt) < prev    next >
Encoding:
Oberon Text  |  1991-02-14  |  13.3 KB  |  119 lines  |  [.Ob./.Ob2]

  1. Syntax10.Scn.Fnt
  2. Syntax20.Scn.Fnt
  3. Syntax12.Scn.Fnt
  4. Syntax12b.Scn.Fnt
  5. Syntax12i.Scn.Fnt
  6. Math12.Scn.Fnt
  7. A Guide to Oberon's Line Drawing System
  8. N. Wirth, 21.7.90 / 18.11.90
  9. Introduction
  10. The system called Draw serves to prepare line drawings. They contain lines, text captions, and other items, and are displayed in graphic viewers (more precisely: in menu viewers' graphic frames). A graphic viewer shows an excerpt of the drawing plane, and several viewers may show different parts of a drawing. The most frequently used commands are built-in as mouse clicks and combinations of clicks. Additional commands are selectable from texts, either in viewer's menus (title bar) or in the text called Draw.Tool. The mouse buttons have the following principal functions;
  11.     left:     draw
  12.     middle:     move/copy
  13.     right:     select 
  14. A mouse command is identified (1) by the key k0 pressed initially, (2) by the initial position P0 of the cursor, (3) by the set of keys k1 of buttons pressed until the last is released, and (4) the cursor position P1 at the time of release.
  15. The basic system consists of the modules Draw, GraphicFrames, and Graphics. These modules contain the facilities to generate and handle horizontal and vertical lines, text captions, and macros. Additional modules serve to introduce other elements, such as rectangles and circles, and the system is extensible, i.e. further modules may be introduced to handle further items.
  16. Basic Commands
  17. The command Draw.Open opens a new viewer and displays the graph with the name given as parameter. If no parameter is specified with the command, the last text selection is taken as parameter. We suggest that file names use the extension Graph.
  18. Drawing a line. In order to draw a horizontal or vertical line from P0 to P1, press the button with the cursor at P0 and, while holding the button, move the mouse and cursor to P1. Then release the button. If P0 and P1differ in both their x and y coordinates, the end point is adjusted so that the line is either horizontal or vertical.
  19. Writing a caption. First place the cursor where the caption is to appear. Then click the left button, causing a crosshair to appear. This is called the caret. Then type the text. Only single line texts are accepted. The DEL key may be used to retract characters (backspace).
  20. Selecting. Most commands require the specification of operands, and many implicitly assume the previously selected elements - the selection - to be their operands. A single element is selected by pointing at it with the cursor and then clicking the right mouse button. This also causes previously seleted elements to be deselected. If their selection is to be retained, also click the left button. This action is called an interclick. If you wish to select several elements at once, move the cursor from P0 to P1 while holding the right key. Then all elements lying within the rectangle with diagonally opposite corners at P0 and P1 are selected. Selected lines are displayed as dotted lines, selected captions (and macros) by inverse video mode. A mocro is selected by pointing at its lower left corner.
  21. Moving. If you wish to move (displace) a set of elements, first select them, and then move the cursor from P0 to P1 while holding the middle button. The vector from P0 to P1 specifies the movement and is called the displacement vector. P0 and P1 may lie in different viewers displaying the same graph.
  22. Copying. Similarly, the selected elements may be copied (duplicated). In addition to pressing the middle button while indicating the displacement vector, interclick the left button. The copy command may also be used to copy elements from one graph into another graph by moving the cursor from one viewer into another viewer displaying the destination graph. A text caption may be copied from a text frame into a graphic frame and vice-versa. There exist two ways to achieve this: 1. First place the caret at the destination position, then select the text and interclick the middle button. 2. First select the text to be copied, then place the caret at the destination point by clicking the left and interclicking the middle button.
  23. Shifting the plane. You may shift the entire drawing plane behind the viewer by specifying a displacement vector pressing the middle button (like in a move command) and interclicking the right button.
  24. Moving and resizing a viewer. A viewer can be enlarged or shrunk by placing the cursor into the title bar and then moving it, while holding the left button to the desired new position. If the viewer is to be moved, additionally interclick the middle button.
  25. The following table shows a summary of the mouse actions:
  26.     interclick:     none    left     middle     right
  27.     primary button
  28.         left     draw line / set caret    -    copy caption    set sec. caret
  29.         middle     move     copy     -    shift plane
  30.         right    select    select     copy caption    -
  31. Menu Commands
  32. The following commands are displayed in the menu (title bar) of every graphic viewer. They are activated by being pointed at and by clicking the middle button.
  33.     System.Close     The viewer is closed.
  34.     System.Copy    A new viewer is opened showing the same drawing.
  35.     System.Grow    The viewer is enlarged to cover the entire track (screen).
  36.     Draw.Cleanup    The entire drawing is repainted.
  37.     Draw.Delete    The selected elements are deleted.
  38.     Draw.Store    The drawing is written as file with the name shown in the title bar. 
  39.         The original file is renamed by changing its extension to Bak.
  40. Further Commands 
  41. The following commands are listed in the text Draw.Tool, but may appear in any text. 
  42.     Draw.Reset     The drawing plane in the marked viewer (*) is reset such that the plane's origin
  43.         lies in the lower left corner. 
  44.     Draw.Store name    The drawing in the marked viewer is stored as a file with the specified name. 
  45.     Draw.Print Servername *   The drawing in the marked viewer is printed by the named print server. 
  46.     Draw.Print Servername {Filename}.  The named files are printed. 
  47.     Draw.SetGrid n     Inside graphic viewers, the cursor moves in discrete steps on an invisible grid.
  48.         The distance between grid points is initially 4 pixels; it can be set by this
  49.         command to 2-n pixels. 
  50.     Draw.CarPos    Displays the numeric coordinates of the caret in the log viewer.
  51. The subsequent commands pertain to attributes of drawing elements, such as line width, text font, and color. The Set-commands determine the respective attributes of subsequently created elements, the Change-commands to those of the current selection in the marked viewer.
  52.     System.SetFont fontname    default = Syntax10.Scn.Fnt
  53.     System.SetColor c     default = white
  54.     Draw.SetWidth w    default = 1,   0 < w < 7.
  55.     Draw.ChangeFont fontname
  56.     Draw.ChangeColor c
  57.     Draw.ChangeWidth w    (0 < w < 7)
  58. The SetColor and ChangeColor commands either take a color number in the range 1 .. 15 or a string as parameter. The latter case serves to select the color from the character immediately following the caret position (see Draw.Tool).
  59. Macros 
  60. A macro is a (small) drawing that can be identified as a whole and be used as an element within a (larger) drawing. Macros are typically stored in collections called libraries, from where they can be selected and copied individually.
  61.     Draw.Macro lib mac    The macro mac is selected from the library named lib and inserted in the
  62.         drawing at the caret's position.
  63.     Draw.LstMacros filename    Lists the macro names contained in the named library file.
  64. Macros are typically used for drawing electronic circuits. The basic library file containing frequently used TTL circuits is called TTL0.Lib, and a drawing showing its elements is called TTL0.Graph.
  65. Rectangles
  66. Rectangles can be created as individual elements and are frequently used as frames around a set of other elements. They consist of four lines which are selectable as a unit. The attribute commands SetWidth, SetColor, ChangeWidth, and ChangeColor also apply to rectangles. Rectangles are selected by pointing at their lower left corner.
  67. Rectangles.New
  68.     1. Place the caret where a corner of the new rectangle is to lie (left button).
  69.     2. Place a secondary caret where the opposite corner is to lie by interclicking the right button.
  70.     3. Activate the command.
  71. Rectangles may be filled with a shade pattern. The shade is specified as a number s (0 # s # 9). 
  72.     Rectangles.SetShade s          default = 0: no shading
  73. Note: In the current implementation, all shades appear as the same pattern on the display but differ on the printer.
  74. Curves 
  75. Further graphic elements are (oblique) lines, circles, and ellipses.
  76. Curves.NewLine
  77.     1. Place the caret where the starting point is to lie. 
  78.     2. Place a secondary caret where the end point is to lie.
  79.     3. Activate the command.
  80. Curves.NewCircle
  81.     1. Place the caret where the center is to lie. 
  82.     2. Place a secondary caret to the right of the center. This position will lie on the circle.
  83.     3. Activate the command.
  84. Curves.NewEllipse
  85.     1. Place the caret where the center is to lie. 
  86.     2. Place a second caret to the right of the center.
  87.     3. Place a third caret above the center.
  88.     4. Activate the command.
  89. Extending the Draw system with additional element classes
  90. Additional element classes may be incorporated by programming further modules which import Graphics. The following notes are a brief guide for the design of such extensions, and module Rectangles is shown as an example. In the following explanations, the reader should have this source available, as well as Graphics.Def.
  91. The data type for the new element class is declared as an extension of Graphics.ObjDesc with fields x, y (position), w (width), h (height), col (color), state (with values normal and selected), and the method field do. A new instance is created by the exported command New. Its position is taken from the caret, namely mark.x and mark.y of the frame descriptor Oberon.FocusViewer.dsc.next. If several coordinates are required, as in the case of rectangles and circles, they are specified by secondary carets. The list of secondary carets is rooted in the field mark.next of the frame descriptor. Further parameters that may be relevant are Graphics.width, Graphics.color, Graphics.fno, and possibly state variables of the new module itself. The field do must be initialized with a (pointer to a) method table, i.e. a record of type Graphics.MethodDesc containing handlers for the following operations:
  92.     copy, draw, selectable, change, write, print
  93. This record is typicall stored in a global variable called method.
  94. In Draw(obj, f, col, x, y, mode), the mode parameter has the following significance:
  95.     mode = 0 :    the object is to be drawn fully, according to the value of obj.state,
  96.     mode = 1 :    the state changes from normal to selected,
  97.     mode = 2 :     the state changes from selected to normal,
  98.     mode = 3 :      the object is to be erased.
  99. Parameters x and y denote a relative offset within frame f.
  100. In Change(obj, msg) the msg parameter specifies the character of the change. It is of the (extensible) type Graphics.ChangeMsg with fields id, k and font:
  101.     id = 0 :    change color to k
  102.     id = 1 :     change width to k
  103.     id = 2 :     change font
  104. Procedure Write(obj, W) is required to contain the first statement Files.Write (W, method.id). Thereafter follow statements to write the values of the extended object record.
  105. Furthermore a method Read must be installed - not in the method table - but through a call of
  106.     Graphics.Install(Read, modname, method.id)
  107. where modname is the name of the module (such as Rectangles, Circles) characterizing the new element class. The format defined by the Write procedure must be followed, of course; however, the first byte, the method-id, has already been read before the call of the Read method.
  108. WriteParcs.Alloc
  109. WriteParcs.Alloc
  110. WriteParcs.Alloc
  111. WriteParcs.Alloc
  112. WriteParcs.Alloc
  113. WriteParcs.Alloc
  114. WriteParcs.Alloc
  115. WriteParcs.Alloc
  116. WriteParcs.Alloc
  117. WriteParcs.Alloc
  118. WriteParcs.Alloc
  119.