Difference between revisions of "Folder Selector"

From CEGUI Wiki - Crazy Eddie's GUI System (Open Source)
Jump to: navigation, search
(Updated links. Added link to forum thread.)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Folder Selector]]
+
{{VersionBadge|0.5}} {{VersionBadge|0.6}} {{VersionBadge|0.7}}
  
Some times you may need to allow your application user to navigate trough system folders. This class allows you to easily integrate a folder selector in your game.<br>
+
Some times you may need to allow your application user to navigate trough system folders. This class allows you to easily integrate a folder selector in your game.<br />
  
Folder Selector uses DiskObject, a class that depends on <windows.h>. So, for now, there's no support for mac or linux users.<br>
+
Folder Selector uses DiskObject, a class that depends on <windows.h>. So, for now, there's no support for mac or linux users.<br />
  
 
----
 
----
<br>
+
<br />
'''Links'''<br>
+
'''Links'''<br />
* Image of the folder selector in action: [[http://ivan.org.es/cegui/fs_preview.JPG]]<br>
+
* Image of the folder selector in action: [http://ivan.org.es/cegui/fs preview.JPG]<br />
* A game currently using Folder Selector: [[http://www.ivan.org.es/showcase/gameview.php?id=2]]<br>
+
* A game currently using Folder Selector: [http://www.ivan.org.es/showcase/gameview.php?id=2]<br />
* Source, project for MSVC9.0 (with SDL & OpenGL) and a live-demo: [[http://ivan.org.es/cegui/FolderSelector.zip]]<br>
+
* Source, project for MSVC9.0 (with SDL & OpenGL) and a live-demo: [http://ivan.org.es/cegui/FolderSelector.zip]<br />
  
 
----
 
----
<br>
+
<br />
'''How to use it'''<br>
+
'''How to use it'''<br />
 
To use Folder Selector in your application, you must call the method:
 
To use Folder Selector in your application, you must call the method:
  
 +
<source lang="cpp">
 
  void show(CEGUI::Window* root);
 
  void show(CEGUI::Window* root);
 +
</source>
  
Where CEGUI::Window* root is a pointer to the window where you want the folder selector to be opened. A file called "fs.layout" contains the current layout used by folder selector.<br>
+
Where CEGUI::Window* root is a pointer to the window where you want the folder selector to be opened. A file called "fs.layout" contains the current layout used by folder selector.<br />
After that, the Folder Selector will be showed on the top and you just need to update CEGUI logic and render methods as usually. When the user selects a folder successfully or cancels the action, the folder selector hides again and your application takes the control back.<br>
+
After that, the Folder Selector will be showed on the top and you just need to update CEGUI logic and render methods as usually. When the user selects a folder successfully or cancels the action, the folder selector hides again and your application takes the control back.<br />
 
If you want to know which folder has been selected by the user, you can subscribe to the PushButton::EventClicked as follows:
 
If you want to know which folder has been selected by the user, you can subscribe to the PushButton::EventClicked as follows:
 +
 +
<source lang="cpp">
 
  // Subscribes the folder selector OK button pusehd event
 
  // Subscribes the folder selector OK button pusehd event
 
     winMgr.getWindow("FolderSelector/Frame/Ok")->
 
     winMgr.getWindow("FolderSelector/Frame/Ok")->
 
       subscribeEvent(PushButton::EventClicked,
 
       subscribeEvent(PushButton::EventClicked,
 
       Event::Subscriber(&handleClick));
 
       Event::Subscriber(&handleClick));
 +
</source>
  
 
And in your handle method, make a call to getResults() to know the selected folder:
 
And in your handle method, make a call to getResults() to know the selected folder:
  
 +
<source lang="cpp">
 
  bool handleClick(const CEGUI::EventArgs &e)
 
  bool handleClick(const CEGUI::EventArgs &e)
 
  {
 
  {
Line 36: Line 42:
 
   return 0;
 
   return 0;
 
  }
 
  }
 +
</source>
  
 
Below you can see the FolderSelector methods and a more complete example of how to use it.
 
Below you can see the FolderSelector methods and a more complete example of how to use it.
 
 
'''Public methods in FolderSelector.h'''
 
'''Public methods in FolderSelector.h'''
 
+
<source lang="cpp">
 
   /**
 
   /**
 
       @short makes the Folder selector to appear in CEGUI::Window
 
       @short makes the Folder selector to appear in CEGUI::Window
Line 68: Line 74:
 
   */
 
   */
 
   void setFileFiler(std::string s){d_fileFilter = s;}
 
   void setFileFiler(std::string s){d_fileFilter = s;}
 +
</source>
  
 
'''This is how the example looks:'''
 
'''This is how the example looks:'''
  
 +
<source lang="cpp">
 
  #include "SDL.h"
 
  #include "SDL.h"
 
  #include "GUI_Menu.h"
 
  #include "GUI_Menu.h"
Line 124: Line 132:
 
   return 0;
 
   return 0;
 
  }
 
  }
 +
</source>
  
 
If you've got some trouble running the example just let me know at this thread:
 
If you've got some trouble running the example just let me know at this thread:
http://www.cegui.org.uk/phpBB2/viewtopic.php?f=1&t=3597&start=0<br>
+
http://www.cegui.org.uk/phpBB2/viewtopic.php?f=1&t=3597&start=0<br />
--[[User:Ivanovich78|Ivanovich78]] 21:47, 19 October 2008 (UTC)
+
--[[User:Ivanovich78]] 21:47, 19 October 2008 (UTC)
 +
 
 +
[[Category:Tutorials]]

Latest revision as of 00:21, 4 March 2011

Written for CEGUI 0.5


Works with versions 0.5.x (obsolete)

Written for CEGUI 0.6


Works with versions 0.6.x (obsolete)

Written for CEGUI 0.7


Works with versions 0.7.x (obsolete)

Some times you may need to allow your application user to navigate trough system folders. This class allows you to easily integrate a folder selector in your game.

Folder Selector uses DiskObject, a class that depends on <windows.h>. So, for now, there's no support for mac or linux users.



Links

  • Image of the folder selector in action: preview.JPG
  • A game currently using Folder Selector: [1]
  • Source, project for MSVC9.0 (with SDL & OpenGL) and a live-demo: [2]


How to use it
To use Folder Selector in your application, you must call the method:

 void show(CEGUI::Window* root);

Where CEGUI::Window* root is a pointer to the window where you want the folder selector to be opened. A file called "fs.layout" contains the current layout used by folder selector.
After that, the Folder Selector will be showed on the top and you just need to update CEGUI logic and render methods as usually. When the user selects a folder successfully or cancels the action, the folder selector hides again and your application takes the control back.
If you want to know which folder has been selected by the user, you can subscribe to the PushButton::EventClicked as follows:

 // Subscribes the folder selector OK button pusehd event
     winMgr.getWindow("FolderSelector/Frame/Ok")->
       subscribeEvent(PushButton::EventClicked,
       Event::Subscriber(&handleClick));

And in your handle method, make a call to getResults() to know the selected folder:

 bool handleClick(const CEGUI::EventArgs &e)
 {
   using namespace CEGUI;
   WindowManager& winMgr = WindowManager::getSingleton();
   String selectedFolder(fs.getResult()); // now selectedFolder contains the full path of the directory selected.
   return 0;
 }

Below you can see the FolderSelector methods and a more complete example of how to use it. Public methods in FolderSelector.h

   /**
      @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;}

This is how the example looks:

 #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;
 }

If you've got some trouble running the example just let me know at this thread: http://www.cegui.org.uk/phpBB2/viewtopic.php?f=1&t=3597&start=0
--User:Ivanovich78 21:47, 19 October 2008 (UTC)