TextArea GUI Element [v1.0]

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
RdR
Competition winner
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm
Contact:

Re: TextArea GUI Element [v1.0]

Post by RdR »

Fixed minor bug, thanks to Necris for reporting
Dreadstew
Posts: 23
Joined: Wed Apr 01, 2015 5:18 pm

Re: TextArea GUI Element [v1.0]

Post by Dreadstew »

I get a bug when using your code.

If you enter lines that wrap scrolling no longer works properly. startIndex isn't large enough to deal with all the lines and when it changes from 1 to 0 and back to 1 instead of scrolling it jumps a lot of lines.

I don't think your variables startIndex or maxLines have the correct values when you enter text that wraps.

Your usage of lines.size() also causes issues because there are effectively more lines to scroll through when there is wrapped texts.

If you could fix it I would love you forever lol. I spent a whole night trying to fix it but I suck lol.
RdR
Competition winner
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm
Contact:

Re: TextArea GUI Element [v1.0]

Post by RdR »

Dreadstew wrote:I get a bug when using your code.

If you enter lines that wrap scrolling no longer works properly. startIndex isn't large enough to deal with all the lines and when it changes from 1 to 0 and back to 1 instead of scrolling it jumps a lot of lines.

I don't think your variables startIndex or maxLines have the correct values when you enter text that wraps.

Your usage of lines.size() also causes issues because there are effectively more lines to scroll through when there is wrapped texts.

If you could fix it I would love you forever lol. I spent a whole night trying to fix it but I suck lol.
Thanks for reporting the bug. Do you have some code to reproduce this bug easy?
I haven't touch this code in a long time so would make it a lot easier for me when I take a look.
Dreadstew
Posts: 23
Joined: Wed Apr 01, 2015 5:18 pm

Re: TextArea GUI Element [v1.0]

Post by Dreadstew »

Wow I can't believe you replied it's been so long. Sweet deal!

I had trouble enabling scrolling so I changed a few lines of your code.

Around line 90 I put autoScroll = false; so that when you scroll with your mouse in the textArea autoScroll gets disabled.

Around line 242 I put autoScroll = true; so that when start index is at its max position scrolling becomes enabled again.

I'm pretty sure those lines aren't causing the bug but I could be mistaken I guess.

After you make those changes to TextArea.cpp try running this:

Code: Select all

 
#include <irrlicht.h>
#include "driverChoice.h"
 
#include <string>
 
#include "Line.h"
#include "TextArea.h"
 
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
 
using namespace std;
using namespace irr;
 
class MyEventReceiver : public IEventReceiver
{
public:
    // We'll create a struct to record info on the mouse state
    struct SMouseState
    {
        core::position2di Position;
        bool LeftButtonDown;
        bool RightButtonDown;
        SMouseState()
        {
            LeftButtonDown = false;
            RightButtonDown = false;
        }
    } MouseState;
 
 
    // This is the one method that we have to implement
    virtual bool OnEvent(const SEvent& event)
    {   
        // Remember the mouse state
        if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
        {
            switch(event.MouseInput.Event)
            {
            case EMIE_LMOUSE_PRESSED_DOWN:
                MouseState.LeftButtonDown = true;
                break;
 
            case EMIE_LMOUSE_LEFT_UP:
                MouseState.LeftButtonDown = false;
                break;
 
            case EMIE_RMOUSE_PRESSED_DOWN:
                MouseState.RightButtonDown = true;
                break;
 
            case EMIE_RMOUSE_LEFT_UP:
                MouseState.RightButtonDown = false;
                break;
 
            case EMIE_MOUSE_MOVED:
                MouseState.Position.X = event.MouseInput.X;
                MouseState.Position.Y = event.MouseInput.Y;
                break;
 
            default:
                // We won't use the wheel
                break;
            }
        }
 
        // Remember whether each key is down or up
        // trigger pressed only once somehow
        if (event.EventType == irr::EET_KEY_INPUT_EVENT) {
            KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
            if (!KeyIsDown[event.KeyInput.Key]) {
                //key was released
                KeyIsPressed[event.KeyInput.Key] = true;
            }
        }
        // for chatbox scroll event
        //if (event.EventType == EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == EMIE_MOUSE_WHEEL) {
        //        mouseWheel += event.MouseInput.Wheel;
        //      mousePosition = core::position2di(event.MouseInput.X, event.MouseInput.Y);
        //}
        return false;
    }
 
    // This is used to check whether a key is being held down
    virtual bool IsKeyDown(EKEY_CODE keyCode) const
    {
        return KeyIsDown[keyCode];
    }
 
    virtual bool IsKeyPressed(EKEY_CODE keyCode) const
    {
        return KeyIsPressed[keyCode];
    }
 
    virtual void resetKeyPressed(EKEY_CODE keyCode)
    {
        KeyIsPressed[keyCode] = false;
    }
 
    const SMouseState & GetMouseState(void) const
    {
        return MouseState;
    }
 
    //float getMouseWheel() {
    //  return mouseWheel;
    //}
 
    //void resetMouseWheel() {
    //  mouseWheel = 0;
    //}
 
    //core::position2di getMousePosition() {
    //  return mousePosition;
    //}
    
    MyEventReceiver()
    {
        for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
            KeyIsDown[i] = false;
        for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
            KeyIsPressed[i] = false;
        //mouseWheel = 0;
        //mousePosition = core::position2di(0,0);
    }
 
private:
    // We use this array to store the current state of each key
    bool KeyIsDown[KEY_KEY_CODES_COUNT];
    bool KeyIsPressed[KEY_KEY_CODES_COUNT];
    //float mouseWheel;
    core::position2di mousePosition;
};
 
int screenWidth = 640;
int screenHeight = 440;
 
int main()
{
    video::E_DRIVER_TYPE driverType=driverChoiceConsole();
    if (driverType==video::EDT_COUNT)
        cout << "couldn't do driver thing" << endl;
 
    MyEventReceiver receiver;
    IrrlichtDevice *device =
        createDevice(driverType, core::dimension2d<u32>(screenWidth, screenHeight), 16, false, false, false, &receiver);
 
    video::IVideoDriver* driver = device->getVideoDriver();
    scene::ISceneManager* smgr = device->getSceneManager();
    gui::IGUIEnvironment* environment = device->getGUIEnvironment();
 
    TextArea* textArea = new TextArea(environment, environment->getRootGUIElement());
    textArea->setDimension(200,110);
    textArea->setMaxLines(10);
    textArea->setAlignment(TextArea::LEFT);
    textArea->setPosition(core::vector2di(10,270));
    textArea->drop();
 
    //the code that fills the textArea with lines that get wrapped, which causes a scrolling bug
    //when startIndex changes from 1 to 0 and back to 1, many lines are skipped past when scrolling
    //startIndex range of values it can be doesn't seem to be big enough when there are wrapped lines
    //startIndex range of values are controlled by variable maxLines and call to lines.size()
    //there is no accounting for wrapped lines, which take multiple lines to display, in the calculation
    for (int i = 0; i < 20; i++) {
        string testline = "this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test.";
        testline += i;
        Line* line = new Line();
        line->addString(testline, video::SColor(255, 0, 0, 0));
        textArea->addLine(line);
    }
    
 
    while ( device->run() )
    {
        driver->beginScene(true, true, 0);
        smgr->drawAll();
        environment->drawAll();
        driver->endScene();
    }
    device->drop();
}
 
That should do it. All you gotta do is copy paste, include irrlicht and irrlicht lib, paste irrlicht lib into project folder (sometimes I do this in multiple folders within project cause it still won't wont find it lol) but you probably know all that your code is pretty snazzy. Thanks for looking into it really means a lot to me. I'm working on a mmorpg engine right now, just finished networked movement part of the engine. Using your chatbox to display sent and received messages. Having a pretty good first foray into making an mmo engine, if you get chatbox working my game will be bug free except for jittery movement lol.
chronologicaldot
Competition winner
Posts: 688
Joined: Mon Sep 10, 2012 8:51 am

Re: TextArea GUI Element [v1.0]

Post by chronologicaldot »

Did this ever get fixed? I'm curious. I would like to use it.
Thanks for this, RdR!
agnas
Posts: 20
Joined: Tue Mar 27, 2007 6:16 pm
Location: Venezuela
Contact:

Re: TextArea GUI Element [v1.0]

Post by agnas »

Hello no idea if the original coder is still around, so just my few notes after test this.
My first question is a very obvious one, why is this called textarea? It doesn't work like <html> textarea, meaning like a >>input<< element, it only display or something very ugly went with my testing.
Secondly, after a lot of testing I didn't make it work when you declarate this way

Code: Select all

 
TextArea* chatBox = new TextArea(env, m_wnd, m_irr_id);
 
where m_wnd it's a irrlicht window created by

Code: Select all

 
m_wnd = env->addWindow(...)
 
It keep positioning itself relative to the app coordinates.
Thanks for reading. Any feedback will be apreciated as I'm about to implement a real textarea and yes, it's a lot of work. Or maybe not.
/\+++/\
< agnas >
\/+++\/
micronosis.com
netpipe
Posts: 670
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Re: TextArea GUI Element [v1.0]

Post by netpipe »

is this really in irrext svn ? i did not find it there.
Live long and phosphor!
-- https://github.com/netpipe/Luna Game Engine Status 95%
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: TextArea GUI Element [v1.0]

Post by CuteAlien »

IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply