|
From: <fl...@ma...> - 2003-07-29 17:45:37
|
OK I've done some corrections (mostly point out what needs to be changed). I
will put the code here for archival purposes but I also attach it. Look
where it sais RED KNIGHT REVIEW...
textrenderer.h
#include <utility/common.h>
#include <utility/misc.h>
#include "fonts.h"
namespace XenoEngine
{
// RED KNIGHT REVIEW: Do not indent the classes... this is an example of
how it should look
//////// Indent Example //////////
class XeTextRenderer
{
public:
//! Prints a string to the screen.
//! /note 0 on the font pointer means use what we got set.
void printString(Real x, Real y, Real z, const char* string, XeFont* font
= 0, Utility::Misc::MiscColorRGB color = Utility::Misc::MiscColorRGB(0,0,0),
bool vertical = false, Real angle = 0.0);
/////// End Indent Example ////////
//! Prints a string to fit a width/height.
//! RED KNIGHT REVIEW: reference shouldnt be = 0, use = NULL
instead... and please use a more readable name.
//! RED KNIGHT REVIEW: For the color in Utility::Misc add a using
namespace clause at the beginning and avoid using the fully qualified name
in here cause it is detrimental to readability.
//! RED KNIGHT REVIEW: I suggest if you are using defaults in Color
to add some entries in the utility package of constant objects like
colorBlack, colorWhite and the like.
void printStringToScale(Real x, Real y, Real z, Real width, Real
height, const char* string, Utility::Misc::MiscColorRGB color =
Utility::Misc::MiscColorRGB(0,0,0), XeFont* reference = 0, bool vertical =
false, Real angle = 0.0);
//! Set the font to a stored version
void setFont(const XeFont& font);
//! Create a font and return it for referencing later.
// RED KNIGHT REVIEW: Get is not a proper name, even though you are
not creating the font after a call... use createFont instead
// RED KNIGHT REVIEW: Add an String overloaded function too.
// RED KNIGHT REVIEW: Weight is of type FONTWEIGHT, bold, italic
and understrike are toghether an Int32 under the type FONTSTYLE.
// RED KNIGHT REVIEW: You are missing the Quality argument.
XeFont getNewFont(const char* name, int size, int weight, bool
bold=false, bool italic=false, bool underline=false, bool strikeout=false);
//! Return the default font.
XeFont getDefaultFont();
// RED KNIGHT REVIEW: You are missing the getCurrentFont method.
(it is pretty useful)
// RED KNIGHT REVIEW: You can add a pushFont and popFont like the
pushMatrix and popMatrix in OpenGL. They are pretty useful.
protected:
friend class XeOpenGLRenderer;
//! Constructor
//! /remark May only be called by the XeOpenGLRenderer
XeTextRenderer();
//! Destructor
//! /remark May only be called by the XeOpenGLRenderer
~XeTextRenderer();
private:
//! The current font being used.
//! RED KNIGHT REVIEW: Do not use underscores for variables or
methods names, only on enum values and at the beginning.
XeFont m_currentfont;
//! The default font.
//! RED KNIGHT REVIEW: Do not use underscores for variables or
methods names, only on enum values and at the beginning.
XeFont m_defaultfont;
};
}// XenoEngine Namespace
fonts.h
#include <utility/common.h>
#include <utility/misc.h>
namespace XenoEngine
{
// RED KNIGHT: Modify this names to be consistent with new code convention,
that was old code so dont use it that way. If we are going to break the
code, then break it completly and we will make things look better.
// OLD CONVENTION: _STYLE<something>
// NEW CONVENTION: _FS<something> (FS stand for FONTSTYLE)
#define _STYLENONE 0
#define _STYLEITALIC 1
#define _STYLEUNDERLINE 2
#define _STYLESTRIKEOUT 4
class XeFontData;
class XeFont
{
public:
enum FONTWEIGHT { _FWDONTCARE = 0, _FWNORMAL = 400, _FWBOLD = 700,
_FWBLACK = 900 };
enum FONTQUALITY { _FQPROOF = 6470, _FQDRAFT, _FQNONANTIALIASED,
_FQDEFAULT, _FQANTIALIASED };
// ADDED BY RED KNIGHT
typedef Int32 FONTSTYLE;
virtual ~XeFont ();
String getFontName ();
FONTWEIGHT getWeight ();
FONTQUALITY getQuality ();
Int32 getSize ();
//! Returns the base address of the compiled list where the fonts
are stored.
UInt32 getBaseList ();
Bool isItalic ();
Bool isUnderline ();
Bool isStrikeout ();
Bool isValid ();
//! Returns the horizontal size of the string in the screen in
pixels.
UInt32 getStringHorizontalSize (String string);
//! Returns the vertical size of the string in the screen in pixels.
//! /note The vertical is how tall the string would be if displayed
vertically.
UInt32 getStringVerticalSize (String string);
//! Returns the vertical size of a horizontally displayed string in
pixels.
UInt32 getStringHeight(String string);
protected:
friend class XeTextRenderer;
//! The Contructor
//! /remark This must only be called by the XeTextRenderer
//! RED KNIGHT: style type have to change from Int32 to FONTSTYLE
XeFont (String& font, Int32 size, FONTWEIGHT weight, Int32 style,
FONTQUALITY quality);
//! Returns the horizontal size vector to be filled by the
XeTextRenderer after creating the font.
//! /remark This must only be called by the XeTextRenderer
std::vector<UInt8>& getHorizontalSizeVector ();
//! Sets the vertical size of the font.
//! /remark This must only be called by the XeTextRenderer
//! RED KNIGHT REVIEW: If you add the information showed below you
wont need that.
void setVerticalRealSize (Int32 realSize);
//! Platform dependent font creator
void createFont ();
private:
//! The functions below is the tracking mechanism for fonts. It
makes sure that
//! no more than one GLlist is created and maintained for each font.
It does all
//! of this transparently.
//! Lazy Evaluated Font Data
//! /note Lazy Evaluation is a one-to-many data-to-object way of
saving memory.
//! RED KNIGHT REVIEW: Do not use underscores for variables or
methods names, only on enum values and at the beginning.
LazyEvaluation<XeFontData> m_fontdata;
//! This data vector keeps track of all font instances
static std::vector<LazyEvaluation<XeFontData>*> fonts;
//! Creates(Reuses) a tracked lazy evaluation of the font data.
//! /remark Used in the constructor to create a non-unique version
of the font if possible.
static LazyEvaluation<XeFontData> createTrackedFontData(const
XeFontData& reference);
//! Destroys the font list, and removes the lazy evaluation from the
fonts vector.
static void destroyTrackedFontData(const LazyEvaluation<XeFontData>&
value);
};
//! This class is used to store all the information about a font.
class XeFontData
{
public:
XeFontData& operator=(const XeFontData& obj);
//! RED KNIGHT REVIEW: Change obj2 to sourceObject and obj1 to
destinationObject
friend bool operator==(const XeFontData& obj1, const XeFontData&
obj2);
//! RED KNIGHT REVIEW: If this means that you are going to check for
less than, you need a CRC Number or something cause it wont work with simple
attributes because there is not a real algebraic order. If the symbol is
intended to be use in something different dont use operators cause it cause
readability problems.
//! RED KNIGHT REVIEW: Change obj2 to sourceObject and obj1 to
destinationObject
friend bool operator<(const XeFontData& obj1, const XeFontData&
obj2);
//! RED KNIGHT REVIEW: Implement the setters and getters for the values if
needed, however most of the information will have to be queried from the
platform in a platform specific call. Define a standard function to that
platform dependant stuff and implement it on a cpp file in the \win32
directory under the current one...
//! RED KNIGHT REVIEW: If you use inlines, put them under the \inline
directory
protected:
friend class XeFont;
String fontName;
Int32 size;
//! RED KNIGHT REVIEW: After the changes this MUST be
XeFont::FONTSTYLE.
Int32 style;
XeFont::FONTQUALITY quality;
XeFont::FONTQUALITY weight;
UInt32 baseList;
Int32 realSize;
std::vector<UInt8> horizontalCharSize;
};
}; // XenoEngine Namespace
//! RED KNIGHT REVIEW: There is lots of infomation that you can add here
that will make text management far easier, specially when you have to do
something difficult.
//! This is taken from the W32 SDK but it will give you some idea of what
else you can add to this.
/*
The TEXTMETRIC structure contains basic information about a physical font.
All sizes are given in logical units; that is, they depend on the current
mapping mode of the display context.
tmHeight : Specifies the height (ascent + descent) of characters.
tmAscent : Specifies the ascent (units above the base line) of characters.
tmDescent : Specifies the descent (units below the base line) of characters.
tmInternalLeading : Specifies the amount of leading (space) inside the
bounds set by the tmHeight member. Accent marks and other diacritical
characters may occur in this area. The designer may set this member to zero.
tmExternalLeading : Specifies the amount of extra leading (space) that the
application adds between rows. Since this area is outside the font, it
contains no marks and is not altered by text output calls in either OPAQUE
or TRANSPARENT mode. The designer may set this member to zero.
tmAveCharWidth : Specifies the average width of characters in the font
(generally defined as the width of the letter x). This value does not
include the overhang required for bold or italic characters.
tmMaxCharWidth : Specifies the width of the widest character in the font.
*/
lazyevaluation.h
#include <utility/common.h>
namespace Utility
{
//! Lazy evaluation allows you to create a single copy of an item
//! that is referenced by multiple instances of an object
template <class T>
class LazyEvaluation
{
public:
//! RED KNIGHT REVIEW: Do not use 0 when what you need is NULL.
//! RED KNIGHT REVIEW: initial in not the better name for it, i
guess that initial is and instance, am I right?. Use identifiers as much
bigger as you need to make the code readable.
LazyEvaluation(const T& initial,void (*destroy)(T& todestroy) = 0);
LazyEvaluation(const LazyEvaluation& obj);
~LazyEvaluation();
LazyEvaluation& operator=(const LazyEvaluation& obj);
T& operator*();
T& operator->();
private:
LazyEvaluation();
//! RED KNIGHT REVIEW: Do not use underscores for variables or
methods names, only on enum values and at the beginning.
//! RED KNIGHT REVIEW: Please document what is the meaning of this
and why you did it this way, that is because is difficult to read, we should
do that for every construct that can become ambiguous or not show its
meaning and use on a first glance.
void (*m_destroy)(T& todestroy);
//! RED KNIGHT REVIEW: Do not use underscores for variables or
methods names, only on enum values and at the beginning.
UInt32& m_count;
//! RED KNIGHT REVIEW: Do not use underscores for variables or
methods names, only on enum values and at the beginning.
T& m_value;
};
}
Greetings
Red Knight
----- Original Message -----
From: "Ed Ray" <Ed...@tu...>
To: <xen...@li...>
Sent: Tuesday, July 29, 2003 5:16 AM
Subject: [Xenocide-programming] Fritz here, Font/Text renderer header files.
> At 05:59 PM 7/28/2003 -0300, you wrote:
>
> I have the header files done for the text renderer, as well as the new
font
> control. Of course, since they are untested header files, they are sure to
> be full of errors, though I ran a surface compiler through them to get rid
> of any syntax/container errors.
>
> Let me know what you think. I'm going to head to bed now. :-)
>
> >And I recommend to tag those methods with the \deprecated (or something
> >like that) in the doxygen documentation too. And with a descriptive
> >description of how it is done in the new system...
> >
> >Greetings
> >Red Knight
> >
> >----- Original Message -----
> >From: "mamutas" <ma...@pr...>
> >To: <xen...@li...>
> >Sent: Saturday, July 26, 2003 11:34 PM
> >Subject: RE: [Xenocide-programming] Fritz here, Font/Text engine makeover
> >proposal.
> >
> >
> >> Hi Ed,
> >>
> >> Welcome to the team.
> >>
> >> You plan looks very reasonable and well thought through. I am in
> >aticipation
> >> to see its results.
> >>
> >> As a suggestion about deprecated functions, I recommend to insert an
> >> assertion call in each of them. Thus every time the depricated function
> >will
> >> be called, the entry will be put in the log indicating that. Those
> >functions
> >> are defined in QA library, advanceassert.h.
> >>
> >> Regards,
> >> mamutas
> >>
> >>
> >> -----Original Message-----
> >> From: xen...@li...
> >> [mailto:xen...@li...] On Behalf Of
Ed
> >> Ray
> >> Sent: Saturday, July 26, 2003 1:44 AM
> >> To: xen...@li...
> >> Subject: [Xenocide-programming] Fritz here, Font/Text engine makeover
> >> proposal.
> >>
> >>
> >> Howdy all, new programmer on the team here, and it seems my first job
is
> >to
> >> improve our font/text engine's capabilities. Without further ado, here
> >goes.
> >>
> >> Current issues with the displaying of text:
> >>
> >> Text functions are currently scattered within the XeOpenGLRenderer and
> >> various other functions. Fonts are free-floating objects, with no
current
> >> management, which is not good as they are very resource-hungry.
Font/Text
> >> interaction has very limited flexability without being done by hand.
Fonts
> >> have few tools to make life easier, only width/height checking.
> >>
> >> Solution:
> >> Create XeTextRenderer, make it accessable through the XeOpenGLRenderer.
> >> Encapsulate all text drawing functionality into the XeTextRenderer.
> >> Encapsulate font management into the XeTextRenderer.
> >>
> >> The XeTextRenderer will have the following capability:
> >> -Create, manage, and select fonts
> >> -Deal with rotation, vertical vs horizontal drawing.
> >> -Scale or style fonts/strings to fit inside restrictive boxes (So
> >> the text fits in the button).
> >> -Draw text on a 2d surface.
> >> -Draw text in 3d, if necessary.
> >> -Be accessible through XeOpenGLRenderer.
> >>
> >> Text drawing is extremely simple, and there should not be any problem
> >> implementing the XeTextRenderer functions anywhere, as it will be a
simple
> >> call away from the renderer. The only issue will be obsoleting all the
> >> previous functions.
> >>
> >> The font memory management would probably best be done using a fairly
> >simple
> >> font handling technique. When you want a handle to a font, you tell the
> >> TextRenderer to build it, and it will use a lazy-evaluation class (ala
STL
> >> strings, one copy, many references to it) to produce the font lists.
There
> >> will of course be a way to define a default text, if you just want to
> >write
> >> something and have it be the same as "everything else". The lists are
the
> >> big memory-hog anyway, so having the handles use the same lists, but
> >> different 'other variables' (everything not defined when the font is
> >> created, eg: verticality, color) should be fine.
> >>
> >> The big 'issue' is that fonts are currently used in quite a few
different
> >> places in the code. I'll go ahead and keep everything backwards
compatible
> >> for now, because the only place that it is heavily used is in the
> >> WinToolkit, which I hear is geared for a heavy makeover. I'll comment
the
> >> functions as being obsolete in the code that are remaining for
backwards
> >> compatibility.
> >>
> >> I'll go ahead and wait till tomorrow to start drawing up the .h files,
to
> >> see if there are any concerns.
> >>
> >>
> >> Ed Ray
> >> --
> >> Ed...@tu...
> >> ICQ: 2271040
> >>
> >>
> >> -------------------------------------------------------
> >> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> >Data
> >> Reports, E-commerce, Portals, and Forums are available now. Download
today
> >> and enter to win an XBOX or Visual Studio .NET.
> >>
>
>http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
> >> _______________________________________________
> >> Xenocide-programming mailing list
> >Xen...@li...
> >> https://lists.sourceforge.net/lists/listinfo/xenocide-programming
> >>
> >>
> >> ---
> >> Incoming mail is certified Virus Free.
> >> Checked by AVG anti-virus system (http://www.grisoft.com).
> >> Version: 6.0.502 / Virus Database: 300 - Release Date: 7/18/2003
> >>
> >>
> >> ---
> >> Outgoing mail is certified Virus Free.
> >> Checked by AVG anti-virus system (http://www.grisoft.com).
> >> Version: 6.0.502 / Virus Database: 300 - Release Date: 7/18/2003
> >>
> >>
> >>
> >>
> >> -------------------------------------------------------
> >> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> >> Data Reports, E-commerce, Portals, and Forums are available now.
> >> Download today and enter to win an XBOX or Visual Studio .NET.
> >>
>
>http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
> >> _______________________________________________
> >> Xenocide-programming mailing list
> >> Xen...@li...
> >> https://lists.sourceforge.net/lists/listinfo/xenocide-programming
> >>
> >
> >
> >
> >
> >-------------------------------------------------------
> >This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> >Data Reports, E-commerce, Portals, and Forums are available now.
> >Download today and enter to win an XBOX or Visual Studio .NET.
>
>http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
> >_______________________________________________
> >Xenocide-programming mailing list
> >Xen...@li...
> >https://lists.sourceforge.net/lists/listinfo/xenocide-programming
> >
----------------------------------------------------------------------------
----
>
>
> Ed Ray
> --
> Ed...@tu...
> ICQ: 2271040
|