Various easy changes suggested by Ray.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3220 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2004-11-18 20:01:00 +00:00
parent ebe7a65305
commit 84b6bf5468
9 changed files with 87 additions and 113 deletions
@@ -1,5 +1,5 @@
//
// $Id: ButtonSprite.java,v 1.4 2004/11/09 03:24:50 andrzej Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -276,52 +276,72 @@ public class ButtonSprite extends Sprite
switch (_style) {
case NORMAL:
gfx.setColor(_enabled ? _backgroundColor : _backgroundColor.darker());
gfx.setColor(_enabled ? _backgroundColor :
_backgroundColor.darker());
gfx.fill3DRect(_bounds.x, _bounds.y, _bounds.width,
_bounds.height, !_pressed);
_label.render(gfx, _bounds.x + (_pressed ? PADDING : PADDING - 1),
_bounds.y + (_pressed ? PADDING : PADDING - 1));
_label.render(gfx, _bounds.x + (_pressed ? PADDING :
PADDING - 1), _bounds.y + (_pressed ? PADDING :
PADDING - 1));
break;
case ROUNDED:
Object aaState = SwingUtil.activateAntiAliasing(gfx);
// draw outline
gfx.setColor(_alternateColor);
gfx.fillRoundRect(_bounds.x, _bounds.y, _bounds.width, _bounds.height,
_arcWidth, _arcHeight);
gfx.fillRoundRect(_bounds.x, _bounds.y, _bounds.width,
_bounds.height, _arcWidth, _arcHeight);
// draw foreground
gfx.setColor(_enabled ? _backgroundColor : _backgroundColor.darker());
gfx.setColor(_enabled ? _backgroundColor :
_backgroundColor.darker());
int innerBoundsX = _bounds.x+1, innerBoundsY = _bounds.y+1,
innerBoundsWidth = _bounds.width-2, innerBoundsHeight = _bounds.height-2,
innerBoundsArcWidth = _arcWidth-2, innerBoundsArcHeight = _arcHeight-2;
gfx.fillRoundRect(innerBoundsX, innerBoundsY, innerBoundsWidth, innerBoundsHeight,
innerBoundsWidth = _bounds.width-2,
innerBoundsHeight = _bounds.height-2,
innerBoundsArcWidth = _arcWidth-2,
innerBoundsArcHeight = _arcHeight-2;
gfx.fillRoundRect(innerBoundsX, innerBoundsY,
innerBoundsWidth, innerBoundsHeight,
innerBoundsArcWidth, innerBoundsArcHeight);
Color brighter = _enabled ? _backgroundColor.brighter() : _backgroundColor,
darker = _enabled ? _backgroundColor.darker() : _backgroundColor.darker().darker();
Color brighter = _enabled ? _backgroundColor.brighter() :
_backgroundColor, darker = _enabled ?
_backgroundColor.darker() :
_backgroundColor.darker().darker();
// draw the upper left/lower right corners (always dark)
gfx.setColor(darker);
gfx.drawArc(innerBoundsX, innerBoundsY, innerBoundsArcWidth, innerBoundsArcHeight, 90, 90);
gfx.drawArc(innerBoundsX + innerBoundsWidth - innerBoundsArcWidth - 1,
innerBoundsY + innerBoundsHeight - innerBoundsArcHeight - 1,
gfx.drawArc(innerBoundsX, innerBoundsY, innerBoundsArcWidth,
innerBoundsArcHeight, 90, 90);
gfx.drawArc(innerBoundsX + innerBoundsWidth -
innerBoundsArcWidth - 1,
innerBoundsY + innerBoundsHeight -
innerBoundsArcHeight - 1,
innerBoundsArcWidth, innerBoundsArcHeight, 270, 90);
// draw the upper right (dark when pressed)
gfx.setColor(_pressed ? darker : brighter);
gfx.drawLine(innerBoundsX + innerBoundsArcWidth/2, innerBoundsY,
innerBoundsX + innerBoundsWidth - innerBoundsArcWidth/2, innerBoundsY);
gfx.drawArc(innerBoundsX + innerBoundsWidth - innerBoundsArcWidth - 1, innerBoundsY,
gfx.drawLine(innerBoundsX + innerBoundsArcWidth/2,
innerBoundsY, innerBoundsX + innerBoundsWidth -
innerBoundsArcWidth/2, innerBoundsY);
gfx.drawArc(innerBoundsX + innerBoundsWidth -
innerBoundsArcWidth - 1, innerBoundsY,
innerBoundsArcWidth, innerBoundsArcHeight, 0, 90);
gfx.drawLine(innerBoundsX + innerBoundsWidth - 1, innerBoundsY + innerBoundsArcHeight/2,
innerBoundsX + innerBoundsWidth - 1, innerBoundsY + innerBoundsHeight - innerBoundsArcHeight/2);
gfx.drawLine(innerBoundsX + innerBoundsWidth - 1,
innerBoundsY + innerBoundsArcHeight/2,
innerBoundsX + innerBoundsWidth - 1, innerBoundsY +
innerBoundsHeight - innerBoundsArcHeight/2);
// draw the lower left (light when pressed)
gfx.setColor(_pressed ? brighter : darker);
gfx.drawLine(innerBoundsX, innerBoundsY + innerBoundsArcHeight/2, innerBoundsX,
innerBoundsY + innerBoundsHeight - innerBoundsArcHeight/2);
gfx.drawArc(innerBoundsX, innerBoundsY + innerBoundsHeight - innerBoundsArcHeight - 1,
gfx.drawLine(innerBoundsX, innerBoundsY +
innerBoundsArcHeight/2, innerBoundsX,
innerBoundsY + innerBoundsHeight -
innerBoundsArcHeight/2);
gfx.drawArc(innerBoundsX, innerBoundsY + innerBoundsHeight -
innerBoundsArcHeight - 1,
innerBoundsArcWidth, innerBoundsArcHeight, 180, 90);
gfx.drawLine(innerBoundsX + innerBoundsArcWidth/2, innerBoundsY + innerBoundsHeight - 1,
gfx.drawLine(innerBoundsX + innerBoundsArcWidth/2,
innerBoundsY + innerBoundsHeight - 1,
innerBoundsX + innerBoundsWidth - innerBoundsArcWidth/2,
innerBoundsY + innerBoundsHeight - 1);
SwingUtil.restoreAntiAliasing(gfx, aaState);
_label.render(gfx, _bounds.x + PADDING + _arcWidth/2 - (_pressed ? 2 : 1),
_label.render(gfx, _bounds.x + PADDING + _arcWidth/2 -
(_pressed ? 2 : 1),
_bounds.y + PADDING + (_pressed ? 1 : 0));
break;
}
@@ -1,38 +0,0 @@
//
// $Id: ButtonSpriteObserver.java,v 1.1 2004/10/29 00:41:50 andrzej Exp $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// 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.parlor.card.client;
import com.samskivert.swing.event.CommandEvent;
/**
* Observer interface for button sprites.
*/
public interface ButtonSpriteObserver
{
/**
* Notifies the observer that the user clicked a button sprite.
*
* @param sprite the clicked sprite
* @param ce the command event associated with the click
*/
public void buttonSpriteClicked (ButtonSprite sprite, CommandEvent ce);
}
@@ -1,5 +1,5 @@
//
// $Id: CardPanel.java,v 1.8 2004/11/04 02:03:47 andrzej Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -55,7 +55,8 @@ public abstract class CardPanel extends VirtualMediaPanel
implements CardCodes
{
/** Calls CardSpriteObserver.cardSpriteClicked. */
protected static class CardSpriteClickedOp implements ObserverList.ObserverOp
protected static class CardSpriteClickedOp implements
ObserverList.ObserverOp
{
public CardSpriteClickedOp (CardSprite sprite, MouseEvent me)
{
@@ -65,7 +66,8 @@ public abstract class CardPanel extends VirtualMediaPanel
public boolean apply (Object observer)
{
((CardSpriteObserver)observer).cardSpriteClicked(_sprite, _me);
((CardSpriteObserver)observer).cardSpriteClicked(_sprite,
_me);
return true;
}
@@ -74,7 +76,8 @@ public abstract class CardPanel extends VirtualMediaPanel
}
/** Calls CardSpriteObserver.cardSpriteEntered. */
protected static class CardSpriteEnteredOp implements ObserverList.ObserverOp
protected static class CardSpriteEnteredOp implements
ObserverList.ObserverOp
{
public CardSpriteEnteredOp (CardSprite sprite, MouseEvent me)
{
@@ -93,7 +96,8 @@ public abstract class CardPanel extends VirtualMediaPanel
}
/** Calls CardSpriteObserver.cardSpriteExited. */
protected static class CardSpriteExitedOp implements ObserverList.ObserverOp
protected static class CardSpriteExitedOp implements
ObserverList.ObserverOp
{
public CardSpriteExitedOp (CardSprite sprite, MouseEvent me)
{
@@ -112,7 +116,8 @@ public abstract class CardPanel extends VirtualMediaPanel
}
/** Calls CardSpriteObserver.cardSpriteDragged. */
protected static class CardSpriteDraggedOp implements ObserverList.ObserverOp
protected static class CardSpriteDraggedOp implements
ObserverList.ObserverOp
{
public CardSpriteDraggedOp (CardSprite sprite, MouseEvent me)
{
@@ -130,25 +135,6 @@ public abstract class CardPanel extends VirtualMediaPanel
protected MouseEvent _me;
}
/** Calls ButtonSpriteObserver.buttonSpriteClicked. */
protected static class ButtonSpriteClickedOp implements ObserverList.ObserverOp
{
public ButtonSpriteClickedOp (ButtonSprite sprite, CommandEvent ce)
{
_sprite = sprite;
_ce = ce;
}
public boolean apply (Object observer)
{
((ButtonSpriteObserver)observer).buttonSpriteClicked(_sprite, _ce);
return true;
}
protected ButtonSprite _sprite;
protected CommandEvent _ce;
}
/**
* Constructor.
*
@@ -177,17 +163,17 @@ public abstract class CardPanel extends VirtualMediaPanel
public void mouseReleased (MouseEvent me) {
if (_activeSprite != null && !isManaged(_activeSprite)) {
_activeSprite = null;
} else if (_activeSprite instanceof CardSprite && _hasBeenDragged) {
} else if (_activeSprite instanceof CardSprite &&
_hasBeenDragged) {
_activeSprite.queueNotification(
new CardSpriteDraggedOp((CardSprite)_activeSprite, me)
);
} else if (_activeSprite instanceof ButtonSprite) {
ButtonSprite bs = (ButtonSprite)_activeSprite;
if (bs.isPressed()) {
CommandEvent ce = new CommandEvent(CardPanel.this, bs.getActionCommand(),
bs.getCommandArgument(), me.getWhen(), me.getModifiers());
bs.queueNotification(
new ButtonSpriteClickedOp(bs, ce));
CommandEvent ce = new CommandEvent(CardPanel.this,
bs.getActionCommand(), bs.getCommandArgument(),
me.getWhen(), me.getModifiers());
Controller.postAction(ce);
bs.setPressed(false);
}
@@ -236,7 +222,8 @@ public abstract class CardPanel extends VirtualMediaPanel
if (_activeSprite instanceof CardSprite &&
isManaged(_activeSprite)) {
_activeSprite.queueNotification(
new CardSpriteExitedOp((CardSprite)_activeSprite, me)
new CardSpriteExitedOp((CardSprite)_activeSprite,
me)
);
} else if (_activeSprite instanceof ButtonSprite &&
isManaged(_activeSprite)) {
@@ -244,7 +231,8 @@ public abstract class CardPanel extends VirtualMediaPanel
}
if (newActiveSprite instanceof CardSprite) {
newActiveSprite.queueNotification(
new CardSpriteEnteredOp((CardSprite)newActiveSprite, me)
new CardSpriteEnteredOp(
(CardSprite)newActiveSprite, me)
);
}
_activeSprite = newActiveSprite;
@@ -1,5 +1,5 @@
//
// $Id: CardSprite.java,v 1.2 2004/10/15 00:14:23 andrzej Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -132,10 +132,10 @@ public class CardSprite extends OrientableImageSprite
*/
private void updateMirage ()
{
setMirage(_facingUp ? _panel.getCardImage(_card) : _panel.getCardBackImage());
setMirage(_facingUp ? _panel.getCardImage(_card) :
_panel.getCardBackImage());
}
/** The panel responsible for the sprite. */
protected CardPanel _panel;
@@ -1,5 +1,5 @@
//
// $Id: Card.java,v 1.7 2004/11/01 22:10:21 andrzej Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -108,8 +108,8 @@ public class Card implements DSet.Entry, Comparable, CardCodes
}
/**
* Checks whether or not this card is valid. The no-arg public constructor
* for deserialization creates an invalid card.
* Checks whether or not this card is valid. The no-arg public
* constructor for deserialization creates an invalid card.
*
* @return true if this card is valid, false if not
*/
@@ -1,5 +1,5 @@
//
// $Id: Deck.java,v 1.6 2004/11/01 22:10:21 andrzej Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -107,9 +107,9 @@ public class Deck implements CardCodes,
else {
Hand hand = new Hand();
int cardsLeft = cards.size();
for (int i=0;i<size;i++) {
hand.cards.add(cards.get(cards.size()-1));
cards.remove(cards.size()-1);
hand.cards.add(cards.remove(--cardsLeft));
}
return hand;
@@ -1,5 +1,5 @@
//
// $Id: CardGameManager.java,v 1.5 2004/10/15 18:20:28 andrzej Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -32,8 +32,8 @@ import com.threerings.parlor.game.GameManager;
import com.threerings.presents.dobj.MessageEvent;
/**
* A manager class for card games. Handles common functions like dealing hands
* of cards to all players.
* A manager class for card games. Handles common functions like dealing
* hands of cards to all players.
*/
public class CardGameManager extends GameManager
implements CardCodes
@@ -1,5 +1,5 @@
//
// $Id: TrickCardGameControllerDelegate.java,v 1.4 2004/10/15 18:20:28 andrzej Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -29,14 +29,16 @@ import com.threerings.presents.dobj.AttributeChangedEvent;
* A card game controller delegate for trick-based card games, such as
* Spades and Hearts.
*/
public class TrickCardGameControllerDelegate extends TurnGameControllerDelegate
public class TrickCardGameControllerDelegate
extends TurnGameControllerDelegate
{
/**
* Constructor.
*
* @param controller the game controller
*/
public TrickCardGameControllerDelegate (TrickCardGameController controller)
public TrickCardGameControllerDelegate (TrickCardGameController
controller)
{
super(controller);
@@ -1,5 +1,5 @@
//
// $Id: TrickCardGameManagerDelegate.java,v 1.4 2004/10/15 18:20:28 andrzej Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -48,7 +48,8 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
// Documentation inherited.
public void setFirstTurnHolder ()
{
if (_trickCardGame.getPlayingHand() && _trickCardGame.getPlayingTrick()) {
if (_trickCardGame.getPlayingHand() &&
_trickCardGame.getPlayingTrick()) {
super.setFirstTurnHolder();
}
else {
@@ -59,7 +60,8 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
// Documentation inherited.
public void setNextTurnHolder ()
{
if (_trickCardGame.getPlayingHand() && _trickCardGame.getPlayingTrick()) {
if (_trickCardGame.getPlayingHand() &&
_trickCardGame.getPlayingTrick()) {
super.setNextTurnHolder();
}
else {