2021-10-27 22:18:09 +02:00
|
|
|
module jsdom
|
|
|
|
|
|
|
|
pub struct HTMLCanvasElement {
|
|
|
|
HTMLElement
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn (cv HTMLCanvasElement) height() int {
|
|
|
|
ret := 0
|
|
|
|
#ret.val = cv.node.height;
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn (cv HTMLCanvasElement) width() int {
|
|
|
|
ret := 0
|
|
|
|
#ret.val = cv.node.width;
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn (cv HTMLCanvasElement) typ() NodeType {
|
|
|
|
return .element
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn (elem HTMLCanvasElement) add_event_listener(event string, cb EventCallback) {
|
|
|
|
#elem.node.addEventListener(event.str, function (event) { let e = jsdom__dispatch_event_target(this);
|
|
|
|
#let ev = jsdom__dispatch_event(event); ev.event = event;
|
|
|
|
#return cb(e,ev)
|
|
|
|
#});
|
|
|
|
}
|
|
|
|
|
2021-11-03 15:54:28 +01:00
|
|
|
pub fn (elem HTMLCanvasElement) get_context(ctx_ string) ContextResult {
|
|
|
|
mut res := NoneContext{}
|
2021-10-27 22:18:09 +02:00
|
|
|
#let ctx = elem.node.getContext(ctx_.str);
|
2021-11-03 15:54:28 +01:00
|
|
|
#if (ctx instanceof CanvasRenderingContext2D) { res = new jsdom__CanvasRenderingContext2D(ctx); res.ctx = ctx; }
|
2021-10-27 22:18:09 +02:00
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
2021-11-07 09:06:28 +01:00
|
|
|
|
|
|
|
pub fn (elem HTMLCanvasElement) get_context_2d() CanvasRenderingContext2D {
|
|
|
|
mut res := CanvasRenderingContext2D{}
|
|
|
|
#let ctx = elem.node.getContext('2d');
|
|
|
|
#res = new jsdom__CanvasRenderingContext2D(ctx);
|
|
|
|
#res.ctx = ctx;
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|