Skip to content

Commit

Permalink
Properly type the attributes param to getContextWebGL().
Browse files Browse the repository at this point in the history
  • Loading branch information
aduros committed Feb 2, 2013
1 parent 2491449 commit b691683
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
14 changes: 10 additions & 4 deletions bin/haxerenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,13 @@ def w_members(members):
w("typedef %s = %s -> %s;" % (to_haxe_class(node.id), arguments, to_haxe_local(callback.type.id)))
return

interface_name = node.ext_attrs["InterfaceName"] if "InterfaceName" in node.ext_attrs else node.id
wln("@:native(\"%s\")" % strip_vendor(interface_name))
w("extern class %s" % to_haxe_class(node.id))
if "HaxeTypedef" in node.ext_attrs:
w("typedef %s =" % to_haxe_class(node.id))
else:
interface_name = node.ext_attrs["InterfaceName"] if "InterfaceName" in node.ext_attrs else node.id
wln("@:native(\"%s\")" % strip_vendor(interface_name))
w("extern class %s" % to_haxe_class(node.id))

strip_vendor_fields(constants)
strip_vendor_fields(attributes)
strip_vendor_fields(operations, False)
Expand Down Expand Up @@ -617,7 +621,7 @@ def w_members(members):
elif node.id == "HTMLCanvasElement":
w_typed_shortcut("getContext2d", "CanvasRenderingContext2D", "getContext(\"2d\")")
wln()
wln("public inline function getContextWebGL (?attribs :Dynamic) :js.html.webgl.RenderingContext {")
wln("public inline function getContextWebGL (?attribs :js.html.webgl.ContextAttributes) :js.html.webgl.RenderingContext {")
begin_indent()
wln("return CanvasUtil.getContextWebGL(this, attribs);")
end_indent()
Expand Down Expand Up @@ -648,6 +652,8 @@ def w_members(members):
stripped = strip_vendor(node.id)
escaped = escape_keyword(stripped)
attr_type = to_haxe_local(node.type.id)
if "HaxeOptional" in node.ext_attrs:
w("@:optional ")
w("var %s " % escaped)
if escaped != stripped:
wln("(get,%s) :%s;" % ("null" if node.is_read_only else "set", attr_type))
Expand Down
2 changes: 1 addition & 1 deletion generated/js/html/CanvasElement.hx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern class CanvasElement extends Element
/** A typed shortcut for <code>getContext("2d")</code>. */
public inline function getContext2d () :CanvasRenderingContext2D { return cast getContext("2d"); }

public inline function getContextWebGL (?attribs :Dynamic) :js.html.webgl.RenderingContext {
public inline function getContextWebGL (?attribs :js.html.webgl.ContextAttributes) :js.html.webgl.RenderingContext {
return CanvasUtil.getContextWebGL(this, attribs);
}
}
Expand Down
15 changes: 7 additions & 8 deletions generated/js/html/webgl/ContextAttributes.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@
// This file is generated, do not edit!
package js.html.webgl;

@:native("WebGLContextAttributes")
extern class ContextAttributes
typedef ContextAttributes =
{
var alpha :Bool;
@:optional var alpha :Bool;

var antialias :Bool;
@:optional var antialias :Bool;

var depth :Bool;
@:optional var depth :Bool;

var premultipliedAlpha :Bool;
@:optional var premultipliedAlpha :Bool;

var preserveDrawingBuffer :Bool;
@:optional var preserveDrawingBuffer :Bool;

var stencil :Bool;
@:optional var stencil :Bool;

}
9 changes: 9 additions & 0 deletions idl/WebGLContextAttributes.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[HaxeTypedef]
interface WebGLContextAttributes {
[HaxeOptional] attribute boolean alpha;
[HaxeOptional] attribute boolean antialias;
[HaxeOptional] attribute boolean depth;
[HaxeOptional] attribute boolean premultipliedAlpha;
[HaxeOptional] attribute boolean preserveDrawingBuffer;
[HaxeOptional] attribute boolean stencil;
};

0 comments on commit b691683

Please sign in to comment.