void WGraphicsPolygonItem::mousePressEvent(WGraphicsSceneMouseEvent* event)
{
	if (event->button() == Ws::LeftButton)
	{
		bool contain = contains(event->scenePos());
		if (isSelectable() && !isSelected() && contain) //not selected ---> selected
		{
			_select_flag = SF_CONTENT;
			setSelected();
			scene()->update(boundingRect());
			event->widget()->setCursor(WCursor(getCursorShape(_select_flag)));

			scene()->itemChange(WGraphicsChange(WGraphicsChange::Selected, this));
		}
		else if (isSelected() && !contain) //selected ---> not selected
		{
			_select_flag = SF_NONE;
			setSelected(false);
			scene()->update(boundingRect());
			event->widget()->setCursor(WCursor(getCursorShape(_select_flag)));

			scene()->itemChange(WGraphicsChange(WGraphicsChange::Unselected, this));
		}
	}
	else if (event->button() == Ws::RightButton) //请求右键菜单
	{
		int flag = low_word(_select_flag);
		Ws::ContextMenuFlags flags = 0;
		if (flag == SF_VERTEX && data()->polygon.size() > 4)
		{
			flags |= Ws::DeleteVertex;
		}
		else if (flag == SF_MID)
		{
			flags |= Ws::AddVertex;
		}
		else if (flag == SF_CONTENT)
		{
			flags |= Ws::Copy;
		}

		if (flags)
		{
			requestContextMenu(flags);
		}
	}
}
Esempio n. 2
0
GHOST_TSuccess GHOST_WindowWin32::setWindowCursorVisibility(bool visible)
{
	if (::GetForegroundWindow() == m_hWnd) {
		loadCursor(visible, getCursorShape());
	}

	return GHOST_kSuccess;
}
void WGraphicsPolygonItem::mouseMoveEvent(WGraphicsSceneMouseEvent* event)
{
	WWorldPointF pos = event->scenePos();
	
	if (isSelected())
	{
		if (event->buttons() & Ws::LeftButton) //drag move
		{
			_dragging = true;

			WWorldPolygonF polygonFrom = draggedPolygon(data()->polygon, scene()->dragStartPos(), event->lastScenePos(), _select_flag);
			WWorldPolygonF polygonTo = draggedPolygon(data()->polygon, scene()->dragStartPos(), event->scenePos(), _select_flag);
			scene()->update(expanded(polygonFrom.boundingRect() | polygonTo.boundingRect() | data()->polygon.boundingRect()));
		}
		else //update select flag (status transfer) 
		{
			int old_flag = _select_flag;
			if (!contains(pos)) //other status ---> none selected
			{
				_select_flag = SF_NONE;
			}
			else
			{
				unsigned i = 0;
				unsigned size = _cp.size();
				for (; i<size; ++i)
				{
					//detect wheter control point is selected
					if (distance(pos, data()->polygon[i]) < CP_RADIUS)
					{
						_select_flag = make_int(i, SF_VERTEX);
						break;
					}
					else if (distance(pos, _cp[i]) < CP_RADIUS) 
					{
						_select_flag = make_int(i, SF_MID);
						break;
					}
				}

				if (i == size) //no control point is selected, that is, content is selected
				{
					_select_flag = SF_CONTENT;
				}
			}

			if (_select_flag != old_flag) //select status changed
			{
				scene()->update(boundingRect());
				event->widget()->setCursor(WCursor(getCursorShape(_select_flag)));
			}
		}
	}
}
void WGraphicsRichTextItem::mousePressEvent(WGraphicsSceneMouseEvent* event)
{
	bool contain = contains(getRotateMatrix_1().map(event->scenePos()));
	if (isSelectable() && isSelectable() && !isSelected() && contain) //status transfer, not selected ---> selected
	{
		_select_flag = SF_CONTENT;
		setSelected();
		scene()->update(boundingRect());
		event->widget()->setCursor(WCursor(getCursorShape(_select_flag)));

		scene()->itemChange(WGraphicsChange(WGraphicsChange::Selected, this));
	}
	else if (isSelected() && !contain) //status transfer, selected ---> not selected
	{
		_select_flag = SF_NONE;
		setSelected(false);
		scene()->update(boundingRect());
		event->widget()->setCursor(WCursor(getCursorShape(_select_flag)));

		scene()->itemChange(WGraphicsChange(WGraphicsChange::Unselected, this));
	}
}
void WGraphicsRichTextItem::mouseMoveEvent(WGraphicsSceneMouseEvent* event)
{
	WWorldPointF pos = getRotateMatrix_1().map(event->scenePos());

	if (isSelected())
	{
		if (event->buttons() & Ws::LeftButton) //drag move
		{
			_dragging = true;
			
			if (_select_flag == SF_CONTENT)
			{
				WWorldRectF r = boundingRect();
				WWorldRectF rectFrom = r.translated(event->lastScenePos() - scene()->dragStartPos());
				WWorldRectF rectTo = r.translated(event->scenePos() - scene()->dragStartPos());
				scene()->update(r | rectFrom | rectTo);
			}
			else if (_select_flag == SF_ROTATE)
			{
				WWorldPointF c = _bound_rect.center();
				double radius = WWorldLineF(_bound_rect.topLeft(), _bound_rect.bottomRight()).length() / 2;
				scene()->update(WWorldRectF(c.x(), c.y(), 0.0, 0.0).adjusted(-radius, -radius, radius, radius));
			}
		}
		else //update select flag (status transfer) 
		{
			int old_flag = _select_flag;
			if (!contains(pos)) //other status ---> none selected
			{
				_select_flag = SF_NONE;
			}
			else
			{
				_select_flag = (distance(_rotate_pt, pos) < CP_RADIUS) ? SF_ROTATE : SF_CONTENT;
			}

			if (_select_flag != old_flag) //select status changed
			{
				scene()->update(boundingRect());
				event->widget()->setCursor(WCursor(getCursorShape(_select_flag)));
			}
		}
	}
}
void WGraphicsRectItem::mouseMoveEvent(WGraphicsSceneMouseEvent* event)
{
	WMatrix matrix = getRotateMatrix_1();
	WWorldPointF pos = matrix.map(event->scenePos());
	
	if (isSelected())
	{
		if (event->buttons() & Ws::LeftButton) //drag move
		{
			_dragging = true;

			WWorldPointF lastPos = matrix.map(event->lastScenePos());
			WWorldPointF dragPos = matrix.map(scene()->dragStartPos());

			WWorldRectF r = boundingRect();
			if (_select_flag != SF_ROTATE) //矩形不是在旋转
			{
				if (_select_flag != SF_CONTENT || isMovable()) //矩形不是整个被选中
				{
					const int (&f)[4] = ADJUST_TABLE[bit(_select_flag)];

					WWorldPointF offsetFrom = lastPos - dragPos;
					WWorldPointF offsetTo = pos - dragPos;
					WWorldRectF rectFrom = data()->rect.adjusted(offsetFrom.x() * f[0], offsetFrom.y() * f[1], offsetFrom.x() * f[2], offsetFrom.y() * f[3]);
					WWorldRectF rectTo = data()->rect.adjusted(offsetTo.x() * f[0], offsetTo.y() * f[1], offsetTo.x() * f[2], offsetTo.y() * f[3]);
					scene()->update(expanded(rectFrom | rectTo | boundingRect()));
				}
			}
			else //矩形在旋转
			{
				double radius = std::max(data()->rect.width() / 2, data()->rect.height() / 2);
				WWorldPointF c = data()->rect.center();
				scene()->update(WWorldRectF(c.x(), c.y(), 0.0, 0.0).adjusted(-radius, -radius, radius, radius));
			}
		}
		else //update select flag (status transfer) 
		{
			int old_flag = _select_flag;
			if (!contains(pos)) //other status ---> none selected
			{
				_select_flag = SF_NONE;
			}
			else
			{
				unsigned i=0;
				unsigned size = array_size(_cp);
				for (; i<size; ++i)
				{
					if (distance(pos, _cp[i]) < CP_RADIUS) //detect wheter control point is selected
					{
						_select_flag = (1 << i); //control point _cp[i] is presently selected
						break;
					}
				}

				if (i == size)
				{
					_select_flag = (distance(_rotate_pt, pos) < CP_RADIUS) ? SF_ROTATE : SF_CONTENT;
				}
			}

			if (_select_flag != old_flag) //select status changed
			{
				scene()->update(boundingRect());
				event->widget()->setCursor(WCursor(getCursorShape(_select_flag)));
			}
		}
	}
}