Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 1 | // Copyright 2019 Google LLC. |
| 2 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
| 3 | #include "fiddle/examples.h" |
| 4 | // HASH=bb1dbfdca3aedf716beb6f07e2aab065 |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(State_Stack_a, 256, 160, false, 0) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 6 | void draw(SkCanvas* canvas) { |
| 7 | SkPaint paint; |
| 8 | canvas->save(); // records stack depth to restore |
| 9 | canvas->clipRect(SkRect::MakeWH(100, 100)); // constrains drawing to clip |
| 10 | canvas->clear(SK_ColorRED); // draws to limit of clip |
| 11 | canvas->save(); // records stack depth to restore |
| 12 | canvas->clipRect(SkRect::MakeWH(50, 150)); // Rect below 100 is ignored |
| 13 | canvas->clear(SK_ColorBLUE); // draws to smaller clip |
| 14 | canvas->restore(); // enlarges clip |
| 15 | canvas->drawLine(20, 20, 150, 150, paint); // line below 100 is not drawn |
| 16 | canvas->restore(); // enlarges clip |
| 17 | canvas->drawLine(150, 20, 50, 120, paint); // line below 100 is drawn |
| 18 | } |
| 19 | } // END FIDDLE |