Page 1 of 1

Why no recti and rectf typedefs?

Posted: Sat Jan 03, 2009 2:37 am
by Ion Dune
I noticed there weren't any typedefs for rects like there are for other core tools (like vector3d - vector3df and vector3di), which I found a bit odd. I made a patch that added these typedefs along with a function for drawing the outline of a rectangle through the video driver (and also capitalized some d's and fixed some an's - because I'm pedantic):

Code: Select all

Index: include/IVideoDriver.h
===================================================================
--- include/IVideoDriver.h	(revision 2023)
+++ include/IVideoDriver.h	(working copy)
@@ -569,7 +569,7 @@
 		virtual void draw2DRectangle(SColor color, const core::rect<s32>& pos,
 			const core::rect<s32>* clip = 0) = 0;
 
-		//! Draws an 2d rectangle with a gradient.
+		//! Draws a 2d rectangle with a gradient.
 		/** \param colorLeftUp Color of the upper left corner to draw.
 		The alpha component will not be ignored and specifies how
 		transparent the rectangle will be.
@@ -591,6 +591,15 @@
 				SColor colorLeftDown, SColor colorRightDown,
 				const core::rect<s32>* clip = 0) = 0;
 
+		//! Draws the outline of a 2D rectangle.
+		/** \param pos Position of the rectangle.
+		\param color Color of the rectangle to draw. The alpha
+		component will not be ignored and specifies how transparent the
+		rectangle outline will be.
+		*/
+		virtual void draw2DRectangleOutline(const core::recti& pos, 
+				SColor color=SColor(255,255,255,255)) = 0 ;
+
 		//! Draws a 2d line.
 		/** \param start: Screen coordinates of the start of the line
 		in pixels.
Index: include/rect.h
===================================================================
--- include/rect.h	(revision 2023)
+++ include/rect.h	(working copy)
@@ -252,6 +252,8 @@
 		position2d<T> LowerRightCorner;
 	};
 
+	typedef rect<f32> rectf;
+	typedef rect<s32> recti;
 
 } // end namespace core
 } // end namespace irr
Index: source/Irrlicht/CNullDriver.cpp
===================================================================
--- source/Irrlicht/CNullDriver.cpp	(revision 2023)
+++ source/Irrlicht/CNullDriver.cpp	(working copy)
@@ -669,7 +669,7 @@
 }
 
 
-//! draws an 2d image, using a color (if color is other then Color(255,255,255,255)) and the alpha channel of the texture if wanted.
+//! Draws a 2d image, using a color (if color is other then Color(255,255,255,255)) and the alpha channel of the texture if wanted.
 void CNullDriver::draw2DImage(const video::ITexture* texture, const core::position2d<s32>& destPos,
 				const core::rect<s32>& sourceRect,
 				const core::rect<s32>* clipRect, SColor color,
@@ -678,8 +678,17 @@
 }
 
 
+//! Draws the outline of a 2d rectangle
+void CNullDriver::draw2DRectangleOutline(const core::recti& pos, SColor color)
+{
+	draw2DLine( pos.UpperLeftCorner , core::position2di( pos.LowerRightCorner.X , pos.UpperLeftCorner.Y ) , color ) ;
+	draw2DLine( core::position2di( pos.LowerRightCorner.X , pos.UpperLeftCorner.Y ) , pos.LowerRightCorner , color ) ;
+	draw2DLine( pos.LowerRightCorner , core::position2di( pos.UpperLeftCorner.X , pos.LowerRightCorner.Y ) , color ) ;
+	draw2DLine( core::position2di( pos.UpperLeftCorner.X , pos.LowerRightCorner.Y ) , pos.UpperLeftCorner , color ) ;
+}
 
-//! draw an 2d rectangle
+
+//! Draw a 2d rectangle
 void CNullDriver::draw2DRectangle(SColor color, const core::rect<s32>& pos, const core::rect<s32>* clip)
 {
 	draw2DRectangle(pos, color, color, color, color, clip);
@@ -687,7 +696,7 @@
 
 
 
-//!Draws an 2d rectangle with a gradient.
+//! Draws a 2d rectangle with a gradient.
 void CNullDriver::draw2DRectangle(const core::rect<s32>& pos,
 	SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
 	const core::rect<s32>* clip)
Index: source/Irrlicht/CNullDriver.h
===================================================================
--- source/Irrlicht/CNullDriver.h	(revision 2023)
+++ source/Irrlicht/CNullDriver.h	(working copy)
@@ -163,7 +163,7 @@
 				SColor color=SColor(255,255,255,255),
 				bool useAlphaChannelOfTexture=false);
 
-		//! draws an 2d image, using a color (if color is other then Color(255,255,255,255)) and the alpha channel of the texture if wanted.
+		//! Draws a 2d image, using a color (if color is other then Color(255,255,255,255)) and the alpha channel of the texture if wanted.
 		virtual void draw2DImage(const video::ITexture* texture, const core::position2d<s32>& destPos,
 			const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
 			SColor color=SColor(255,255,255,255), bool useAlphaChannelOfTexture=false);
@@ -173,14 +173,17 @@
 			const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
 			const video::SColor* const colors=0, bool useAlphaChannelOfTexture=false);
 
-		//! draw an 2d rectangle
+		//! Draws a 2d rectangle
 		virtual void draw2DRectangle(SColor color, const core::rect<s32>& pos, const core::rect<s32>* clip = 0);
 
-		//!Draws an 2d rectangle with a gradient.
+		//! Draws a 2d rectangle with a gradient.
 		virtual void draw2DRectangle(const core::rect<s32>& pos,
 			SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
 			const core::rect<s32>* clip = 0);
 
+		//! Draws the outline of a 2d rectangle
+		virtual void draw2DRectangleOutline(const core::recti& pos, SColor color=SColor(255,255,255,255));
+
 		//! Draws a 2d line.
 		virtual void draw2DLine(const core::position2d<s32>& start,
 					const core::position2d<s32>& end,

Re: Why no recti and rectf typedefs?

Posted: Sat Jan 03, 2009 2:32 pm
by zillion42
Ion Dune wrote:I noticed there weren't any typedefs for rects like there are for other core tools (like vector3d - vector3df and vector3di), which I found a bit odd. I made a patch that added these typedefs along with a function for drawing the outline of a rectangle through the video driver (and also capitalized some d's and fixed some an's - because I'm pedantic):
well there certainly already was:

typedef dimension2d< f32 > dimension2df = Typedef for an f32 dimension.
typedef dimension2d< s32 > dimension2di = Typedef for an integer dimension.

aswell as:

typedef vector2d< f32 > vector2df = Typedef for f32 2d vector.
typedef vector2d< s32 > vector2di = Typedef for integer 2d vector.

EDIT:
I find your post quite amusing btw...

Posted: Sat Jan 03, 2009 2:39 pm
by MasterGod
How about adding a test case to rogerborg's test project showing your patch works?
Maybe they would like it and add it to the lib, who knows..

Posted: Sat Jan 03, 2009 7:30 pm
by Ion Dune
@zillion42: Yeah, that's why I found it odd. It seems there were typedefs for everything except rects.

@MasterGod: Well, I made a simple example:

Code: Select all

#include <irrlicht.h>

using namespace irr;

#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif

int main()
{
	IrrlichtDevice *device =
		createDevice( video::EDT_OPENGL, core::dimension2di(640, 480), 16,
			false, false, false, 0);
	video::IVideoDriver* driver = device->getVideoDriver();

	while(device->run())
	{
		driver->beginScene(true, true, video::SColor(255,100,101,140));

		core::recti r;
		r.UpperLeftCorner = core::vector2di(1,1);
		r.LowerRightCorner = device->getCursorControl()->getPosition();
		driver->draw2DRectangleOutline( r ) ;

		r += core::vector2di( 10 , 10 ) ;
		driver->draw2DRectangleOutline( r , video::SColor(128, 255, 128, 128) ) ;

		driver->endScene();
	}

	device->drop();
	return 0;
}
But I'm not sure how I would go about adding this to his test cases... or should I just submit this to the patch tracker?

Posted: Mon Jan 05, 2009 3:52 pm
by rogerborg
Patch tracker is always good.

I've just updated the tests/tests-readme.txt file on the 1.5 branch to hopefully describe how to add a test. It's basically what you've got, except with a slightly different entry point, and a screenshot at the end instead of while(device->run()) loop.

I know it seems like it would be quicker for me to just do it myself and commit this, but the more we can help each other out by getting into the habit of writing unit tests, the more robust Irrlicht will be.

Posted: Thu Jan 08, 2009 1:33 am
by Ion Dune