void xCanvas::ProcessMsg(UINT msg, int x, int y) { if (msg == WM_XINK_STARTSTROKE) StartStroke(); if (msg == WM_XINK_ADDPOINT) AddPoint(x, y); if (msg == WM_XINK_STOPSTROKE) StopStroke(); }
//---------------------------------------------------------------------------- void DragDropLink::AutoStroke(){ //---------------------------------------------------------------------------- PROC_TRACE; assert(m_pFrom != NULL); assert(m_pTo != NULL); CPoint fromPt, toPt; int fromDir, toDir; // fromPt is an x,y to start from. fromDir is an angle that the first link must // obey (0,90,180,270 for now) // // 0 - right // 90 - up // 180 - left // 270 - down fromPt = m_pFrom->GetFromLinkPoint(); fromDir = m_pFrom->GetFromLinkDir(); toPt = m_pTo->GetToLinkPoint(); toDir = m_pTo->GetToLinkDir(); // draw a line between the two points. StartStroke(); AddPoint(fromPt); // MIN_LINK_SEGMENT = minimum length of Initial/final link segment // MAX_LINK_SEGMENT = maximum length of Initial/final link segment // CALC_LINK_SEGMENT = divisor to calculate Initial/final link segment // Minimize "Z-shaped" links by adjusting the Initial & final link // segments when the x and y deltas are small. int xseg = abs(fromPt.x - toPt.x) / CALC_LINK_SEGMENT; int yseg = abs(fromPt.y - toPt.y) / CALC_LINK_SEGMENT; if (xseg > MAX_LINK_SEGMENT) xseg = MAX_LINK_SEGMENT; else if (xseg < MIN_LINK_SEGMENT) xseg = MIN_LINK_SEGMENT; if (yseg > MAX_LINK_SEGMENT) yseg = MAX_LINK_SEGMENT; else if (yseg < MIN_LINK_SEGMENT) yseg = MIN_LINK_SEGMENT; // now, we have the minimum X offsets for the normal case. It is // time to see if the port would like to increase that minimum offset int fromMinXOffset = m_pFrom->GetMinXOffset(); int xsegFrom = (xseg > fromMinXOffset) ? xseg : fromMinXOffset; int toMinXOffset = m_pTo->GetMinXOffset(); int xsegTo = (xseg > toMinXOffset) ? xseg : toMinXOffset; // draw the Initial offset in Initial direction int cx = 0; int cy = 0; if (fromDir == 0) cx = xsegFrom; if (fromDir == 90) cy = yseg; if (fromDir == 180) cx = - xsegFrom; if (fromDir == 270) cy = - yseg; fromPt += CSize(cx, cy); AddPoint(fromPt); // calculate the offset from the "to" point fromPt = toPt; // copy to point cx = cy = 0; if (toDir == 0) cx = xsegTo; if (toDir == 90) cy = yseg; if (toDir == 180) cx = - xsegTo; if (toDir == 270) cy = - yseg; fromPt += CSize(cx, cy); AddPoint(fromPt); // now finish up AddPoint(toPt); FinishStroke(); }