예제 #1
0
void Dialog::run_step(bool block)
{
   ALLEGRO_EVENT event;

   if (block) {
      al_wait_for_event(event_queue, NULL);
   }

   while (al_get_next_event(event_queue, &event)) {
      switch (event.type) {
         case ALLEGRO_EVENT_DISPLAY_CLOSE:
            this->request_quit();
            break;

         case ALLEGRO_EVENT_KEY_DOWN:
         case ALLEGRO_EVENT_KEY_REPEAT:
            on_key_down(event.keyboard);
            break;

         case ALLEGRO_EVENT_MOUSE_AXES:
            on_mouse_axes(event.mouse);
            break;

         case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
            on_mouse_button_down(event.mouse);
            break;

         case ALLEGRO_EVENT_MOUSE_BUTTON_UP:
            on_mouse_button_up(event.mouse);
            break;

         case ALLEGRO_EVENT_DISPLAY_EXPOSE:
            this->request_draw();
            break;

         default:
            if (event_handler) {
               event_handler->handle_event(event);
            }
            break;
      }
   }
}
예제 #2
0
 virtual void on_mouse_move(int x, int y, unsigned flags)
 {
     on_mouse_button_down(x, y, flags);
 }
예제 #3
0
    //------------------------------------------------------------------------
    int platform_support::run()
    {
        SDL_Event event;
        bool ev_flag = false;

        for(;;)
        {
            if(m_specific->m_update_flag)
            {
                on_draw();
                update_window();
                m_specific->m_update_flag = false;
            }

            ev_flag = false;
            if(m_wait_mode)
            {
                SDL_WaitEvent(&event);
                ev_flag = true;
            }
            else
            {
                if(SDL_PollEvent(&event))
                {
                    ev_flag = true;
                }
                else
                {
                    on_idle();
                }
            }

            if(ev_flag)
            {
                if(event.type == SDL_QUIT)
                {
                    break;
                }

                int y;
                unsigned flags = 0;

                switch (event.type) 
                {
                case SDL_VIDEORESIZE:
                    if(!init(event.resize.w, event.resize.h, m_window_flags)) return false;
                    on_resize(m_rbuf_window.width(), m_rbuf_window.height());
                    trans_affine_resizing(event.resize.w, event.resize.h);
                    m_specific->m_update_flag = true;
                    break;

                case SDL_KEYDOWN:
                    {
                        flags = 0;
                        if(event.key.keysym.mod & KMOD_SHIFT) flags |= kbd_shift;
                        if(event.key.keysym.mod & KMOD_CTRL)  flags |= kbd_ctrl;

                        bool left  = false;
                        bool up    = false;
                        bool right = false;
                        bool down  = false;

                        switch(event.key.keysym.sym)
                        {
                        case key_left:
                            left = true;
                            break;

                        case key_up:
                            up = true;
                            break;

                        case key_right:
                            right = true;
                            break;

                        case key_down:
                            down = true;
                            break;
                        }

                        if(m_ctrls.on_arrow_keys(left, right, down, up))
                        {
                            on_ctrl_change();
                            force_redraw();
                        }
                        else
                        {
                            on_key(m_specific->m_cur_x,
                                   m_specific->m_cur_y,
                                   event.key.keysym.sym,
                                   flags);
                        }
                    }
                    break;

                case SDL_MOUSEMOTION:
                    y = m_flip_y ? 
                        m_rbuf_window.height() - event.motion.y : 
                        event.motion.y;

                    m_specific->m_cur_x = event.motion.x;
                    m_specific->m_cur_y = y;
                    flags = 0;
                    if(event.motion.state & SDL_BUTTON(1)) flags |= mouse_left;
                    if(event.motion.state & SDL_BUTTON(3)) flags |= mouse_right;

                    if(m_ctrls.on_mouse_move(m_specific->m_cur_x, 
                                             m_specific->m_cur_y,
                                             (flags & mouse_left) != 0))
                    {
                        on_ctrl_change();
                        force_redraw();
                    }
                    else
                    {
                        on_mouse_move(m_specific->m_cur_x, 
                                      m_specific->m_cur_y, 
                                      flags);
                    }
		    SDL_Event eventtrash;
		    while (SDL_PeepEvents(&eventtrash, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_MOUSEMOTION))!=0){;}
                    break;

                case SDL_MOUSEBUTTONDOWN:
                    y = m_flip_y ? 
                        m_rbuf_window.height() - event.motion.y : 
                        event.motion.y;

                    m_specific->m_cur_x = event.motion.x;
                    m_specific->m_cur_y = y;
                    flags = 0;
                    if(event.button.button == SDL_BUTTON_LEFT)  flags = mouse_left;
                    if(event.button.button == SDL_BUTTON_RIGHT) flags = mouse_right;

                    if(flags & mouse_left)
                    {
                        if(m_ctrls.on_mouse_button_down(m_specific->m_cur_x, 
                                                        m_specific->m_cur_y))
                        {
                            m_ctrls.set_cur(m_specific->m_cur_x, 
                                            m_specific->m_cur_y);
                            on_ctrl_change();
                            force_redraw();
                        }
                        else
                        {
                            if(m_ctrls.in_rect(m_specific->m_cur_x, 
                                               m_specific->m_cur_y))
                            {
                                if(m_ctrls.set_cur(m_specific->m_cur_x, 
                                                   m_specific->m_cur_y))
                                {
                                    on_ctrl_change();
                                    force_redraw();
                                }
                            }
                            else
                            {
                                on_mouse_button_down(m_specific->m_cur_x, 
                                                     m_specific->m_cur_y, 
                                                     flags);
                            }
                        }
                    }
                    if(flags & mouse_right)
                    {
                        on_mouse_button_down(m_specific->m_cur_x, 
                                             m_specific->m_cur_y, 
                                             flags);
                    }
                    break;

                case SDL_MOUSEBUTTONUP:
                    y = m_flip_y ? 
                        m_rbuf_window.height() - event.motion.y : 
                        event.motion.y;

                    m_specific->m_cur_x = event.motion.x;
                    m_specific->m_cur_y = y;
                    flags = 0;
                    if(m_ctrls.on_mouse_button_up(m_specific->m_cur_x, 
                                                  m_specific->m_cur_y))
                    {
                        on_ctrl_change();
                        force_redraw();
                    }
                    on_mouse_button_up(m_specific->m_cur_x, 
                                       m_specific->m_cur_y, 
                                       flags);
                    break;
                }
            }
        }
        return 0;
    }
예제 #4
0
    //------------------------------------------------------------------------
    int platform_support::run()
    {
        SDL_Event event;
        bool ev_flag = false;

        for(;;)
        {
            if(m_specific->m_update_flag)
            {
                on_draw();
                update_window();
                m_specific->m_update_flag = false;
            }

            ev_flag = false;
            if(m_wait_mode)
            {
                SDL_WaitEvent(&event);
                ev_flag = true;
            }
            else
            {
                if(SDL_PollEvent(&event))
                {
                    ev_flag = true;
                }
                else
                {
                    on_idle();
                }
            }

            if(ev_flag)
            {
                if(event.type == SDL_QUIT)
                {
                    break;
                }

                int y;
                unsigned flags = 0;

                switch (event.type) 
                {
                   int event_x;
                   int event_y;

                   case SDL_WINDOWEVENT:
                      switch (event.window.event)
                      {
                         case SDL_WINDOWEVENT_RESIZED:
                            ERROR_PRINT("SDL_WINDOWEVENT_RESIZED %d,%d\n", event.window.data1, event.window.data2);
#ifndef __ANDROID__
                            if(!init(event.window.data1, event.window.data2, m_window_flags)) return false;
                            on_resize(m_rbuf_window.width(), m_rbuf_window.height());
                            trans_affine_resizing(event.window.data1, event.window.data2);
#endif
                            m_specific->m_update_flag = true;
                            break;
                         default:
                            DEBUG_PRINT("unknown win event type %d\n", event.window.event);
                            break;
                      }
                      break;

                case SDL_APP_DIDENTERFOREGROUND:
                   DEBUG_PRINT("SDL_APP_DIDENTERFOREGROUND");
                   enter_foreground();
                   break;

                case SDL_APP_WILLENTERFOREGROUND:
                   DEBUG_PRINT("SDL_APP_WILLENTERFOREGROUND");
                   break;

                case SDL_APP_DIDENTERBACKGROUND:
                   DEBUG_PRINT("SDL_APP_DIDENTERBACKGROUND");
                   enter_background();
                   break;

                case SDL_APP_WILLENTERBACKGROUND:
                   DEBUG_PRINT("SDL_APP_WILLENTERBACKGROUND");
                   break;

                case SDL_KEYDOWN:
                    {
                        flags = 0;
                        if(event.key.keysym.mod & KMOD_SHIFT) flags |= kbd_shift;
                        if(event.key.keysym.mod & KMOD_CTRL)  flags |= kbd_ctrl;

                        bool left  = false;
                        bool up    = false;
                        bool right = false;
                        bool down  = false;

                        switch(event.key.keysym.sym)
                        {
                        case key_left:
                            left = true;
                            break;

                        case key_up:
                            up = true;
                            break;

                        case key_right:
                            right = true;
                            break;

                        case key_down:
                            down = true;
                            break;
                        }

                        if(m_ctrls.on_arrow_keys(left, right, down, up))
                        {
                            on_ctrl_change();
                            force_redraw();
                        }
                        else
                        {
                            on_key(m_specific->m_cur_x,
                                   m_specific->m_cur_y,
                                   event.key.keysym.sym,
                                   flags);
                        }
                    }
                    break;

                case SDL_MOUSEMOTION:
                    event_x = (double)event.button.x*width_factor;
                    event_y = (double)event.button.y*hight_factor;
                    y = m_flip_y ? 
                        m_rbuf_window.height() - event_y : 
                        event_y;

                    m_specific->m_cur_x = event_x;
                    m_specific->m_cur_y = y;
                    flags = 0;
                    if(event.motion.state & SDL_BUTTON_LMASK) flags |= mouse_left;
                    if(event.motion.state & SDL_BUTTON_RMASK) flags |= mouse_right;

                    if(m_ctrls.on_mouse_move(m_specific->m_cur_x, 
                                             m_specific->m_cur_y,
                                             (flags & mouse_left) != 0))
                    {
                        on_ctrl_change();
                        force_redraw();
                    }
                    else
                    {
                        on_mouse_move(m_specific->m_cur_x, 
                                      m_specific->m_cur_y, 
                                      flags);
                    }
		    SDL_Event eventtrash;
		    while (SDL_PeepEvents(&eventtrash, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION)!=0){;}
                    break;

		case SDL_MOUSEBUTTONDOWN:
                    event_x = (double)event.button.x*width_factor;
                    event_y = (double)event.button.y*hight_factor;
                    DEBUG_PRINT("mouse down: %d,%d %d,%d\n", event.button.x,event.button.y,
                          event_x,event_y);

                    y = m_flip_y
                        ? m_rbuf_window.height() - event_y
                        : event_y;

                    m_specific->m_cur_x = event_x;
                    m_specific->m_cur_y = y;
                    flags = 0;
                    DEBUG_PRINT("mouse down: %d,%d w %d,%d\n", event_x,y,
                          m_rbuf_window.width(), m_rbuf_window.height());
                    switch(event.button.button)
                    {
                    case SDL_BUTTON_LEFT:
                        {
                            flags = mouse_left;

if(m_ctrls.on_mouse_button_down(m_specific->m_cur_x,
                                m_specific->m_cur_y))
                            {
                                m_ctrls.set_cur(m_specific->m_cur_x, 
                                    m_specific->m_cur_y);
                                on_ctrl_change();
                                force_redraw();
                            }
                            else
                            {
                                if(m_ctrls.in_rect(m_specific->m_cur_x, 
                                    m_specific->m_cur_y))
                                {
                                    if(m_ctrls.set_cur(m_specific->m_cur_x, 
                                        m_specific->m_cur_y))
                                    {
                                        on_ctrl_change();
                                        force_redraw();
                                    }
                                }
                                else
                                {
                                    on_mouse_button_down(m_specific->m_cur_x, 
                                        m_specific->m_cur_y, 
                                        flags);
                                }
                            }
                        }
                        break;
                    case SDL_BUTTON_RIGHT:
                        DEBUG_PRINT("SDL_BUTTON_RIGHT");
                        flags = mouse_right;
                        on_mouse_button_down(m_specific->m_cur_x, 
                            m_specific->m_cur_y, 
                            flags);
                        break;
                    } //switch(event.button.button)
                    break;
		    
                case SDL_MOUSEBUTTONUP:
                    event_x = (double)event.button.x*width_factor;
                    event_y = (double)event.button.y*hight_factor;
                    y = m_flip_y
                        ? m_rbuf_window.height() - event_y
                        : event_y;

                    m_specific->m_cur_x = event_x;
                    m_specific->m_cur_y = y;
                    flags = 0;
                    if(m_ctrls.on_mouse_button_up(m_specific->m_cur_x, 
                                                  m_specific->m_cur_y))
                    {
                        on_ctrl_change();
                        force_redraw();
                    }
                    on_mouse_button_up(m_specific->m_cur_x, 
                                       m_specific->m_cur_y, 
                                       flags);
                    break;
                case SDL_MOUSEWHEEL:
                    break;
                case SDL_FINGERDOWN:
                case SDL_FINGERUP:
                case SDL_FINGERMOTION:
                    DEBUG_PRINT("Finger: x=%f, y=%f dx=%f, dy=%f, %d\n",
                          event.tfinger.x,
                          event.tfinger.y,
                          event.tfinger.dx,
                          event.tfinger.dy,
                          (int)event.tfinger.fingerId);
                    on_touch_event(
                          event.tfinger.x,
                          m_flip_y ? 1-event.tfinger.y: event.tfinger.y,
                          event.tfinger.dx,
                          event.tfinger.dy,
                          (int)event.tfinger.fingerId,
                          !(event.type == SDL_FINGERUP));
                    break;
                case SDL_MULTIGESTURE:
                    DEBUG_PRINT("Multi Gesture: x = %f, y = %f, dAng = %f, dR = %f numDownTouch = %i\n",
                          event.mgesture.x,
                          event.mgesture.y,
                          event.mgesture.dTheta,
                          event.mgesture.dDist,
                          event.mgesture.numFingers);
                    on_multi_gesture(
                          event.mgesture.x,
                          event.mgesture.y,
                          event.mgesture.dTheta,
                          event.mgesture.dDist,
                          event.mgesture.numFingers);
                    break;
                default:
                    DEBUG_PRINT("unknown event type %d\n", event.type);
                    break;
                }
            }
        }
        return 0;
    }