kungfoomasta
26-04-2008 00:19:38
So first of all, I want to allow the following kind of functionality with Text:
- mix colors on a character by character basis
- mix fonts on a character by character basis
- organize text and properties in a format that is accessible for rendering
Part of the problem here is that I don't know where to draw the line between responsibilities of my "Text" class, and responsibilities of say a "TextBox" class.
A note on how rendering works: I have followed the RBGUI example by having a "Brush" class. This Brush class is used to draw to the screen. The common use of the class is to draw textured rectangles on the screen. This could be used for each character within a body of Text, however it would be more convenient to batch these rectangles together. Also note that we can only batch characters of the same font and color together.
Another important point: This is the first draft, it doesn't have to be the most optimized process in the world. We should focus on having a concrete implementation, and after its all working, we can analyze weaknesses and strengths, and upgrade to more efficient methods.
So here is my current thoughts...
The Text class will manage text (UTFString support via Ogre's classes), including fonts and colors. Rendering of Cursors and text highlighting will be done by Widgets and not the Text. The Text will make this process easier by providing functions to determine cursor positions based on a given position.
Here are some structs or classes I've been thinking about.. although its definately not set in stone.
I'm also not sure about how to organize the data. I wrote down that the Text class should build a list of TextLines, via the function:
Part of my problem is that I'm thinking of text box functionality, (or Text functionality) that is removing characters, adding in characters, etc.
I guess I'm mainly posting to see if anybody has any good ideas, or to show me my approach won't be a good one. Please post any ideas you have.
- mix colors on a character by character basis
- mix fonts on a character by character basis
- organize text and properties in a format that is accessible for rendering
Part of the problem here is that I don't know where to draw the line between responsibilities of my "Text" class, and responsibilities of say a "TextBox" class.
A note on how rendering works: I have followed the RBGUI example by having a "Brush" class. This Brush class is used to draw to the screen. The common use of the class is to draw textured rectangles on the screen. This could be used for each character within a body of Text, however it would be more convenient to batch these rectangles together. Also note that we can only batch characters of the same font and color together.
Another important point: This is the first draft, it doesn't have to be the most optimized process in the world. We should focus on having a concrete implementation, and after its all working, we can analyze weaknesses and strengths, and upgrade to more efficient methods.
So here is my current thoughts...
The Text class will manage text (UTFString support via Ogre's classes), including fonts and colors. Rendering of Cursors and text highlighting will be done by Widgets and not the Text. The Text will make this process easier by providing functions to determine cursor positions based on a given position.
Here are some structs or classes I've been thinking about.. although its definately not set in stone.
struct Character
{
codepoint,
Rect bounds
}
// Each Segment will be one rendering batch.
// This means all characters will have the same font/color
struct TextSegment
{
vector<Character>,
fontName,
colour
}
// I wrote this down originally, but I don't know how it fits with TextSegments..
struct TextLine
{
vector<Character>,
startIndex,
endIndex,
Rect bounds
}
I'm also not sure about how to organize the data. I wrote down that the Text class should build a list of TextLines, via the function:
Text::buildLineData(float maxWidth)
Part of my problem is that I'm thinking of text box functionality, (or Text functionality) that is removing characters, adding in characters, etc.
I guess I'm mainly posting to see if anybody has any good ideas, or to show me my approach won't be a good one. Please post any ideas you have.