From 3a9c8440b3277ead560f3a3600c4f63fcbe69434 Mon Sep 17 00:00:00 2001 From: hneemann Date: Fri, 8 Jul 2016 19:40:33 +0200 Subject: [PATCH] first working graphics card --- .../components/graphics/GraphicComponent.java | 72 +++++++++++++++++-- .../components/graphics/GraphicDialog.java | 1 + src/main/resources/lang/lang_de.xml | 4 +- src/main/resources/lang/lang_en.xml | 2 +- 4 files changed, 72 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/neemann/digital/gui/components/graphics/GraphicComponent.java b/src/main/java/de/neemann/digital/gui/components/graphics/GraphicComponent.java index 5b7fc05fa..709de5304 100644 --- a/src/main/java/de/neemann/digital/gui/components/graphics/GraphicComponent.java +++ b/src/main/java/de/neemann/digital/gui/components/graphics/GraphicComponent.java @@ -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; } } diff --git a/src/main/java/de/neemann/digital/gui/components/graphics/GraphicDialog.java b/src/main/java/de/neemann/digital/gui/components/graphics/GraphicDialog.java index 312875895..4949f7ce2 100644 --- a/src/main/java/de/neemann/digital/gui/components/graphics/GraphicDialog.java +++ b/src/main/java/de/neemann/digital/gui/components/graphics/GraphicDialog.java @@ -19,6 +19,7 @@ public class GraphicDialog extends JDialog { getContentPane().add(graphicComponent); pack(); + setAlwaysOnTop(true); setLocationRelativeTo(null); setVisible(true); } diff --git a/src/main/resources/lang/lang_de.xml b/src/main/resources/lang/lang_de.xml index e030e1a7d..e807c4015 100644 --- a/src/main/resources/lang/lang_de.xml +++ b/src/main/resources/lang/lang_de.xml @@ -82,7 +82,7 @@ Ein gibt einen Eingang für das Beschreiben und einen Ausgang für das Auslesen Ist dieser Eingang 1 wird das Datenwort ausgegeben. Ist dieser Eingang 1 wird mit steigendem Takt das Datenwort gespeichert. Ein RAM Module mit einem bidirektionellem Anschluss für das Lesen und Schreiben von Daten. - Grafikkarte + Grafik-RAM Wird verwendet um Bitmap Grafiken anzuzeigen. Auswahl der anzuzeigenden Seite. ROM @@ -228,6 +228,8 @@ Zur Analyse können Sie die Schaltung im Gatterschrittmodus ausführen. Als Messwert verwenden Wenn gesetzt, taucht der Wert als Messwert in Graph und Tabelle auf Testdaten + Breite in Pixel + Höhe in Pixel Logisch Arithmetik FlipFlops diff --git a/src/main/resources/lang/lang_en.xml b/src/main/resources/lang/lang_en.xml index 383304a93..91c114f1b 100644 --- a/src/main/resources/lang/lang_en.xml +++ b/src/main/resources/lang/lang_en.xml @@ -81,7 +81,7 @@ So this gate can emulate every combinatorial gate. If this input is high the output is activated and the data is visible at the output. If this input is high when the clock becomes high, the the data is stored. A RAM module with a bidirectional connection for reading and writing the data. - GraphicCard + Graphic RAM Used to show bitmap graphic Selects the buffer to show ROM