Design Issue - Making a Font Global (C++, Marmalade) -


i have marmalade c++ project built in font doesn't scale screen size. deal issue i'm making custom font, png , .xml file, containing (0,0) vector of each character, , each character's size. i'm creating instance of png, , drawing regions of in loop write on screen.

the issue i'm having scope of class. want used throughout entire project. static debuglogger use font, ui's, or gameobjects, need characters, use font. it's pre-built system.

the logger in project static class, static functions. custom font class have singleton, understanding, must instantiated object program draw images of it. did not make static. there clear cut answer type of problem? issue static class won't create reference singleton, , i've been told singleton avoided design perspective anyway!

thanks in advance guys!

here's code reference:

customfontclass

#ifndef _character_set_h_ #define _character_set_h_  #include "iw2d.h" #include "singleton.h" #include "baseimage.h" #include <map> #include <string>  typedef ciwarray<std::string> str_arr;  class characterset : public singleton<characterset> { public:     characterset();      void write(std::string, ciwfvec2, float);     void write(std::string, float, float, float);     void write(char, ciwfvec2, float);     void write(char, float, float, float);      bool isinitialised() const { return misinitialised; }      // space between characters equivalent 1 character width. float multiplies number. default .55f     void setfontspacing(float);  protected:     baseimage* mspcharacters;     bool initialise();  private:     std::map<const char, ciwfvec2> mfontmap;     static const std::string texture_path;     static const std::string texture_name;     static const ciwfvec2 mfontsize;         float mfontspacing;         str_arr matexturelocations;         bool misinitialised; };       #define characterset singleton<characterset>::getinstance()      #endif 

cpp

#include "iw2d.h" #include "singleton.h" #include "baseimage.h" #include "characterset.h" #include "iwlogger.h" #include <map> #include <sstream> #include <string>  const std::string characterset::texture_path = "textures/"; const std::string characterset::texture_name = "font_main.png"; const ciwfvec2 characterset::mfontsize = ciwfvec2(50, 63);   characterset::characterset() : singleton<characterset>() {     mfontspacing = 0.55f;     misinitialised = initialise(); };  void characterset::setfontspacing(float spacing) {     if (spacing != null)     {         mfontspacing = spacing;     } };  void characterset::write(std::string text, ciwfvec2 position = ciwfvec2(50,50), float fontsize = 25.0f) {     if (!text.empty())     {         mspcharacters->setsize(ciwfvec2(fontsize, fontsize));          float newposition = 0;         (char& c : text)         {             mspcharacters->setposition(ciwfvec2((position.x + newposition), position.y));              if (mfontmap.find(c) == mfontmap.end())             {                 std::stringstream ss;                 std::string mcharref;                 ss << c;                 ss >> mcharref;                  std::string error = "characterset::mfontmap[" + mcharref + "] - not exist!";                 iw_log_error(error);             }             else             {                 mspcharacters->render(mfontmap[c], mfontsize);             }              newposition += (fontsize * mfontspacing);         }     }     else     {         iw_log_error("characterset::write - std::string text empty!");     }  };  bool characterset::initialise() {     matexturelocations.push_back(std::string(texture_path + texture_name));     mspcharacters = new baseimage(matexturelocations[0].c_str());      if (mspcharacters == null)     {         iw_log_error("characterset::mspcharacters - failed create baseimage!");         return false;     }      //numerical symbols     mfontmap['1'] = ciwfvec2(0, 0);     mfontmap['2'] = ciwfvec2(50, 0);     mfontmap['3'] = ciwfvec2(100, 0);     mfontmap['4'] = ciwfvec2(150, 0);     mfontmap['5'] = ciwfvec2(200, 0); // ect... lots of these 

iwlogger

#ifndef _iw_logger_h_ #define _iw_logger_h_  #include "iwdebug.h" #include <string>  class iwlogger {     public:         iwlogger();          enum loglevel         {             info,             warn,             error         };          static void log(loglevel level, std::string msg);         static void log(loglevel level, std::string callingfunc, std::string msg);          static void logfailedresource(std::string callingfunc, std::string resourcepath);          static void logerror(std::string msg) { log(error, msg); }         static void logwarn(std::string msg) { log(warn, msg); }         static void loginfo(std::string msg) { log(info, msg); }          static void logerror(std::string callingfunc, std::string msg) { log(error, callingfunc, msg); }         static void logwarn(std::string callingfunc, std::string msg) { log(warn, callingfunc, msg); }         static void loginfo(std::string callingfunc, std::string msg) { log(info, callingfunc, msg); } };  #define iw_log_error(msg) iwlogger::logerror(__function__, msg) #define iw_log_warn(msg) iwlogger::logwarn(__function__, msg) #define iw_log_info(msg) iwlogger::loginfo(__function__, msg)  #define iw_log_failed_res(respath) iwlogger::logfailedresource(__function__, respath)  #endif 

cpp

#include "characterset.h" #include "iwlogger.h"  void iwlogger::log(iwlogger::loglevel level, std::string msg) {     switch (level)     {         case info:             iwtrace(info, (msg.c_str()));             break;         case warn:             iwtrace(warn, (msg.c_str()));             break;         case error:             iwtrace(error, (msg.c_str()));             break;         default:             iwtrace(error, ("iwlogger::log() - uncatered case! nothing log!"));             break;     } }  void iwlogger::log(iwlogger::loglevel level, std::string callingfunc, std::string msg) {     std::string finalmsg = callingfunc + "() - " + msg;     switch (level)     {         case info:             iwtrace(info, (finalmsg.c_str()));             break;         case warn:             iwtrace(warn, (finalmsg.c_str()));             break;         case error:             iwtrace(error, (finalmsg.c_str()));             break;         default:             iwtrace(error, ("iwlogger::log() - uncatered case! nothing log!"));             break;     } }  void iwlogger::logfailedresource(std::string callingfunc, std::string resourcepath) {     std::string msg = "failed load resource: " + resourcepath;     logerror(callingfunc, msg); } 

the error messages:

1>c:\users\...\source\framework\customfont.h(12): error c2504: 'singleton' : base class undefined (..\source\framework\baseobject.cpp)   1>c:\users\...\source\framework\customfont.h(12): error c2143: syntax error : missing ',' before '<' (..\source\framework\baseobject.cpp)   1>c:\users\nigel\...\source\framework\customfont.h(12): error c2504: 'singleton' : base class undefined (..\source\framework\customfont.cpp)   


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -