From 28183b7575199f283a8ba14fda4a389961966d98 Mon Sep 17 00:00:00 2001 From: Henning Stahlke Date: Sat, 5 Jan 2019 16:43:20 +0100 Subject: [PATCH] canvas/api.nas add setClipByBoundinbox and setClipByElement function --- Nasal/canvas/api.nas | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Nasal/canvas/api.nas b/Nasal/canvas/api.nas index 6dcfc26b6..c941c4f08 100644 --- a/Nasal/canvas/api.nas +++ b/Nasal/canvas/api.nas @@ -282,6 +282,29 @@ var Element = { return center; }, + + # convert bounding box vector into clip string (yes, different order) + boundingbox2clip: func(bb) { + return sprintf("rect(%d,%d,%d,%d)", bb[1], bb[2], bb[3], bb[0]) + }, + + # set clip by bounding box + # bounding_box: [xmin, ymin, xmax, ymax] + setClipByBoundingBox: func(bounding_box, clip_frame = nil) { + if (clip_frame == nil) + clip_frame = Element.PARENT; + me.set("clip", boundingbox2clip(bounding_box)); + me.set("clip-frame", clip_frame); + return me; + }, + + # set clipping by bounding box of another element + setClipByElement: func(clip_elem) { + clip_elem.update(); + var bounds = clip_elem.getTightBoundingBox(); + me.setClipByBB(bounds, canvas.Element.PARENT); + }, + # Internal Transform for convenience transform functions _getTf: func {