Example #1
0
/*************************************************************************
Sample specific initialisation goes here.
*************************************************************************/
bool EffectsDemo::initialise(CEGUI::GUIContext* guiContext)
{
    using namespace CEGUI;

    d_usedFiles = CEGUI::String(__FILE__);
    d_guiContext = guiContext;

    // Register our effects with the system
    RenderEffectManager::getSingleton().addEffect<ElasticWindowEffect>(s_effectNameElastic);
    RenderEffectManager::getSingleton().addEffect<WobblyWindowEffect>(s_effectNameWobblyNew);
    RenderEffectManager::getSingleton().addEffect<OldWobblyWindowEffect>(s_effectNameWobblyOld);

    // Now we make a Falagard mapping for a frame window that uses this effect.
    // We create a type "Vanilla/WobblyFrameWindow".  Note that it would be
    // more usual for this mapping to be specified in the scheme xml file,
    // though here we are doing in manually to save from needing either multiple
    // versions of the schemes or from having demo specific definitions in
    // the schemes.
    WindowFactoryManager::getSingleton().addFalagardWindowMapping(
        "Vanilla/WobblyFrameWindow",    // type to create
        "CEGUI/FrameWindow",            // 'base' widget type
        "Vanilla/FrameWindow",          // WidgetLook to use.
        "Core/FrameWindow",             // WindowRenderer to use.
        s_effectNameWobblyNew);         // effect to use.

    // Since we want to be able to load the EffectsDemo.layout in the editor
    // tools (where the above mapping is not available), we now alias the
    // new window type onto the original TaharezLook/FrameWindow.  This has
    // the effect that - after the alias is added - any time a window of
    // type "TaharezLook/FrameWindow" is requested, the system will create a
    // "TaharezLook/WobblyFrameWindow" instead.

    WindowFactoryManager::getSingleton().addWindowTypeAlias(
        "Vanilla/FrameWindow",  // alias name - can shadow existing types
        "Vanilla/WobblyFrameWindow"); // target type to create.

    // we will use of the WindowManager.
    WindowManager& winMgr = WindowManager::getSingleton();

    // load scheme and set up defaults
    SchemeManager::getSingleton().createFromFile("TaharezLook.scheme");
    SchemeManager::getSingleton().createFromFile("VanillaSkin.scheme");
    guiContext->getMouseCursor().setDefaultImage("TaharezLook/MouseArrow");

    // load font and setup default if not loaded via scheme
    Font& defaultFont = FontManager::getSingleton().createFromFile("DejaVuSans-12.font");
    // Set default font for the gui context
    guiContext->setDefaultFont(&defaultFont);

    // load an image to use as a background
    if( !ImageManager::getSingleton().isDefined("SpaceBackgroundImage") )
        ImageManager::getSingleton().addFromImageFile("SpaceBackgroundImage", "SpaceBackground.jpg");

    if( !ImageManager::getSingleton().isDefined("AliasingTestImage") )
        ImageManager::getSingleton().addFromImageFile("AliasingTestImage", "Aliasing.jpg");

    // here we will use a StaticImage as the root, then we can use it to place a background image
    Window* background = winMgr.createWindow("TaharezLook/StaticImage", "background_wnd");
    // set position and size
    background->setPosition(UVector2(cegui_reldim(0), cegui_reldim( 0)));
    background->setSize(USize(cegui_reldim(1), cegui_reldim( 1)));
    // disable frame and standard background
    background->setProperty("FrameEnabled", "false");
    background->setProperty("BackgroundEnabled", "false");
    // set the background image
    background->setProperty("Image", "SpaceBackgroundImage");
    // set the background window as the root window for our GUIContext
    guiContext->setRootWindow(background);

    // load the windows for the EffectsDemo from the layout file.
    Window* sheet = winMgr.loadLayoutFromFile("EffectsDemo.layout");
 
    // Get the combobox created from within the layout
    CEGUI::Combobox* effectsCombobox = static_cast<CEGUI::Combobox*>(sheet->getChild("EffectsFrameWindow/EffectsCombobox"));

    // attach this to the 'real' root
    background->addChild(sheet);
    //Initialise the render effects
    initialiseEffects(effectsCombobox->getParent());

    // Initialise the items and subscribe the event for the combobox
    initialiseEffectsCombobox(effectsCombobox);
    
    // We can switch the automatic effects mapping off now
    WindowFactoryManager::getSingleton().removeWindowTypeAlias(
        "Vanilla/FrameWindow",  // alias name - can shadow existing types
        "Vanilla/WobblyFrameWindow"); // target type to create.




    // We create a mapping for the elastic windows effect too,
    // and we will apply it to a window we create from code
    WindowFactoryManager::getSingleton().addFalagardWindowMapping(
        "Vanilla/ElasticFrameWindow",   // type to create
        "CEGUI/FrameWindow",            // 'base' widget type
        "Vanilla/FrameWindow",          // WidgetLook to use.
        "Core/FrameWindow",             // WindowRenderer to use.
        s_effectNameElastic);    // effect to use.

    // We will create another window using the effects-mapping we created before, this time directly from code
    CEGUI::FrameWindow* aliasingFrameWnd = static_cast<CEGUI::FrameWindow*>(
        WindowManager::getSingleton().createWindow("Vanilla/ElasticFrameWindow", "AliasingTestWindow") );

    // Add it to the layout root
    sheet->addChild(aliasingFrameWnd);

    // We will add an image to it using a StaticImage window
    Window* aliasingWnd = WindowManager::getSingleton().createWindow("Vanilla/StaticImage", "AliasingTestImage");
    aliasingFrameWnd->addChild(aliasingWnd);
    aliasingFrameWnd->setPosition(CEGUI::UVector2(cegui_reldim(0.05f), cegui_reldim(0.15f)));
    aliasingFrameWnd->setSize(CEGUI::USize(cegui_reldim(0.2f), cegui_reldim(0.28f)));
    aliasingFrameWnd->setSizingEnabled(true);
    aliasingFrameWnd->setCloseButtonEnabled(false);
    aliasingFrameWnd->setTitleBarEnabled(true);
    aliasingFrameWnd->setText("Elastic Window - Aliasing Testimage");

    // Image window setup
    aliasingWnd->setSize(CEGUI::USize(cegui_reldim(1.0f), cegui_reldim(1.0f)));
    aliasingWnd->setProperty("FrameEnabled", "false");
    aliasingWnd->setProperty("BackgroundEnabled", "false");
    aliasingWnd->setProperty("Image", "AliasingTestImage");

    // success!
    return true;
}