void PathView::Draw(BRect updateRect) { if (fMode == kDrawOutline) { } else if (fMode == kStroke) { const int n = fPath.CountPoints(); BShape shape; for (int i = 0; i < n; i++) { if (i == 0) shape.MoveTo(fPath.PointAt(i)); else shape.LineTo(fPath.PointAt(i)); } if (fPath.IsClosed()) shape.Close(); SetPenSize(fWidth); StrokeShape(&shape); ShapeLPB path(&fPath, fWidth, LineCapMode(), LineJoinMode(), LineMiterLimit()); path.CreateLinePath(); SetPenSize(1); BPicture picture; BeginPicture(&picture); FillShape(path.Shape()); EndPicture(); PushState(); ClipToPicture(&picture); SetHighColor(0, 255, 0); FillRect(Bounds()); PopState(); SetOrigin(200, 0); SetHighColor(255, 0, 0); StrokeShape(path.Shape()); Flush(); } }
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); }
void TextDocumentView::_DrawSelection() { int32 start; int32 end; GetSelection(start, end); BShape shape; _GetSelectionShape(shape, start, end); SetDrawingMode(B_OP_SUBTRACT); SetLineMode(B_ROUND_CAP, B_ROUND_JOIN); MovePenTo(fInsetLeft - 0.5f, fInsetTop - 0.5f); if (IsFocus() && Window() != NULL && Window()->IsActive()) { SetHighColor(30, 30, 30); FillShape(&shape); } SetHighColor(40, 40, 40); StrokeShape(&shape); }
float fOffsetY; } translator; MovePenTo(B_ORIGIN); const float arcRX = 50; const float arcRY = 80; BShape shape; shape.MoveTo(BPoint(20, 10)); shape.LineTo(BPoint(10, 90)); shape.LineTo(BPoint(90, 100)); shape.ArcTo(arcRX, arcRY, 45, true, true, BPoint(100, 20)); shape.Close(); StrokeShape(&shape); shape.Clear(); shape.MoveTo(BPoint(20, 10)); shape.LineTo(BPoint(10, 90)); shape.LineTo(BPoint(90, 100)); shape.ArcTo(arcRX, arcRY, 45, false, true, BPoint(100, 20)); shape.Close(); translator.SetOffset(10, 10); translator.Iterate(&shape); SetHighColor(140, 30, 50, 255); StrokeShape(&shape); shape.Clear();
void MouseView::Draw(BRect updateFrame) { SetDrawingMode(B_OP_ALPHA); SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); SetScale(fScaling * 1.8); BShape mouseShape; mouseShape.MoveTo(BPoint(16, 12)); // left BPoint control[3] = { BPoint(12, 16), BPoint(8, 64), BPoint(32, 64) }; mouseShape.BezierTo(control); // right BPoint control2[3] = { BPoint(56, 64), BPoint(52, 16), BPoint(48, 12) }; mouseShape.BezierTo(control2); // top BPoint control3[3] = { BPoint(44, 8), BPoint(20, 8), BPoint(16, 12) }; mouseShape.BezierTo(control3); mouseShape.Close(); // Draw the shadow SetOrigin(-17 * fScaling, -11 * fScaling); SetHighColor(kMouseShadowColor); FillShape(&mouseShape, B_SOLID_HIGH); // Draw the body SetOrigin(-21 * fScaling, -14 * fScaling); BGradientRadial bodyGradient(28, 24, 128); bodyGradient.AddColor(kMouseBodyTopColor, 0); bodyGradient.AddColor(kMouseBodyBottomColor, 255); FillShape(&mouseShape, bodyGradient); // Draw the outline SetPenSize(1 / 1.8 / fScaling); SetDrawingMode(B_OP_OVER); SetHighColor(kMouseOutlineColor); StrokeShape(&mouseShape, B_SOLID_HIGH); // bottom button border BShape buttonsOutline; buttonsOutline.MoveTo(BPoint(13, 27)); BPoint control4[] = { BPoint(18, 30), BPoint(46, 30), BPoint(51, 27) }; buttonsOutline.BezierTo(control4); SetHighColor(kMouseButtonOutlineColor); StrokeShape(&buttonsOutline, B_SOLID_HIGH); SetScale(1); SetOrigin(0, 0); // Separator between the buttons const int32* offset = getButtonOffsets(fType); for (int32 i = 1; i < fType; i++) { BRect buttonRect = _ButtonRect(offset, i); StrokeLine(buttonRect.LeftTop(), buttonRect.LeftBottom()); } mouse_map map; fSettings.Mapping(map); SetDrawingMode(B_OP_OVER); if (fButtons != 0) ClipToPicture(&fButtonsPicture, B_ORIGIN, false); for (int32 i = 0; i < fType; i++) { // draw mapping number centered over the button bool pressed = (fButtons & map.button[_ConvertFromVisualOrder(i)]) != 0; // is button currently pressed? if (pressed) { SetDrawingMode(B_OP_ALPHA); SetHighColor(kButtonPressedColor); FillRect(_ButtonRect(offset, i)); } BRect border(fScaling * (offset[i] + 1), fScaling * (kButtonTop + 5), fScaling * offset[i + 1] - 1, fScaling * (kButtonTop + kMouseDownHeight - 4)); if (i == 0) border.left += fScaling * 5; if (i == fType - 1) border.right -= fScaling * 4; char number[2] = {0}; number[0] = getMappingNumber(map.button[_ConvertFromVisualOrder(i)]) + '1'; SetDrawingMode(B_OP_OVER); SetHighColor(kButtonTextColor); DrawString(number, BPoint( border.left + (border.Width() - StringWidth(number)) / 2, border.top + fDigitBaseline + (border.IntegerHeight() - fDigitHeight) / 2)); } if (fButtons != 0) ClipToPicture(NULL); }