Ejemplo n.º 1
0
    //------------------------------------------------------------------------
    bool gamma_ctrl_impl::on_mouse_move(double x, double y, bool button_flag)
    {
        inverse_transform_xy(&x, &y);
        if(!button_flag)
        {
            return on_mouse_button_up(x, y);
        }

        if(m_mouse_point == 1)
        {
            m_xp1 = x + m_pdx;
            m_yp1 = y + m_pdy;
            calc_values();
            return true;
        }
        if(m_mouse_point == 2)
        {
            m_xp2 = x + m_pdx;
            m_yp2 = y + m_pdy;
            calc_values();
            return true;
        }
        return false;
    }
Ejemplo n.º 2
0
  virtual void on_mouse_move(int x, int y, unsigned flags) {
    if (flags & agg::mouse_left) {
      if (m_idx == 3) {
        double dx = x - m_dx;
        double dy = y - m_dy;
        m_x[1] -= m_x[0] - dx;
        m_y[1] -= m_y[0] - dy;
        m_x[2] -= m_x[0] - dx;
        m_y[2] -= m_y[0] - dy;
        m_x[0] = dx;
        m_y[0] = dy;
        force_redraw();
        return;
      }

      if (m_idx >= 0) {
        m_x[m_idx] = x - m_dx;
        m_y[m_idx] = y - m_dy;
        force_redraw();
      }
    } else {
      on_mouse_button_up(x, y, flags);
    }
  }
Ejemplo n.º 3
0
    //------------------------------------------------------------------------
    bool scale_ctrl_impl::on_mouse_move(double x, double y, bool button_flag)
    {
        inverse_transform_xy(&x, &y);
        if(!button_flag)
        {
            return on_mouse_button_up(x, y);
        }

        double xp = x + m_pdx;
        double yp = y + m_pdy;
        double dv;

        switch(m_move_what)
        {
        case move_value1:
            if(fabs(m_x2 - m_x1) > fabs(m_y2 - m_y1))
            {
                m_value1 = (xp - m_xs1) / (m_xs2 - m_xs1);
            }
            else
            {
                m_value1 = (yp - m_ys1) / (m_ys2 - m_ys1);
            }
            if(m_value1 < 0.0) m_value1 = 0.0;
            if(m_value1 > m_value2 - m_min_d) m_value1 = m_value2 - m_min_d;
            return true;

        case move_value2:
            if(fabs(m_x2 - m_x1) > fabs(m_y2 - m_y1))
            {
                m_value2 = (xp - m_xs1) / (m_xs2 - m_xs1);
            }
            else
            {
                m_value2 = (yp - m_ys1) / (m_ys2 - m_ys1);
            }
            if(m_value2 > 1.0) m_value2 = 1.0;
            if(m_value2 < m_value1 + m_min_d) m_value2 = m_value1 + m_min_d;
            return true;

        case move_slider:
            dv = m_value2 - m_value1;
            if(fabs(m_x2 - m_x1) > fabs(m_y2 - m_y1))
            {
                m_value1 = (xp - m_xs1) / (m_xs2 - m_xs1);
            }
            else
            {
                m_value1 = (yp - m_ys1) / (m_ys2 - m_ys1);
            }
            m_value2 = m_value1 + dv;
            if(m_value1 < 0.0)
            {
                dv = m_value2 - m_value1;
                m_value1 = 0.0;
                m_value2 = m_value1 + dv;
            }
            if(m_value2 > 1.0)
            {
                dv = m_value2 - m_value1;
                m_value2 = 1.0;
                m_value1 = m_value2 - dv;
            }
            return true;
        }

        return false;
    }
Ejemplo n.º 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) 
                {
                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;
    }
Ejemplo n.º 5
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;
    }