예제 #1
0
void MouseListener::SendNotification(int &x, int &y)
{
    for (List<MouseListener*>::Iterator itr = mListenersList.begin(); itr != mListenersList.end(); ++itr)
    {
        MouseListener *listener = *itr;
        if (nullptr != listener)
            listener->NotifyMousePosition(x, y);
    }
}
예제 #2
0
void MultipleProcess::mouseCallback(int event, int x, int y, int flags, void *ptr)
{
    ProcessListenerWrapper *w   = (ProcessListenerWrapper*)ptr;
    MouseListener   *listener   = w->processListener;
    MultipleProcess *processor  = w->processor;

    processor->setActiveWindow(w->identifier);

    if (listener)
    {
        listener->mouseInput(event, x, y, flags);

        if (event == EVENT_LBUTTONDOWN)
        {
            listener->leftButtonDown(x, y, flags);
        }
        else if (event == EVENT_RBUTTONDOWN)
        {
            listener->rightButtonDown(x, y, flags);
        }
        else if (event == EVENT_MBUTTONDOWN)
        {
            listener->middleButtonDown(x, y, flags);
        }
        else if (event == EVENT_MOUSEMOVE)
        {
            listener->mouseMove(x, y, flags);
        }
    }
}
예제 #3
0
파일: viva.cpp 프로젝트: VIVAlab/vivaVideo
void Processor::mouseCallback(int event, int x, int y, int flags, void *ptr)
{
    MouseListener* listener = (MouseListener*)ptr;
    if (listener)
    {
        listener->mouseInput(event, x, y, flags);
        
        if (event == EVENT_LBUTTONDOWN)
        {
            listener->leftButtonDown(x, y, flags);
        }
        else if (event == EVENT_RBUTTONDOWN)
        {
            listener->rightButtonDown(x, y, flags);
        }
        else if (event == EVENT_MBUTTONDOWN)
        {
            listener->middleButtonDown(x, y, flags);
        }
        else if (event == EVENT_MOUSEMOVE)
        {
            listener->mouseMove(x, y, flags);
        }
    }
}
예제 #4
0
bool GLFWMouseManager::registerListener(MouseListener &listener)
{
    bool setCallback = false;
    if (_listeners.empty()) {
        setCallback = true;
    }
    _listeners.push_back(&listener);
    if (setCallback) {
        /* Set the callback here as setting it in the constructor leads
         * to an infinite loop because setting the callback calls back and
         * the _mouseManager field is still not set when the callback is called,
         * leading to another object being created and so on */
        glfwSetCursorPosCallback(glfwGetCurrentContext(), mouseCallback);

        double xPos, yPos;
        glfwGetCursorPos(glfwGetCurrentContext(), &xPos, &yPos);

        /* Call the callback manually to initialize the values */
        listener.processMouse((int32_t)xPos, (int32_t)yPos);
    }
    return true;
}
예제 #5
0
int main(int argc, char** argv)
{
	ros::init(argc, argv, "mouse_listener");
	MouseListener ml;
	ros::Rate loop_rate(50);
	double min,max,init;
	std::string max_st, min_st,init_st;
	//Reading max,min and init positions from ROS param server, loaded from yaml file
	ROS_INFO("Loading position parameters from server ...");
	if(ros::param::get("/tilt_controller/motor/max",max))
	{
		ROS_INFO("ok max");
	}
	if(ros::param::get("/tilt_controller/motor/min",min))
	{
		ROS_INFO("ok min");
	}
	if(ros::param::get("/tilt_controller/motor/init",init))
	{
		ROS_INFO("ok init");
	}
	ROS_INFO("Min: %d  Max: %d  Init:%d  ",int(min),int(max),int(init));
	std_msgs::Float64 msg_pos;
	float K=0.05;
	float action_threshold=0.02; //Radians
	//Set motor to zero
	float max_angle_deg=150;   //Ax-12 has a rotation about 300 degrees (150+/150-)
	float max_angle=max_angle_deg*M_PI/180;
	float relative_zero=ml.map(init,0,1023,-max_angle,max_angle);  //Zero position in radians from config file.
	ROS_INFO("Abs 0 = %f   Rel 0= %f",ml.map(512,0,1023,-max_angle,max_angle),ml.map(init,0,1023,-max_angle,max_angle));
	//First position equals relative zero
	float position= relative_zero;
	double max_rad=ml.map(max,0,1023,-max_angle,max_angle);
	double min_rad=ml.map(min,0,1023,-max_angle,max_angle);
	float internal_counter=position;
	int old_position=position;
	ROS_INFO("Sending servo to %f",ml.map(position,0,1023,-max_angle,max_angle));
	msg_pos.data=position;
	ml.positionSND(msg_pos,1);
	while(ros::ok())
	{
			//Read relative increment in mouse wheel
			//std::cout<<"In \n";
			internal_counter+=K*ml.getMouseBtn();
			//std::cout<<"Out \n";
			//Check for max and min possible position
			position=internal_counter;
			if (internal_counter>max_rad) position=internal_counter=max_rad;
			if (internal_counter<min_rad) position=internal_counter=min_rad;
			if (fabs((old_position-position))>action_threshold)
			{
				//ROS_INFO("Encoder: %d  Angle: %f",position,current_radians-target_radians);
				if(open_hand) {position=internal_counter=relative_zero;open_hand=0;}
				old_position=position;
				msg_pos.data=position;
				ml.positionSND(msg_pos,0.1);
			}
			//ROS_INFO("Abs: %f Rel: %f   Counter: %f",ml.map(position+relative_zero,0,1023,-max_angle,max_angle),position,internal_counter);
			//std::cout<<"ROS\n";
			if(opening)
				ROS_INFO("Opening");
			else
				ROS_INFO("Stopped");
			ros::spinOnce();
			loop_rate.sleep();
	}
	return 0;
}