我目前有两个鼠标回调函数都做不同的事情
1,1,1,1,1,
第二个回调从点击窗口的点开始绘制一条线,同时鼠标左键被按下直到它被释放的点
// Function to choose midpoint of a circle
static void onMouse( int event, int x, int y, int, void* )
{
//Detect Mouse button event
if( event == EVENT_LBUTTONDOWN )
{
//store point clicked
}
}
如何按顺序分别调用每个函数。即首先运行onMouse Callback并运行DrawLine Callback函数
// Draws a line from the beginning of a point to another.
// This line is the diameter of a circle
// The first point isn't the coordinates stored by onMouse
static void DrawLine( int event, int x, int y, int, void* )
{
switch (event)
{
case EVENT_LBUTTONDOWN:
// start point
case EVENT_LBUTTONUP:
//endpoint
break;
case EVENT_MOUSEMOVE:
if(clicked)
{
// store point
}
break;
default : break;
}
}
答案 0 :(得分:0)
只需使用一个回调函数onMouse
:
setMouseCallback("WinName", onMouse, 0);
然后,您可以从DrawLine
致电onMouse
:
static void DrawLine( int event, int x, int y)
{
// Do something...
}
static void onMouse( int event, int x, int y, int, void* )
{
//Detect Mouse button event
if( SOME_CONDITION )
{
// Do something...
}
else
{
DrawLine( event, x, y )
}
}
根据CTRL, ALT, SHIFT等修饰符,您通常会做不同的事情。