bool IntroState::info(const CEGUI::EventArgs &e) { CEGUI::Window* sheet=CEGUI::System::getSingleton().getDefaultGUIContext().getRootWindow(); _credits=false; _options=false; _info=true; //Sheet Creditos Window* sheetBG = WindowManager::getSingleton().createWindow("TaharezLook/StaticImage","background_info"); sheetBG->setPosition( UVector2(cegui_reldim(0),cegui_reldim(0))); sheetBG->setSize( USize(cegui_reldim(1),cegui_reldim(1))); sheetBG->setProperty("Image","BackgroundImageControls"); sheetBG->setProperty("FrameEnabled","False"); sheetBG->setProperty("BackgroundEnabled", "False"); CEGUI::Window* backButton = CEGUI::WindowManager::getSingleton().createWindow("OgreTray/Button","back"); backButton->setText("[font='DickVanDyke'] Back "); backButton->setSize(CEGUI::USize(CEGUI::UDim(0.23,0),CEGUI::UDim(0.07,0))); backButton->setXPosition(UDim(0.66f, 0.0f)); backButton->setYPosition(UDim(0.85f, 0.0f)); backButton->subscribeEvent(CEGUI::PushButton::EventClicked,CEGUI::Event::Subscriber(&IntroState::back,this)); sheetBG->addChild(backButton); sheet->addChild(sheetBG); return true; }
bool IntroState::options(const CEGUI::EventArgs &e) { CEGUI::Window* sheet=CEGUI::System::getSingleton().getDefaultGUIContext().getRootWindow(); _credits=false; _options=true; _info=false; //Sheet Records Window* sheetBG = WindowManager::getSingleton().createWindow("TaharezLook/StaticImage","background_options"); sheetBG->setPosition( UVector2(cegui_reldim(0),cegui_reldim(0))); sheetBG->setSize( USize(cegui_reldim(1),cegui_reldim(1))); sheetBG->setProperty("Image","BackgroundImageOptions"); sheetBG->setProperty("FrameEnabled","False"); sheetBG->setProperty("BackgroundEnabled", "False"); CEGUI::Window* backButton = CEGUI::WindowManager::getSingleton().createWindow("OgreTray/Button","back"); backButton->setText("[font='DickVanDyke'] Back "); backButton->setSize(CEGUI::USize(CEGUI::UDim(0.23,0),CEGUI::UDim(0.07,0))); backButton->setXPosition(UDim(0.66f, 0.0f)); backButton->setYPosition(UDim(0.85f, 0.0f)); backButton->subscribeEvent(CEGUI::PushButton::EventClicked,CEGUI::Event::Subscriber(&IntroState::back,this)); CEGUI::Window* applyButton = CEGUI::WindowManager::getSingleton().createWindow("OgreTray/Button","apply"); applyButton->setText("[font='DickVanDyke'] apply "); applyButton->setSize(CEGUI::USize(CEGUI::UDim(0.23,0),CEGUI::UDim(0.07,0))); applyButton->setXPosition(UDim(0.66f, 0.0f)); applyButton->setYPosition(UDim(0.77f, 0.0f)); applyButton->subscribeEvent(CEGUI::PushButton::EventClicked,CEGUI::Event::Subscriber(&IntroState::apply,this)); CEGUI::Window* text = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticText","text"); text->setText("[font='DickVanDyke'] Mouse Speed"); text->setSize(CEGUI::USize(CEGUI::UDim(0.15,0),CEGUI::UDim(0.1,0))); text->setPosition(CEGUI::UVector2(CEGUI::UDim(0.12,0),CEGUI::UDim(0.32,0))); text->setProperty("FrameEnabled","False"); text->setProperty("BackgroundEnabled", "False"); text->setProperty("HorzFormatting", "RightAligned"); CEGUI::Slider* sb = static_cast<CEGUI::Slider*> (CEGUI::WindowManager::getSingleton().createWindow("OgreTray/Slider","SliderSpeed")); sb->setPosition(CEGUI::UVector2(CEGUI::UDim(0.15,0),CEGUI::UDim(0.4,0))); sb->setMaxValue(40.0f); sb->setClickStep(1.0f); sb->setCurrentValue(20.0f); sb->subscribeEvent(Slider::EventValueChanged, Event::Subscriber(&IntroState::onSliderValueChanged, this)); CEGUI::Window* sbText = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticText","textSliderSpeed"); sbText->setText("[font='DickVanDyke']20"); sbText->setSize(CEGUI::USize(CEGUI::UDim(0.05,0),CEGUI::UDim(0.08,0))); sbText->setPosition(CEGUI::UVector2(CEGUI::UDim(0.36,0),CEGUI::UDim(0.38,0))); sbText->setProperty("FrameEnabled","False"); sbText->setProperty("BackgroundEnabled", "False"); sbText->setProperty("HorzFormatting", "RightAligned"); CEGUI::Window* text2 = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticText","text2"); text2->setText("[font='DickVanDyke'] Auto-Reload Arrows"); text2->setSize(CEGUI::USize(CEGUI::UDim(0.25,0),CEGUI::UDim(0.06,0))); text2->setPosition(CEGUI::UVector2(CEGUI::UDim(0.15,0),CEGUI::UDim(0.46,0))); text2->setProperty("FrameEnabled","False"); text2->setProperty("BackgroundEnabled", "False"); text2->setProperty("HorzFormatting", "LeftAligned"); CEGUI::ToggleButton* cb = static_cast<CEGUI::ToggleButton*> (CEGUI::WindowManager::getSingleton().createWindow("OgreTray/Checkbox","CBAutoReload")); cb->setPosition(CEGUI::UVector2(CEGUI::UDim(0.08,0),CEGUI::UDim(0.52,0))); CEGUI::Window* resetButton = CEGUI::WindowManager::getSingleton().createWindow("OgreTray/Button","resetButton"); resetButton->setText("[font='DickVanDyke'] Reset Records "); resetButton->setSize(CEGUI::USize(CEGUI::UDim(0.23,0),CEGUI::UDim(0.07,0))); resetButton->setXPosition(UDim(0.40f, 0.0f)); resetButton->setYPosition(UDim(0.85f, 0.0f)); resetButton->subscribeEvent(CEGUI::PushButton::EventClicked,CEGUI::Event::Subscriber(&IntroState::resetRecords,this)); CEGUI::Window* configButton = CEGUI::WindowManager::getSingleton().createWindow("OgreTray/Button","configButton"); configButton->setText("[font='DickVanDyke'] Restore Config "); configButton->setSize(CEGUI::USize(CEGUI::UDim(0.23,0),CEGUI::UDim(0.07,0))); configButton->setXPosition(UDim(0.40f, 0.0f)); configButton->setYPosition(UDim(0.77f, 0.0f)); configButton->subscribeEvent(CEGUI::PushButton::EventClicked,CEGUI::Event::Subscriber(&IntroState::resetConfig,this)); CEGUI::Window* text3 = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticText","FullscreenText"); text3->setText("[font='DickVanDyke'] Fullscreen"); text3->setSize(CEGUI::USize(CEGUI::UDim(0.25,0),CEGUI::UDim(0.06,0))); text3->setPosition(CEGUI::UVector2(CEGUI::UDim(0.15,0),CEGUI::UDim(0.57,0))); text3->setProperty("FrameEnabled","False"); text3->setProperty("BackgroundEnabled", "False"); text3->setProperty("HorzFormatting", "LeftAligned"); CEGUI::ToggleButton* cbFullscreen = static_cast<CEGUI::ToggleButton*> (CEGUI::WindowManager::getSingleton().createWindow("OgreTray/Checkbox","CBFullscreen")); cbFullscreen->setPosition(CEGUI::UVector2(CEGUI::UDim(0.08,0),CEGUI::UDim(0.62,0))); cbFullscreen->subscribeEvent(CEGUI::ToggleButton::EventSelectStateChanged,CEGUI::Event::Subscriber(&IntroState::tbFullscreenChanged,this)); CEGUI::Window* text4 = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticText","ResolutionText"); text4->setText("[font='DickVanDyke'] Resolution"); text4->setSize(CEGUI::USize(CEGUI::UDim(0.25,0),CEGUI::UDim(0.06,0))); text4->setPosition(CEGUI::UVector2(CEGUI::UDim(0.5,0),CEGUI::UDim(0.35,0))); text4->setProperty("FrameEnabled","False"); text4->setProperty("BackgroundEnabled", "False"); text4->setProperty("HorzFormatting", "LeftAligned"); CEGUI::Listbox* lbRes = static_cast<CEGUI::Listbox*> (CEGUI::WindowManager::getSingleton().createWindow("OgreTray/Listbox","lbRes")); lbRes->setSize(CEGUI::USize(CEGUI::UDim(0.3,0),CEGUI::UDim(0.3,0))); lbRes->setPosition(CEGUI::UVector2(CEGUI::UDim(0.5, 0),CEGUI::UDim(0.40, 0))); lbRes->subscribeEvent(Listbox::EventSelectionChanged,CEGUI::Event::Subscriber(&IntroState::changeResolution,this)); const CEGUI::Image* sel_img = &CEGUI::ImageManager::getSingleton().get("TaharezLook/MultiListSelectionBrush"); CEGUI::ListboxTextItem* itm; itm = new CEGUI::ListboxTextItem("800x600",0); itm->setFont("DickVanDyke-28"); itm->setTextColours(CEGUI::Colour(0.0,0.8,0.5)); itm->setSelectionBrushImage(sel_img); lbRes->addItem(itm); CEGUI::ListboxTextItem* itm2; itm2 = new CEGUI::ListboxTextItem("1200x800",1); itm2->setFont("DickVanDyke-28"); itm2->setTextColours(CEGUI::Colour(0.0,0.8,0.5)); itm2->setSelectionBrushImage(sel_img); lbRes->addItem(itm2); CEGUI::ListboxTextItem* itm3; itm3 = new CEGUI::ListboxTextItem("1920x1020",2); itm3->setFont("DickVanDyke-28"); itm3->setTextColours(CEGUI::Colour(0.0,0.8,0.5)); itm3->setSelectionBrushImage(sel_img); lbRes->addItem(itm3); sheetBG->addChild(text4); sheetBG->addChild(lbRes); sheetBG->addChild(cb); sheetBG->addChild(text2); sheetBG->addChild(cbFullscreen); sheetBG->addChild(text3); sheetBG->addChild(sbText); sheetBG->addChild(sb); sheetBG->addChild(applyButton); sheetBG->addChild(backButton); sheetBG->addChild(resetButton); sheetBG->addChild(configButton); sheetBG->addChild(text); sheet->addChild(sheetBG); if(_fullscreen){ cbFullscreen->setSelected(true); }else{ cbFullscreen->setSelected(false); } return true; }
/************************************************************************* Sample specific initialisation goes here. *************************************************************************/ bool MinesweeperSample::initialise(CEGUI::GUIContext* guiContext) { using namespace CEGUI; d_usedFiles = CEGUI::String(__FILE__); // Register Timer Window WindowFactoryManager::getSingleton().addFactory( &getTimerFactory() ); // 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); d_gameStarted = false; // Get window manager which we wil use for a few jobs here. WindowManager& winMgr = WindowManager::getSingleton(); // Load the scheme to initialse the VanillaSkin which we use in this sample SchemeManager::getSingleton().createFromFile("VanillaSkin.scheme"); SchemeManager::getSingleton().createFromFile("TaharezLook.scheme"); guiContext->setDefaultTooltipType("TaharezLook/Tooltip"); // set default mouse image guiContext->getMouseCursor().setDefaultImage("Vanilla-Images/MouseArrow"); // load an image to use as a background if( !ImageManager::getSingleton().isDefined("SpaceBackgroundImage") ) ImageManager::getSingleton().addFromImageFile("SpaceBackgroundImage", "SpaceBackground.jpg"); // here we will use a StaticImage as the root, then we can use it to place a background image Window* background = winMgr.createWindow("Vanilla/StaticImage"); // set area rectangle background->setArea(URect(cegui_reldim(0), cegui_reldim(0), 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"); // install this as the root GUI sheet guiContext->setRootWindow(background); d_alarm = (Timer*)winMgr.createWindow("Timer"); background->addChild(d_alarm); d_alarm->setDelay(0.5); // Tick each 0.5 seconds // create the game frame Window* frame = winMgr.createWindow("Vanilla/FrameWindow"); d_alarm->addChild(frame); frame->setXPosition(UDim(0.3f, 0.0f)); frame->setYPosition(UDim(0.15f, 0.0f)); frame->setWidth(UDim(0.4f, 0.0f)); frame->setHeight(UDim(0.7f, 0.0f)); frame->setText("CEGUI Minesweeper"); // create the action panel Window* action = winMgr.createWindow("DefaultWindow"); frame->addChild(action); action->setXPosition(UDim(0.03f, 0.0f)); action->setYPosition(UDim(0.10f, 0.0f)); action->setWidth(UDim(0.94f, 0.0f)); action->setHeight(UDim(0.1f, 0.0f)); d_counter = (Editbox*)winMgr.createWindow("Vanilla/Editbox", "mine_counter"); action->addChild(d_counter); d_counter->setText("0"); d_counter->setTooltipText("Number of mine"); d_counter->setReadOnly(true); d_counter->setXPosition(UDim(0.0f, 0.0f)); d_counter->setYPosition(UDim(0.0f, 0.0f)); d_counter->setWidth(UDim(0.3f, 0.0f)); d_counter->setHeight(UDim(1.0f, 0.0f)); Window* newGame = winMgr.createWindow("Vanilla/Button", "new_game"); action->addChild(newGame); newGame->setText("Start"); newGame->setTooltipText("Start a new game"); newGame->setXPosition(UDim(0.35f, 0.0f)); newGame->setYPosition(UDim(0.0f, 0.0f)); newGame->setWidth(UDim(0.3f, 0.0f)); newGame->setHeight(UDim(1.0f, 0.0f)); newGame->subscribeEvent(PushButton::EventClicked, Event::Subscriber(&MinesweeperSample::handleGameStartClicked, this)); d_timer = (Editbox*)winMgr.createWindow("Vanilla/Editbox", "timer"); action->addChild(d_timer); d_timer->setText("0"); d_timer->setTooltipText("Time elapsed"); d_timer->setReadOnly(true); d_timer->setXPosition(UDim(0.7f, 0.0f)); d_timer->setYPosition(UDim(0.0f, 0.0f)); d_timer->setWidth(UDim(0.3f, 0.0f)); d_timer->setHeight(UDim(1.0f, 0.0f)); d_alarm->subscribeEvent(Timer::EventTimerAlarm, Event::Subscriber(&MinesweeperSample::handleUpdateTimer, this)); // Board button grid Window* grid = winMgr.createWindow("DefaultWindow"); frame->addChild(grid); grid->setXPosition(UDim(0.03f, 0.0f)); grid->setYPosition(UDim(0.23f, 0.0f)); grid->setWidth( UDim(0.94f, 0.0f)); grid->setHeight( UDim(0.74f, 0.0f)); const float d_inc = 1.0f / MinesweeperSize; for(size_t i = 0 ; i < MinesweeperSize ; ++i) { // create a container for each row Window* row = winMgr.createWindow("DefaultWindow"); row->setArea(URect(UDim(0,0), UDim(d_inc * i, 0), UDim(1,0), UDim(d_inc * (i + 1), 0))); grid->addChild(row); for(size_t j = 0 ; j < MinesweeperSize ; ++j) { // Initialize buttons coordinate d_buttonsMapping[i][j].d_col = j; d_buttonsMapping[i][j].d_row = i; d_buttons[i][j] = (PushButton*)winMgr.createWindow("Vanilla/Button"); row->addChild(d_buttons[i][j]); d_buttons[i][j]->setArea(URect(UDim(d_inc * j, 0), UDim(0,0), UDim(d_inc * (j + 1), 0), UDim(1,0))); d_buttons[i][j]->setEnabled(false); // Associate user data d_buttons[i][j]->setUserData(&(d_buttonsMapping[i][j])); d_buttons[i][j]->setID(0); // Connect event handlers d_buttons[i][j]->subscribeEvent(PushButton::EventClicked, Event::Subscriber(&MinesweeperSample::handleMineButtonClicked, this)); d_buttons[i][j]->subscribeEvent(Window::EventMouseButtonDown, Event::Subscriber(&MinesweeperSample::handleMineButtonDown, this)); } } d_result = winMgr.createWindow("Vanilla/StaticText"); grid->addChild(d_result); d_result->setXPosition(UDim(0.0, 0.0)); d_result->setYPosition(UDim(0.0, 0.0)); d_result->setWidth(UDim(1.0, 0.0)); d_result->setHeight(UDim(1.0, 0.0)); d_result->setAlwaysOnTop(true); d_result->setProperty("HorzFormatting", "HorzCentred"); d_result->setVisible(false); d_result->setAlpha(0.67f); // activate the background window background->activate(); // success! return true; }