Adding the TabControl

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.
Locked
HantaCore
Posts: 21
Joined: Wed Mar 22, 2006 4:38 pm

Adding the TabControl

Post by HantaCore »

To add TabControl support to IrrlichtNET.dll, add the following files to the solution:

IGUITab.h
IGUITab.cpp
IGUITabControl.h
IGUITabControl.cpp

you will have to edit
IGUIEnvironment.h
IGUIEnvironment.cpp

Sorry for the lack of comments, and for the commented useless lines, you can delete them, I really need more time to improve this.

Code in IGUITab.h

Code: Select all

// Copyright (C) 2002-2005 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h

#pragma once

#using <mscorlib.dll>
using namespace System;

#pragma unmanaged
#include "..\\irrlicht\\include\\irrlicht.h"
#pragma managed

#include "Color.h"
#include "IGUIElement.h"

namespace Irrlicht
{
	namespace GUI
	{
		public __gc class IGUIFont;

		/// <summary>
		/// Default list box GUI element.
		/// </summary>
		public __gc class IGUITab : public IGUIElement
		{
		public:
			/// <summary>
			/// You should access the IGUIElement 
			/// through the methods in IGUIEnvironment. Simply don't use
			/// this constructor.
			///</summary>
			///<param name="font">The real, unmanaged C++ element</param>
			IGUITab(irr::gui::IGUITab* Tab);

			~IGUITab();

			int GetIndex();
			void SetBackgroundColor(Video::Color c);
			void SetDrawBackground(bool Draw);

			/// <summary>
			/// Returns the internal pointer to the native C++ irrlicht element.
			/// Do not use this, only needed by the internal .NET wrapper.
			///</summary>
			__property inline irr::gui::IGUITab* get_NativeTab()
			{
				return (irr::gui::IGUITab*)Element;
			}
		};
	}
}

Code in IGUITab.cpp

Code: Select all

// Copyright (C) 2002-2005 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h

#include "IGUITab.h"
#include "NativeConverter.h"
#include <vcclr.h> // for PtrToStringChars
#include "IGUIFont.h"

namespace Irrlicht
{
namespace GUI
{
	IGUITab::IGUITab(irr::gui::IGUITab* e)
		: IGUIElement(e)
	{
	}

	IGUITab::~IGUITab()
	{
	}

	int IGUITab::GetIndex()
	{
		return get_NativeTab()->getNumber();
	}

	void IGUITab::SetBackgroundColor(Video::Color c)
	{
		get_NativeTab()->setBackgroundColor(irr::NativeConverter::getNativeColor(c));
	}

	void IGUITab::SetDrawBackground(bool Draw)
	{
		get_NativeTab()->setDrawBackground(Draw);
	}

}
}

Code in IGUITabControl.h

Code: Select all

// Copyright (C) 2002-2005 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h

#pragma once

#using <mscorlib.dll>
using namespace System;

#pragma unmanaged
#include "..\\irrlicht\\include\\irrlicht.h"
#pragma managed

#include "IGUIElement.h"
#include "IGUITab.h"

namespace Irrlicht
{
	namespace GUI
	{
		public __gc class IGUIFont;

		/// <summary>
		/// Default list box GUI element.
		/// </summary>
		public __gc class IGUITabControl : public IGUIElement
		{
		public:
			/// <summary>
			/// You should access the IGUIElement 
			/// through the methods in IGUIEnvironment. Simply don't use
			/// this constructor.
			///</summary>
			///<param name="font">The real, unmanaged C++ element</param>
			IGUITabControl(irr::gui::IGUITabControl* tabControl);

			~IGUITabControl();

			int GetActiveTab();
			int GetTabCount();
			bool SetActiveTab(int TabIndex);

			IGUITab* AddTab(System::String* Caption, int Index);
			IGUITab* GetTab(int TabIndex);

			/// <summary>
			/// Returns the internal pointer to the native C++ irrlicht element.
			/// Do not use this, only needed by the internal .NET wrapper.
			///</summary>
			__property inline irr::gui::IGUITabControl* get_NativeTabControl()
			{
				return (irr::gui::IGUITabControl*)Element;
			}
		};
	}
}
Code in IGUITabControl.cpp

Code: Select all

// Copyright (C) 2002-2005 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h

#include "IGUITabControl.h"
#include "NativeConverter.h"
#include <vcclr.h> // for PtrToStringChars
#include "IGUIFont.h"

namespace Irrlicht
{
namespace GUI
{
	IGUITabControl::IGUITabControl(irr::gui::IGUITabControl* e)
		: IGUIElement(e)
	{
	}

	IGUITabControl::~IGUITabControl()
	{
	}			
	
	int IGUITabControl::GetActiveTab()
	{
		return get_NativeTabControl()->getActiveTab();
	}

	int IGUITabControl::GetTabCount()
	{
		return get_NativeTabControl()->getTabcount();
	}

	bool IGUITabControl::SetActiveTab(int TabIndex)
	{
		return get_NativeTabControl()->setActiveTab(TabIndex);
	}

	IGUITab* IGUITabControl::AddTab(System::String* Caption, int Index)
	{
		//wchar_t * pinchars = PtrToStringChars(Caption);  
		wchar_t __pin* pinchars = PtrToStringChars(Caption);  
		//pin_ptr<const wchar_t> pinchars = PtrToStringChars(Caption);
		return new IGUITab(get_NativeTabControl()->addTab(pinchars,Index));
	}

	IGUITab* IGUITabControl::GetTab(int TabIndex)
	{
		return new IGUITab(get_NativeTabControl()->getTab(TabIndex));
	}
}
}
Add to IGUIEnvironment.h

Code: Select all

		IGUITabControl* AddTabControl(System::String* text, Core::Rect position,
			bool fillBackground, bool border, IGUIElement* parent, int id);

		IGUITab* AddTab(System::String* text, Core::Rect position,
			bool fillBackground, bool border, IGUIElement* parent, int id);

Add to IGUIEnvironment.cpp

Code: Select all

	IGUITabControl* IGUIEnvironment::AddTabControl(System::String* text, Core::Rect position,
		bool fillBackground, bool border, IGUIElement* parent, int id)
	{
		const wchar_t __pin* ntext = PtrToStringChars(text); 
		irr::gui::IGUITabControl* e = Environment->addTabControl (
			irr::NativeConverter::getNativeRect(position), 
			parent ? parent->get_NativeElement() : 0, 
			fillBackground, 
			border, 
			id);

		if (!e)
			return 0;

		e->setText(ntext);

		return new IGUITabControl(e);
	}

	IGUITab* IGUIEnvironment::AddTab(System::String* text, Core::Rect position,
		bool fillBackground, bool border, IGUIElement* parent, int id)
	{
		const wchar_t __pin* ntext = PtrToStringChars(text); 
		irr::gui::IGUITab* e = Environment->addTab(
			irr::NativeConverter::getNativeRect(position), 
			parent ? parent->get_NativeElement() : 0, 
			id);

		if (!e)
			return 0;

		e->setText(ntext);

		return new IGUITab(e);
	}
Currently working on a C# MMORPG using Irrlicht.NET
Locked