//----------------------------------------------------------------------------//
bool EditboxValidationSample::initialise(CEGUI::GUIContext* guiContext)
{
    using namespace CEGUI;

    d_usedFiles = CEGUI::String(__FILE__);

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

    SchemeManager::getSingleton().createFromFile("AlfiskoSkin.scheme");
    guiContext->getCursor().setDefaultImage("AlfiskoSkin/MouseArrow");
    WindowManager& winMgr = WindowManager::getSingleton();

    Window* root = winMgr.createWindow("DefaultWindow");
    guiContext->setRootWindow(root);

    Window* wnd = root->createChild("AlfiskoSkin/FrameWindow");
    wnd->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.25f)));
    wnd->setSize(USize(cegui_reldim(0.5f), cegui_reldim( 0.5f)));
    wnd->setText("Editbox Validation Sample");

    Window* label = wnd->createChild("AlfiskoSkin/Label");
    label->setProperty("HorzFormatting", "WordWrapCentreAligned");
    label->setSize(USize(cegui_reldim(1.0f), cegui_reldim(0.2f)));
    label->setText("Enter 4 digits into the Editbox. A valid entry will be "
        "[colour='FF00FF00']green, [colour='FFFFFFFF']an invalid entry will be "
        "[colour='FFFF0000']red [colour='FFFFFFFF']and a partially valid entry "
        "will be [colour='FFFFBB11']orange");

    Editbox* eb = static_cast<Editbox*>(wnd->createChild("AlfiskoSkin/Editbox"));
    eb->setPosition(UVector2(cegui_reldim(0.1f), cegui_reldim(0.25f)));
    eb->setSize(USize(cegui_reldim(0.8f), cegui_reldim(0.15f)));
    eb->subscribeEvent(
        Editbox::EventTextValidityChanged,
        Event::Subscriber(&EditboxValidationSample::validationChangeHandler, this));

    eb->setValidationString("[0-9]{4}");
    eb->activate();

    return true;
}
//----------------------------------------------------------------------------//
bool EditboxValidation::initialiseSample()
{
    using namespace CEGUI;

    SchemeManager::getSingleton().createFromFile("AlfiskoSkin.scheme");
    System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage("AlfiskoSkin/MouseArrow");
    WindowManager& winMgr = WindowManager::getSingleton();

    Window* root = winMgr.createWindow("DefaultWindow");
    System::getSingleton().getDefaultGUIContext().setRootWindow(root);

    Window* wnd = root->createChild("AlfiskoSkin/FrameWindow");
    wnd->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.25f)));
    wnd->setSize(USize(cegui_reldim(0.5f), cegui_reldim( 0.5f)));
    wnd->setText("Editbox Validation Demo");

    Window* label = wnd->createChild("AlfiskoSkin/Label");
    label->setProperty("HorzFormatting", "WordWrapCentreAligned");
    label->setSize(USize(cegui_reldim(1.0f), cegui_reldim(0.2f)));
    label->setText("Enter 4 digits into the Editbox. A valid entry will be "
        "[colour='FF00FF00']green, [colour='FFFFFFFF']an invalid entry will be "
        "[colour='FFFF0000']red [colour='FFFFFFFF']and a partially valid entry "
        "will be [colour='FFFFBB11']orange");

    Editbox* eb = static_cast<Editbox*>(wnd->createChild("AlfiskoSkin/Editbox"));
    eb->setPosition(UVector2(cegui_reldim(0.1f), cegui_reldim(0.25f)));
    eb->setSize(USize(cegui_reldim(0.8f), cegui_reldim(0.15f)));
    eb->subscribeEvent(
        Editbox::EventTextValidityChanged,
        Event::Subscriber(&EditboxValidation::validationChangeHandler, this));

    eb->setValidationString("[0-9]{4}");
    eb->activate();

    return true;
}
Exemple #3
0
/*************************************************************************
    Create the windows and widgets for the demo
*************************************************************************/
void Demo6Sample::createDemoWindows(void)
{
    using namespace CEGUI;
    ListboxTextItem* itm;

    WindowManager& winMgr = WindowManager::getSingleton();
    Window* root = winMgr.getWindow("root_wnd");

    // create the main list.
    MultiColumnList* mcl = static_cast<MultiColumnList*>(winMgr.createWindow("TaharezLook/MultiColumnList", "Demo6/MainList"));
    root->addChildWindow(mcl);
    mcl->setPosition(UVector2(cegui_reldim(0.01f), cegui_reldim( 0.1f)));
    mcl->setSize(UVector2(cegui_reldim(0.5f), cegui_reldim( 0.8f)));

    // create frame window for control panel
    FrameWindow* fwnd = static_cast<FrameWindow*>(winMgr.createWindow("TaharezLook/FrameWindow", "Demo6/ControlPanel"));
    root->addChildWindow(fwnd);
    fwnd->setPosition(UVector2(cegui_reldim(0.53f), cegui_reldim( 0.03f)));
    fwnd->setMaxSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
    fwnd->setSize(UVector2(cegui_reldim(0.44f), cegui_reldim( 0.94f)));
    fwnd->setText("Demo 6 - Control Panel");

    // create combo-box.
    Combobox* cbbo = static_cast<Combobox*>(winMgr.createWindow("TaharezLook/Combobox", "Demo6/ControlPanel/SelModeBox"));
    fwnd->addChildWindow(cbbo);
    cbbo->setPosition(UVector2(cegui_reldim(0.04f), cegui_reldim( 0.06f)));
    cbbo->setSize(UVector2(cegui_reldim(0.66f), cegui_reldim( 0.33f)));
    //cbbo->setSortingEnabled(true);

    // populate combobox with possible selection modes
    const CEGUI::Image* sel_img = &ImagesetManager::getSingleton().getImageset("TaharezLook")->getImage("MultiListSelectionBrush");
    itm = new ListboxTextItem("Full Row (Single)", 0);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    itm = new ListboxTextItem("Full Row (Multiple)", 1);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    itm = new ListboxTextItem("Full Column (Single)", 2);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    itm = new ListboxTextItem("Full Column (Multiple)", 3);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    itm = new ListboxTextItem("Single Cell (Single)", 4);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    itm = new ListboxTextItem("Single Cell (Multiple)", 5);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    itm = new ListboxTextItem("Nominated Column (Single)", 6);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    itm = new ListboxTextItem("Nominated Column (Multiple)", 7);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    ListboxTextItem* pStore = itm;
    itm = new ListboxTextItem("Nominated Row (Single)", 8);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    itm = new ListboxTextItem("Nominated Row (Multiple)", 9);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    cbbo->setReadOnly(true);
    // Now change the text to test the sorting
    pStore->setText("Abracadabra");
    //cbbo->setSortingEnabled(false);
    cbbo->setSortingEnabled(true);
    //cbbo->handleUpdatedListItemData();

    // column control section
    Window* st = winMgr.createWindow("TaharezLook/StaticText", "Demo6/ControlPanel/ColumnPanel");
    fwnd->addChildWindow(st);
    st->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.12f)));
    st->setSize(UVector2(cegui_reldim(0.96f), cegui_reldim( 0.25f)));
    st->setText("Column Control");
    st->setProperty("VertFormatting", "TopAligned");

    Window* label = winMgr.createWindow("TaharezLook/StaticText", "Demo6/ControlPanel/Label1");
    st->addChildWindow(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.2f)));
    label->setSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
    label->setText("ID Code:");

    label = winMgr.createWindow("TaharezLook/StaticText", "Demo6/ControlPanel/Label2");
    st->addChildWindow(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.23f), cegui_reldim( 0.2f)));
    label->setSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
    label->setText("Width:");

    label = winMgr.createWindow("TaharezLook/StaticText", "Demo6/ControlPanel/Label3");
    st->addChildWindow(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.44f), cegui_reldim( 0.2f)));
    label->setSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
    label->setText("Caption:");

    PushButton* btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "Demo6/ControlPanel/ColumnPanel/AddColButton"));
    st->addChildWindow(btn);
    btn->setPosition(UVector2(cegui_reldim(0.81f), cegui_reldim( 0.32f)));
    btn->setSize(UVector2(cegui_reldim(0.15f), cegui_reldim( 0.2f)));
    btn->setText("Add");

    Editbox* ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "Demo6/ControlPanel/ColumnPanel/NewColIDBox"));
    st->addChildWindow(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.32f)));
    ebox->setSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
    ebox->setValidationString("\\d*");
    ebox->setText("Test -- ");

    ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "Demo6/ControlPanel/ColumnPanel/NewColWidthBox"));
    st->addChildWindow(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.23f), cegui_reldim( 0.32f)));
    ebox->setSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
    ebox->setValidationString("\\d*");

    ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "Demo6/ControlPanel/ColumnPanel/NewColTextBox"));
    st->addChildWindow(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.44f), cegui_reldim( 0.32f)));
    ebox->setSize(UVector2(cegui_reldim(0.36f), cegui_reldim( 0.2f)));
    ebox->setValidationString(".*");

    label = winMgr.createWindow("TaharezLook/StaticText", "Demo6/ControlPanel/Label4");
    st->addChildWindow(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.55f)));
    label->setSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
    label->setText("ID Code:");

    ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "Demo6/ControlPanel/ColumnPanel/DelColIDBox"));
    st->addChildWindow(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.67f)));
    ebox->setSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
    ebox->setValidationString("\\d*");

    btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "Demo6/ControlPanel/ColumnPanel/DelColButton"));
    st->addChildWindow(btn);
    btn->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.67f)));
    btn->setSize(UVector2(cegui_reldim(0.4f), cegui_reldim( 0.2f)));
    btn->setText("Delete Column");

    // Row control box
    st = winMgr.createWindow("TaharezLook/StaticText", "Demo6/ControlPanel/RowControl");
    fwnd->addChildWindow(st);
    st->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.38f)));
    st->setSize(UVector2(cegui_reldim(0.96f), cegui_reldim( 0.25f)));
    st->setText("Row Control");
    st->setProperty("VertFormatting", "TopAligned");

    label = winMgr.createWindow("TaharezLook/StaticText", "Demo6/ControlPanel/Label5");
    st->addChildWindow(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.2f)));
    label->setSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
    label->setText("Col ID:");

    label = winMgr.createWindow("TaharezLook/StaticText", "Demo6/ControlPanel/Label6");
    st->addChildWindow(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.23f), cegui_reldim( 0.2f)));
    label->setSize(UVector2(cegui_reldim(0.55f), cegui_reldim( 0.12f)));
    label->setText("Item Text:");

    ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "Demo6/ControlPanel/ColumnPanel/RowColIDBox"));
    st->addChildWindow(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.32f)));
    ebox->setSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
    ebox->setValidationString("\\d*");

    ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "Demo6/ControlPanel/ColumnPanel/RowTextBox"));
    st->addChildWindow(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.23f), cegui_reldim( 0.32f)));
    ebox->setSize(UVector2(cegui_reldim(0.55f), cegui_reldim( 0.2f)));
    ebox->setValidationString(".*");

    btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "Demo6/ControlPanel/ColumnPanel/AddRowButton"));
    st->addChildWindow(btn);
    btn->setPosition(UVector2(cegui_reldim(0.81f), cegui_reldim( 0.32f)));
    btn->setSize(UVector2(cegui_reldim(0.15f), cegui_reldim( 0.2f)));
    btn->setText("Add");

    label = winMgr.createWindow("TaharezLook/StaticText", "Demo6/ControlPanel/Label7");
    st->addChildWindow(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.55f)));
    label->setSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
    label->setText("Row Idx:");

    ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "Demo6/ControlPanel/ColumnPanel/DelRowIdxBox"));
    st->addChildWindow(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.67f)));
    ebox->setSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
    ebox->setValidationString("\\d*");

    btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "Demo6/ControlPanel/ColumnPanel/DelRowButton"));
    st->addChildWindow(btn);
    btn->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.67f)));
    btn->setSize(UVector2(cegui_reldim(0.4f), cegui_reldim( 0.2f)));
    btn->setText("Delete Row");

    // set item box
    st = winMgr.createWindow("TaharezLook/StaticText", "Demo6/ControlPanel/SetItemPanel");
    fwnd->addChildWindow(st);
    st->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.65f)));
    st->setSize(UVector2(cegui_reldim(0.96f), cegui_reldim( 0.25f)));
    st->setText("Item Modification");
    st->setProperty("VertFormatting", "TopAligned");

    label = winMgr.createWindow("TaharezLook/StaticText", "Demo6/ControlPanel/Label8");
    st->addChildWindow(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.2f)));
    label->setSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
    label->setText("Row Idx:");

    label = winMgr.createWindow("TaharezLook/StaticText", "Demo6/ControlPanel/Label9");
    st->addChildWindow(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.23f), cegui_reldim( 0.2f)));
    label->setSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
    label->setText("Col ID:");

    label = winMgr.createWindow("TaharezLook/StaticText", "Demo6/ControlPanel/Label10");
    st->addChildWindow(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.44f), cegui_reldim( 0.2f)));
    label->setSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
    label->setText("Item Text:");

    ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "Demo6/ControlPanel/ColumnPanel/SetItemRowBox"));
    st->addChildWindow(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.32f)));
    ebox->setSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
    ebox->setValidationString("\\d*");

    ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "Demo6/ControlPanel/ColumnPanel/SetItemIDBox"));
    st->addChildWindow(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.23f), cegui_reldim( 0.32f)));
    ebox->setSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
    ebox->setValidationString("\\d*");

    ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "Demo6/ControlPanel/ColumnPanel/SetItemTextBox"));
    st->addChildWindow(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.44f), cegui_reldim( 0.32f)));
    ebox->setSize(UVector2(cegui_reldim(0.36f), cegui_reldim( 0.2f)));
    ebox->setValidationString(".*");

    btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "Demo6/ControlPanel/ColumnPanel/SetItemButton"));
    st->addChildWindow(btn);
    btn->setPosition(UVector2(cegui_reldim(0.81f), cegui_reldim( 0.32f)));
    btn->setSize(UVector2(cegui_reldim(0.15f), cegui_reldim( 0.2f)));
    btn->setText("Set");

    label = winMgr.createWindow("TaharezLook/StaticText", "Demo6/ControlPanel/RowCount");
    st->addChildWindow(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.55f)));
    label->setSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 0.12f)));
    label->setText("Current Row Count:");

    label = winMgr.createWindow("TaharezLook/StaticText", "Demo6/ControlPanel/ColCount");
    st->addChildWindow(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.67f)));
    label->setSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 0.12f)));
    label->setText("Current Column Count:");

    label = winMgr.createWindow("TaharezLook/StaticText", "Demo6/ControlPanel/SelCount");
    st->addChildWindow(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.79f)));
    label->setSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 0.12f)));
    label->setText("Current Selected Count:");

    btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "Demo6/QuitButton"));
    fwnd->addChildWindow(btn);
    btn->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.93f)));
    btn->setSize(UVector2(cegui_reldim(0.50f), cegui_reldim( 0.05f)));
    btn->setText("Quit This Demo!");
}