| 192 | | cursor.x() = 500; |
| 193 | | cursor.y() = margin; |
| | 207 | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| | 208 | // |
| | 209 | // Examples of how to set up different alignments |
| | 210 | // |
| | 211 | |
| | 212 | osg::Vec4 alignmentSizeColor(0.0f,1.0f,0.0f,1.0f); |
| | 213 | float alignmentCharacterSize = 25.0f; |
| | 214 | cursor.x() = 640; |
| | 215 | cursor.y() = margin*4.0f; |
| | 216 | |
| | 217 | typedef std::pair<osgText::Text::AlignmentType,std::string> AlignmentPair; |
| | 218 | typedef std::vector<AlignmentPair> AlignmentList; |
| | 219 | AlignmentList alignmentList; |
| | 220 | alignmentList.push_back(AlignmentPair(osgText::Text::LEFT_TOP,"text->setAlignment(osgText::Text::LEFT_TOP);")); |
| | 221 | alignmentList.push_back(AlignmentPair(osgText::Text::LEFT_CENTER,"text->setAlignment(osgText::Text::LEFT_CENTER);")); |
| | 222 | alignmentList.push_back(AlignmentPair(osgText::Text::LEFT_BOTTOM,"text->setAlignment(osgText::Text::LEFT_BOTTOM);")); |
| | 223 | alignmentList.push_back(AlignmentPair(osgText::Text::CENTER_TOP,"text->setAlignment(osgText::Text::CENTER_TOP);")); |
| | 224 | alignmentList.push_back(AlignmentPair(osgText::Text::CENTER_CENTER,"text->setAlignment(osgText::Text::CENTER_CENTER);")); |
| | 225 | alignmentList.push_back(AlignmentPair(osgText::Text::CENTER_BOTTOM,"text->setAlignment(osgText::Text::CENTER_BOTTOM);")); |
| | 226 | alignmentList.push_back(AlignmentPair(osgText::Text::RIGHT_TOP,"text->setAlignment(osgText::Text::RIGHT_TOP);")); |
| | 227 | alignmentList.push_back(AlignmentPair(osgText::Text::RIGHT_CENTER,"text->setAlignment(osgText::Text::RIGHT_CENTER);")); |
| | 228 | alignmentList.push_back(AlignmentPair(osgText::Text::RIGHT_BOTTOM,"text->setAlignment(osgText::Text::RIGHT_BOTTOM);")); |
| | 229 | alignmentList.push_back(AlignmentPair(osgText::Text::BASE_LINE,"text->setAlignment(osgText::Text::BASE_LINE);//default")); |
| 196 | | |
| | 232 | { |
| | 233 | for(AlignmentList::iterator itr=alignmentList.begin(); |
| | 234 | itr!=alignmentList.end(); |
| | 235 | ++itr) |
| | 236 | { |
| | 237 | osg::Geode* alignmentGeode = new osg::Geode; |
| | 238 | sequence->addChild(alignmentGeode); |
| | 239 | sequence->setTime(sequence->getNumChildren(), 1.0f); |
| | 240 | |
| | 241 | osgText::Text* text = new osgText::Text; |
| | 242 | text->setFont(font); |
| | 243 | text->setColor(alignmentSizeColor); |
| | 244 | text->setCharacterSize(alignmentCharacterSize); |
| | 245 | text->setPosition(cursor); |
| | 246 | text->setDrawMode(osgText::Text::TEXT|osgText::Text::ALIGNMENT|osgText::Text::BOUNDINGBOX); |
| | 247 | |
| | 248 | text->setAlignment(itr->first); |
| | 249 | text->setText(itr->second); |
| | 250 | |
| | 251 | alignmentGeode->addDrawable(text); |
| | 252 | |
| | 253 | |
| | 254 | } |
| | 255 | |
| | 256 | } |
| | 257 | |
| 201 | | // osg::Group* sequence = new osg::Group; |
| 202 | | // rootNode->addChild(sequence); |
| 203 | | |
| 204 | | { |
| 205 | | for(unsigned int i=osgText::Text::LEFT_TOP;i<=osgText::Text::BASE_LINE;i++) |
| 206 | | { |
| 207 | | osg::Geode* alignmentGeode = new osg::Geode; |
| 208 | | sequence->addChild(alignmentGeode); |
| 209 | | sequence->setTime(i, 1.0f); |
| 210 | | |
| 211 | | osgText::Text* text = new osgText::Text; |
| 212 | | text->setFont(font); |
| 213 | | text->setColor(characterSizeColor); |
| 214 | | text->setPosition(cursor); |
| 215 | | text->setDrawMode(osgText::Text::TEXT|osgText::Text::ALIGNMENT|osgText::Text::BOUNDINGBOX); |
| 216 | | |
| 217 | | text->setAlignment((osgText::Text::AlignmentType)i); |
| 218 | | |
| 219 | | text->setText("text->setAlignment();"); |
| 220 | | alignmentGeode->addDrawable(text); |
| 221 | | |
| 222 | | cursor.y() += 40.0f; |
| 223 | | |
| 224 | | |
| 225 | | } |
| 226 | | |
| 227 | | } |
| | 263 | |
| | 264 | |
| | 265 | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| | 266 | // |
| | 267 | // Examples of how to set up different fonts... |
| | 268 | // |
| | 269 | |
| | 270 | cursor.x() = margin*2.0f; |
| | 271 | cursor.y() = margin*2.0f; |
| | 272 | |
| | 273 | osg::Vec4 fontColor(1.0f,0.5f,0.0f,1.0f); |
| | 274 | float fontCharacterSize = 20.0f; |
| | 275 | float spacing = 40.0f; |
| | 276 | |
| | 277 | { |
| | 278 | osgText::Text* text = new osgText::Text; |
| | 279 | text->setColor(fontColor); |
| | 280 | text->setPosition(cursor); |
| | 281 | text->setCharacterSize(fontCharacterSize); |
| | 282 | |
| | 283 | text->setFont(0); |
| | 284 | text->setText("text->setFont(0); // inbuilt font."); |
| | 285 | geode->addDrawable(text); |
| | 286 | |
| | 287 | cursor.x() = text->getBound().xMax() + spacing ; |
| | 288 | } |
| | 289 | |
| | 290 | { |
| | 291 | osgText::Font* arial = osgText::readFontFile("fonts/arial.ttf"); |
| | 292 | |
| | 293 | osgText::Text* text = new osgText::Text; |
| | 294 | text->setColor(fontColor); |
| | 295 | text->setPosition(cursor); |
| | 296 | text->setCharacterSize(fontCharacterSize); |
| | 297 | |
| | 298 | text->setFont(arial); |
| | 299 | text->setText(arial!=0? |
| | 300 | "text->setFont(\"fonts/arial.ttf\");": |
| | 301 | "unable to load \"fonts/arial.ttf\""); |
| | 302 | geode->addDrawable(text); |
| | 303 | |
| | 304 | cursor.x() = text->getBound().xMax() + spacing ; |
| | 305 | } |
| | 306 | |
| | 307 | { |
| | 308 | osgText::Font* times = osgText::readFontFile("fonts/times.ttf"); |
| | 309 | |
| | 310 | osgText::Text* text = new osgText::Text; |
| | 311 | text->setColor(fontColor); |
| | 312 | text->setPosition(cursor); |
| | 313 | text->setCharacterSize(fontCharacterSize); |
| | 314 | |
| | 315 | geode->addDrawable(text); |
| | 316 | text->setFont(times); |
| | 317 | text->setText(times!=0? |
| | 318 | "text->setFont(\"fonts/times.ttf\");": |
| | 319 | "unable to load \"fonts/times.ttf\""); |
| | 320 | |
| | 321 | cursor.x() = text->getBound().xMax() + spacing ; |
| | 322 | } |
| | 323 | |
| | 324 | cursor.x() = margin*2.0f; |
| | 325 | cursor.y() = margin; |
| | 326 | |
| | 327 | { |
| | 328 | osgText::Font* dirtydoz = osgText::readFontFile("fonts/dirtydoz.ttf"); |
| | 329 | |
| | 330 | osgText::Text* text = new osgText::Text; |
| | 331 | text->setColor(fontColor); |
| | 332 | text->setPosition(cursor); |
| | 333 | text->setCharacterSize(fontCharacterSize); |
| | 334 | |
| | 335 | text->setFont(dirtydoz); |
| | 336 | text->setText(dirtydoz!=0? |
| | 337 | "text->setFont(\"fonts/dirtydoz.ttf\");": |
| | 338 | "unable to load \"fonts/dirtydoz.ttf\""); |
| | 339 | geode->addDrawable(text); |
| | 340 | |
| | 341 | cursor.x() = text->getBound().xMax() + spacing ; |
| | 342 | } |
| | 343 | |
| | 344 | { |
| | 345 | osgText::Font* fudd = osgText::readFontFile("fonts/fudd.ttf"); |
| | 346 | |
| | 347 | osgText::Text* text = new osgText::Text; |
| | 348 | text->setColor(fontColor); |
| | 349 | text->setPosition(cursor); |
| | 350 | text->setCharacterSize(fontCharacterSize); |
| | 351 | |
| | 352 | text->setFont(fudd); |
| | 353 | text->setText(fudd!=0? |
| | 354 | "text->setFont(\"fonts/fudd.ttf\");": |
| | 355 | "unable to load \"fonts/fudd.ttf\""); |
| | 356 | geode->addDrawable(text); |
| | 357 | |
| | 358 | cursor.x() = text->getBound().xMax() + spacing ; |
| | 359 | } |