1 package edu.berkeley.slipway.gui;
2 // gui: use colors to distinguish planes? dot-dash lines?
5 import com.atmel.fpslic.*;
6 import edu.berkeley.slipway.*;
7 import static com.atmel.fpslic.FpslicConstants.*;
8 import static com.atmel.fpslic.FpslicUtil.*;
9 import static java.awt.event.KeyEvent.*;
10 import edu.berkeley.slipway.*;
12 import java.awt.geom.*;
13 import java.awt.event.*;
14 import java.awt.color.*;
15 import org.ibex.util.*;
19 import static edu.berkeley.slipway.gui.GuiConstants.*;
21 public class Gui3 extends Canvas implements MouseWheelListener, MouseMotionListener, KeyListener {
28 private int magnify = 0;
29 public GuiCell[][] ca = new GuiCell[128][];
30 private FtdiBoard ftdiboard;
31 public Gui3(Fpslic at40k, FtdiBoard drone) {
32 this(at40k, drone, 24, 24);
34 public Gui3(Fpslic at40k, FtdiBoard drone, int width, int height) {
39 for(int i=0; i<ca.length; i++)
40 ca[i] = new GuiCell[128];
41 for(int x=0; x<width; x++)
42 for(int y=0; y<height; y++)
43 ca[x][y] = new GuiCell(at40k.cell(x, y));
44 addMouseWheelListener(this);
45 addMouseMotionListener(this);
49 public void mouseWheelMoved(MouseWheelEvent e) {
50 magnify -= e.getWheelRotation();
54 Fpslic.Cell selectedCell = null;
55 public void _paint(Graphics2D g_) {
57 //g_.setStroke(new BasicStroke((float)1.0/SIZE));
58 g_.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
59 g_.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
62 AffineTransform at = new AffineTransform();
63 at.translate(getWidth()/2, getHeight()/2);
71 } else if (magnify < 0) {
75 at.scale(-1.0/mag, -1.0/mag);
77 at.translate(-(width*SIZE)/4, -(height*SIZE)/4);
79 for(int x=0; x<ca.length; x++)
80 for(int y=0; y<ca[x].length; y++) {
81 R r = new R(SIZE*x, SIZE*y,
82 SIZE*(x+1), SIZE*(y+1));
83 if (ca[x][y] != null) {
84 g.color(GuiCell.BORDER_COLOR);
89 P mouse = new P(mousex, mousey);
90 mouse = mouse.inverseTransform(at);
92 for(int x=0; x<ca.length; x++)
93 for(int y=0; y<ca[x].length; y++) {
94 R r = new R(SIZE*x, SIZE*y,
95 SIZE*(x+1), SIZE*(y+1));
96 if (ca[x][y] != null) {
97 if (r.contains(mouse)) selectedCell = ca[x][y].fpslicCell;
98 ca[x][y].draw(g, r, r.contains(mouse));
101 at = g.getTransform();
104 R statusArea = new R(0, getHeight() - 150, getWidth(), getHeight());
108 double keyboardRatio = ((double)keyboard1.getWidth(null)) / ((double)keyboard1.getHeight(null));
109 g.g.drawImage(keyboard1,
110 (int)statusArea.minx(),
111 (int)statusArea.miny(),
112 (int)((keyboardRatio * 150)),
116 statusArea = statusArea.plus(keyboardRatio * 150 + 10, 0, 0, 0);
117 Inspector.draw(g, statusArea, selectedCell);
120 R map = new R(getWidth() - 150, getHeight() - 150, getWidth(), getHeight());
121 map = map.plus(5, 5, -5, -5);
122 double mapw = map.width() / width;
123 double maph = map.height() / height;
124 P p1 = new P(0, 0).inverseTransform(at);
125 P p2 = new P(getWidth(), getHeight()-150).inverseTransform(at);
126 p1 = p1.scale(map.width() / (SIZE*width));
127 p2 = p2.scale(map.width() / (SIZE*width));
128 R rv = new R(map.minx() + p1.x,
132 for(int x=0; x<width; x++)
133 for(int y=0; y<height; y++) {
134 R rc = new R(map.minx() + x * mapw,
135 map.miny() + y * maph,
136 map.minx() + (x+1) * mapw - 1,
137 map.miny() + (y+1) * maph - 1);
138 if (selectedCell != null && selectedCell.row==(height-y-1) && selectedCell.col==x) g.color(0xffff00);
139 else if (rc.within(rv)) g.color(0x006600);
140 else g.color(0x444444);
147 public void paint(Graphics g) { _paint((Graphics2D)g); }
148 public void mouseDragged(MouseEvent e) { mouseMoved(e); }
149 public void mouseMoved(MouseEvent e) {
156 private static Image keyboard1 =
157 Toolkit.getDefaultToolkit().createImage("images/keyboard1.png");
158 private static Image keyboard2 =
159 Toolkit.getDefaultToolkit().createImage("images/keyboard2.png");
160 private static Image keyboard3 =
161 Toolkit.getDefaultToolkit().createImage("images/keyboard3.png");
163 private boolean[] keys = new boolean[1024];
164 public void keyTyped(KeyEvent k) { }
165 public void keyReleased(KeyEvent k) {
166 keys[k.getKeyCode()] = false;
168 public void keyPressed(KeyEvent k) {
170 keys[k.getKeyCode()] = true;
171 switch(k.getKeyCode()) {
173 if (selectedCell != null) {
174 selectedCell.ylut(0xff);
179 if (selectedCell != null) {
180 selectedCell.ylut(0x00);
185 if (selectedCell != null) {
186 selectedCell.ylut((LUT_SELF & ~LUT_OTHER) |
187 (LUT_Z & ~LUT_OTHER) |
193 case VK_0: case VK_1: case VK_2: case VK_3: case VK_4: {
194 if (selectedCell != null) {
195 int plane = k.getKeyCode() - VK_0;
196 if (keys[VK_X]) selectedCell.xi(plane+L0);
197 else if (keys[VK_Y]) selectedCell.yi(plane+L0);
198 else if (keys[VK_O]) selectedCell.out(plane+L0, !selectedCell.out(plane+L0));