Difference between revisions of "Project A2 20141 - OOP344"

From CDOT Wiki
Jump to: navigation, search
(draw: Added fullscreen clause)
(Recommendations: row,col,absrow,abscol)
Line 100: Line 100:
  
 
You may use either of these implementations of setLine or use any third implementation that you prefer.
 
You may use either of these implementations of setLine or use any third implementation that you prefer.
 +
 +
==== row, col ====
 +
The normal row and column functions (row, col) return the relative position of the widget to its parent where (0,0) indicates the most top left position on which anything can be drawn.
 +
 +
If a widget has a parent then the relative position is relative to the parent's position. If a widget has no parent <u>or if it's parent is fullscreen</u> then the position is relative to the screen in which case the position (0,0) is the most top left character on the screen.
 +
 +
==== absRow, absCol ====
 +
The The idea behind the abs functions is to return the position of the widget <u>on the screen</u>.
  
 
== CField ==
 
== CField ==

Revision as of 00:04, 8 March 2014


OOP344 | Weekly Schedule | Student List | Teams | Project | A1 | A2 | A3 | Student Resources

Introduction

The basic information of A2 is on the BTP300 site linked here. A number of issues have been identified within the assignment spec and so a series of amendments is required in order for the spec to produce a correct assignment. The amendments are listed here. In addition, we are also listing a number of clarifications and suggestions that you may find helpful while implementing this assignment. Those will follow the spec code amendments.

Spec Code Amendments

cfg.h

  • Instead of #defining NULL in cfg.h, you should #include <cstdlib> at the top of cfg.h. eg:
#ifndef __CFG_H__
#define __CFG_H__
#include <cstdlib>

...

#endif

CFrame

Functions to be Updated

The following functions should be made public or protected:

  • CFrame::absRow
  • CFrame::absCol

Functions to be Removed

The following two functions should be removed from the specification completely. Let me be extra clear: DO NOT PUT THEM IN YOUR CFrame HEADER, DO NOT CODE THEM, DO NOT USE THEM!

  • CFrame::display
  • CFrame::edit

CField

Functions to be Updated

  • The function CField::edit currently accepts 4 parameters and is not virtual.
    It should be updated as follows to be consistent with its child classes:
    • pure virtual
    • should not accept any parameters
    • should return int (it already does)

Functions to be Removed

The following functions are a bit awkward. Remove them. See the Functions to be Added section for a better design.

  • void** data()
  • const void* pdata() const

Functions to be Added

These functions act as setters/getters to CField's internal data member. Code them so that other classes can obtain or update the data member. Make these public.

  • void* data() const
  • void data(void*)

CLine

Constructors

Both constructors should accept a bool* and NOT a bool for insert mode. Updated descriptions follow:

Constructor 1

Receives 8 values.
...

  • bool* - the insert mode for the line field

...

Constructor 2

Receives 7 values.
...

  • bool* - the insert mode for the line field

...

Big Picture, Clarifications, Recommendations

This assignment is about creating a basic console GUI system. It is meant to show the student how OOP can be used effectively to design a system. The basic setup for this system are the 6 classes iFrame, CFrame, CField, CLabel, CLine, CButton and the supplemental class CDialog provided already implemented as a part of the spec. Let's look at the role of each of these.

NOTE: In the assignment spec, any value in parentheses ( () ) is the default value of that particular parameter.

iFrame

iFrame is an interface class that describes a widget that has a frame. We can easily spot interface classes by looking for the "i" at the beginning of their name. A widget is basically a window component such as a label, a button, a field, or even a full window. Since iFrame is an interface, iFrame's job is to declare the set of functionality that every framed object can publicly perform. We call this type of design design by contract because we can think of any class derived from iFrame to be contractually obligated to fulfill what iFrame has promised.

iFrame's contract consists of a set of pure virtual functions that any concrete deriving class must implement. In this case, iFrame declares that any object instanced from it can draw itself, hide itself, and move.

CFrame

CFrame inherits from iFrame and implements iFrame's core responsibilities. The "C" in CFrame stands for "concrete" (even though it is technically abstract! More on this later). In this system, CFrame is the parent class of all other deriving classes (CDialog, CField) and the ancestor of the other three (CLabel, CLine, CButton).

Responsibilities

CFrame is responsible for common communication with the underlying console including:

  • Clearing a portion of the screen (draw)
    • Optionally drawing a border/frame while doing this
  • Restoring a section of a cleared portion of the screen or in its entirety (hide)
  • Storing attributes and providing functionality for retrieving the basic state of the frame including:
    • Whether it is in fullscreen mode
    • Whether it is bordered
    • Relative top left row/top left column
    • Absolute top left row/top left column
    • Width/height of the frame, including the frame/border
      • This should be the width/height of the screen if the frame is in fullscreen

Clarifications

draw

  • The integer accepted by this function can be a value equivalent to C_NO_FRAME or any other value. If it is C_NO_FRAME, then no frame should be drawn even if the current widget was constructed bordered.
  • Child classes should adjust their drawn content so as not to overlap the border if a border will be drawn.
  • If a frame is in fullscreen mode (width < 0 or height < 0) then no border should be drawn.

Recommendations

setLine

setLine is somewhat awkward in implementation. Its purpose is to fill a string that is the width of the frame with a first character, a fill character, and an end character. This however requires a string for output which typically must be dynamically allocated before use and then deallocated after use.

However, the same effect can be achieved through a similar function that instead of filling a string simply prints the same characters directly to console utilizing two output statements and a loop. This approach removes the need for an additional string. Obviously a function like this would not need to accept a char*.

You may use either of these implementations of setLine or use any third implementation that you prefer.

row, col

The normal row and column functions (row, col) return the relative position of the widget to its parent where (0,0) indicates the most top left position on which anything can be drawn.

If a widget has a parent then the relative position is relative to the parent's position. If a widget has no parent or if it's parent is fullscreen then the position is relative to the screen in which case the position (0,0) is the most top left character on the screen.

absRow, absCol

The The idea behind the abs functions is to return the position of the widget on the screen.

CField

CField inherits from CFrame and implements some of the functionalities common to most widgets eg buttons, fields, and labels. It also propagates a contract of its own. This is to allow container objects to work with more derived objects (CLine, CLabel, CButton) without needing to know their exact class.

Contract

CField's contract consists of functions that could be used to query the capabilities of an object derived from CField and to perform the basic actions typically required from a window component. These functions are all pure virtual. The functions are as follows:

  • void draw(int)
  • int edit() [mentioned above]
  • bool editable() const
  • void set(const void*)

Responsibilities

CField is responsible for implementing the data setter/getter.

CLabel

A CLabel is an uneditable line of text to be displayed somewhere on the screen. It inherits from CField.

CLine

A CLine is an editable line of text. It inherits from CField.

CButton

A CButton is a text field with additional decoration displayed when the button is in its "edit" state. The edit state is exited when the user presses any key.