Scroll wheel as pinch zoom in Cocos2d for Windows

Hey everyone,

I’ve added some code to CCEGLView_win32.cpp/.h that adds some primitive scroll wheel support. This is useful for testing pinching features on Windows machines.

In CCEGLView_win32.h, I’ve added a new private variable: CCTouch *m_pTouch2 and m_eZoom;
In CCEGLView::CCEGLView(), allocate the new variable m_pTouch2, and set m_eZoom = 0.

Finally, in CCEGLView::WindowProc, add:

case WM_MOUSEWHEEL:
if((short) HIWORD (wParam) < 0){
m_eZoom++;
}else{
m_eZoom—;
}

if(m_eZoom >= 24){
m_eZoom = 24;
}

if(m_eZoom <= ~~24){
m_eZoom =~~24;
}

//Add upper touch point
m_pTouch~~>SetTouchInfo) / m_fScreenScaleFactor,
) / m_fScreenScaleFactor);
m_pSet~~>addObject(m_pTouch);
//Add lower touch point
m_pTouch2~~>SetTouchInfo) / m_fScreenScaleFactor,
) / m_fScreenScaleFactor);
m_pSet~~>addObject(m_pTouch2);
//Send touch to delegate
m_pDelegate~~>touchesMoved;
m_pSet~~>removeObject(m_pTouch);
m_pSet~~>removeObject;
break;
To use the new feature, in a touchesMoved callback:
switch ) {
case 1:
break;
case 2:
touch1 = );
touches~~>removeObject(touch1);
touch2 = (CCTouch*)(*touches->begin());

break;
}

Like I said, it is pretty primitive, feedback is welcome!

Austin

Thanks, very useful. I’ve tried to modify it a bit to support scrolling in a ccscrolllayer using the scrollwheel, but I couldn’t get it to work. Do you by any chance have an idea on how I can accomplish that ?

Nevermind, I solved it by simulating a click, move and release every time a WM_MOUSEWHEEL message is received. Works perfectly.

Yeah that’s what I did too, works fine and you can even zoom at the mouse pointer position.
Here’s my code to add to CCEGLView_win32.cpp if anyone’s interested:

case WM_MOUSEWHEEL: {
    int id[2] = {1,2};
    POINT point = {(short)LOWORD(lParam),(short)HIWORD(lParam)};
    ScreenToClient(m_hWnd,&point);
    CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR());
    pt.x *= m_windowTouchScaleX;  pt.y *= m_windowTouchScaleY;
    float xs[2] = {pt.x+20,pt.x-20};
    float ys[2] = {pt.y+20,pt.y-20};            
    handleTouchesBegin(2, id, xs, ys);
    float step=((short) HIWORD(wParam) < 0)?10:-10;
    xs[0]-=step; ys[0]-=step; 
    xs[1]+=step; ys[1]+=step;
    handleTouchesMove(2,id,xs,ys);
    handleTouchesEnd(2,id,xs,ys);
    break;
}

I used a WM_MOUSEWHEEL case. However, I sent the events to KeyboardDispatcher.