void Viewer::Align (GraphicComp* comp, Alignment a) { Graphic* g = comp->GetGraphic(); float cl, cb, cr, ct; g->GetBounds(cl, cb, cr, ct); Perspective* p = GetPerspective(); float mag = GetMagnification(); float vl = float(p->curx - p->x0) / mag; float vb = float(p->cury - p->y0) / mag; float vr = float(p->curx - p->x0 + p->curwidth - 1) / mag; float vt = float(p->cury - p->y0 + p->curheight - 1) / mag; float dx, dy; switch (a) { case TopLeft: case CenterLeft: case BottomLeft: case Left: dx = vl - cl; break; case TopCenter: case Center: case BottomCenter: dx = (vr + vl - cr - cl) / 2; break; case TopRight: case CenterRight: case BottomRight: case Right: dx = vr - cr; break; } switch (a) { case TopLeft: case TopCenter: case TopRight: case Top: dy = vt - ct; break; case CenterLeft: case Center: case CenterRight: dy = (vt + vb - ct - cb) / 2; break; case BottomLeft: case BottomCenter: case BottomRight: case Bottom: dy = vb - cb; break; } MoveCmd mvcmd(GetEditor(), dx, dy); comp->Interpret(&mvcmd); }
void PadComp::Connect (Connector* target, CGlue* g) { PadGraphic* padgr = GetPad(); float l, b, r, t; padgr->GetBounds(l, b, r, t); float h = (r - l)/2; float v = (t - b)/2; if (target->IsA(PIN_COMP)) { CGlue padGlue(0, 0, h*hfil, h*hfil, v*vfil, v*vfil, h, h, v, v); padGlue.Interpose(g); csolver->Connect(this, target, &padGlue); Connector::Connect(target, &padGlue); } else if (target->IsA(HSLOT_COMP)) { Graphic* peergr = target->GetGraphic(); peergr->GetBounds(l, b, r, t); h += (r - l)/2; CGlue slotGlue(0, 0, h*hfil, h*hfil, v*vfil, v*vfil, h, h, v, v); slotGlue.Interpose(g); csolver->Connect(this, target, &slotGlue); Connector::Connect(target, &slotGlue); } else if (target->IsA(VSLOT_COMP)) { Graphic* peergr = target->GetGraphic(); peergr->GetBounds(l, b, r, t); v += (t - b)/2; CGlue slotGlue(0, 0, h*hfil, h*hfil, v*vfil, v*vfil, h, h, v, v); slotGlue.Interpose(g); csolver->Connect(this, target, &slotGlue); Connector::Connect(target, &slotGlue); } else if (target->IsA(PAD_COMP)) { Graphic* peergr = target->GetGraphic(); peergr->GetBounds(l, b, r, t); h += (r - l)/2; v += (t - b)/2; CGlue padGlue(0, 0, h*hfil, h*hfil, v*vfil, v*vfil, h, h, v, v); padGlue.Interpose(g); csolver->Connect(this, target, &padGlue); Connector::Connect(target, &padGlue); } }