Difference between revisions of "PropertyFinder"
(→PropertyFinder.h) |
(Added an export button, Wiki format) |
||
Line 17: | Line 17: | ||
#include <direct.h> | #include <direct.h> | ||
#include <map> | #include <map> | ||
+ | #include <vector> | ||
+ | #include <algorithm> | ||
class DemoSample : public CEGuiSample | class DemoSample : public CEGuiSample | ||
Line 24: | Line 26: | ||
{ | { | ||
using namespace CEGUI; | using namespace CEGUI; | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
try | try | ||
{ | { | ||
Line 63: | Line 49: | ||
mProperties = static_cast<CEGUI::Listbox*>(winMgr.getWindow("PropertyFinder/Properties")); | mProperties = static_cast<CEGUI::Listbox*>(winMgr.getWindow("PropertyFinder/Properties")); | ||
mInformation = static_cast<CEGUI::MultiLineEditbox*>(winMgr.getWindow("PropertyFinder/Information")); | mInformation = static_cast<CEGUI::MultiLineEditbox*>(winMgr.getWindow("PropertyFinder/Information")); | ||
+ | mRadioButton = static_cast<CEGUI::RadioButton*>(winMgr.getWindow("PropertyFinder/ExportWiki")); | ||
− | // Configure the | + | // Configure the schemes |
− | mSchemes->subscribeEvent(Combobox::EventTextChanged, Event::Subscriber(&DemoSample::onSchemeChanged, this)); | + | mSchemes->subscribeEvent(Combobox::EventTextChanged, Event::Subscriber(&DemoSample::onSchemeChanged, this)); |
− | mSchemes->subscribeEvent(Combobox::EventListSelectionAccepted, Event::Subscriber(&DemoSample::onSchemeChanged, this)); | + | mSchemes->subscribeEvent(Combobox::EventListSelectionAccepted, Event::Subscriber(&DemoSample::onSchemeChanged, this)); |
mSchemes->setSortingEnabled(true); | mSchemes->setSortingEnabled(true); | ||
− | mWidgets->subscribeEvent(Combobox::EventTextChanged, Event::Subscriber(&DemoSample::onWidgetChanged, this)); | + | |
− | mWidgets->subscribeEvent(Combobox::EventListSelectionAccepted, Event::Subscriber(&DemoSample::onWidgetChanged, this)); | + | // Configure the widgets |
+ | mWidgets->subscribeEvent(Combobox::EventTextChanged, Event::Subscriber(&DemoSample::onWidgetChanged, this)); | ||
+ | mWidgets->subscribeEvent(Combobox::EventListSelectionAccepted, Event::Subscriber(&DemoSample::onWidgetChanged, this)); | ||
mWidgets->setSortingEnabled(true); | mWidgets->setSortingEnabled(true); | ||
+ | |||
+ | // Configure the properties | ||
mProperties->setSortingEnabled(true); | mProperties->setSortingEnabled(true); | ||
mProperties->setMultiselectEnabled(false); | mProperties->setMultiselectEnabled(false); | ||
− | mProperties->subscribeEvent(Listbox::EventSelectionChanged, Event::Subscriber(&DemoSample::onPropertyChanged, this)); | + | mProperties->subscribeEvent(Listbox::EventSelectionChanged, Event::Subscriber(&DemoSample::onPropertyChanged, this)); |
+ | |||
+ | // Configure the export | ||
+ | CEGUI::PushButton* btnExport = static_cast<CEGUI::PushButton*>(winMgr.getWindow("PropertyFinder/Export")); | ||
+ | btnExport->subscribeEvent(PushButton::EventClicked, Event::Subscriber(&DemoSample::onExport, this)); | ||
+ | mRadioButton->setGroupID(1); | ||
+ | mRadioButton->setID(Wiki); | ||
+ | mRadioButton->setSelected(true); | ||
+ | CEGUI::RadioButton* radioButton = static_cast<CEGUI::RadioButton*>(winMgr.getWindow("PropertyFinder/ExportHtml")); | ||
+ | radioButton->setGroupID(1); | ||
+ | radioButton->setID(Html); | ||
+ | radioButton->setSelected(false); | ||
+ | radioButton = static_cast<CEGUI::RadioButton*>(winMgr.getWindow("PropertyFinder/ExportXml")); | ||
+ | radioButton->setGroupID(1); | ||
+ | radioButton->setID(Xml); | ||
+ | radioButton->setSelected(false); | ||
// Load every scheme | // Load every scheme | ||
Line 111: | Line 117: | ||
_findclose( hFile ); | _findclose( hFile ); | ||
} | } | ||
− | |||
// Parse the loaded schemes and determine their internal names (as widget prefixes) | // Parse the loaded schemes and determine their internal names (as widget prefixes) | ||
Line 165: | Line 170: | ||
mSchemes->addItem(schemeItem); | mSchemes->addItem(schemeItem); | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
Line 178: | Line 176: | ||
// Refresh the widget list | // Refresh the widget list | ||
mWidgets->resetList(); | mWidgets->resetList(); | ||
+ | getWidgets( mSchemes->getText() ); | ||
+ | |||
+ | CEGUI::ListboxTextItem* widgetItem; | ||
+ | WidgetList::iterator itWidgetList; | ||
+ | for(itWidgetList = mWidgetList.begin(); itWidgetList != mWidgetList.end(); itWidgetList++) | ||
+ | { | ||
+ | widgetItem = new CEGUI::ListboxTextItem( (*itWidgetList) ); | ||
+ | widgetItem->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush"); | ||
+ | mWidgets->addItem(widgetItem); | ||
+ | } | ||
+ | |||
+ | // Select the first widget | ||
+ | if(mWidgets->getItemCount() > 0) | ||
+ | { | ||
+ | mWidgets->setText( mWidgets->getListboxItemFromIndex(0)->getText() ); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | mWidgets->setText(""); | ||
+ | } | ||
+ | |||
+ | return true; | ||
+ | } | ||
+ | |||
+ | void getWidgets(const CEGUI::String& pScheme) | ||
+ | { | ||
+ | mWidgetList.clear(); | ||
− | |||
const CEGUI::String separator("/"); | const CEGUI::String separator("/"); | ||
CEGUI::String currentFal; | CEGUI::String currentFal; | ||
Line 191: | Line 215: | ||
pos = currentFal.find(separator); | pos = currentFal.find(separator); | ||
newLook = currentFal.substr(0, pos); | newLook = currentFal.substr(0, pos); | ||
− | if( | + | if(pScheme.compare(newLook) == 0) |
{ | { | ||
widget = currentFal.substr(pos + 1); | widget = currentFal.substr(pos + 1); | ||
− | + | mWidgetList.push_back(widget); | |
} | } | ||
itFalagardMapping++; | itFalagardMapping++; | ||
} | } | ||
− | + | std::sort( mWidgetList.begin(), mWidgetList.end() ); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
Line 216: | Line 230: | ||
// Refresh the property list | // Refresh the property list | ||
mProperties->resetList(); | mProperties->resetList(); | ||
− | + | getProperties( mSchemes->getText(), mWidgets->getText() ); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
CEGUI::ListboxTextItem* propertyItem; | CEGUI::ListboxTextItem* propertyItem; | ||
− | + | PropertyList::iterator itPropertyList; | |
− | + | for(itPropertyList = mPropertyList.begin(); itPropertyList != mPropertyList.end(); itPropertyList++) | |
{ | { | ||
− | propertyItem = new CEGUI::ListboxTextItem( | + | propertyItem = new CEGUI::ListboxTextItem( (*itPropertyList).first ); |
propertyItem->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush"); | propertyItem->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush"); | ||
mProperties->addItem(propertyItem); | mProperties->addItem(propertyItem); | ||
− | |||
− | |||
− | |||
} | } | ||
− | |||
− | |||
// Select the first property | // Select the first property | ||
Line 244: | Line 247: | ||
mProperties->setItemSelectState(selectedProperty, true); | mProperties->setItemSelectState(selectedProperty, true); | ||
mProperties->ensureItemIsVisible(selectedProperty); | mProperties->ensureItemIsVisible(selectedProperty); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | mInformation->setText(""); | ||
} | } | ||
return true; | return true; | ||
+ | } | ||
+ | |||
+ | void getProperties(const CEGUI::String& pScheme, const CEGUI::String& pWidget) | ||
+ | { | ||
+ | const CEGUI::String separator("/"); | ||
+ | mPropertyList.clear(); | ||
+ | |||
+ | try | ||
+ | { | ||
+ | CEGUI::Window* widget = CEGUI::WindowManager::getSingleton().createWindow(pScheme + separator + pWidget); | ||
+ | CEGUI::PropertySet::Iterator itPropertySet = ((CEGUI::PropertySet*) widget)->getIterator(); | ||
+ | while (!itPropertySet.isAtEnd() ) | ||
+ | { | ||
+ | mPropertyList[itPropertySet.getCurrentKey()] = (*itPropertySet)->getHelp(); | ||
+ | itPropertySet++; | ||
+ | } | ||
+ | CEGUI::WindowManager::getSingleton().destroyWindow(widget); | ||
+ | } | ||
+ | catch(...) | ||
+ | { | ||
+ | // Silently ignore errors | ||
+ | // TaharezLook/TabPane generates one such error | ||
+ | } | ||
} | } | ||
Line 255: | Line 285: | ||
if(selectedItem) | if(selectedItem) | ||
{ | { | ||
− | + | PropertyList::iterator itPropertyList = mPropertyList.find( selectedItem->getText() ); | |
− | if( | + | if( itPropertyList != mPropertyList.end() ) |
{ | { | ||
− | mInformation->setText( (* | + | mInformation->setText( (*itPropertyList).second ); |
} | } | ||
} | } | ||
Line 267: | Line 297: | ||
return true; | return true; | ||
+ | } | ||
+ | |||
+ | bool onExport(const CEGUI::EventArgs& args) | ||
+ | { | ||
+ | CEGUI::uint exportType = mRadioButton->getSelectedButtonInGroup()->getID(); | ||
+ | switch(exportType) | ||
+ | { | ||
+ | case Wiki: | ||
+ | ExportWiki(); | ||
+ | break; | ||
+ | case Html: | ||
+ | ExportHtml(); | ||
+ | break; | ||
+ | case Xml: | ||
+ | ExportXml(); | ||
+ | break; | ||
+ | } | ||
+ | |||
+ | return true; | ||
+ | } | ||
+ | |||
+ | void ExportWiki() | ||
+ | { | ||
+ | std::ofstream out("PropertyFinder.txt"); | ||
+ | const CEGUI::String sectionHeader("==="); | ||
+ | const CEGUI::String widgetHeader("===="); | ||
+ | const CEGUI::String propertyHeader("===="); | ||
+ | |||
+ | PropertyList completePropertyList; | ||
+ | |||
+ | CEGUI::String schemeName; | ||
+ | WidgetList::iterator itWidgetList; | ||
+ | PropertyList::iterator itPropertyList; | ||
+ | |||
+ | const int propertiesPerLine = 5; | ||
+ | int propertiesOnLine; | ||
+ | |||
+ | /******************* Option 1 *******************/ | ||
+ | // Export every detected scheme | ||
+ | /* | ||
+ | for(size_t schemeItem = 0; schemeItem < mSchemes->getItemCount(); schemeItem++) | ||
+ | { | ||
+ | schemeName = mSchemes->getListboxItemFromIndex(schemeItem)->getText(); | ||
+ | getWidgets(schemeName); | ||
+ | if(mWidgetList.size() == 0) | ||
+ | { | ||
+ | continue; | ||
+ | } | ||
+ | */ | ||
+ | |||
+ | /******************* Option 2 *******************/ | ||
+ | // Only export the currently selected scheme | ||
+ | { | ||
+ | schemeName = mSchemes->getText(); | ||
+ | getWidgets(schemeName); | ||
+ | /************** End of the options **************/ | ||
+ | |||
+ | |||
+ | out << sectionHeader | ||
+ | << " " | ||
+ | << schemeName | ||
+ | << " " | ||
+ | << sectionHeader | ||
+ | << "\n"; | ||
+ | |||
+ | for(itWidgetList = mWidgetList.begin(); itWidgetList != mWidgetList.end(); itWidgetList++) | ||
+ | { | ||
+ | getProperties( schemeName, (*itWidgetList) ); | ||
+ | if(mPropertyList.size() == 0) | ||
+ | { | ||
+ | continue; | ||
+ | } | ||
+ | |||
+ | out << widgetHeader | ||
+ | << " " | ||
+ | << (*itWidgetList) | ||
+ | << " " | ||
+ | << widgetHeader | ||
+ | << "\n"; | ||
+ | |||
+ | propertiesOnLine = 0; | ||
+ | out << "{| class=\"wikitable\" border=\"1\" \n"; | ||
+ | for(itPropertyList = mPropertyList.begin(); itPropertyList != mPropertyList.end(); itPropertyList++) | ||
+ | { | ||
+ | if( propertiesOnLine == propertiesPerLine ) | ||
+ | { | ||
+ | out << "|-\n"; | ||
+ | propertiesOnLine = 0; | ||
+ | } | ||
+ | |||
+ | out << "| [[#" | ||
+ | << (*itPropertyList).first | ||
+ | << "]]\n"; | ||
+ | ++propertiesOnLine; | ||
+ | |||
+ | if( completePropertyList.find( (*itPropertyList).first ) == completePropertyList.end() ) | ||
+ | { | ||
+ | completePropertyList[(*itPropertyList).first] = (*itPropertyList).second; | ||
+ | } | ||
+ | } | ||
+ | out << "|}\n\n"; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | out << sectionHeader | ||
+ | << " Properties " | ||
+ | << sectionHeader | ||
+ | << "\n"; | ||
+ | PropertyList::iterator itCompletePropertyList; | ||
+ | for(itCompletePropertyList = completePropertyList.begin(); | ||
+ | itCompletePropertyList != completePropertyList.end(); | ||
+ | itCompletePropertyList++) | ||
+ | { | ||
+ | out << propertyHeader | ||
+ | << " " | ||
+ | << (*itCompletePropertyList).first | ||
+ | << " " | ||
+ | << propertyHeader | ||
+ | << "\n" | ||
+ | << (*itCompletePropertyList).second | ||
+ | << "\n"; | ||
+ | } | ||
+ | |||
+ | out.close(); | ||
+ | } | ||
+ | |||
+ | void ExportHtml() | ||
+ | { | ||
+ | } | ||
+ | |||
+ | void ExportXml() | ||
+ | { | ||
} | } | ||
Line 280: | Line 442: | ||
CEGUI::Listbox* mProperties; | CEGUI::Listbox* mProperties; | ||
− | typedef std::map<CEGUI::String, CEGUI::String> | + | // Type of list of widgets for a scheme |
− | + | typedef std::vector<CEGUI::String> WidgetList; | |
+ | |||
+ | // List of widgets for a scheme | ||
+ | WidgetList mWidgetList; | ||
+ | |||
+ | // Type of list of properties for a widget <property, help> | ||
+ | typedef std::map<CEGUI::String, CEGUI::String> PropertyList; | ||
+ | |||
+ | // List of properties for a widget | ||
+ | PropertyList mPropertyList; | ||
// Widget displaying additional information on a property | // Widget displaying additional information on a property | ||
CEGUI::MultiLineEditbox* mInformation; | CEGUI::MultiLineEditbox* mInformation; | ||
+ | |||
+ | // Radiobutton part of a group | ||
+ | CEGUI::RadioButton* mRadioButton; | ||
+ | |||
+ | // Defines the types of export | ||
+ | enum ExportType :CEGUI::uint {Wiki, Html, Xml}; | ||
}; | }; | ||
Revision as of 01:33, 1 May 2007
Introduction
This code creates a tool to list the properties associated with the widgets of a scheme. It loads the .scheme files from within the Scheme directory and displays the widgets defined within that scheme. Selecting a widget will list every property associated to that widget by default. And selecting a property will display its help.
Please discuss this snippet within the Property Finder thread.
Files
PropertyFinder.h
<cpp/>
- ifndef _PropertyFinder_h_
- define _PropertyFinder_h_
- include "CEGuiSample.h"
- include "CEGUI.h"
- include "CEGUIDefaultResourceProvider.h"
- include <io.h>
- include <direct.h>
- include <map>
- include <vector>
- include <algorithm>
class DemoSample : public CEGuiSample { public:
bool initialiseSample()
{ using namespace CEGUI; try { // Retrieve the window manager WindowManager& winMgr = WindowManager::getSingleton();
// Load the TaharezLook scheme and set up the default mouse cursor and font Scheme* currentScheme = SchemeManager::getSingleton().loadScheme("TaharezLook.scheme"); System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow"); FontManager::getSingleton().createFont("Commonwealth-10.font");
// Set the GUI Sheet Window* sheet = winMgr.createWindow("DefaultWindow", "root_wnd"); System::getSingleton().setGUISheet(sheet);
// Load a layout Window* guiLayout = winMgr.loadWindowLayout("PropertyFinder.layout"); sheet->addChildWindow(guiLayout);
// Retrieve the handle to the often used widgets mSchemes = static_cast<CEGUI::Combobox*>(winMgr.getWindow("PropertyFinder/SchemeList")); mWidgets = static_cast<CEGUI::Combobox*>(winMgr.getWindow("PropertyFinder/WidgetList")); mProperties = static_cast<CEGUI::Listbox*>(winMgr.getWindow("PropertyFinder/Properties")); mInformation = static_cast<CEGUI::MultiLineEditbox*>(winMgr.getWindow("PropertyFinder/Information")); mRadioButton = static_cast<CEGUI::RadioButton*>(winMgr.getWindow("PropertyFinder/ExportWiki"));
// Configure the schemes mSchemes->subscribeEvent(Combobox::EventTextChanged, Event::Subscriber(&DemoSample::onSchemeChanged, this)); mSchemes->subscribeEvent(Combobox::EventListSelectionAccepted, Event::Subscriber(&DemoSample::onSchemeChanged, this)); mSchemes->setSortingEnabled(true);
// Configure the widgets mWidgets->subscribeEvent(Combobox::EventTextChanged, Event::Subscriber(&DemoSample::onWidgetChanged, this)); mWidgets->subscribeEvent(Combobox::EventListSelectionAccepted, Event::Subscriber(&DemoSample::onWidgetChanged, this)); mWidgets->setSortingEnabled(true);
// Configure the properties mProperties->setSortingEnabled(true); mProperties->setMultiselectEnabled(false); mProperties->subscribeEvent(Listbox::EventSelectionChanged, Event::Subscriber(&DemoSample::onPropertyChanged, this));
// Configure the export CEGUI::PushButton* btnExport = static_cast<CEGUI::PushButton*>(winMgr.getWindow("PropertyFinder/Export")); btnExport->subscribeEvent(PushButton::EventClicked, Event::Subscriber(&DemoSample::onExport, this)); mRadioButton->setGroupID(1); mRadioButton->setID(Wiki); mRadioButton->setSelected(true); CEGUI::RadioButton* radioButton = static_cast<CEGUI::RadioButton*>(winMgr.getWindow("PropertyFinder/ExportHtml")); radioButton->setGroupID(1); radioButton->setID(Html); radioButton->setSelected(false); radioButton = static_cast<CEGUI::RadioButton*>(winMgr.getWindow("PropertyFinder/ExportXml")); radioButton->setGroupID(1); radioButton->setID(Xml); radioButton->setSelected(false);
// Load every scheme loadEverySchemes(currentScheme); } catch(Exception &e) { #if defined( __WIN32__ ) || defined( _WIN32 ) MessageBox(NULL, e.getMessage().c_str(), "Error initializing the demo", MB_OK | MB_ICONERROR | MB_TASKMODAL); #else std::cerr << "Error initializing the demo:" << e.getMessage().c_str() << "\n"; #endif }
return true; }
void cleanupSample(void)
{ }
void loadEverySchemes(CEGUI::Scheme* pCurrentScheme) { // Locate the scheme directory and suffix the scheme file search pattern CEGUI::DefaultResourceProvider* rp = reinterpret_cast<CEGUI::DefaultResourceProvider*>(CEGUI::System::getSingleton().getResourceProvider()); CEGUI::String schemeDirectory = rp->getResourceGroupDirectory("schemes") + "\\*.scheme";
// Read the filtered contents of the scheme directory struct _finddata_t c_file; intptr_t hFile = _findfirst(schemeDirectory.c_str(), &c_file ); if(hFile != -1L) { do { loadScheme(c_file.name); } while( _findnext( hFile, &c_file ) == 0 ); _findclose( hFile ); }
// Parse the loaded schemes and determine their internal names (as widget prefixes) const CEGUI::String separator("/"); CEGUI::String currentFal; CEGUI::String::size_type pos; CEGUI::String newLook, currentLook; CEGUI::String widget; CEGUI::WindowFactoryManager::FalagardMappingIterator itFalagardMapping = CEGUI::WindowFactoryManager::getSingletonPtr()->getFalagardMappingIterator(); while( !itFalagardMapping.isAtEnd() ) { currentFal = itFalagardMapping.getCurrentKey(); pos = currentFal.find(separator); newLook = currentFal.substr(0, pos); if(currentLook.compare(newLook) != 0) { currentLook = newLook; addScheme(newLook); } itFalagardMapping++; }
// Select the "current" scheme CEGUI::ListboxItem* current = mSchemes->findItemWithText( pCurrentScheme->getName(), 0 ); if(current) { mSchemes->setText( pCurrentScheme->getName() ); } }
void loadScheme(const CEGUI::String& pScheme, const CEGUI::String& pResourceGroup = "") { try { if( !CEGUI::SchemeManager::getSingleton().isSchemePresent(pScheme) ) { CEGUI::Scheme* scheme = CEGUI::SchemeManager::getSingleton().loadScheme(pScheme, pResourceGroup); } } catch(...) { // Silently ignore errors } }
void addScheme(const CEGUI::String& pScheme) { if( !mSchemes->findItemWithText(pScheme, 0) ) { // This scheme has not yet been added CEGUI::ListboxTextItem* schemeItem = new CEGUI::ListboxTextItem(pScheme); schemeItem->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush"); mSchemes->addItem(schemeItem); } }
bool onSchemeChanged(const CEGUI::EventArgs& args) { // Refresh the widget list mWidgets->resetList(); getWidgets( mSchemes->getText() );
CEGUI::ListboxTextItem* widgetItem; WidgetList::iterator itWidgetList; for(itWidgetList = mWidgetList.begin(); itWidgetList != mWidgetList.end(); itWidgetList++) { widgetItem = new CEGUI::ListboxTextItem( (*itWidgetList) ); widgetItem->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush"); mWidgets->addItem(widgetItem); }
// Select the first widget if(mWidgets->getItemCount() > 0) { mWidgets->setText( mWidgets->getListboxItemFromIndex(0)->getText() ); } else { mWidgets->setText(""); }
return true; }
void getWidgets(const CEGUI::String& pScheme) { mWidgetList.clear();
const CEGUI::String separator("/"); CEGUI::String currentFal; CEGUI::String::size_type pos; CEGUI::String newLook; CEGUI::String widget; CEGUI::WindowFactoryManager::FalagardMappingIterator itFalagardMapping = CEGUI::WindowFactoryManager::getSingletonPtr()->getFalagardMappingIterator(); while( !itFalagardMapping.isAtEnd() ) { currentFal = itFalagardMapping.getCurrentKey(); pos = currentFal.find(separator); newLook = currentFal.substr(0, pos); if(pScheme.compare(newLook) == 0) { widget = currentFal.substr(pos + 1); mWidgetList.push_back(widget); } itFalagardMapping++; }
std::sort( mWidgetList.begin(), mWidgetList.end() ); }
bool onWidgetChanged(const CEGUI::EventArgs& args) { // Refresh the property list mProperties->resetList(); getProperties( mSchemes->getText(), mWidgets->getText() );
CEGUI::ListboxTextItem* propertyItem; PropertyList::iterator itPropertyList; for(itPropertyList = mPropertyList.begin(); itPropertyList != mPropertyList.end(); itPropertyList++) { propertyItem = new CEGUI::ListboxTextItem( (*itPropertyList).first ); propertyItem->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush"); mProperties->addItem(propertyItem); }
// Select the first property if(mProperties->getItemCount() > 0) { CEGUI::ListboxItem* selectedProperty = mProperties->getListboxItemFromIndex(0); mProperties->setItemSelectState(selectedProperty, true); mProperties->ensureItemIsVisible(selectedProperty); } else { mInformation->setText(""); }
return true; }
void getProperties(const CEGUI::String& pScheme, const CEGUI::String& pWidget) { const CEGUI::String separator("/"); mPropertyList.clear();
try { CEGUI::Window* widget = CEGUI::WindowManager::getSingleton().createWindow(pScheme + separator + pWidget); CEGUI::PropertySet::Iterator itPropertySet = ((CEGUI::PropertySet*) widget)->getIterator(); while (!itPropertySet.isAtEnd() ) { mPropertyList[itPropertySet.getCurrentKey()] = (*itPropertySet)->getHelp(); itPropertySet++; } CEGUI::WindowManager::getSingleton().destroyWindow(widget); } catch(...) { // Silently ignore errors // TaharezLook/TabPane generates one such error } }
bool onPropertyChanged(const CEGUI::EventArgs& args) { // Display the appropriate help information CEGUI::ListboxItem* selectedItem = mProperties->getFirstSelectedItem(); if(selectedItem) { PropertyList::iterator itPropertyList = mPropertyList.find( selectedItem->getText() ); if( itPropertyList != mPropertyList.end() ) { mInformation->setText( (*itPropertyList).second ); } } else { mInformation->setText(""); }
return true; }
bool onExport(const CEGUI::EventArgs& args) { CEGUI::uint exportType = mRadioButton->getSelectedButtonInGroup()->getID(); switch(exportType) { case Wiki: ExportWiki(); break; case Html: ExportHtml(); break; case Xml: ExportXml(); break; }
return true; }
void ExportWiki() { std::ofstream out("PropertyFinder.txt"); const CEGUI::String sectionHeader("==="); const CEGUI::String widgetHeader("===="); const CEGUI::String propertyHeader("====");
PropertyList completePropertyList;
CEGUI::String schemeName; WidgetList::iterator itWidgetList; PropertyList::iterator itPropertyList;
const int propertiesPerLine = 5; int propertiesOnLine;
/******************* Option 1 *******************/ // Export every detected scheme /* for(size_t schemeItem = 0; schemeItem < mSchemes->getItemCount(); schemeItem++) { schemeName = mSchemes->getListboxItemFromIndex(schemeItem)->getText(); getWidgets(schemeName); if(mWidgetList.size() == 0) { continue; } */
/******************* Option 2 *******************/ // Only export the currently selected scheme { schemeName = mSchemes->getText(); getWidgets(schemeName); /************** End of the options **************/
out << sectionHeader
<< " "
<< schemeName
<< " "
<< sectionHeader
<< "\n";
for(itWidgetList = mWidgetList.begin(); itWidgetList != mWidgetList.end(); itWidgetList++) { getProperties( schemeName, (*itWidgetList) ); if(mPropertyList.size() == 0) { continue; }
out << widgetHeader << " " << (*itWidgetList) << " " << widgetHeader << "\n";
propertiesOnLine = 0; out << "{| class=\"wikitable\" border=\"1\" \n"; for(itPropertyList = mPropertyList.begin(); itPropertyList != mPropertyList.end(); itPropertyList++) { if( propertiesOnLine == propertiesPerLine ) { out << "|-\n"; propertiesOnLine = 0; }
out << "| [[#" << (*itPropertyList).first << "]]\n"; ++propertiesOnLine;
if( completePropertyList.find( (*itPropertyList).first ) == completePropertyList.end() ) { completePropertyList[(*itPropertyList).first] = (*itPropertyList).second; } } out << "|}\n\n"; } }
out << sectionHeader << " Properties " << sectionHeader << "\n"; PropertyList::iterator itCompletePropertyList; for(itCompletePropertyList = completePropertyList.begin(); itCompletePropertyList != completePropertyList.end(); itCompletePropertyList++) { out << propertyHeader << " " << (*itCompletePropertyList).first << " " << propertyHeader << "\n" << (*itCompletePropertyList).second << "\n"; }
out.close(); }
void ExportHtml() { }
void ExportXml() { }
private:
// Widget containing the list of schemes CEGUI::Combobox* mSchemes;
// Widget containing the list of widgets in a scheme CEGUI::Combobox* mWidgets;
// Widget containing the list of properties CEGUI::Listbox* mProperties;
// Type of list of widgets for a scheme typedef std::vector<CEGUI::String> WidgetList;
// List of widgets for a scheme WidgetList mWidgetList;
// Type of list of properties for a widget <property, help> typedef std::map<CEGUI::String, CEGUI::String> PropertyList;
// List of properties for a widget PropertyList mPropertyList;
// Widget displaying additional information on a property CEGUI::MultiLineEditbox* mInformation;
// Radiobutton part of a group CEGUI::RadioButton* mRadioButton;
// Defines the types of export enum ExportType :CEGUI::uint {Wiki, Html, Xml}; };
- endif // _PropertyFinder_h_
Main.cpp
<cpp/>
- if defined( __WIN32__ ) || defined( _WIN32 )
#define WIN32_LEAN_AND_MEAN #define NOMINMAX #include "windows.h"
- endif
- include "PropertyFinder.h"
- if defined( __WIN32__ ) || defined( _WIN32 )
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow)
- else
int main(int argc, char *argv[])
- endif
{
DemoSample app; int i = app.run(); return i;
}
PropertyFinder.layout
<?xml version="1.0" encoding="UTF-8"?> <GUILayout > <Window Type="TaharezLook/FrameWindow" Name="PropertyFinder" > <Property Name="Text" Value="Property Finder" /> <Property Name="TitlebarFont" Value="Commonwealth-10" /> <Property Name="InheritsAlpha" Value="False" /> <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> <Property Name="TitlebarEnabled" Value="True" /> <Property Name="UnifiedAreaRect" Value="{{0.00937452,0},{0.0499997,0},{0.848439,0},{0.695834,0}}" /> <Window Type="TaharezLook/StaticText" Name="PropertyFinder/SchemeLabel" > <Property Name="Text" Value="Scheme:" /> <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> <Property Name="UnifiedAreaRect" Value="{{0.0195535,0},{0.109678,0},{0.114991,0},{0.201613,0}}" /> </Window> <Window Type="TaharezLook/Combobox" Name="PropertyFinder/SchemeList" > <Property Name="ReadOnly" Value="True" /> <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> <Property Name="UnifiedAreaRect" Value="{{0.116201,0},{0.109678,0},{0.440692,0},{0.875806,0}}" /> <Property Name="MaxEditTextLength" Value="1073741823" /> </Window> <Window Type="TaharezLook/StaticText" Name="PropertyFinder/WidgetLabel" > <Property Name="Font" Value="Commonwealth-10" /> <Property Name="Text" Value="Widget:" /> <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> <Property Name="UnifiedAreaRect" Value="{{0.473929,0},{0.109678,0},{0.569368,0},{0.201613,0}}" /> </Window> <Window Type="TaharezLook/Combobox" Name="PropertyFinder/WidgetList" > <Property Name="Font" Value="Commonwealth-10" /> <Property Name="ReadOnly" Value="True" /> <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> <Property Name="UnifiedAreaRect" Value="{{0.570578,0},{0.109678,0},{0.969551,0},{0.850001,0}}" /> <Property Name="MaxEditTextLength" Value="1073741823" /> </Window> <Window Type="TaharezLook/Listbox" Name="PropertyFinder/Properties" > <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> <Property Name="UnifiedAreaRect" Value="{{0.0195535,0},{0.225806,0},{0.440692,0},{0.972579,0}}" /> </Window> <Window Type="TaharezLook/MultiLineEditbox" Name="PropertyFinder/Information" > <Property Name="Text" > </Property> <Property Name="ReadOnly" Value="True" /> <Property Name="MaxTextLength" Value="1073741823" /> <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> <Property Name="UnifiedAreaRect" Value="{{0.473929,0},{0.225806,0},{0.969551,0},{0.972579,0}}" /> </Window> </Window> </GUILayout>