home *** CD-ROM | disk | FTP | other *** search
- {
-
- PanScrol.pas
- 5-10-90
- Generic panner-scroller object
-
- Copyright 1990
- John W. Small
- All rights reserved
-
- PSW / Power SoftWare
- P.O. Box 10072
- McLean, Virginia 22102 8072
- (703) 759-3838
-
- The PanScroller object can be used in form editors,
- text editors, pick lists, data browsers, game-map
- browsers etc. Several design tradeoffs were made to
- facilitate ease of use and maintainability while
- retaining reasonable execution speed. If speed is
- not sufficient than study and use the code of the
- PanScroller object to cookbook your own. If code
- size needs to be crunched than do likewise. Don't
- be too hasty; remember, Turbo Pascal has a smart
- linker and besides if the PanScroller object is
- used in several places in your application, e.g.
- editor, browser, etc, than the code space savings
- would be substantial over your own "crunched" code
- replicated in various places. The typical complex
- application will consume only about 3 kbytes total.
- I personally got tired of rewriting this type of
- code with every application so I wrote the
- PanScroller object.
-
- The PanScroller maintains a cursor and window on an
- image. The cursor can be made to drag the window,
- the window can be made to drag the cursor, or both
- can be moved independently. You control this behavior
- with the boolean variables DragWindow and DragCursor.
- The defaults are both true! If you set DragWindow to
- true, call DragWindowToCursor immediately. If you set
- DragCursor to true, call DragCursorToWindow immediately.
-
- VerticalScroll and HorizonalScroll, control how far the
- window is moved whenever the cursor is walked off the
- window when DragWindow is true. Their defaults are 1.
- PageRows and PageColumns specify how far the "page"
- methods move the cursor and/or window. They can range
- from 1 to 1 less than the window dimensions.
- ImageOverViewRows and ImageOverViewColumns let the
- window view past the edges of the image. This is
- necessary in writing editors. In browsers you don't
- want the window to move beyond the edges of the image.
- The defaults for both are 0. If you modify any of the
- variables mentioned in this paragraph, call
- ValidateOthers before calling any other PanScroller
- method.
-
- After calling PanScroller methods, your application
- should test both the UpdateWindow and UpdateCursor
- boolean variables. If UpdateWindow is true, your
- application should refresh the window and reset
- UpdateWindow to false. If UpdateCursor is true, your
- application should refresh the cursor and reset
- UpdateCursor to false. Whenever the cursor is moved,
- UpdateCursor is set to true whether or not it is in
- the window. This is because the new cursor location
- may need to be acted upon in some manner. Call
- the CursorInWindow method to determine if the the
- cursor is visible. If DragWindow is true, you can be
- sure the cursor is visible where ever it is moved. Be
- careful, if the window is moved instead of the cursor,
- the cursor will only be guaranteed to be visible if
- DragCursor is true! When guaranteed visible, the
- cursor's window coordinates are stored in
- CursorWindowRow and CursorWindowColumn. Calling the
- CursorInWindow method guarantees the cursor's window
- coordinates are up to date regardless of DragWindow and
- DragCursor settings. If the cursor is not visible, its
- window coordinates will be (0,0). Don't worry too much
- about this since most of the time DragWindow and
- DragCursor are both true (defaults) and the cursor is
- guaranteed to be visible. Only in more complicated
- applications will you need an independent cursor and
- window.
-
- RowWrap and ColumnWrap allow the cursor to wrap around
- to the next row or column respectively. If ImageWrap
- is true also then the cursor will wrap around between
- the upper lefthand and lower righthand of the image
- area. The defaults are RowWrap: true, ColumnWrap and
- ImageWrap: false.
-
- LinearRowTrueColumnFalse allows the Linear/RC
- conversion methods to determine whether an image laid
- out in a linear fashion is in row or column order.
- The default is true which means row order.
-
- The user defined variables are there for you to use
- any way you want. It saves some time in deriving a
- new object.
-
-
- }
-
- unit PanScrol;
-
- interface
-
- type
-
- PanScroller = object
- { public: read only }
- ImageRows, ImageColumns,
- WindowRows, WindowColumns,
- WindowStartRow, WindowStartColumn,
- WindowEndRow, WindowEndColumn,
- CursorImageRow, CursorImageColumn,
- CursorWindowRow, CursorWindowColumn,
- { public, call ValidateOthers if modified: }
- VerticalScroll, HorizonalScroll,
- PageRows, PageColumns,
- ImageOverViewRows,
- ImageOverViewColumns : word;
- { public: }
- { Wrap to adjacent rows and/or columns. }
- RowWrap, ColumnWrap, ImageWrap : boolean;
- { If you set true, call DragWindowToCursor. }
- DragWindow,
- { If you set true, call DragCursorToWindow. }
- DragCursor,
- { If true, refresh window and set to false. }
- UpdateWindow,
- { If true, refresh cursor and set to false. }
- UpdateCursor : boolean;
- { For linear position methods. }
- LinearRowTrueColumnFalse : boolean;
- { User defined: }
- ScreenStartRow, ScreenStartColumn,
- ScreenRowHeight, ScreenColumnWidth,
- LastCursorWindowRow,
- LastCursorWindowColumn : word;
- constructor init(irows, icols,
- wrows, wcols: word);
- procedure ResizeImage(irows, icols : word);
- procedure ResizeWindow(wrows, wcols : word);
- procedure CursorRight;
- procedure CursorLeft;
- procedure CursorDown;
- procedure CursorUp;
- procedure CursorPgDown;
- procedure CursorPgUp;
- procedure CursorPgRight;
- procedure CursorPgLeft;
- procedure CursorImageTop;
- procedure CursorImageBottom;
- procedure CursorImageLeft;
- procedure CursorImageRight;
- procedure CursorWindowTop;
- procedure CursorWindowBottom;
- procedure CursorWindowLeft;
- procedure CursorWindowRight;
- procedure CenterCursorInWindow;
- procedure DragCursorToWindow;
- procedure CursorRC(r,c: word);
- procedure CursorRCFrom(
- LinearPosition : longint);
- function CursorLinearPosition : longint;
- function CursorInWindow : boolean;
- procedure ValidateCursor; { private }
- { Put cursor at (c,r) and view (x1,y1,x2,y2). }
- { Region is validated to be viewable. }
- { Cursor is validated to be in region. }
- procedure ViewRegion(r,c,x1,y1,x2,y2: word);
- function RowsToEOW : word;
- function ColumnsToEOW : word;
- procedure WindowDown;
- procedure WindowUp;
- procedure WindowRight;
- procedure WindowLeft;
- procedure WindowPgDown;
- procedure WindowPgUp;
- procedure WindowPgRight;
- procedure WindowPgLeft;
- procedure WindowImageTop;
- procedure WindowImageBottom;
- procedure WindowImageLeft;
- procedure WindowImageRight;
- procedure WindowCursorTop;
- procedure WindowCursorBottom;
- procedure WindowCursorLeft;
- procedure WindowCursorRight;
- procedure CenterWindowOnCursor;
- procedure DragWindowToCursor;
- procedure WindowStartRC(r,c: word);
- procedure WindowStartRCFrom(
- LinearPosition : longint);
- function WindowStartLinearPosition : longint;
- procedure ValidateWindow; { private }
- procedure ValidateOthers;
- destructor done;
- end;
-
- implementation
-
- constructor PanScroller.init(irows, icols,
- wrows, wcols: word);
- begin
- if irows = 0 then irows := 1;
- if icols = 0 then icols := 1;
- if wrows = 0 then wrows := 1;
- if wcols = 0 then wcols := 1;
- ImageRows := irows; ImageColumns := icols;
- WindowRows := wrows; WindowColumns := wcols;
- WindowStartRow := 1; WindowStartColumn := 1;
- WindowEndRow := WindowRows;
- WindowEndColumn := WindowColumns;
- CursorImageRow := 1; CursorImageColumn := 1;
- CursorWindowRow := 1; CursorWindowColumn := 1;
- VerticalScroll := 1; HorizonalScroll := 1;
- PageRows := wrows - 1; PageColumns := wcols - 1;
- ImageOverViewRows := 0;
- ImageOverViewColumns := 0;
- RowWrap := true;
- ColumnWrap := false;
- ImageWrap := false;
- DragWindow := true; DragCursor := true;
- UpdateWindow := true; UpdateCursor := true;
- LinearRowTrueColumnFalse := true
- end;