]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/participant/HandPainter.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / participant / HandPainter.java
diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/HandPainter.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/HandPainter.java
new file mode 100644 (file)
index 0000000..95b9dde
--- /dev/null
@@ -0,0 +1,74 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.g2d.participant;\r
+\r
+import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;\r
+import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent;\r
+import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonEvent;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;\r
+\r
+/**\r
+ * Paints a grabbed hand when canvas is grabbed.\r
+ * \r
+ * TODO: out of order for now, needs to be adapted to scene graph\r
+ * \r
+ * @author Toni Kalajainen\r
+ */\r
+public class HandPainter extends AbstractCanvasParticipant {\r
+\r
+    @Dependency CanvasGrab grab;\r
+    @Dependency SymbolUtil symbols;\r
+    @Dependency TransformUtil util;\r
+    @Dependency MouseUtil mice;\r
+\r
+//    @Painter(priority=PointerPainter.CURSOR_PAINT_PRIORITY+10)\r
+//    public void paint(GraphicsContext gc) {\r
+//        assertDependencies();\r
+//        Map<Integer, PointerInfo> pis = grab.getGrabInfo();\r
+//        Collection<MouseInfo> mis = mice.getMiceInfo().values();\r
+//        if (mis.isEmpty()) return;\r
+//\r
+//        // Symbol\r
+//        Image grab = symbols.get(DefaultImages.GRAB32, gc.getGraphics2D().getDeviceConfiguration());\r
+//        double gcx = grab.getBounds().getCenterX();\r
+//        double gcy = grab.getBounds().getCenterY();\r
+//        Image hand = symbols.get(DefaultImages.HAND32, gc.getGraphics2D().getDeviceConfiguration());\r
+//        double hcx = hand.getBounds().getCenterX();\r
+//        double hcy = hand.getBounds().getCenterY();\r
+//\r
+//        for (MouseInfo mi : mis) {\r
+//            GraphicsContext g = gc.clone();\r
+//            PointerInfo pi = pis.get(mi.mouseId);\r
+//            if (pi!=null) {\r
+//                Point2D pos = util.canvasToControl(pi.anchorPos, null);\r
+//                g.getGraphics2D().translate(pos.getX(), pos.getY());\r
+//                g.getGraphics2D().translate(-gcx, -gcy);\r
+//                grab.paint(g);\r
+//            } else {\r
+//                Point2D pos = mi.controlPosition;\r
+//                g.getGraphics2D().translate(pos.getX(), pos.getY());\r
+//                g.getGraphics2D().translate(-gcx, -gcy);\r
+//                hand.paint(g);\r
+//            }\r
+//            g.dispose();\r
+//        }\r
+//    }\r
+\r
+    @EventHandler(priority = Integer.MAX_VALUE)\r
+    public boolean handleMouseEvent(MouseEvent e) {\r
+        if (e instanceof MouseMovedEvent || e instanceof MouseButtonEvent)\r
+            setDirty();\r
+        return false;\r
+    }\r
+}\r