Permalink
Browse files

Window: Change the draw methods into a more D'ish way.

Transformation: added properties for the x and y coordinate to get and
set them more easily
  • Loading branch information...
Dgame committed Apr 30, 2015
1 parent 3784d98 commit bf4be2254c19a055ce10a54d88c9c45c2247b4bd
@@ -55,11 +55,10 @@ public:
Line /// Show only the lines
}
private:
protected:
Texture* _texture;
Vertex[] _vertices;
protected:
@nogc
override void draw(ref const Window wnd) nothrow {
glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT | GL_LINE_BIT);
@@ -86,8 +85,7 @@ protected:
break;
}
// prevent 64 bit bug, because *.length is size_t and therefore on 64 bit platforms ulong
wnd.draw(this.geometry, super.getMatrix(), _texture, _vertices.ptr, cast(uint) _vertices.length);
wnd.draw(this.geometry, super.getMatrix(), _texture, _vertices);
}
public:
@@ -176,7 +174,6 @@ final:
@nogc
void setTexture(Texture* texture) pure nothrow {
_texture = texture;
if (texture)
this.setTextureRect(Rect(0, 0, texture.width, texture.height));
}
@@ -50,7 +50,7 @@ protected:
@nogc
override void draw(ref const Window wnd) nothrow {
wnd.draw(Geometry.TriangleStrip, super.getMatrix(), _texture, _vertices.ptr, 4);
wnd.draw(Geometry.TriangleStrip, super.getMatrix(), _texture, _vertices[]);
}
@nogc
@@ -78,8 +78,8 @@ protected:
_vertices[3].position.y = th;
}
immutable ubyte vCount = _text.length != 0 ? 4 : 0;
wnd.draw(Geometry.TriangleStrip, super.getMatrix(), &_texture, _vertices.ptr, vCount);
if (_text.length != 0)
wnd.draw(Geometry.TriangleStrip, super.getMatrix(), &_texture, _vertices[]);
}
@nogc
@@ -120,6 +120,48 @@ final:
return _position;
}
/**
* Returns the x coordinate <b>by value</b>
*
* Note: if you want to change the coordinate, use either move or setPosition
*/
@nogc
@property
float x() const pure nothrow {
return _position.x;
}
/**
* Set a new x coordinate
*/
@nogc
@property
void x(float cx) pure nothrow {
_position.x = cx;
_notifyTransform();
}
/**
* Returns the y coordinate <b>by value</b>
*
* Note: if you want to change the coordinate, use either move or setPosition
*/
@nogc
@property
float y() const pure nothrow {
return _position.y;
}
/**
* Set a new y coordinate
*/
@nogc
@property
void y(float cy) pure nothrow {
_position.y = cy;
_notifyTransform();
}
/**
* Set the center position
*/
@@ -550,31 +550,6 @@ public:
d.draw(this);
}
@nogc
void draw(Geometry geo, ref const Matrix4 mat, const Texture* texture, const Vertex* vertices, uint vCount) const nothrow {
if (vCount == 0)
return;
glPushMatrix();
scope(exit) glPopMatrix();
glLoadMatrixf(mat.getValues().ptr);
if (texture) {
glEnable(GL_TEXTURE_2D);
texture.bind();
}
glVertexPointer(2, GL_FLOAT, Vertex.sizeof, &vertices[0].position.x);
glColorPointer(4, GL_FLOAT, Vertex.sizeof, &vertices[0].color.red);
if (texture)
glTexCoordPointer(2, GL_FLOAT, Vertex.sizeof, &vertices[0].texCoord.x);
glDrawArrays(geo, 0, vCount);
if (texture)
texture.unbind();
}
/**
* Make all changes visible on screen
*/
@@ -716,4 +691,36 @@ public:
bool isFullscreen() nothrow {
return (this.getStyle() & FullScreenMask) != 0;
}
package(Dgame):
@nogc
void draw(Geometry geo, const Texture* texture, const Vertex[] vertices) const nothrow {
if (texture) {
glEnable(GL_TEXTURE_2D);
texture.bind();
}
glVertexPointer(2, GL_FLOAT, Vertex.sizeof, &vertices[0].position.x);
glColorPointer(4, GL_FLOAT, Vertex.sizeof, &vertices[0].color.red);
if (texture)
glTexCoordPointer(2, GL_FLOAT, Vertex.sizeof, &vertices[0].texCoord.x);
glDrawArrays(geo, 0, vertices.length);
if (texture)
texture.unbind();
}
@nogc
void draw(Geometry geo, ref const Matrix4 mat, const Texture* texture, const Vertex[] vertices) const nothrow {
if (vertices.length == 0)
return;
glPushMatrix();
scope(exit) glPopMatrix();
glLoadMatrixf(mat.getValues().ptr);
this.draw(geo, texture, vertices);
}
}
@@ -51,6 +51,32 @@ <h1>Dgame.Graphic.Transformable</h1>
</big></dt>
<dd>Returns the current position<br><br>
</dd>
<dt><big><a name="Transformable.x"></a>final const pure nothrow @nogc @property float <u>x</u>();
</big></dt>
<dd>Returns the <u>x</u> coordinate <b>by value</b>
<br><br>
<b>Note:</b><br>
if you want to change the coordinate, use either move or setPosition<br><br>
</dd>
<dt><big><a name="Transformable.x.2"></a>final pure nothrow @nogc @property void <u>x</u>(float <i>cx</i>);
</big></dt>
<dd>Set a new <u>x</u> coordinate<br><br>
</dd>
<dt><big><a name="Transformable.y"></a>final const pure nothrow @nogc @property float <u>y</u>();
</big></dt>
<dd>Returns the <u>y</u> coordinate <b>by value</b>
<br><br>
<b>Note:</b><br>
if you want to change the coordinate, use either move or setPosition<br><br>
</dd>
<dt><big><a name="Transformable.y.2"></a>final pure nothrow @nogc @property void <u>y</u>(float <i>cy</i>);
</big></dt>
<dd>Set a new <u>y</u> coordinate<br><br>
</dd>
<dt><big><a name="Transformable.setCenter"></a>final pure nothrow @nogc void <u>setCenter</u>(float <i>x</i>, float <i>y</i>);
</big></dt>
@@ -5,6 +5,6 @@
"derelict-sdl2": "1.9.5",
"derelict-gl3": "1.0.12"
},
"lastUpgrade": "2015-04-28T22:30:52.372814"
"lastUpgrade": "2015-04-29T23:04:38.3196326"
}
}

0 comments on commit bf4be22

Please sign in to comment.