void uiDrawMatrixRotate(uiDrawMatrix *m, double x, double y, double amount) { BAffineTransform a; m2a(m, &a); // TODO degrees or radians? a.RotateBy(BPoint(x, y), amount); a2m(&a, m); }
void Leaves::Draw(BView* view, int32 frame) { float scale = fLeafSize / kLeafWidth / (kMaximumLeafSize * 2); scale *= view->Bounds().Width(); scale += scale * drand48() * fSizeVariation / 100.; BAffineTransform transform; transform.TranslateBy(-kLeafWidth / 2, -kLeafHeight / 2); // draw the leaf centered on the point transform.RotateBy(drand48() * 2. * M_PI); if ((rand() & 64) == 0) transform.ScaleBy(-1., 1.); // flip half of the time transform.ScaleBy(scale); transform.TranslateBy(_RandomPoint(view->Bounds())); BPoint center = transform.Apply(BPoint(kLeafWidth / 2, kLeafHeight / 2)); BPoint gradientOffset = BPoint(60 * scale, 80 * scale); BGradientLinear gradient(center - gradientOffset, center + gradientOffset); int color = (rand() / 7) % kColorCount; gradient.AddColor(kColors[color][0], 0.f); gradient.AddColor(kColors[color][1], 255.f); BShape leafShape; leafShape.MoveTo(transform.Apply(kLeafBegin)); for (int i = 0; i < kLeafCurveCount; ++i) { BPoint control[3]; for (int j = 0; j < 3; ++j) control[j] = transform.Apply(kLeafCurves[i][j]); leafShape.BezierTo(control); } leafShape.Close(); view->PushState(); view->SetDrawingMode(B_OP_ALPHA); view->SetHighColor(0, 0, 0, 50); for (int i = 2; i >= 0; --i) { view->SetOrigin(i * 0.1, i * 0.3); view->SetPenSize(i * 2); view->StrokeShape(&leafShape); } view->PopState(); view->FillShape(&leafShape, gradient); }
const BAffineTransform& BAffineTransform::SetScale(double x, double y) { double tx; double ty; double rotation; double shearX; double shearY; if (!GetAffineParameters(&tx, &ty, &rotation, NULL, NULL, &shearX, &shearY)) { return *this; } BAffineTransform result; result.ShearBy(shearX, shearY); result.ScaleBy(x, y); result.RotateBy(rotation); result.TranslateBy(tx, ty); return *this = result; }