Reading background color of a ICanvasContext with SCL 05/2205/2
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 19 Sep 2018 19:41:44 +0000 (22:41 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 21 Sep 2018 08:29:03 +0000 (11:29 +0300)
refs #127

Change-Id: I58fd39f4df42643a7aac7441a55c89b6f693cd8d

bundles/org.simantics.modeling/scl/Simantics/Scenegraph.scl
bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java

index 6a1ecd8fcb67cc33ac4607e4a8b05ec11daf521f..3d1170682a606f0db33b8cdbad6cc8575c3fb3f7 100644 (file)
@@ -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 -> <Proc> ICanvasSceneGraphProvider
     
index 7545106580b7ea0fa3eebeef97605f7e87605687..55ed12656131c0629595cd7ded70c4f4bd064234 100644 (file)
@@ -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<Integer> format, or null.
+     */
+    public static List<Integer> getBackgroundColor(ICanvasContext ctx) {
+       Color color = ctx.getDefaultHintContext().getHint(Hints.KEY_BACKGROUND_COLOR);
+       if (color == null)
+               return null;
+       ArrayList<Integer> 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) {