Changes

Jump to: navigation, search

Console UI Core Classes - OOP344 20112

5,867 bytes added, 09:00, 20 July 2011
no edit summary
{{OOP344 Index | 20112}}
Under Construction!
''' Release 0.1 '''
|-------- CMenu ?? maybe
</pre></big>
=Basic IOL Encapsulating Classes=
==CFrame==
The code for this class is provided. You must understand and use it to develop your core classes.
 
CFrame class is responsible to create a frame or structure in which all user interface classes contain themselves in. It can draw a border around it self or be border-less.
CFrame also, before displaying itself on the screen, will save the area it is about to cover, so it can redisplay them to hide itself.
 
CFrame is base of all objects in our user interface system.
 
<big><syntaxhighlight lang="cpp">
#pragma once
#include "cgh.h"
 
class CFrame{
int _row; // relative row of left top corner to the container frame or the screen if _frame is null
int _col; // relative col of left top corner to the container frame or the screen if _frame is null
int _height;
int _width;
char _border[9]; // border characters
bool _visible; // is bordered or not
CFrame* _frame; // pointer to the container of the frame (the frame, surrounding this frame)
char* _covered; // pointer to the characters of the screen which are covered by this frame, when displayed
void capture(); // captures and saves the characters in the area covered by this frame when displayed and sets
// _covered to point to it
protected:
int absRow()const;
int absCol()const;
public:
CFrame(int Row=-1, int Col=-1, int Width=-1,int Height=-1,
bool Visible = false,
const char* Border=C_BORDER_CHARS,
CFrame* Frame = (CFrame*)0);
virtual void draw(int fn=C_FULL_FRAME);
virtual void move(CDirection dir);
virtual void hide();
 
virtual ~CFrame();
/* setters and getters: */
 
bool fullscreen()const;
 
void visible(bool val);
bool visible()const;
 
void frame(CFrame* theContainer);
CFrame* frame();
void row(int val);
int row()const;
 
void col(int val);
int col()const;
 
void height(int val);
int height()const;
 
void width(int val);
int width()const;
 
void refresh();
};
</syntaxhighlight></big>
===Properties===
int _row, holds the relative coordinate of top row of this border with respect to its container.<br />
int _col, same as _row, but for _col. <br />
int _height, height of the entity. <br />
int _width, width of the entity. <br />
char _border[9], characters used to draw the border: <br />
: _border[0], left top
: _border[1], top side
: _border[2], right top
: _border[3], right side
: _border[4], right bottom
: _border[5], bottom side
: _border[6], bottom left
: _border[7], left side
bool _visible; Indicates if the border surrounding the entity is to be drawn or not. <br />
CFrame* _frame; holds the container (another CFrame) which has opened this one (owner or container of the current CFrame). '''_frame''' will be NULL if this CFrame does not have a container, in which case, it will be full screen and no matter what the values of row, col, width and height are, CFrame will be '''Full Screen''' (no border will be drawn)<br />
char* _covered; is a pointer to a character array that hold what was under this frame before being drawn. When the CFrame wants to hides itself, it simple copies the content of this array back on the screen on its own coordinates.
===Methods and Constructors===
====Private Methods====
<big><syntaxhighlight lang="cpp">
void capture();
</syntaxhighlight></big>
:if _covered pointer is not pointing to any allocated memory, it will call the bio_capture function to capture the area that is going to be covered by this frame and keeps its address in _covered.
 
====Protected Methods====
*int absRow()const; calculates the absolute row (relative to the left top corner of the screen) and returns it.
*:it returns the sum of '''row()''' of this border plus all the '''row()'''s of the '''_frame'''s
*int absCol()const; calculates the absolute column(relative to the left top corner of the screen) and returns it.
*:it returns the sum of '''col()''' of this border plus all the '''col()'''s of the '''_frame'''s
 
====Public Methods====
 
<big><syntaxhighlight lang="cpp">
CFrame(int Row=-1, int Col=-1, int Width=-1,int Height=-1,
bool Visible = false,
const char* Border=C_BORDER_CHARS,
CFrame* Frame = (CFrame*)0);
</syntaxhighlight></big>
:Sets the corresponding attributes to the incoming values in the argument list and set _covered to null
 
<big><syntaxhighlight lang="cpp">
virtual void draw(int fn=C_FULL_FRAME);
</syntaxhighlight></big>
* First it will '''capture()''' the coordinates it is supposed to cover
* If frame is '''fullscreen()''' then it just clears the screen and exits. <br />
 
Otherwise:<br />
*If the _visible flag is true, it will draw a box at _row and _col, with size of _width and _height using the _border characters and fills it with spaces. Otherwise it will just draw a box using spaces at the same location and same size.
 
 
<big><syntaxhighlight lang="cpp">
virtual void move(CDirection dir);
</syntaxhighlight></big>
First it will hide the Frame, then adjust the row and col to more to the "dir" direction and then draws the Frame back on screen.
<big><syntaxhighlight lang="cpp">
virtual void hide();
</syntaxhighlight></big>
using bio_restore()it restores the characters behind the Frame back on screen. It will also free the memory pointed by _covered;
 
<big><syntaxhighlight lang="cpp">
virtual ~CFrame();
</syntaxhighlight></big>
It will make sure allocated memories are freed.
 
<big><syntaxhighlight lang="cpp">
bool fullscreen()const;
void visible(bool val);
bool visible()const;
void frame(CFrame* theContainer);
CFrame* frame();
void row(int val);
int row()const;
void col(int val);
int col()const;
void height(int val);
int height()const;
void width(int val);
int width()const;
</syntaxhighlight></big>
 
These functions set and get the attributes of the CFrame.

Navigation menu