Changeset 2624


Ignore:
Timestamp:
08/03/07 16:42:50 (6 years ago)
Author:
mickey
Message:

add neod skeleton

Location:
trunk/src/target/OM-2007.2
Files:
15 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/target/OM-2007.2/applications/fingerscroll/example.c

    r2483 r2624  
    114114   
    115115  w = scroll = moko_finger_scroll_new (); 
     116  g_object_set( G_OBJECT(scroll), "mode", MOKO_FINGER_SCROLL_MODE_PHYSICAL, NULL );  
    116117  gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0); 
    117118 
  • trunk/src/target/OM-2007.2/applications/fingerscroll/moko-finger-scroll.c

    r2499 r2624  
    11 
     2#include <glib.h> 
    23#include "moko-finger-scroll.h" 
    34 
     
    67  (G_TYPE_INSTANCE_GET_PRIVATE ((o), MOKO_TYPE_FINGER_SCROLL, MokoFingerScrollPrivate)) 
    78typedef struct _MokoFingerScrollPrivate MokoFingerScrollPrivate; 
     9 
     10typedef struct _point point; 
     11struct _point 
     12{ 
     13        gdouble x; 
     14        gdouble y; 
     15        gint32 time; 
     16}; 
    817 
    918struct _MokoFingerScrollPrivate { 
     
    1322        gdouble ex; 
    1423        gdouble ey; 
     24        point prev_values[3]; 
    1525        gboolean enabled; 
    1626        gboolean clicked; 
     
    2333        gdouble vel_x; 
    2434        gdouble vel_y; 
    25          
     35; 
     36 
    2637        GtkWidget *align; 
    2738        gboolean hscroll; 
     
    3849}; 
    3950 
     51#define PHYSICAL_MOVE_PERIOD 300 
     52 
     53static gint32 
     54time_diff (gint32 t1, gint32 t2) 
     55{ 
     56        if (t2 > t1) 
     57                return t2-t1; 
     58        else 
     59                return ((gint64)t2 + 1<<32) - (gint64)t1; 
     60} 
     61 
     62static void 
     63rough_linear (point p0, point p1, point p2, gdouble *xm, gdouble *ym) 
     64{ 
     65        /* just calulate two slopes and avarage */ 
     66        *xm = (((p0.x-p1.x) / time_diff(p1.time,p0.time)) 
     67                + ((p0.x-p1.x) / time_diff(p2.time,p0.time))) / 2; 
     68        *ym = (((p0.y-p1.y) / time_diff(p1.time,p0.time)) 
     69                + ((p0.y-p2.y) / time_diff(p2.time,p0.time))) / 2; 
     70} 
     71 
    4072static gboolean 
    4173moko_finger_scroll_button_press_cb (MokoFingerScroll *scroll, 
     
    5183        priv->x = event->x; 
    5284        priv->y = event->y; 
     85        priv->ex = event->x; 
     86        priv->ey = event->y; 
    5387        priv->moved = FALSE; 
    5488        priv->clicked = TRUE; 
     
    5690        priv->vel_x = 0; 
    5791        priv->vel_y = 0; 
    58          
     92 
     93        priv->prev_values[0].x = event->x; 
     94        priv->prev_values[0].y = event->y; 
     95        priv->prev_values[0].time = event->time; 
     96        priv->prev_values[1].x = event->x; 
     97        priv->prev_values[1].y = event->y; 
     98        priv->prev_values[1].time = event->time; 
    5999        return TRUE; 
    60100} 
     
    112152        MokoFingerScrollPrivate *priv = FINGER_SCROLL_PRIVATE (scroll); 
    113153         
     154        g_debug ("vel_x=%f, vel_y=%fr",priv->vel_x,priv->vel_y); 
     155 
    114156        if ((!priv->enabled) || 
    115             (priv->mode != MOKO_FINGER_SCROLL_MODE_ACCEL)) return FALSE; 
     157            (priv->mode == MOKO_FINGER_SCROLL_MODE_PUSH)) return FALSE; 
    116158        if (!priv->clicked) { 
    117159                /* Decelerate gradually when pointer is raised */ 
     
    187229                                (priv->vmax-priv->vmin)) + priv->vmin); 
    188230                        break; 
     231                    case MOKO_FINGER_SCROLL_MODE_PHYSICAL: 
     232                        /* Scroll by the amount of pixels the cursor has moved 
     233                         * since the last motion event. 
     234                         */ 
     235                        moko_finger_scroll_scroll (scroll, x, y, NULL, NULL); 
     236                        priv->prev_values[1].x = priv->prev_values[0].x; 
     237                        priv->prev_values[1].y = priv->prev_values[0].y; 
     238                        priv->prev_values[1].time = priv->prev_values[0].time; 
     239                        priv->prev_values[0].x = event->x; 
     240                        priv->prev_values[0].y = event->y; 
     241                        priv->prev_values[0].time = event->time; 
     242                        priv->x = event->x; 
     243                        priv->y = event->y; 
     244                             
     245                        break; 
     246         
    189247                    default : 
    190248                        break; 
     
    273331                ((GdkEvent *)event)->type = GDK_BUTTON_RELEASE; 
    274332                gdk_event_put ((GdkEvent *)event); 
     333        } 
     334        if (priv->moved && priv->mode == MOKO_FINGER_SCROLL_MODE_PHYSICAL) { 
     335                point p0; 
     336                gdouble velx, vely; 
     337                p0.x = event->x; 
     338                p0.y = event->y; 
     339                p0.time = event->time; 
     340                g_debug ("doing physical"); 
     341                /*velx and vely are in pixels/ms..*/ 
     342                rough_linear (p0, priv->prev_values[0], priv->prev_values[1], &velx, &vely); 
     343                 
     344                priv->vel_x = (velx * 1000.0) / priv->sps; 
     345                priv->vel_y = (vely * 1000.0) / priv->sps; 
     346                g_timeout_add ((gint)(1000.0/(gdouble)priv->sps), 
     347                        (GSourceFunc)moko_finger_scroll_timeout, 
     348                        scroll); 
    275349        } 
    276350 
     
    514588                        "Change the finger-scrolling mode.", 
    515589                        MOKO_FINGER_SCROLL_MODE_PUSH, 
    516                         MOKO_FINGER_SCROLL_MODE_ACCEL, 
    517                         MOKO_FINGER_SCROLL_MODE_ACCEL, 
     590                        MOKO_FINGER_SCROLL_MODE_PHYSICAL, 
     591                        MOKO_FINGER_SCROLL_MODE_PHYSICAL, 
    518592                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); 
    519593 
  • trunk/src/target/OM-2007.2/applications/fingerscroll/moko-finger-scroll.h

    r2499 r2624  
    4040        MOKO_FINGER_SCROLL_MODE_PUSH, 
    4141        MOKO_FINGER_SCROLL_MODE_ACCEL, 
     42        MOKO_FINGER_SCROLL_MODE_PHYSICAL, 
    4243} MokoFingerScrollMode; 
    4344 
Note: See TracChangeset for help on using the changeset viewer.