void uiDrawMatrixScale(uiDrawMatrix *m, double xCenter, double yCenter, double x, double y) { BAffineTransform a; m2a(m, &a); a.ScaleBy(BPoint(xCenter, yCenter), BPoint(x, y)); a2m(&a, m); }
void uiDrawMatrixTranslate(uiDrawMatrix *m, double x, double y) { BAffineTransform a; m2a(m, &a); a.TranslateBy(x, y); a2m(&a, m); }
void uiDrawTransform(uiDrawContext *c, uiDrawMatrix *m) { BAffineTransform a; m2a(m, &a); // see windows/draw.c a.Multiply(c->view->Transform()); c->view->SetTransform(a); }
void uiDrawMatrixSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount) { BAffineTransform a; m2a(m, &a); // TODO degrees or radians? a.ShearBy(BPoint(x, y), BPoint(xamount, yamount)); a2m(&a, m); }
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); }
static void rotate_by(void* _canvas, double angleRadians) { Canvas* const canvas = reinterpret_cast<Canvas*>(_canvas); BAffineTransform transform = canvas->CurrentState()->Transform(); transform.PreRotateBy(angleRadians); canvas->CurrentState()->SetTransform(transform); canvas->GetDrawingEngine()->SetTransform(transform); }
static void scale_by(void* _canvas, double x, double y) { Canvas* const canvas = reinterpret_cast<Canvas*>(_canvas); BAffineTransform transform = canvas->CurrentState()->Transform(); transform.PreScaleBy(x, y); canvas->CurrentState()->SetTransform(transform); canvas->GetDrawingEngine()->SetTransform(transform); }
void uiDrawMatrixMultiply(uiDrawMatrix *dest, uiDrawMatrix *src) { BAffineTransform c; BAffineTransform d; m2a(dest, &c); m2a(src, &d); c.Multiply(d); a2m(&c, dest); }
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; }
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); }
void LeafView::Draw(BRect updateRect) { float scale = Bounds().Width() / kLeafWidth; BAffineTransform transform; transform.ScaleBy(scale); // BGradientRadial gradient(BPoint(kLeafWidth * 0.75, kLeafHeight * 1.5), // kLeafWidth * 2); BGradientLinear gradient(B_ORIGIN, transform.Apply(BPoint(kLeafWidth, kLeafHeight))); rgb_color lightBlue = make_color(6, 169, 255); rgb_color darkBlue = make_color(0, 50, 126); gradient.AddColor(darkBlue, 0.0); gradient.AddColor(lightBlue, 255.0); // build leaf shape BShape leafShape; leafShape.MoveTo(transform.Apply(kLeafBegin)); for (int i = 0; i < kNumLeafCurves; ++i) { BPoint controlPoints[3]; for (int j = 0; j < 3; ++j) controlPoints[j] = transform.Apply(kLeafCurves[i][j]); leafShape.BezierTo(controlPoints); } leafShape.Close(); PushState(); SetDrawingMode(B_OP_ALPHA); SetHighColor(0, 0, 0, 50); for (int i = 2; i >= 0; --i) { SetOrigin(i * 0.1, i * 0.3); SetPenSize(i * 2); StrokeShape(&leafShape); } PopState(); FillShape(&leafShape, gradient); }