Exemplo n.º 1
0
void EWAUserAction::setEvent( const QEvent* pEvent )
{
    if( pEvent )
    {
        if( isKeyEvent( pEvent->type() ) )
        {
            const QKeyEvent *pKeyEvent = static_cast< const QKeyEvent* >( pEvent );
            if( pKeyEvent )
            {
                return rememberKeyEvent( pKeyEvent );
            }
        }
        
        if( isMouseEvent( pEvent->type() ) )
        {
            const QMouseEvent *pMouseEvent = static_cast< const QMouseEvent* >( pEvent );
            if( pMouseEvent )
            {
                return rememberMouseEvent( pMouseEvent );
            }
        }
    }
    
    Q_ASSERT( 0 );
}
Exemplo n.º 2
0
void EWAUserAction::save( QSettings *pSettings )
{
    if( !pSettings || !m_pEvent )
    {
        return;
    }
    
    bool bSaved = false;
    if( isMouseEvent( m_pEvent->type() ) )
    {
        bSaved = saveMouseEvent( pSettings, static_cast< QMouseEvent* >( m_pEvent ) );
        /*if( bSaved )
        {
            pSettings->beginWriteArray( "ClickedElement" );
                for( int nodeCounter = 0; nodeCounter < m_clickedElement.count(); ++nodeCounter )
                {
                    pSettings->setArrayIndex( nodeCounter );
                    pSettings->setValue( QLatin1String( "node" ), m_clickedElement.at( nodeCounter ) );
                }
            pSettings->endArray();
        }*/
        
    }
    else if( isKeyEvent( m_pEvent->type() ) )
    {
        bSaved = saveKeyEvent( pSettings, static_cast< QKeyEvent* >( m_pEvent ) );
    }
    
    if( bSaved )
    {
        pSettings->setValue( QLatin1String( "delay" ), getTime() );
        pSettings->setValue( QLatin1String( "sz" ), getWebViewSize() );
    }
}
Exemplo n.º 3
0
void AllegroShell::run(){
// run the loop
	unsigned num = 0;
	ALLEGRO_EVENT ev;
	al_start_timer(timer);

	unsigned keyboard_count = 0;
	unsigned mouse_count = 0;
	unsigned timer_count = 0;
	
	while( run_flag ){
		al_wait_for_event(queue,&ev);
		num++;
		printf("\r%d",num);

		if( ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE){
			run_flag = false;
		}else if( isKeyboardEvent(&ev)){
			// handle keyboard input
			++keyboard_count;
			al_get_keyboard_state(&(keyboard));
			handle_keyboard(&ev);
		}else if( isMouseEvent(&ev) ){
			// handle mouse input
			++mouse_count;
			mouse->update(&ev);
			handle_mouse(&ev);
		}else if( ev.type  == ALLEGRO_EVENT_TIMER){
			++timer_count;
			// Update the model only if we haven't drawn the scene
			if(draw_flag == false){
				if(step_once_flag){
					// always step once if the user requests it
					model->step();
					step_once_flag = false;
				}else if(step_flag) {
					model->step();
				}
			}
			draw_flag = true;
		}else if (ev.type == USER_VIEW_EVENT){
			// handling user events
			al_unref_user_event(&ev.user);
		}

		if( draw_flag && al_event_queue_is_empty(queue)){
			draw();
			draw_flag = false;
		}
	} // end while(run_flag)

	Textlog::get().log("\nkeyboard_count = %u\n",keyboard_count);
	Textlog::get().log("mouse_count = %u\n",mouse_count);
	Textlog::get().log("timer_count = %u\n",timer_count);
}
Exemplo n.º 4
0
void EWAUserAction::execute( QWebView *webViewPtr ) const
{
    if( !webViewPtr )
    {
        return;
    }
    
    //EWAWebView *pEwaWebView = qobject_cast<EWAWebView*>( webViewPtr );
    //bool bNeedSetFocus = false;
    QEvent *pEventCopy = 0;
    
    if( isMouseEvent( m_pEvent->type() ) )
    {
        QMouseEvent *pSrcMouseEvent = static_cast<QMouseEvent *>( m_pEvent );
        
        QPoint clickCoords = pSrcMouseEvent->pos();
        
        pEventCopy = new QMouseEvent( 
            pSrcMouseEvent->type(), 
            clickCoords, 
            webViewPtr->mapToGlobal( clickCoords ), 
            pSrcMouseEvent->button(), 
            pSrcMouseEvent->buttons(),
            pSrcMouseEvent->modifiers() );
        
        
    }
    
    else if( isKeyEvent( m_pEvent->type() ) )
    {
        QKeyEvent *pSrcKeyEvent = static_cast<QKeyEvent*>( m_pEvent );
        
        pEventCopy = new QKeyEvent( 
            pSrcKeyEvent->type(), 
            pSrcKeyEvent->key(), 
            pSrcKeyEvent->modifiers(),
            pSrcKeyEvent->text(), 
            pSrcKeyEvent->isAutoRepeat(), 
            pSrcKeyEvent->count() );
    }
     
     if( pEventCopy )
     {
        QSize dstSz = getWebViewSize();
        if( webViewPtr->page()->preferredContentsSize() != dstSz )
        {
            webViewPtr->page()->setPreferredContentsSize( dstSz );
        }
        
        EWAApplication::postEvent( webViewPtr, pEventCopy );
     }
}
Exemplo n.º 5
0
void EWAUserAction::load( QSettings *pSettings )
{
    if( !pSettings )
    {
        return;
    }
    
    //m_clickedElement.clear();
        
    
    QEvent::Type eType = (QEvent::Type) pSettings->value( QLatin1String( "type" ) ).toInt();
    
    bool bLoaded = false;
    if( isMouseEvent( eType ) )
    {
        m_pEvent = new QMouseEvent( eType
        ,pSettings->value( QLatin1String( "pos" ) ).toPoint()
        ,(Qt::MouseButton)pSettings->value( QLatin1String( "button" ) ).toInt()
        ,(Qt::MouseButtons)pSettings->value( QLatin1String( "buttons" ) ).toInt()
        ,(Qt::KeyboardModifiers)pSettings->value( QLatin1String( "modifiers" ) ).toInt()
        );
        
        /*int nodesCount = pSettings->beginReadArray( "ClickedElement" );
            for( int nodeCounter = 0; nodeCounter < nodesCount; ++nodeCounter )
            {
                pSettings->setArrayIndex( nodeCounter );
                m_clickedElement += pSettings->value( QLatin1String( "node" ), 0 ).toInt();
            }
        pSettings->endArray();*/
        
        bLoaded = true;
    }
    else if( isKeyEvent( eType ) )
    {
        m_pEvent = new QKeyEvent( eType
            ,pSettings->value( QLatin1String( "key" ) ).toInt()
            ,(Qt::KeyboardModifiers)pSettings->value( QLatin1String( "modifiers" ) ).toInt()
            ,pSettings->value( QLatin1String( "text" ) ).toString()
            ,pSettings->value( QLatin1String( "autoRepeat" ) ).toBool()
            ,pSettings->value( QLatin1String( "count" ) ).toInt()
            );
        
        bLoaded = true;
    }
    
    if( bLoaded )
    {
        setTime( pSettings->value( QLatin1String( "delay" ) ).toInt() );
        setWebViewSize( pSettings->value( QLatin1String( "sz" ) ).toSize() );
    }
}
Exemplo n.º 6
0
bool Event::composed() const
{
    if (m_composed)
        return true;

    // http://w3c.github.io/webcomponents/spec/shadow/#scoped-flag
    if (!isTrusted())
        return false;

    return m_type == eventNames().inputEvent
        || m_type == eventNames().textInputEvent
        || m_type == eventNames().DOMActivateEvent
        || isCompositionEvent()
        || isClipboardEvent()
        || isFocusEvent()
        || isKeyboardEvent()
        || isMouseEvent()
        || isTouchEvent();
}
Exemplo n.º 7
0
//Hook for events
int SLTipWindow::FilterEvent(wxEvent& hookedEvent)
{
	//Only mouse events are in interest
	if (isMouseEvent(hookedEvent)) {
		//Remove hook before proceed, prevents deadlock
		wxEvtHandler::RemoveFilter(this);
		isHookInstalled = false;

		//Send event to parent control
		wxEvent* clonedEvent = hookedEvent.Clone();
		parentWindow->GetEventHandler()->QueueEvent(clonedEvent);

		//Close tip window
		Close();
		return Event_Processed;
	}

	//Leave events unhandled
	return Event_Skip;
}
Exemplo n.º 8
0
/*****************************************************************************
 * EventThread: Create video window & handle its messages
 *****************************************************************************
 * This function creates a video window and then enters an infinite loop
 * that handles the messages sent to that window.
 * The main goal of this thread is to isolate the Win32 PeekMessage function
 * because this one can block for a long time.
 *****************************************************************************/
static void *EventThread( void *p_this )
{
    event_thread_t *p_event = (event_thread_t *)p_this;
    vout_display_t *vd = p_event->vd;
    MSG msg;
    POINT old_mouse_pos = {0,0}, mouse_pos;
    int canc = vlc_savecancel ();

    bool b_mouse_support = var_InheritBool( p_event->vd, "mouse-events" );
    bool b_key_support = var_InheritBool( p_event->vd, "keyboard-events" );

    vlc_mutex_lock( &p_event->lock );
    /* Create a window for the video */
    /* Creating a window under Windows also initializes the thread's event
     * message queue */
    if( DirectXCreateWindow( p_event ) )
        p_event->b_error = true;

    p_event->b_ready = true;
    vlc_cond_signal( &p_event->wait );

    const bool b_error = p_event->b_error;
    vlc_mutex_unlock( &p_event->lock );

    if( b_error )
    {
        vlc_restorecancel( canc );
        return NULL;
    }

#ifndef UNDER_CE
    /* Prevent monitor from powering off */
    SetThreadExecutionState( ES_DISPLAY_REQUIRED | ES_CONTINUOUS );
#endif

    /* Main loop */
    /* GetMessage will sleep if there's no message in the queue */
    for( ;; )
    {
        vout_display_place_t place;
        video_format_t       source;

        if( !GetMessage( &msg, 0, 0, 0 ) )
        {
            vlc_mutex_lock( &p_event->lock );
            p_event->b_done = true;
            vlc_mutex_unlock( &p_event->lock );
            break;
        }

        /* Check if we are asked to exit */
        vlc_mutex_lock( &p_event->lock );
        const bool b_done = p_event->b_done;
        vlc_mutex_unlock( &p_event->lock );
        if( b_done )
            break;

        if( !b_mouse_support && isMouseEvent( msg.message ) )
            continue;

        if( !b_key_support && isKeyEvent( msg.message ) )
            continue;

        /* Handle mouse state */
        if( msg.message == WM_MOUSEMOVE ||
            msg.message == WM_NCMOUSEMOVE )
        {
            GetCursorPos( &mouse_pos );
            /* FIXME, why this >2 limits ? */
            if( (abs(mouse_pos.x - old_mouse_pos.x) > 2 ||
                (abs(mouse_pos.y - old_mouse_pos.y)) > 2 ) )
            {
                old_mouse_pos = mouse_pos;
                UpdateCursor( p_event, true );
            }
        }
        else if( isMouseEvent( msg.message ) )
        {
            UpdateCursor( p_event, true );
        }
        else if( msg.message == WM_VLC_HIDE_MOUSE )
        {
            UpdateCursor( p_event, false );
        }

        /* */
        switch( msg.message )
        {
        case WM_MOUSEMOVE:
            vlc_mutex_lock( &p_event->lock );
            place  = p_event->place;
            source = p_event->source;
            vlc_mutex_unlock( &p_event->lock );

            if( place.width > 0 && place.height > 0 )
            {
                if( msg.hwnd == p_event->hvideownd )
                {
                    /* Child window */
                    place.x = 0;
                    place.y = 0;
                }
                const int x = source.i_x_offset +
                    (int64_t)(GET_X_LPARAM(msg.lParam) - place.x) * source.i_width  / place.width;
                const int y = source.i_y_offset +
                    (int64_t)(GET_Y_LPARAM(msg.lParam) - place.y) * source.i_height / place.height;
                vout_display_SendEventMouseMoved(vd, x, y);
            }
            break;
        case WM_NCMOUSEMOVE:
            break;

        case WM_VLC_HIDE_MOUSE:
            break;

        case WM_LBUTTONDOWN:
            MousePressed( p_event, msg.hwnd, MOUSE_BUTTON_LEFT );
            break;
        case WM_LBUTTONUP:
            MouseReleased( p_event, MOUSE_BUTTON_LEFT );
            break;
        case WM_LBUTTONDBLCLK:
            vout_display_SendEventMouseDoubleClick(vd);
            break;

        case WM_MBUTTONDOWN:
            MousePressed( p_event, msg.hwnd, MOUSE_BUTTON_CENTER );
            break;
        case WM_MBUTTONUP:
            MouseReleased( p_event, MOUSE_BUTTON_CENTER );
            break;

        case WM_RBUTTONDOWN:
            MousePressed( p_event, msg.hwnd, MOUSE_BUTTON_RIGHT );
            break;
        case WM_RBUTTONUP:
            MouseReleased( p_event, MOUSE_BUTTON_RIGHT );
            break;

        case WM_KEYDOWN:
        case WM_SYSKEYDOWN:
        {
            /* The key events are first processed here and not translated
             * into WM_CHAR events because we need to know the status of the
             * modifier keys. */
            int i_key = DirectXConvertKey( msg.wParam );
            if( !i_key )
            {
                /* This appears to be a "normal" (ascii) key */
                i_key = tolower( MapVirtualKey( msg.wParam, 2 ) );
            }

            if( i_key )
            {
                if( GetKeyState(VK_CONTROL) & 0x8000 )
                {
                    i_key |= KEY_MODIFIER_CTRL;
                }
                if( GetKeyState(VK_SHIFT) & 0x8000 )
                {
                    i_key |= KEY_MODIFIER_SHIFT;
                }
                if( GetKeyState(VK_MENU) & 0x8000 )
                {
                    i_key |= KEY_MODIFIER_ALT;
                }

                vout_display_SendEventKey(vd, i_key);
            }
            break;
        }

        case WM_MOUSEWHEEL:
        {
            int i_key;
            if( GET_WHEEL_DELTA_WPARAM( msg.wParam ) > 0 )
            {
                i_key = KEY_MOUSEWHEELUP;
            }
            else
            {
                i_key = KEY_MOUSEWHEELDOWN;
            }
            if( i_key )
            {
                if( GetKeyState(VK_CONTROL) & 0x8000 )
                {
                    i_key |= KEY_MODIFIER_CTRL;
                }
                if( GetKeyState(VK_SHIFT) & 0x8000 )
                {
                    i_key |= KEY_MODIFIER_SHIFT;
                }
                if( GetKeyState(VK_MENU) & 0x8000 )
                {
                    i_key |= KEY_MODIFIER_ALT;
                }
                vout_display_SendEventKey(vd, i_key);
            }
            break;
        }

        case WM_VLC_CHANGE_TEXT:
        {
            vlc_mutex_lock( &p_event->lock );
            wchar_t *pwz_title = NULL;
            if( p_event->psz_title )
            {
                const size_t i_length = strlen(p_event->psz_title);
                pwz_title = malloc( 2 * (i_length + 1) );
                if( pwz_title )
                {
                    mbstowcs( pwz_title, p_event->psz_title, 2 * i_length );
                    pwz_title[i_length] = 0;
                }
            }
            vlc_mutex_unlock( &p_event->lock );

            if( pwz_title )
            {
                SetWindowTextW( p_event->hwnd, pwz_title );
                if( p_event->hfswnd )
                    SetWindowTextW( p_event->hfswnd, pwz_title );
                free( pwz_title );
            }
            break;
        }

        default:
            /* Messages we don't handle directly are dispatched to the
             * window procedure */
            TranslateMessage(&msg);
            DispatchMessage(&msg);
            break;

        } /* End Switch */

    } /* End Main loop */

    /* Check for WM_QUIT if we created the window */
    if( !p_event->hparent && msg.message == WM_QUIT )
    {
        msg_Warn( vd, "WM_QUIT... should not happen!!" );
        p_event->hwnd = NULL; /* Window already destroyed */
    }

    msg_Dbg( vd, "DirectXEventThread terminating" );

    DirectXCloseWindow( p_event );
    vlc_restorecancel(canc);
    return NULL;
}
Exemplo n.º 9
0
void render::run(rawTexture* imageList, int size){
	// variables
	Timer timer(1000 / 30);
	SDL_Renderer* ren;
	SDL_Window* win;
	int win_x = 200;
	int win_y = 200;
	int win_w = 400;
	int win_h = 400;

	// Create the window
	Uint32 window_flags = SDL_WINDOW_SHOWN;
	win = SDL_CreateWindow(
		"binPackerTest",
		win_x, win_y, win_w, win_h,
		window_flags
		);
	if(win == NULL){
		printf("Failed to create window\n");
		return;
	}

	// create the renderer
	Uint32 ren_flags = SDL_RENDERER_ACCELERATED;
	ren_flags = SDL_RENDERER_PRESENTVSYNC;
	ren = SDL_CreateRenderer(win, -1, ren_flags);
	if(ren == NULL){
		SDL_DestroyWindow(win);
		printf("Failed to create renderer\n");
		return;
	}

	// main loop
	SDL_Event e;
	bool exit_flag = false;
	bool draw_flag = false;
	timer.start();
	for(;;){
		while(SDL_PollEvent(&e) && exit_flag == false){
			if(e.type == SDL_QUIT){
				exit_flag = true;
			} else if(isKeyboardEvent(e)){
				const Uint8* keyboard = SDL_GetKeyboardState(NULL);
				if(keyboard[SDL_SCANCODE_ESCAPE]){
					SDL_Event ev;
					SDL_zero(ev);
					ev.type = SDL_QUIT;
					ev.quit.type = SDL_QUIT;
					ev.quit.timestamp = SDL_GetTicks();
					SDL_PushEvent(&ev);
				}
			} else if(isMouseEvent(e)){
				// do nothing				
			} else if(e.type >= SDL_USEREVENT){
				if(e.user.type == timer.type){
					draw_flag = true;
				}
				// do nothing
			}
		}

		if(exit_flag){ break; }
		if(draw_flag){
			// draw the shit here.
			SDL_RenderClear(ren);

			SDL_Rect rect;
			SDL_Color color = { 90, 90, 120, 140 };
			for(int i = 0; i < size; ++i){
				rect.x = imageList[i].extent.x();
				rect.y = imageList[i].extent.y();
				rect.w = imageList[i].extent.w();
				rect.h = imageList[i].extent.h();
				render_rectangle(ren, &rect, color);
			}

			SDL_RenderPresent(ren);
		}
	}

	// destruction
	timer.stop();
	SDL_DestroyRenderer(ren);
	SDL_DestroyWindow(win);
}
Exemplo n.º 10
0
bool EWAUserAction::isMouseEvent() const
{
    return m_pEvent ? isMouseEvent( m_pEvent->type() ) : false;
}