]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g2d.participant;\r
13 \r
14 import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;\r
15 import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;\r
16 import org.simantics.scenegraph.g2d.events.MouseEvent;\r
17 import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;\r
18 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonEvent;\r
19 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;\r
20 \r
21 /**\r
22  * Paints a grabbed hand when canvas is grabbed.\r
23  * \r
24  * TODO: out of order for now, needs to be adapted to scene graph\r
25  * \r
26  * @author Toni Kalajainen\r
27  */\r
28 public class HandPainter extends AbstractCanvasParticipant {\r
29 \r
30     @Dependency CanvasGrab grab;\r
31     @Dependency SymbolUtil symbols;\r
32     @Dependency TransformUtil util;\r
33     @Dependency MouseUtil mice;\r
34 \r
35 //    @Painter(priority=PointerPainter.CURSOR_PAINT_PRIORITY+10)\r
36 //    public void paint(GraphicsContext gc) {\r
37 //        assertDependencies();\r
38 //        Map<Integer, PointerInfo> pis = grab.getGrabInfo();\r
39 //        Collection<MouseInfo> mis = mice.getMiceInfo().values();\r
40 //        if (mis.isEmpty()) return;\r
41 //\r
42 //        // Symbol\r
43 //        Image grab = symbols.get(DefaultImages.GRAB32, gc.getGraphics2D().getDeviceConfiguration());\r
44 //        double gcx = grab.getBounds().getCenterX();\r
45 //        double gcy = grab.getBounds().getCenterY();\r
46 //        Image hand = symbols.get(DefaultImages.HAND32, gc.getGraphics2D().getDeviceConfiguration());\r
47 //        double hcx = hand.getBounds().getCenterX();\r
48 //        double hcy = hand.getBounds().getCenterY();\r
49 //\r
50 //        for (MouseInfo mi : mis) {\r
51 //            GraphicsContext g = gc.clone();\r
52 //            PointerInfo pi = pis.get(mi.mouseId);\r
53 //            if (pi!=null) {\r
54 //                Point2D pos = util.canvasToControl(pi.anchorPos, null);\r
55 //                g.getGraphics2D().translate(pos.getX(), pos.getY());\r
56 //                g.getGraphics2D().translate(-gcx, -gcy);\r
57 //                grab.paint(g);\r
58 //            } else {\r
59 //                Point2D pos = mi.controlPosition;\r
60 //                g.getGraphics2D().translate(pos.getX(), pos.getY());\r
61 //                g.getGraphics2D().translate(-gcx, -gcy);\r
62 //                hand.paint(g);\r
63 //            }\r
64 //            g.dispose();\r
65 //        }\r
66 //    }\r
67 \r
68     @EventHandler(priority = Integer.MAX_VALUE)\r
69     public boolean handleMouseEvent(MouseEvent e) {\r
70         if (e instanceof MouseMovedEvent || e instanceof MouseButtonEvent)\r
71             setDirty();\r
72         return false;\r
73     }\r
74 }\r