Class code (until the curve):
EditControl::EditControl(Font &_font, int x, int y, float _width, float _height)
{
font = &_font;
TextColor = Color(255,255,255);
CStandart = Color(27, 27, 28);
positionX = x;
positionY = y;
width = _width;
height = _height;
text.setFont(*font);
text.setCharacterSize(11);
text.setColor(TextColor);
text.setPosition(x + 4, y + 1);
SettingTheTextShift();//установка сдвига текста
Background.setPosition(x, y);
Background.setFillColor(CStandart);
Background.setSize(Vector2f(_width, _height + 1));//"+1"рамка
}
EditControl::~EditControl()
{
}
void EditControl::envent(sf::Event &event)
{
if (event.type == sf::Event::TextEntered)
{
m_newText = text.getString();
//Обработка ввода
switch ( event.text.unicode )
{
case 0xD: //Return
//m_newText += L'\n' ;
break ;
case 0x8://Backspace
if ( !m_newText.isEmpty() )
m_newText.erase(m_newText.getSize()-1) ;
break ;
default :
{
m_newText += static_cast<wchar_t>(event.text.unicode);
}
}
text.setString(m_newText);
SettingTheTextShift();//установка сдвига текста
}
}
void EditControl::draw(RenderWindow &window)
{
}
void EditControl::setTextColor(Color &color)
{
TextColor = color;
}
void EditControl::setCStandartColor(Color &color)
{
CStandart = color;
}
void EditControl::setTest(wchar_t *PText)
{
text.setString(PText);
SettingTheTextShift();
}
void EditControl::setTest(String &test)
{
text.setString(test);
SettingTheTextShift();
}
//private
void EditControl::SettingTheTextShift()
{
FloatRect Bounding_Rectangle(text.getLocalBounds());
int temp_width = (Bounding_Rectangle.width + 7);
if(temp_width > width)
{
temp_width = temp_width - width;
text.setPosition(positionX + 4 - temp_width, positionY + 1);
}
else
{
text.setPosition(positionX + 4, positionY + 1);
}
}
As far as I understand, these functions can determine the window themselves.
Can there be problems when used in multiple windows?