first working graphics card

This commit is contained in:
hneemann 2016-07-08 19:40:33 +02:00
parent 681a2ac674
commit 3a9c8440b3
4 changed files with 72 additions and 7 deletions

View File

@ -4,9 +4,12 @@ import javax.swing.*;
import java.awt.*; import java.awt.*;
/** /**
* The component to show the graphics.
*
* @author hneemann * @author hneemann
*/ */
public class GraphicComponent extends JComponent { public class GraphicComponent extends JComponent {
private static final Color[] PALETTE = createPalette();
private final int pixSize; private final int pixSize;
private final int width; private final int width;
@ -14,27 +17,86 @@ public class GraphicComponent extends JComponent {
private long[] data; private long[] data;
private int offs; private int offs;
/**
* Creates a new instance.
*
* @param width the width in pixels
* @param height the height in pixels
*/
public GraphicComponent(int width, int height) { public GraphicComponent(int width, int height) {
this.width = width; this.width = width;
this.height = height; this.height = height;
pixSize=4;
int pw = 640 / width;
int ph = 400 / height;
pixSize = (pw + ph) / 2;
Dimension size = new Dimension(width * pixSize, height * pixSize); Dimension size = new Dimension(width * pixSize, height * pixSize);
setPreferredSize(size); setPreferredSize(size);
setMinimumSize(size); setMinimumSize(size);
setMinimumSize(size); setMinimumSize(size);
setOpaque(true);
} }
/**
* Updates the graphics window
*
* @param data the data to show
* @param bank the bank to show
*/
public void updateGraphic(long[] data, boolean bank) { public void updateGraphic(long[] data, boolean bank) {
this.data = data; this.data = data;
if (bank) if (bank)
offs=width*height; offs = width * height;
else else
offs=0; offs = 0;
repaint(); repaint();
} }
@Override @Override
protected void printComponent(Graphics g) { protected void paintComponent(Graphics g) {
super.printComponent(g); for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++) {
int p = (int) data[offs + y * width + x];
if (p >= PALETTE.length) p = 1;
g.setColor(PALETTE[p]);
g.fillRect(x * pixSize, y * pixSize, pixSize, pixSize);
}
}
private static Color[] createPalette() {
Color[] col = new Color[64 + 16 + 32];
for (int i = 0; i < col.length; i++)
col[i] = Color.BLACK;
col[0] = Color.WHITE;
col[1] = Color.BLACK;
col[2] = Color.RED;
col[3] = Color.GREEN;
col[4] = Color.BLUE;
col[5] = Color.YELLOW;
col[6] = Color.CYAN;
col[7] = Color.MAGENTA;
col[8] = Color.ORANGE;
col[9] = Color.PINK;
for (int g = 0; g < 32; g++) {
int in = (255 * (31-g)) / 31;
col[10 + g] = new Color(in, in, in);
}
int index = 42;
for (int r = 0; r < 4; r++)
for (int g = 0; g < 4; g++)
for (int b = 0; b < 4; b++) {
col[index] = new Color(getComp(r), getComp(g), getComp(b));
index++;
}
return col;
}
private static int getComp(int c) {
return (255 * c) / 3;
} }
} }

View File

@ -19,6 +19,7 @@ public class GraphicDialog extends JDialog {
getContentPane().add(graphicComponent); getContentPane().add(graphicComponent);
pack(); pack();
setAlwaysOnTop(true);
setLocationRelativeTo(null); setLocationRelativeTo(null);
setVisible(true); setVisible(true);
} }

View File

@ -82,7 +82,7 @@ Ein gibt einen Eingang für das Beschreiben und einen Ausgang für das Auslesen
<string name="elem_RAMSinglePort_pin_ld">Ist dieser Eingang 1 wird das Datenwort ausgegeben.</string> <string name="elem_RAMSinglePort_pin_ld">Ist dieser Eingang 1 wird das Datenwort ausgegeben.</string>
<string name="elem_RAMSinglePort_pin_str">Ist dieser Eingang 1 wird mit steigendem Takt das Datenwort gespeichert.</string> <string name="elem_RAMSinglePort_pin_str">Ist dieser Eingang 1 wird mit steigendem Takt das Datenwort gespeichert.</string>
<string name="elem_RAMSinglePort_tt">Ein RAM Module mit einem bidirektionellem Anschluss für das Lesen und Schreiben von Daten.</string> <string name="elem_RAMSinglePort_tt">Ein RAM Module mit einem bidirektionellem Anschluss für das Lesen und Schreiben von Daten.</string>
<string name="elem_GraphicCard">Grafikkarte</string> <string name="elem_GraphicCard">Grafik-RAM</string>
<string name="elem_GraphicCard_tt">Wird verwendet um Bitmap Grafiken anzuzeigen.</string> <string name="elem_GraphicCard_tt">Wird verwendet um Bitmap Grafiken anzuzeigen.</string>
<string name="elem_GraphicCard_pin_B">Auswahl der anzuzeigenden Seite.</string> <string name="elem_GraphicCard_pin_B">Auswahl der anzuzeigenden Seite.</string>
<string name="elem_ROM">ROM</string> <string name="elem_ROM">ROM</string>
@ -228,6 +228,8 @@ Zur Analyse können Sie die Schaltung im Gatterschrittmodus ausführen.</string>
<string name="key_valueIsProbe">Als Messwert verwenden</string> <string name="key_valueIsProbe">Als Messwert verwenden</string>
<string name="key_valueIsProbe_tt">Wenn gesetzt, taucht der Wert als Messwert in Graph und Tabelle auf</string> <string name="key_valueIsProbe_tt">Wenn gesetzt, taucht der Wert als Messwert in Graph und Tabelle auf</string>
<string name="key_Testdata">Testdaten</string> <string name="key_Testdata">Testdaten</string>
<string name="key_graphicWidth">Breite in Pixel</string>
<string name="key_graphicHeight">Höhe in Pixel</string>
<string name="lib_Logic">Logisch</string> <string name="lib_Logic">Logisch</string>
<string name="lib_arithmetic">Arithmetik</string> <string name="lib_arithmetic">Arithmetik</string>
<string name="lib_flipFlops">FlipFlops</string> <string name="lib_flipFlops">FlipFlops</string>

View File

@ -81,7 +81,7 @@ So this gate can emulate every combinatorial gate.</string>
<string name="elem_RAMSinglePort_pin_ld">If this input is high the output is activated and the data is visible at the output.</string> <string name="elem_RAMSinglePort_pin_ld">If this input is high the output is activated and the data is visible at the output.</string>
<string name="elem_RAMSinglePort_pin_str">If this input is high when the clock becomes high, the the data is stored.</string> <string name="elem_RAMSinglePort_pin_str">If this input is high when the clock becomes high, the the data is stored.</string>
<string name="elem_RAMSinglePort_tt">A RAM module with a bidirectional connection for reading and writing the data.</string> <string name="elem_RAMSinglePort_tt">A RAM module with a bidirectional connection for reading and writing the data.</string>
<string name="elem_GraphicCard">GraphicCard</string> <string name="elem_GraphicCard">Graphic RAM</string>
<string name="elem_GraphicCard_tt">Used to show bitmap graphic</string> <string name="elem_GraphicCard_tt">Used to show bitmap graphic</string>
<string name="elem_GraphicCard_pin_B">Selects the buffer to show</string> <string name="elem_GraphicCard_pin_B">Selects the buffer to show</string>
<string name="elem_ROM">ROM</string> <string name="elem_ROM">ROM</string>