Folder Selector for CEGUI and win32

Forum for general chit-chat or off-topic discussion.

Moderators: CEGUI MVP, CEGUI Team

Ivanovich78
Just popping in
Just popping in
Posts: 16
Joined: Fri Feb 01, 2008 20:29

Folder Selector for CEGUI and win32

Postby Ivanovich78 » Fri Oct 10, 2008 10:23

Hello, CEGUI community!

I while ago I was looking for an open source folder selector for win32 based on CEGUI, but I didn't found anyone.
So I decided to make my own, and share it with others. This is how it looks:
Image

It's pretty simple so far, but if you just need a folder navigator that allows you to move trough directories and logical units, it can do the job.

I've tried to keep the things as simple as possible for the example purpose in the downloadable file below:
Download the MSVC2k8 project & source<--Contains Source and a pre-compiled example in folder bin
Wikified version<--Wikified documentation.

Folder selector is showed in a CEGUI Window, using the method:

Code: Select all

void show(CEGUI::Window* root);

Where root is the window where you want the folder selector to be showed.

Here you've got the Folder Selector header. As you can see, it uses DiskObject, wich is a small class without no more dependencies than "windows.h" and stl.

Code: Select all

#pragma once

#include <CEGUI.h>
#include "DiskObject.h"

class GUI_FolderSelector
{
public:
   GUI_FolderSelector();
   ~GUI_FolderSelector(void);

   /**
      @short makes the Folder selector to appear in CEGUI::Window
   */
   void show(CEGUI::Window* root);

   /**
      @short hide Folder Selector
   */
   void hide();

   /**
      @short Returns the last selected file
   */
   std::string getResult();

   /**
      @short set the current folder
   */
   void setFolder(std::string);

   /**
      @short sets the filter string. The string will be used to enable/disable OK
    button when files in the current folder matches the filter string
    (i.e., "*.jpg" string will enable OK button only when the current folder
    contains files with extension .jpg). By default is "*", showing all files.
   */
   void setFileFiler(std::string s){d_fileFilter = s;}

private:
   bool handleClick(const CEGUI::EventArgs& e);
   void wireEvents();
   void updateFolderList();
   DiskObject* disk;
   CEGUI::Window* frame;
   std::string d_result;
   std::string d_fileFilter;
   std::vector<std::string> d_itemList;
};


This is how main loop looks:

Code: Select all

#include "SDL.h"
#include "GUI_Menu.h"
#include "GUI_FolderSelector.h"

#define QUIT -1
#define MENU 0
#define FOLDER_SELECTOR 1

GUI_FolderSelector fs;

void init()
{
  // ... This is just an example, complete code in downloadable file
}

void setupCEGUI()
{
  // ... This is just an example, complete code in downloadable file
}

bool handleClick(const CEGUI::EventArgs &e)
{
  using namespace CEGUI;
  WindowManager& winMgr = WindowManager::getSingleton();
  Window* btn = static_cast<Window*>(winMgr.getWindow("Root/Play"));
      btn->setText(fs.getResult());

  return 0;
}

int main(int argc, char **argv)
{
  using namespace CEGUI;
  // init SDL/OpenGL Framework
  init();
  // init CEGUI
  setupCEGUI();
  // create main menu
  WindowManager& winMgr = WindowManager::getSingleton();
  GUI_Menu menu("menu.layout");

  //Main loop
  do
  {
    menu.injectInput();
    menu.render();
    if (menu.getState() == FOLDER_SELECTOR)
    {
      // makes appear the folder selector
      fs.show(CEGUI::System::getSingleton().getGUISheet());
      // Subscribe OK button event
      winMgr.getWindow("FolderSelector/Frame/Ok")->
        subscribeEvent(PushButton::EventClicked,
        Event::Subscriber(&handleClick));
      // back to menu (fs will auto-hide when done)
      menu.setState(MENU);
    }
    SDL_Delay(10);
  } while (menu.getState() != QUIT);
  return 0;
}


I know this is not the piece of code that is going to save the world, but it can (hopefully) save some minutes to other developers.
I want to thank CEGUI team for this magnificent library. A revision from you to my code will be a very good feedback :)
Any other feedback is also welcomed.
Last edited by Ivanovich78 on Wed Oct 29, 2008 18:22, edited 1 time in total.
My projects: www.ivan.org.es

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Mon Oct 13, 2008 09:22

Hi there,

Thanks for posting this :)

I think we also need a wikified version :mrgreen:

CE.

Ivanovich78
Just popping in
Just popping in
Posts: 16
Joined: Fri Feb 01, 2008 20:29

Postby Ivanovich78 » Sun Oct 19, 2008 21:51

My projects: www.ivan.org.es

Ivanovich78
Just popping in
Just popping in
Posts: 16
Joined: Fri Feb 01, 2008 20:29

Postby Ivanovich78 » Mon Oct 20, 2008 12:34

Hmmm....
I have placed the article in Tutorials section, but taking a more careful read to wiki organization, I wonder if should I move the article to User Contributed Material.
Is just change a couple of links (link on this page and wiki link).
My projects: www.ivan.org.es

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Sun Oct 26, 2008 10:11

Hi,

Thanks for the wiki version :)

Perhaps it would be more at home in the Code Snippets area?

CE.

Ivanovich78
Just popping in
Just popping in
Posts: 16
Joined: Fri Feb 01, 2008 20:29

Postby Ivanovich78 » Wed Oct 29, 2008 18:24

Sure :)
Moved to CodeSnippets.
My projects: www.ivan.org.es


Return to “Offtopic Discussion”

Who is online

Users browsing this forum: No registered users and 12 guests