1 package edu.berkeley.slipway.gui;
3 import com.atmel.fpslic.*;
4 import edu.berkeley.slipway.*;
5 import static com.atmel.fpslic.FpslicConstants.*;
6 import static com.atmel.fpslic.FpslicUtil.*;
7 import static java.awt.event.KeyEvent.*;
8 import edu.berkeley.slipway.*;
10 import java.awt.geom.*;
11 import java.awt.event.*;
12 import java.awt.color.*;
13 import org.ibex.util.*;
17 import static edu.berkeley.slipway.gui.GuiConstants.*;
19 public class Gui3 extends Canvas implements MouseWheelListener, MouseMotionListener, KeyListener {
26 private int magnify = 0;
27 public GuiCell[][] ca = new GuiCell[128][];
28 private FtdiBoard ftdiboard;
29 public Gui3(Fpslic at40k, FtdiBoard drone) {
30 this(at40k, drone, 24, 24);
32 public Gui3(Fpslic at40k, FtdiBoard drone, int width, int height) {
37 for(int i=0; i<ca.length; i++)
38 ca[i] = new GuiCell[128];
39 for(int x=0; x<width; x++)
40 for(int y=0; y<height; y++)
41 ca[x][y] = new GuiCell(at40k.cell(x, y));
42 addMouseWheelListener(this);
43 addMouseMotionListener(this);
47 public void mouseWheelMoved(MouseWheelEvent e) {
48 magnify -= e.getWheelRotation();
52 Fpslic.Cell selectedCell = null;
53 public void _paint(Graphics2D g_) {
55 //g_.setStroke(new BasicStroke((float)1.0/SIZE));
56 g_.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
57 g_.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
60 AffineTransform at = new AffineTransform();
61 at.translate(getWidth()/2, getHeight()/2);
69 } else if (magnify < 0) {
73 at.scale(-1.0/mag, -1.0/mag);
75 at.translate(-(width*SIZE)/4, -(height*SIZE)/4);
77 for(int x=0; x<ca.length; x++)
78 for(int y=0; y<ca[x].length; y++) {
79 R r = new R(SIZE*x, SIZE*y,
80 SIZE*(x+1), SIZE*(y+1));
81 if (ca[x][y] != null) {
82 g.color(GuiCell.BORDER_COLOR);
87 P mouse = new P(mousex, mousey);
88 mouse = mouse.inverseTransform(at);
90 for(int x=0; x<ca.length; x++)
91 for(int y=0; y<ca[x].length; y++) {
92 R r = new R(SIZE*x, SIZE*y,
93 SIZE*(x+1), SIZE*(y+1));
94 if (ca[x][y] != null) {
95 if (r.contains(mouse)) selectedCell = ca[x][y].fpslicCell;
96 ca[x][y].draw(g, r, r.contains(mouse));
99 at = g.getTransform();
102 R statusArea = new R(0, getHeight() - 150, getWidth(), getHeight());
106 double keyboardRatio = ((double)keyboard1.getWidth(null)) / ((double)keyboard1.getHeight(null));
107 g.g.drawImage(keyboard1,
108 (int)statusArea.minx(),
109 (int)statusArea.miny(),
110 (int)((keyboardRatio * 150)),
114 statusArea = statusArea.plus(keyboardRatio * 150 + 10, 0, 0, 0);
115 Inspector.draw(g, statusArea, selectedCell);
118 R map = new R(getWidth() - 150, getHeight() - 150, getWidth(), getHeight());
119 map = map.plus(5, 5, -5, -5);
120 double mapw = map.width() / width;
121 double maph = map.height() / height;
122 P p1 = new P(0, 0).inverseTransform(at);
123 P p2 = new P(getWidth(), getHeight()-150).inverseTransform(at);
124 p1 = p1.scale(map.width() / (SIZE*width));
125 p2 = p2.scale(map.width() / (SIZE*width));
126 R rv = new R(map.minx() + p1.x,
130 for(int x=0; x<width; x++)
131 for(int y=0; y<height; y++) {
132 R rc = new R(map.minx() + x * mapw,
133 map.miny() + y * maph,
134 map.minx() + (x+1) * mapw - 1,
135 map.miny() + (y+1) * maph - 1);
136 if (selectedCell != null && selectedCell.row==(height-y-1) && selectedCell.col==x) g.color(0xffff00);
137 else if (rc.within(rv)) g.color(0x006600);
138 else g.color(0x444444);
145 public void paint(Graphics g) { _paint((Graphics2D)g); }
146 public void mouseDragged(MouseEvent e) { mouseMoved(e); }
147 public void mouseMoved(MouseEvent e) {
154 private static Image keyboard1 =
155 Toolkit.getDefaultToolkit().createImage("images/keyboard1.png");
156 private static Image keyboard2 =
157 Toolkit.getDefaultToolkit().createImage("images/keyboard2.png");
158 private static Image keyboard3 =
159 Toolkit.getDefaultToolkit().createImage("images/keyboard3.png");
161 private boolean[] keys = new boolean[1024];
162 public void keyTyped(KeyEvent k) { }
163 public void keyReleased(KeyEvent k) {
164 keys[k.getKeyCode()] = false;
166 public void keyPressed(KeyEvent k) {
168 keys[k.getKeyCode()] = true;
169 switch(k.getKeyCode()) {
171 if (selectedCell != null) {
172 selectedCell.ylut(0xff);
177 if (selectedCell != null) {
178 selectedCell.ylut(0x00);
183 if (selectedCell != null) {
184 selectedCell.ylut((LUT_SELF & ~LUT_OTHER) |
185 (LUT_Z & ~LUT_OTHER) |
191 case VK_0: case VK_1: case VK_2: case VK_3: case VK_4: {
192 if (selectedCell != null) {
193 int plane = k.getKeyCode() - VK_0;
194 if (keys[VK_X]) selectedCell.xi(plane+L0);
195 else if (keys[VK_Y]) selectedCell.yi(plane+L0);
196 else if (keys[VK_O]) selectedCell.out(plane+L0, !selectedCell.out(plane+L0));