From 6223edf13f7d35e18c45e35343c0347fb0159b2b Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Wed, 19 Sep 2018 22:41:44 +0300 Subject: [PATCH] Reading background color of a ICanvasContext with SCL refs #127 Change-Id: I58fd39f4df42643a7aac7441a55c89b6f693cd8d --- .../scl/Simantics/Scenegraph.scl | 2 ++ .../org/simantics/modeling/SCLScenegraph.java | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/bundles/org.simantics.modeling/scl/Simantics/Scenegraph.scl b/bundles/org.simantics.modeling/scl/Simantics/Scenegraph.scl index 6a1ecd8fc..3d1170682 100644 --- a/bundles/org.simantics.modeling/scl/Simantics/Scenegraph.scl +++ b/bundles/org.simantics.modeling/scl/Simantics/Scenegraph.scl @@ -44,6 +44,8 @@ importJava "org.simantics.modeling.SCLScenegraph" where @JavaName getNodeTransform getTransform :: ICanvasContext -> String -> String + getBackgroundColor :: ICanvasContext -> Maybe [Integer] + @Deprecated getICanvasSceneGraphProvider :: Model -> Resource -> String -> ICanvasSceneGraphProvider diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java index 754510658..55ed12656 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java @@ -1,6 +1,7 @@ package org.simantics.modeling; import java.awt.BasicStroke; +import java.awt.Color; import java.awt.Dimension; import java.awt.RenderingHints; import java.awt.RenderingHints.Key; @@ -45,6 +46,7 @@ import org.simantics.diagram.elements.DiagramNodeUtil; import org.simantics.diagram.elements.TextGridNode; import org.simantics.diagram.elements.TextNode; import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.g2d.canvas.Hints; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.diagram.DiagramHints; import org.simantics.g2d.diagram.IDiagram; @@ -276,6 +278,23 @@ public class SCLScenegraph { } return "No nodes in scenegraph!"; } + + /** + * Returns background color of a canvasContext or null. + * @param ctx + * @return color in RGBA List format, or null. + */ + public static List getBackgroundColor(ICanvasContext ctx) { + Color color = ctx.getDefaultHintContext().getHint(Hints.KEY_BACKGROUND_COLOR); + if (color == null) + return null; + ArrayList rgba = new ArrayList<>(4); + rgba.add(color.getRed()); + rgba.add(color.getGreen()); + rgba.add(color.getBlue()); + rgba.add(color.getAlpha()); + return rgba; + } public static String sceneGraphTest (ICanvasContext ctx, String module, String value) { -- 2.47.1