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 java.awt.event.KeyEvent.*;
9 import edu.berkeley.slipway.*;
11 import java.awt.geom.*;
12 import java.awt.event.*;
13 import java.awt.color.*;
14 import org.ibex.util.*;
18 import static edu.berkeley.slipway.gui.GuiConstants.*;
20 public class Gui3 extends Canvas implements MouseWheelListener, MouseMotionListener, KeyListener {
27 private int magnify = 0;
28 public GuiCell[][] ca = new GuiCell[128][];
29 private SlipwayBoard ftdiboard;
30 public Gui3(FpslicDevice at40k, SlipwayBoard slipway) {
31 this(at40k, slipway, 24, 24);
33 public Gui3(FpslicDevice at40k, SlipwayBoard slipway, int width, int height) {
35 this.slipway = slipway;
38 for(int i=0; i<ca.length; i++)
39 ca[i] = new GuiCell[128];
40 for(int x=0; x<width; x++)
41 for(int y=0; y<height; y++)
42 ca[x][y] = new GuiCell(at40k.cell(x, y));
43 addMouseWheelListener(this);
44 addMouseMotionListener(this);
48 public void mouseWheelMoved(MouseWheelEvent e) {
49 magnify -= e.getWheelRotation();
53 FpslicDevice.Cell selectedCell = null;
54 public void _paint(Graphics2D g_) {
56 //g_.setStroke(new BasicStroke((float)1.0/SIZE));
57 g_.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
58 g_.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
61 AffineTransform at = new AffineTransform();
62 at.translate(getWidth()/2, getHeight()/2);
70 } else if (magnify < 0) {
74 at.scale(-1.0/mag, -1.0/mag);
76 at.translate(-(width*SIZE)/4, -(height*SIZE)/4);
78 for(int x=0; x<ca.length; x++)
79 for(int y=0; y<ca[x].length; y++) {
80 R r = new R(SIZE*x, SIZE*y,
81 SIZE*(x+1), SIZE*(y+1));
82 if (ca[x][y] != null) {
83 g.color(GuiCell.BORDER_COLOR);
88 P mouse = new P(mousex, mousey);
89 mouse = mouse.inverseTransform(at);
91 for(int x=0; x<ca.length; x++)
92 for(int y=0; y<ca[x].length; y++) {
93 R r = new R(SIZE*x, SIZE*y,
94 SIZE*(x+1), SIZE*(y+1));
95 if (ca[x][y] != null) {
96 if (r.contains(mouse)) selectedCell = ca[x][y].fpslicCell;
97 ca[x][y].draw(g, r, r.contains(mouse));
100 at = g.getTransform();
103 R statusArea = new R(0, getHeight() - 150, getWidth(), getHeight());
107 double keyboardRatio = ((double)keyboard1.getWidth(null)) / ((double)keyboard1.getHeight(null));
108 g.g.drawImage(keyboard1,
109 (int)statusArea.minx(),
110 (int)statusArea.miny(),
111 (int)((keyboardRatio * 150)),
115 statusArea = statusArea.plus(keyboardRatio * 150 + 10, 0, 0, 0);
116 Inspector.draw(g, statusArea, selectedCell);
119 R map = new R(getWidth() - 150, getHeight() - 150, getWidth(), getHeight());
120 map = map.plus(5, 5, -5, -5);
121 double mapw = map.width() / width;
122 double maph = map.height() / height;
123 P p1 = new P(0, 0).inverseTransform(at);
124 P p2 = new P(getWidth(), getHeight()-150).inverseTransform(at);
125 p1 = p1.scale(map.width() / (SIZE*width));
126 p2 = p2.scale(map.width() / (SIZE*width));
127 R rv = new R(map.minx() + p1.x,
131 for(int x=0; x<width; x++)
132 for(int y=0; y<height; y++) {
133 R rc = new R(map.minx() + x * mapw,
134 map.miny() + y * maph,
135 map.minx() + (x+1) * mapw - 1,
136 map.miny() + (y+1) * maph - 1);
137 if (selectedCell != null && selectedCell.row==(height-y-1) && selectedCell.col==x) g.color(0xffff00);
138 else if (rc.within(rv)) g.color(0x006600);
139 else g.color(0x444444);
146 public void paint(Graphics g) { _paint((Graphics2D)g); }
147 public void mouseDragged(MouseEvent e) { mouseMoved(e); }
148 public void mouseMoved(MouseEvent e) {
155 private static Image keyboard1 =
156 Toolkit.getDefaultToolkit().createImage("images/keyboard1.png");
157 private static Image keyboard2 =
158 Toolkit.getDefaultToolkit().createImage("images/keyboard2.png");
159 private static Image keyboard3 =
160 Toolkit.getDefaultToolkit().createImage("images/keyboard3.png");
162 private boolean[] keys = new boolean[1024];
163 public void keyTyped(KeyEvent k) { }
164 public void keyReleased(KeyEvent k) {
165 keys[k.getKeyCode()] = false;
167 public void keyPressed(KeyEvent k) {
169 keys[k.getKeyCode()] = true;
170 switch(k.getKeyCode()) {
172 if (selectedCell != null) {
173 selectedCell.ylut(0xff);
178 if (selectedCell != null) {
179 selectedCell.ylut(0x00);
184 if (selectedCell != null) {
185 selectedCell.ylut((LUT_SELF & ~LUT_OTHER) |
186 (LUT_Z & ~LUT_OTHER) |
192 case VK_0: case VK_1: case VK_2: case VK_3: case VK_4: {
193 if (selectedCell != null) {
194 int plane = k.getKeyCode() - VK_0;
195 if (keys[VK_X]) selectedCell.xi(plane+L0);
196 else if (keys[VK_Y]) selectedCell.yi(plane+L0);
197 else if (keys[VK_O]) selectedCell.out(plane+L0, !selectedCell.out(plane+L0));