NOGDUS
December 17, 2018, 03:29:18 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Blogs Help Search Tags Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: How does MarkupText work?  (Read 5090 times)
0 Members and 1 Guest are viewing this topic.
Cycl0ne
Guest
« on: April 26, 2011, 10:08:45 AM »

Hi,

how does this work, and how does TextWindow work? Couldnt get it to run. I think i have to initialise the MarkupTextManager. Still guessing.

Want to write a console, where i can change options in game on the fly without compiling it allways new. (like quake & co. do).

Cheers
Logged
Mattias Gustavsson
Moderator
Member
*

Respect: 58
Offline Offline

Posts: 94



« Reply #1 on: April 27, 2011, 07:23:52 AM »

The markup text is a bit experimental in the current release - none of the released games are using it, so there's no sample for how to use it (but I could dig one out, if you need it - but I'm going away for about a week from tomorrow, and won't have internet access, so might no be very soon).

However, I don't think the markup text is the best option for a console - I would suggest to use DebugFont instead, which allows easy text output without even having to load any font data :-)

Actually, if you use the sprite object StaticText, without specifying a font, it will use the DebugFont as a default, so you could do a console window by having one StaticText object per line. But I think that personally, I'd build a custom sprite object using DebugFont directly (which could handle both drawing and input).
Logged
Cycl0ne
Guest
« Reply #2 on: April 27, 2011, 08:20:47 AM »

Ahh ok, i will build something myself.
Logged
Mattias Gustavsson
Moderator
Member
*

Respect: 58
Offline Offline

Posts: 94



« Reply #3 on: April 27, 2011, 08:55:05 AM »

The markup text will be quite useful once finished though - it will allow you to do simple html-like markup for text formating, bold/italic, different fonts, hyperlinks etc, all within a single Pixie sprite.

You can see an example of how it can look here:
http://mattiasgustavsson.com/Blog/thieves-and-warriors/ (all the text in this one is markup text)
Logged
Cycl0ne
Guest
« Reply #4 on: April 27, 2011, 03:47:01 PM »

oh yes look really nice. Happy holiday to you Smiley see you in 1 week or so Smiley
Logged
Cycl0ne
Guest
« Reply #5 on: April 28, 2011, 04:01:51 AM »

Ohh and while we are at it : how does your XML System work?
Logged
Mattias Gustavsson
Moderator
Member
*

Respect: 58
Offline Offline

Posts: 94



« Reply #6 on: April 30, 2011, 02:25:10 PM »

Oh, the XML system is fairly straightforward to use. One example of how it is used is the Font class (Font.h/Font.cpp). First thing you do is inherit from XMLObject

Code:
class Font:XMLObject

then, you add two overloaded virtual methods to the class

Code:
       virtual XMLObject* XML_Element(StringId _name, const XMLAttributeList& _attributes);
 
       virtual void XML_Attribute(StringId _name, const XMLVariant& _value);

These methods will be called by the XML system as data is parsed.

The implementation of those methods might look like this
Code:
//*** XML_Element ***
 
 XMLObject* Font::XML_Element(StringId _name, const XMLAttributeList& _attributes)
    {
    xmlCase(Character)
       {
       int ascii=xmlAttributeValue("ascii");
       if (ascii>=0 && ascii<=255)
          {
          Character& character=characters_[ascii];
          character.ascii=ascii;
          character.spacing=xmlAttributeValue("spacing");
          character.x=xmlAttributeValue("x");
          character.y=xmlAttributeValue("y");
          character.width=xmlAttributeValue("width");
          character.height=xmlAttributeValue("height");
          character.xoffset=xmlAttributeValue("xoffset");
          character.yoffset=xmlAttributeValue("yoffset");
          character.isBlank=xmlAttributeValue("blank");
          }
       }
 
    xmlCase(Layer)
       {
       char* filename=StrDup(xmlAttributeValue("filename"));
       layers_.Add(filename);     
       }
 
    return 0;
    }
 
 
 //*** XML_Attribute ***
 
 void Font::XML_Attribute(StringId _name, const XMLVariant& _value)
    {
    xmlCase(name)
       {
       name_=StringId(xmlValue);
       }
 
    xmlCase(size)
       {
       size_=xmlValue;
       }
 
    xmlCase(lineSpacing)
       {
       lineSpacing_=xmlValue;
       }
    }
 

To load a file, you just call LoadXML on your object, and it will load and parse the specified XML file, and call those methods as it parses the data.

The first method, XML_Element, is called every time an XML element is encountered in the data stream. You can use the xmlCase macro as a shortcut for doing an if... statement on each name. The macro makes sure that the comparison of the element names will be done using just a pointer comparison, rather than a full string compare, making it very efficient. There's also the xmlAttributeValue, which allows you to look up any attribute attached to that element, to store the value (alternatively, you can instead catch the attribute values in the second method, XML_Attribute, by using the xmlValue macro). Attribute values are given as the special type XMLVariant, which means you can assign it to any type of variable, and it will automatically convert it to the right type, making it very handy for reading data.

Btw, I've recently spent a bit of time integrating support for the YAML data definition format in Pixie, using a similar abstraction layer - I find YAML much easier to work with than XML, as it is more readable and easy to edit (and also, JSON is a subset of YAML, so it technically supports JSON as well). I'll personally be switching over to YAML for most things, but will leave XML support around, maybe as part of the main Pixie code base, but more likely as an optional extension - I'm a big believer in culling stuff out from the engine, to keep it mean and lean - not good to let it get too bloated Cheesy
Logged
Cycl0ne
Guest
« Reply #7 on: May 06, 2011, 06:43:52 AM »

Hi,

its me again. At the moment i havent got too many spare time to work and code again. But perhaps on the weekend it will change a bit. What i was wondering. Can i put .xml (or YAML) into an Archive? So i can distribute the .exe with a .bin (Archive) and get everything out of there?

How is your progress with ZLIB Archive? Cheesy And with YAML? And with Mirror/Turn of RLE Bitmaps? Smiley (I know questions, about questions Smiley
Logged
Mattias Gustavsson
Moderator
Member
*

Respect: 58
Offline Offline

Posts: 94



« Reply #8 on: May 06, 2011, 09:00:57 AM »

Yes, as long as you read data using the Asset class, you can put any files into an Archive and just have an EXE and a single data file for distribution. XML files (and later YAML as well) do read data using Assets, as does all other files in Pixie (including streaming OGG files etc).

I've not done much progress with the other stuff... not sure when I will get around to it Tongue
Logged
Tags:
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!