Something went wrong. Try again.
Massive multiplayer game aiming to create a collaborative musical environment.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719/*********************************************************************** filename: CEGUISystem.cpp created: 20/2/2004 author: Paul D Turner
purpose: Implementation of main system object*************************************************************************//*************************************************************************** * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif
#include "CEGUISystem.h"#include "CEGUIDefaultLogger.h"#include "CEGUIImagesetManager.h"#include "CEGUIFontManager.h"#include "CEGUIWindowFactoryManager.h"#include "CEGUIWindowManager.h"#include "CEGUISchemeManager.h"#include "CEGUIMouseCursor.h"#include "CEGUIWindow.h"#include "CEGUIImageset.h"#include "CEGUIExceptions.h"#include "elements/CEGUIBaseFactories.h"#include "CEGUIScriptModule.h"#include "CEGUIConfig_xmlHandler.h"#include "CEGUIDataContainer.h"#include "CEGUIResourceProvider.h"#include "CEGUIGlobalEventSet.h"#include "falagard/CEGUIFalWidgetLookManager.h"#include "CEGUIPropertyHelper.h"#include "CEGUIWindowRendererManager.h"#include "CEGUIDynamicModule.h"#include "CEGUIXMLParser.h"#include <ctime>#include <clocale>
//This block includes the proper headers when static linking#if defined(CEGUI_STATIC) #ifdef CEGUI_WITH_EXPAT #include "../XMLParserModules/expatParser/CEGUIExpatParserModule.h" #elif CEGUI_WITH_TINYXML #include "../XMLParserModules/TinyXMLParser/CEGUITinyXMLParserModule.h" #elif CEGUI_WITH_XERCES #include "../XMLParserModules/XercesParser/CEGUIXercesParserModule.h" #endif#endif
#define S_(X) #X#define STRINGIZE(X) S_(X)
// Start of CEGUI namespace sectionnamespace CEGUI{const String System::EventNamespace("System");
/*!\brief Simple timer class.*/class SimpleTimer{ double d_baseTime;
public: static double currentTime(); ///< returns time in seconds
SimpleTimer() : d_baseTime(currentTime()) {}
void restart() { d_baseTime = currentTime(); } double elapsed() { return currentTime() - d_baseTime; }};
#if defined(__WIN32__) || defined(_WIN32)#include <windows.h>double SimpleTimer::currentTime(){ return timeGetTime() / 1000.0;}
#elif defined(__linux__) || defined(__APPLE__)#include <sys/time.h>double SimpleTimer::currentTime(){ timeval timeStructure; gettimeofday(&timeStructure, 0); return timeStructure.tv_sec + timeStructure.tv_usec / 1000000.0;}#else#error "SimpleTimer not available for this platform, please implement it"#endif
/*!\brief Implementation structure used in tracking up & down mouse button inputs in order to generate click, double-click, and triple-click events.*/struct MouseClickTracker{ MouseClickTracker(void) : d_click_count(0), d_click_area(0, 0, 0, 0) {}
SimpleTimer d_timer; //!< Timer used to track clicks for this button. int d_click_count; //!< count of clicks made so far. Rect d_click_area; //!< area used to detect multi-clicks Window* d_target_window; //!< target window for any events generated.};
struct MouseClickTrackerImpl{ MouseClickTracker click_trackers[MouseButtonCount];};
/************************************************************************* Constants definitions*************************************************************************/const char System::CEGUIConfigSchemaName[] = "CEGUIConfig.xsd";
/************************************************************************* Static Data Definitions*************************************************************************/// singleton instance pointertemplate<> System* Singleton<System>::ms_Singleton = 0;
// click event generation defaultsconst double System::DefaultSingleClickTimeout = 0.2;const double System::DefaultMultiClickTimeout = 0.33;const Size System::DefaultMultiClickAreaSize(12,12);
// event namesconst String System::EventGUISheetChanged( "GUISheetChanged" );const String System::EventSingleClickTimeoutChanged( "SingleClickTimeoutChanged" );const String System::EventMultiClickTimeoutChanged( "MultiClickTimeoutChanged" );const String System::EventMultiClickAreaSizeChanged( "MultiClickAreaSizeChanged" );const String System::EventDefaultFontChanged( "DefaultFontChanged" );const String System::EventDefaultMouseCursorChanged( "DefaultMouseCursorChanged" );const String System::EventMouseMoveScalingChanged( "MouseMoveScalingChanged" );
// Holds name of default XMLParserString System::d_defaultXMLParserName(STRINGIZE(CEGUI_DEFAULT_XMLPARSER));
/************************************************************************* Constructor*************************************************************************/System::System(Renderer* renderer, ResourceProvider* resourceProvider, XMLParser* xmlParser, ScriptModule* scriptModule, const String& configFile, const String& logFile)
: d_renderer(renderer), d_resourceProvider(resourceProvider ? resourceProvider : d_renderer->createResourceProvider()), d_defaultFont(0), d_wndWithMouse(0), d_activeSheet(0), d_modalTarget(0), d_sysKeys(0), d_lshift(false), d_rshift(false), d_lctrl(false), d_rctrl(false), d_lalt(false), d_ralt(false), d_click_timeout(DefaultSingleClickTimeout), d_dblclick_timeout(DefaultMultiClickTimeout), d_dblclick_size(DefaultMultiClickAreaSize), d_clickTrackerPimpl(new MouseClickTrackerImpl), d_defaultMouseCursor(0), d_scriptModule(scriptModule), d_mouseScalingFactor(1.0f), d_xmlParser(xmlParser), d_ourXmlParser(false), d_parserModule(0), d_defaultTooltip(0), d_weOwnTooltip(false){ bool userCreatedLogger = true;
// Start out by fixing the numeric locale to C (we depend on this behaviour) // consider a UVector2 as a property {{0.5,0},{0.5,0}} could become {{0,5,0},{0,5,0}} setlocale(LC_NUMERIC, "C");
// Instantiate logger first (we have no file at this point, but entries will be cached until we do) // NOTE: If the user already created a logger prior to calling this constructor, // we mark it as so and leave the logger untouched. This allows the user to fully customize // the logger as he sees fit without fear of seeing its configuration overwritten by this. if (!Logger::getSingletonPtr()) { new DefaultLogger(); userCreatedLogger = false; }
// Set CEGUI version d_strVersion = PropertyHelper::uintToString(CEGUI_VERSION_MAJOR) + "." + PropertyHelper::uintToString(CEGUI_VERSION_MINOR) + "." + PropertyHelper::uintToString(CEGUI_VERSION_PATCH);
// handle initialisation and setup of the XML parser setupXMLParser();
// strings we may get from the configuration file. String configLogname, configSchemeName, configLayoutName, configInitScript, defaultFontName;
// now XML is available, read the configuration file (if any) if (!configFile.empty()) { // create handler object Config_xmlHandler handler;
// do parsing of xml file try { d_xmlParser->parseXMLFile(handler, configFile, CEGUIConfigSchemaName, ""); } catch(...) { // cleanup XML stuff d_xmlParser->cleanup(); delete d_xmlParser;
throw; }
// Set the logging level if the user didn't create a logger beforehand if(!userCreatedLogger) Logger::getSingleton().setLoggingLevel(handler.getLoggingLevel());
// get the strings read configLogname = handler.getLogFilename(); configSchemeName = handler.getSchemeFilename(); configLayoutName = handler.getLayoutFilename(); defaultFontName = handler.getDefaultFontName(); configInitScript = handler.getInitScriptFilename(); d_termScriptName = handler.getTermScriptFilename();
// set default resource group if it was specified. if (!handler.getDefaultResourceGroup().empty()) { d_resourceProvider->setDefaultResourceGroup(handler.getDefaultResourceGroup()); } }
// Start up the logger if the user didn't create a logger beforehand if(!userCreatedLogger) { // Prefer log filename from config file if (!configLogname.empty()) { Logger::getSingleton().setLogFilename(configLogname, false); } // No log specified in configuration, use default / hard-coded option else { Logger::getSingleton().setLogFilename(logFile, false); } }
// beginning main init Logger::getSingleton().logEvent("---- Begining CEGUI System initialisation ----");
// create the core system singleton objects createSingletons();
// add the window factories for the core window types addStandardWindowFactories();
// GUISheet's name was changed, register an alias so both can be used WindowFactoryManager::getSingleton().addWindowTypeAlias("DefaultGUISheet", GUISheet::WidgetTypeName);
// success - we are created! Log it for prosperity :) outputLogHeader();
// subscribe to hear about display mode changes d_rendererCon = d_renderer->subscribeEvent(Renderer::EventDisplaySizeChanged, Event::Subscriber(&CEGUI::System::handleDisplaySizeChange, this));
// load base scheme if (!configSchemeName.empty()) { try { SchemeManager::getSingleton().loadScheme(configSchemeName, d_resourceProvider->getDefaultResourceGroup());
// set default font if that was specified also if (!defaultFontName.empty()) { setDefaultFont(defaultFontName); }
} catch (CEGUI::Exception&) {} // catch exception and try to continue anyway
}
// load initial layout if (!configLayoutName.empty()) { try { setGUISheet(WindowManager::getSingleton().loadWindowLayout(configLayoutName)); } catch (CEGUI::Exception&) {} // catch exception and try to continue anyway
}
// Create script module bindings if (d_scriptModule) { d_scriptModule->createBindings(); }
// execute start up script if (!configInitScript.empty()) { try { executeScriptFile(configInitScript); } catch (...) {} // catch all exceptions and try to continue anyway
}}
/************************************************************************* Destructor*************************************************************************/System::~System(void){ Logger::getSingleton().logEvent("---- Begining CEGUI System destruction ----");
// execute shut-down script if (!d_termScriptName.empty()) { try { executeScriptFile(d_termScriptName); } catch (...) {} // catch all exceptions and continue system shutdown
}
// unsubscribe from the renderer d_rendererCon->disconnect();
// cleanup XML stuff cleanupXMLParser();
// // perform cleanup in correct sequence // // ensure no windows get created during destruction. NB: I'm allowing the // potential exception to escape here so as to make it obvious that client // code should really be adjusted to not create windows during cleanup. WindowManager::getSingleton().lock(); // destroy windows so it's safe to destroy factories WindowManager::getSingleton().destroyAllWindows(); WindowManager::getSingleton().cleanDeadPool();
// remove factories so it's safe to unload GUI modules WindowFactoryManager::getSingleton().removeAllFactories();
// Cleanup script module bindings if (d_scriptModule) d_scriptModule->destroyBindings();
// cleanup singletons destroySingletons();
char addr_buff[32]; sprintf(addr_buff, "(%p)", static_cast<void*>(this)); Logger::getSingleton().logEvent("CEGUI::System singleton destroyed. " + String(addr_buff)); Logger::getSingleton().logEvent("---- CEGUI System destruction completed ----"); delete Logger::getSingletonPtr();
delete d_clickTrackerPimpl;}
/************************************************************************* Render the GUI for this frame*************************************************************************/void System::renderGUI(void){ ////////////////////////////////////////////////////////////////////////// // This makes use of some tricks the Renderer can do so that we do not // need to do a full redraw every frame - only when some UI element has // changed. // // Since the mouse is likely to move very often, and in order not to // short-circuit the above optimisation, the mouse is not queued, but is // drawn directly to the display every frame. //////////////////////////////////////////////////////////////////////////
if (d_gui_redraw) { d_renderer->resetZValue(); d_renderer->setQueueingEnabled(true); d_renderer->clearRenderList();
if (d_activeSheet) { d_activeSheet->render(); }
d_gui_redraw = false; }
d_renderer->doRender();
// draw mouse d_renderer->setQueueingEnabled(false); MouseCursor::getSingleton().draw();
// do final destruction on dead-pool windows WindowManager::getSingleton().cleanDeadPool();}
/************************************************************************* Set the active GUI sheet (root) window.*************************************************************************/Window* System::setGUISheet(Window* sheet){ Window* old = d_activeSheet; d_activeSheet = sheet;
// Force and update for the area Rects for 'sheet' so they're correct according // to the screen size. if (sheet) { WindowEventArgs sheetargs(0); sheet->onParentSized(sheetargs); }
// fire event WindowEventArgs args(old); onGUISheetChanged(args);
return old;}
/************************************************************************* Set the default font to be used by the system*************************************************************************/void System::setDefaultFont(const String& name){ if (name.empty()) { setDefaultFont(0); } else { setDefaultFont(FontManager::getSingleton().getFont(name)); }
}
/************************************************************************* Set the default font to be used by the system*************************************************************************/void System::setDefaultFont(Font* font){ d_defaultFont = font;
// fire event EventArgs args; onDefaultFontChanged(args);}
/************************************************************************* Set the image to be used as the default mouse cursor.*************************************************************************/void System::setDefaultMouseCursor(const Image* image){ // the default, default, is for nothing! if (image == (const Image*)DefaultMouseCursor) image = 0;
// if mouse cursor is set to the current default we *may* need to // update its Image immediately (first, we will investigate further!) // // NB: The reason we do this check, is to allow code to modify the cursor // image directly without a call to this member changing the image back // again. However, 'normal' updates to the cursor when the mouse enters // a window will, of course, update the mouse image as expected. if (MouseCursor::getSingleton().getImage() == d_defaultMouseCursor) { // does the window containing the mouse use the default cursor? if ((d_wndWithMouse) && (0 == d_wndWithMouse->getMouseCursor(false))) { // default cursor is active, update the image immediately MouseCursor::getSingleton().setImage(image); } }
// update our pointer for the default mouse cursor image. d_defaultMouseCursor = image;
// fire off event. EventArgs args; onDefaultMouseCursorChanged(args);}
/************************************************************************* Set the image to be used as the default mouse cursor.*************************************************************************/void System::setDefaultMouseCursor(const String& imageset, const String& image_name){ setDefaultMouseCursor(&ImagesetManager::getSingleton().getImageset(imageset)->getImage(image_name));}
/************************************************************************* Return a pointer to the ScriptModule being used for scripting within the GUI system.*************************************************************************/ScriptModule* System::getScriptingModule(void) const{ return d_scriptModule;}
/************************************************************************* Set the scripting module*************************************************************************/void System::setScriptingModule(ScriptModule* scriptModule){ // cleanup old bindings if (d_scriptModule) d_scriptModule->destroyBindings(); // set new scriptModule d_scriptModule = scriptModule;
if (d_scriptModule) { // log the new ScriptModule ID string Logger::getSingleton().logEvent("---- Scripting module is now: " + d_scriptModule->getIdentifierString() + " ----");
// create bindings on the new scriptModule d_scriptModule->createBindings(); }}
/************************************************************************* Return a pointer to the ResourceProvider being used for within the GUI system.*************************************************************************/ResourceProvider* System::getResourceProvider(void) const{ return d_resourceProvider;}
/************************************************************************* Execute a script file if possible.*************************************************************************/void System::executeScriptFile(const String& filename, const String& resourceGroup) const{ if (d_scriptModule) { try { d_scriptModule->executeScriptFile(filename, resourceGroup); } // Forward script exceptions with line number and file info catch(ScriptException& e) { throw e; } catch(...) { throw GenericException("System::executeScriptFile - An exception was thrown during the execution of the script file."); }
} else { Logger::getSingleton().logEvent("System::executeScriptFile - the script named '" + filename +"' could not be executed as no ScriptModule is available.", Errors); }
}
/************************************************************************* Execute a scripted global function if possible. The function should not take any parameters and should return an integer.*************************************************************************/int System::executeScriptGlobal(const String& function_name) const{ if (d_scriptModule) { try { return d_scriptModule->executeScriptGlobal(function_name); } // Forward script exceptions with line number and file info catch(ScriptException& e) { throw e; } catch(...) { throw GenericException("System::executeScriptGlobal - An exception was thrown during execution of the scripted function."); }
} else { Logger::getSingleton().logEvent("System::executeScriptGlobal - the global script function named '" + function_name +"' could not be executed as no ScriptModule is available.", Errors); }
return 0;}
/************************************************************************* If possible, execute script code contained in the given CEGUI::String object.*************************************************************************/void System::executeScriptString(const String& str) const{ if (d_scriptModule) { try { d_scriptModule->executeString(str); } // Forward script exceptions with line number and file info catch(ScriptException& e) { throw e; } catch(...) { throw GenericException("System::executeScriptString - An exception was thrown during execution of the script code."); }
} else { Logger::getSingleton().logEvent("System::executeScriptString - the script code could not be executed as no ScriptModule is available.", Errors); }}
/************************************************************************* return the current mouse movement scaling factor.*************************************************************************/float System::getMouseMoveScaling(void) const{ return d_mouseScalingFactor;}
/************************************************************************* Set the current mouse movement scaling factor*************************************************************************/void System::setMouseMoveScaling(float scaling){ d_mouseScalingFactor = scaling;
// fire off event. EventArgs args; onMouseMoveScalingChanged(args);}
/************************************************************************* Method that injects a mouse movement event into the system*************************************************************************/bool System::injectMouseMove(float delta_x, float delta_y){ MouseEventArgs ma(0); MouseCursor& mouse = MouseCursor::getSingleton();
ma.moveDelta.d_x = delta_x * d_mouseScalingFactor; ma.moveDelta.d_y = delta_y * d_mouseScalingFactor;
// only continue setup and injection if mouse position has changed if ((ma.moveDelta.d_x != 0) || (ma.moveDelta.d_y != 0)) { ma.sysKeys = d_sysKeys; ma.wheelChange = 0; ma.clickCount = 0; ma.button = NoButton;
// move the mouse cursor & update position in args. mouse.offsetPosition(ma.moveDelta); ma.position = mouse.getPosition();
return mouseMoveInjection_impl(ma); }
return false;}
/************************************************************************* Method that injects that the mouse is leaves the application window*************************************************************************/bool System::injectMouseLeaves(void){ MouseEventArgs ma(0);
// if there is no window that currently contains the mouse, then // there is nowhere to send input if (d_wndWithMouse) { ma.position = MouseCursor::getSingleton().getPosition(); ma.moveDelta = Vector2(0.0f, 0.0f); ma.button = NoButton; ma.sysKeys = d_sysKeys; ma.wheelChange = 0; ma.window = d_wndWithMouse; ma.clickCount = 0;
d_wndWithMouse->onMouseLeaves(ma); d_wndWithMouse = 0; }
return ma.handled;}
/************************************************************************* Method that injects a mouse button down event into the system.*************************************************************************/bool System::injectMouseButtonDown(MouseButton button){ // update system keys d_sysKeys |= mouseButtonToSyskey(button);
MouseEventArgs ma(0); ma.position = MouseCursor::getSingleton().getPosition(); ma.moveDelta = Vector2(0.0f, 0.0f); ma.button = button; ma.sysKeys = d_sysKeys; ma.wheelChange = 0;
// find the likely destination for generated events. Window* dest_window = getTargetWindow(ma.position);
// // Handling for multi-click generation // MouseClickTracker& tkr = d_clickTrackerPimpl->click_trackers[button];
tkr.d_click_count++;
// if multi-click requirements are not met if (((d_dblclick_timeout > 0) && (tkr.d_timer.elapsed() > d_dblclick_timeout)) || (!tkr.d_click_area.isPointInRect(ma.position)) || (tkr.d_target_window != dest_window) || (tkr.d_click_count > 3)) { // reset to single down event. tkr.d_click_count = 1;
// build new allowable area for multi-clicks tkr.d_click_area.setPosition(ma.position); tkr.d_click_area.setSize(d_dblclick_size); tkr.d_click_area.offset(Point(-(d_dblclick_size.d_width / 2), -(d_dblclick_size.d_height / 2)));
// set target window for click events on this tracker tkr.d_target_window = dest_window; }
// set click count in the event args ma.clickCount = tkr.d_click_count;
// loop backwards until event is handled or we run out of windows. while ((!ma.handled) && (dest_window != 0)) { ma.window = dest_window;
if (dest_window->wantsMultiClickEvents()) { switch (tkr.d_click_count) { case 1: dest_window->onMouseButtonDown(ma); break;
case 2: dest_window->onMouseDoubleClicked(ma); break;
case 3: dest_window->onMouseTripleClicked(ma); break; } } // current target window does not want multi-clicks, // so just send a mouse down event instead. else { dest_window->onMouseButtonDown(ma); }
dest_window = getNextTargetWindow(dest_window); }
// reset timer for this tracker. tkr.d_timer.restart();
return ma.handled;}
/************************************************************************* Method that injects a mouse button up event into the system.*************************************************************************/bool System::injectMouseButtonUp(MouseButton button){ // update system keys d_sysKeys &= ~mouseButtonToSyskey(button);
MouseEventArgs ma(0); ma.position = MouseCursor::getSingleton().getPosition(); ma.moveDelta = Vector2(0.0f, 0.0f); ma.button = button; ma.sysKeys = d_sysKeys; ma.wheelChange = 0;
// get the tracker that holds the number of down events seen so far for this button MouseClickTracker& tkr = d_clickTrackerPimpl->click_trackers[button]; // set click count in the event args ma.clickCount = tkr.d_click_count;
Window* const initial_dest_window = getTargetWindow(ma.position); Window* dest_window = initial_dest_window;
// loop backwards until event is handled or we run out of windows. while ((!ma.handled) && (dest_window != 0)) { ma.window = dest_window; dest_window->onMouseButtonUp(ma); dest_window = getNextTargetWindow(dest_window); }
bool wasUpHandled = ma.handled;
// if requirements for click events are met if (((d_click_timeout == 0) || (tkr.d_timer.elapsed() <= d_click_timeout)) && (tkr.d_click_area.isPointInRect(ma.position)) && (tkr.d_target_window == initial_dest_window)) { ma.handled = false; dest_window = initial_dest_window;
// loop backwards until event is handled or we run out of windows. while ((!ma.handled) && (dest_window != 0)) { ma.window = dest_window; dest_window->onMouseClicked(ma); dest_window = getNextTargetWindow(dest_window); }
}
return (ma.handled | wasUpHandled);}
/************************************************************************* Method that injects a key down event into the system.*************************************************************************/bool System::injectKeyDown(uint key_code){ // update system keys d_sysKeys |= keyCodeToSyskey((Key::Scan)key_code, true);
KeyEventArgs args(0);
if (d_activeSheet && d_activeSheet->isVisible()) { args.scancode = (Key::Scan)key_code; args.sysKeys = d_sysKeys;
Window* dest = getKeyboardTargetWindow();
// loop backwards until event is handled or we run out of windows. while ((dest != 0) && (!args.handled)) { args.window = dest; dest->onKeyDown(args); dest = getNextTargetWindow(dest); }
}
return args.handled;}
/************************************************************************* Method that injects a key up event into the system.*************************************************************************/bool System::injectKeyUp(uint key_code){ // update system keys d_sysKeys &= ~keyCodeToSyskey((Key::Scan)key_code, false);
KeyEventArgs args(0);
if (d_activeSheet && d_activeSheet->isVisible()) { args.scancode = (Key::Scan)key_code; args.sysKeys = d_sysKeys;
Window* dest = getKeyboardTargetWindow();
// loop backwards until event is handled or we run out of windows. while ((dest != 0) && (!args.handled)) { args.window = dest; dest->onKeyUp(args); dest = getNextTargetWindow(dest); }
}
return args.handled;}
/************************************************************************* Method that injects a typed character event into the system.*************************************************************************/bool System::injectChar(utf32 code_point){ KeyEventArgs args(0);
if (d_activeSheet && d_activeSheet->isVisible()) { args.codepoint = code_point; args.sysKeys = d_sysKeys;
Window* dest = getKeyboardTargetWindow();
// loop backwards until event is handled or we run out of windows. while ((dest != 0) && (!args.handled)) { args.window = dest; dest->onCharacter(args); dest = getNextTargetWindow(dest); }
}
return args.handled;}
/************************************************************************* Method that injects a mouse-wheel / scroll-wheel event into the system.*************************************************************************/bool System::injectMouseWheelChange(float delta){ MouseEventArgs ma(0); ma.position = MouseCursor::getSingleton().getPosition(); ma.moveDelta = Vector2(0.0f, 0.0f); ma.button = NoButton; ma.sysKeys = d_sysKeys; ma.wheelChange = delta; ma.clickCount = 0;
Window* dest_window = getTargetWindow(ma.position);
// loop backwards until event is handled or we run out of windows. while ((!ma.handled) && (dest_window != 0)) { ma.window = dest_window; dest_window->onMouseWheel(ma); dest_window = getNextTargetWindow(dest_window); }
return ma.handled;}
/************************************************************************* Method that injects a new position for the mouse cursor.*************************************************************************/bool System::injectMousePosition(float x_pos, float y_pos){ Point new_position(x_pos, y_pos); MouseCursor& mouse = MouseCursor::getSingleton();
// setup mouse movement event args object. MouseEventArgs ma(0); ma.moveDelta = new_position - mouse.getPosition();
// only continue setup and injection if mouse position has changed if ((ma.moveDelta.d_x != 0) || (ma.moveDelta.d_y != 0)) { ma.sysKeys = d_sysKeys; ma.wheelChange = 0; ma.clickCount = 0; ma.button = NoButton;
// move mouse cursor to new position mouse.setPosition(new_position); // update position in args (since actual position may be constrained) ma.position = mouse.getPosition();
return mouseMoveInjection_impl(ma); }
return false;}
/************************************************************************* Method to inject time pulses into the system.*************************************************************************/bool System::injectTimePulse(float timeElapsed){ if (d_activeSheet) { d_activeSheet->update(timeElapsed); }
return true;}
/************************************************************************* Return window that should get mouse inouts when mouse it at 'pt'*************************************************************************/Window* System::getTargetWindow(const Point& pt) const{ Window* dest_window = 0;
// if there is no GUI sheet visible, then there is nowhere to send input if (d_activeSheet && d_activeSheet->isVisible()) { dest_window = Window::getCaptureWindow();
if (!dest_window) { dest_window = d_activeSheet->getTargetChildAtPosition(pt);
if (!dest_window) { dest_window = d_activeSheet; }
} else { if (dest_window->distributesCapturedInputs()) { Window* child_window = dest_window->getTargetChildAtPosition(pt);
if (child_window) { dest_window = child_window; }
}
}
// modal target overrules if (d_modalTarget != 0 && dest_window != d_modalTarget) { if (!dest_window->isAncestor(d_modalTarget)) { dest_window = d_modalTarget; }
}
}
return dest_window;}
/************************************************************************* Return window that should receive keyboard input*************************************************************************/Window* System::getKeyboardTargetWindow(void) const{ Window* target = 0;
if (!d_modalTarget) { target = d_activeSheet->getActiveChild(); } else { target = d_modalTarget->getActiveChild(); if (!target) { target = d_modalTarget; } }
return target;}
/************************************************************************* Return the next window that should receive input in the chain*************************************************************************/Window* System::getNextTargetWindow(Window* w) const{ // if we have not reached the modal target, return the parent if (w != d_modalTarget) { return w->getParent(); }
// otherwise stop now return 0;}
/************************************************************************* Translate a MouseButton value into the corresponding SystemKey value*************************************************************************/SystemKey System::mouseButtonToSyskey(MouseButton btn) const{ switch (btn) { case LeftButton: return LeftMouse;
case RightButton: return RightMouse;
case MiddleButton: return MiddleMouse;
case X1Button: return X1Mouse;
case X2Button: return X2Mouse;
default: throw InvalidRequestException("System::mouseButtonToSyskey - the parameter 'btn' is not a valid MouseButton value."); }}
/************************************************************************* Translate a Key::Scan value into the corresponding SystemKey value*************************************************************************/SystemKey System::keyCodeToSyskey(Key::Scan key, bool direction){ switch (key) { case Key::LeftShift: d_lshift = direction;
if (!d_rshift) { return Shift; } break;
case Key::RightShift: d_rshift = direction;
if (!d_lshift) { return Shift; } break;
case Key::LeftControl: d_lctrl = direction;
if (!d_rctrl) { return Control; } break;
case Key::RightControl: d_rctrl = direction;
if (!d_lctrl) { return Control; } break;
case Key::LeftAlt: d_lalt = direction;
if (!d_ralt) { return Alt; } break;
case Key::RightAlt: d_ralt = direction;
if (!d_lalt) { return Alt; } break;
default: break; }
// if not a system key or overall state unchanged, return 0. return (SystemKey)0;}
System& System::getSingleton(void){ return Singleton<System>::getSingleton();}
System* System::getSingletonPtr(void){ return Singleton<System>::getSingletonPtr();}
/************************************************************************* Set the timeout to be used for the generation of single-click events.*************************************************************************/void System::setSingleClickTimeout(double timeout){ d_click_timeout = timeout;
// fire off event. EventArgs args; onSingleClickTimeoutChanged(args);}
/************************************************************************* Set the timeout to be used for the generation of multi-click events.*************************************************************************/void System::setMultiClickTimeout(double timeout){ d_dblclick_timeout = timeout;
// fire off event. EventArgs args; onMultiClickTimeoutChanged(args);}
/************************************************************************* Set the size of the allowable mouse movement tolerance used when generating multi-click events.*************************************************************************/void System::setMultiClickToleranceAreaSize(const Size& sz){ d_dblclick_size = sz;
// fire off event. EventArgs args; onMultiClickAreaSizeChanged(args);}
/************************************************************************* Handler called when the main system GUI Sheet (or root window) is changed*************************************************************************/void System::onGUISheetChanged(WindowEventArgs& e){ fireEvent(EventGUISheetChanged, e, EventNamespace);}
/************************************************************************* Handler called when the single-click timeout value is changed.*************************************************************************/void System::onSingleClickTimeoutChanged(EventArgs& e){ fireEvent(EventSingleClickTimeoutChanged, e, EventNamespace);}
/************************************************************************* Handler called when the multi-click timeout value is changed.*************************************************************************/void System::onMultiClickTimeoutChanged(EventArgs& e){ fireEvent(EventMultiClickTimeoutChanged, e, EventNamespace);}
/************************************************************************* Handler called when the size of the multi-click tolerance area is changed.*************************************************************************/void System::onMultiClickAreaSizeChanged(EventArgs& e){ fireEvent(EventMultiClickAreaSizeChanged, e, EventNamespace);}
/************************************************************************* Handler called when the default system font is changed.*************************************************************************/void System::onDefaultFontChanged(EventArgs& e){ // here we need to inform every window using the default font that // it's font has been changed. WindowManager::WindowIterator iter = WindowManager::getSingleton().getIterator();
// Args structure we will re-use for all windows. WindowEventArgs args(0);
while (!iter.isAtEnd()) { Window* wnd = iter.getCurrentValue();
if (wnd->getFont(false) == 0) { args.window = wnd; wnd->onFontChanged(args); // ensure 'handled' state is reset. args.handled = false; }
++iter; }
fireEvent(EventDefaultFontChanged, e, EventNamespace);}
/************************************************************************* Handler called when the default system mouse cursor image is changed.*************************************************************************/void System::onDefaultMouseCursorChanged(EventArgs& e){ fireEvent(EventDefaultMouseCursorChanged, e, EventNamespace);}
/************************************************************************* Handler called when the mouse movement scaling factor is changed.*************************************************************************/void System::onMouseMoveScalingChanged(EventArgs& e){ fireEvent(EventMouseMoveScalingChanged, e, EventNamespace);}
/************************************************************************* Handler method for display size change notifications*************************************************************************/bool System::handleDisplaySizeChange(const EventArgs& e){ // notify the imageset/font manager of the size change Size new_sz = getRenderer()->getSize(); ImagesetManager::getSingleton().notifyScreenResolution(new_sz); FontManager::getSingleton().notifyScreenResolution(new_sz);
// notify gui sheet / root if size change, event propagation will ensure everything else // gets updated as required. if (d_activeSheet) { WindowEventArgs args(0); d_activeSheet->onParentSized(args); }
Logger::getSingleton().logEvent( "Display resize:" " w=" + PropertyHelper::floatToString(new_sz.d_width) + " h=" + PropertyHelper::floatToString(new_sz.d_height));
return true;}
/************************************************************************* Internal method used to inform the System object whenever a window is destroyed, so that System can perform any required housekeeping.*************************************************************************/void System::notifyWindowDestroyed(const Window* window){ if (d_wndWithMouse == window) { d_wndWithMouse = 0; }
if (d_activeSheet == window) { d_activeSheet = 0; }
if (d_modalTarget == window) { d_modalTarget = 0; }
}
void System::setDefaultTooltip(Tooltip* tooltip){ // destroy current custom tooltip if one exists and we created it if (d_defaultTooltip && d_weOwnTooltip) WindowManager::getSingleton().destroyWindow(d_defaultTooltip);
// set new custom tooltip d_weOwnTooltip = false; d_defaultTooltip = tooltip; d_defaultTooltip->setWritingXMLAllowed(false);}
void System::setDefaultTooltip(const String& tooltipType){ // destroy current tooltip if one exists and we created it if (d_defaultTooltip && d_weOwnTooltip) WindowManager::getSingleton().destroyWindow(d_defaultTooltip);
if (tooltipType.empty()) { d_defaultTooltip = 0; d_weOwnTooltip = false; } else { try { d_defaultTooltip = static_cast<Tooltip*>(WindowManager::getSingleton().createWindow(tooltipType, "CEGUI::System::default__auto_tooltip__")); d_weOwnTooltip = true; d_defaultTooltip->setWritingXMLAllowed(false); } catch(UnknownObjectException x) { d_defaultTooltip = 0; d_weOwnTooltip = false; } }}
void System::outputLogHeader(){ char addr_buff[32]; sprintf(addr_buff, "(%p)", static_cast<void*>(this)); Logger::getSingleton().logEvent("CEGUI::System singleton created. " + String(addr_buff)); Logger::getSingleton().logEvent("---- CEGUI System initialisation completed ----"); Logger::getSingleton().logEvent("---- Version " + d_strVersion + " ----"); Logger::getSingleton().logEvent("---- Renderer module is: " + d_renderer->getIdentifierString() + " ----"); Logger::getSingleton().logEvent("---- XML Parser module is: " + d_xmlParser->getIdentifierString() + " ----"); Logger::getSingleton().logEvent(d_scriptModule ? "---- Scripting module is: " + d_scriptModule->getIdentifierString() + " ----" : "---- Scripting module is: None ----");}
void System::addStandardWindowFactories(){ // Add factories for types all base elements WindowFactoryManager& wfMgr = WindowFactoryManager::getSingleton(); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(GUISheet)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(DragContainer)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(ScrolledContainer)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(ClippedContainer)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(Checkbox)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(PushButton)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(RadioButton)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(Combobox)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(ComboDropList)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(Editbox)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(FrameWindow)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(ItemEntry)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(Listbox)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(ListHeader)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(ListHeaderSegment)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(Menubar)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(PopupMenu)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(MenuItem)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(MultiColumnList)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(MultiLineEditbox)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(ProgressBar)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(ScrollablePane)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(Scrollbar)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(Slider)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(Spinner)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(TabButton)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(TabControl)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(Thumb)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(Titlebar)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(Tooltip)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(ItemListbox)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(GroupBox)); wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(Tree));}
void System::createSingletons(){ // cause creation of other singleton objects new ImagesetManager(); new FontManager(); new WindowFactoryManager(); new WindowManager(); new SchemeManager(); new MouseCursor(); new GlobalEventSet(); new WidgetLookManager(); new WindowRendererManager();}
void System::destroySingletons(){ delete SchemeManager::getSingletonPtr(); delete WindowManager::getSingletonPtr(); delete WindowFactoryManager::getSingletonPtr(); delete WidgetLookManager::getSingletonPtr(); delete WindowRendererManager::getSingletonPtr(); delete FontManager::getSingletonPtr(); delete MouseCursor::getSingletonPtr(); delete ImagesetManager::getSingletonPtr(); delete GlobalEventSet::getSingletonPtr();}
//----------------------------------------------------------------------------//void System::setupXMLParser(){ // handle creation / initialisation of XMLParser if (!d_xmlParser) {#ifndef CEGUI_STATIC setXMLParser(d_defaultXMLParserName);#else //Static Linking Call d_xmlParser = createParser(); // make sure we know to cleanup afterwards. d_ourXmlParser = true;#endif } // parser object already set, just initialise it. else d_xmlParser->initialise();}
//----------------------------------------------------------------------------//void System::cleanupXMLParser(){ // bail out if no parser if (!d_xmlParser) return;
// get parser object to do whatever cleanup it needs to d_xmlParser->cleanup();
// exit if we did not create this parser object if (!d_ourXmlParser) return;
// if parser module loaded, destroy the parser object & cleanup module if (d_parserModule) { // get pointer to parser deletion function void(*deleteFunc)(XMLParser*) = (void(*)(XMLParser*))d_parserModule-> getSymbolAddress("destroyParser"); // cleanup the xml parser object deleteFunc(d_xmlParser);
// delete the dynamic module for the xml parser delete d_parserModule; d_parserModule = 0; }#ifdef CEGUI_STATIC else //Static Linking Call destroyParser(d_xmlParser);#endif
d_xmlParser = 0;}
//----------------------------------------------------------------------------//void System::setXMLParser(const String& parserName){#ifndef CEGUI_STATIC cleanupXMLParser(); // load dynamic module d_parserModule = new DynamicModule(String("CEGUI") + parserName); // get pointer to parser creation function XMLParser* (*createFunc)(void) = (XMLParser* (*)(void))d_parserModule->getSymbolAddress("createParser"); // create the parser object d_xmlParser = createFunc(); // make sure we know to cleanup afterwards. d_ourXmlParser = true; // perform initialisation of XML parser. d_xmlParser->initialise();#else Logger::getSingleton().logEvent( "System::setXMLParser(const String& parserName) called from statically " "linked CEGUI library - unable to load dynamic module!", Errors);#endif}
//----------------------------------------------------------------------------//void System::setXMLParser(XMLParser* parser){ cleanupXMLParser(); d_xmlParser = parser; d_ourXmlParser = false; setupXMLParser();}
//----------------------------------------------------------------------------//void System::setDefaultXMLParserName(const String& parserName){ d_defaultXMLParserName = parserName;}
const String System::getDefaultXMLParserName(){ return d_defaultXMLParserName;}
//----------------------------------------------------------------------------//bool System::mouseMoveInjection_impl(MouseEventArgs& ma){ updateWindowContainingMouse();
// inform appropriate window of the mouse movement event if (Window* dest_window = d_wndWithMouse) { // ensure event starts as 'not handled' ma.handled = false;
// loop backwards until event is handled or we run out of windows. while ((!ma.handled) && (dest_window != 0)) { ma.window = dest_window; dest_window->onMouseMove(ma); dest_window = getNextTargetWindow(dest_window); } }
return ma.handled;}
//----------------------------------------------------------------------------//bool System::updateWindowContainingMouse(){ MouseEventArgs ma(0); ma.position = MouseCursor::getSingleton().getPosition();
Window* const curr_wnd_with_mouse = getTargetWindow(ma.position);
// exit if window containing mouse has not changed. if (curr_wnd_with_mouse == d_wndWithMouse) return false;
ma.sysKeys = d_sysKeys; ma.wheelChange = 0; ma.clickCount = 0; ma.button = NoButton;
Window* oldWindow = d_wndWithMouse; d_wndWithMouse = curr_wnd_with_mouse;
// inform previous window the mouse has left it if (oldWindow) { ma.window = oldWindow; oldWindow->onMouseLeaves(ma); }
// inform window containing mouse that mouse has entered it if (d_wndWithMouse) { ma.handled = false; ma.window = d_wndWithMouse; d_wndWithMouse->onMouseEnters(ma); }
return true;}
} // End of CEGUI namespace section