net.tmachine.gpg.hue
Class ShapeShifter2

java.lang.Object
  extended bynet.tmachine.gpg.hue.BaseHUD
      extended bynet.tmachine.gpg.hue.ShapeShifter2
All Implemented Interfaces:
java.util.EventListener, HUD, java.awt.event.MouseListener, java.awt.event.MouseMotionListener

public class ShapeShifter2
extends BaseHUD

Simple HUD which displays a "your mouse cursor is currently floating over THIS shape" selection-box style thing, and includes a tool which will allow you to drag shapes around the document, even multiple shapes at once (if they overlap and can be dragged in a single gesture).

Not very user-friendly, but a basic example.

Note how it uses the ContextManager to find out the cursor position, and uses that to decide which shapes are currently under the cursor; this is instead of listening to all input events. It would be possible to split this HUD into it's rendering and tool components and have the input part ignoring the cursor position inside/outside shapes (using some abstracted concept of "selected shape" in the ContextManager) and have the display part not needing any information on input events, instead deriving cursor co-ords indirectly from the context, as it does now.


Field Summary
protected  int lastx
          Co-ords where a drag-translate was last updated (so we can work out how far to shift it)
protected  int lasty
          Co-ords where a drag-translate was last updated (so we can work out how far to shift it)
protected  java.util.ArrayList movingObjects
           
protected  int sx
          Co-ords where a drag-translate was started
protected  int sy
          Co-ords where a drag-translate was started
 
Fields inherited from class net.tmachine.gpg.hue.BaseHUD
isActive, isVisible, manager, name
 
Constructor Summary
ShapeShifter2()
           
 
Method Summary
 void mouseDragged(java.awt.event.MouseEvent e)
          Compares the mouse cursor position to it's last known position, and translates all "currently being moved" shapes by the same relative distance
 void mousePressed(java.awt.event.MouseEvent e)
          Finds all shapes under the mouse cursor, and flags them internally as being "currently being moved"
 void paint(java.awt.Graphics g)
          If this HUD is visible, it will be asked to paint to the supplied display surface during repaints
 
Methods inherited from class net.tmachine.gpg.hue.BaseHUD
getName, isActive, isActive, isVisible, isVisible, mouseClicked, mouseEntered, mouseExited, mouseMoved, mouseReleased, setManager, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

movingObjects

protected java.util.ArrayList movingObjects

sx

protected int sx
Co-ords where a drag-translate was started


sy

protected int sy
Co-ords where a drag-translate was started


lastx

protected int lastx
Co-ords where a drag-translate was last updated (so we can work out how far to shift it)


lasty

protected int lasty
Co-ords where a drag-translate was last updated (so we can work out how far to shift it)

Constructor Detail

ShapeShifter2

public ShapeShifter2()
Method Detail

paint

public void paint(java.awt.Graphics g)
Description copied from interface: HUD
If this HUD is visible, it will be asked to paint to the supplied display surface during repaints

Parameters:
g -

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Finds all shapes under the mouse cursor, and flags them internally as being "currently being moved"

A mouse press over an empty area will clear the "currently being moved" list

Specified by:
mousePressed in interface java.awt.event.MouseListener
Overrides:
mousePressed in class BaseHUD
See Also:
mouseDragged(MouseEvent)

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Compares the mouse cursor position to it's last known position, and translates all "currently being moved" shapes by the same relative distance

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Overrides:
mouseDragged in class BaseHUD
See Also:
mousePressed(MouseEvent)