home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TPPAN.ZIP / PANSCROL.INT < prev    next >
Encoding:
Text File  |  1990-05-10  |  8.2 KB  |  231 lines

  1. {
  2.  
  3.     PanScrol.pas
  4.     5-10-90
  5.     Generic panner-scroller object
  6.  
  7.     Copyright 1990
  8.     John W. Small
  9.     All rights reserved
  10.  
  11.     PSW / Power SoftWare
  12.     P.O. Box 10072
  13.     McLean, Virginia 22102 8072
  14.     (703) 759-3838
  15.  
  16.     The PanScroller object can be used in form editors,
  17.     text editors, pick lists, data browsers, game-map
  18.     browsers etc.  Several design tradeoffs were made to
  19.     facilitate ease of use and maintainability while
  20.     retaining reasonable execution speed.  If speed is
  21.     not sufficient than study and use the code of the
  22.     PanScroller object to cookbook your own.  If code
  23.     size needs to be crunched than do likewise.  Don't
  24.     be too hasty; remember, Turbo Pascal has a smart
  25.     linker and besides if the PanScroller object is
  26.     used in several places in your application, e.g.
  27.     editor, browser, etc, than the code space savings
  28.     would be substantial over your own "crunched" code
  29.     replicated in various places.  The typical complex
  30.     application will consume only about 3 kbytes total.
  31.     I personally got tired of rewriting this type of
  32.     code with every application so I wrote the
  33.     PanScroller object.
  34.  
  35.     The PanScroller maintains a cursor and window on an
  36.     image.  The cursor can be made to drag the window,
  37.     the window can be made to drag the cursor, or both
  38.     can be moved independently.  You control this behavior
  39.     with the boolean variables DragWindow and DragCursor.
  40.     The defaults are both true!  If you set DragWindow to
  41.     true, call DragWindowToCursor immediately.  If you set
  42.     DragCursor to true, call DragCursorToWindow immediately.
  43.  
  44.     VerticalScroll and HorizonalScroll, control how far the
  45.     window is moved    whenever the cursor is walked off the
  46.     window when DragWindow is true.  Their defaults are 1.
  47.     PageRows and PageColumns specify how far the "page"
  48.     methods    move the cursor and/or window.  They can range
  49.     from 1 to 1 less than the window dimensions.
  50.     ImageOverViewRows and ImageOverViewColumns let the
  51.     window view past the edges of the image.  This is
  52.     necessary in writing editors.  In browsers you don't
  53.     want the window to move beyond the edges of the image.
  54.     The defaults for both are 0.  If you modify any of the
  55.     variables mentioned in this paragraph, call
  56.     ValidateOthers before calling any other PanScroller
  57.     method.
  58.  
  59.     After calling PanScroller methods, your application
  60.     should test both the UpdateWindow and UpdateCursor
  61.     boolean variables.  If UpdateWindow is true, your
  62.     application should refresh the window and reset
  63.     UpdateWindow to false.  If UpdateCursor is true, your
  64.     application should refresh the cursor and reset
  65.     UpdateCursor to false.  Whenever the cursor is moved,
  66.     UpdateCursor is set to true whether or not it is in
  67.     the window.  This is because the new cursor location
  68.     may need to be acted upon in some manner.  Call
  69.     the CursorInWindow method to determine if the the
  70.     cursor is visible.  If DragWindow is true, you can be
  71.     sure the cursor is visible where ever it is moved.  Be
  72.     careful, if the window is moved instead of the cursor,
  73.     the cursor will only be guaranteed to be visible if
  74.     DragCursor is true!  When guaranteed visible, the
  75.     cursor's window coordinates are stored in
  76.     CursorWindowRow and CursorWindowColumn. Calling the
  77.     CursorInWindow method guarantees the cursor's window
  78.     coordinates are up to date regardless of DragWindow and
  79.     DragCursor settings.  If the cursor is not visible, its
  80.     window coordinates will be (0,0).  Don't worry too much
  81.     about this since most of the time DragWindow and
  82.     DragCursor are both true (defaults) and the cursor is
  83.     guaranteed to be visible.  Only in more complicated
  84.     applications will you need an independent cursor and
  85.     window.
  86.  
  87.     RowWrap and ColumnWrap allow the cursor to wrap around
  88.     to the next row or column respectively.  If ImageWrap
  89.     is true also then the cursor will wrap around between
  90.     the upper lefthand and lower righthand of the image
  91.     area.  The defaults are RowWrap: true, ColumnWrap and
  92.     ImageWrap: false.
  93.  
  94.     LinearRowTrueColumnFalse allows the Linear/RC
  95.     conversion methods to determine whether an image laid
  96.     out in a linear fashion is in row or column order.
  97.     The default is true which means row order.
  98.  
  99.     The user defined variables are there for you to use
  100.     any way you want.  It saves some time in deriving a
  101.     new object.
  102.  
  103.  
  104. }
  105.  
  106. unit PanScrol;
  107.  
  108. interface
  109.  
  110.     type
  111.  
  112.         PanScroller = object
  113.         { public: read only }
  114.             ImageRows, ImageColumns,
  115.             WindowRows, WindowColumns,
  116.             WindowStartRow, WindowStartColumn,
  117.             WindowEndRow, WindowEndColumn,
  118.             CursorImageRow, CursorImageColumn,
  119.             CursorWindowRow, CursorWindowColumn,
  120.         { public, call ValidateOthers if modified: }
  121.             VerticalScroll, HorizonalScroll,
  122.             PageRows, PageColumns,
  123.             ImageOverViewRows,
  124.             ImageOverViewColumns : word;
  125.         { public: }
  126.             { Wrap to adjacent rows and/or columns. }
  127.             RowWrap, ColumnWrap, ImageWrap : boolean;
  128.             { If you set true, call DragWindowToCursor. }
  129.             DragWindow,
  130.             { If you set true, call DragCursorToWindow. }
  131.             DragCursor,
  132.             { If true, refresh window and set to false. }
  133.             UpdateWindow,
  134.             { If true, refresh cursor and set to false. }
  135.             UpdateCursor : boolean;
  136.             { For linear position methods. }
  137.             LinearRowTrueColumnFalse : boolean;
  138.             { User defined: }
  139.             ScreenStartRow, ScreenStartColumn,
  140.             ScreenRowHeight, ScreenColumnWidth,
  141.             LastCursorWindowRow,
  142.             LastCursorWindowColumn : word;
  143.             constructor init(irows, icols,
  144.                             wrows, wcols: word);
  145.             procedure ResizeImage(irows, icols : word);
  146.             procedure ResizeWindow(wrows, wcols : word);
  147.             procedure CursorRight;
  148.             procedure CursorLeft;
  149.             procedure CursorDown;
  150.             procedure CursorUp;
  151.             procedure CursorPgDown;
  152.             procedure CursorPgUp;
  153.             procedure CursorPgRight;
  154.             procedure CursorPgLeft;
  155.             procedure CursorImageTop;
  156.             procedure CursorImageBottom;
  157.             procedure CursorImageLeft;
  158.             procedure CursorImageRight;
  159.             procedure CursorWindowTop;
  160.             procedure CursorWindowBottom;
  161.             procedure CursorWindowLeft;
  162.             procedure CursorWindowRight;
  163.             procedure CenterCursorInWindow;
  164.             procedure DragCursorToWindow;
  165.             procedure CursorRC(r,c: word);
  166.             procedure CursorRCFrom(
  167.                         LinearPosition : longint);
  168.             function  CursorLinearPosition : longint;
  169.             function  CursorInWindow : boolean;
  170.             procedure ValidateCursor;    { private }
  171.             { Put cursor at (c,r) and view (x1,y1,x2,y2). }
  172.             { Region is validated to be viewable. }
  173.             { Cursor is validated to be in region. }
  174.             procedure ViewRegion(r,c,x1,y1,x2,y2: word);
  175.             function  RowsToEOW : word;
  176.             function  ColumnsToEOW : word;
  177.             procedure WindowDown;
  178.             procedure WindowUp;
  179.             procedure WindowRight;
  180.             procedure WindowLeft;
  181.             procedure WindowPgDown;
  182.             procedure WindowPgUp;
  183.             procedure WindowPgRight;
  184.             procedure WindowPgLeft;
  185.             procedure WindowImageTop;
  186.             procedure WindowImageBottom;
  187.             procedure WindowImageLeft;
  188.             procedure WindowImageRight;
  189.             procedure WindowCursorTop;
  190.             procedure WindowCursorBottom;
  191.             procedure WindowCursorLeft;
  192.             procedure WindowCursorRight;
  193.             procedure CenterWindowOnCursor;
  194.             procedure DragWindowToCursor;
  195.             procedure WindowStartRC(r,c: word);
  196.             procedure WindowStartRCFrom(
  197.                         LinearPosition : longint);
  198.             function  WindowStartLinearPosition : longint;
  199.             procedure ValidateWindow; { private }
  200.             procedure ValidateOthers;
  201.             destructor done;
  202.         end;
  203.  
  204. implementation
  205.  
  206. constructor PanScroller.init(irows, icols,
  207.                 wrows, wcols: word);
  208.     begin
  209.         if irows = 0 then irows := 1;
  210.         if icols = 0 then icols := 1;
  211.         if wrows = 0 then wrows := 1;
  212.         if wcols = 0 then wcols := 1;
  213.         ImageRows := irows; ImageColumns := icols;
  214.         WindowRows := wrows; WindowColumns := wcols;
  215.         WindowStartRow := 1; WindowStartColumn := 1;
  216.         WindowEndRow := WindowRows;
  217.         WindowEndColumn := WindowColumns;
  218.         CursorImageRow := 1; CursorImageColumn := 1;
  219.         CursorWindowRow := 1; CursorWindowColumn := 1;
  220.         VerticalScroll := 1; HorizonalScroll := 1;
  221.         PageRows := wrows - 1; PageColumns := wcols - 1;
  222.         ImageOverViewRows := 0;
  223.         ImageOverViewColumns := 0;
  224.         RowWrap := true;
  225.         ColumnWrap := false;
  226.         ImageWrap := false;
  227.         DragWindow := true; DragCursor := true;
  228.         UpdateWindow := true; UpdateCursor := true;
  229.         LinearRowTrueColumnFalse := true
  230.     end;
  231.