|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
com.threerings.media.MediaPanel
public class MediaPanel
Provides a useful extensible framework for rendering animated displays that use sprites and
animations. Sprites and animations can be added to this panel and they will automatically be
ticked and rendered (see addSprite(com.threerings.media.sprite.Sprite) and addAnimation(com.threerings.media.animation.Animation)).
To facilitate optimized sprite and animation rendering, the panel provides a dirty region manager which is used to only repaint dirtied regions on each frame. Derived classes can add dirty regions to the scene and/or augment the dirty regions created by moving sprites and changing animations.
Sprite and animation rendering is done in two layers: front and back. Callbacks are provided
to render behind the back layer (paintBehind(java.awt.Graphics2D, java.awt.Rectangle)), in between front and back (paintBetween(java.awt.Graphics2D, java.awt.Rectangle)) and in front of the front layer (paintInFront(java.awt.Graphics2D, java.awt.Rectangle)).
The animated panel automatically registers with the FrameManager to participate in
the frame tick. It only does so while it is a visible part of the UI hierarchy, so animations
and sprites are paused while the animated panel is hidden.
| Nested Class Summary | |
|---|---|
protected class |
MediaPanel.ActionSpriteHandler
Handles ActionSprite/HoverSprite/ArmingSprite manipulation. |
static interface |
MediaPanel.Obscurer
|
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
JComponent.AccessibleJComponent |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
protected MediaPanel.ActionSpriteHandler |
_actionHandler
The action sprite handler, or null for none. |
protected int |
_actionSpriteCount
The number of action/hover sprites being managed. |
protected AnimationManager |
_animmgr
Legacy reference to avoid breaking children in the wild. |
protected MetaMediaManager |
_metamgr
Handles most of our heavy lifting. |
protected ArrayList<MediaPanel.Obscurer> |
_obscurerList
Anyone registered as someone who might obscure the media panel (and thus require extra redrawing. |
protected RegionManager |
_remgr
Legacy reference to avoid breaking children in the wild. |
protected SpriteManager |
_spritemgr
Legacy reference to avoid breaking children in the wild. |
protected boolean |
_tickPaintPending
Used to correlate tick()s with paint()s. |
| Fields inherited from class javax.swing.JComponent |
|---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface com.threerings.media.MediaConstants |
|---|
ALL, BACK, FRONT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
MediaPanel(FrameManager framemgr)
Constructs a media panel. |
|
| Method Summary | |
|---|---|
void |
abortAnimation(Animation anim)
Aborts a currently running animation and removes it from this panel. |
void |
addAnimation(Animation anim)
Adds an animation to this panel. |
void |
addObscurer(MediaPanel.Obscurer obscurer)
Adds an element that could be obscuring the panel and thus requires extra redrawing. |
protected void |
addObscurerDirtyRegion(Rectangle region)
Adds the particular region as dirty. |
protected void |
addObscurerDirtyRegions(boolean changedOnly)
Add dirty regions for all our obscurers. |
void |
addSprite(Sprite sprite)
Adds a sprite to this panel. |
void |
clearAnimations()
Removes all animations from this panel. |
void |
clearSprites()
Removes all sprites from this panel. |
protected void |
clipToDirtyRegion(Graphics2D gfx,
Rectangle dirty)
This is called to clip the rendering output to the supplied dirty region. |
protected void |
constrainToBounds(Rectangle dirty)
Called by the main rendering code to constrain this dirty rectangle to the bounds of the media panel. |
protected MediaPanel.ActionSpriteHandler |
createActionSpriteHandler()
Creates the mouse listener that will handle action sprites and their variants. |
Graphics2D |
createGraphics()
Creates a graphics context for the component underlying this media host. |
protected void |
didTick(long tickStamp)
Derived classes can override this method and perform computation subsequent to the ticking of the sprite and animation managers. |
protected void |
dirtyScreenRect(Rectangle rect)
Called to mark the specified rectangle (in screen coordinates) as dirty. |
AnimationManager |
getAnimationManager()
Returns a reference to the animation manager used by this media panel. |
Component |
getComponent()
If a frame participant wishes also to be actively rendered every frame rather than use passive rendering (which for Swing, at least, is hijacked when using the frame manager such that we take care of repainting dirty Swing components every frame into our off-screen buffer), it can return a component here which will have Component.paint(java.awt.Graphics) called on it once per frame with a translated but
unclipped graphics object. |
RegionManager |
getRegionManager()
Returns a reference to the region manager used by this media panel. |
SpriteManager |
getSpriteManager()
Returns a reference to the sprite manager used by this media panel. |
long |
getTimeStamp()
Returns a timestamp from the MediaTimer used to track time intervals for this media
panel. |
Rectangle |
getViewBounds()
Get the bounds of the viewport, in media coordinates. |
boolean |
isManaged(Animation anim)
|
boolean |
isManaged(Sprite sprite)
|
boolean |
needsPaint()
Called immediately prior to FrameParticipant.getComponent() and then Component.paint(java.awt.Graphics) on said component, to determine whether or not
this frame participant needs to be painted. |
void |
paint(Graphics g)
|
protected void |
paint(Graphics2D gfx,
Rectangle[] dirty)
Performs the actual painting of the media panel. |
protected void |
paintBehind(Graphics2D gfx,
Rectangle dirtyRect)
Paints behind all sprites and animations. |
protected void |
paintBetween(Graphics2D gfx,
Rectangle dirtyRect)
Paints between the front and back layer of sprites and animations. |
protected void |
paintBits(Graphics2D gfx,
int layer,
Rectangle dirty)
Renders the sprites and animations that intersect the supplied dirty region in the specified layer. |
protected void |
paintDirtyRect(Graphics2D gfx,
Rectangle rect)
Paints all the layers of the specified dirty region. |
protected void |
paintInFront(Graphics2D gfx,
Rectangle dirtyRect)
Paints in front of all sprites and animations. |
void |
removeObscurer(MediaPanel.Obscurer obscurer)
Removes an obscuring element. |
void |
removeSprite(Sprite sprite)
Removes a sprite from this panel. |
void |
repaint(long tm,
int x,
int y,
int width,
int height)
|
void |
setOpaque(boolean opaque)
|
void |
setPaused(boolean paused)
Pauses the sprites and animations that are currently active on this media panel. |
void |
tick(long tickStamp)
This is called on all registered frame participants, one for every frame. |
protected void |
willTick(long tickStamp)
Derived classes can override this method and perform computation prior to the ticking of the sprite and animation managers. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected MetaMediaManager _metamgr
protected AnimationManager _animmgr
protected SpriteManager _spritemgr
protected RegionManager _remgr
protected boolean _tickPaintPending
protected MediaPanel.ActionSpriteHandler _actionHandler
protected int _actionSpriteCount
protected ArrayList<MediaPanel.Obscurer> _obscurerList
| Constructor Detail |
|---|
public MediaPanel(FrameManager framemgr)
| Method Detail |
|---|
public Rectangle getViewBounds()
public AnimationManager getAnimationManager()
public SpriteManager getSpriteManager()
public RegionManager getRegionManager()
public void setPaused(boolean paused)
public long getTimeStamp()
MediaTimer used to track time intervals for this media
panel. Note: this should only be called from the AWT thread.
public void addSprite(Sprite sprite)
public boolean isManaged(Sprite sprite)
public void removeSprite(Sprite sprite)
public void clearSprites()
public void addAnimation(Animation anim)
public boolean isManaged(Animation anim)
public void abortAnimation(Animation anim)
public void clearAnimations()
public Graphics2D createGraphics()
MediaHost
createGraphics in interface MediaHostpublic void tick(long tickStamp)
FrameParticipant
tick in interface FrameParticipantpublic boolean needsPaint()
FrameParticipantFrameParticipant.getComponent() and then Component.paint(java.awt.Graphics) on said component, to determine whether or not
this frame participant needs to be painted.
needsPaint in interface FrameParticipantpublic Component getComponent()
FrameParticipantComponent.paint(java.awt.Graphics) called on it once per frame with a translated but
unclipped graphics object.
Because clipping is expensive in terms of rectangle object allocation, frame participants are given the opportunity to do their own clipping because they are likely to want to clip to a more fine grained region than their entire bounds. If a participant does not wish to be actively rendered, it can safely return null.
getComponent in interface FrameParticipantpublic void setOpaque(boolean opaque)
setOpaque in class JComponent
public void repaint(long tm,
int x,
int y,
int width,
int height)
repaint in class JComponentpublic void paint(Graphics g)
paint in class JComponentpublic void addObscurer(MediaPanel.Obscurer obscurer)
public void removeObscurer(MediaPanel.Obscurer obscurer)
protected void addObscurerDirtyRegions(boolean changedOnly)
protected void addObscurerDirtyRegion(Rectangle region)
protected void willTick(long tickStamp)
protected void didTick(long tickStamp)
protected void paint(Graphics2D gfx,
Rectangle[] dirty)
protected void paintDirtyRect(Graphics2D gfx,
Rectangle rect)
protected void constrainToBounds(Rectangle dirty)
protected void clipToDirtyRegion(Graphics2D gfx,
Rectangle dirty)
Graphics.setClip(int, int, int, int) because the clipping region will need to be replaced as we iterate
through our dirty regions. By default, a region is assumed to represent screen coordinates,
but if a derived class wishes to maintain dirty regions in non-screen coordinates, it can
override this method to properly clip to the dirty region.
protected void dirtyScreenRect(Rectangle rect)
If derived classes wish to convert from screen coordinates to some virtual coordinate system to be used by their repaint manager, this is the place to do it.
protected void paintBehind(Graphics2D gfx,
Rectangle dirtyRect)
protected void paintBetween(Graphics2D gfx,
Rectangle dirtyRect)
protected void paintInFront(Graphics2D gfx,
Rectangle dirtyRect)
protected void paintBits(Graphics2D gfx,
int layer,
Rectangle dirty)
protected MediaPanel.ActionSpriteHandler createActionSpriteHandler()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||