Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: samples/openglui/src/openglui_canvas_tests.dart

Issue 12340036: Android improvements: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: samples/openglui/src/openglui_canvas_tests.dart
===================================================================
--- samples/openglui/src/openglui_canvas_tests.dart (revision 18917)
+++ samples/openglui/src/openglui_canvas_tests.dart (working copy)
@@ -23,8 +23,10 @@
void setup(canvasp, int w, int h) {
if (canvasp == null) {
+ log("Allocating canvas");
canvas = new CanvasElement(width: w, height: h);
} else {
+ log("Using parent canvas");
canvas = canvasp;
// called from gl_driver.dart.
// This is a kludge; we need a clean way of handling events.
@@ -494,9 +496,9 @@
initTest("Image loading");
var imageObj = new ImageElement();
imageObj.on.load.add((e) {
- ctx.drawImage(imageObj, 69, 50);
+ ctx.drawImage(e, 69, 50);
});
- imageObj.src = 'http://www.html5canvastutorials.com/demos/assets/darth-vader.bmp';
+ imageObj.src = 'file://chrome.png';
vsm 2013/02/23 00:25:25 Won't file: break running in the browser? Could i
}
void clip() {
@@ -605,17 +607,60 @@
}
}
+class Rectangle {
+ num x, y, width, height, borderWidth;
+}
+
+var startTime = 0;
+var myRectangle = null;
+
+void anim() {
+ if (myRectangle == null) {
+ myRectangle = new Rectangle();
+ myRectangle.x = 250;
+ myRectangle.y = 70;
+ myRectangle.width = 100;
+ myRectangle.height = 50;
+ myRectangle.borderWidth = 5;
+ startTime = (new DateTime.now()).millisecondsSinceEpoch;
vsm 2013/02/23 00:25:25 I think it's a little cleaner to use Stopwatch, bu
+ }
+
+ var now = (new DateTime.now()).millisecondsSinceEpoch;
+ var time = now - startTime;
+ var amplitude = 150;
+
+ // in ms
+ var period = 2000;
+ var centerX = width / 2 - myRectangle.width / 2;
+ var nextX = amplitude * Math.sin(time * 2 * Math.PI / period) + centerX;
+ myRectangle.x = nextX;
+
+ // clear
+ ctx.clearRect(0, 0, width, height);
+
+ // draw
+
+ ctx.beginPath();
+ ctx.rect(myRectangle.x, myRectangle.y, myRectangle.width, myRectangle.height);
+ ctx.fillStyle = '#8ED6FF';
+ ctx.fill();
+ ctx.lineWidth = myRectangle.borderWidth;
+ ctx.strokeStyle = 'black';
+ ctx.stroke();
+}
+
int testnum = -1; // Start with latest.
void update() {
+ if (testnum == 0) {
+ anim();
+ return;
+ }
if (!isDirty) return;
switch(testnum) {
- case 0:
+ case 1:
helloWorld();
break;
- case 1:
- smiley();
- break;
case 2:
blocks();
break;
@@ -676,9 +721,12 @@
case 21:
composite();
break;
+ case 22:
+ smiley();
+ break;
default:
if (testnum < 0) {
- testnum = 21;
+ testnum = 22;
} else {
testnum = 0;
}
@@ -711,9 +759,11 @@
onMotionPointerUp(num when, num x, num y) {}
onKeyDown(num when, int flags, int keycode, int metastate, int repeat) {
- ++testnum;
- isDirty = true;
- log("Marking dirty");
+ if (keycode == 32) {
+ ++testnum;
+ isDirty = true;
+ log("Marking dirty");
+ }
}
onKeyUp(num when, int flags, int keycode, int metastate, int repeat) {}
« runtime/embedders/openglui/common/vm_glue.cc ('K') | « samples/openglui/src/chrome.hex ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698