mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 07:17:13 -04:00
first working graphics card
This commit is contained in:
parent
681a2ac674
commit
3a9c8440b3
@ -4,9 +4,12 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* The component to show the graphics.
|
||||
*
|
||||
* @author hneemann
|
||||
*/
|
||||
public class GraphicComponent extends JComponent {
|
||||
private static final Color[] PALETTE = createPalette();
|
||||
|
||||
private final int pixSize;
|
||||
private final int width;
|
||||
@ -14,27 +17,86 @@ public class GraphicComponent extends JComponent {
|
||||
private long[] data;
|
||||
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) {
|
||||
this.width = width;
|
||||
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);
|
||||
setPreferredSize(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) {
|
||||
this.data = data;
|
||||
if (bank)
|
||||
offs=width*height;
|
||||
offs = width * height;
|
||||
else
|
||||
offs=0;
|
||||
offs = 0;
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void printComponent(Graphics g) {
|
||||
super.printComponent(g);
|
||||
protected void paintComponent(Graphics 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;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ public class GraphicDialog extends JDialog {
|
||||
getContentPane().add(graphicComponent);
|
||||
pack();
|
||||
|
||||
setAlwaysOnTop(true);
|
||||
setLocationRelativeTo(null);
|
||||
setVisible(true);
|
||||
}
|
||||
|
@ -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_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_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_pin_B">Auswahl der anzuzeigenden Seite.</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_tt">Wenn gesetzt, taucht der Wert als Messwert in Graph und Tabelle auf</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_arithmetic">Arithmetik</string>
|
||||
<string name="lib_flipFlops">FlipFlops</string>
|
||||
|
@ -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_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_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_pin_B">Selects the buffer to show</string>
|
||||
<string name="elem_ROM">ROM</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user