SmallChange
1.0.0
A collection of extensions to Coin3D
Loading...
Searching...
No Matches
SmTextureFont.h
1
#ifndef SM_TEXTURE_FONT_H
2
#define SM_TEXTURE_FONT_H
3
4
/**************************************************************************\
5
* Copyright (c) Kongsberg Oil & Gas Technologies AS
6
* All rights reserved.
7
*
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions are
10
* met:
11
*
12
* Redistributions of source code must retain the above copyright notice,
13
* this list of conditions and the following disclaimer.
14
*
15
* Redistributions in binary form must reproduce the above copyright
16
* notice, this list of conditions and the following disclaimer in the
17
* documentation and/or other materials provided with the distribution.
18
*
19
* Neither the name of the copyright holder nor the names of its
20
* contributors may be used to endorse or promote products derived from
21
* this software without specific prior written permission.
22
*
23
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
\**************************************************************************/
35
36
#include <Inventor/SbImage.h>
37
#include <Inventor/nodes/SoNode.h>
38
#include <Inventor/nodes/SoSubNode.h>
39
#include <Inventor/elements/SoReplacedElement.h>
40
#include <Inventor/elements/SoSubElement.h>
41
#include <Inventor/SbVec2f.h>
42
#include <Inventor/SbDict.h>
43
#include <SmallChange/basic.h>
44
45
class
SoGLImage
;
46
47
48
class
SMALLCHANGE_DLL_API
SmTextureFont
:
public
SoNode
{
49
typedef
SoNode
inherited
;
50
51
SO_NODE_HEADER(
SmTextureFont
);
52
53
public
:
54
class
SMALLCHANGE_DLL_API
FontImage
:
public
SbImage
{
55
public
:
56
FontImage
(
const
SbVec2s glyphsize,
57
const
int
leading,
58
const
int
ascent,
59
const
int
descent,
60
const
int
numcomponents
);
61
~FontImage
();
62
63
void
addGlyph(
unsigned
char
c
,
64
const
SbImage
& image,
65
const
int
width,
66
const
int
gfxwidth
= -1,
67
const
int
xoffset = 0);
68
int
getGlyphWidth(
unsigned
char
c
)
const
;
69
70
void
setKerning(
unsigned
char
glyph
,
unsigned
char
next,
int
kerning
);
71
int
getKerning(
unsigned
char
glyph
,
unsigned
char
next)
const
;
72
int
getXOffset(
unsigned
char
glyph
)
const
;
73
74
SoGLImage
* getGLImage(
void
)
const
;
75
76
SbVec2s getGlyphPositionPixels(
unsigned
char
c
)
const
;
77
const
SbVec2s & getGlyphSizePixels()
const
;
78
79
SbVec2f getGlyphPosition(
unsigned
char
c
)
const
;
80
SbVec2f getGlyphSize(
unsigned
char
c
)
const
;
81
82
int
getLeading()
const
;
83
int
getAscent()
const
;
84
int
getDescent()
const
;
85
int
height()
const
;
86
87
SbImage
getGlyphImage(
const
unsigned
char
c
)
const
;
88
89
int
stringWidth(
const
SbString &
s
)
const
;
90
void
renderString(
const
SbString &
s
,
91
const
SbVec3f
& pos,
92
const
bool
needglbeginend
=
true
)
const
;
93
94
private
:
95
FontImage
();
96
97
void
copyGlyph(
unsigned
char
c
,
const
SbImage
&
glyph
);
98
SbVec2s glyphsize;
99
int
numcomp;
100
int
leading;
101
int
ascent;
102
int
descent;
103
SoGLImage
* glimage;
104
short
glyphwidth[256];
105
short
gfxglyphwidth[256];
106
short
xoffset[256];
107
SbDict kerningdict;
108
109
};
110
111
static
void
initClass(
void
);
112
static
void
destroyClass(
void
);
113
114
SmTextureFont
(
void
);
115
116
virtual
void
doAction(
SoAction
*
action
);
117
virtual
void
GLRender(
SoGLRenderAction
*
action
);
118
virtual
void
pick(
SoPickAction
*
action
);
119
virtual
void
getBoundingBox(
SoGetBoundingBoxAction
*
action
);
120
121
virtual
void
setFont(
FontImage
* image);
122
virtual
const
FontImage
* getFont(
void
)
const
;
123
124
protected
:
125
virtual
~SmTextureFont
();
126
127
private
:
128
FontImage
* image;
129
};
130
131
class
SMALLCHANGE_DLL_API
SmTextureFontElement
:
public
SoReplacedElement
{
132
typedef
SoReplacedElement
inherited
;
133
134
SO_ELEMENT_HEADER(
SmTextureFontElement
);
135
public
:
136
static
void
initClass(
void
);
137
protected
:
138
virtual
~SmTextureFontElement
();
139
140
public
:
141
virtual
void
init(
SoState
* state);
142
static
void
set(
SoState
* state,
SoNode
* node,
143
SmTextureFont::FontImage
* image);
144
145
static
const
SmTextureFont::FontImage
* get(
SoState
*
const
state);
146
147
private
:
148
SmTextureFont::FontImage
* image;
149
};
150
151
class
SMALLCHANGE_DLL_API
SmTextureFontBundle
{
152
public
:
153
SmTextureFontBundle
(
SoAction
*
action
,
SoNode
* node =
NULL
);
154
~SmTextureFontBundle
();
155
156
void
begin()
const
;
157
void
renderString(
const
SbString &
string
,
158
const
SbVec3f
& pos)
const
;
159
void
end()
const
;
160
int
stringWidth(
const
SbString &
s
)
const
{
161
return
this->font->stringWidth(
s
);
162
}
163
int
getLeading()
const
{
164
return
this->font->getLeading();
165
}
166
int
getAscent()
const
{
167
return
this->font->getAscent();
168
}
169
int
getDescent()
const
{
170
return
this->font->getDescent();
171
}
172
int
height()
const
{
173
return
this->font->height();
174
}
175
176
private
:
177
178
SoState
* state;
179
SoNode
* node;
180
bool
didupdatecoin;
181
const
SmTextureFont::FontImage
* font;
182
};
183
184
185
#endif
// SM_TEXTURE_FONT_H
SbImage
SbList
Definition
misc/SbList.h:69
SbVec3f
SmTextureFontBundle
Definition
SmTextureFont.h:151
SmTextureFontElement
Definition
SmTextureFont.h:131
SmTextureFont::FontImage
Definition
SmTextureFont.h:54
SmTextureFont
The SmTextureFont is used for setting up a texture font used by SmTextureText2.
Definition
SmTextureFont.h:48
SoAction
SoNode
SoReplacedElement
lib
SmallChange
nodes
SmTextureFont.h
Generated on Tue Sep 10 2024 20:35:47 for SmallChange by
1.10.0