View Javadoc
1 package org.argosfields.battlefield; 2 3 import org.argosfields.image.ImageSet; 4 import org.argosfields.image.TileImageSet; 5 import org.argosfields.model.IMobile; 6 import org.argosfields.model.Unit; 7 import org.eclipse.swt.events.KeyEvent; 8 import org.eclipse.swt.events.MouseEvent; 9 import org.eclipse.swt.events.PaintEvent; 10 import org.eclipse.swt.graphics.Image; 11 import org.eclipse.swt.graphics.Rectangle; 12 13 /*** 14 * DefaultState.java 15 * 16 * @author Xavier Cho 17 * @version $Revision: 1.5 $ $Date: 2003/12/01 07:38:05 $ 18 */ 19 public class DefaultState extends State { 20 private BattleFieldView battleFieldView; 21 22 /*** 23 * @param context 24 */ 25 public DefaultState(final Context context) { 26 super(context); 27 28 this.battleFieldView = context.getBattleFieldView(); 29 battleFieldView.redraw(); 30 } 31 32 /*** 33 * @see org.argosfields.widget.state.State#getName() 34 */ 35 public String getName() { 36 return "Default"; 37 } 38 39 /*** 40 * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent) 41 */ 42 public void mouseDoubleClick(final MouseEvent event) { 43 Unit unit = battleFieldView.getSelectedUnit(); 44 45 if (unit instanceof IMobile) { 46 int index = battleFieldView.getSelectedIndex(); 47 48 Context context = getContext(); 49 context.setCurrentState(new SelectDestinationState(index, context)); 50 } 51 } 52 53 /*** 54 * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent) 55 */ 56 public void mouseDown(final MouseEvent event) { 57 BattleField battleField = battleFieldView.getBattleField(); 58 59 int previousIndex = battleFieldView.getSelectedIndex(); 60 int index = battleField.getIndexFromPoint(event.x, event.y); 61 62 battleFieldView.setSelectedIndex(index); 63 64 if (previousIndex != -1) { 65 Rectangle bounds = battleField.getTileBounds(previousIndex); 66 battleFieldView.redraw( 67 bounds.x, 68 bounds.y, 69 bounds.width, 70 bounds.height, 71 false); 72 } 73 74 if (index != -1) { 75 Rectangle bounds = battleField.getTileBounds(index); 76 battleFieldView.redraw( 77 bounds.x, 78 bounds.y, 79 bounds.width, 80 bounds.height, 81 false); 82 } 83 } 84 85 public void keyPressed(final KeyEvent event) { 86 BattleFieldView view = getContext().getBattleFieldView(); 87 88 int index = view.getSelectedIndex(); 89 BattleField field = view.getBattleField(); 90 } 91 92 public void paintControl(final PaintEvent event) { 93 Image image = battleFieldView.getMapImage(); 94 95 if (image != null) { 96 event.gc.drawImage( 97 image, 98 event.x, 99 event.y, 100 event.width, 101 event.height, 102 event.x, 103 event.y, 104 event.width, 105 event.height); 106 107 int selectedIndex = battleFieldView.getSelectedIndex(); 108 109 if (selectedIndex != -1) { 110 BattleField battleField = battleFieldView.getBattleField(); 111 112 Rectangle bounds = battleField.getTileBounds(selectedIndex); 113 Rectangle paintArea = 114 new Rectangle(event.x, event.y, event.width, event.height); 115 116 if (bounds.intersects(paintArea)) { 117 ImageSet tileSet = TileImageSet.getInstance(); 118 119 tileSet.drawIcon( 120 TileImageSet.OVERLAY_SELECTED, 121 bounds, 122 battleFieldView, 123 event.gc); 124 } 125 } 126 } 127 } 128 }

This page was automatically generated by Maven