From: Marko Luukkainen Date: Wed, 19 Sep 2018 19:41:44 +0000 (+0300) Subject: Reading background color of a ICanvasContext with SCL X-Git-Tag: v1.43.0~136^2~364^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F05%2F2205%2F2;p=simantics%2Fplatform.git Reading background color of a ICanvasContext with SCL refs #127 Change-Id: I58fd39f4df42643a7aac7441a55c89b6f693cd8d --- 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) {