Skip to content

Calculating frames only when shown #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/custom/ColorTable.hx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package custom;
import haxe.ui.events.UIEvent;
import haxe.io.Bytes;
import haxe.ui.Toolkit;
import haxe.ui.components.Canvas;
Expand All @@ -12,14 +13,24 @@ class ColorTable extends Canvas {
super();
componentGraphics.setProperty("html5.graphics.method", "canvas");
}

private override function onReady() {
super.onReady();
pixels = Bytes.alloc(Std.int(this.width * this.height * 4));

private var _showNextFrame = false;

@:bind(this, UIEvent.SHOWN)
private function onShown(_) {
if (_showNextFrame) return;
_showNextFrame = true;
if (pixels == null) pixels = Bytes.alloc(Std.int(this.width * this.height * 4));
frame();
}

@:bind(this, UIEvent.HIDDEN)
private function onHidden(_) {
_showNextFrame = false;
}

private function frame() {
if (!_showNextFrame) return;
drawColorTable(componentGraphics, Std.int(this.width), Std.int(this.height), 1);
}

Expand Down
15 changes: 13 additions & 2 deletions src/custom/DemoGraph.hx
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
package custom;

import haxe.ui.events.UIEvent;
import haxe.ui.Toolkit;
import haxe.ui.components.Canvas;
import haxe.ui.geom.Point;
import haxe.ui.graphics.ComponentGraphics;

class DemoGraph extends Canvas {
public function new() {
super();
private var _showNextFrame = false;

@:bind(this, UIEvent.SHOWN)
private function onShown(_) {
if (_showNextFrame) return;
_showNextFrame = true;
frame();
}

@:bind(this, UIEvent.HIDDEN)
private function onHidden(_) {
_showNextFrame = false;
}

private static var offset1:Float = 0;
private static var offset1Direction = 1;
Expand All @@ -24,6 +34,7 @@ class DemoGraph extends Canvas {
private var _pointCDirection = 1;
private var _pointCOffset:Float = 0;
private function frame() {
if (!_showNextFrame) return;
componentGraphics.clear();

drawGrid(componentGraphics, 520, 420, 10);
Expand Down
23 changes: 18 additions & 5 deletions src/custom/MiniGraph.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package custom;

import haxe.ui.events.UIEvent;
import haxe.io.Bytes;
import haxe.ui.Toolkit;
import haxe.ui.components.Canvas;
Expand All @@ -12,13 +13,24 @@ class MiniGraph extends Canvas {
super();
componentGraphics.setProperty("html5.graphics.method", "canvas");
}

private override function onReady() {
super.onReady();
pixels = Bytes.alloc(Std.int(this.width * this.height * 4));
populateDataPoints();

private var _showNextFrame = false;

@:bind(this, UIEvent.SHOWN)
private function onShown(_) {
if (_showNextFrame) return;
_showNextFrame = true;
if (pixels == null) {
pixels = Bytes.alloc(Std.int(this.width * this.height * 4));
populateDataPoints();
}
frame();
}

@:bind(this, UIEvent.HIDDEN)
private function onHidden(_) {
_showNextFrame = false;
}

private function populateDataPoints() {
var cx = Std.int(this.width);
Expand Down Expand Up @@ -56,6 +68,7 @@ class MiniGraph extends Canvas {

var skipFrame:Bool = false; // lets just slow it down in a hacky way bu skipping every other "frame"
private function frame() {
if (!_showNextFrame) return;
if (skipFrame == true) {
skipFrame = false;
Toolkit.callLater(frame);
Expand Down
23 changes: 18 additions & 5 deletions src/custom/Noise.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package custom;

import haxe.ui.events.UIEvent;
import haxe.io.Bytes;
import haxe.ui.Toolkit;
import haxe.ui.components.Canvas;
Expand All @@ -15,16 +16,28 @@ class Noise extends Canvas {
super();
componentGraphics.setProperty("html5.graphics.method", "canvas");
}

private override function onReady() {
super.onReady();
pixels = Bytes.alloc(Std.int(this.width * this.height * 4));

private var _showNextFrame = false;

@:bind(this, UIEvent.SHOWN)
private function onShown(_) {
if (_showNextFrame) return;
_showNextFrame = true;
if (pixels == null) {
pixels = Bytes.alloc(Std.int(this.width * this.height * 4));
}
frame();
}

@:bind(this, UIEvent.HIDDEN)
private function onHidden(_) {
_showNextFrame = false;
}

var skipFrame:Bool = false; // lets just slow it down in a hacky way bu skipping every other "frame"
private function frame() {
if (skipFrame == true) {
if (!_showNextFrame) return;
if (skipFrame) {
skipFrame = false;
Toolkit.callLater(frame);
return;
Expand Down