Ejemplo n.º 1
0
BOOL LLWindowMacOSX::setCursorPosition(const LLCoordWindow position)
{
	BOOL result = FALSE;
	LLCoordScreen screen_pos;

	if (!convertCoords(position, &screen_pos))
	{
		return FALSE;
	}

	CGPoint newPosition;

	//	LL_INFOS() << "setCursorPosition(" << screen_pos.mX << ", " << screen_pos.mY << ")" << LL_ENDL;

	newPosition.x = screen_pos.mX;
	newPosition.y = screen_pos.mY;

	CGSetLocalEventsSuppressionInterval(0.0);
	if(CGWarpMouseCursorPosition(newPosition) == noErr)
	{
		result = TRUE;
	}

	// Under certain circumstances, this will trigger us to decouple the cursor.
	adjustCursorDecouple(true);

	// trigger mouse move callback
	LLCoordGL gl_pos;
	convertCoords(position, &gl_pos);
	mCallbacks->handleMouseMove(this, gl_pos, (MASK)0);

	return result;
}
Ejemplo n.º 2
0
void Input::mouseVisible(bool visible)
{
    if (visible)
    {
#ifdef __APPLE__
    	CGAssociateMouseAndMouseCursorPosition(TRUE);
	    CGDisplayShowCursor(kCGDirectMainDisplay);
#else
        glfwEnable(GLFW_MOUSE_CURSOR);
        glfwSetMousePos(m_mouseMiddleX, m_mouseMiddleY);
#endif
    }
    else
    {
#ifdef __APPLE__
	    glfwSetMousePos(m_mouseMiddleX, m_mouseMiddleY);
        CGDisplayHideCursor(kCGDirectMainDisplay);
	    CGPoint p;
	    p.x = m_mouseMiddleX;
	    p.y = m_mouseMiddleY;
	    //CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, p);
	    CGWarpMouseCursorPosition(p);
	    CGAssociateMouseAndMouseCursorPosition(FALSE);
#else
        glfwDisable(GLFW_MOUSE_CURSOR);
        glfwSetMousePos(m_mouseMiddleX, m_mouseMiddleY);
#endif
    }
    m_mouseVisible = visible;
}
Ejemplo n.º 3
0
void setMousePositionRelative(const WindowsDesc* winDesc, int32_t x, int32_t y)
{
    CGPoint location;
    location.x = winDesc->windowedRect.left + x;
    location.y = winDesc->windowedRect.bottom - y;
    CGWarpMouseCursorPosition(location);
}
Ejemplo n.º 4
0
static void SetMouse(const Point *cp) {

#if TARGET_API_MAC_CARBON

	CGPoint	pt;

	pt.x = (float)cp->h;
	pt.y = (float)cp->v;
	CGWarpMouseCursorPosition(pt);

#else
	CursorDevice	*curdev;
	Point			pt;
	WindowPtr		saveport;

	curdev = NULL;
	CursorDeviceNextDevice(&curdev);
	if (curdev != NULL) {
		pt.h = cp->h;
		pt.v = cp->v;
		GetPort(&saveport);
		SetPort(hWndMain);
		LocalToGlobal(&pt);
		SetPort(saveport);
		CursorDeviceMoveTo(curdev, pt.h, pt.v);
	}
#endif
}
Ejemplo n.º 5
0
void MCScreenDC::setmouse(int2 x, int2 y)
{ //move mouse/cursor to new (x,y) location

	CGPoint point;
	point.x = x;
	point.y = y;
	CGWarpMouseCursorPosition(point);
}
Ejemplo n.º 6
0
static void SetMouse(const Point *cp) {

	CGPoint	pt;

	pt.x = (float)cp->h;
	pt.y = (float)cp->v;
	CGWarpMouseCursorPosition(pt);
}
Ejemplo n.º 7
0
void MoveCursorToCenterOfWindow(ax_window *Window)
{
    if(KWMSettings.UseMouseFollowsFocus)
    {
        CGWarpMouseCursorPosition(CGPointMake(Window->Position.x + Window->Size.width / 2,
                                              Window->Position.y + Window->Size.height / 2));
    }
}
Ejemplo n.º 8
0
void BaseApp::setCursorPos(const int x, const int y){
	Rect structureBounds;
	GetWindowBounds(window, kWindowStructureRgn, &structureBounds);

	CGPoint point;
	point.x = x + structureBounds.left;
	point.y = y + structureBounds.bottom - height;

//	CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, point);
	CGWarpMouseCursorPosition(point);
}
Ejemplo n.º 9
0
void
COSXScreen::warpCursor(SInt32 x, SInt32 y)
{
	// move cursor without generating events
	CGPoint pos;
	pos.x = x;
	pos.y = y;
	CGWarpMouseCursorPosition(pos);
	
	// save new cursor position
	m_xCursor        = x;
	m_yCursor        = y;
	m_cursorPosValid = true;
}
Ejemplo n.º 10
0
GHOST_TSuccess GHOST_SystemCarbon::setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y)
{
	float xf = (float)x, yf = (float)y;

	CGAssociateMouseAndMouseCursorPosition(false);
	CGSetLocalEventsSuppressionInterval(0);
	CGWarpMouseCursorPosition(CGPointMake(xf, yf));
	CGAssociateMouseAndMouseCursorPosition(true);

//this doesn't work properly, see game engine mouse-look scripts
//	CGWarpMouseCursorPosition(CGPointMake(xf, yf));
	// this call below sends event, but empties other events (like shift)
	// CGPostMouseEvent(CGPointMake(xf, yf), TRUE, 1, FALSE, 0);

	return GHOST_kSuccess;
}
Ejemplo n.º 11
0
void update() {

    // Recenter mouse
    if(m_centerMouse)
    {
#ifdef __APPLE__
        CGWarpMouseCursorPosition(mCenterPoint);
#elif __LINUX__
        XSelectInput(display, rootWindow, KeyReleaseMask);
        XWarpPointer(display, None, rootWindow, 0, 0, 0, 0, m_screenCenter[0], m_screenCenter[1]);
        XFlush(display);
#endif
    }

    if(chatWindow!=0)
    {
        chatWindow->fade();
    }
}
Ejemplo n.º 12
0
void start(bool centerMouse) {

    m_centerMouse = centerMouse;

    if(m_centerMouse)
    {
        // Recenter mouse
#ifdef __APPLE__
        CGSetLocalEventsSuppressionInterval(0);
        mCenterPoint.x = m_screenCenter[0];
        mCenterPoint.y = m_screenCenter[1];
        CGWarpMouseCursorPosition(mCenterPoint);
#elif __LINUX__
        display = XOpenDisplay(0);
        rootWindow = DefaultRootWindow(display);
        XWarpPointer(display, None, rootWindow, 0, 0, 0, 0, m_screenCenter[0], m_screenCenter[1]);
//        qApp->setOverrideCursor(QCursor(Qt::BlankCursor));
#endif
    }

    peerWindow = new PeerWindow(
                cinder::Vec2f(0,cinder::app::getWindowHeight()*0.875),
                cinder::Rectf(cinder::Vec2f(0,0),cinder::Vec2f(15*43,30)),
                cinder::ColorA(0.25,0.25,0.25,0.425)
                );
    chatWindow = new ChatWindow(
                cinder::Vec2f(cinder::app::getWindowWidth()*0.2,cinder::app::getWindowHeight()*0.2),
                cinder::Rectf(cinder::Vec2f(0,0),cinder::Vec2f(cinder::app::getWindowWidth()*0.6,cinder::app::getWindowHeight()*0.55)),
                cinder::ColorA(0.25,0.25,0.25,0.425)
                );
    chatEntry = new ChatEntry(
                cinder::Vec2f(cinder::app::getWindowWidth()*0.2,cinder::app::getWindowHeight()*0.85),
                cinder::Rectf(cinder::Vec2f(0,0),cinder::Vec2f(cinder::app::getWindowWidth()*0.6,cinder::app::getWindowHeight()*0.15)),
                cinder::ColorA(0.25,0.25,0.25,0.425)
                );
//    scoreWindow = new Score(
//                cinder::Vec2f(cinder::app::getWindowWidth()*0.6,cinder::app::getWindowHeight()*0.6),
//                cinder::Rectf(cinder::Vec2f(0,0),cinder::Vec2f(cinder::app::getWindowWidth()*0.2,cinder::app::getWindowHeight()*0.4)),
//                cinder::ColorA(0.25,0.25,0.25,0.425)
//                );
}
//ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
// Carbon_EnableMouse
//ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
// Controls whether our Carbon event handler will handle mouse events or
// ignore them totally. Used around dialogs, similar to InputSprocket.
// If mouse events are enabled, we eat all the events we can handle, which
// means that they don't get passed back to the system.
//ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
void Carbon_EnableMouse( Boolean inState ) {
    int i;

    // set the state
    sMouseEnabled = inState;

    if ( inState ) {
        CGPoint newPoint;
        CGRect bounds;
        CGDirectDisplayID displayID;

        displayID = (CGDirectDisplayID) macPrefs.displayID;
        if ( displayID == 0 ) {
            displayID = kCGDirectMainDisplay;
        }

        bounds = CGDisplayBounds( displayID );

        // FIXME: this is hosed when you're running in a window .. that stuff is working with the display

        // If we're capturing the mouse, pin cursor to center of selected display.
        newPoint.x = bounds.origin.x + ( bounds.size.width / 2 );
        newPoint.y = bounds.origin.y + ( bounds.size.height / 2 );

        CGSetLocalEventsSuppressionInterval( 0.0 );
        CGWarpMouseCursorPosition( newPoint );
    }

    CGAssociateMouseAndMouseCursorPosition( !inState );

    // reset our internal states to default values
    sMouseDelta.h = sMouseDelta.v = 0;
    sMouseWheelDelta = 0;
    for ( i = 0; i < MAX_BUTTONS; i++ )
        sMouseButtons[i] = 0;
}
Ejemplo n.º 14
0
void Input::update()
{
    m_mouse.z = glfwGetMouseWheel();
    glfwSetMouseWheel(0);
    if (m_mouseVisible == false)
    {
#ifdef __APPLE__
 		CGGetLastMouseDelta(&m_mouse.x, &m_mouse.y);
        GLFWvidmode mode;
        glfwGetDesktopMode(&mode);
	    CGPoint p;
		p.x = m_mouseMiddleX;
		p.y = m_mouseMiddleY;
		CGWarpMouseCursorPosition(p);
#else
        glfwGetMousePos(&m_mouse.x, &m_mouse.y);
        m_mouse.x -= m_mouseMiddleX;
        m_mouse.y -= m_mouseMiddleY;
        glfwSetMousePos(m_mouseMiddleX, m_mouseMiddleY);
#endif
    }
    else
    {
        glfwGetMousePos(&m_mouse.x, &m_mouse.y);
    }
    
    m_mouse.b = 0;
    if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_1))
    {
        m_mouse.b |= 1;
    }
    if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_2))
    {
        m_mouse.b |= 2;
    }
}
Ejemplo n.º 15
0
void Mouse::warpMousePos(const cinder::Vec2i& pos) {
  CGAssociateMouseAndMouseCursorPosition(0);
  CGWarpMouseCursorPosition(Monitor::getInstance().getCenterCG());
  CGAssociateMouseAndMouseCursorPosition(1);
}
Ejemplo n.º 16
0
void SL::Remote_Access_Library::Input::SimulateMouseEvent(const Input::MouseEvent & m)
{

	SL_RAT_LOG(Utilities::Logging_Levels::INFO_log_level,"SetMouseEvent EventData:"<<m.EventData<<" ScrollDelta: "<<m.ScrollDelta<<" PressData: "<<m.PressData);
	
#if _WIN32

	INPUT input;
	memset(&input, 0, sizeof(input));
	input.type = INPUT_MOUSE;
	input.mi.mouseData = m.ScrollDelta * 120;
	input.mi.dx = static_cast<LONG>(static_cast<float>(m.Pos.X)*(65536.0f / static_cast<float>(GetSystemMetrics(SM_CXSCREEN))));//x being coord in pixels
	input.mi.dy = static_cast<LONG>(static_cast<float>(m.Pos.Y)*(65536.0f / static_cast<float>(GetSystemMetrics(SM_CYSCREEN))));//y being coord in pixels
	input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;

	switch (m.EventData) {
	case Input::Mouse::Events::LEFT:
		if (m.PressData == Input::Mouse::Press::UP) input.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
		else if (m.PressData == Input::Mouse::Press::DOWN) input.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
		else input.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP;
		break;
	case Input::Mouse::Events::MIDDLE:
		if (m.PressData == Input::Mouse::Press::UP) input.mi.dwFlags |= MOUSEEVENTF_MIDDLEUP;
		else if (m.PressData == Input::Mouse::Press::DOWN) input.mi.dwFlags |= MOUSEEVENTF_MIDDLEDOWN;
		else input.mi.dwFlags |= MOUSEEVENTF_MIDDLEDOWN | MOUSEEVENTF_MIDDLEUP;
		break;
	case Input::Mouse::Events::RIGHT:
		if (m.PressData == Input::Mouse::Press::UP) input.mi.dwFlags |= MOUSEEVENTF_RIGHTUP;
		else if (m.PressData == Input::Mouse::Press::DOWN) input.mi.dwFlags |= MOUSEEVENTF_RIGHTDOWN;
		else input.mi.dwFlags |= MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP;
		break;
	case Input::Mouse::Events::SCROLL:
		input.mi.dwFlags |= MOUSEEVENTF_WHEEL;
		break;
	default:
		break;
	}

	SendInput(1, &input, sizeof(input));
	if (m.PressData == Input::Mouse::Press::DBLCLICK) SendInput(1, &input, sizeof(input));
#elif __APPLE__
	CGPoint new_pos;
	CGEventErr err;
	new_pos.x = m.Pos.X;
	new_pos.y = m.Pos.Y;
	!CGWarpMouseCursorPosition(new_pos);
#elif __ANDROID__

#elif __linux__
    
	auto display = XOpenDisplay(NULL);
    XTestFakeMotionEvent(display, 0, m.Pos.X, m.Pos.Y,0);
    
	
    
    switch (m.EventData) {
	case Input::Mouse::Events::LEFT:
		if (m.PressData == Input::Mouse::Press::UP) XTestFakeButtonEvent(display, Button1,False, CurrentTime);
		else if (m.PressData == Input::Mouse::Press::DOWN) XTestFakeButtonEvent(display, Button1,True,CurrentTime);
		else {//double click
            XTestFakeButtonEvent(display, Button1,True, CurrentTime);
            XTestFakeButtonEvent(display, Button1,False, CurrentTime);
            XTestFakeButtonEvent(display, Button1,True, CurrentTime );
            XTestFakeButtonEvent(display, Button1,False, CurrentTime );
        }
		break;
	case Input::Mouse::Events::MIDDLE:
		if (m.PressData == Input::Mouse::Press::UP) XTestFakeButtonEvent(display, Button2,False, CurrentTime);
		else if (m.PressData == Input::Mouse::Press::DOWN) XTestFakeButtonEvent(display, Button2,True, CurrentTime);
		else {//double click
            XTestFakeButtonEvent(display, Button2,True, CurrentTime);
            XTestFakeButtonEvent(display, Button2,False, CurrentTime);
            XTestFakeButtonEvent(display, Button2,True, CurrentTime);
            XTestFakeButtonEvent(display, Button2,False, CurrentTime);
        }
		break;
	case Input::Mouse::Events::RIGHT:
		if (m.PressData == Input::Mouse::Press::UP) XTestFakeButtonEvent(display, Button3,False, CurrentTime );
		else if (m.PressData == Input::Mouse::Press::DOWN) XTestFakeButtonEvent(display, Button3,True, CurrentTime);
		else {//double click
            XTestFakeButtonEvent(display, Button3,True, CurrentTime);
            XTestFakeButtonEvent(display, Button3,False, CurrentTime);
            XTestFakeButtonEvent(display, Button3,True,CurrentTime );
            XTestFakeButtonEvent(display, Button3,False, CurrentTime);
        }
		break;
	case Input::Mouse::Events::SCROLL:
        if(m.ScrollDelta <0){
            for(auto i=0;i< abs(m.ScrollDelta) && i< 5; i++){///cap at 5
                XTestFakeButtonEvent(display, Button4,True, CurrentTime );  
                XTestFakeButtonEvent(display, Button4,False, CurrentTime); 
            }   
        } else if(m.ScrollDelta>0) {
             for(auto i=0;i< m.ScrollDelta && i< 5; i++){///cap at 5
                XTestFakeButtonEvent(display, Button5,True, CurrentTime );  
                XTestFakeButtonEvent(display, Button5,False, CurrentTime); 
            }     
        }
        
		break;
	default:
		break;
	}
    
	XCloseDisplay(display);

#endif



}
Ejemplo n.º 17
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXMouseEventQueue_nWarpCursor(JNIEnv *env, jclass unused, jint x, jint y) {
    CGPoint p;
    p.x = x;
    p.y = y;
    CGWarpMouseCursorPosition(p);
}
Ejemplo n.º 18
0
void GiveFocusToScreen(unsigned int ScreenIndex, tree_node *FocusNode, bool Mouse, bool UpdateFocus)
{
    screen_info *Screen = GetDisplayFromScreenID(ScreenIndex);
    if(Screen && Screen != KWMScreen.Current)
    {
        KWMScreen.PrevSpace = KWMScreen.Current->ActiveSpace;
        KWMScreen.Current = Screen;

        Screen->ActiveSpace = GetActiveSpaceOfDisplay(Screen);
        ShouldActiveSpaceBeManaged();
        space_info *Space = GetActiveSpaceOfScreen(Screen);

        DEBUG("GiveFocusToScreen() " << ScreenIndex << \
              ": Space transition ended " << KWMScreen.PrevSpace << \
              " -> " << Screen->ActiveSpace);

        if(UpdateFocus)
        {
            if(Space->Initialized && FocusNode)
            {
                DEBUG("Populated Screen 'Window -f Focus'");

                UpdateActiveWindowList(Screen);
                FilterWindowList(Screen);
                SetWindowFocusByNode(FocusNode);
                MoveCursorToCenterOfFocusedWindow();
            }
            else if(Space->Initialized && Space->RootNode)
            {
                DEBUG("Populated Screen Key/Mouse Focus");

                UpdateActiveWindowList(Screen);
                FilterWindowList(Screen);

                bool WindowBelowCursor = IsAnyWindowBelowCursor();
                if(Mouse && !WindowBelowCursor)
                    ClearFocusedWindow();
                else if(Mouse && WindowBelowCursor)
                    FocusWindowBelowCursor();

                if(!Mouse)
                {
                    if(Space->FocusedWindowID == -1)
                    {
                        if(Space->Settings.Mode == SpaceModeBSP)
                        {
                            void *FocusNode = NULL;
                            GetFirstLeafNode(Space->RootNode, (void**)&FocusNode);
                            Space->FocusedWindowID = ((tree_node*)FocusNode)->WindowID;
                        }
                        else if(Space->Settings.Mode == SpaceModeMonocle)
                        {
                            if(Space->RootNode->List)
                                Space->FocusedWindowID = Space->RootNode->List->WindowID;
                        }
                    }

                    FocusWindowByID(Space->FocusedWindowID);
                    MoveCursorToCenterOfFocusedWindow();
                }
            }
            else
            {
                if(!Space->Initialized ||
                   Space->Settings.Mode == SpaceModeFloating ||
                   !Space->RootNode)
                {
                    DEBUG("Uninitialized Screen");
                    ClearFocusedWindow();

                    if(!Mouse)
                        CGWarpMouseCursorPosition(CGPointMake(Screen->X + (Screen->Width / 2), Screen->Y + (Screen->Height / 2)));

                    if(Space->Settings.Mode != SpaceModeFloating && !Space->RootNode)
                    {
                        CGPoint ClickPos = GetCursorPos();
                        CGEventRef ClickEvent = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, ClickPos, kCGMouseButtonLeft);
                        CGEventSetFlags(ClickEvent, 0);
                        CGEventPost(kCGHIDEventTap, ClickEvent);
                        CFRelease(ClickEvent);

                        ClickEvent = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseUp, ClickPos, kCGMouseButtonLeft);
                        CGEventSetFlags(ClickEvent, 0);
                        CGEventPost(kCGHIDEventTap, ClickEvent);
                        CFRelease(ClickEvent);
                    }
                }
            }
        }
    }
}
Ejemplo n.º 19
0
//--------------------------------------------------------------
void testApp::update(){
    current_color = ofColor(current_color.r, current_color.g, current_color.b, current_alpha);
    if(current_sides==0){
        current_bk = current_color;
        current_preview = ofColor(0,0,0);
    } else {
        if(current_color.r == current_bk.r && current_color.g == current_bk.g && current_color.b == current_bk.b){
            current_preview = ofColor(0,0,0);
        } else {
            current_preview = current_color;
        }
    }
    preview_object.update_geometry(current_point, current_sides, current_radius, current_preview, current_z, line, false);
    for(int i=0; i<objects.size(); i++){
        objects[i].update_geometry(objects[i].centroid, objects[i].verticies-1, objects[i].radius, objects[i].color, objects[i].z, objects[i].line, oskar);
    }
    ofBackground(current_bk);

    do {
        arduino = ofxGetSerialString(serial,';'); //read until end of line
        if(arduino != ""){
            output = arduino;
            values = ofSplitString(output, " ", true, true); // trues are ignoreempty & trim
            if(values.size()==20){
                current_point.x += ofToInt(values[0]);
                if(current_point.x > ofGetScreenWidth()+current_radius){
                    current_point.x = ofGetScreenWidth()+current_radius;
                }
                if(current_point.x < -current_radius-5){
                    current_point.x = -current_radius-5;
                }
                current_point.y += -ofToInt(values[1]);
                if(current_point.y > ofGetScreenHeight()+current_radius){
                    current_point.y = ofGetScreenHeight()+current_radius;
                }
                if(current_point.y < -current_radius-5){
                    current_point.y = -current_radius-5;
                }
                CGPoint point;  
                point.x = current_point.x;  
                point.y = current_point.y;  
                CGWarpMouseCursorPosition(point);
                if(ofToInt(values[2]) == 1 && j1_up == false){
                    // J1 UP
                    if(current_object < (objects.size()-1) && objects.size()>0){
                        current_object++;
                    } else {
                        current_object = 0;
                    }
                    j1_up = true;
                } else {
                    j1_up = false;
                }
                if(ofToInt(values[3]) == 1 && j1_down == false){
                    // J1 DOWN
                    if((current_object) > -1 && objects.size()>0){
                        current_object--;
                    } else {
                        current_object = (objects.size()-1);
                    }
                    j1_down = true;
                } else {
                    j1_down = false;
                }
                if(ofToInt(values[4]) == 1 && j1_left == false){
                    // J1 LEFT
                    if((current_object) > -1 && objects.size()>0){
                        current_object--;
                    } else {
                        current_object = (objects.size()-1);
                    }
                    j1_left = true;
                } else {
                    j1_left = false;
                }
                if(ofToInt(values[5]) == 1 && j1_right == false){
                    // J1 RIGHT
                    if(current_object < (objects.size()-1) && objects.size()>0){
                        current_object++;
                    } else {
                        current_object = 0;
                    }
                    j1_right = true;
                } else {
                    j1_right = false;
                }
                if(ofToInt(values[6]) == 0 && ok_button == false){
                    // OK button
                    if(current_sides!=0){
                        if(current_object<0){
                            if(current_sides!=0){
                                placeObject();
                            }
                        } else {
                            edit();
                        }
                    }
                    ok_button = true;
                } else {
                    ok_button = false;
                }
                if(ofToInt(values[7]) == 0 && delete_button == false){
                    // DELETE
                    if(current_object>=0){
                        deleteObject(current_object);            
                    }
                    delete_button = true;
                } else {
                    delete_button = false;
                }
                if(values[8] == "0" && j2_up == false){                    
                    // J2 UP
                    float bri = current_color.getBrightness();
                    bri+=step;
                    current_color.setBrightness(bri);
                    j2_up = true;
                } else {
                    j2_up = false;
                }
                if(values[9] == "0" && j2_down == false){
                    // J2 DOWN
                    float bri = current_color.getBrightness();
                    bri-=step;
                    current_color.setBrightness(bri);
                    j2_down = true;
                } else {
                    j2_down = false;
                }
                if(values[10] == "0" && j2_left == false){
                    // J1 LEFT
                    float sat = current_color.getSaturation();
                    if(sat>step){
                        sat-=(2*step);
                        current_color.setSaturation(sat);
                    }
                    j2_left = true;
                } else {
                    j2_left = false;
                }
                if(values[11] == "0" && j2_right == false){
                    // J2 RIGHT
                    float sat = current_color.getSaturation();
                    if(sat<(255-step)){
                        sat+=(2*step);
                        current_color.setSaturation(sat);
                    }
                    j2_right = true;
                } else {
                    j2_right = false;
                }
                current_sides = (int)(ofMap(ofToInt(values[12]), 58, 1006, 0, 20));
                current_radius = (int)(ofMap(ofToInt(values[13]), 0, 1020, 0, ofGetScreenWidth()/2));
                current_color.setHue(ofMap(ofToInt(values[14]), 58, 1021, 0, 255));
                current_z = (int)(ofMap(ofToInt(values[15]), 58, 1008, 0, objects.size()));
                current_alpha = (int)(ofMap(ofToInt(values[16]), 58, 1020, 0, 255));
                if(ofToInt(values[17]) == 0 && delete_button == false){
                    // CLOSE SHAPE
                    line.close();
                    close = true;
                } else {
                    close = false;
                }
                if(ofToInt(values[18]) == 0 && delete_button == false){
                    // VERTEX
                    if(current_sides==1){
                        line.addVertex(current_point);
                    }
                    vertex = true;
                } else {
                    vertex = false;
                }
                if(ofToInt(values[19]) == 0){
                    // OSKAR MODE
                    oskar = false;
                } else {
                    oskar = true;
                }
            }
        }
        if (arduino == "") continue;
        //do something with str
    } while (arduino != "");
    if(current_sides != 1){
        if(line.getArea() != 0){
            line.clear();            
        }
    }
}
Ejemplo n.º 20
0
//--------------------------------------------------------------
void testApp::draw(){
    
	ofSetColor(255, 255, 255);
    
    ofPushMatrix();
    openNIDevice.drawDebug();
    ofPopMatrix();
    
    ofPushMatrix();
    ofEnableBlendMode(OF_BLENDMODE_ALPHA);
    
    numUsers = openNIDevice.getNumTrackedUsers();
    
    for (int i = 0; i < numUsers; i++){
        
        ofxOpenNIUser & user = openNIDevice.getTrackedUser(0);
        user.drawMask();
       
       current_time=ofGetElapsedTimef();
       left_hand = user.getJoint(JOINT_LEFT_HAND).getProjectivePosition();
       right_hand = user.getJoint(JOINT_RIGHT_HAND).getProjectivePosition();
       left_foot = user.getJoint(JOINT_LEFT_FOOT).getProjectivePosition();
        
       //计算每次左手拉拽的行为
       //每100微秒 计算一次prev_hand 在这100微秒中 hand-prevhand > 某个值的时候 证明拉拽动作
        dist_time=current_time-prev_time;
        if(dist_time>200) switchT = true;
        if(switchT){
            prev_time = ofGetElapsedTimef();
            prev_left_hand = left_hand;
            prev_right_hand = right_hand;
            prev_left_foot = left_foot;
            switchT=false;
        }
        
        float dist_left_hand=ofDist(left_hand.x, left_hand.y, prev_left_hand.x, prev_left_hand.y);
        float dist_right_hand=ofDist(right_hand.x, right_hand.y, prev_right_hand.x, prev_right_hand.y);
        float dist_left_foot=ofDist(left_foot.x, left_foot.y, prev_left_foot.x, prev_left_foot.y);
        
        CGPoint point;
        point.x = left_hand.x;
        point.y = left_hand.y;
        CGWarpMouseCursorPosition(point);
        
        
        
      //判断左手
        if(dist_left_hand>20&&dist_time<200){
            left_drag=true;
        } else { left_drag = false;}
        
        if (left_drag && leftByRun == 0) {
            ofSetColor(255,0,0);
            ofCircle(20, 20, 20);
            holdLeftKey();
            //CGEventRef a =  CGEventCreateKeyboardEvent(NULL, 123, 1);
            //CGEventPost(kCGHIDEventTap, a);
        } //else {
            //CGEventRef b =  CGEventCreateKeyboardEvent(NULL, 123, 0);
            //CGEventPost(kCGHIDEventTap, b);
        //}
        
        
        //判断右手
        if(dist_right_hand>20 && dist_time<200){
            right_drag=true;
        } else { right_drag = false;}
        
        if (right_drag && rightByRun == 0) {
            ofSetColor(255,0,0);
            ofCircle(50, 20, 20);
            holdRightKey();
            //CGEventRef a =  CGEventCreateKeyboardEvent(NULL, 123, 1);
            //CGEventPost(kCGHIDEventTap, a);
        }
        
        //判断跑步
        if(dist_left_foot>10 && dist_time<200){
            running=true;
        } else { running = false;}
        
        if (running) {
            ofSetColor(255);
            ofCircle(20, 50, 20);
            holdUpKey();
            //CGEventRef a =  CGEventCreateKeyboardEvent(NULL, 123, 1);
            //CGEventPost(kCGHIDEventTap, a);
        }
        
        ofSetColor(0,255,0);
        font.drawString( ofToString(left_hand.x) , 200, 200);
        font.drawString( ofToString(left_hand.y) , 200, 250);
        //font.drawString( "Prev"+ofToString(prev_left_hand) , 200, 300);
        font.drawString( "dist_left_hand"+ofToString(dist_left_hand) , 200, 350);
        font.drawString( "dist_right_hand"+ofToString(dist_right_hand) , 200, 400);
        font.drawString( "dist_left_foot"+ofToString(dist_left_foot) , 200, 450);
        
        //cout << ofGetElapsedTimeMillis()<<endl;
        
        
        ofSetColor(255, 0, 0);
        ofCircle(left_hand.x, left_hand.y, 10);
               ofPushMatrix();
        ofTranslate(320, 240, 10);
        user.drawPointCloud();        
        ofPopMatrix();
        prev_left_hand = left_hand;
        prev_left_foot = left_foot;
        prev_right_hand = right_hand;
    }
    
    ofDisableBlendMode();
    ofPopMatrix();
    
    // draw some info regarding frame counts etc
	//ofSetColor(0, 255, 0);
	//string msg = " MILLIS: " + ofToString(ofGetElapsedTimeMillis()) + " FPS: " + ofToString(ofGetFrameRate()) + " Device FPS: " + ofToString(openNIDevice.getFrameRate());
	//verdana.drawString(msg, 20, openNIDevice.getNumDevices() * 480 - 20);
    
    cout << ofGetElapsedTimeMillis()<<endl;
}
Ejemplo n.º 21
0
void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecursor)
{
	if (!mouse_avail || !window)
		relative = hidecursor = false;

	if (relative)
	{
		if(vid_usingmouse && (vid_usingnoaccel != !!apple_mouse_noaccel.integer))
			VID_SetMouse(false, false, false); // ungrab first!
		if (!vid_usingmouse)
		{
			Rect winBounds;
			CGPoint winCenter;

			SelectWindow(window);

			// Put the mouse cursor at the center of the window
			GetWindowBounds (window, kWindowContentRgn, &winBounds);
			winCenter.x = (winBounds.left + winBounds.right) / 2;
			winCenter.y = (winBounds.top + winBounds.bottom) / 2;
			CGWarpMouseCursorPosition(winCenter);

			// Lock the mouse pointer at its current position
			CGAssociateMouseAndMouseCursorPosition(false);

			// Save the status of mouse acceleration
			originalMouseSpeed = -1.0; // in case of error
			if(apple_mouse_noaccel.integer)
			{
				io_connect_t mouseDev = IN_GetIOHandle();
				if(mouseDev != 0)
				{
					if(IOHIDGetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), &originalMouseSpeed) == kIOReturnSuccess)
					{
						Con_DPrintf("previous mouse acceleration: %f\n", originalMouseSpeed);
						if(IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), -1.0) != kIOReturnSuccess)
						{
							Con_Print("Could not disable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n");
							Cvar_SetValueQuick(&apple_mouse_noaccel, 0);
						}
					}
					else
					{
						Con_Print("Could not disable mouse acceleration (failed at IOHIDGetAccelerationWithKey).\n");
						Cvar_SetValueQuick(&apple_mouse_noaccel, 0);
					}
					IOServiceClose(mouseDev);
				}
				else
				{
					Con_Print("Could not disable mouse acceleration (failed at IO_GetIOHandle).\n");
					Cvar_SetValueQuick(&apple_mouse_noaccel, 0);
				}
			}

			vid_usingmouse = true;
			vid_usingnoaccel = !!apple_mouse_noaccel.integer;
		}
	}
	else
	{
		if (vid_usingmouse)
		{
			if(originalMouseSpeed != -1.0)
			{
				io_connect_t mouseDev = IN_GetIOHandle();
				if(mouseDev != 0)
				{
					Con_DPrintf("restoring mouse acceleration to: %f\n", originalMouseSpeed);
					if(IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), originalMouseSpeed) != kIOReturnSuccess)
						Con_Print("Could not re-enable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n");
					IOServiceClose(mouseDev);
				}
				else
					Con_Print("Could not re-enable mouse acceleration (failed at IO_GetIOHandle).\n");
			}

			CGAssociateMouseAndMouseCursorPosition(true);

			vid_usingmouse = false;
		}
	}

	if (vid_usinghidecursor != hidecursor)
	{
		vid_usinghidecursor = hidecursor;
		if (hidecursor)
			CGDisplayHideCursor(CGMainDisplayID());
		else
			CGDisplayShowCursor(CGMainDisplayID());
	}
}