fix image() issue with pixels and width/height change; support for link()

This commit is contained in:
benfry
2010-02-28 02:46:36 +00:00
parent 3697fee5e9
commit 950e4e7993
2 changed files with 58 additions and 63 deletions
+24 -16
View File
@@ -38,6 +38,7 @@ import java.util.regex.*;
import java.util.zip.*;
import android.app.Activity;
import android.net.Uri;
import android.opengl.GLSurfaceView;
import android.text.format.Time;
import android.util.DisplayMetrics;
@@ -1900,6 +1901,8 @@ public class PApplet extends Activity implements PConstants, Runnable {
* yet have a standard method for launching URLs.
*/
public void link(String url, String frameTitle) {
Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse(url));
startActivity(viewIntent);
}
@@ -3018,6 +3021,8 @@ public class PApplet extends Activity implements PConstants, Runnable {
}
return new PFont(baseFont, round(size), smooth, charset);
}
//////////////////////////////////////////////////////////////
@@ -6268,6 +6273,25 @@ public class PApplet extends Activity implements PConstants, Runnable {
}
private void tellPDE(final String message) {
Log.i(getComponentName().getPackageName(), "PROCESSING " + message);
}
@Override
protected void onStart() {
tellPDE("onStart");
super.onStart();
}
@Override
protected void onStop() {
tellPDE("onStop");
super.onStop();
}
//////////////////////////////////////////////////////////////
// everything below this line is automatically generated. no touch.
@@ -7361,20 +7385,4 @@ public class PApplet extends Activity implements PConstants, Runnable {
int dx, int dy, int dw, int dh, int mode) {
g.blend(src, sx, sy, sw, sh, dx, dy, dw, dh, mode);
}
private void tellPDE(final String message)
{
Log.i(getComponentName().getPackageName(), "PROCESSING " + message);
}
@Override
protected void onStart() {
tellPDE("onStart");
super.onStart();
}
@Override
protected void onStop() {
tellPDE("onStop");
super.onStop();
}
}
@@ -919,12 +919,6 @@ public class PGraphicsAndroid2D extends PGraphics {
protected void imageImpl(PImage src,
float x1, float y1, float x2, float y2,
int u1, int v1, int u2, int v2) {
// pushStyle();
// rectMode(CORNERS);
// noStroke();
// rect(x1, y1, x2, y2);
// popStyle();
// if (true) return;
if (src.bitmap == null && src.format == ALPHA) {
// create an alpha bitmap for this feller
@@ -937,48 +931,41 @@ public class PGraphicsAndroid2D extends PGraphics {
src.modified = false;
}
//if (who.bitmap == null && (who.format == ARGB || who.format == RGB)) {
if (src.bitmap == null) { // format is ARGB or RGB
int offset = v1*src.width + u1;
// System.out.println(tint + " " + PApplet.hex(tintPaint.getColor()));
// System.out.println(src.pixels + " " + src.width + " " + src.height);
canvas.drawBitmap(src.pixels, offset, src.width,
x1, y1, u2-u1, v2-v1,
src.format == ARGB, tint ? tintPaint : null);
} else {
// rect.set(x1, y1, x2, y2);
if (src.width != src.bitmap.getWidth() ||
src.height != src.bitmap.getHeight()) {
// System.out.println("creating bitmap " + who.format + " " +
// who.width + "x" + who.height);
src.bitmap = Bitmap.createBitmap(src.width, src.height, Config.ARGB_8888);
// who.bitmap =
// Bitmap.createBitmap(who.width, who.height,
// who.format == ALPHA ? Config.ALPHA_8 : Config.ARGB_8888);
src.modified = true;
}
if (src.modified) {
//System.out.println("mutable, recycled = " + who.bitmap.isMutable() + ", " + who.bitmap.isRecycled());
if (!src.bitmap.isMutable()) {
src.bitmap = Bitmap.createBitmap(src.width, src.height, Config.ARGB_8888);
}
src.bitmap.setPixels(src.pixels, 0, src.width, 0, 0, src.width, src.height);
src.modified = false;
}
if (imageImplSrcRect == null) {
imageImplSrcRect = new Rect(u1, v1, u2, v2);
imageImplDstRect = new RectF(x1, y1, x2, y2);
} else {
imageImplSrcRect.set(u1, v1, u2, v2);
imageImplDstRect.set(x1, y1, x2, y2);
}
//canvas.drawBitmap(who.bitmap, imageImplSrcRect, imageImplDstRect, tint ? tintPaint : null);
//System.out.println(PApplet.hex(fillPaint.getColor()));
//canvas.drawBitmap(who.bitmap, imageImplSrcRect, imageImplDstRect, fillPaint);
// System.out.println("drawing lower, tint = " + tint + " " + PApplet.hex(tintPaint.getColor()));
canvas.drawBitmap(src.bitmap, imageImplSrcRect, imageImplDstRect, tint ? tintPaint : null);
// this version's not usable because it doesn't allow you to set output w/h
// if (src.bitmap == null) { // format is ARGB or RGB
// int offset = v1*src.width + u1;
// canvas.drawBitmap(src.pixels, offset, src.width,
// x1, y1, u2-u1, v2-v1,
// src.format == ARGB, tint ? tintPaint : null);
// } else {
if (src.bitmap == null ||
src.width != src.bitmap.getWidth() ||
src.height != src.bitmap.getHeight()) {
src.bitmap = Bitmap.createBitmap(src.width, src.height, Config.ARGB_8888);
src.modified = true;
}
if (src.modified) {
//System.out.println("mutable, recycled = " + who.bitmap.isMutable() + ", " + who.bitmap.isRecycled());
if (!src.bitmap.isMutable()) {
src.bitmap = Bitmap.createBitmap(src.width, src.height, Config.ARGB_8888);
}
src.bitmap.setPixels(src.pixels, 0, src.width, 0, 0, src.width, src.height);
src.modified = false;
}
if (imageImplSrcRect == null) {
imageImplSrcRect = new Rect(u1, v1, u2, v2);
imageImplDstRect = new RectF(x1, y1, x2, y2);
} else {
imageImplSrcRect.set(u1, v1, u2, v2);
imageImplDstRect.set(x1, y1, x2, y2);
}
//canvas.drawBitmap(who.bitmap, imageImplSrcRect, imageImplDstRect, tint ? tintPaint : null);
//System.out.println(PApplet.hex(fillPaint.getColor()));
//canvas.drawBitmap(who.bitmap, imageImplSrcRect, imageImplDstRect, fillPaint);
// System.out.println("drawing lower, tint = " + tint + " " + PApplet.hex(tintPaint.getColor()));
canvas.drawBitmap(src.bitmap, imageImplSrcRect, imageImplDstRect, tint ? tintPaint : null);
}