diff options
author | Christopher Baines <cbaines8@gmail.com> | 2011-10-10 09:34:20 +0100 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2011-10-10 09:34:20 +0100 |
commit | c34f84af6108c17cdf451a5162bf9fa9709d19f0 (patch) | |
tree | 2b9a6b2eda951413d26fa4ea768f5ffcad29ef55 | |
parent | c908ca694912508ac3d937d66a2316d6402cc379 (diff) | |
parent | bc1c9a0736d0eb5198eb1fe481812976a70b6591 (diff) | |
download | punchingbag-c34f84af6108c17cdf451a5162bf9fa9709d19f0.tar punchingbag-c34f84af6108c17cdf451a5162bf9fa9709d19f0.tar.gz |
Merge branch 'graphics' into dev
3 files changed, 37 insertions, 6 deletions
diff --git a/PunchingBag/src/uk/ac/open/punchingbag/PunchingBag.java b/PunchingBag/src/uk/ac/open/punchingbag/PunchingBag.java index e4e0c5e..6582fba 100644 --- a/PunchingBag/src/uk/ac/open/punchingbag/PunchingBag.java +++ b/PunchingBag/src/uk/ac/open/punchingbag/PunchingBag.java @@ -175,7 +175,7 @@ public class PunchingBag implements Runnable { * Private constructor, starts the run method. */ private PunchingBag() { - loadConfig(); + //loadConfig(); Thread bagControlThread = new Thread(this); bagControlThread.setPriority(Thread.MAX_PRIORITY); bagControlThread.start(); @@ -233,6 +233,7 @@ public class PunchingBag implements Runnable { * the <code>ButtonListener</code> to be added */ public void addButtonListener(ButtonListener l) { + System.out.println(l.toString() + " added as button listener"); buttonListenerList.add(ButtonListener.class, l); } @@ -370,6 +371,21 @@ public class PunchingBag implements Runnable { public void fillRect(int x, int y, int width, int height, Color colour, long time) { runningEffects.add(new FillRect(x, y, width, height, colour, time)); } + + /** + * This should fill in a rectangle + * + * @param x + * The x coordinate of the top right of the rectangle + * @param y + * The y coordinate of the top right of the + * @param width + * @param height + * @param colour + */ + public void fillRect(int x, int y, int width, int height, Color colour) { + runningEffects.add(new FillRect(x, y, width, height, colour)); + } /** * @param x @@ -468,10 +484,19 @@ public class PunchingBag implements Runnable { this.colour = colour; this.time = System.currentTimeMillis() + time; } + + public FillRect(int x, int y, int width, int height, Color colour) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.colour = colour; + this.time = -1; + } public void draw() { fillRectInternal(x, y, width, height, colour); - if (System.currentTimeMillis() >= time) { + if (time != -1 && System.currentTimeMillis() >= time) { stop(); } } @@ -1164,10 +1189,12 @@ public class PunchingBag implements Runnable { if (buttonsChanged) { ButtonListener[] buttonListeners = buttonListenerList.getListeners(ButtonListener.class); + //System.out.println(buttonListenerList.getListenerCount() + " button listeners"); for (int i = 0; i < buttonListenerList.getListenerCount(); i++) { for (int x = 0; x < buttonWidth; x++) { for (int y = 0; y < buttonHeight; y++) { if (buttons[x][y]) { + System.out.println(" x " + x + " y " + y + " is pressed"); buttonListeners[i].buttonPressed(x, y); buttonListeners[i].contact(new Contact(System.currentTimeMillis(), x, y, bottomAccelX)); } diff --git a/PunchingBag/src/uk/ac/open/punchingbag/PunchingBagGUI.java b/PunchingBag/src/uk/ac/open/punchingbag/PunchingBagGUI.java index f76c033..f6cebe2 100644 --- a/PunchingBag/src/uk/ac/open/punchingbag/PunchingBagGUI.java +++ b/PunchingBag/src/uk/ac/open/punchingbag/PunchingBagGUI.java @@ -54,6 +54,7 @@ import javax.sound.sampled.AudioFormat.Encoding; import javax.sound.sampled.Mixer.Info; import uk.ac.open.punchingbag.examples.Keyboard; +import uk.ac.open.punchingbag.examples.MidiSequencer; import uk.ac.open.punchingbag.examples.SimpleKeyboard; import PicHelper.ImagePanel; @@ -95,7 +96,8 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener, public static void main(String[] args) throws InterruptedException { new PunchingBagGUI(); - new Keyboard(); + //new Keyboard(); + new MidiSequencer(); } PunchingBagGUI() throws InterruptedException { @@ -112,7 +114,7 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener, } frame = new JFrame("Punching Bag GUI"); - frame.setUndecorated(true); + //frame.setUndecorated(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // frame.setSize(600, 600); @@ -156,7 +158,7 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener, device = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice(); if (device.isFullScreenSupported()) { - device.setFullScreenWindow(frame); + //device.setFullScreenWindow(frame); } else { System.err.println("Full screen not supported"); } diff --git a/PunchingBag/src/uk/ac/open/punchingbag/examples/Keyboard.java b/PunchingBag/src/uk/ac/open/punchingbag/examples/Keyboard.java index 14d29a1..8b0d19d 100644 --- a/PunchingBag/src/uk/ac/open/punchingbag/examples/Keyboard.java +++ b/PunchingBag/src/uk/ac/open/punchingbag/examples/Keyboard.java @@ -42,6 +42,8 @@ public class Keyboard implements Runnable, ButtonListener { public static final int END_OF_TRACK = 47; Sequencer sequencer; + + int instrument = 0; static final int[] offsets = { // add these amounts to the base value // A B C D E F G @@ -114,7 +116,7 @@ public class Keyboard implements Runnable, ButtonListener { void genKeys() throws InvalidMidiDataException, MidiUnavailableException { for (int key = 0; key < 20; key++) { - int instrument = 0; + instrument++; // 16 ticks per quarter note. Sequence sequence = new Sequence(Sequence.PPQ, 16); |