-
Notifications
You must be signed in to change notification settings - Fork 0
/
OgreText.h
108 lines (91 loc) · 3.05 KB
/
OgreText.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//-
//URL TO FREE OGRE TEXT CLASS http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Simple+text&structure=Cookbook
//----------------------------------------------------------------------------
// Lonewolff
//
// Filename: OgreText.h
// Description: Class for simple text in Ogre (Version 040507:18.30)
//-----------------------------------------------------------------------------
/*
How to make the program run:
OgreText *textItem=new OgreText;
textItem->setText("Hello World!"); // Text to be displayed
// Now it is possible to use the Ogre::String as parameter too
textItem->setPos(0.1f,0.1f); // Text position, using relative co-ordinates
textItem->setCol(1.0f,1.0f,1.0f,0.5f); // Text colour (Red, Green, Blue, Alpha)
delete textItem; // Must do this or there will be memory leaks
*/
#include <OGRE/Ogre.h>
#include "OgreTextAreaOverlayElement.h"
#include "OgreStringConverter.h"
using namespace Ogre;
#ifndef __OgreText_H__
#define __OgreText_H__
class OgreText
{
public:
OgreText()
{
olm=OverlayManager::getSingletonPtr();
if(init==0)
{
panel=static_cast<OverlayContainer*>(olm->createOverlayElement("Panel","GUI"));
panel->setMetricsMode(Ogre::GMM_PIXELS);
panel->setPosition(0,0);
panel->setDimensions(1.0f,1.0f);
overlay=olm->create("GUI_OVERLAY");
overlay->add2D(panel);
}
++(this->init);
szElement="element_"+StringConverter::toString(init);
overlay=olm->getByName("GUI_OVERLAY");
panel=static_cast<OverlayContainer*>(olm->getOverlayElement("GUI"));
textArea=static_cast<TextAreaOverlayElement*>(olm->createOverlayElement("TextArea",szElement));
panel->addChild(textArea);
overlay->show();
}
~OgreText()
{
szElement="element_"+StringConverter::toString(init);
olm->destroyOverlayElement(szElement);
--(this->init);
if(init==0)
{
olm->destroyOverlayElement("GUI");
olm->destroy("GUI_OVERLAY");
}
}
void setText(char *szString)
{
textArea->setCaption(szString);
textArea->setDimensions(1.0f,1.0f);
textArea->setMetricsMode(Ogre::GMM_RELATIVE);
textArea->setFontName("BlueHighway");
textArea->setCharHeight(0.03f);
}
void setText(String szString) // now You can use Ogre::String as text
{
textArea->setCaption(szString);
textArea->setDimensions(1.0f,1.0f);
textArea->setMetricsMode(Ogre::GMM_RELATIVE);
textArea->setFontName("BlueHighway");
textArea->setCharHeight(0.03f);
}
void setPos(float x,float y)
{
textArea->setPosition(x,y);
}
void setCol(float R,float G,float B,float I)
{
textArea->setColour(Ogre::ColourValue(R,G,B,I));
}
private:
OverlayManager *olm;
OverlayContainer *panel ;
Overlay *overlay;
TextAreaOverlayElement *textArea;
static int init;
String szElement;
};
int OgreText::init=0;
#endif