![]() |
AtOne Application Framework
"A Framework working with you, not against you..." |
|||||||||||||||||||||
|
Features Programming License Downloads Directions Contact
|
Commonly used ClassesAtOne is an extensive application framework and within that framework are a host of very useful and commonly used classes. Before touching upon the details of GUI programming in AtOne it is worthwhile introducing these classes to you as you are likely to encounter some of then during later discussions and you will be glad to know of the existence of the others so that you need not re-invent the wheel.Handling StringsEvery GUI application framework seems to have it's own string class and AtOne is no exception. However you might find its style quite different from any other. In putting together the OsiString class I wanted a class in which I had the full range of functionality of the C string support, but the ability to use this functionality easily in-situ. I also wanted to support both unicode and MBCS (multi-byte character sets) using the one notation that was consistent with the C style libraries. By that I am refering to the name given to strings and characters. MFC, for example, uses TCHAR to designate a wide character which equates to a char in a non-unicode build. I wanted to have a naming convention in which strings where strings and nothing else. From this perspective AtOne uses the keyword character to designate a single character in a string and the keyword string to designate a pointer to a string. Internally these are macro defined as,#ifdef _UNICODE #define character unsigned short
#else #define character char
#endif The lowercase naming convention is consitent with the C standard libraries and intrinsic variable types (as strings are). Therefore if you use these types for strings and characters your code will compile correctly to unicode or MBCS depending upon the option you chose. Furthermore, you will find your code takes on a more readable appearance as a result of the keyword names. In cases where you would like to call the C string handling functions you can use macro over-ridden versions supplied with AtOne to ensure that the correct version is called under the string model used. These macros have the same name as the standard C functions except that they are prefixed with Osi_ (Osi_strcpy for example). You will find these macro definitions in common.hpp. The OsiString class definition is, class OsiString
int
bufferLength() const;
operator const string() const;
const OsiString& toUpper();
// Access to string implementation
buffer as "C" character array
//Concatentation
//search for character
//string comparison
//string copying
//search for substring in string
//string initialisation
//string token parsing
//string duplication
//to lower case, to upper case and
order reversing
//Incrementing and decremening character
pointers
//string length
//String formating : time, date, numbers
and general formated output
This string class has a very similar set of constructors and overloaded
operators to the CString class in MFC. The main difference lies in the
addition of members corresponding to the C string handling functions. Rather
than come up with new names to methods corresponding to the C functions
(that you would need to remember) I chose to give them the same name as
the corresponding C function. Thus, if you familiar with C string manipulation
you'll easily be able to use the OsiString class. The only thing
to remember is that the methods will generally have differing parameter
lists owing to the fact that the method is acting on this
string and not an externally specified one (sprintf() for example,
does not have the destination argument since the destination is the class
instance string buffer). That aside, the inclusion of these methods gives
the flexibility of C string manipulation which the convenience of C++ string
memory management. The string class is declared and implemented in costr.hpp
and costr.cpp respectively.
Handling FilesI have always found C file handling far more flexible, convenient and easy to understand than the ANSI streams library in C++. In fact, whilst the ANSI streams library performs streaming adequately it lacks a vast range of functionality that is only accessible through the C libraries. For this reason I have added C++ wrappers arround the most useful (and portable) C file handling rountines. These include OsiFileStream for reading and writing to files, OsiFilePermission giving file access rights information, OsdFileAttributes giving general file attributes, OsiFileStatus giving status information about a file and or stream, and OsiDir for navigating directories. These file handling classes are declared and implemented in cofile.hpp and cofile.cpp respectively.Specifying ColoursGUI programming invariably involves the use of colour. WIN32 provide a multitude of ways to specify colour depending upon whether your using palettes, or simply specifying system colours. GuiColour is a class designed to unify the specification of colour under all these circumstances. The class definition for GuiColour is,class GuiColour
public:
unsigned char
red() const;
A unified colour specification is provided through the enumerated type GuiColourType which can be ColourTypeRGB (colour is specified as red green and blue components), ColourTypePaletteIndex (the red component specifies an index into a palette) or ColourTypePaletteRGB (the red, green and blue components specify an RGB colour mapped into the current palette). The enumerated type GuiSystemColour also provides a unified access to WIN32 system colours which can be one of, SystemColourScrollbar
= COLOR_SCROLLBAR
System colours can also be directly specified (ie. not using a GuiColour object instance) in standard graphics objects such as pens (GuiLogPen) and brushes (GuiLogBrush). This has the advantage that if the user changes any of the system colours while your application is running the pen and brush colours change in unison automatically. Another unique feature of colour specification in AtOne is the concept of transparent colour. Often in a GUI application you would like to be able to specify a transparent colour that if used in drawing will result in no action being taken. In AtOne you do just that by nominating a transparent colour using the GuiTransparentColour constructor. The colour nominated will then be assumed to be transparent henceforth. If you then, for example use that colour to specify a brush the brush will automatically evaluate to a null brush producing the expected behaviour. By treating colour in this way code can be dramatically simplified since transparency is just another colour requiring no special condition check code in your application. Beyond these features AtOne also supplies you with two other different colour models, HSV - Hue, Saturation and Value, and HLS - Hue, Lightness and Saturation. These colour models are supported through the classes GuiHsv and GuiHls which support conversion to and from GuiColour. The addition of these colour models makes the implementation of colour gradients simple. The colour support in AtOne is declared and implemented in guicol.hpp
and guicol.cpp respectively.
Handling ResourcesTypically WIN32 applications specify a significant proportion of their graphical and other resources in the form of resource scripts defining dialogs, menus, accelerators, resource strings and the like. To access resources usually requires two parameters : a module instance handle and a resource identifier. This is further complicated by the fact that WIN32 allows resource identifiers to be either numbers or strings. In AtOne the concept of resource identifier has been unified into a single class, namely GuiResId whose definition is,class GuiResId
void
instance(HINSTANCE hInstance);
GuiResId's are used extensively to specify the location of menu, accelerator and dialog template resources. In addition to resource Id's AtOne also provides a special class, GuiResString, that mimmicks a string to load and access resource strings. Specifying Graphics GeometryWhen programming in a GUI invironment at some point in time the geometry of your graphics must be specified and or manipulated. AtOne gives you a host of classes for this purpose. Points or co-ordinates are specified using the GuiPoint and GuiRealPoint classes. Note that GuiPoint is essentially equivalent to the WIN32 POINT structure with functionality added. We have an additional point structure GuiRealPoint in which the co-ordinates are doubles that is used in the various mapping classes that AtOne supports. Having this extra class avoids unecessary truncation of co-ordinates in complex graphical mappings. The class definition for GuiPoint is,class GuiPoint
public:
void
null();
It is common in WIN32 to have to specify the size or dimension of some graphical operation and that this is usually done with a SIZE structure. AtOne caters for size specification with the GuiDimension class which can be used interchangeably with the SIZE structure. The class definition for GuiDimension is, class GuiDimension
public:
void
null();
Rectangles are also commonly specified in WIN32 using a RECT structure. In AtOne we use GuiRect which can be used interchangeably with RECT but has a host of useful methods making it easier and more convenient to use. The class definition for GuiRect is, class GuiRect
public:
void
normalise();
Less commonly used but also very useful are ranges. The name range here comes from the mathematical definition in which a pair of numbers specify a specific range in which another number can belong to. AtOne has a GuiRange and GuiRealRange class which is used for such range specifications. The GuiRealRange is for real numbers whilst GuiRange is for integers. Beyond these basic classes AtOne has a number of very useful point mapping classes that can make graphics programming that much easier. The class GuiPointByVectors is essentially a conversion class that can either determine the scaling of two vector added together required to construct a given point or alternatively, construct a point out of a scaled linear combination of two vectors. This class is typically very useful in building graphs as it allows points to be mapped to and from the graph space. The class GuiParallelogram is a mapping class that allows you to map co-ordinates from one parallelogram to another. Unlike a rectangle a parallogram can have corners that are not at right angles. The only constraint is that opposite sides are parallel to one another. By using two instances of this class you can map points and rectangles from a rectangular space to a sheared (that is flatterned) rectangular space with any degree of scaling that you like. This can be particularly useful if, for example, you need to perform a shearing operation on a bitmap. The class GuiLineSegment is used to manipulate line segments. In particular, with this class you can check if a line segment is wholly contained within a given rectangle, intersects and given rectangle and clip it to the border of a given rectangle. You can also find out the effective length of the line segment. Finally the class GuiCoOrdinateTransform is a generalised 2-dimension co-ordinate transformation supporting translation, rotation, scaling and shearing transformations. It is also structured in a way to concurrently support the forward and inverse co-ordinate transformation of points using the transformation that you have constructed. You should find this class exceptionally useful in any 2-D graphics application that needs to specify graphics transformations in an arbitrary fashion. The class definition for GuiCoOrdinateTransform is, class GuiCoOrdinateTransform
void
reset();
All of these classes and more are declared and implemented in guigeom.hpp
and guigeom.cpp respectively.
"We use Zeus for Windows and Watcom C/C++ 11.0 as our development environment of choice..." Paavo Jumppanen
|
|||||||||||||||||||||