markluffel / Corkbird (http://corkbird.org/)

Corkbird is a library for Processing that saves snapshots of a Processing sketch in JSON format and can reload these JSON snapshots in a running sketch. The library integrates with the corkbird.org website so that users can share and continue to interact with the snapshots.

Clone this repository (size: 491.7 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/markluffel/corkbird/
commit 35: 9046adc17ca3
parent 34: 55f540b1a88d
branch: default
fixing extraneous ui image request
mar...@gmail.com
11 months ago

Changed (Δ1.1 KB):

raw changeset »

Makefile (2 lines added, 2 lines removed)

src/corkbird/CorkbirdUI.java (41 lines added, 3 lines removed)

test/corkbird/SketchOneTest.java (2 lines added, 0 lines removed)

Up to file-list Makefile:

1
1
2
CORKBIRD_VERSION=1
2
VERSION=0001
3
3
4
4
CWD=$(shell pwd)
5
5
JAVAC_ARGS=-source 1.5 -target 1.5
@@ -21,7 +21,7 @@ TEST_CLASSES=$(patsubst $(TEST_DIR)/%.ja
21
21
library/corkbird.jar: build library $(CLASSES)
22
22
	cp resources/* build/corkbird
23
23
	jar cvf library/corkbird.jar -C build corkbird
24
	cp library/corkbird.jar ~/code/corkbird/static/
24
	cp library/corkbird.jar ~/code/corkbird-web/static/corkbird-$(VERSION).jar
25
25
26
26
build/corkbird/%.class: src/corkbird/%.java
27
27
	javac -cp $(CLASSPATH) $(JAVAC_ARGS) src/corkbird/$*.java -d build

Up to file-list src/corkbird/CorkbirdUI.java:

1
1
package corkbird;
2
2
3
3
import java.awt.Cursor;
4
import java.awt.Image;
5
import java.awt.MediaTracker;
6
import java.awt.Toolkit;
4
7
import java.awt.event.MouseEvent;
8
import java.io.InputStream;
5
9
6
10
import processing.core.PApplet;
7
11
import processing.core.PConstants;
@@ -39,11 +43,45 @@ public class CorkbirdUI {
39
43
    uiTop = sketchHeight-UI_HEIGHT;
40
44
  }
41
45
  
46
  PImage loadImage(String path) {
47
    ClassLoader cl = getClass().getClassLoader();
48
49
    InputStream stream = cl.getResourceAsStream(path);
50
    if (stream != null) {
51
      byte[] bytes = PApplet.loadBytes(stream);
52
      Image awtImage = Toolkit.getDefaultToolkit().createImage(bytes);
53
      PImage image = loadImageMT(awtImage);
54
      return image;
55
    } else {
56
      return null;
57
    }
58
  }
59
  
60
  // copied from PApplet because of access modifiers
61
  PImage loadImageMT(Image awtImage) {
62
    MediaTracker tracker = new MediaTracker(sketch);
63
    tracker.addImage(awtImage, 0);
64
    try {
65
      tracker.waitForAll();
66
    } catch (InterruptedException e) {
67
      //e.printStackTrace();  // non-fatal, right?
68
    }
69
70
    PImage image = new PImage(awtImage);
71
    image.parent = sketch;
72
    image.format = PConstants.ARGB;
73
    return image;
74
  }
75
  
42
76
  public void draw() {
43
77
    if(saveButton == null) {
44
      saveButton = sketch.loadImage("corkbird/save_button.png");
45
      saveHover = sketch.loadImage("corkbird/save_hover.png");
46
      savePressed = sketch.loadImage("corkbird/save_pressed.png");
78
      saveButton = loadImage("corkbird/save_button.png");
79
      saveHover = loadImage("corkbird/save_hover.png");
80
      savePressed = loadImage("corkbird/save_pressed.png");
81
    }
82
    if(saveButton == null) {
83
      System.err.println("bad");
84
      return;
47
85
    }
48
86
  
49
87
    if(uiTop == 0) {

Up to file-list test/corkbird/SketchOneTest.java:

@@ -21,6 +21,7 @@ public int r0h, r0s, r0b;
21
21
public int NUM_BOMBS = 11;
22
22
public ArrayList bombs = new ArrayList();
23
23
public LeafTrail orphans = null;
24
transient Corkbird cb;
24
25
25
26
public void draw() {
26
27
  background(bg);
@@ -256,6 +257,7 @@ public float SMOKE_WONK = 0.01f;
256
257
257
258
public void setup() {
258
259
  size(480,320);
260
  cb = new Corkbird(this);
259
261
  colorMode(HSB);
260
262
  redTexture = makeTexture(8,8, new int[] {
261
263
    r0,r1,r2  }