CGUIFileSaveDialog

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
MolokoTheMole
Posts: 109
Joined: Tue Jan 09, 2007 1:18 pm

CGUIFileSaveDialog

Post by MolokoTheMole »

Why isn't this already implemented in Irrlicht I have no idea. Here is a save file dialog.

CGUIFileSaveDialog.h

Code: Select all

#ifndef __C_GUI_FILE_SAVE_DIALOG_H_INCLUDED__
#define __C_GUI_FILE_SAVE_DIALOG_H_INCLUDED__

#include "IGUIFileOpenDialog.h"
#include "IGUIButton.h"
#include "IGUIListBox.h"
#include "IGUIEditBox.h"
#include "IFileSystem.h"

namespace irr
{
namespace gui
{

	class CGUIFileSaveDialog : public IGUIFileOpenDialog
	{
	public:

		//! constructor
		CGUIFileSaveDialog(const wchar_t* title, IGUIEnvironment* environment, IGUIElement* parent, s32 id);

		//! destructor
		virtual ~CGUIFileSaveDialog();

		//! returns the filename of the selected file. Returns NULL, if no file was selected.
		virtual const wchar_t* getFilename();

		//! called if an event happened.
		virtual bool OnEvent(SEvent event);

		//! draws the element and its children
		virtual void draw();

		//! Returns the filename of the selected file. Returns NULL, if no file was selected.
//		virtual const wchar_t* getFilename();

	protected:

		//! fills the listbox with files.
		void fillListBox();

		//! sends the event that the file has been selected.
		void sendSelectedEvent();

		//! sends the event that the file choose process has been canceld
		void sendCancelEvent();

		core::position2d<s32> DragStart;
		core::stringw FileName;
		bool Dragging;
		IGUIButton* CloseButton;
		IGUIButton* OKButton;
		IGUIButton* CancelButton;
		IGUIListBox* FileBox;
		IGUIElement* FileNameText;
		IGUIElement* EventParent;
		io::IFileSystem* FileSystem;
		IGUIEditBox* FileEdit;

		io::IFileList* FileList;
	};


} // end namespace gui
} // end namespace irr

#endif
CGUIFileSaveDialog.cpp

Code: Select all

#include "CGUIFileSaveDialog.h"
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IVideoDriver.h"
#include "IGUIButton.h"
#include "IGUIStaticText.h"
#include "IGUIFont.h"
#include "IGUIFontBitmap.h"
#include "IFileList.h"
#include "irrstring.h"
//#include "os.h"

namespace irr
{
namespace gui
{

const s32 FOD_WIDTH = 350;
const s32 FOD_HEIGHT = 260;


//! constructor
CGUIFileSaveDialog::CGUIFileSaveDialog(const wchar_t* title, IGUIEnvironment* environment, IGUIElement* parent, s32 id)
: IGUIFileOpenDialog(environment, parent, id,
 core::rect<s32>((parent->getAbsolutePosition().getWidth()-FOD_WIDTH)/2,
					(parent->getAbsolutePosition().getHeight()-FOD_HEIGHT)/2,	
					(parent->getAbsolutePosition().getWidth()-FOD_WIDTH)/2+FOD_WIDTH,
					(parent->getAbsolutePosition().getHeight()-FOD_HEIGHT)/2+FOD_HEIGHT)),	
  Dragging(false), FileNameText(0), FileList(0)
{
	#ifdef _DEBUG
	IGUIElement::setDebugName("CGUIFileSaveDialog");
	#endif

	Text = title;

	IGUISkin* skin = Environment->getSkin();
	IGUISpriteBank* sprites = 0;
	video::SColor color(255,255,255,255);
	if (skin)
	{
		sprites = skin->getSpriteBank();
		color = skin->getColor(EGDC_WINDOW_SYMBOL);
	}

	s32 buttonw = environment->getSkin()->getSize(EGDS_WINDOW_BUTTON_WIDTH);
	s32 posx = RelativeRect.getWidth() - buttonw - 4;

	CloseButton = Environment->addButton(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw), this, -1, 
		L"", skin ? skin->getDefaultText(EGDT_MSG_BOX_OK) : L"Close");
	CloseButton->setSubElement(true);
	if (sprites)
	{
		CloseButton->setSpriteBank(sprites);
		CloseButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_CLOSE), color);
		CloseButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_CLOSE), color);
	}
	CloseButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
	CloseButton->grab();

	OKButton = Environment->addButton(
		core::rect<s32>(RelativeRect.getWidth()-80, 30, RelativeRect.getWidth()-10, 50), 
		this, -1, skin ? skin->getDefaultText(EGDT_MSG_BOX_OK) : L"OK");
	OKButton->setSubElement(true);
	OKButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
	OKButton->grab();

	CancelButton = Environment->addButton(
		core::rect<s32>(RelativeRect.getWidth()-80, 55, RelativeRect.getWidth()-10, 75), 
		this, -1, skin ? skin->getDefaultText(EGDT_MSG_BOX_CANCEL) : L"Cancel");
	CancelButton->setSubElement(true);
	CancelButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
	CancelButton->grab();

	FileBox = Environment->addListBox(core::rect<s32>(10, 55, RelativeRect.getWidth()-90, 230), this, -1, true);
	FileBox->setSubElement(true);
	FileBox->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
	FileBox->grab();

	FileEdit = Environment->addEditBox(0, core::rect<s32>(10, 235, RelativeRect.getWidth()-10, 255), true, this);
	FileEdit->setSubElement(true);
	FileEdit->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
	FileEdit->grab();

	FileNameText = Environment->addStaticText(0, core::rect<s32>(10, 30, RelativeRect.getWidth()-90, 50), true, false, this);
	FileNameText->setSubElement(true);
	FileNameText->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
	FileNameText->grab();

	FileSystem = Environment->getFileSystem();

	if (FileSystem)
		FileSystem->grab();

	fillListBox();

	FileEdit->setText( irr::core::stringw(FileSystem->getWorkingDirectory()).c_str() );
}



//! destructor
CGUIFileSaveDialog::~CGUIFileSaveDialog()
{
	if (CloseButton)
		CloseButton->drop();

	if (OKButton)
		OKButton->drop();

	if (CancelButton)
		CancelButton->drop();

	if (FileBox)
		FileBox->drop();

	if (FileNameText)
		FileNameText->drop();

	if (FileSystem)
		FileSystem->drop();

	if (FileList)
		FileList->drop();
}


//! returns the filename of the selected file. Returns NULL, if no file was selected.
const wchar_t* CGUIFileSaveDialog::getFilename()
{
	return FileName.c_str();
}



//! called if an event happened.
bool CGUIFileSaveDialog::OnEvent(SEvent event)
{
	switch(event.EventType)
	{
	case EET_GUI_EVENT:
		switch(event.GUIEvent.EventType)
		{
		case EGET_ELEMENT_FOCUS_LOST:
			Dragging = false;
			break;
		case EGET_BUTTON_CLICKED:
			if (event.GUIEvent.Caller == CloseButton ||
				event.GUIEvent.Caller == CancelButton)
			{
				sendCancelEvent();
				remove();
				return true;
			}
			else
			if (event.GUIEvent.Caller == OKButton && FileName != L"")
			{
				sendSelectedEvent();
				remove();
				return true;
			}
			break;

		case EGET_LISTBOX_CHANGED:
			{
				s32 selected = FileBox->getSelected();
				if (FileList && FileSystem)
				{
					if (FileList->isDirectory(selected))
						FileName = L"";
					else
						FileName = FileList->getFullFileName(selected);

					FileEdit->setText( FileName.c_str() );
				}
			}
			break;

		case EGET_LISTBOX_SELECTED_AGAIN:
			{
				s32 selected = FileBox->getSelected();
				if (FileList && FileSystem)
				{
					if (FileList->isDirectory(selected))
					{
						FileSystem->changeWorkingDirectoryTo(FileList->getFileName(selected));
						fillListBox();
						FileName = L"";
					}
					else
					{
						FileName = FileList->getFullFileName(selected);
						return true;
					}
				}
			}
			break;
		}
		break;
	case EET_KEY_INPUT_EVENT:
		FileName = FileEdit->getText();
		break;
	case EET_MOUSE_INPUT_EVENT:
		switch(event.MouseInput.Event)
		{
		case EMIE_LMOUSE_PRESSED_DOWN:
			DragStart.X = event.MouseInput.X;
			DragStart.Y = event.MouseInput.Y;
			Dragging = true;
			Environment->setFocus(this);
			return true;
		case EMIE_LMOUSE_LEFT_UP:
			Dragging = false;
			Environment->removeFocus(this);
			return true;
		case EMIE_MOUSE_MOVED:
			if (Dragging)
			{
				// gui window should not be dragged outside its parent
				if (Parent)
					if (event.MouseInput.X < Parent->getAbsolutePosition().UpperLeftCorner.X +1 ||
						event.MouseInput.Y < Parent->getAbsolutePosition().UpperLeftCorner.Y +1 ||
						event.MouseInput.X > Parent->getAbsolutePosition().LowerRightCorner.X -1 ||
						event.MouseInput.Y > Parent->getAbsolutePosition().LowerRightCorner.Y -1)

						return true;

				move(core::position2d<s32>(event.MouseInput.X - DragStart.X, event.MouseInput.Y - DragStart.Y));
				DragStart.X = event.MouseInput.X;
				DragStart.Y = event.MouseInput.Y;
				return true;
			}
			break;
		}
	}

	return Parent ? Parent->OnEvent(event) : false;
}


//! draws the element and its children
void CGUIFileSaveDialog::draw()
{
	if (!IsVisible)
		return;

	IGUISkin* skin = Environment->getSkin();

	core::rect<s32> rect = AbsoluteRect;

	rect = skin->draw3DWindowBackground(this, true, skin->getColor(EGDC_ACTIVE_BORDER), 
		rect, &AbsoluteClippingRect);

	if (Text.size())
	{
		rect.UpperLeftCorner.X += 2;
		rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5;

		IGUIFont* font = skin->getFont(EGDF_WINDOW);
		if (font)
			font->draw(Text.c_str(), rect, skin->getColor(EGDC_ACTIVE_CAPTION), false, true, 
			&AbsoluteClippingRect);
	}

	IGUIElement::draw();
}


//! fills the listbox with files.
void CGUIFileSaveDialog::fillListBox()
{
	IGUISkin *skin = Environment->getSkin();

	if (!FileSystem || !FileBox || !skin)
		return;

	if (FileList)
		FileList->drop();

	FileBox->clear();

	FileList = FileSystem->createFileList();
	core::stringw s;

	for (s32 i=0; i<FileList->getFileCount(); ++i)
	{
		s = FileList->getFileName(i);
		FileBox->addItem(s.c_str(), skin->getIcon(FileList->isDirectory(i) ? EGDI_DIRECTORY : EGDI_FILE));
	}

	if (FileNameText)
	{
		s = FileSystem->getWorkingDirectory();
		FileNameText->setText(s.c_str());
	}
}


//! sends the event that the file has been selected.
void CGUIFileSaveDialog::sendSelectedEvent()
{
	SEvent event;
	event.EventType = EET_GUI_EVENT;
	event.GUIEvent.Caller = this;
	event.GUIEvent.EventType = EGET_FILE_SELECTED;
	Parent->OnEvent(event);
}

//! sends the event that the file choose process has been canceld
void CGUIFileSaveDialog::sendCancelEvent()
{
	SEvent event;
	event.EventType = EET_GUI_EVENT;
	event.GUIEvent.Caller = this;
	event.GUIEvent.EventType = EGET_FILE_CHOOSE_DIALOG_CANCELLED;
	Parent->OnEvent(event);
}

} // end namespace gui
} // end namespace irr

Example of usage (retrieving file name same as open dialog; EGET_FILE_SELECTED event is fired):

Code: Select all

	
CGUIFileSaveDialog* dialog = new CGUIFileSaveDialog(L"Title", gui, gui->getRootGUIElement(), -1);
dialog->drop();
Crimson Glory full Irrlicht game source code!
What I Do - my blog & dev log
Currently developing Link-Dead
zet.dp.ua
Posts: 66
Joined: Sat Jul 07, 2007 8:10 am

Post by zet.dp.ua »

thanks, this is useful for me
kszych
Posts: 2
Joined: Sat Jul 26, 2008 11:57 am

FileSaveDialog

Post by kszych »

Hello
I'm a begginer so please be patient.
I have copied this code, and I'm trying to use it in my project.
I've built working user interface, and it can open files (meshes and textures) and some other things. Now I want to save files.
I have copied this code, and I'm trying to use it in my project.
When I put Your example of usage into my project there are errors:

error: cannot allocate an object of type `irr::gui::CGUIFileSaveDialog'
error: because the following virtual functions are abstract:
.../irrlicht-1.4.1/include/IGUIFileOpenDialog.h:28: error: virtual const wchar_t*

I've added CGUIFileSaveDialog.cpp and CGUIFileSaveDialog.h to the project. I've also copied CGUIFileSaveDialog.h to Include directory.

I've noticed that this line is ok to compiler:

CGUIFileSaveDialog* dialog;

The errors ocure during compilation of this line:
dialog = new CGUIFileSaveDialog(t, okno, okno->getRootGUIElement, -1);

okno is:
IGUIEnvironment* okno = Device->getGUIEnvironment();

... and Device is:

IrrlichtDevice *Device

"t" is:
const wchar_t* t=0;

I'm using Code::Blocks with GNU GCC Compiler and Windows XP.

Thank you for any help
kszych
Posts: 2
Joined: Sat Jul 26, 2008 11:57 am

Ok

Post by kszych »

Ok, now I know - It's all due to differences between Irrlicht 1.4 and Irrlicht 1.3. It's working with 1.3 version...
pera
Posts: 460
Joined: Wed May 14, 2008 1:05 pm
Location: Novi Sad, Serbia
Contact:

Post by pera »

Here is Irrlicht 1.4 code:

CGUIFileSaveDialog.h

Code: Select all

/*This file is downloaded from irrlicht forum.
* http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=23210&highlight=iguifileopendialog
* Code is not changed here. It is dialog for saving map files.
* It is made by MolokoTheMole - big thanks to him.
*/
#ifndef __C_GUI_FILE_SAVE_DIALOG_H_INCLUDED__
#define __C_GUI_FILE_SAVE_DIALOG_H_INCLUDED__

#include "IGUIFileOpenDialog.h"
#include "IGUIButton.h"
#include "IGUIListBox.h"
#include "IGUIEditBox.h"
#include "IFileSystem.h"

namespace irr
{
namespace gui
{

   class CGUIFileSaveDialog : public IGUIFileOpenDialog
   {
   public:

      //! constructor
      CGUIFileSaveDialog(const wchar_t* title, IGUIEnvironment* environment, IGUIElement* parent, s32 id);

      //! destructor
      virtual ~CGUIFileSaveDialog();

		//! returns the filename of the selected file. Returns NULL, if no file was selected.
		virtual const wchar_t* getFileName() const;

		//! called if an event happened.
		virtual bool OnEvent(const SEvent& event);

      //! draws the element and its children
      virtual void draw();

      //! Returns the filename of the selected file. Returns NULL, if no file was selected.
//      virtual const wchar_t* getFilename();

   protected:

      //! fills the listbox with files.
      void fillListBox();

      //! sends the event that the file has been selected.
      void sendSelectedEvent();

      //! sends the event that the file choose process has been canceld
      void sendCancelEvent();

      core::position2d<s32> DragStart;
      core::stringw FileName;
      bool Dragging;
      IGUIButton* CloseButton;
      IGUIButton* OKButton;
      IGUIButton* CancelButton;
      IGUIListBox* FileBox;
      IGUIElement* FileNameText;
      IGUIElement* EventParent;
      io::IFileSystem* FileSystem;
      IGUIEditBox* FileEdit;

      io::IFileList* FileList;
   };


} // end namespace gui
} // end namespace irr

#endif
CGUIFileSaveDialog.cpp

Code: Select all

#include "CGUIFileSaveDialog.h"
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IVideoDriver.h"
#include "IGUIButton.h"
#include "IGUIStaticText.h"
#include "IGUIFont.h"
#include "IGUIFontBitmap.h"
#include "IFileList.h"
#include "irrstring.h"

namespace irr
{
namespace gui
{

const s32 FOD_WIDTH = 350;
const s32 FOD_HEIGHT = 250;


//! constructor
CGUIFileSaveDialog::CGUIFileSaveDialog(const wchar_t* title, 
		IGUIEnvironment* environment, IGUIElement* parent, s32 id)
: IGUIFileOpenDialog(environment, parent, id,
		core::rect<s32>((parent->getAbsolutePosition().getWidth()-FOD_WIDTH)/2,
					(parent->getAbsolutePosition().getHeight()-FOD_HEIGHT)/2,   
					(parent->getAbsolutePosition().getWidth()-FOD_WIDTH)/2+FOD_WIDTH,
					(parent->getAbsolutePosition().getHeight()-FOD_HEIGHT)/2+FOD_HEIGHT)),   
  Dragging(false), FileNameText(0), FileList(0)
{
   #ifdef _DEBUG
   IGUIElement::setDebugName("CGUIFileSaveDialog");
   #endif

   Text = title;

   IGUISkin* skin = Environment->getSkin();
   IGUISpriteBank* sprites = 0;
   video::SColor color(255,255,255,255);
   if (skin)
   {
      sprites = skin->getSpriteBank();
      color = skin->getColor(EGDC_WINDOW_SYMBOL);
   }

   s32 buttonw = environment->getSkin()->getSize(EGDS_WINDOW_BUTTON_WIDTH);
   s32 posx = RelativeRect.getWidth() - buttonw - 4;

   CloseButton = Environment->addButton(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw), this, -1,
      L"", skin ? skin->getDefaultText(EGDT_MSG_BOX_OK) : L"Close");
   CloseButton->setSubElement(true);
   if (sprites)
   {
      CloseButton->setSpriteBank(sprites);
      CloseButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_CLOSE), color);
      CloseButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_CLOSE), color);
   }
   CloseButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
   CloseButton->grab();

   OKButton = Environment->addButton(
      core::rect<s32>(RelativeRect.getWidth()-80, 30, RelativeRect.getWidth()-10, 50),
      this, -1, skin ? skin->getDefaultText(EGDT_MSG_BOX_OK) : L"OK");
   OKButton->setSubElement(true);
   OKButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
   OKButton->grab();

   CancelButton = Environment->addButton(
      core::rect<s32>(RelativeRect.getWidth()-80, 55, RelativeRect.getWidth()-10, 75),
      this, -1, skin ? skin->getDefaultText(EGDT_MSG_BOX_CANCEL) : L"Cancel");
   CancelButton->setSubElement(true);
   CancelButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
   CancelButton->grab();

   FileBox = Environment->addListBox(core::rect<s32>(10, 55, RelativeRect.getWidth()-90, 230), this, -1, true);
   FileBox->setSubElement(true);
   FileBox->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
   FileBox->grab();

   FileEdit = Environment->addEditBox(0, core::rect<s32>(10, 235, RelativeRect.getWidth()-10, 255), true, this);
   FileEdit->setSubElement(true);
   FileEdit->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
   FileEdit->grab();

   FileNameText = Environment->addStaticText(0, core::rect<s32>(10, 30, RelativeRect.getWidth()-90, 50), true, false, this);
   FileNameText->setSubElement(true);
   FileNameText->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
   FileNameText->grab();

   FileSystem = Environment->getFileSystem();

   if (FileSystem)
      FileSystem->grab();

   fillListBox();

   FileEdit->setText( irr::core::stringw(FileSystem->getWorkingDirectory()).c_str() );
}



//! destructor
CGUIFileSaveDialog::~CGUIFileSaveDialog()
{
   if (CloseButton)
      CloseButton->drop();

   if (OKButton)
      OKButton->drop();

   if (CancelButton)
      CancelButton->drop();

   if (FileBox)
      FileBox->drop();

   if (FileNameText)
      FileNameText->drop();

   if (FileSystem)
      FileSystem->drop();

   if (FileList)
      FileList->drop();
}


//! returns the filename of the selected file. Returns NULL, if no file was selected.
const wchar_t* CGUIFileSaveDialog::getFileName() const
{
   return FileName.c_str();
}



//! called if an event happened.
bool CGUIFileSaveDialog::OnEvent(const SEvent& event)
{
   switch(event.EventType)
   {
   case EET_GUI_EVENT:
      switch(event.GUIEvent.EventType)
      {
      case EGET_ELEMENT_FOCUS_LOST:
         Dragging = false;
         break;
      case EGET_BUTTON_CLICKED:
         if (event.GUIEvent.Caller == CloseButton ||
            event.GUIEvent.Caller == CancelButton)
         {
            sendCancelEvent();
            remove();
            return true;
         }
         else
         if (event.GUIEvent.Caller == OKButton && FileName != L"")
         {
            sendSelectedEvent();
            remove();
            return true;
         }
         break;

      case EGET_LISTBOX_CHANGED:
         {
            s32 selected = FileBox->getSelected();
            if (FileList && FileSystem)
            {
               if (FileList->isDirectory(selected))
                  FileName = L"";
               else
                  FileName = FileList->getFullFileName(selected);

               FileEdit->setText( FileName.c_str() );
            }
         }
         break;

      case EGET_LISTBOX_SELECTED_AGAIN:
         {
            s32 selected = FileBox->getSelected();
            if (FileList && FileSystem)
            {
               if (FileList->isDirectory(selected))
               {
                  FileSystem->changeWorkingDirectoryTo(FileList->getFileName(selected));
                  fillListBox();
                  FileName = L"";
               }
               else
               {
                  FileName = FileList->getFullFileName(selected);
                  return true;
               }
            }
         }
         break;
      }
      break;
   case EET_KEY_INPUT_EVENT:
      FileName = FileEdit->getText();
      break;
   case EET_MOUSE_INPUT_EVENT:
      switch(event.MouseInput.Event)
      {
      case EMIE_LMOUSE_PRESSED_DOWN:
         DragStart.X = event.MouseInput.X;
         DragStart.Y = event.MouseInput.Y;
         Dragging = true;
         Environment->setFocus(this);
         return true;
      case EMIE_LMOUSE_LEFT_UP:
         Dragging = false;
         Environment->removeFocus(this);
         return true;
      case EMIE_MOUSE_MOVED:
         if (Dragging)
         {
            // gui window should not be dragged outside its parent
            if (Parent)
               if (event.MouseInput.X < Parent->getAbsolutePosition().UpperLeftCorner.X +1 ||
                  event.MouseInput.Y < Parent->getAbsolutePosition().UpperLeftCorner.Y +1 ||
                  event.MouseInput.X > Parent->getAbsolutePosition().LowerRightCorner.X -1 ||
                  event.MouseInput.Y > Parent->getAbsolutePosition().LowerRightCorner.Y -1)

                  return true;

            move(core::position2d<s32>(event.MouseInput.X - DragStart.X, event.MouseInput.Y - DragStart.Y));
            DragStart.X = event.MouseInput.X;
            DragStart.Y = event.MouseInput.Y;
            return true;
         }
         break;
      }
   }

   return Parent ? Parent->OnEvent(event) : false;
}


//! draws the element and its children
void CGUIFileSaveDialog::draw()
{
   if (!IsVisible)
      return;

   IGUISkin* skin = Environment->getSkin();

   core::rect<s32> rect = AbsoluteRect;

   rect = skin->draw3DWindowBackground(this, true, skin->getColor(EGDC_ACTIVE_BORDER),
      rect, &AbsoluteClippingRect);

   if (Text.size())
   {
      rect.UpperLeftCorner.X += 2;
      rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5;

      IGUIFont* font = skin->getFont(EGDF_WINDOW);
      if (font)
         font->draw(Text.c_str(), rect, skin->getColor(EGDC_ACTIVE_CAPTION), false, true,
         &AbsoluteClippingRect);
   }

   IGUIElement::draw();
}


//! fills the listbox with files.
void CGUIFileSaveDialog::fillListBox()
{
   IGUISkin *skin = Environment->getSkin();

   if (!FileSystem || !FileBox || !skin)
      return;

   if (FileList)
      FileList->drop();

   FileBox->clear();

   FileList = FileSystem->createFileList();
   core::stringw s;

   for (u32 i=0; i<FileList->getFileCount(); ++i)
   {
      s = FileList->getFileName(i);
      FileBox->addItem(s.c_str(), skin->getIcon(FileList->isDirectory(i) ? EGDI_DIRECTORY : EGDI_FILE));
   }

   if (FileNameText)
   {
      s = FileSystem->getWorkingDirectory();
      FileNameText->setText(s.c_str());
   }
}


//! sends the event that the file has been selected.
void CGUIFileSaveDialog::sendSelectedEvent()
{
   SEvent event;
   event.EventType = EET_GUI_EVENT;
   event.GUIEvent.Caller = this;
   event.GUIEvent.Element = 0;
   event.GUIEvent.EventType = EGET_FILE_SELECTED;
   Parent->OnEvent(event);
}

//! sends the event that the file choose process has been canceld
void CGUIFileSaveDialog::sendCancelEvent()
{
   SEvent event;
   event.EventType = EET_GUI_EVENT;
   event.GUIEvent.Caller = this;
   event.GUIEvent.Element = 0;
   event.GUIEvent.EventType = EGET_FILE_CHOOSE_DIALOG_CANCELLED;
   Parent->OnEvent(event);
}

} // end namespace gui
} // end namespace irr 
only small changes are made so now it should work out of the box.[/code]
Post Reply