[Scummvm-cvs-logs] SF.net SVN: scummvm: [25281] residual/trunk

aquadran at users.sourceforge.net aquadran at users.sourceforge.net
Tue Jan 30 13:38:27 CET 2007


Revision: 25281
          http://scummvm.svn.sourceforge.net/scummvm/?rev=25281&view=rev
Author:   aquadran
Date:     2007-01-30 04:38:26 -0800 (Tue, 30 Jan 2007)

Log Message:
-----------
added draw Polygon support needed for checkbox in Don's computer

Modified Paths:
--------------
    residual/trunk/driver.h
    residual/trunk/driver_gl.cpp
    residual/trunk/driver_gl.h
    residual/trunk/driver_tinygl.cpp
    residual/trunk/driver_tinygl.h
    residual/trunk/lua.cpp
    residual/trunk/primitives.cpp
    residual/trunk/primitives.h

Modified: residual/trunk/driver.h
===================================================================
--- residual/trunk/driver.h	2007-01-30 12:14:45 UTC (rev 25280)
+++ residual/trunk/driver.h	2007-01-30 12:38:26 UTC (rev 25281)
@@ -103,6 +103,7 @@
 
 	virtual void drawRectangle(PrimitiveObject *primitive) = 0;
 	virtual void drawLine(PrimitiveObject *primitive) = 0;
+	virtual void drawPolygon(PrimitiveObject *primitive) = 0;
 
 	virtual void prepareSmushFrame(int width, int height, byte *bitmap) = 0;
 	virtual void drawSmushFrame(int offsetX, int offsetY) = 0;

Modified: residual/trunk/driver_gl.cpp
===================================================================
--- residual/trunk/driver_gl.cpp	2007-01-30 12:14:45 UTC (rev 25280)
+++ residual/trunk/driver_gl.cpp	2007-01-30 12:38:26 UTC (rev 25281)
@@ -903,9 +903,7 @@
 
 	glBegin(GL_LINES);
 	glVertex2f(x1, y1);
-	glVertex2f(x2, y1);
 	glVertex2f(x2, y2);
-	glVertex2f(x1, y2);
 	glEnd();
 
 	glColor3f(1.0f, 1.0f, 1.0f);
@@ -914,3 +912,44 @@
 	glEnable(GL_DEPTH_TEST);
 	glEnable(GL_LIGHTING);
 }
+
+void DriverGL::drawPolygon(PrimitiveObject *primitive) {
+	int x1 = primitive->getX1();
+	int y1 = primitive->getY1();
+	int x2 = primitive->getX2();
+	int y2 = primitive->getY2();
+	int x3 = primitive->getX3();
+	int y3 = primitive->getY3();
+	int x4 = primitive->getX4();
+	int y4 = primitive->getY4();
+
+	Color color = primitive->getColor();
+
+	glMatrixMode(GL_PROJECTION);
+	glLoadIdentity();
+	glOrtho(0, _screenWidth, _screenHeight, 0, 0, 1);
+	glMatrixMode(GL_MODELVIEW);
+	glLoadIdentity();
+
+	glDisable(GL_LIGHTING);
+	glDisable(GL_DEPTH_TEST);
+	glDepthMask(GL_FALSE);
+
+	glColor3f(color.red() / 255.0f, color.green() / 255.0f, color.blue() / 255.0f);
+
+	glBegin(GL_LINES);
+	glVertex2f(x1, y1);
+	glVertex2f(x2, y2);
+	glEnd();
+
+	glBegin(GL_LINES);
+	glVertex2f(x3, y3);
+	glVertex2f(x4, y4);
+	glEnd();
+
+	glColor3f(1.0f, 1.0f, 1.0f);
+
+	glDepthMask(GL_TRUE);
+	glEnable(GL_DEPTH_TEST);
+	glEnable(GL_LIGHTING);
+}

Modified: residual/trunk/driver_gl.h
===================================================================
--- residual/trunk/driver_gl.h	2007-01-30 12:14:45 UTC (rev 25280)
+++ residual/trunk/driver_gl.h	2007-01-30 12:38:26 UTC (rev 25281)
@@ -89,6 +89,7 @@
 
 	void drawRectangle(PrimitiveObject *primitive);
 	void drawLine(PrimitiveObject *primitive);
+	void drawPolygon(PrimitiveObject *primitive);
 
 	void prepareSmushFrame(int width, int height, byte *bitmap);
 	void drawSmushFrame(int offsetX, int offsetY);

Modified: residual/trunk/driver_tinygl.cpp
===================================================================
--- residual/trunk/driver_tinygl.cpp	2007-01-30 12:14:45 UTC (rev 25280)
+++ residual/trunk/driver_tinygl.cpp	2007-01-30 12:38:26 UTC (rev 25281)
@@ -610,7 +610,37 @@
 	uint16 c = ((color.red() & 0xF8) << 8) | ((color.green() & 0xFC) << 3) | (color.blue() >> 3);
 
 	for (int x = x1; x <= x2; x++) {
-		int y = (int) (m * x) + b;
+		int y = (int)(m * x) + b;
 		WRITE_LE_UINT16(dst + 640 * y + x, c);
 	}
 }
+
+void DriverTinyGL::drawPolygon(PrimitiveObject *primitive) {
+	uint16 *dst = (uint16 *)_zb->pbuf;
+	int x1 = primitive->getX1();
+	int y1 = primitive->getY1();
+	int x2 = primitive->getX2();
+	int y2 = primitive->getY2();
+	int x3 = primitive->getX3();
+	int y3 = primitive->getY3();
+	int x4 = primitive->getX4();
+	int y4 = primitive->getY4();
+	float m;
+	int b;
+
+	Color color = primitive->getColor();
+	uint16 c = ((color.red() & 0xF8) << 8) | ((color.green() & 0xFC) << 3) | (color.blue() >> 3);
+
+	m = (y2 - y1) / (x2 - x1);
+	b = (int)(-m * x1 + y1);
+	for (int x = x1; x <= x2; x++) {
+		int y = (int)(m * x) + b;
+		WRITE_LE_UINT16(dst + 640 * y + x, c);
+	}
+	m = (y4 - y3) / (x4 - x3);
+	b = (int)(-m * x3 + y3);
+	for (int x = x3; x <= x4; x++) {
+		int y = (int)(m * x) + b;
+		WRITE_LE_UINT16(dst + 640 * y + x, c);
+	}
+}

Modified: residual/trunk/driver_tinygl.h
===================================================================
--- residual/trunk/driver_tinygl.h	2007-01-30 12:14:45 UTC (rev 25280)
+++ residual/trunk/driver_tinygl.h	2007-01-30 12:38:26 UTC (rev 25281)
@@ -90,6 +90,7 @@
 
 	void drawRectangle(PrimitiveObject *primitive);
 	void drawLine(PrimitiveObject *primitive);
+	void drawPolygon(PrimitiveObject *primitive);
 
 	void prepareSmushFrame(int width, int height, byte *bitmap);
 	void drawSmushFrame(int offsetX, int offsetY);

Modified: residual/trunk/lua.cpp
===================================================================
--- residual/trunk/lua.cpp	2007-01-30 12:14:45 UTC (rev 25280)
+++ residual/trunk/lua.cpp	2007-01-30 12:38:26 UTC (rev 25281)
@@ -125,7 +125,7 @@
 	lua_Object param = lua_getparam(num);
 	if (lua_isuserdata(param) && lua_tag(param) == MKID('PRIM'))
 		return static_cast<PrimitiveObject *>(lua_getuserdata(param));
-	luaL_argerror(num, "primitive (rectangle) expected");
+	luaL_argerror(num, "primitive expected");
 	return NULL;
 } 
 
@@ -2530,7 +2530,67 @@
 }
 
 static void DrawPolygon() {
-	stubWarning("DrawPolygon");
+	lua_Object tableObj1, tableObj2, pointObj;
+	int x1, y1, x2, y2, x3, y3, x4, y4;
+	Color color;
+
+	color._vals[0] = 255;
+	color._vals[1] = 255;
+	color._vals[2] = 255;
+
+	tableObj1 = lua_getparam(1);
+	tableObj2 = lua_getparam(2);
+
+	if (lua_istable(tableObj1)) {
+		lua_pushobject(tableObj1);
+		lua_pushnumber(1);
+		pointObj = lua_gettable();
+		x1 = lua_getnumber(pointObj);
+		lua_pushobject(tableObj1);
+		lua_pushnumber(2);
+		pointObj = lua_gettable();
+		y1 = lua_getnumber(pointObj);
+		lua_pushobject(tableObj1);
+		lua_pushnumber(3);
+		pointObj = lua_gettable();
+		x2 = lua_getnumber(pointObj);
+		lua_pushobject(tableObj1);
+		lua_pushnumber(4);
+		pointObj = lua_gettable();
+		y2 = lua_getnumber(pointObj);
+		lua_pushobject(tableObj1);
+		lua_pushnumber(5);
+		pointObj = lua_gettable();
+		x3 = lua_getnumber(pointObj);
+		lua_pushobject(tableObj1);
+		lua_pushnumber(6);
+		pointObj = lua_gettable();
+		y3 = lua_getnumber(pointObj);
+		lua_pushobject(tableObj1);
+		lua_pushnumber(7);
+		pointObj = lua_gettable();
+		x4 = lua_getnumber(pointObj);
+		lua_pushobject(tableObj1);
+		lua_pushnumber(8);
+		pointObj = lua_gettable();
+		y4 = lua_getnumber(pointObj);
+	} else {
+		lua_pushnil();
+	}
+
+	if (lua_istable(tableObj2)) {
+		lua_pushobject(tableObj2);
+		lua_pushstring("color");
+		lua_Object colorObj = lua_gettable();
+		if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKID('COLR')) {
+			color = static_cast<Color *>(lua_getuserdata(colorObj));
+		}
+	}
+
+	PrimitiveObject *p = new PrimitiveObject();
+	p->createPolygon(x1, y1, x2, y2, x3, y3, x4, y4, color);
+	g_engine->registerPrimitiveObject(p);
+	lua_pushusertag(p, MKID('PRIM'));
 }
 
 static void DrawLine() {
@@ -2548,7 +2608,7 @@
 	color._vals[1] = 255;
 	color._vals[2] = 255;
 
-	if (lua_istable(tableObj)){
+	if (lua_istable(tableObj)) {
 		lua_pushobject(tableObj);
 		lua_pushstring("color");
 		lua_Object colorObj = lua_gettable();
@@ -2600,12 +2660,26 @@
 		color = static_cast<Color *>(lua_getuserdata(colorObj));
 		pmodify->setColor(color);
 	}
+
 	lua_pushobject(tableObj);
 	lua_pushstring("y");
 	lua_Object yObj = lua_gettable();
 	if (!lua_isnil(yObj)) {
-		pmodify->setY1(atoi(lua_getstring(yObj)));
-		pmodify->setY2(atoi(lua_getstring(yObj)));
+		int y = atoi(lua_getstring(yObj));
+		if (pmodify->getType() == 4) {
+			int y1 = pmodify->getY1();
+			int y2 = pmodify->getY2();
+			int y3 = pmodify->getY3();
+			int y4 = pmodify->getY4();
+			int dy = y - y1;
+			pmodify->setY1(y1 + dy);
+			pmodify->setY2(y2 + dy);
+			pmodify->setY3(y3 + dy);
+			pmodify->setY4(y4 + dy);
+		} else {
+			pmodify->setY1(y);
+			pmodify->setY2(y);
+		}
 	}
 }
 

Modified: residual/trunk/primitives.cpp
===================================================================
--- residual/trunk/primitives.cpp	2007-01-30 12:14:45 UTC (rev 25280)
+++ residual/trunk/primitives.cpp	2007-01-30 12:38:26 UTC (rev 25281)
@@ -75,6 +75,19 @@
 	_type = 3;
 }
 
+void PrimitiveObject::createPolygon(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, Color color) {
+	_x1 = x1;
+	_y1 = y1;
+	_x2 = x2;
+	_y2 = y2;
+	_x3 = x3;
+	_y3 = y3;
+	_x4 = x4;
+	_y4 = y4;
+	_color = color;
+	_type = 4;
+}
+
 void PrimitiveObject::draw() {
 	assert(_type);
 
@@ -84,4 +97,6 @@
 		g_driver->drawBitmap(_bitmap);
 	else if (_type == 3)
 		g_driver->drawLine(this);
+	else if (_type == 4)
+		g_driver->drawPolygon(this);
 }

Modified: residual/trunk/primitives.h
===================================================================
--- residual/trunk/primitives.h	2007-01-30 12:14:45 UTC (rev 25280)
+++ residual/trunk/primitives.h	2007-01-30 12:38:26 UTC (rev 25281)
@@ -39,12 +39,20 @@
 	void createRectangle(int x1, int x2, int y1, int y2, Color color, bool filled);
 	void createBitmap(Bitmap *bitmap, int x, int y, bool transparent);
 	void createLine(int x1, int x2, int y1, int y2, Color color);
+	void createPolygon(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, Color color);
 	int getX1() { return _x1; }
+	int getY1() { return _y1; }
 	int getX2() { return _x2; }
-	int getY1() { return _y1; }
 	int getY2() { return _y2; }
+	int getX3() { return _x3; }
+	int getY3() { return _y3; }
+	int getX4() { return _x4; }
+	int getY4() { return _y4; }
 	void setY1(int coord) { _y1 = coord; }
 	void setY2(int coord) { _y2 = coord; }
+	void setY3(int coord) { _y3 = coord; }
+	void setY4(int coord) { _y4 = coord; }
+	int getType() { return _type; }
 	void setColor(Color color) { _color = color; }
 	Color getColor() { return _color; }
 	bool isFilled() { return _filled; }
@@ -53,7 +61,7 @@
 	Bitmap *getBitmapHandle() { assert(_bitmap); return _bitmap; }
 
 private:
-	int _x1, _x2, _y1, _y2;
+	int _x1, _y1, _x2, _y2, _x3, _y3, _x4, _y4;
 	Color _color;
 	bool _filled;
 	int _type;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list