Here you go...
// rapide's development
#pragma once
#include "UpgradedSprite.h"
#include "WindowMenager.h"
#include "ImageStorage.h"
// *******************************************************************************************
// ********************************** class WriteDisplayer ***********************************
// *******************************************************************************************
// Class which is console to get input.
class WriteDisplayer
{
// ------------------------------------------ Variables ------------------------------------------
private:
WindowMenager* window; // Pointer to the main window.
UpgradedSprite console; // Sprite with the screener.
std::string mainStr; // String with text.
sf::String sfStr; // String which will be display on screen.
float positionX; // Position X.
float positionY; // Position Y.
bool isActive;
// --------------------------------- Constructors and destructor ---------------------------------
public:
WriteDisplayer(WindowMenager* argWindow, float fontSize, unsigned int fontIndex,
unsigned int consoleIndex, ImageStorage *images);
~WriteDisplayer() {}
// --------------------------------------- Standard methods --------------------------------------
public:
bool checkState();
// Function for checking if displayer is active now.
// Returns: True if write displayer is active.
void writing();
// Function for checking events and describe them for charakters.
// Returns: Void.
void clear();
// Function for clearing displayer's console and main string.
// Returns: Void.
float getWidth();
// Function for getting displayer's width.
// Returns: Width of displayer.
float getHeight();
// Function for getting displayer's height.
// Returns: Height of displayer.
std::string getString() const;
// Function for getting main string from displayer.
// Returns: Main string.
void setPosition(float posX, float posY);
// Function for setting displayer's position.
// Returns: Void.
void updateWordsPosition();
// Function for updating words position because when we adding more characters then rectangle of sf::string is bigger.
// Returns: Void.
void setStringAtBegin(std::string& argStr);
// Function for setting main string at begin.
// 1st argument: Reference to string.
// Returns: Void.
void draw();
// Function for drawing write displayer.
// Returns: Void.
};
// Inside *.cpp
#include "WriteDisplayer.h"
// *******************************************************************************************
// ***************************** Constructors and destructor *********************************
// *******************************************************************************************
// ---------------------------------------- Constructor ------------------------------------------
WriteDisplayer::WriteDisplayer(WindowMenager* argWindow, float sizeFont, unsigned int fontIndex,
unsigned int consoleIndex, ImageStorage* images) : window(argWindow)
{
console.SetImage(*images->getImage(consoleIndex));
sfStr.SetFont(*images->getFont(fontIndex));
sfStr.SetColor(sf::Color::Black);
sfStr.SetSize(sizeFont);
isActive = false;
}
// *******************************************************************************************
// ************************************** writing() ******************************************
// *******************************************************************************************
void WriteDisplayer::writing()
{
if(isActive)
{
sf::Event currentEvent = window->getEvent();
if (currentEvent.Type == sf::Event::TextEntered && window->checkEventUniqueness())
{
if (currentEvent.Text.Unicode < 128 || currentEvent.Text.Unicode == 322) ///-> 322 == 'ł' ?
mainStr.push_back(currentEvent.Text.Unicode);
}
else if(currentEvent.Key.Code == sf::Key::Code::Back && window->checkEventUniqueness())
{
if(!mainStr.empty())
mainStr.pop_back();
}
sfStr.SetText(mainStr);
}
}
// *******************************************************************************************
// *************************************** draw() ********************************************
// *******************************************************************************************
void WriteDisplayer::draw()
{
window->draw(console);
updateWordsPosition();
window->draw(sfStr);
}
//...
// This is from ImageStorage which contains vector of pointers to the sf::Font.
// ----------------------------------------- loadFontToVector ----------------------------------------
void ImageStorage::loadFontToVector(char* filePath)
{
sf::Font* temporaryFont = new sf::Font;
temporaryFont->LoadFromFile(filePath, 30 * 3, polishCharakters());
fontsContent.push_back(temporaryFont);
}
// ------------------------------------- polishCharakters ------------------------------------
const sf::Unicode::Text ImageStorage::polishCharakters()
{
std::wstring cPL;
cPL = L"abcdefghijklmnopqrstuvwxyz";
cPL += L"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cPL += L"0123456789";
cPL += L"ąćęłńóśźż";
cPL += L"ĄĆĘŁŃÓŚŹŻ";
cPL += L".,\\/'<>;:[]{}|+=-_()*&^%$#@!~\" \n\t";
return cPL;
}
// ------------------------------------------- getFont -------------------------------------------
sf::Font* ImageStorage::getFont(unsigned int index) const
{
return fontsContent[index];
}
I hope that it will brighten your little concept.