Open main menu

CDOT Wiki β

BTP300 Practical Tips 2012

Revision as of 16:33, 7 September 2012 by Peter.liu (talk | contribs)

Purpose

Share useful information that can help all groups with their projects.

A1

  • demo: executable code (BORLAND) about the display and edit functions [1]

A2: Useful Pseudo Code (Dr. Chris Szalwinski)

This is one way to design some of your classes. Other ways are also possible. The instance variable and pointer names are left to your discretion. Not all methods and functions are included. The simpler ones are omitted.

CFrame

  • Constructor
    • initialize instance variables
    • determine if full screen
      • if full screen set width and height to console width and height
    • initialize covered area to nothing
  • Destructor
    • release the covered area
  • CFrame::setLine
    • do this yourself
  • CFrame::absRow
    • start with the row value for this frame - call row()
    • add the row value for the parent frame if any
    • add the row value for the parent's parent frame if any
    • continue until you run out of parents
  • CFrame::absCol
    • same as absRow except for columns
  • CFrame::goMiddle
    • calculate the absolute row and column position of the middle accounting for the border if any
    • set the cursor position to these absolute values
  • CFrame::display
    • remember to account for a border if any and is on
    • calculate the width of the frame with a border if any
    • reduce width if frame extends beyond the border of the parent frame
    • calculate the absolute position of the frame
    • call your display function to display the string
  • CFrame::edit
    • remember to account for a border if any and is on
    • calculate the width of the frame with a border if any
    • reduce width if frame extends beyond the border of the parent frame
    • calculate the absolute position of the frame
    • call your edit function to edit the string
  • CFrame::draw
    • allocate dynamic memory for string to hold a single line of the frame
    • capture the rectangle of characters that will be hidden by the drawing of the frame
    • if the frame is bordered and the parameter does not hold the no frame value
    • create the top line of the frame
    • position the cursor for the top line
    • insert the top line into the output stream (<<)
    • create an interior line of the frame
    • for each interior line
      • position the cursor for the interior line
      • insert the interior line into the output stream (<<)
    • create the bottom line of the frame
    • position the cursor for the bottom line
    • insert the bottom line into the output stream (<<)
    • deallocate dynamic memory
  • CFrame::move
    • hide the frame
    • switch on direction received
      • increment or decrement row or column value
      • ensure that frame does not move outside parent frame or console space
    • draw the frame
  • CFrame::hide
    • restore the hidden rectangle of characters at the current position of the frame
    • release the dynamic memory used to store the hidden characters
  • move
    • create pointer to message for moving
    • capture the characters hidden by the message
    • for each move request
      • insert the message into the output stream (<<)
      • extract the key pressed from the console (>>)
      • switch on the key press
        • move the frame referred to in the parameter as requested
        • exit moving operations on Escape
      • restore the characters hidden by the message
      • release the dynamic memory for the message
      • may need to draw the frame after removing the message

CField

  • Constructor
    • pass parameter data to CFrame
    • store the address of the field data in the instance pointer
  • Destructor
    • does nothing
  • CField::display
    • call CFrame::display with the offset received
  • CField::edit
    • call CFrame::edit with the address of the data belonging to the field
  • CField::pdata
    • return the address of the data belonging to the field
  • CField::data
    • return the address of the pointer that holds the address of the data belonging to the field

Useful Diagrams

Useful Links On The Web

Useful Code Snippets