Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //
  // Nenya library - tools for developing networked games
  // Copyright (C) 2002-2012 Three Rings Design, Inc., All Rights Reserved
  // https://github.com/threerings/nenya
  //
  // This library is free software; you can redistribute it and/or modify it
  // under the terms of the GNU Lesser General Public License as published
  // by the Free Software Foundation; either version 2.1 of the License, or
  // (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Lesser General Public License for more details.
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 package com.threerings.chat;
 
 import java.awt.Color;
 import java.awt.Point;
 import java.awt.Shape;
 
 
 
 
 import static com.threerings.NenyaLog.log;

Responsible for rendering a "unit" of chat on a com.threerings.media.MediaPanel.
 
 public class ChatGlyph extends Animation
 {
    
Can be used by the Overlay to mark our position in the history.
 
     public int histIndex;

    
Construct a chat glyph.

Parameters:
owner the subtitle overlay that ownz us.
bounds the bounds of the glyph
shape the shape to draw/outline.
icon the Icon to draw inside the bubble, or null for none
iconpos the virtual coordinate at which to draw the icon (can be null if no icon)
label the Label to draw inside the bubble.
labelpos the virtual coordinate at which to draw the label
 
     public ChatGlyph (SubtitleChatOverlay ownerint typelong lifetimeRectangle bounds,
         Shape shapeIcon iconPoint iconposLabel labelPoint labelposColor outline)
     {
         super(bounds);
         jiggleBounds();
 
          = owner;
          = shape;
          = type;
          = icon;
          = iconpos;
          = label;
          = labelpos;
          = lifetime;
          = outline;
 
         if (..equals()) {
              = .;
         } else {
              = ColorUtil.blend(., .8f);
         }
     }

    
Sets whether or not this glyph is in dimmed mode.
 
     public void setDim (boolean dim)
     {
         if ( != dim) {
              = dim;
             invalidate();
         }
     }

    
Render the chat glyph with no thought to dirty rectangles or restoring composites.
    public void render (Graphics2D gfx)
    {
        Object oalias = SwingUtil.activateAntiAliasing(gfx);
        gfx.setColor(getBackground());
        gfx.fill();
        gfx.setColor();
        gfx.draw();
        SwingUtil.restoreAntiAliasing(gfxoalias);
        if ( != null) {
            .paintIcon(.getTarget(), gfx..);
        }
        gfx.setColor(.);
        .render(gfx..);
    }

    
Get the internal chat type of this bubble.
    public int getType ()
    {
        return ;
    }

    
Returns the shape of this chat bubble.
    public Shape getShape ()
    {
        return ;
    }
    @Override
    public void setLocation (int xint y)
    {
        // we'll need these so that we can translate our complex shapes
        int dx = x - .dy = y - .;
        super.setLocation(xy);
        if (dx != 0 || dy != 0) {
            // update our icon position, if any
            if ( != null) {
                .translate(dxdy);
            }
            // update our label position
            .translate(dxdy);
            if ( instanceof Area) {
                ((Area).transform(
                    AffineTransform.getTranslateInstance(dxdy));
            } else if ( instanceof Polygon) {
                ((Polygon).translate(dxdy);
            } else {
                .warning("Unable to translate shape""glyph"this"shape" + "]!");
            }
        }
    }

    
Called when the view has scrolled. The default implementation adjusts the glyph to remain in the same position relative to the view rather than allowing it to scroll with the view.
    public void viewDidScroll (int dxint dy)
    {
        translate(dxdy);
    }

    
Attempt to translate this glyph.
    public void translate (int dxint dy)
    {
        setLocation(. + dx. + dy);
    }
    @Override
    public void tick (long tickStamp)
    {
        // set up our born stamp if we've got one
        if ( == 0L) {
             = tickStamp;
            invalidate(); // make sure we're painted the first time
        }
        // if we're not yet ready to die, do nothing
        long deathTime =  + ;
        if (tickStamp < deathTime) {
            /* TEMPORARILY disabled blinking until we sort it out
            if (_type == SubtitleChatOverlay.ATTENTION) {
                float alphaWas = _alpha;
                long val = tickStamp - _bornStamp;
                if ((val < 3000) && (val % 1000 < 500)) {
                    _alpha = 0f;
                } else {
                    _alpha = ALPHA;
                }
                if (_alpha != alphaWas) {
                    invalidate();
                }
            }
            */
            return;
        }
        long msecs = tickStamp - deathTime;
        if (msecs >= ) {
             = 0f;
            // stick a fork in ourselves
             = true;
            .glyphExpired(this);
        } else {
             =  * ( - msecs) / ;
        }
        invalidate();
    }
    @Override
    public void fastForward (long timeDelta)
    {
        if ( > 0L) {
             += timeDelta;
        }
    }
    @Override
    public void paint (Graphics2D gfx)
    {
        float alpha =  ?  / 3 : ;
        if (alpha == 0f) {
            return;
        }
        if (alpha != 1f) {
            Composite ocomp = gfx.getComposite();
            gfx.setComposite(AlphaComposite.getInstance(.alpha));
            render(gfx);
            gfx.setComposite(ocomp);
        } else {
            render(gfx);
        }
    }
    protected Color getBackground ()
    {
        return ;
    }

    
The damn repaint manager expects 1 more pixel than the shape gives, so we manually resize.
    protected void jiggleBounds ()
    {
        .setSize(. + 1, . + 1);
    }

    
The subtitle chat overlay that ownz us.
    protected SubtitleChatOverlay _owner;

    
The type of chat represented by this glyph.
    protected int _type;

    
The shape of this glyph.
    protected Shape _shape;

    
The visual icon, or null for none.
    protected Icon _icon;

    
The position at which we render our icon.
    protected Point _ipos;

    
The textual label.
    protected Label _label;

    
The position at which we render our text.
    protected Point _lpos;

    
The alpha level that we'll render at when fading out.
    protected float _alpha = ;

    
Whether we're in dimmed mode.
    protected boolean _dim = false;

    
The length of the fade animation.
    protected static final long ANIM_TIME = 800L;

    
The number of milliseconds to wait before this bubble will expire and should begin to fade out.
    protected long _lifetime;

    
The time at which we came into being on the screen.
    protected long _bornStamp;

    
Our outline color.
    protected Color _outline;

    
Our background color.
    protected Color _background;

    
The initial alpha of all chat glyphs.
    protected static final float ALPHA = .9f;
New to GrepCode? Check out our FAQ X