shadows.dart 975 Bytes
Newer Older
1 2 3 4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'dart:ui' as ui;
6

7
/// A helper class to build a [ui.DrawLooper] for drawing shadows
8
class ShadowDrawLooperBuilder {
Hixie's avatar
Hixie committed
9
  ui.LayerDrawLooperBuilder _builder = new ui.LayerDrawLooperBuilder();
10

Florian Loitsch's avatar
Florian Loitsch committed
11
  /// Adds a shadow with the given parameters.
12
  void addShadow(ui.Offset offset, ui.Color color, double blur) {
Hixie's avatar
Hixie committed
13 14 15 16 17 18 19 20 21
    _builder.addLayerOnTop(
      new ui.DrawLooperLayerInfo()
        ..setPaintBits(ui.PaintBits.all)
        ..setOffset(offset)
        ..setColorMode(ui.TransferMode.src),
      new ui.Paint()
        ..color = color
        ..maskFilter = new ui.MaskFilter.blur(ui.BlurStyle.normal, blur)
    );
22 23
  }

24
  /// Returns the draw looper built for the added shadows
25
  ui.DrawLooper build() {
Hixie's avatar
Hixie committed
26 27
    _builder.addLayerOnTop(new ui.DrawLooperLayerInfo(), new ui.Paint());
    return _builder.build();
28 29
  }
}