SEvent question

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.

SEvent question

Postby REDDemon » Sat Jun 30, 2012 1:04 pm

is there any way to disable automatic double click?

If I do double click I get 2 events:
cpp Code: Select all
 
EMIE_LMOUSE_PRESSED_DOWN
EMIE_LMOUSE_DOUBLE_CLICK
 



I want those events:
cpp Code: Select all
 
EMIE_LMOUSE_PRESSED_DOWN
EMIE_LMOUSE_PRESSED_DOWN
 


If not I think I'll use the condition
cpp Code: Select all
 
(MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN || MouseInput.Event == EMIE_LMOUSE_DOUBLE_CLICK)
 
OpenGL is not hard. What you have to do is just explained in specifications. What is hard is dealing with poor OpenGL implementations.
User avatar
REDDemon
 
Posts: 831
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: SEvent question

Postby CuteAlien » Sat Jun 30, 2012 2:34 pm

Hm, usually the order should be:
EMIE_LMOUSE_PRESSED_DOWN
EMIE_LMOUSE_LEFT_UP
EMIE_LMOUSE_PRESSED_DOWN
EMIE_LMOUSE_DOUBLE_CLICK
EMIE_LMOUSE_LEFT_UP

Here's the mouse-test app I'm usually using:
cpp Code: Select all
 
#include <irrlicht.h>
#include <iostream>
#include <vector>
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif
 
const int DELAY_TIME = 3000;
 
enum ETimerAction
{
        ETA_MOUSE_VISIBLE,
        ETA_MOUSE_INVISIBLE,
};
 
struct TimerAction
{
        u32 TargetTime;
        ETimerAction Action;
};
 
struct SAppContext
{
        SAppContext() : device(0), infoStatic(0), infoBox(0), buttonSetVisible(0), buttonSetInvisible(0) {}
       
        void Update()
        {
                if (!device)
                        return;
                u32 timeNow = device->getTimer()->getTime();
                for ( std::vector<TimerAction>::iterator it = timerActions.begin(); it != timerActions.end(); )
                {
                        if ( timeNow >= it->TargetTime )
                        {
                                RunAction(*it);
                                it = timerActions.erase(it);
                        }
                        else
                        {
                                ++it;
                        }
                }
        }
 
        void RunAction(const TimerAction& action)
        {
                if (ETA_MOUSE_VISIBLE == action.Action)
                {
                        device->getCursorControl()->setVisible(true);
                        buttonSetVisible->setEnabled(true);
                }
                else if ( ETA_MOUSE_INVISIBLE == action.Action)
                {
                        device->getCursorControl()->setVisible(false);
                        buttonSetInvisible->setEnabled(true);
                }
        }
 
       
        IrrlichtDevice * device;
        irr::gui::IGUIStaticText * infoStatic;
        irr::gui::IGUIListBox * infoBox;
        irr::gui::IGUIButton * buttonSetVisible;
        irr::gui::IGUIButton * buttonSetInvisible;
        std::vector<TimerAction> timerActions; 
};
 
void PrintMouseEventName(const SEvent& event, irr::core::stringw &result)
{
        switch ( event.MouseInput.Event )
        {
                case EMIE_LMOUSE_PRESSED_DOWN:  result += stringw(L"EMIE_LMOUSE_PRESSED_DOWN"); break;
                case EMIE_RMOUSE_PRESSED_DOWN:  result += stringw(L"EMIE_RMOUSE_PRESSED_DOWN"); break;
                case EMIE_MMOUSE_PRESSED_DOWN:  result += stringw(L"EMIE_MMOUSE_PRESSED_DOWN"); break;
                case EMIE_LMOUSE_LEFT_UP:               result += stringw(L"EMIE_LMOUSE_LEFT_UP"); break;
                case EMIE_RMOUSE_LEFT_UP:               result += stringw(L"EMIE_RMOUSE_LEFT_UP"); break;
                case EMIE_MMOUSE_LEFT_UP:               result += stringw(L"EMIE_MMOUSE_LEFT_UP"); break;
                case EMIE_MOUSE_MOVED:                  result += stringw(L"EMIE_MOUSE_MOVED"); break;
                case EMIE_MOUSE_WHEEL:                  result += stringw(L"EMIE_MOUSE_WHEEL"); break;
                case EMIE_LMOUSE_DOUBLE_CLICK:  result += stringw(L"EMIE_LMOUSE_DOUBLE_CLICK"); break;
                case EMIE_RMOUSE_DOUBLE_CLICK:  result += stringw(L"EMIE_RMOUSE_DOUBLE_CLICK"); break;
                case EMIE_MMOUSE_DOUBLE_CLICK:  result += stringw(L"EMIE_MMOUSE_DOUBLE_CLICK"); break;
                case EMIE_LMOUSE_TRIPLE_CLICK:  result += stringw(L"EMIE_LMOUSE_TRIPLE_CLICK"); break;
                case EMIE_RMOUSE_TRIPLE_CLICK:  result += stringw(L"EMIE_RMOUSE_TRIPLE_CLICK"); break;
                case EMIE_MMOUSE_TRIPLE_CLICK:  result += stringw(L"EMIE_MMOUSE_TRIPLE_CLICK"); break;
                default:
                break;
        }
}
 
void PrintCursorState(IrrlichtDevice * device, irr::core::stringw &result)
{
        gui::ICursorControl * cursor = device->getCursorControl();
       
        core::position2d<f32> relPos = cursor->getRelativePosition();
        result += stringw(L"relPos.X: ");
        result += stringw(relPos.X);
        result += stringw(L"\n");
        result += stringw(L"relPos.Y: ");
        result += stringw(relPos.Y);
        result += stringw(L"\n");
       
        core::position2d<s32> position = cursor->getPosition();
        result += stringw(L"position.X: ");
        result += stringw(position.X);
        result += stringw(L"\n");
        result += stringw(L"position.Y: ");
        result += stringw(position.Y);
        result += stringw(L"\n");
}
 
void PrintMouseState(const SEvent& event, irr::core::stringw &result)
{
        result += stringw(L"event X: ");
        result += stringw(event.MouseInput.X);
        result += stringw(L"\n");
               
        result += stringw(L"event Y: ");
        result += stringw(event.MouseInput.Y);
        result += stringw(L"\n");
 
 
        result += stringw(L"event Wheel: ");
        result += stringw(event.MouseInput.Wheel);
        result += stringw(L"\n");
       
        result += stringw(L"event Shift: ");
        if ( event.MouseInput.Shift )
                result += stringw(L"true\n");
        else
                result += stringw(L"false\n");
 
        result += stringw(L"event Control: ");
        if ( event.MouseInput.Control )
                result += stringw(L"true\n");
        else
                result += stringw(L"false\n");
 
        result += stringw(L"event ButtonStates: ");
        result += stringw(event.MouseInput.ButtonStates);
        result += stringw(L"\n");
 
        result += stringw(L"event isLeftPressed: ");
        if ( event.MouseInput.isLeftPressed() )
                result += stringw(L"true\n");
        else
                result += stringw(L"false\n");
 
        result += stringw(L"event isRightPressed: ");
        if ( event.MouseInput.isRightPressed() )
                result += stringw(L"true\n");
        else
                result += stringw(L"false\n");
 
        result += stringw(L"event isMiddlePressed: ");
        if ( event.MouseInput.isMiddlePressed() )
                result += stringw(L"true\n");
        else
                result += stringw(L"false\n");
 
        result += stringw(L"Event: ");
       
        PrintMouseEventName(event, result);
       
        result += stringw(L"\n");
}
 
class MyEventReceiver : public IEventReceiver
{
public:
        MyEventReceiver(SAppContext & context) : Context(context) { }
 
        virtual bool OnEvent(const SEvent& event)
        {
                if (event.EventType == EET_GUI_EVENT )
                {
                        switch ( event.GUIEvent.EventType )
                        {
                                case EGET_BUTTON_CLICKED:
                                {
                                        u32 timeNow = Context.device->getTimer()->getTime();
                                        TimerAction action;
                                        action.TargetTime = timeNow + DELAY_TIME;
                                        if ( event.GUIEvent.Caller == Context.buttonSetVisible )
                                        {
                                                action.Action = ETA_MOUSE_VISIBLE;
                                                Context.timerActions.push_back(action);
                                                Context.buttonSetVisible->setEnabled(false);
                                        }
                                        else if ( event.GUIEvent.Caller == Context.buttonSetInvisible )
                                        {
                                                action.Action = ETA_MOUSE_INVISIBLE;
                                                Context.timerActions.push_back(action);
                                                Context.buttonSetInvisible->setEnabled(false);
                                        }
                                }
                                break;
                                default:
                                break;
                        }
                }
               
                if (event.EventType == EET_MOUSE_INPUT_EVENT)
                {
                        irr::core::stringw infoText;
                        PrintCursorState(Context.device, infoText);
                        PrintMouseState(event, infoText);
                        Context.infoStatic->setText(infoText.c_str());
                        if ( event.MouseInput.Event != EMIE_MOUSE_MOVED && event.MouseInput.Event != EMIE_MOUSE_WHEEL ) // no spam
                        {
                                infoText = L"";
                                PrintMouseEventName(event, infoText);
                                Context.infoBox->addItem(infoText.c_str());
                        }
                }
 
                return false;
        }
 
private:
        SAppContext & Context;
};
 
 
int main()
{
        video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;
        IrrlichtDevice * device = createDevice(driverType, core::dimension2d<u32>(640, 480));
        if (device == 0)
                return 1; // could not create selected driver.
 
        video::IVideoDriver* driver = device->getVideoDriver();
        IGUIEnvironment* env = device->getGUIEnvironment();
       
        SAppContext context;
        context.device = device;
       
        core::rect< s32 > rectInfoStatic(10,10, 200, 400);
        context.infoStatic = env->addStaticText (L"", rectInfoStatic, true, true);
        core::rect< s32 > rectInfoBox(210,10, 400, 400);
        context.infoBox = env->addListBox(rectInfoBox);
        context.buttonSetVisible = env->addButton( rect<s32>( 410, 20, 500, 40 ), 0, -1, L"set visible (delayed)" );
        context.buttonSetInvisible = env->addButton( rect<s32>( 410, 50, 500, 70 ), 0, -1, L"set invisible (delayed)" );
       
       
        MyEventReceiver receiver(context);
        device->setEventReceiver(&receiver);
       
 
        while(device->run() && driver)
        {
                // if (device->isWindowActive())
                {
                        /*                      static int triggerMousePos = 0;
                        if ( !(++triggerMousePos % 100) )
                        {
                                gui::ICursorControl * cursor = device->getCursorControl();
                                core::position2d<f32> relPos = cursor->getRelativePosition();
                                cursor->setPosition(relPos);
                        }*/

 
                        context.Update();
                       
                        driver->beginScene(true, true, SColor(0,200,200,200));
       
                        env->drawAll();
               
                        driver->endScene();
                }
               
                device->sleep(10);
        }
 
        device->drop();
 
        return 0;
}
 
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5362
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: SEvent question

Postby REDDemon » Sat Jun 30, 2012 8:29 pm

mmh.. so I just have to ignore double click since LMB down is sent even when double click is sent .. thx :)
OpenGL is not hard. What you have to do is just explained in specifications. What is hard is dealing with poor OpenGL implementations.
User avatar
REDDemon
 
Posts: 831
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)


Return to Beginners Help

Who is online

Users browsing this forum: jrlago, Triadian and 1 guest