inner shadow for rounded rect with stroke

688 views
Skip to first unread message

Igor Khromov

unread,
Jun 18, 2016, 7:12:00 AM6/18/16
to skia-discuss
I'm trying to draw rounded rectangle with stroke and inner shadow (like input fields have), but no success.

Can anybody tell me how to do that? Or just describe the algorithm.

Example: (shadow has blur, outer pixels transparent)


Thanks for help!

Shawn Riordan

unread,
Jun 18, 2016, 10:56:17 AM6/18/16
to skia-discuss
There are probably better ways to do it, but here is my attempt at it:

https://fiddle.skia.org/c/0cac3426f37741a891787b989dad6415

Shawn Riordan

unread,
Jun 18, 2016, 11:08:37 AM6/18/16
to skia-discuss


On Saturday, June 18, 2016 at 4:12:00 AM UTC-7, Igor Khromov wrote:

Shawn Riordan

unread,
Jun 18, 2016, 2:41:27 PM6/18/16
to skia-discuss
Ok, final draft.  
https://fiddle.skia.org/c/0e07c3305b200068e9dffb2c1fafa7ef

(I need to find another hobby)


On Saturday, June 18, 2016 at 4:12:00 AM UTC-7, Igor Khromov wrote:

Igor Khromov

unread,
Jun 19, 2016, 11:23:39 AM6/19/16
to skia-discuss
Thanks a lot!!!

Just one more question, how canvas->save() and canvas->restore() works?
Can't find that in docs on skia.org.


суббота, 18 июня 2016 г., 21:41:27 UTC+3 пользователь Shawn Riordan написал:

Shawn Riordan

unread,
Jun 19, 2016, 12:17:47 PM6/19/16
to skia-discuss
The documentation on skia.org is mostly for demonstration.
The full documenation is on this site:
http://chromium-skia-gm.commondatastorage.googleapis.com/doxygen/doxygen/html/classSkCanvas.html#ac98147dc771b47c7353a51e7c171e428

The code in drawFieldBackground() applied a clip region and a change to the matrix (that call to transform()).
I wanted to be able to undo those changes, once I was done.  So I did a save() before I did them, then a restore() after I no longer wanted those changes.

You can read about them on that site I linked.

Igor Khromov

unread,
Jun 20, 2016, 5:05:56 AM6/20/16
to skia-discuss
Thanks for your time, I really appreciate your help!!!!

воскресенье, 19 июня 2016 г., 19:17:47 UTC+3 пользователь Shawn Riordan написал:
Reply all
Reply to author
Forward
0 new messages