示例#1
0
    void    LogManager::SetLogFile(const sf::String& logFile)
    {
        myLogFile.open(logFile.ToAnsiString().c_str(), std::ios::out | std::ios::trunc);

        if (!myLogFile)
            std::cerr << "Impossible d'ouvrir le fichier " << logFile.ToAnsiString() << std::endl;
    }
示例#2
0
文件: sfUtil.cpp 项目: Oberon00/jd
void breakTextLines(sf::Text& t, float maxX)
{
    sf::String s = t.getString();
    std::size_t lastBreakCharIdx = s.getSize();
    static sf::String const breakBeforeChars("([{\"'`'");
    static auto const isBreakBeforeChar = [] (sf::Uint32 c) {
        return breakBeforeChars.find(c) != sf::String::InvalidPos;
    };
    for (std::size_t i = 0; i < s.getSize(); ++i) {
        if (t.findCharacterPos(i).x > maxX) {
            if (lastBreakCharIdx > i)
                lastBreakCharIdx = i;
            if (s.getSize() > lastBreakCharIdx &&
                !std::iswgraph(static_cast<std::wint_t>(s[lastBreakCharIdx + 1]))
            ) {
                s[lastBreakCharIdx + 1] = '\n';
            } else {
                s.insert(lastBreakCharIdx + 1, '\n');
            }
            t.setString(s);
            i += 1;
        }
        if (!std::iswalnum(static_cast<std::wint_t>(s[i]))) {
            lastBreakCharIdx = i;
            if (i > 0 && isBreakBeforeChar(s[i]))
                lastBreakCharIdx -= 1;
        }
    }
}
示例#3
0
文件: Param.cpp 项目: Neckara/Patcher
void Param::lire_Texte(std::ifstream &fichier, sf::String &destination, sf::Font &myFont)
{
    std::string ligne;
    int x, y, z;
    lire_string(fichier, ligne);
    destination.SetText(traduire(ligne.c_str()));
    lire_position(fichier, x, y);
    destination.SetPosition(x, y);
    lire_string(fichier, ligne);
    if(ligne != "default" && !myFont.LoadFromFile(ligne))
    {
        std::cerr << "Erreur lors du chargement de la police '" << ligne << "'" << std::endl;
        myFont = sf::Font::GetDefaultFont();
    }
    else if(ligne == "default")
        myFont = sf::Font::GetDefaultFont();
    lire_int(fichier, x);
    destination.SetSize(x);
    lire_string(fichier, ligne);
    set_police(destination, ligne.c_str());
    lire_couleur(fichier, x, y, z);
    destination.SetColor(sf::Color(x, y, z));
    lire_int(fichier, x);
    destination.SetRotation(x);
}
示例#4
0
void drawScore(sf::RenderWindow& App, Player* player, sf::String& KillCount, 
               sf::String& Timer, sf::String& HP, sf::String& Score, int running_time)
{
    std::stringstream kill, s2, s3, s4;
    kill << player->getKill();

    KillCount.SetText("Kills: " + kill.str());
    App.Draw(KillCount);

    s2 << (int)running_time;
    std::string time_string;
    s2 >> time_string;      

    Timer.SetText("Time: " + time_string);
    App.Draw(Timer);

    s3 << player->getHealth()/100;
    std::string hp_string;
    s3 >> hp_string;

    HP.SetText("HP: " + hp_string);
    App.Draw(HP);

    s4 << player->getKill() + (int)running_time;
    std::string score_string;
    s4 >> score_string;

    Score.SetText("Score: " + score_string);
}
示例#5
0
文件: main.cpp 项目: Hanmac/sfml-ruby
VALUE wrap< sf::String >(const sf::String &cstr )
{

	std::string str(cstr.begin(),cstr.end());
#ifdef HAVE_RUBY_ENCODING_H
	return rb_enc_str_new(str.c_str(),strlen(str.c_str()),rb_utf8_encoding());
#else
	return rb_str_new2(str.c_str());
#endif
}
示例#6
0
void toDebugLog(const sf::String &pStr)
{
#ifndef DEBUG
	std::ofstream lfile;
	lfile.open(gDebugLog.ToAnsiString(), std::ios::app);
	lfile<<pStr.ToAnsiString()<<std::endl;
	lfile.close();
#else
	//std::cout<<pStr.ToAnsiString()<<std::endl;
#endif
}
示例#7
0
void KeyboardMenu::set_string_position(sf::String &string, int v_pos, int screen_width)
{
	if( default_hpos == HorizontalPositions::LEFT )
	{
		string.SetPosition(10, v_pos);
	}
	else
	{
		string.SetPosition(screen_width - string.GetRect().GetWidth() - 10, v_pos);
	}
}
示例#8
0
std::map<sf::String, sf::String> parseDataFile(const sf::String &pFile)
{
	std::map<sf::String, sf::String> lReturn;

	std::ifstream t(pFile.ToAnsiString());

	if(!t.is_open())
		return lReturn;

	std::string str;

	t.seekg(0, std::ios::end);   
	str.reserve(t.tellg());
	t.seekg(0, std::ios::beg);

	str.assign((std::istreambuf_iterator<char>(t)),
				std::istreambuf_iterator<char>());

	std::string lStrData(str);

	lStrData.erase(std::remove_if(lStrData.begin(), lStrData.end(), ::isspace), lStrData.end());
	
	std::vector<std::string> lLine = split(lStrData, ';');

	for(int i = 0; i < lLine.size(); i++)
	{
		std::vector<std::string> lValue = split(lLine.at(i), '=');

		lReturn[lValue.at(0)] = lValue.at(1);
	}

	return lReturn;
}
示例#9
0
std::vector<std::string> getAllFolders(const sf::String &pFolder)
{
	DIR *lDir;
	struct dirent *ent;

	std::vector<std::string> mReturn;

	// *********** IMAGE LOADING ****/////////////////////////
	lDir = opendir (pFolder.ToAnsiString().c_str());

	if (lDir != NULL) 
	{

	  /* print all the files and directories within directory */
	  while ((ent = readdir (lDir)) != NULL) 
	  {
		  if(ent->d_type == DT_DIR)
		  {
			  sf::String lStr(ent->d_name);
			  if(lStr == "." || lStr == "..")
				  continue;

			  mReturn.push_back(lStr.ToAnsiString());
		  }
	  }
	  closedir (lDir);
	}

	  return mReturn;
}
示例#10
0
文件: PC.cpp 项目: cakelake/FireFly
void PC::sendSfString(Entity* entity, sf::String message)
{
	playButtonSound();
	if(message.getSize() <= 5)
	{
		msfString = message;
	}
}
示例#11
0
void initDebugLog()
{
#ifndef DEBUG
	std::ofstream lfile;
	lfile.open(gDebugLog.ToAnsiString(), std::ios::out);
	lfile.close();
#endif
}
示例#12
0
文件: Shader.cpp 项目: tsingzhen/sf3d
    void    Program::Send(const sf::String& name, float value)
    {
        if (!myIsLinked)
            return;

        GLint loc = glGetUniformLocation(myProgram, name.ToAnsiString().c_str());
        glUseProgram(myProgram);
        glUniform1f(loc, value);
    }
示例#13
0
文件: Shader.cpp 项目: tsingzhen/sf3d
    // Program class
    Program::Program(const sf::String& vertex, const sf::String& fragment)
        :   myIsLinked(false)
    {
        myProgram = glCreateProgram();

        if (!vertex.IsEmpty())
        {
            Shader vShader(Shader::VERTEX_SHADER, vertex);
            Attach(vShader);
        }
        if (!fragment.IsEmpty())
        {
            Shader fShader(Shader::FRAGMENT_SHADER, fragment);
            Attach(fShader);
        }

        if (!fragment.IsEmpty() || !vertex.IsEmpty())
            Link();
    }
示例#14
0
// enforces limitations on XMPP  resource name
static sf::String fixResourceName (const sf::String & s) {
	// max 63 characters, no empties, no '/'
	sf::String result;
	for (size_t i = 0; i < 64 && i < s.length(); i++) {
		char c = s[i];
		if (c != '/' && c != '.' && c != '_' && c != ' '&& c >= 32 && c < 128) result += c;
	}
	if (result.empty()) result = "SF";
	return result;
}
示例#15
0
文件: Shader.cpp 项目: tsingzhen/sf3d
    void    Program::Send(const sf::String& name, const sf::Vector3f& vector)
    {
        if (!myIsLinked)
            return;

        GLint loc = glGetUniformLocation(myProgram, name.ToAnsiString().c_str());
        glUseProgram(myProgram);

        glUniform3f(loc, vector.x, vector.y, vector.z);
    }
示例#16
0
文件: Shader.cpp 项目: tsingzhen/sf3d
    void    Program::Send(const sf::String& name, Texture& texture)
    {
        if (!myIsLinked)
            return;

        GLint loc = glGetUniformLocation(myProgram, name.ToAnsiString().c_str());
        glUseProgram(myProgram);

        myTextures[loc] = &texture;
    }
示例#17
0
	ResourceCache::ResourceCache(sf::String& contentDirectory)
	{
		gLogger.Write("Resource Cache: Created");
		
		ContentDirectory = contentDirectory.ToAnsiString();
		
		gLogger.Write("Resource Cache: Directory: " + ContentDirectory);

		
	}
示例#18
0
文件: Shader.cpp 项目: tsingzhen/sf3d
    void    Program::Send(const sf::String& name, float f1, float f2, float f3, float f4)
    {
        if (!myIsLinked)
            return;

        GLint loc = glGetUniformLocation(myProgram, name.ToAnsiString().c_str());
        glUseProgram(myProgram);

        glUniform4f(loc, f1, f2, f3, f4);
    }
示例#19
0
文件: Button.hpp 项目: Zylann/Grid
 Button(int x, int y, int w, int h,
        const std::string & text,
        const sf::Font & font,
        WidgetContainer * parent = NULL)
 : Widget(x, y, w, h, parent)
 {
     m_renderText.SetFont(font);
     setText(text);
     m_action = NULL;
 }
示例#20
0
文件: TextBar.hpp 项目: Zylann/Grid
 TextBar(int x, int y, int w, int h,
         const sf::Font & font,
         GenericAction * enterAction = NULL,
         WidgetContainer * parent = NULL)
     : Widget(x, y, w, h, parent)
 {
     m_renderText.SetFont(font);
     setText("");
     m_enterAction = enterAction;
 }
示例#21
0
文件: Shader.cpp 项目: tsingzhen/sf3d
    Shader::Shader(ShaderType type, const sf::String& filename)
        :   myType(type)
    {
        if (type == VERTEX_SHADER)
            myShader = glCreateShader(GL_VERTEX_SHADER);
        else
            myShader = glCreateShader(GL_FRAGMENT_SHADER);

        if (!filename.IsEmpty())
            LoadFromFile(filename);
    }
示例#22
0
文件: Shader.cpp 项目: tsingzhen/sf3d
    void    Program::Send(const sf::String& name, const sf::Color& color)
    {
        if (!myIsLinked)
            return;

        float fcolor[4] = { static_cast<float>(color.r) / 255.f,
                            static_cast<float>(color.g) / 255.f,
                            static_cast<float>(color.b) / 255.f,
                            static_cast<float>(color.a) / 255.f };

        GLint loc = glGetUniformLocation(myProgram, name.ToAnsiString().c_str());
        glUseProgram(myProgram);

        glUniform4fv(loc, 4, fcolor);
    }
示例#23
0
int log_setup_1(){
	//Load Font
	if( PTSANS_loaded == false ){
		if (!PTSANS.LoadFromFile("PTN57F.ttf", 50)) return -1;
		PTSANS_loaded = true;
	}

	//Setup Strings
	log_string.SetFont( PTSANS );
	log_string.SetSize(24.f);
	log_string.SetColor( sf::Color(255, 255, 255) );
	log_string.SetPosition(100.f, 600.f);

	log_name.SetFont( PTSANS );
	log_name.SetSize(40.f);
	log_name.SetColor( sf::Color(255, 255, 255) );
	log_name.SetPosition(100.f, 550.f);
}
示例#24
0
void Logger::log(sf::String message)
{
	if (isLoggingEnabled)
	{
		time_t now = time(0);
		tm *localTime = localtime(&now);
		std::clog << 1900 + localTime->tm_year << ".";
		std::clog << 1 + localTime->tm_mon << ".";
		std::clog << localTime->tm_mday << ". ";
		std::clog << localTime->tm_hour << ":";
		std::clog << localTime->tm_min << ":";
		std::clog << localTime->tm_sec << " [";
		std::clog << className.toAnsiString() << "] ";
		std::clog << message.toAnsiString();
		std::clog << std::endl;
	}
}
示例#25
0
文件: Param.cpp 项目: Neckara/Patcher
void Param::set_police(sf::String &destination, const char *ligne)
{
    int i = 0;
    long unsigned int style = sf::String::Regular;
    while(ligne[i] != '\0')
    {
        switch(ligne[i])
        {
            case 's' :
            case 'u' :
            case 'S' :
            case 'U' :
                style |=  sf::String::Underlined;
            break;
            case 'b' :
            case 'g' :
            case 'B' :
            case 'G' :
                style |=  sf::String::Bold;
            break;
            case 'n' :
            case 'd' :
            case 'N' :
            case 'D' :
                style = sf::String::Regular;
            break;
            case 'i' :
            case 'I' :
                style |=  sf::String::Italic;
            break;
        }
        i++;
        while(ligne[i] != '|' && ligne[i] != '\0')
        {
            i++;
        }
        if(ligne[i] != '\0')
        {
            i++;
            if(ligne[i] == ' ')
                i++;
        }
    }
    destination.SetStyle(style);
}
示例#26
0
    void    InfoBox::draw(sf::RenderWindow& rw)
    {
        glColor3f(0.6, 0.6, 0.6);
        drawRectangle(start_, end_, true);

        static sf::String tx;
        tx.SetText("Status");
        tx.SetFont(sf::Font::GetDefaultFont());
        tx.SetStyle(sf::String::Bold);
        tx.SetPosition(start_[0] + 20, start_[1] + 20);
        tx.SetSize(16);
        rw.Draw(tx);
    }
示例#27
0
文件: Shader.cpp 项目: tsingzhen/sf3d
    void    Shader::LoadFromFile(const sf::String& filename)
    {
        std::fstream file;
        file.open(filename.ToAnsiString().c_str());
        if (file.fail())
        {
            return;
        }


        std::stringstream bufStr;
        bufStr << file.rdbuf();
        file.close();

        const char* buffer = bufStr.str().c_str();
        glShaderSource(myShader, 1, &buffer, NULL);

        glCompileShader(myShader);
        GLint status, logSize;
        glGetShaderiv(myShader, GL_COMPILE_STATUS, &status);

        if (status != GL_TRUE)
        {
            glGetShaderiv(myShader, GL_INFO_LOG_LENGTH, &logSize);
            char* log = new char[logSize + 1];
            memset(log, 0, logSize + 1);
            glGetShaderInfoLog(myShader, logSize, &logSize, log);

            std::cerr << "Unable to compile ";
            if (myType == VERTEX_SHADER)
                std::cerr << "vertex";
            else
                std::cerr << "fragment";

            std::cerr << " shader. Reason :" << std::endl;
            std::cerr << log << std::endl;
            delete[] log;
            return;
        }
    }
示例#28
0
void FontFunctions::InitString(sf::String& str, const int size)
{
	str.SetFont(FontFunctions::_font);
	str.SetColor(sf::Color::Black);
	str.SetSize(size);
}
示例#29
0
// Accepts input (stringin) and returns sf::String with corresponding kana
sf::String toKatakana (sf::String InputString)
{
	std::size_t InputLength = InputString.getSize();
	sf::Uint32 lastChar1 = 0;
	sf::Uint32 lastChar2 = 0;
	sf::Uint32 lastChar3 = 0;
	if (InputLength > 0)
		lastChar1 = InputString[(InputLength - 1)];
	if (InputLength > 1)
		lastChar2 = InputString[(InputLength - 2)];
	if (InputLength > 2)
		lastChar3 = InputString[(InputLength - 3)];
	
	// Return string
	sf::String kanaOut;
	// A/a	a
	if (lastChar1 == 65 || lastChar1 == 97)
	{
		// Y/y	ya
		if (lastChar2 == 89 || lastChar2 == 121)
		{
			// K/k	kya
			if (lastChar3 == 75 || lastChar3 == 107)
			{
				lastChar1 = 12461;
				kanaOut += lastChar1;
				lastChar2 = 12515;
				kanaOut += lastChar2;
			}
			// N/n	nya
			else if (lastChar3 == 78 || lastChar3 == 110)
			{
				lastChar1 = 12491;
				kanaOut += lastChar1;
				lastChar2 = 12515;
				kanaOut += lastChar2;
			}
			// H/h	hya
			else if (lastChar3 == 72 || lastChar3 == 104)
			{
				lastChar1 = 12498;
				kanaOut += lastChar1;
				lastChar2 = 12515;
				kanaOut += lastChar2;
			}
			// M/m	mya
			else if (lastChar3 == 77 || lastChar3 == 109)
			{
				lastChar1 = 12511;
				kanaOut += lastChar1;
				lastChar2 = 12515;
				kanaOut += lastChar2;
			}
			// R/r	rya
			else if (lastChar3 == 82 || lastChar3 == 114)
			{
				lastChar1 = 12522;
				kanaOut += lastChar1;
				lastChar2 = 12515;
				kanaOut += lastChar2;
			}
			// G/g	gya
			else if (lastChar3 == 71 || lastChar3 == 103)
			{
				lastChar1 = 12462;
				kanaOut += lastChar1;
				lastChar2 = 12515;
				kanaOut += lastChar2;
			}
			// B/b	bya
			else if (lastChar3 == 66 || lastChar3 == 98)
			{
				lastChar1 = 12499;
				kanaOut += lastChar1;
				lastChar2 = 12515;
				kanaOut += lastChar2;
			}
			// P/p	pya
			else if (lastChar3 == 80 || lastChar3 == 112)
			{
				lastChar1 = 12500;
				kanaOut += lastChar1;
				lastChar2 = 12515;
				kanaOut += lastChar2;
			}
			else
			{
				lastChar1 = 12516;
				kanaOut += lastChar1;
			}
		}
		// H/h	ha
		else if (lastChar2 == 72 || lastChar2 == 104)
		{
			// S/s	sha
			if (lastChar3 == 83 || lastChar3 == 115)
			{
				lastChar1 = 12471;
				kanaOut += lastChar1;
				lastChar2 = 12515;
				kanaOut += lastChar2;
			}
			// C/c	cha
			else if (lastChar3 == 67 || lastChar3 == 99)
			{
				lastChar1 = 12481;
				kanaOut += lastChar1;
				lastChar2 = 12515;
				kanaOut += lastChar2;
			}
			else
			{
				lastChar1 = 12495;
				kanaOut += lastChar1;
			}
		}
		// S/s	sa
		else if (lastChar2 == 83 || lastChar2 == 115)
		{
			lastChar1 = 12469;
			kanaOut += lastChar1;
		}
		// K/k	ka
		else if (lastChar2 == 75 || lastChar2 == 107)
		{
			lastChar1 = 12459;
			kanaOut += lastChar1;
		}
		// T/t	ta
		else if (lastChar2 == 84 || lastChar2 == 116)
		{
			lastChar1 = 12479;
			kanaOut += lastChar1;
		}
		// N/n	na
		else if (lastChar2 == 78 || lastChar2 == 110)
		{
			lastChar1 = 12490;
			kanaOut += lastChar1;
		}
		// M/m	ma
		else if (lastChar2 == 77 || lastChar2 == 109)
		{
			lastChar1 = 12510;
			kanaOut += lastChar1;
		}
		// R/r	ra
		else if (lastChar2 == 82 || lastChar2 == 114)
		{
			lastChar1 = 12521;
			kanaOut += lastChar1;
		}
		// W/w	wa
		else if (lastChar2 == 87 || lastChar2 == 119)
		{
			lastChar1 = 12527;
			kanaOut += lastChar1;
		}
		// G/g	ga
		else if (lastChar2 == 71 || lastChar2 == 103)
		{
			lastChar1 = 12460;
			kanaOut += lastChar1;
		}
		// Z/z	za
		else if (lastChar2 == 90 || lastChar2 == 122)
		{
			lastChar1 = 12470;
			kanaOut += lastChar1;
		}
		// D/d	da
		else if (lastChar2 == 68 || lastChar2 == 100)
		{
			lastChar1 = 12480;
			kanaOut += lastChar1;
		}
		// B/b	ba
		else if (lastChar2 == 66 || lastChar2 == 98)
		{
			lastChar1 = 12496;
			kanaOut += lastChar1;
		}
		// P/p	pa
		else if (lastChar2 == 80 || lastChar2 == 112)
		{
			lastChar1 = 12497;
			kanaOut += lastChar1;
		}
		// J/j	ja
		else if (lastChar2 == 74 || lastChar2 == 106)
		{
			lastChar1 = 12472;
			kanaOut += lastChar1;
			lastChar2 = 12515;
			kanaOut += lastChar2;
		}
		else
		{
			lastChar1 = 12450;
			kanaOut += lastChar1;
		}
	}
	// I/i	i
	else if (lastChar1 == 73 || lastChar1 == 105)
	{
		// H/h	hi
		if (lastChar2 == 72 || lastChar2 == 104)
		{
			// S/s	shi
			if (lastChar3 == 83 || lastChar3 == 115)
			{
				lastChar1 = 12471;
				kanaOut += lastChar1;
			}
			// C/c	chi
			else if (lastChar3 == 67 || lastChar3 == 99)
			{
				lastChar1 = 12481;
				kanaOut += lastChar1;
			}
			else
			{
				lastChar1 = 12498;
				kanaOut += lastChar1;
			}
		}
		// K/k	ki
		else if (lastChar2 == 75 || lastChar2 == 107)
		{
			lastChar1 = 12461;
			kanaOut += lastChar1;
		}
		// N/n	ni
		else if (lastChar2 == 78 || lastChar2 == 110)
		{
			lastChar1 = 12491;
			kanaOut += lastChar1;
		}
		// M/m	mi
		else if (lastChar2 == 77 || lastChar2 == 109)
		{
			lastChar1 = 12511;
			kanaOut += lastChar1;
		}
		// R/r	ri
		else if (lastChar2 == 82 || lastChar2 == 114)
		{
			lastChar1 = 12522;
			kanaOut += lastChar1;
		}
		// G/g	gi
		else if (lastChar2 == 71 || lastChar2 == 103)
		{
			lastChar1 = 12462;
			kanaOut += lastChar1;
		}
		// Z/z D/d J/j	ji
		else if (lastChar2 == 90 || lastChar2 == 122 || lastChar2 == 68 || lastChar2 == 100 || lastChar2 == 74 || lastChar2 == 106)
		{
			lastChar1 = 12472;
			kanaOut += lastChar1;
		}
		// B/b	bi
		else if (lastChar2 == 66 || lastChar2 == 98)
		{
			lastChar1 = 12499;
			kanaOut += lastChar1;
		}
		// P/p	pi
		else if (lastChar2 == 80 || lastChar2 == 112)
		{
			lastChar1 = 12500;
			kanaOut += lastChar1;
		}
		else
		{
			lastChar1 = 12452;
			kanaOut += lastChar1;
		}
	}
	// U/u	u
	else if (lastChar1 == 85 || lastChar1 == 117)
	{
		// Y/y	yu
		if (lastChar2 == 89 || lastChar2 == 121)
		{
			// K/k	kyu
			if (lastChar3 == 75 || lastChar3 == 107)
			{
				lastChar1 = 12461;
				kanaOut += lastChar1;
				lastChar2 = 12517;
				kanaOut += lastChar2;
			}
			// N/n	nyu
			else if (lastChar3 == 78 || lastChar3 == 110)
			{
				lastChar1 = 12491;
				kanaOut += lastChar1;
				lastChar2 = 12517;
				kanaOut += lastChar2;
			}
			// H/h	hyu
			else if (lastChar3 == 72 || lastChar3 == 104)
			{
				lastChar1 = 12498;
				kanaOut += lastChar1;
				lastChar2 = 12517;
				kanaOut += lastChar2;
			}
			// M/m	myu
			else if (lastChar3 == 77 || lastChar3 == 109)
			{
				lastChar1 = 12511;
				kanaOut += lastChar1;
				lastChar2 = 12517;
				kanaOut += lastChar2;
			}
			// R/r	ryu
			else if (lastChar3 == 82 || lastChar3 == 114)
			{
				lastChar1 = 12522;
				kanaOut += lastChar1;
				lastChar2 = 12517;
				kanaOut += lastChar2;
			}
			// G/g	gyu
			else if (lastChar3 == 71 || lastChar3 == 103)
			{
				lastChar1 = 12462;
				kanaOut += lastChar1;
				lastChar2 = 12517;
				kanaOut += lastChar2;
			}
			// B/b	byu
			else if (lastChar3 == 66 || lastChar3 == 98)
			{
				lastChar1 = 12499;
				kanaOut += lastChar1;
				lastChar2 = 12517;
				kanaOut += lastChar2;
			}
			// P/p	pyu
			else if (lastChar3 == 80 || lastChar3 == 112)
			{
				lastChar1 = 12500;
				kanaOut += lastChar1;
				lastChar2 = 12517;
				kanaOut += lastChar2;
			}
			else
			{
				lastChar1 = 12518;
				kanaOut += lastChar1;
			}
		}
		// H/h F/f	fu
		else if (lastChar2 == 72 || lastChar2 == 104 || lastChar2 == 70 || lastChar2 == 102)
		{
			// S/s	shu
			if (lastChar3 == 83 || lastChar3 == 115)
			{
				lastChar1 = 12471;
				kanaOut += lastChar1;
				lastChar2 = 12517;
				kanaOut += lastChar2;
			}
			// C/c	chu
			else if (lastChar3 == 67 || lastChar3 == 99)
			{
				lastChar1 = 12481;
				kanaOut += lastChar1;
				lastChar2 = 12517;
				kanaOut += lastChar2;
			}
			else
			{
				lastChar1 = 12501;
				kanaOut += lastChar1;
			}
		}
		// S/s	su
		else if (lastChar2 == 83 || lastChar2 == 115)
		{
			// T/t	tsu
			if (lastChar3 == 84 || lastChar3 == 116)
			{
				lastChar1 = 12484;
				kanaOut += lastChar1;
			}
			else
			{
				lastChar1 = 12473;
				kanaOut += lastChar1;
			}
		}
		// K/k	ku
		else if (lastChar2 == 75 || lastChar2 == 107)
		{
			lastChar1 = 12463;
			kanaOut += lastChar1;
		}
		// N/n	nu
		else if (lastChar2 == 78 || lastChar2 == 110)
		{
			lastChar1 = 12492;
			kanaOut += lastChar1;
		}
		// M/m	mu
		else if (lastChar2 == 77 || lastChar2 == 109)
		{
			lastChar1 = 12512;
			kanaOut += lastChar1;
		}
		// R/r	ru
		else if (lastChar2 == 82 || lastChar2 == 114)
		{
			lastChar1 = 12523;
			kanaOut += lastChar1;
		}
		// G/g	gu
		else if (lastChar2 == 71 || lastChar2 == 103)
		{
			lastChar1 = 12464;
			kanaOut += lastChar1;
		}
		// Z/z D/d	zu
		else if (lastChar2 == 90 || lastChar2 == 122 || lastChar2 == 68 || lastChar2 == 100)
		{
			lastChar1 = 12474;
			kanaOut += lastChar1;
		}
		// B/b	bu
		else if (lastChar2 == 66 || lastChar2 == 98)
		{
			lastChar1 = 12502;
			kanaOut += lastChar1;
		}
		// P/p	pu
		else if (lastChar2 == 80 || lastChar2 == 112)
		{
			lastChar1 = 12503;
			kanaOut += lastChar1;
		}
		// V/v	vu
		else if (lastChar2 == 86 || lastChar2 == 118)
		{
			lastChar1 = 12532;
			kanaOut += lastChar1;
		}
		// J/j	ju
		else if (lastChar2 == 74 || lastChar2 == 106)
		{
			lastChar1 = 12472;
			kanaOut += lastChar1;
			lastChar2 = 12517;
			kanaOut += lastChar2;
		}
		else
		{
			lastChar1 = 12454;
			kanaOut += lastChar1;
		}
	}
	// E/e	e
	else if (lastChar1 == 69 || lastChar1 == 101)
	{
		// H/h	he
		if (lastChar2 == 72 || lastChar2 == 104)
		{
			lastChar1 = 12504;
			kanaOut += lastChar1;
		}
		// S/s	se
		else if (lastChar2 == 83 || lastChar2 == 115)
		{
			lastChar1 = 12475;
			kanaOut += lastChar1;
		}
		// K/k	ke
		else if (lastChar2 == 75 || lastChar2 == 107)
		{
			lastChar1 = 12465;
			kanaOut += lastChar1;
		}
		// T/t	te
		else if (lastChar2 == 84 || lastChar2 == 116)
		{
			lastChar1 = 12486;
			kanaOut += lastChar1;
		}
		// N/n	ne
		else if (lastChar2 == 78 || lastChar2 == 110)
		{
			lastChar1 = 12493;
			kanaOut += lastChar1;
		}
		// M/m	me
		else if (lastChar2 == 77 || lastChar2 == 109)
		{
			lastChar1 = 12513;
			kanaOut += lastChar1;
		}
		// R/r	re
		else if (lastChar2 == 82 || lastChar2 == 114)
		{
			lastChar1 = 12524;
			kanaOut += lastChar1;
		}
		// G/g	ge
		else if (lastChar2 == 71 || lastChar2 == 103)
		{
			lastChar1 = 12466;
			kanaOut += lastChar1;
		}
		// Z/z	ze
		else if (lastChar2 == 90 || lastChar2 == 122)
		{
			lastChar1 = 12476;
			kanaOut += lastChar1;
		}
		// D/d	de
		else if (lastChar2 == 68 || lastChar2 == 100)
		{
			lastChar1 = 12487;
			kanaOut += lastChar1;
		}
		// B/b	be
		else if (lastChar2 == 66 || lastChar2 == 98)
		{
			lastChar1 = 12505;
			kanaOut += lastChar1;
		}
		// P/p	pe
		else if (lastChar2 == 80 || lastChar2 == 112)
		{
			lastChar1 = 12506;
			kanaOut += lastChar1;
		}
		else
		{
			lastChar1 = 12456;
			kanaOut += lastChar1;
		}
	}
	// O/o	o
	else if (lastChar1 == 79 || lastChar1 == 111)
	{
		// Y/y	yo
		if (lastChar2 == 89 || lastChar2 == 121)
		{
			// K/k	kyo
			if (lastChar3 == 75 || lastChar3 == 107)
			{
				lastChar1 = 12461;
				kanaOut += lastChar1;
				lastChar2 = 12519;
				kanaOut += lastChar2;
			}
			// N/n	nyo
			else if (lastChar3 == 78 || lastChar3 == 110)
			{
				lastChar1 = 12491;
				kanaOut += lastChar1;
				lastChar2 = 12519;
				kanaOut += lastChar2;
			}
			// H/h	hyo
			else if (lastChar3 == 72 || lastChar3 == 104)
			{
				lastChar1 = 12498;
				kanaOut += lastChar1;
				lastChar2 = 12519;
				kanaOut += lastChar2;
			}
			// M/m	myo
			else if (lastChar3 == 77 || lastChar3 == 109)
			{
				lastChar1 = 12511;
				kanaOut += lastChar1;
				lastChar2 = 12519;
				kanaOut += lastChar2;
			}
			// R/r	ryo
			else if (lastChar3 == 82 || lastChar3 == 114)
			{
				lastChar1 = 12522;
				kanaOut += lastChar1;
				lastChar2 = 12519;
				kanaOut += lastChar2;
			}
			// G/g	gyo
			else if (lastChar3 == 71 || lastChar3 == 103)
			{
				lastChar1 = 12462;
				kanaOut += lastChar1;
				lastChar2 = 12519;
				kanaOut += lastChar2;
			}
			// B/b	byo
			else if (lastChar3 == 66 || lastChar3 == 98)
			{
				lastChar1 = 12499;
				kanaOut += lastChar1;
				lastChar2 = 12519;
				kanaOut += lastChar2;
			}
			// P/p	pyo
			else if (lastChar3 == 80 || lastChar3 == 112)
			{
				lastChar1 = 12500;
				kanaOut += lastChar1;
				lastChar2 = 12519;
				kanaOut += lastChar2;
			}
			else
			{
				lastChar1 = 12520;
				kanaOut += lastChar1;
			}
		}
		// H/h	ho
		else if (lastChar2 == 72 || lastChar2 == 104)
		{
			// S/s	sho
			if (lastChar3 == 83 || lastChar3 == 115)
			{
				lastChar1 = 12471;
				kanaOut += lastChar1;
				lastChar2 = 12519;
				kanaOut += lastChar2;
			}
			// C/c	cho
			else if (lastChar3 == 67 || lastChar3 == 99)
			{
				lastChar1 = 12481;
				kanaOut += lastChar1;
				lastChar2 = 12519;
				kanaOut += lastChar2;
			}
			else
			{
				lastChar1 = 12507;
				kanaOut += lastChar1;
			}
		}
		// S/s	so
		else if (lastChar2 == 83 || lastChar2 == 115)
		{
			lastChar1 = 12477;
			kanaOut += lastChar1;
		}
		// K/k	ko
		else if (lastChar2 == 75 || lastChar2 == 107)
		{
			lastChar1 = 12467;
			kanaOut += lastChar1;
		}
		// T/t	to
		else if (lastChar2 == 84 || lastChar2 == 116)
		{
			lastChar1 = 12488;
			kanaOut += lastChar1;
		}
		// N/n	no
		else if (lastChar2 == 78 || lastChar2 == 110)
		{
			lastChar1 = 12494;
			kanaOut += lastChar1;
		}
		// M/m	mo
		else if (lastChar2 == 77 || lastChar2 == 109)
		{
			lastChar1 = 12514;
			kanaOut += lastChar1;
		}
		// R/r	ro
		else if (lastChar2 == 82 || lastChar2 == 114)
		{
			lastChar1 = 12525;
			kanaOut += lastChar1;
		}
		// W/w	wo
		else if (lastChar2 == 87 || lastChar2 == 119)
		{
			lastChar1 = 12530;
			kanaOut += lastChar1;
		}
		// G/g	go
		else if (lastChar2 == 71 || lastChar2 == 103)
		{
			lastChar1 = 12468;
			kanaOut += lastChar1;
		}
		// Z/z	zo
		else if (lastChar2 == 90 || lastChar2 == 122)
		{
			lastChar1 = 12478;
			kanaOut += lastChar1;
		}
		// D/d	do
		else if (lastChar2 == 68 || lastChar2 == 100)
		{
			lastChar1 = 12489;
			kanaOut += lastChar1;
		}
		// B/b	bo
		else if (lastChar2 == 66 || lastChar2 == 98)
		{
			lastChar1 = 12508;
			kanaOut += lastChar1;
		}
		// P/p	po
		else if (lastChar2 == 80 || lastChar2 == 112)
		{
			lastChar1 = 12509;
			kanaOut += lastChar1;
		}
		// J/j	jo
		else if (lastChar2 == 74 || lastChar2 == 106)
		{
			lastChar1 = 12472;
			kanaOut += lastChar1;
			lastChar2 = 12519;
			kanaOut += lastChar2;
		}
		else
		{
			lastChar1 = 12458;
			kanaOut += lastChar1;
		}
	}
	else if	(
				lastChar1 != 65 && lastChar1 != 97 &&	// !(A/a)
				lastChar1 != 73 && lastChar1 != 105 &&	// !(I/i)
				lastChar1 != 85 && lastChar1 != 117 &&	// !(U/u)
				lastChar1 != 69 && lastChar1 != 101 &&	// !(E/e)
				lastChar1 != 79 && lastChar1 != 111 &&	// !(O/o)
				lastChar1 != 89 && lastChar1 != 121 &&	// !(Y/y)
				(lastChar2 == 78 || lastChar2 == 110)	// N/n
			)
	{
		lastChar1 = 12531;
		kanaOut += lastChar1;
	}
	/* N/n
	else if (lastChar1 == 78 || lastChar1 == 110)
	{
		lastChar1 = 12531;
		kanaOut += lastChar1;
	}*/
	// ,
	else if (lastChar1 == 44)
	{
		lastChar1 = 12289;
		kanaOut += lastChar1;
	}
	// .
	else if (lastChar1 == 46)
	{
		lastChar1 = 12290;
		kanaOut += lastChar1;
	}
	// "Space"
	else if (lastChar1 == 32)
	{
		lastChar1 = 12288;
		kanaOut += lastChar1;
	}
	// $
	else if (lastChar1 == 36)
	{
		lastChar1 = 165;
		kanaOut += lastChar1;
	}
	// -
	else if (lastChar1 == 45)
	{
		lastChar1 = 12540;
		kanaOut += lastChar1;
	}
	// ~
	else if (lastChar1 == 126)
	{
		lastChar1 = 12316;
		kanaOut += lastChar1;
	}
	// (
	else if (lastChar1 == 40)
	{
		lastChar1 = 12304;
		kanaOut += lastChar1;
	}
	// )
	else if (lastChar1 == 41)
	{
		lastChar1 = 12305;
		kanaOut += lastChar1;
	}
	else if (
				lastChar1 == lastChar2 &&				// double character
				( (lastChar1 > 65 && lastChar1 < 91) || (lastChar1 > 97 && lastChar1 < 123) ) && // B-Z , b-z
				lastChar1 != 69 && lastChar1 != 101 &&	// !(E/e)
				lastChar1 != 73 && lastChar1 != 105 &&	// !(I/i)
				lastChar1 != 79 && lastChar1 != 111 &&	// !(O/o)
				lastChar1 != 85 && lastChar1 != 117		// !(U/u)
			)
	{
		lastChar1 = 12483;
		kanaOut += lastChar1;
	}
	// other
	else if ( (lastChar1 > 32 && lastChar1 < 65) || (lastChar1 > 90 && lastChar1 < 96) || (lastChar1 > 122 && lastChar1 < 126) )
	{
		kanaOut += lastChar1;
	}
	return kanaOut;
}
示例#30
0
void KText::drawText(sf::RenderWindow & window, int x, int y, sf::String str, sf::Color colour = sf::Color::Black)
{
	sf::View view;
	view.setSize(sf::Vector2f(SCREEN_WIDTH, SCREEN_HEIGHT));
	view.setCenter(sf::Vector2f(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2));
	window.setView(view);

	int row = 0;
	int col = 0;
	int charWidth = FONT_SIZE;

	for (int i = 0; i < str.toWideString().length(); i++)
	{
		bool draw = false;
		wchar_t w = str[i];
		sf::Sprite c;
		charWidth = FONT_SIZE;
		if (w != str.toWideString().size() - 1 && w == L'\\' && str[i + 1] == L'n') //If w is the enter key
		{
			//Go down a row and adjust all the way to the left side of the dialog box, also display the enter key with a width of zero
			row++;
			col = 0;
			charWidth = 0;
			i++;
			continue;
		}
		else if (w != str.toWideString().size() - 1 && w == L'\\' && str[i + 1] == L't') //If w is the tab key
		{
			col += charWidth * 2;
			i++;
			continue;
		}
		else if ((32 <= w && w <= 126) || (161 <= w && w <= 255)) //basic latin
		{
			draw = true;
			c = sf::Sprite(basic_latin, sf::IntRect((w % 16) * FONT_SIZE, ((w - (w % 16)) / 16) * FONT_SIZE, latinWidths[w], FONT_SIZE));
			charWidth = latinWidths[w];
			col += 4; //This is for space between each character, Japanese doesn't need this
		}
		else if (w == 8230) //...
		{
			draw = true;
			//This character isn't actually in the Japanese section of unicode, but I decided to give a spot in the Japanese spritesheet
			//because English users won't ever be typing in the single character form of the ellipses, also putting a character in a blank
			//spot goes againsts the unicode policy, but hey, it keeps me from having to create a hundred new characters
			c = sf::Sprite(japanese, sf::IntRect(0, 16 * FONT_SIZE, FONT_SIZE, FONT_SIZE));
		}
		else if (12288 <= w && w <= 12543) //1st japanese section of unicode stuff
		{
			draw = true;
			c = sf::Sprite(japanese, sf::IntRect((w % 16) * FONT_SIZE, (((w - (w % 16)) / 16) - 768) * FONT_SIZE, FONT_SIZE, FONT_SIZE));
		}
		else if (65281 <= w && w <= 65376) //2nd part of japanese stuff in unicode
		{
			draw = true;
			c = sf::Sprite(japanese, sf::IntRect((w % 16) * FONT_SIZE, (((w - (w % 16)) / 16) - 4064) * FONT_SIZE, FONT_SIZE, FONT_SIZE));
		}
		else if (65377 <= w && w <= 65439) //2nd part of japanese stuff in unicode, but halfwidth stuff
		{
			draw = true;
			c = sf::Sprite(japanese, sf::IntRect((w % 16) * FONT_SIZE, (((w - (w % 16)) / 16) - 4064) * FONT_SIZE, FONT_SIZE * .5, FONT_SIZE));
			charWidth = .5 * FONT_SIZE;\

		}
		else if (65440 <= w && w <= 65519) //2nd part of japanese stuff in unicode, but back to full width characters
		{
			draw = true;
			c = sf::Sprite(japanese, sf::IntRect((w % 16) * FONT_SIZE, (((w - (w % 16)) / 16) - 4064) * FONT_SIZE, FONT_SIZE, FONT_SIZE));
		}
		if (draw)
		{
			c.setPosition(sf::Vector2f(x + col, y + (row * FONT_SIZE)));
			col += charWidth;
			//Set the x value of the next character to += the width of the last character
		}
		c.setColor(colour);
		window.draw(c);
	}
}