Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/graphics/text_engine/resource_font.cc @ 9839

Last change on this file since 9839 was 9839, checked in by bensch, 18 years ago

Font completely ported to the new Resource-Format.
Now all the Basic Resources previously loaded from a central ResourceManager are Distributed over the Resource-Types

File size: 1.6 KB
RevLine 
[9781]1
[9837]2#include "resource_font.h"
[9823]3#include "substring.h"
4#include "multi_type.h"
[9790]5#include "debug.h"
[9781]6
7
[9839]8ResourceFont::ResourceFont(const std::string& fontName, unsigned int renderSize)
9  : Font(), NewResource(&ResourceFont::type)
[9784]10{
[9839]11  assert(!fontName.empty());
12  Resources::StorePointer* ptr = this->acquireResource(fontName + ',' + MultiType((int)renderSize).getString());
[9781]13
[9784]14  if (ptr)
[9786]15  {
[9839]16    PRINTF(5)("FOUND FONT: %s\n", fontName.c_str());
17    this->Font::acquireData(static_cast<ResourceFont::FontResourcePointer*>(ptr)->ptr());
[9786]18  }
[9784]19  else
20  {
[9839]21    PRINTF(5)("NOT FOUND FONT: %s\n", fontName.c_str());
22    std::string fileName = this->NewResource::locateFile(fontName);
23
24    printf("FONTFILE %s TO %s\n", fontName.c_str(), fileName.c_str());
25
26    this->Font::loadFontFromTTF(fileName, renderSize);
27    this->NewResource::addResource(new ResourceFont::FontResourcePointer(fontName + ',' + MultiType((int)renderSize).getString(), Resources::KeepLevel(0), this->Font::dataPointer()));
[9784]28  }
29}
30
[9837]31ResourceFont ResourceFont::createFromString(const std::string& loadString)
[9823]32{
33  SubString loadValues(loadString, ',');
[9839]34  std::string fontName;
35  unsigned int renderSize = 20;
[9823]36  if (loadValues.size() > 0)
[9839]37    fontName = loadValues[0];
[9823]38  if (loadValues.size() > 1)
[9839]39    renderSize = (unsigned int)MultiType(loadValues[2]).getInt();
[9784]40
[9839]41  return ResourceFont(fontName, renderSize);
[9823]42}
[9784]43
44
45
[9837]46Resources::tType<ResourceFont> ResourceFont::type("Font");
[9784]47
48
[9823]49
50
51
[9837]52ResourceFont::FontResourcePointer::FontResourcePointer(const std::string& loadString, const Resources::KeepLevel& keepLevel, const FontData::Pointer& data)
[9791]53    : Resources::StorePointer(loadString, keepLevel) , pointer(data)
[9785]54{}
[9781]55
56
Note: See TracBrowser for help on using the repository browser.