SmartGUI font Interface

Source: Internet
Author: User

I finally wrote the SmartGUi library in half, and the basic architecture was built up.
Now I plan to write a blog for development.
Although I have done GUI before, I still want to do it well this time (it would be nice if I name it like CEGUI or MYGUI)

Let's talk about the GUI font interface first.
It should be said that the location in this database is irrelevant to the specific rendering machine.
Then we need a specific rendering plug-in.

Obviously, there are three main parts for GUI:
1. Texture/bitmap
2. Font
3. Draw Basic Elements
Of course there are other...

Below is the abstract base class CORE_BEGIN_NAMESPACE of the basic font.

Class GUI_EXPORT GFont: public Object
{
Public:
Const static int LEFT =-1;
Const static int TOP =-1;
Const static int CENTER = 0;
Const static int RIGHT = 1;
Const static int BOTTOM = 1;
Public:
Virtual ~ GFont ();
Virtual gstring GetFileName () const = 0;
Virtual int GetFontSize () = 0;
Virtual int GetLineHeight () const = 0;
Virtual int GetWidth (const gstring & text) const = 0;
Virtual int GetHitCharIndex (const gstring & text, float offset) const = 0;
Virtual void Render (const gstring & text, const Recti & area,
Int halignment = CENTER,
Int valignment = CENTER,
Bool oneline = true) = 0;
DECLARE_OBJECT (GFont)
};

CORE_END_NAMESPACE
Basic understanding of function Functions
It must be noted that
1. GetHitCharIndex is the character number for the given offset in this document.
2. This does not provide a function to Render a given text at a given position. Instead, it provides a more intimate Render to Render the text in a given rectangle-you can specify the method and whether to Render the text for multiple rows.
3. There are no more complex font properties, such as italic, underline, and bold.

A related font factory object is as follows: CORE_BEGIN_NAMESPACE

Class GUI_EXPORT GFontFactory: public Object
{
Public:
Virtual ~ GFontFactory ();
Virtual boost: shared_ptr <GFont> CreateFont (const gstring & font, int size) = 0;
DECLARE_OBJECT (GFontFactory)
};

CORE_END_NAMESPACE: generate a font pointer Based on the font file and font size.
Another related object is FontManager.
The interface is as follows: CORE_BEGIN_NAMESPACE

Class GUI_EXPORT GFontManager:
Public Manager <boost: shared_ptr <GFont>,
Public GSerializer
{
Public:
Bool AddFont (const gstring & name, const gstring & font, int size, bool del = false );
Gstring GetSerializerTag () {return "fontlist ";}
Bool Load (boost: shared_ptr <XMLNode> node );
Bool Save (boost: shared_ptr <XMLDocument> doc, boost: shared_ptr <XMLNode> & node );
Apiuse
Void SetFontFactory (boost: shared_ptr <GFontFactory> factory );
Private:
Boost: shared_ptr <GFontFactory> factory;
DEFINE_SINGLETON (GFontManager)
};

CORE_END_NAMESPACE
1. Apparently the font manager is a single piece
2. The SetFontFactory () function is provided to the plug-in to set a specific font factory, so here there is a flag apiuse
3. The GetSerializerTag, Load, and Save functions are inherited from GSerializer to provide serialization and deserialization of fonts. Our GUI should be as automated as possible.

In SmartGUI, the font system basically consists of these three objects. In the future, the changes will not be too large, and only function interfaces may be added.

In addition, this font system is easy to understand from the perspective of design patterns.

------------------------------------------------------------ Mark
Interfaces are more important than implementations.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.