本文整理汇总了C++中AffineTransform::rect_to_rect方法的典型用法代码示例。如果您正苦于以下问题:C++ AffineTransform::rect_to_rect方法的具体用法?C++ AffineTransform::rect_to_rect怎么用?C++ AffineTransform::rect_to_rect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AffineTransform
的用法示例。
在下文中一共展示了AffineTransform::rect_to_rect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pivot
// DragTo
void
DragSideState::DragTo(BPoint current, uint32 modifiers)
{
BRect oldBox = fParent->Box();
if (oldBox.Width() == 0.0 || oldBox.Height() == 0.0)
return;
// TODO: some of this can be combined into less steps
BRect newBox = oldBox;
fOldTransform.InverseTransform(¤t);
switch (fSide) {
case LEFT_SIDE:
newBox.left = current.x - fOffsetFromSide;
break;
case RIGHT_SIDE:
newBox.right = current.x - fOffsetFromSide;
break;
case TOP_SIDE:
newBox.top = current.y - fOffsetFromSide;
break;
case BOTTOM_SIDE:
newBox.bottom = current.y - fOffsetFromSide;
break;
}
if (!(modifiers & B_SHIFT_KEY)) {
// keep the x and y scale the same
double xScale = newBox.Width() / oldBox.Width();
double yScale = newBox.Height() / oldBox.Height();
if (modifiers & B_COMMAND_KEY) {
xScale = snap_scale(xScale);
yScale = snap_scale(yScale);
}
if (fSide == LEFT_SIDE || fSide == RIGHT_SIDE)
yScale = yScale > 0.0 ? fabs(xScale) : -fabs(xScale);
else
xScale = xScale > 0.0 ? fabs(yScale) : -fabs(yScale);
switch (fSide) {
case LEFT_SIDE: {
newBox.left = oldBox.right - oldBox.Width() * xScale;
float middle = (oldBox.top + oldBox.bottom) / 2.0;
float newHeight = oldBox.Height() * yScale;
newBox.top = middle - newHeight / 2.0;
newBox.bottom = middle + newHeight / 2.0;
break;
}
case RIGHT_SIDE: {
newBox.right = oldBox.left + oldBox.Width() * xScale;
float middle = (oldBox.top + oldBox.bottom) / 2.0;
float newHeight = oldBox.Height() * yScale;
newBox.top = middle - newHeight / 2.0;
newBox.bottom = middle + newHeight / 2.0;
break;
}
case TOP_SIDE: {
newBox.top = oldBox.bottom - oldBox.Height() * yScale;
float middle = (oldBox.left + oldBox.right) / 2.0;
float newWidth = oldBox.Width() * xScale;
newBox.left = middle - newWidth / 2.0;
newBox.right = middle + newWidth / 2.0;
break;
}
case BOTTOM_SIDE: {
newBox.bottom = oldBox.top + oldBox.Height() * yScale;
float middle = (oldBox.left + oldBox.right) / 2.0;
float newWidth = oldBox.Width() * xScale;
newBox.left = middle - newWidth / 2.0;
newBox.right = middle + newWidth / 2.0;
break;
}
}
}
// build a matrix that performs just the
// distortion of the box with the opposite
// corner of the one being dragged staying fixed
AffineTransform s;
s.rect_to_rect(oldBox.left, oldBox.top, oldBox.right, oldBox.bottom,
newBox.left, newBox.top, newBox.right, newBox.bottom);
// construct a transformation that
// * excludes the effect of the fParant->Pivot()
// * includes the effect of the changed scaling and translation
// (see DragCornerState::DragTo() for explaination)
AffineTransform t;
BPoint pivot(fParent->Pivot());
t.TranslateBy(pivot.x, pivot.y);
t.Multiply(s);
t.Multiply(fOldTransform);
t.TranslateBy(-pivot.x, -pivot.y);
//.........这里部分代码省略.........