round_rect_painter.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ui/views/round_rect_painter.h"
  5. #include "cc/paint/paint_canvas.h"
  6. #include "ui/gfx/canvas.h"
  7. #include "ui/gfx/geometry/skia_conversions.h"
  8. namespace views {
  9. RoundRectPainter::RoundRectPainter(SkColor border_color, int corner_radius)
  10. : border_color_(border_color), corner_radius_(corner_radius) {}
  11. RoundRectPainter::~RoundRectPainter() = default;
  12. gfx::Size RoundRectPainter::GetMinimumSize() const {
  13. return gfx::Size(1, 1);
  14. }
  15. void RoundRectPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) {
  16. cc::PaintFlags flags;
  17. flags.setColor(border_color_);
  18. flags.setStyle(cc::PaintFlags::kStroke_Style);
  19. flags.setStrokeWidth(kBorderWidth);
  20. flags.setAntiAlias(true);
  21. gfx::Rect rect(size);
  22. rect.Inset(gfx::Insets::TLBR(0, 0, kBorderWidth, kBorderWidth));
  23. SkRect skia_rect = gfx::RectToSkRect(rect);
  24. skia_rect.offset(kBorderWidth / 2.f, kBorderWidth / 2.f);
  25. canvas->sk_canvas()->drawRoundRect(skia_rect, SkIntToScalar(corner_radius_),
  26. SkIntToScalar(corner_radius_), flags);
  27. }
  28. } // namespace views