示例#1
0
void wxCompositeShape::OnBeginDragLeft(double x, double y, int WXUNUSED(keys), int WXUNUSED(attachment))
{
	objectStartX = x;
	objectStartY = y;

	wxClientDC dc(GetCanvas());
	GetCanvas()->PrepareDC(dc);

	Erase();

	dc.SetLogicalFunction(OGLRBLF);

	wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
	dc.SetPen(dottedPen);
	dc.SetBrush((* wxTRANSPARENT_BRUSH));
	m_canvas->CaptureMouse();

	double xx = x;
	double yy = y;
	m_canvas->Snap(&xx, &yy);
	double offsetX = xx - objectStartX;
	double offsetY = yy - objectStartY;

	GetEventHandler()->OnDrawOutline(dc, GetX() + offsetX, GetY() + offsetY, GetWidth(), GetHeight());

//  wxShape::OnBeginDragLeft(x, y, keys, attachment);
}
示例#2
0
文件: view.cpp 项目: EdgarTx/wx
void csCanvas::DrawOutline(wxDC& dc, double x1, double y1, double x2, double y2)
{
    wxPen dottedPen(*wxBLACK, 1, wxDOT);
    dc.SetPen(dottedPen);
    dc.SetBrush(* wxTRANSPARENT_BRUSH);

    dc.DrawRectangle((long) x1, (long) y1, (long) (x2 - x1), (long) (y2 - y1));
}
示例#3
0
void wxPolygonShape::OnSizingBeginDragLeft(wxControlPoint *pt, double x, double y, int WXUNUSED(keys), int WXUNUSED(attachment))
{
	wxPolygonControlPoint *ppt = (wxPolygonControlPoint *) pt;

	wxClientDC dc(GetCanvas());
	GetCanvas()->PrepareDC(dc);

	this->Erase();

	dc.SetLogicalFunction(OGLRBLF);

	double bound_x;
	double bound_y;
	this->GetBoundingBoxMin(&bound_x, &bound_y);

	double dist = (double)sqrt((x - this->GetX()) * (x - this->GetX()) +
	                           (y - this->GetY()) * (y - this->GetY()));
	ppt->m_originalDistance = dist;
	ppt->m_originalSize.x = bound_x;
	ppt->m_originalSize.y = bound_y;

	if (ppt->m_originalDistance == 0.0) ppt->m_originalDistance = (double) 0.0001;

	wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
	dc.SetPen(dottedPen);
	dc.SetBrush((* wxTRANSPARENT_BRUSH));

#if 0 // keys & KEY_CTRL)
	{
		// TODO: mend this code. Currently we rely on altering the
		// actual points, but we should assume we're not, as per
		// the normal sizing case.
		m_canvas->Snap(&x, &y);

		// Move point
		ppt->m_polygonVertex->x = x - this->GetX();
		ppt->m_polygonVertex->y = y - this->GetY();
		ppt->SetX(x);
		ppt->SetY(y);
		((wxPolygonShape *)this)->CalculateBoundingBox();
		((wxPolygonShape *)this)->CalculatePolygonCentre();
	}
#else
	{
		ppt->CalculateNewSize(x, y);
	}
#endif

	this->GetEventHandler()->OnDrawOutline(dc, this->GetX(), this->GetY(),
	                                       ppt->GetNewSize().x, ppt->GetNewSize().y);

	m_canvas->CaptureMouse();
}
示例#4
0
void MyEvtHandler::OnDragRight(bool WXUNUSED(draw), double x, double y, int WXUNUSED(keys), int attachment)
{
  // Force attachment to be zero for now
  attachment = 0;

  wxClientDC dc(GetShape()->GetCanvas());
  GetShape()->GetCanvas()->PrepareDC(dc);

  wxPen dottedPen(*wxBLACK, 1, wxDOT);
  dc.SetLogicalFunction(OGLRBLF);
  dc.SetPen(dottedPen);
  double xp, yp;
  GetShape()->GetAttachmentPosition(attachment, &xp, &yp);
  dc.DrawLine((long) xp, (long) yp, (long) x, (long) y);
}
示例#5
0
void MyEvtHandler::OnBeginDragRight(double x, double y, int WXUNUSED(keys), int attachment)
{
  // Force attachment to be zero for now. Eventually we can deal with
  // the actual attachment point, e.g. a rectangle side if attachment mode is on.
  attachment = 0;

  wxClientDC dc(GetShape()->GetCanvas());
  GetShape()->GetCanvas()->PrepareDC(dc);

  wxPen dottedPen(*wxBLACK, 1, wxDOT);
  dc.SetLogicalFunction(OGLRBLF);
  dc.SetPen(dottedPen);
  double xp, yp;
  GetShape()->GetAttachmentPosition(attachment, &xp, &yp);
  dc.DrawLine((long) xp, (long) yp, (long) x, (long) y);
  GetShape()->GetCanvas()->CaptureMouse();
}
示例#6
0
void wxDiagram::DrawOutline(wxDC& dc, double x1, double y1, double x2, double y2)
{
  wxPen dottedPen(*wxBLACK, 1, wxDOT);
  dc.SetPen(dottedPen);
  dc.SetBrush((* wxTRANSPARENT_BRUSH));

  wxPoint points[5];

  points[0].x = (int) x1;
  points[0].y = (int) y1;

  points[1].x = (int) x2;
  points[1].y = (int) y1;

  points[2].x = (int) x2;
  points[2].y = (int) y2;

  points[3].x = (int) x1;
  points[3].y = (int) y2;

  points[4].x = (int) x1;
  points[4].y = (int) y1;
  dc.DrawLines(5, points);
}
示例#7
0
void wxShape::OnSizingBeginDragLeft(wxControlPoint *pt, double x, double y, int keys, int WXUNUSED(attachment))
{
	m_canvas->CaptureMouse();

	wxClientDC dc(GetCanvas());
	GetCanvas()->PrepareDC(dc);
	/*
	  if (pt->m_eraseObject)
	    this->Erase(dc);
	*/

	dc.SetLogicalFunction(OGLRBLF);

	double bound_x;
	double bound_y;
	this->GetBoundingBoxMin(&bound_x, &bound_y);

	// Choose the 'opposite corner' of the object as the stationary
	// point in case this is non-centring resizing.
	if (pt->GetX() < this->GetX())
		pt->sm_controlPointDragStartX = (double)(this->GetX() + (bound_x / 2.0));
	else
		pt->sm_controlPointDragStartX = (double)(this->GetX() - (bound_x / 2.0));

	if (pt->GetY() < this->GetY())
		pt->sm_controlPointDragStartY = (double)(this->GetY() + (bound_y / 2.0));
	else
		pt->sm_controlPointDragStartY = (double)(this->GetY() - (bound_y / 2.0));

	if (pt->m_type == CONTROL_POINT_HORIZONTAL)
		pt->sm_controlPointDragStartY = (double)(this->GetY() - (bound_y / 2.0));
	else if (pt->m_type == CONTROL_POINT_VERTICAL)
		pt->sm_controlPointDragStartX = (double)(this->GetX() - (bound_x / 2.0));

	// We may require the old width and height.
	pt->sm_controlPointDragStartWidth = bound_x;
	pt->sm_controlPointDragStartHeight = bound_y;

	wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
	dc.SetPen(dottedPen);
	dc.SetBrush((* wxTRANSPARENT_BRUSH));

	if (this->GetCentreResize())
	{
		double new_width = (double)(2.0 * fabs(x - this->GetX()));
		double new_height = (double)(2.0 * fabs(y - this->GetY()));

		// Constrain sizing according to what control point you're dragging
		if (pt->m_type == CONTROL_POINT_HORIZONTAL)
		{
			if (GetMaintainAspectRatio())
			{
				new_height = bound_y * (new_width / bound_x);
			}
			else
				new_height = bound_y;
		}
		else if (pt->m_type == CONTROL_POINT_VERTICAL)
		{
			if (GetMaintainAspectRatio())
			{
				new_width = bound_x * (new_height / bound_y);
			}
			else
				new_width = bound_x;
		}
		else if (pt->m_type == CONTROL_POINT_DIAGONAL && (keys & KEY_SHIFT))
			new_height = bound_y * (new_width / bound_x);

		if (this->GetFixedWidth())
			new_width = bound_x;

		if (this->GetFixedHeight())
			new_height = bound_y;

		pt->sm_controlPointDragEndWidth = new_width;
		pt->sm_controlPointDragEndHeight = new_height;
		this->GetEventHandler()->OnDrawOutline(dc, this->GetX(), this->GetY(),
		                                       new_width, new_height);
	}
	else
	{
		// Don't maintain the same centre point!
		double newX1 = wxMin(pt->sm_controlPointDragStartX, x);
		double newY1 = wxMin(pt->sm_controlPointDragStartY, y);
		double newX2 = wxMax(pt->sm_controlPointDragStartX, x);
		double newY2 = wxMax(pt->sm_controlPointDragStartY, y);
		if (pt->m_type == CONTROL_POINT_HORIZONTAL)
		{
			newY1 = pt->sm_controlPointDragStartY;
			newY2 = newY1 + pt->sm_controlPointDragStartHeight;
		}
		else if (pt->m_type == CONTROL_POINT_VERTICAL)
		{
			newX1 = pt->sm_controlPointDragStartX;
			newX2 = newX1 + pt->sm_controlPointDragStartWidth;
		}
		else if (pt->m_type == CONTROL_POINT_DIAGONAL && ((keys & KEY_SHIFT) || GetMaintainAspectRatio()))
		{
			double newH = (double)((newX2 - newX1) * (pt->sm_controlPointDragStartHeight / pt->sm_controlPointDragStartWidth));
			if (pt->GetY() > pt->sm_controlPointDragStartY)
				newY2 = (double)(newY1 + newH);
			else
				newY1 = (double)(newY2 - newH);
		}
		double newWidth = (double)(newX2 - newX1);
		double newHeight = (double)(newY2 - newY1);

		if (pt->m_type == CONTROL_POINT_VERTICAL && GetMaintainAspectRatio())
		{
			newWidth = bound_x * (newHeight / bound_y) ;
		}

		if (pt->m_type == CONTROL_POINT_HORIZONTAL && GetMaintainAspectRatio())
		{
			newHeight = bound_y * (newWidth / bound_x) ;
		}

		pt->sm_controlPointDragPosX = (double)(newX1 + (newWidth / 2.0));
		pt->sm_controlPointDragPosY = (double)(newY1 + (newHeight / 2.0));
		if (this->GetFixedWidth())
			newWidth = bound_x;

		if (this->GetFixedHeight())
			newHeight = bound_y;

		pt->sm_controlPointDragEndWidth = newWidth;
		pt->sm_controlPointDragEndHeight = newHeight;
		this->GetEventHandler()->OnDrawOutline(dc, pt->sm_controlPointDragPosX, pt->sm_controlPointDragPosY, newWidth, newHeight);
	}
}