Пример #1
0
//更新界面上显示的鼠标坐标以及对应点灰度信息。
//输入x y为img_on_show上的坐标,如果为-1,则会自动调用getMouseXY获取
void CSpotsMainDlg::refreshPosInfo(int x, int y)
{
	if (x == -1)
	{
		cv::Point xy = getMouseXY();
		if (xy.x != -1)   //鼠标是否在控件范围之内
		{
			x = xy.x;
			y = xy.y;
		}
		else
			return; 
	}
	int r = 0, g = 0, b = 0;
	if (img_on_show.channels() == 1)
		r = g = b = img_on_show.ptr<uchar>(y)[x];
	else
	{
		b = img_on_show.ptr<uchar>(y)[x * 3];
		g = img_on_show.ptr<uchar>(y)[x * 3 + 1];
		r = img_on_show.ptr<uchar>(y)[x * 3 + 2];
	}
	stringstream ss;
	ss << "(" << x << "," << y << ")=>(" << r << "," << g << "," << b << ") zoom=1/" << zoom << "";

	//ss转为LPWSTR
	int dwLen = ss.str().length() + 1;//strlen(ss.str().c_str()) + 1;
	int nwLen = MultiByteToWideChar(CP_ACP, 0, ss.str().c_str(), dwLen, NULL, 0);//算出合适的长度
	LPWSTR lpszPath = new WCHAR[dwLen];
	MultiByteToWideChar(CP_ACP, 0, ss.str().c_str(), dwLen, lpszPath, nwLen);

	GetDlgItem(IDC_LABLE_IMG_INFO)->SetWindowText(lpszPath);
	delete lpszPath;
}
Пример #2
0
int
myScreenGetModifierPressed (ScreenInfo *screen_info)
{
    int rx, ry;

    return (int) getMouseXY (screen_info, screen_info->xroot, &rx, &ry);
}
Пример #3
0
void CSpotsMainDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
	if (img_on_show.rows > 0)//有图才继续走
	{
		cv::Point xy = getMouseXY();
		DrawPicToHDC(bigImg_cache, IDC_IMG_BIG);
		DrawPicToHDC(historyImg_cache, IDC_IMG_HISTORY);
		DrawPicToHDC(SampleImg_cache, IDC_MAIN_SHOWSAMPLE);
		if (xy.x != -1)   //鼠标是否在控件范围之内
		{
			int x = xy.x;
			int y = xy.y;
			if (p_contrller->PauseFlag)//只有暂停的时候能缩放
			{
				////进入放大模式
				//if (zoom == 8)
				//{
				//	zoom = 1;
				//	ShowImgROI(x, y);
				//	point_StartUpLeft = cv::Point(x, y);//记录ROI左上点坐标
				//}
				//else//取消放大模式
				//{
				//	zoom = 8;
				//	ShowImgROI();
				//}
				//else//通过鼠标点击,切换ROI显示的范围
				{
					CPoint mpoint;
					::GetCursorPos(&mpoint);
					point_LButtonDown = mpoint;//记录鼠标按下点坐标

					CRect rect;
					GetDlgItem(IDC_IMG_BIG)->GetClientRect(rect);
					GetDlgItem(IDC_IMG_BIG)->ClientToScreen(rect);//函数是将你打开的APP中客户区的坐标点信息转换为整个屏幕的坐标
					x -= (mpoint.x - rect.left)*zoom;
					y -= (mpoint.y - rect.top)*zoom;
					point_StartUpLeft = cv::Point(x, y);//记录ROI左上点坐标

					//stringstream ss;
					//ss << point_StartUpLeft.x << "," << point_StartUpLeft.y << endl;
					//MFCConsole::Output(ss.str());
					//ShowImgROI(x, y);
				}
			}
		}
	}
	CDialogEx::OnLButtonDown(nFlags, point);
}
Пример #4
0
BOOL CSpotsMainDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint point)
{
	//此处的CPoint point已经是Screen坐标了,不需要再进行转换
	if (img_on_show.rows > 0)//有图才继续走
	{
		if (p_contrller->PauseFlag)//只有暂停的时候能缩放
		{
			cv::Point xy = getMouseXY();
			if (xy.x != -1)   //鼠标是否在控件范围之内
			{
				int x = xy.x;
				int y = xy.y;
				if (img_on_show.rows > 0)
				{
					//调整缩放值
					//zDelta:大于0时为向上滚动,小于0时为向下滚动。
					if (zDelta > 0)
					{
						zoom = zoom % 2 == 0 ? zoom - 2 : zoom - 1;
						zoom = zoom < 1 ? 1 : zoom;
					}
					else//当zoom == 8时显示全图
					{
						zoom = zoom % 2 == 0 ? zoom + 2 : zoom + 1;
						zoom = zoom > 8 ? 8 : zoom;
					}
				}
				if (zoom == 8)
				{
					ShowImgROI();
				}
				else
				{
					//x y为鼠标位置,减去半宽半高得到ROI起点坐标
					x -= idc_width / 2 * zoom;
					y -= idc_height / 2 * zoom;
					ShowImgROI(x, y);
				}
			}
		}
	}
	return CDialogEx::OnMouseWheel(nFlags, zDelta, point);
}
Пример #5
0
void CSpotsMainDlg::OnMouseMove(UINT nFlags, CPoint point)
{
	cv::Point xy = getMouseXY();
	if (xy.x != -1)   //鼠标是否在图片显示控件范围之内
	{
		if (img_on_show.rows > 0)//有图才继续走
		{
			//鼠标的程序内坐标转换为屏幕坐标
			ClientToScreen(&point);
			//移动鼠标的时候显示对应位置的灰度值
			if (p_contrller->PauseFlag)//只有暂停的时候能
			{

				int x = xy.x;
				int y = xy.y;

				if (point_LButtonDown.x == -1)//没有按下鼠标左键,则显示坐标与灰度值
				{
					refreshPosInfo(x, y);
				}
				else//按下鼠标左键实现拖动ROI
				{
					CPoint mpoint;
					::GetCursorPos(&mpoint);
					int offsetx = (mpoint.x - point_LButtonDown.x)*zoom;
					int offsety = (mpoint.y - point_LButtonDown.y)*zoom;

					x = point_StartUpLeft.x - offsetx;
					y = point_StartUpLeft.y - offsety;
					ShowImgROI(x, y);
				}

			}
		}
	}
	else if (point_LButtonDown.x != -1 || point_LButtonDown.y != -1)
	{
		point_LButtonDown = CPoint(-1, -1);		
		//MFCConsole::Output("leave rect,point_LButtonDown = CPoint(-1, -1);\r");
	}
	CDialogEx::OnMouseMove(nFlags, point);
}
Пример #6
0
void
clientInitPosition (Client * c)
{
    ScreenInfo *screen_info;
    Client *c2;
    GdkRectangle rect;
    int full_x, full_y, full_w, full_h, msx, msy;
    gint n_monitors;
    gboolean place;
    gboolean position;

    g_return_if_fail (c != NULL);
    TRACE ("entering clientInitPosition");

    screen_info = c->screen_info;
    msx = 0;
    msy = 0;
    position = (c->size->flags & (PPosition | USPosition));

    n_monitors = myScreenGetNumMonitors (c->screen_info);
    if ((n_monitors > 1) || (screen_info->params->placement_mode == PLACE_MOUSE))
    {
        getMouseXY (screen_info, screen_info->xroot, &msx, &msy);
        myScreenFindMonitorAtPoint (screen_info, msx, msy, &rect);
    }
    else
    {
        gdk_screen_get_monitor_geometry (screen_info->gscr, 0, &rect);
    }
    if (position || (c->type & (WINDOW_TYPE_DONT_PLACE | WINDOW_TYPE_DIALOG)) || clientIsTransient (c))
    {
        if (!position && clientIsTransient (c) && (c2 = clientGetTransient (c)))
        {
            /* Center transient relative to their parent window */
            c->x = c2->x + (c2->width - c->width) / 2;
            c->y = c2->y + (c2->height - c->height) / 2;

            if (n_monitors > 1)
            {
                msx = frameX (c) + (frameWidth (c) / 2);
                msy = frameY (c) + (frameHeight (c) / 2);
                myScreenFindMonitorAtPoint (screen_info, msx, msy, &rect);
            }
        }
        if (CONSTRAINED_WINDOW (c))
        {
            clientKeepVisible (c, n_monitors, &rect);
        }
        place = FALSE;
    }
    else
    {
        place = TRUE;
    }

    full_x = MAX (screen_info->params->xfwm_margins[STRUTS_LEFT], rect.x);
    full_y = MAX (screen_info->params->xfwm_margins[STRUTS_TOP], rect.y);
    full_w = MIN (screen_info->width - screen_info->params->xfwm_margins[STRUTS_RIGHT],
                  rect.x + rect.width) - full_x;
    full_h = MIN (screen_info->height - screen_info->params->xfwm_margins[STRUTS_BOTTOM],
                  rect.y + rect.height) - full_y;

    /* Adjust size to the widest size available, not covering struts */
    clientMaxSpace (screen_info, &full_x, &full_y, &full_w, &full_h);

    /*
       If the windows is smaller than the given ratio of the available screen area,
       or if the window is larger than the screen area or if the given ratio is higher
       than 100% place the window at the center.
       Otherwise, place the window "smartly", using the good old CPU consuming algorithm...
     */
    if (place)
    {
        if ((screen_info->params->placement_ratio >= 100) ||
            (100 * frameWidth(c) * frameHeight(c)) < (screen_info->params->placement_ratio * full_w * full_h))
        {
            if (screen_info->params->placement_mode == PLACE_MOUSE)
            {
                mousePlacement (c, full_x, full_y, full_w, full_h, msx, msy);
            }
            else
            {
                centerPlacement (c, full_x, full_y, full_w, full_h);
            }
        }
        else if ((frameWidth(c) >= full_w) && (frameHeight(c) >= full_h))
        {
            centerPlacement (c, full_x, full_y, full_w, full_h);
        }
        else
        {
            smartPlacement (c, full_x, full_y, full_w, full_h);
        }
    }

    if (c->type & WINDOW_REGULAR_FOCUSABLE)
    {
        clientAutoMaximize (c, full_w, full_h);
    }
}