//-----------------------------------------------------------------------------
// Mouse motion (with either key pressed) event handler
//-----------------------------------------------------------------------------
void GlutDisplay::mouseMotionEvent(const int x, const int y)
{
   if (isMessageEnabled(MSG_DEBUG)) {
      std::cout << "GlutDisplay::mouseEvent(): " << std::endl;
   }

   if (picked != nullptr) {
      Graphic* selected = pick();
      if (selected != nullptr) {
         if (selected != picked) {
            picked->event(ON_CANCEL);
            picked->unref();
            picked = nullptr;
         }
         selected->event(ON_MOTION);

      }
      else {
         if (picked != nullptr) {
            picked->event(ON_CANCEL);
            picked->unref();
            picked = nullptr;
         }
      }
   }
   setMouse(x,y);
}
예제 #2
0
void initialize()
{
	hasSavePoint = false;
	if (currLevel == 0){
		//glutSetCursor(GLUT_CURSOR_NONE);
		setMouse(win1.width / 2, win1.height / 2);
		updateProjection(win1);
	}
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glClearColor(0.0, 0.0, 0.0, 1.0);											// specify clear values for the color buffers	
	loadImages();
	levels[currLevel] = new Level(currLevel + 1);
	Stamina = 100;
	makeEntites();
	levelEdges = levels[currLevel]->getEdges();
	
	camera1 = new Camera(Vector3(levels[currLevel]->startPoint->x, 2, levels[currLevel]->startPoint->y), findPosition(levels[currLevel]), Vector3(0, 1, 0));
	if (levels[currLevel]->startNode->left || levels[currLevel]->startNode->right){
		cylinder1.yaw(90);
	}
	startPlayer = cylinder1;
	resetEnemies();
	sound = new Sound();
	sound->Load();
	sound->Play(SOUND_MUSIC1);
	
}
예제 #3
0
void CGame::Init(int argc, char **argv)
{
	srand(time(0));

	glutInit(&argc, argv);
	glutInitContextVersion(3, 0);

	//if (data->fullscreen)
	//{
	//glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH), glutGet(GLUT_SCREEN_HEIGHT));
	//glutInitWindowPosition(0, 0);
	//}
	//else
	//{
	glutInitWindowSize(1, 1);
	glutInitWindowPosition(1, 1);
	//glutInitWindowSize(data->window->size.x, data->window->size.y);
	//glutInitWindowPosition(data->window->pos.x, data->window->pos.y);
	//}

	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
	glutCreateWindow("Space Explorer");

	std::cout << glGetString(GL_VENDOR) << std::endl;
	std::cout << glGetString(GL_RENDERER) << std::endl;
	std::cout << "OpenGL " << glGetString(GL_VERSION) << std::endl;

	GLenum err = glewInit();
	if (GLEW_OK != err)
	{
		MessageBox(0, (LPCSTR)glewGetErrorString(err), "GLEW Error", MB_ICONERROR | MB_OK);
		exit(1);
	}

	if (GLEW_VERSION_3_0 == false)
	{
		MessageBox(0, "To run a game, OpenGL 3.0 or higher is required", "Error", MB_ICONERROR | MB_OK);
		exit(1);
	}
	std::cout << "Using GLEW " << glewGetString(GLEW_VERSION) << std::endl;


	data->audioDevice = audiere::OpenDevice();


	//glutTimerFunc(1000, callbackDrawFPS, 0);
	//glutTimerFunc(15, callbackRedisplay, 0);
	//glutRedisplayFunc(callbackRedisplay);

	setMouse();
	loadData();

	setGlutCallbacks();

	glutFullScreen();

	glutMainLoop();
}
예제 #4
0
//====================================
// setMouse
//------------------------------------
void SaXManipulateMice::setMouse (
	const QString& vendor, const QString& model
) {
	// .../
	//! set all mouse data associated with the given vendor
	//! and model name to the current pointer data.
	// ----
	setMouse (vendor+":"+model);
}
//-----------------------------------------------------------------------------
// passive mouse motion (no mouse key pressed) event handler
//-----------------------------------------------------------------------------
void GlutDisplay::passiveMotionEvent(const int x, const int y)
{
   if (isMessageEnabled(MSG_DEBUG)) {
      std::cout << "GlutDisplay::mouseEvent(): " << std::endl;
   }

   // set our mouse to the current position and update our number of clicks
   // do another pick, just to make sure
   setMouse(x,y);
}
예제 #6
0
void 
InputState::setEvent ( const InputEvent &e , Point2D local_pt) 
{ 
    event = e;
    event.pos = local_pt;
    setMouse  ( event );
    if ( e.type == ae_input_KEY ) setKey(event);
    if ( e.type == ae_input_SPEC ) setSpec(event);
//    setTime(event.time);
}
예제 #7
0
void
mousemotionTracker( int mx, int my )
{
  Wpoint pt;

  pt.h=mx;
  pt.v=my;

  setMouse( mx, my );
  mouseControls( tracker.trackerControls, pt );

}
예제 #8
0
void Input::handleInput() {
	switch (event->type) {
	case SDL_KEYDOWN:
		setFlag(event->key, true);
		break;
	case SDL_KEYUP:
		setFlag(event->key, false);
		break;
	case SDL_QUIT:
		setQuit();
		break;
	case SDL_MOUSEBUTTONDOWN:
		setMouse(event->button, true);
		break;
	case SDL_MOUSEBUTTONUP:
		setMouse(event->button, false);
		break;
	default:
		break;
	}
}
//This will get called whenever there's in event in an object we're filtering
bool StaticImageColorSource::eventFilter(QObject *obj, QEvent *event)
{
	//We only care about mouse move events
	if (event->type() == QEvent::MouseMove)
	{
		//Recast it to a mouse event so we can get the data from it
		QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
        
        setMouse(mouseEvent->pos());
		
		return true;
	}
	else
	{
		//If it's not a mouse movement, let qobject handle it
		return QObject::eventFilter(obj,event);
	}
}
예제 #10
0
void Display::mouseMotionEvent(const int x, const int y)
{
    if (dragging) {
        const auto page = static_cast<MapPage*>(subpage());
        if (page != nullptr) {
            // get our ref lat, because we won't go passed 70 degrees lat (either way);
            const double lat = page->getReferenceLatDeg();
            if (lat < 70 && lat > -70) {
                page->moveMap(startX, startY, x, y);
            } else {
                if (lat > 0) page->setReferenceLatDeg(65);
                else page->setReferenceLatDeg(-65);
            }
            startX = x;
            startY = y;
        }
    }
    setMouse(x, y);
}
//-----------------------------------------------------------------------------
// passive button event handler
//-----------------------------------------------------------------------------
void GlutDisplay::mouseEvent(const int button, const int state, const int x, const int y)
{
   if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
      Graphic* selected = pick();
      if (selected != nullptr) {
         selected->event(INPUT_LEFT_EDGE);
         if (picked != nullptr) picked->unref();
         picked = selected;
         picked->ref();
      }
   }
   if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) {
      if (picked != nullptr) {
         picked->event(ON_SINGLE_CLICK);
         picked->unref();
         picked = nullptr;
      }
   }
   setMouse(x,y);
}
예제 #12
0
//创建一则消息,包括将其加入MsgTable和MsgQueue中
void createMsg(int msg_type, int pos_x, int pos_y, char key)
{
    int x = pos_x;
    int y = pos_y;
    //if(msg_type != 0) cprintf("msg type: %d\n", msg_type);
    /*if(msg_type == MSG_LPRESS || msg_type == MSG_RPRESS || msg_type == MSG_DOUBLECLICK
        || msg_type == MSG_KEYDOWN || msg_type == MSG_DRAG)
        cprintf("msg type: %d\n", msg_type);*/
	int pid;
    int msg_index;
	if(msg_type == MSG_KEYDOWN)//键盘事件
	{
		pid = getActivated()->pid;
        msg_index = requireMsg(msg_type, x, y, key, 0);
	    if (msg_index == -1) return;
        dispatch(pid, msg_index);
	}
	else//鼠标事件
	{
        if(mouse_x == -1) mouse_x = pos_x;
        if(mouse_y == -1) mouse_y = pos_y;

        struct Window* win_ptr = getWindowByPoint(pos_x, pos_y);
        //cprintf("%d\n", win_ptr);
        pid = win_ptr->pid;

        x = pos_x - win_ptr->window_position.left_x;//relative x
        y = pos_y - win_ptr->window_position.left_y;//relative y

        if(msg_type == MSG_LPRESS || msg_type == MSG_RPRESS || msg_type == MSG_DOUBLECLICK)
        {
            if (win_ptr->next_window != 0)
                setActivated(win_ptr);
            msg_index = requireMsg(msg_type, x, y, key, 0);
	        if (msg_index == -1) return;
            dispatch(pid, msg_index);
        }

        if(msg_type == MSG_DRAG)
        {
            if (win_ptr->next_window != 0)
              setActivated(win_ptr);
        	if(win_ptr->prior_window == 0)//desktop
            {
                mouse_x = pos_x;
                mouse_y = pos_y;
		        drawMouse(pos_x, pos_y);
             	return;
            }

            int dx = pos_x - mouse_x;
            int dy = pos_y - mouse_y;

            int win_left_x = win_ptr->window_position.left_x;
            int win_left_y = win_ptr->window_position.left_y;
            int win_right_x = win_ptr->window_position.right_x;
            int win_right_y = win_ptr->window_position.right_y;

            int x1 = (dx > 0) ? win_left_x : (win_left_x + dx);
            int y1 = (dy > 0) ? win_left_y : (win_left_y + dy);
            int x2 = (dx > 0) ? (win_right_x + dx) : win_right_x;
            int y2 = (dy > 0) ? (win_right_y + dy) : win_right_y;

            /*if( (dx > -10 && dx < 10)|| (dy > -10 && dy < 10))
            {
                //cprintf("one tiny drag!\n");
                return;
            }*/
            if(win_left_x + dx >= 0 && win_left_y + dy >= 0
                && win_right_x + dx < SCREEN_WIDTH
                && win_right_y + dy < SCREEN_HEIGHT)//判断合法位移
            {
                win_ptr->window_position.left_x += dx;
                win_ptr->window_position.left_y += dy;
                win_ptr->window_position.right_x += dx;
                win_ptr->window_position.right_y += dy;
            }
            else
            {
                mouse_x = pos_x;
                mouse_y = pos_y;
		        drawMouse(pos_x, pos_y);
                return;
            }
            /*
	        if (msg_index == -1) return;*/
            //dispatch(pid, msg_index);
            cprintf("update area: x1: %d, y1: %d, x2: %d, y2:%d.\n", x1, y1, x2, y2);
            //drawScreenArea(x1, y1, x2, y2);
            drawScreen();
            mouse_x = pos_x;
            mouse_y = pos_y;
            setMouse(mouse_x, mouse_y);
            return;
        }

        mouse_x = pos_x;
        mouse_y = pos_y;
		drawMouse(pos_x, pos_y);
	}
}
예제 #13
0
void Completion::mousePressEvent ( QMouseEvent * e )
{
	setMouse( e->pos() );
	QFrame::mousePressEvent( e );
}
예제 #14
0
//oh god
SFML_Input::SFML_Input(void)
{
	mouseLock = false;
	setMouse(0,0);
	//oldPos = pos;

	//comp_but or but_comp
	but_comp[0] = sf::Mouse::Left;
	but_comp[1] = sf::Mouse::Right;
	but_comp[2] = sf::Mouse::Middle;
	but_comp[3] = sf::Mouse::XButton1;
	but_comp[4] = sf::Mouse::XButton2;

	//comp[i]=sf::Keyboard::Unknown 
	int i = 0;
	comp[i]=sf::Keyboard::A;
	i++;       
	comp[i]=sf::Keyboard::B;
	i++;            
	comp[i]=sf::Keyboard::C;
	i++;            
	comp[i]=sf::Keyboard::D;
	i++;            
	comp[i]=sf::Keyboard::E;
	i++;            
	comp[i]=sf::Keyboard::F;
	i++;            
	comp[i]=sf::Keyboard::G;
	i++;            
	comp[i]=sf::Keyboard::H;
	i++;            
	comp[i]=sf::Keyboard::I;
	i++;            
	comp[i]=sf::Keyboard::J;
	i++;            
	comp[i]=sf::Keyboard::K;
	i++;            
	comp[i]=sf::Keyboard::L;
	i++;            
	comp[i]=sf::Keyboard::M;
	i++;            
	comp[i]=sf::Keyboard::N;
	i++;            
	comp[i]=sf::Keyboard::O;
	i++;            
	comp[i]=sf::Keyboard::P;
	i++;            
	comp[i]=sf::Keyboard::Q;
	i++;            
	comp[i]=sf::Keyboard::R;
	i++;            
	comp[i]=sf::Keyboard::S;
	i++;            
	comp[i]=sf::Keyboard::T;
	i++;            
	comp[i]=sf::Keyboard::U;
	i++;            
	comp[i]=sf::Keyboard::V;
	i++;            
	comp[i]=sf::Keyboard::W;
	i++;            
	comp[i]=sf::Keyboard::X;
	i++;            
	comp[i]=sf::Keyboard::Y;
	i++;            
	comp[i]=sf::Keyboard::Z;
	i++;            
	comp[i]=sf::Keyboard::Num0;
	i++;         
	comp[i]=sf::Keyboard::Num1;
	i++;         
	comp[i]=sf::Keyboard::Num2;
	i++;         
	comp[i]=sf::Keyboard::Num3;
	i++;         
	comp[i]=sf::Keyboard::Num4;
	i++;         
	comp[i]=sf::Keyboard::Num5;
	i++;         
	comp[i]=sf::Keyboard::Num6;
	i++;         
	comp[i]=sf::Keyboard::Num7;
	i++;         
	comp[i]=sf::Keyboard::Num8;
	i++;         
	comp[i]=sf::Keyboard::Num9;
	i++;         
	comp[i]=sf::Keyboard::Escape;
	i++;       
	comp[i]=sf::Keyboard::LControl;
	i++;     
	comp[i]=sf::Keyboard::LShift;
	i++;       
	comp[i]=sf::Keyboard::LAlt;
	i++;        
	comp[i]=sf::Keyboard::LSystem;
	i++;      
	comp[i]=sf::Keyboard::RControl;
	i++;     
	comp[i]=sf::Keyboard::RShift;
	i++;       
	comp[i]=sf::Keyboard::RAlt;
	i++;         
	comp[i]=sf::Keyboard::RSystem;
	i++;      
	comp[i]=sf::Keyboard::Menu;
	i++;         
	comp[i]=sf::Keyboard::LBracket;
	i++;     
	comp[i]=sf::Keyboard::RBracket;
	i++;     
	comp[i]=sf::Keyboard::SemiColon;
	i++;    
	comp[i]=sf::Keyboard::Comma;
	i++;        
	comp[i]=sf::Keyboard::Period;
	i++;       
	comp[i]=sf::Keyboard::Quote;
	i++;        
	comp[i]=sf::Keyboard::Slash;
	i++;        
	comp[i]=sf::Keyboard::BackSlash;
	i++;    
	comp[i]=sf::Keyboard::Tilde;
	i++;        
	comp[i]=sf::Keyboard::Equal;
	i++;        
	comp[i]=sf::Keyboard::Dash;
	i++;         
	comp[i]=sf::Keyboard::Space;
	i++;        
	comp[i]=sf::Keyboard::Return;
	i++;       
	comp[i]=sf::Keyboard::BackSpace;
	i++;    
	comp[i]=sf::Keyboard::Tab;
	i++;          
	comp[i]=sf::Keyboard::PageUp;
	i++;       
	comp[i]=sf::Keyboard::PageDown;
	i++;     
	comp[i]=sf::Keyboard::End;
	i++;          
	comp[i]=sf::Keyboard::Home;
	i++;         
	comp[i]=sf::Keyboard::Insert;
	i++;       
	comp[i]=sf::Keyboard::Delete;
	i++;       
	comp[i]=sf::Keyboard::Add;
	i++;          
	comp[i]=sf::Keyboard::Subtract;
	i++;     
	comp[i]=sf::Keyboard::Multiply;
	i++;     
	comp[i]=sf::Keyboard::Divide;
	i++;       
	comp[i]=sf::Keyboard::Left;
	i++;         
	comp[i]=sf::Keyboard::Right;
	i++;        
	comp[i]=sf::Keyboard::Up;
	i++;           
	comp[i]=sf::Keyboard::Down;
	i++;         
	comp[i]=sf::Keyboard::Numpad0;
	i++;      
	comp[i]=sf::Keyboard::Numpad1;
	i++;      
	comp[i]=sf::Keyboard::Numpad2;
	i++;      
	comp[i]=sf::Keyboard::Numpad3;
	i++;      
	comp[i]=sf::Keyboard::Numpad4;
	i++;      
	comp[i]=sf::Keyboard::Numpad5;
	i++;      
	comp[i]=sf::Keyboard::Numpad6;
	i++;      
	comp[i]=sf::Keyboard::Numpad7;
	i++;      
	comp[i]=sf::Keyboard::Numpad8;
	i++;      
	comp[i]=sf::Keyboard::Numpad9;
	i++;      
	comp[i]=sf::Keyboard::F1;
	i++;           
	comp[i]=sf::Keyboard::F2;
	i++;           
	comp[i]=sf::Keyboard::F3;
	i++;           
	comp[i]=sf::Keyboard::F4;
	i++;           
	comp[i]=sf::Keyboard::F5;
	i++;           
	comp[i]=sf::Keyboard::F6;
	i++;           
	comp[i]=sf::Keyboard::F7;
	i++;           
	comp[i]=sf::Keyboard::F8;
	i++;           
	comp[i]=sf::Keyboard::F9;
	i++;           
	comp[i]=sf::Keyboard::F10;
	i++;          
	comp[i]=sf::Keyboard::F11;
	i++;          
	comp[i]=sf::Keyboard::F12;
	i++;          
	comp[i]=sf::Keyboard::F13;
	i++;          
	comp[i]=sf::Keyboard::F14;
	i++;          
	comp[i]=sf::Keyboard::F15;
	i++;          
	comp[i]=sf::Keyboard::Pause;
	i++;           
	
	pos.x = 0;
	pos.y = 0;
	newPos.x = 0;
	newPos.y = 0;
	difference.x = 0;
	difference.y = 0;
}