{Two Panel CheckerBoard Test application for the Tool Kit} { This program has a few enhancements over the one panel version, including optimzing screen updates and mouse dragging within the panels } UNIT UCB2Sample; INTERFACE {$SETC ColHeadings := TRUE} USES {$U UObject} UObject, {$U QuickDraw} QuickDraw, {$U UDraw} UDraw, (* OTHER BUILDING BLOCKS IF WANTED *) {$U UABC} UABC; CONST { Colors } colorWhite = 0; colorLtGray = 1; colorGray = 2; colorDkGray = 3; colorBlack = 4; { Menu commands } uWhite = 1006; uLtGray = 1007; uGray = 1008; uDkGray = 1009; uBlack = 1010; {$IFC ColHeadings} uShowHeads = 1100; uHideHeads = 1101; {$ENDC} { Board Dimensions } numRows = 8; { # rows } numCols = 8; { # cols } boxH = 45; { width of a box } boxV = 30; { height of a box } txMargin = 4; { horizontal space between view and edge of text } { Selection kind } samKind = 1; TYPE { Numbers used in the view to represent the color of a square } TColor = ColorWhite..ColorBlack; { The checkerboard itself } TCheckerboard = SUBCLASS OF TObject {Fields} boxes: ARRAY[1..numrows, 1..numcols] OF TColor; {Creation} FUNCTION {TCheckerboard.}CREATE(object: TObject; heap: THeap): TCheckerboard; {Accessing} PROCEDURE {TCheckerboard.}ColorAlternating(evenColor, oddColor: TColor); { color the checkerboard; boxes with row+col even are made evenColor otherwise oddColor } FUNCTION {TCheckerboard.}GetColor(rowIndex, colIndex: INTEGER): TColor; PROCEDURE {TCheckerboard.}SetColor(rowIndex, colIndex: INTEGER; color: TColor); END; { The "process" controlling this application } TSamProcess = SUBCLASS OF TProcess {Creation} FUNCTION {TSamProcess.}CREATE: TSamProcess; {FUNCTION TSamProcess. NewDocManager(volumePrefix: TFilePath): TDocManager;} END; { Manager of the application's document} TSamDocManager = SUBCLASS OF TDocManager {Creation} FUNCTION {TSamDocManager.}CREATE(object: TObject; heap: THeap; itsPathPrefix: TFilePath): TSamDocManager; {FUNCTION TSamDocManager. NewWindow(heap: THeap; WmgrId: TWindowId): TWindow;} END; { Common code and data of each view } TSamView = SUBCLASS OF TView {Fields} window: TSamWindow; { gives us an easy way to access the color database } {Creation} FUNCTION {TSamView.}CREATE(object: TObject; heap: THeap; itsExtent: LRect; itsPanel: TPanel): TSamView; {Selection} {PROCEDURE TSamView. MousePress(mouseLPt: LPoint);} {PROCEDURE TSamView. MouseMove(mouseLPt: LPoint);} { adding this method will implement selections while button is down } FUNCTION {TSamView.}NewSelection(rowIndex, colIndex: INTEGER): TSamSelection; ABSTRACT; { Create a new selection of the appropriate class; this is called by TSamWindow.Select } {Utilities} PROCEDURE {TSamView.}GetDrawLimits(VAR firstRow, firstCol, lastRow, lastCol: INTEGER); { used to optimize the Draw procedure } PROCEDURE {TSamView.}LPtToRowCol(VAR rowIndex, colIndex: INTEGER; lPt: LPoint); ABSTRACT; PROCEDURE {TSamView.}SetUpBox(rowIndex, colIndex: INTEGER; VAR bbox: LRect); ABSTRACT; END; { This view controls the graphic interpretation of the colors } TSamCBView = SUBCLASS OF TSamView {Fields} boxH: INTEGER; { the size of a box } boxV: INTEGER; {Creation} FUNCTION {TSamCBView.}CREATE(object: TObject; heap: THeap; itsPanel: TPanel; itsBoxH, itsBoxV: INTEGER): TSamCBView; {Drawing} {PROCEDURE TSamCBView. Draw;} PROCEDURE {TSamCBView.}DrawBox(itsColor: TColor; rowIndex, colIndex: INTEGER); PROCEDURE {TSamCBView.}DrawHeading(rowIndex, colIndex: INTEGER); {Selection} {PROCEDURE TSamCBView. Select(rowIndex, colIndex: INTEGER);} {Utilities} {FUNCTION TSamCBView. LPtToRowCol(VAR rowIndex, colIndex: INTEGER; lPt: LPoint): BOOLEAN;} {PROCEDURE TSamCBView. SetUpBox(rowIndex, colIndex: INTEGER; VAR bbox: LRect);} END; { This view controls the text interpretation of the colors } TSamTXView = SUBCLASS OF TSamView {Fields} lineHeight: INTEGER; { height of each line including leading } lineAscent: INTEGER; { position of baseline relative to top of line } {Creation} FUNCTION {TSamTXView.}CREATE(object: TObject; heap: THeap; itsPanel: TPanel): TSamTXView; {Selection} {PROCEDURE TSamTXView. NewSelection(rowIndex, colIndex: INTEGER);} {Drawing} {PROCEDURE TSamTXView. Draw;} PROCEDURE {TSamTXView.}DrawName(itsColor: TColor; rowIndex, colIndex: INTEGER); PROCEDURE {TSamTxView.}GetBoxString(rowIndex, colIndex: INTEGER; color: INTEGER; VAR str: S255); { return the string used to describe a row/col/color combination } PROCEDURE {TSamTXView.}SetPen; { setup the pen for drawing the text; this is a method so that the pen is setup the same way throughout the program and so it can be overridden } {Utilities} {FUNCTION TSamTXView. LPtToRowCol(VAR rowIndex, colIndex: INTEGER; lPt: LPoint): BOOLEAN;} {PROCEDURE TSamTXView. SetUpBox(rowIndex, colIndex: INTEGER; VAR bbox: LRect);} END; { This is the common code and info for both the panel's selections. } TSamSelection = SUBCLASS OF TSelection {Fields} row: INTEGER; { row of selected box } col: INTEGER; { column of selected box } {Creation} FUNCTION {TSamSelection.}CREATE(object: TObject; heap: THeap; itsView: TSamView; selRow, selCol: INTEGER): TSamSelection; {Debugging} {FUNCTION TSamSelection. Field(index: INTEGER; VAR numFields: INTEGER; VAR fVal: TFieldValue): BOOLEAN;} {Command Execution} {FUNCTION TSamSelection. CanDoCommand(cmdNumber: TCmdNumber; VAR checkIt: BOOLEAN): BOOLEAN;} { set up the menu items (gray, check, etc.) before the user has a chance to see them } {PROCEDURE TSamSelection. NewCommand(cmdNumber: TCmdNumber): TCommand} END; { This selection is the graphic representation of the selection } TSamCBSelection = SUBCLASS OF TSamSelection {Creation} FUNCTION {TSamCBSelection.}CREATE(object: TObject; heap: THeap; itsView: TSamView; selRow, selCol: INTEGER): TSamCBSelection; {Highlighting} {PROCEDURE TSamCBSelection. Highlight(highTransit: THighTransit);} END; { This selection is the text representation of the selection } TSamTXSelection = SUBCLASS OF TSamSelection {Creation} FUNCTION {TSamTXSelection.}CREATE(object: TObject; heap: THeap; itsView: TSamView; selRow, selCol: INTEGER): TSamTXSelection; {Highlighting} {PROCEDURE TSamTXSelection. Highlight(highTransit: THighTransit);} END; { The window for this Application } TSamWindow = SUBCLASS OF TWindow {Fields} CB: TCheckerboard; { putting the color database here means that it can easily be shared by both panels and that we can use a filtering approach to undo } showRowColHeads: BOOLEAN; cbPanel: TPanel; txPanel: TPanel; {Creation} FUNCTION {TSamWindow.}CREATE(object: TObject; heap: THeap; itsWmgrId: TWindowId): TSamWindow; {Command Execution} {FUNCTION TSamWindow. CanDoCommand(cmdNumber: TCmdNumber; VAR checkIt: BOOLEAN): BOOLEAN;} { set up the menu items (gray, check, etc.) before the user has a chance to see them } {PROCEDURE TSamWindow. NewCommand(cmdNumber: TCmdNumber): TCommand} {Other Methods} {PROCEDURE TSamWindow. BlankStationery;} { set up a blank document } PROCEDURE {TSamWindow.}InvalidateBox(rowIndex, colIndex: INTEGER); { invalidates a row and column in both panels } PROCEDURE {TSamWindow.}Select(selectPanel: TPanel; rowSel, colSel: INTEGER); { change selection in both panels, and update highlighting; rowSel=0 means change to no selection } END; { The command object used to recolor boxes and implement Undo } TRecolorCommand = SUBCLASS OF TCommand {Fields} window: TSamWindow; selPanel: TPanel; {select panel when command was first done} rowChanged: INTEGER; {also the row that will be selected after an UNDO} colChanged: INTEGER; oldColor: TColor; {color before command was executed} newColor: TColor; {color the user asked for} {Creation} FUNCTION {TRecolorCommand.}CREATE(object: TObject; heap: THeap; itsWindow: TSamWindow; currSelection: TSamSelection; itsCmdNumber: TCmdNumber): TRecolorCommand; {Command Execution} {PROCEDURE TRecolorCommand. Perform(cmdPhase: TCmdPhase);} END; IMPLEMENTATION {$I ucb2sample2.text } END.