Why no recti and rectf typedefs?

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Why no recti and rectf typedefs?

Post 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,
zillion42
Posts: 324
Joined: Wed Aug 29, 2007 12:32 am
Location: Hamburg, Germany

Re: Why no recti and rectf typedefs?

Post 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...
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post 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..
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Post 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?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post 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.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Post by Ion Dune »

Post Reply