Changes

Jump to: navigation, search

Console UI Core Classes - OOP344 20121

3,092 bytes added, 15:49, 15 February 2012
Constructors and Methods
</syntaxhighlight></big>
Sets and Gets the _frame attribute of CFrame by calling CFrame::frame() method. Make sure to cast The CDialog to CFrame when setting and cast CFrame to CDialog when getting!
==CLabel==
A readonly Field that encapsulates console.display() function. (i.e it is responsible to display a short character string on the display) CLable although, by inheritance is Frame, but it is never '''bordered'''.
<big><syntaxhighlight lang="cpp">
#include "cfield.h"
class CLabel : public CField{
// int _length; Use void CFrame::width(int) to store length, and int CFrame::width() to retrieve the length
 
public:
CLabel(const CLabel& L);
CLabel(const char *Str, int Row, int Col,
int Len = 0);
CLabel(int Row, int Col, int Len);
~CLabel();
void draw(int fn=C_NO_FRAME) ;
int edit();
bool editable()const;
void set(const void* str);
};
</syntaxhighlight></big>
===Attributes===
No attributes, (use Cframe attributes)
<big><syntaxhighlight lang="cpp">
// int _length; removed! use void CFrame::width(int) to store and int CFrame::width() to retrieve length
</syntaxhighlight></big>
<del>Holds the Length of the label, this will be stored to be passed to console.display function.</del>
 
===Constructors / Destructor ===
<big><syntaxhighlight lang="cpp">
CLabel(const char *Str, int Row, int Col,
int Len = 0);
</syntaxhighlight></big>
passes the Row and Col to the CField constructor and then;
if len is zero, it will allocate enough memory to store the string pointed by Str and then copies the Str into it.
if len > 0, then it will allocate enough memory to store '''len''' chars in a string.
In any way, the allocated memory is pointed by '''_data'''
<big><syntaxhighlight lang="cpp">
CLabel(int Row, int Col, int Len);
</syntaxhighlight></big>
Works exactly like the previous constructor, but len in this case can not be zero. (no validation required) and the string pointed by _data will be set to an empty string.
<big><syntaxhighlight lang="cpp">
CLabel(const CLabel& L);
</syntaxhighlight></big>
<del>A private and empty copy Constructor. This prevents copying CLabel.</del><br />
Copies a CLabel safely to guaranty there is no memory leak.
<big><syntaxhighlight lang="cpp">
~CLabel();
</syntaxhighlight></big>
makes sure that memory pointed by _data is deallocated before the object is destroyed.
 
===Methods===
<big><syntaxhighlight lang="cpp">
void draw(int fn=C_NO_FRAME) ;
</syntaxhighlight></big>
makes a direct call to console.display(), passing '''_data''' for the string to be printed and absRow() and absCol() for row and col and _length for len.
this function ignores the argument fn.
<big><syntaxhighlight lang="cpp">
int edit();
</syntaxhighlight></big>
calls draw, returning 0.
<big><syntaxhighlight lang="cpp">
bool editable()const;
</syntaxhighlight></big>
always return false.
<big><syntaxhighlight lang="cpp">
void set(const void* str);
</syntaxhighlight></big>
if _length is greater than zero, it will copy the string pointed by str into the string pointed by _data upto _length characters.
if _length is zero,<br /> It will delete the memory pointed by _data and reallocates enough memory for str and copies the string pointed by str into the newly allocated memory pointed by _data.

Navigation menu