X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scenegraph%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fg2d%2FIG2DNode.java;fp=bundles%2Forg.simantics.scenegraph%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fg2d%2FIG2DNode.java;h=4e816c04189c8150fd0baa7fd299bad7de6dbddc;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/IG2DNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/IG2DNode.java new file mode 100644 index 000000000..4e816c041 --- /dev/null +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/IG2DNode.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.scenegraph.g2d; + +import java.awt.Composite; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +import org.simantics.scenegraph.INode; +import org.simantics.scenegraph.g2d.events.IEventHandler; + +/** + * + * + * @author Tuukka Lehtonen + */ +public interface IG2DNode extends INode, IEventHandler { + + /** + * Set the z-index, i.e. the rendering order number for this 2D node. + * 2D nodes are sorted in ascending z-order for rendering. + * + * @param z + */ + @SyncField("z") + public void setZIndex(int z); + + /** + * @return the rendering order of this 2D node. + */ + public int getZIndex(); + + /** + * @return false if this node will not render anything if + * {@link #render(Graphics2D)} was invoked. Serves as a means to + * optimize rendering. Should always return true by + * default. + */ + public boolean validate(); + + /** + * Perform the actual rendering. Node state changes should be avoided in + * this method. This method should not change the transform of the g2d + * instance. You should call g2d.create or copy the original transform and + * put it back at the end of this method according to what is specified in + * {@link Graphics2D#setTransform(AffineTransform)}. + * + * This method is always invoked so that the local transform of this + * {@link IG2DNode} has not been applied to the Graphics2D rendering + * context. It is this node's responsibility to apply its own transform + * during rendering if necessary. + * + * The method must also make sure that it returns the {@link Composite} of + * g2d to its original state using (see {@link Graphics2D#setComposite(Composite)). + * + * @param g2d + * + * @see #setTransform(AffineTransform) + * @see #getTransform() + */ + public void render(Graphics2D g2d); + + /** + * Mark the scene graph to be repainted in its current rendering context (UI + * component) as soon as is appropriate for the backend system. + */ + public void repaint(); + + // Bounds and transformation + + /** + * @return affine transformation set for this node to transform it into its + * parent's coordinate space + */ + public AffineTransform getTransform(); + + /** + * Set an affine transformation for this node that transforms its local + * coordinates into its parent's coordinate space + * + * @param transform local → parent transform + */ + public void setTransform(AffineTransform transform); + + /** + * Return bounds transformed with local transformation + * + * @return transformed bounds + */ + public Rectangle2D getBounds(); + + /** + * Return bounds in local coordinates. May expose internal state of the + * node. The client is not allowed to modify the returned value. + * + * @return bounds + */ + public Rectangle2D getBoundsInLocal(); + + public Rectangle2D getBoundsInLocal(boolean ignoreNulls); + + // Helper methods for bounds checking + + public boolean contains(Point2D point); + + public boolean intersects(Rectangle2D rect); + + public Point2D localToParent(Point2D point); + + public Rectangle2D localToParent(Rectangle2D rect); + + public Point2D parentToLocal(Point2D point); + + public Rectangle2D parentToLocal(Rectangle2D rect); + + public Point2D localToControl(Point2D point); + + public Rectangle2D localToControl(Rectangle2D rect); + + public Point2D controlToLocal(Point2D point); + + public Rectangle2D controlToLocal(Rectangle2D rect); + + /** + * @return root node of the 2D scene graph or null if this node is + * not part of a properly rooted scene graph hierarchy + */ + public G2DSceneGraph getRootNode2D(); + + /** + * @return true if this node has focus in the owner scene graph + */ + public boolean hasFocus(); + + /** + * @return the node that has focus in the owner scene graph + */ + public IG2DNode getFocusNode(); + + /** + * @param node the node to have focus in the owner scene graph. The + * specified node must be a part of the same scene graph. + */ + public void setFocusNode(IG2DNode node); + +}