Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Text Box  (Read 3427 times)

0 Members and 1 Guest are viewing this topic.

Tima32

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
Text Box
« on: January 31, 2018, 02:43:41 pm »
Good day!
I'm writing my TextBox so that the text does not go beyond the window, I use
glEnable(GL_SCISSOR_TEST);
glScissor(x, y, getSize().x, getSize().y);
window.draw(text);
glDisable(GL_SCISSOR_TEST);
But how do I use it if I have more than one window?

Pinco

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Text Box
« Reply #1 on: February 04, 2018, 01:00:36 pm »
Good day!
I'm writing my TextBox so that the text does not go beyond the window, I use
glEnable(GL_SCISSOR_TEST);
glScissor(x, y, getSize().x, getSize().y);
window.draw(text);
glDisable(GL_SCISSOR_TEST);
But how do I use it if I have more than one window?

Do you want to input text even though it won't fit in the textbox or do you want to prevent the user from entering more text than what actually fits?

It's not really clear what you want to do and we are missing part of the code. Could you articulate better?
My potato is 5 petaflops faster than your high end pc.
https://imgur.com/gallery/0S5spVm

Tima32

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
Re: Text Box
« Reply #2 on: February 07, 2018, 02:57:25 pm »
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();//&#1091;&#1089;&#1090;&#1072;&#1085;&#1086;&#1074;&#1082;&#1072; &#1089;&#1076;&#1074;&#1080;&#1075;&#1072; &#1090;&#1077;&#1082;&#1089;&#1090;&#1072;
        }
}
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?

Tima32

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
Re: Text Box
« Reply #3 on: February 07, 2018, 02:59:20 pm »
p.s Windows will be processed in different threads.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Text Box
« Reply #4 on: February 07, 2018, 03:12:38 pm »
how do I use it if I have more than one window?
Can there be problems when used in multiple windows?
Is the problem that you can't do it in multiple windows but it's fine in just one?
Could the problem being active OpenGL contexts? Maybe it needs activating.
https://www.sfml-dev.org/tutorials/2.4/window-opengl.php#managing-opengl-contexts
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Tima32

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
Re: Text Box
« Reply #5 on: February 07, 2018, 03:45:44 pm »
What am I doing wrong?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Text Box
« Reply #6 on: February 07, 2018, 04:19:54 pm »
What is causing it to crash? Unfortunately, I don't understand the error message and cannot investigate the call stack.

One thing to consider though, is to have the main thread control all windows rather than having the window created by a separate thread. Also note that I mentioned activating contexts earlier; did you try this? Is it possible that both windows are trying to access OpenGL at the same time?

I suppose one question is whether you need a separate thread to create and extra window. Multiple windows can be easily - and much more simply and safely - managed from the main thread. This also makes your code more portable but I presume that this code is intended for Windows only.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*