void handleMsg( ZMsg *msg ) { zviewpointHandleMsg( msg ); if( zMsgIsUsed() ) return; if( zmsgIs(type,Key) && zmsgIs(which,q) ) { cheReactionReset(); } }
void handleMsg( ZMsg *msg ) { zviewpointHandleMsg( msg ); if( zMsgIsUsed() ) return; if( zmsgIs(type,Key) && zmsgIs(which,q) ) { reset(); } if( zmsgIs(type,Key) && zmsgIs(which,w) ) { } }
void handleMsg( ZMsg *msg ) { if( zmsgIs( type, KeyDown ) ) { if( zmsgIs( which, ctrl_p ) ) { gWorldPause = !gWorldPause; } if( zmsgIs( which, ctrl_t ) ) { gWorldPause = 0; gWorldTick = 5; } if( zmsgIs( which, ctrl_r ) ) { gWorldPause = 0; gWorldTick = INT_MAX; } if( zmsgIs( which, ctrl_d ) ) { myApp->getModel()->dump(); } if( zmsgIs( which, ctrl_a ) ) { myApp->getModel()->alloc(); // realloc the world with current properties as set // by user } if( zmsgIs( which, ctrl_u ) ) { myApp->getModel()->unselectChakra(); } } }
void GUI3DDirectionArrow::handleMsg( ZMsg *msg ) { if( zmsgIs(type,MouseClickOn) && zmsgIs(which,L) && zmsgIs(dir,D) ) { startDrag = FVec2( zmsgF(localX), zmsgF(localY) ); startDragMat = mat; requestExclusiveMouse( 1, 1 ); zMsgUsed(); sendMsg(); } else if( zmsgIs(type,MouseReleaseDrag) ) { requestExclusiveMouse( 1, 0 ); zMsgUsed(); } else if( zmsgIs(type,MouseDrag) ) { FVec2 mouseDelta( zmsgF(localX), zmsgF(localY) ); mouseDelta.sub( startDrag ); mouseDelta.mul( 0.03f ); mat = startDragMat; FMat4 eye = mat; eye.setTrans( FVec3::Origin ); eye.inverse(); FVec3 yEye = eye.mul( FVec3::YAxisMinus ); FVec3 xEye = eye.mul( FVec3::XAxis ); mat.cat( rotate3D( yEye, mouseDelta.x ) ); mat.cat( rotate3D( xEye, mouseDelta.y ) ); zMsgUsed(); sendMsg(); } else if( zmsgIs(type,SetDir) ) { FVec3 xaxis( zmsgF(x), zmsgF(y), zmsgF(z) ); xaxis.mul(-1.f); FVec3 yaxis( 0.f, 1.f, 0.f ); yaxis.cross( xaxis ); FVec3 zaxis = yaxis; zaxis.cross( xaxis ); xaxis.normalize(); yaxis.normalize(); zaxis.normalize(); mat.m[0][0] = xaxis.x; mat.m[0][1] = xaxis.y; mat.m[0][2] = xaxis.z; mat.m[0][3] = 0.f; mat.m[1][0] = yaxis.x; mat.m[1][1] = yaxis.y; mat.m[1][2] = yaxis.z; mat.m[1][3] = 0.f; mat.m[2][0] = zaxis.x; mat.m[2][1] = zaxis.y; mat.m[2][2] = zaxis.z; mat.m[2][3] = 0.f; mat.m[3][0] = 0.f; mat.m[3][1] = 0.f; mat.m[3][2] = 0.f; mat.m[3][3] = 1.f; } }
void ZViewpoint::zviewpointHandleMsgFly( ZMsg *msg ) { static float viewpointMouseLast[2]; static int dragging = 0; float newzviewpointScale = 0.f; int scaleChange = 0; if( (zmsgIs(type,ZUIMouseClickOn) || zmsgIs(type,MouseClick)) && zmsgIs(dir,D) && (zmsgIs(which,R) || zmsgIs(which,M)) && zmsgI(shift) && zmsgI(ctrl) && zmsgI(alt) ) { // RESET memset( &zviewpointTrans, 0, sizeof(zviewpointTrans) ); zviewpointRotQuat.fromAxisAngle( FVec3::XAxis, 0.f ); zviewpointScale = 1.f; } char button = msg->getS( "which", "X" ) [0]; // if( (zmsgIs(type,ZUIMouseClickOn) || zmsgIs(type,MouseClick)) && zmsgIs(dir,D) && zmsgIs(which,M) ) { if( (zmsgIs(type,ZUIMouseClickOn) || zmsgIs(type,MouseClick)) && zmsgIs(dir,D) && button==zviewpointRotateButton ) { dragging = zMouseMsgRequestExclusiveDrag( "type=Viewpoint_MouseDrag" ); } if( zmsgIs(type,Viewpoint_MouseDrag) ) { if( zmsgI(releaseDrag) ) { zMouseMsgCancelExclusiveDrag(); } else { int _deltaX = zMouseMsgX - zMouseMsgLastX; int _deltaY = zMouseMsgY - zMouseMsgLastY; FQuat deltaX( FVec3::XAxis, -0.01f * _deltaX ); FQuat deltaY( FVec3::YAxis, +0.01f * _deltaY ); FQuat deltaZ; deltaX.mul( zviewpointRotQuat ); deltaY.mul( deltaX ); deltaZ.mul( deltaY ); zviewpointRotQuat = deltaZ; } } }
void ZUITabPanel::handleMsg( ZMsg *msg ) { ZUIPanel::handleMsg( msg ); if( zMsgIsUsed() ) return; if( zmsgIs(type,ZUITabButtonSelected) ) { int slavePanel = zmsgI(slavePanel); ZUI *z = headChild; if( z ) { // SKIP over the tabs panel z = z->nextSibling; } for( ; z; z=z->nextSibling ) { if( z->getI("slavePanel") == slavePanel ) { zMsgQueue( "type=ZUIShow toZUI='%s' tracemsg='ZUIShow (sent by %s) for %s'", z->name, name, z->name ); } else { zMsgQueue( "type=ZUIHide toZUI='%s' tracemsg='ZUIShow (sent by %s) for %s'", z->name, name, z->name ); } } } }
void ZViewpoint::zviewpointHandleMsgTrackball( ZMsg *msg ) { static float viewpointMouseLast[2]; static int dragging = 0; float newzviewpointScale = 0.f; int scaleChange = 0; if( (zmsgIs(type,ZUIMouseClickOn) || zmsgIs(type,MouseClick)) && zmsgIs(dir,D) && (zmsgIs(which,R) || zmsgIs(which,M)) && zmsgI(shift) && zmsgI(ctrl) && zmsgI(alt) ) { // RESET memset( &zviewpointTrans, 0, sizeof(zviewpointTrans) ); zviewpointRotQuat.fromAxisAngle( FVec3::XAxis, 0.f ); zviewpointScale = 1.f; } char button = msg->getS( "which", "X" ) [0]; // if( (zmsgIs(type,ZUIMouseClickOn) || zmsgIs(type,MouseClick)) && zmsgIs(dir,D) && ( ( zmsgIs(which,M) && (zviewpointPermitRotX||zviewpointPermitRotY||zviewpointPermitRotZ) ) || zmsgIs(which,R) ) ) { if( (zmsgIs(type,ZUIMouseClickOn) || zmsgIs(type,MouseClick)) && zmsgIs(dir,D) && ( ( button==zviewpointRotateButton && (zviewpointPermitRotX||zviewpointPermitRotY||zviewpointPermitRotZ) ) || button==zviewpointTranslateButton ) ) { // I added the checks on permitrot but I think that this is probably temporay. I probably need to put in // some kind of better mapping system so that calling code can assign the mappings that they want // I had commented out the M button for some reason probably because // it conflicted with something. But I need it in Jarle. So this probably // needs to turn into a option but I will leave it on until // I see what it is that needs it turned off. Of course the // higher level thing could trap it and "zmsgUsed" to make ti disappear viewpointMouseLast[0] = zmsgF(x); viewpointMouseLast[1] = zmsgF(y); dragging = zMouseMsgRequestExclusiveDrag( "type=Viewpoint_MouseDrag" ); if( dragging ) { zviewpointRotating = button == zviewpointRotateButton; zviewpointTranslating = button == zviewpointTranslateButton; } zMsgUsed(); } else if( zmsgIs( type, KeyDown ) ) { if( zmsgIs( which, down ) ) { zviewpointRotateTrackball( 0.f, -zviewpointRotateStep ); zMsgUsed(); } if( zmsgIs( which, up ) ) { zviewpointRotateTrackball( 0.f, +zviewpointRotateStep ); zMsgUsed(); } if( zmsgIs( which, left ) ) { zviewpointRotateTrackball( +zviewpointRotateStep, 0.f ); zMsgUsed(); } if( zmsgIs( which, right ) ) { zviewpointRotateTrackball( -zviewpointRotateStep, 0.f ); zMsgUsed(); } } else if( (zmsgIs(type,Key) && zmsgIs(which,wheelforward)) || (zmsgIs(type,Key) && !strcmp(msg->getS("which"),",") ) ) { newzviewpointScale = zviewpointScale * 0.8f; scaleChange = 1; zMsgUsed(); } else if( (zmsgIs(type,Key) && zmsgIs(which,wheelbackward)) || (zmsgIs(type,Key) && !strcmp(msg->getS("which"),".") ) ) { newzviewpointScale = zviewpointScale * 1.2f; scaleChange = 1; zMsgUsed(); } if( scaleChange && zviewpointPermitScale ) { float x = (float)zMouseMsgX; float y = (float)zMouseMsgY; // I want the world coord at which the mouse is pointing before the zoom // to be the same as the world coord at which the mouse is pointing after the zoom // @TODO: convert his mess into a single function DMat4 preScale = zviewpointReferenceModel; DMat4 preScaleMat( scale3D( DVec3(zviewpointScale, zviewpointScale, zviewpointScale) ) ); preScale.cat( preScaleMat ); DVec3 pre0, pre1; gluUnProject( x, y, 0.f, preScale, zviewpointReferenceProj, zviewpointReferenceViewport, &pre0.x, &pre0.y, &pre0.z ); gluUnProject( x, y, 1.f, preScale, zviewpointReferenceProj, zviewpointReferenceViewport, &pre1.x, &pre1.y, &pre1.z ); FVec3 wp0 = zviewpointLinePlaneIntersect( FVec3::Origin, FVec3::ZAxis, FVec3((float)pre0.x,(float)pre0.y,(float)pre0.z), FVec3((float)pre1.x,(float)pre1.y,(float)pre1.z) ); DMat4 postScale = zviewpointReferenceModel; DMat4 postScaleMat = ( scale3D( DVec3(newzviewpointScale, newzviewpointScale, newzviewpointScale) ) ); postScale.cat( postScaleMat ); DVec3 post0, post1; gluUnProject( x, y, 0.f, postScale, zviewpointReferenceProj, zviewpointReferenceViewport, &post0.x, &post0.y, &post0.z ); gluUnProject( x, y, 1.f, postScale, zviewpointReferenceProj, zviewpointReferenceViewport, &post1.x, &post1.y, &post1.z ); FVec3 wp1 = zviewpointLinePlaneIntersect( FVec3::Origin, FVec3::ZAxis, FVec3((float)post0.x,(float)post0.y,(float)post0.z), FVec3((float)post1.x,(float)post1.y,(float)post1.z) ); wp1.sub( wp0 ); zviewpointTrans.add( wp1 ); zviewpointScale = newzviewpointScale; } if( zmsgIs(type,Viewpoint_MouseDrag) ) { if( zmsgI(releaseDrag) ) { zMouseMsgCancelExclusiveDrag(); zviewpointRotating = zviewpointTranslating = 0; } else { if( zviewpointRotating ) { float dx = +0.01f * ( viewpointMouseLast[0] - zmsgF(x) ); float dy = -0.01f * ( viewpointMouseLast[1] - zmsgF(y) ); float side = zmsgI( shift ) ? ( (zmsgF(localX) < zmsgF(w)/2) ? -1.f : 1.f ) : 0.f; // note: the side doesn't really work if the object is being rendered in a ZUI because the // w here refers to the screen, and not the ZUI. zviewpointRotateTrackball( dx, dy, side ); viewpointMouseLast[0] = zmsgF(x); viewpointMouseLast[1] = zmsgF(y); zMsgUsed(); } // else if( zmsgI(r) ) { else if( zviewpointTranslating ) { // COMPUTE how big is one pixel at the world z-plane of interest // For now, this plane normal to the camera and passes-though the origin // Do this by unprojecting rays at the mouse current and last and then // solving for the world position at the intersection of that plane // CAT in tranforms which take place before the translate DMat4 m = zviewpointReferenceModel; DMat4 _m( scale3D( DVec3(zviewpointScale, zviewpointScale, zviewpointScale) ) ); m.cat( _m ); DMat4 _m1( trans3D( DVec3(zviewpointTrans )) ); m.cat( _m1 ); DVec3 p0, p1, p2, p3; gluUnProject( zmsgF(x), zmsgF(y), 0.f, m, zviewpointReferenceProj, zviewpointReferenceViewport, &p0.x, &p0.y, &p0.z ); gluUnProject( zmsgF(x), zmsgF(y), 1.f, m, zviewpointReferenceProj, zviewpointReferenceViewport, &p1.x, &p1.y, &p1.z ); gluUnProject( viewpointMouseLast[0], viewpointMouseLast[1], 0.f, m, zviewpointReferenceProj, zviewpointReferenceViewport, &p2.x, &p2.y, &p2.z ); gluUnProject( viewpointMouseLast[0], viewpointMouseLast[1], 1.f, m, zviewpointReferenceProj, zviewpointReferenceViewport, &p3.x, &p3.y, &p3.z ); FVec3 wp0 = zviewpointLinePlaneIntersect( FVec3::Origin, FVec3::ZAxis, FVec3((float)p0.x,(float)p0.y,(float)p0.z), FVec3((float)p1.x,(float)p1.y,(float)p1.z) ); FVec3 wp1 = zviewpointLinePlaneIntersect( FVec3::Origin, FVec3::ZAxis, FVec3((float)p2.x,(float)p2.y,(float)p2.z), FVec3((float)p3.x,(float)p3.y,(float)p3.z) ); wp0.sub( wp1 ); FVec3 delta( wp0.x, wp0.y, 0.f ); if( zmsgI(shift) ) { delta.x = 0.f; delta.y = 0.f; delta.z = wp0.y * 4.f; } zviewpointTrans.add( delta ); viewpointMouseLast[0] = zmsgF(x); viewpointMouseLast[1] = zmsgF(y); zMsgUsed(); } } } }
void GUIAttrEdit::handleMsg( ZMsg *msg ) { float lineH = getLineH(); int scroll = getAttrI( "scroll" ); float x = zmsgF(localX); float y = zmsgF(localY); if( zmsgIs(type,Key) && zmsgIs(which,wheelforward) ) { if( contains(x,y) ) { scroll-=2; scroll = max( -10, scroll ); scroll = min( view.count-5, scroll ); setAttrI( "scroll", scroll ); mouseOver = (int)( (myH-y) / lineH ); mouseOver += scroll; mouseOver = selected > view.count-1 ? view.count-1 : mouseOver; zMsgUsed(); } } else if( zmsgIs(type,Key) && zmsgIs(which,wheelbackward) ) { if( contains(x,y) ) { scroll+=2; scroll = max( -10, scroll ); scroll = min( view.count-5, scroll ); setAttrI( "scroll", scroll ); mouseOver = (int)( (myH-y) / lineH ); mouseOver += scroll; mouseOver = selected > view.count-1 ? view.count-1 : mouseOver; zMsgUsed(); } } else if( zmsgIs(type,MouseMove) ) { mouseOver = (int)( (myH-y) / lineH ); mouseOver += scroll; mouseOver = selected > view.count-1 ? view.count-1 : mouseOver; } else if( zmsgIs(type,MouseClickOn) && zmsgIs(dir,D) && zmsgI(ctrl) && zmsgI(shift) ) { //ADJUST the linIncrement if( zmsgIs(which,L) ) { linIncrement *= 2.f; } else if( zmsgIs(which,R) ) { linIncrement /= 2.f; } } else if( zmsgIs(type,MouseClickOn) && zmsgIs(dir,D) && zmsgIs(which,L) ) { selected = (int)( (myH-y) / lineH ); selected += scroll; selected = selected > view.count-1 ? view.count-1 : selected; ZHashTable *hash = (ZHashTable *)getAttrp( "hashPtr" ); if( !hash ) return; char *val = hash->getS( view[selected] ); char *end; double valD = strtod( val, &end ); if( end != val ) { // This is a number that can be manipulated // if( zmsgI(shift) && !zmsgI(ctrl) ) { // linMode = 0; // zMsgQueue( "type=GUIAttrEdit_CreateOptionMenu key=%s val=%lf toGUI=%s", selectVarPtr->name, selectVarPtr->getDouble(), getAttrS("name") ); // } // else { if( zmsgI(ctrl) && !zmsgI(shift) ) { linMode = 1; } else { linMode = 0; } selectX = x; selectY = y; mouseX = x; mouseY = y; startVal = valD; requestExclusiveMouse( 1, 1 ); // } } else { selected = -1; } /* ZVarPtr *selectVarPtr = getSelectedVar( selected ); if( selectVarPtr ) { if( zmsgI(shift) && !zmsgI(ctrl) ) { linMode = 0; zMsgQueue( "type=GUIAttrEdit_CreateOptionMenu key=%s val=%lf toGUI=%s", selectVarPtr->name, selectVarPtr->getDouble(), getAttrS("name") ); } else { if( zmsgI(ctrl) && !zmsgI(shift) ) { linMode = 1; } else { linMode = 0; } selectX = x; selectY = y; mouseX = x; mouseY = y; switch( selectVarPtr->type ) { case zVarTypeINT: startVal = (double)*(int *)selectVarPtr->ptr + 0.4; break; case zVarTypeSHORT: startVal = (double)*(short *)selectVarPtr->ptr + 0.4; break; case zVarTypeFLOAT: startVal = (double)*(float *)selectVarPtr->ptr; break; case zVarTypeDOUBLE: startVal = (double)*(double *)selectVarPtr->ptr; break; } requestExclusiveMouse( 1, 1 ); } } */ zMsgUsed(); return; } else if( zmsgIs(type,MouseReleaseDrag) ) { if( selected >= 0 ) { // ZVarPtr *selectVarPtr = getSelectedVar( selected ); // if( selectVarPtr ) { // zMsgQueue( "type=GUIAttrEdit_VarDoneChange key=%s val=%lf", selectVarPtr->name, selectVarPtr->getDouble() ); // } } requestExclusiveMouse( 1, 0 ); selected = -1; zMsgUsed(); return; } else if( zmsgIs(type,MouseDrag) && zmsgI(l) ) { int last = -1; int count = 0; //while( count++ != selected+1 && zVarsEnum( last, selectVarPtr, regExp ) ); ZHashTable *hash = (ZHashTable *)getAttrp( "hashPtr" ); double val = hash->getD( view[selected] ); mouseX = x; mouseY = y; if( linMode ) { val = startVal + (mouseY-selectY) * linIncrement; } else{ val = startVal * exp( (mouseY-selectY) / 50.0 ); } hash->putS( view[selected], ZTmpStr("%4.3le",val) ); } else if( zmsgIs(type,MouseClickOn) && zmsgIs(dir,D) && zmsgIs(which,R) ) { selectX = x; selectY = y; startScroll = scroll; requestExclusiveMouse( 1, 1 ); zMsgUsed(); return; } else if( zmsgIs(type,MouseDrag) && zmsgI(r) ) { scroll = (int)( startScroll + ( y - selectY ) / lineH ); scroll = max( -10, scroll ); scroll = min( view.count-5, scroll ); setAttrI( "scroll", scroll ); } else if( zmsgIs(type,GUIAttrEdit_Clear) ) { clearView(); } // else if( zmsgIs(type,GUIAttrEdit_Add) ) { // if( zmsgHas(regexp) ) { // addVarsByRegExp( zmsgS(regexp) ); // } // else if( zmsgHas(name) ) { // addVar( zmsgS(name) ); // } // } else if( zmsgIs(type,GUIAttrEdit_Sort) ) { if( zmsgIs(which,name) ) { sortViewByName(); } // else if( zmsgIs(which,order) ) { // sortViewByDeclOrder(); // } } else if( zmsgIs(type,GUIAttrEdit_CreateOptionMenu) ) { ZHashTable hash; hash.putS( "who", getAttrS("name") ); hash.putS( "key", zmsgS(key) ); hash.putS( "val", ZTmpStr("%1.2e", zmsgF(val)) ); createOptionMenu( &hash ); optMenuUp = 1; zMsgQueue( "type=GUILayout toGUI=varEditOptMenu" ); zMsgQueue( "type=GUIMoveNear who=%s where=T x=4 y=%f toGUI=varEditOptMenu", getAttrS("name"), -(mouseOver-scroll)*lineH ); zMsgQueue( "type=GUISetModal val=1 toGUI=varEditOptMenu" ); } else if( zmsgIs(type,GUIAttrEdit_CreateOptionMenuDone) ) { optMenuUp = 0; selected = -1; } else if( zmsgIs(type,GUIAttrEdit_CreateOptionMenuDirectEntry) ) { GUIObject *obj = guiFind( zmsgS(fromGUI) ); if( obj ) { zMsgQueue( "type=SetVar key=%s val=%f", zmsgS(key), atof(obj->getAttrS("text")) ); } } // else if( zmsgIs(type,GUIAttrEdit_ResetAll) ) { // for( int i=0; i<view.count; i++ ) { // ZVarPtr *v = zVarsLookup( varsView.vec[i] ); // v->resetDefault(); // } // } else if( zmsgIs(type,GUIAttrEdit_Clear) ) { clearView(); } else if( zmsgIs(type,GUIAttrEdit_Add) ) { addVar( zmsgS(key) ); } else if( zmsgIs(type,GUIAttrEdit_ViewAll) ) { if( zmsgI(clear) ) { clearView(); } addAllVars(); } GUIPanel::handleMsg( msg ); }