LICENSE
The COOL is a public open source project
of Quésoft under the GNU General Public License. For more information
read lisence.txt.
Copyright 2001-2002 Frédéric Brown
This program
is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License
as published by
the Free Software Foundation; either version 2 of
the License, or
(at your option) any later version.
This program is distributed in the hope that it will
be useful,
but WITHOUT ANY WARRANTY; without even the implied
warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the
GNU General Public License for more details.
You should have received a copy of the GNU General
Public License
along with this program; if not, write to the Free
Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston,
MA 02111-1307 USA
JOIN QUÉSOFT
e-mail : brown_frede@hotmail.com
REQUIREMENTS
TI-89, TI-92 II or TI-92+ calculator.
THE COOL SYNTAX
Objects can be manipulated in as all
the other C types
To access an attribute : objectName->attribute
To access non-static method : objectName->methodName(objectName[,
arguments ...])
An alternative "non standard" way to access a non-static method : e(objectName, method, argument1[, other arguments ...])
Objects references are pointers, so o1 = o2 will not copy o2 to o1 but make
o1 to point to o2. If an object is used as parameter of a function,
any changes to the object in the function will be permanent and remanent
in the calling function.
The strings used in most COOL classes are TString objects instead of char*
ANSI C strings. To convert an ANSI string to a TString object, use
the s(ANSIString) macro. To
copy a TString object, use the c(TStringString)
macro instead of '='.
Object are created via objects constructors
(constructors are functions named by the class' name followed by an integer).
To instanciate then use an object, declare a pointer to the type of
the object, then call the constructor : TClassType*
object = TClassType0();
To access a static member of a class, field of method, use the class
name without the 'T' followed by an underscore ('_') and the name
of the field or the method : ClassType_method(arguments...);
ClassType_attribute;
Object structure are defined by a struc structure.
Child structures must conserve the entries of parent structures.
Methods are declared as ClassType_method(arguments...)
for static ones and TClassType_method(arguments)
for non-static ones.
Constructors returns a pointer to the type of the object and are named
after the class' name followed by an integer.
PROGRAMMING
COOL's keywords
this
Refers to the current object.
Example :
this->setVisible(this,
FALSE); //Set the object visibility to false
Class
A typical class :
//Static attributes
typedef struct
ClassName {
//parent entries
//class attributes
//class methods (pointers to functions)
} TClassName;
//Declaration of
the static methods
//Declaration of
the constructors
//Declaration of the methods
//Definition of
the methods and constructors
Methods
A typical method :
If a method of the same name exist in the
parent's class it will be remplaced.
void TClassName_methodName(TClassName*
this[, arguments...]) {
//method instructions
}
A typical static method :
void ClassName_methodName([,
arguments...]) {
//method instructions
}
Constructors
The constructors are the methods executed
at the creation of an object.
A typical constructor :
TClassType* TClassType0([arguments...])
{
TClassType* this = (TClassType*)(malloc sizeof(TClassType));
//Assignation of the pointers to the functions. For
non-remplaced herited methods they point on the parent's functions, for
remplaced or non-herited methods they point on the current class functions.
return this;
}
EXAMPLES
The TLabel object's class
This class inherit from the TCaptionedComponent
class.
#define Label_COLOR_WHITE 0//A static field
"COLOR_WHITE"
#define Label_COLOR_BLACK 1//A
static field "COLOR_BLACK"
//Structure
of the object
typedef struct Label {
//Fields herited from TObject
char *class;
//Name
of the class
char *super;
//Name of the supperclass
struct Label* (*clone)
(struct Label*);//A method that returns a
copy of the label
BOOL
(*equals) (struct
CaptionedComponent*, struct Object*);//A method that compares
the object with the others
void
(*finalize) (struct Label*);//A method that frees the
memory allocated to the object once it became obselete
TString*
(*toString)
(struct CaptionedComponent*);//A
method that returns a string representation of the object
//Fields herited from TVisualComponent
int height;
//The
height of the component
BITMAP *img;
//An
image of the part of the screen hidded by the component
BOOL visible;
//The
visibility of the component
int width;
//The width of the component
int x;
//The horizontal position
of the component
int y;
//The vertical position of
the component
void
(*move)
(struct Component*, int, int);//A method that moves the
component
void
(*print)
(struct Label*);//A method that print the
component
void
(*setBounds) (struct
Component*, int, int, int, int);//A method that fixes the bounds(coordinates) of
the component
void
(*setHeight) (struct
Component*, int);//A method that fixes the height of the component
void
(*setVisible) (struct
Component*, BOOL);//A method that fixes the visibility of the component
void
(*setWidth)
(struct Component*, int);//A method that fixes the width of the component
void
(*setX)
(struct Component*, int);//A method that fixes the
horizontal position of the component
void
(*setY)
(struct Component*, int);//A method that fixes the
vertical position of the component
//Fields herited from TCaptionedComponent
TString* caption;
//The
caption of the component
void
(*setCaption) (struct
CaptionedComponent*, TString*);//A method that fixes the caption of the component
//Fields of the current class
BOOL opaque;
//The opacity of the label
int color;
//The color of the text
void
(*setColor)
(struct Label*, int);//A method that fixes the color of the text
void
(*setOpaque) (struct
Label*, BOOL);//A method that fixes the opacity of the label
} TLabel;
//Declaration
of the constructors
TLabel* TLabel0();
TLabel* TLabel1(TString*);
TLabel* TLabel2(char*);
//Declaration
of the methods
TLabel*
TLabel_clone
(TLabel*);
void
TLabel_finalize
(TLabel*);
void
TLabel_print
(TLabel*);
void
TLabel_setColor
(TLabel*, int);
void
TLabel_setOpaque (TLabel*, BOOL);
//A constructor without
arguments
TLabel* TLabel0 () {
TLabel *this = (TLabel*)malloc(sizeof(TLabel));//Allocate the memory
this->class = "TLabel";//Assigns the class' name
this->super
= "TCaptionedComponent";//Assigns the parent's name
//Initialization
of the attributes
this->height = 0;
this->visible
= FALSE;
this->width = 0;
this->x
= 0;
this->y
= 0;
this->img
= (BITMAP*)malloc(sizeof(BITMAP));
this->caption = s("");
this->opaque = FALSE;
this->color =
Label_COLOR_BLACK;
this->clone
= TLabel_clone;//Pointer
to class function
this->equals
= TCaptionedComponent_equals;//Pointer to inherited method from
TCaptionedComponent
this->finalize
= TLabel_finalize;//Pointer
to class function
this->toString
= TCaptionedComponent_toString;//Pointer
to inherited method from TCaptionedComponent
this->move
= TComponent_move;//Pointer to inherited method
from TComponent
this->print
= TLabel_print;//Pointer to class function
this->setBounds
= TComponent_setBounds;//Pointer to inherited
method from TComponent
this->setHeight
= TComponent_setHeight;//Pointer to inherited
method from TComponent
this->setVisible
= TComponent_setVisible;//Pointer to inherited
method from TComponent
this->setWidth
= TComponent_setWidth;//Pointer
to inherited method from TComponent
this->setX
= TComponent_setX;//Pointer
to inherited method from TComponent
this->setY
= TComponent_setY;//Pointer
to inherited method from TComponent
this->setCaption
= TCaptionedComponent_setCaption;//Pointer
to inherited method from TCaptionedComponent
this->setColor
= TLabel_setColor;//Pointer
to class function
this->setOpaque
= TLabel_setOpaque;//Pointer
to class function
return this;
}
//A
constructor accepting a TString object
TLabel* TLabel1 (TString* caption)
{
TLabel *this = TLabel0();//Calls
the constructor without argument
this->setCaption(this, caption);//Sets
the component caption to the caption parameter
return this;
}
//A
constructor accepting an ANSI string char pointer
TLabel* TLabel2 (char* caption) {
TLabel *this;//Pointer
to a TLabel object
TString *string;//Pointer
to a TString object
string = s(caption);//Convert
ANSI string caption to TString object
this = TLabel1(string);//Calls
the constructor accepting string as a TString object
string->finalize(string);//clean
up the tempory TString object
return this;
}
//A
method that return a copy of the object
TLabel* TLabel_clone(TLabel* this)
{
TLabel *clone;//The
copy
clone = TLabel0();//Creates
a new TLabel object
//Copy the attributes
clone->height = this->height;
clone->visible
= FALSE;
clone->width =
this->width;
clone->x
= this->x;
clone->y
= this->y;
clone->caption = c(this->caption);
clone->opaque =
this->opaque;
return clone;
}
//Destroy
the object once obselete
void TLabel_finalize (TLabel* this)
{
this->setVisible(this, FALSE);//Insure
that the component is no more visible to avoid GUI junk
TRY {
this->caption->finalize(this->caption);//Finalizes
the TString object used as caption
free(this->img);//frees the memory
allocated for the image of the part of the screen
hidded by the component
free(this);//frees
the memory allocated for the component
}
ONERR {}
ENDTRY
}
//Prints
the component
void TLabel_print(TLabel* this) {
int x0 = this->x;
int y0 = this->y;
int attr;
//If the component is oppaque
if (this->opaque)
{
attr = A_REPLACE;//Remplace
background
}
else {
attr = A_NORMAL;//Overwrite
background
}
DrawStr((x0+2), (y0+2), this->caption->string,
attr);//Draws
the string
//If the color property of the object is COLOR_WHITE,
xor the black string
if (this->color ==
Label_COLOR_WHITE)
{
DrawStr((x0+2), (y0+2), this->caption->string,
A_XOR);
}
}
//Sets
the color of the label
void TLabel_setColor(TLabel* this,
int color) {
BOOL visible = this->visible;
//If the component is visible
if (visible) {
TComponent_setVisible(this, FALSE);//Hides
the component
}
this->color = color;//Changes
color property
//If the component was visible
if (visible) {
TComponent_setVisible(this, TRUE);//Shows
the component
}
}
//Sets
the opacity of the label
void TLabel_setOpaque(TLabel* this,
BOOL opaque) {
BOOL visible = this->visible;
//If the component is visible
if (visible) {
TComponent_setVisible(this, FALSE);
}
this->opaque = opaque;//Changes
color property
//If
the component was visible
if (visible) {
TComponent_setVisible(this, TRUE);//Shows
the component
}
}