Пример #1
0
bool Demo6Sample::handleAddColumn(const CEGUI::EventArgs& e)
{
    using namespace CEGUI;

    // get access to the widgets that contain details about the column to add
    MultiColumnList* mcl = static_cast<MultiColumnList*>(WindowManager::getSingleton().getWindow("Demo6/MainList"));
    Editbox* idbox = static_cast<Editbox*>(WindowManager::getSingleton().getWindow("Demo6/ControlPanel/ColumnPanel/NewColIDBox"));
    Editbox* widthbox = static_cast<Editbox*>(WindowManager::getSingleton().getWindow("Demo6/ControlPanel/ColumnPanel/NewColWidthBox"));
    Editbox* textbox = static_cast<Editbox*>(WindowManager::getSingleton().getWindow("Demo6/ControlPanel/ColumnPanel/NewColTextBox"));

    // get ID for new column
    CEGUI::uint id = atoi(idbox->getText().c_str());
    // get width to use for new column (in pixels)
    float width = atof(widthbox->getText().c_str());
    // get column label text
    String text = textbox->getText();

    // re-set the widget contents
    idbox->setText("");
    widthbox->setText("");
    textbox->setText("");

    // ensure a minimum width of 10 pixels
    if (width < 10.0f)
        width = 10.0f;

    // finally, add the new column to the list.
    mcl->addColumn(text, id, cegui_absdim(width));

    // event was handled.
    return true;
}
Пример #2
0
  UiTest(const uvec2 & )  {
    Gui::init(uvec2(100, 200));
    gameList = Fics::GameSummary::parseList(Platform::getResourceString(Resource::MISC_GAMELIST_TXT));
    try {
      WindowManager & wmgr = WindowManager::getSingleton();
      rootWindow = wmgr.createWindow("DefaultWindow", "root");
      System::getSingleton().getDefaultGUIContext().setRootWindow(rootWindow);
      rootWindow->addChild(wmgr.loadLayoutFromFile("Login.layout"));


      //rb->setSelected(tc->getTabPanePosition() == TabControl::Top);
      //rb->subscribeEvent(
      //  RadioButton::EventSelectStateChanged,
      //  Event::Subscriber(&TabControlDemo::handleTabPanePos, this));
      //    bool handleTabPanePos(const EventArgs& e)
      //dumpWindows(rootWindow);
      rootWindow->getChild("LoginWindow/Login")->
        subscribeEvent(PushButton::EventClicked, [&](const EventArgs& e) -> bool {
          return true;
        });

#if 0
      rootWindow->addChild(wmgr.loadLayoutFromFile("TabControl.layout"));
      TabControl* tc = static_cast<TabControl*>(rootWindow->getChild("TabControl"));

      //// Add some pages to tab control
      tc->addTab(wmgr.loadLayoutFromFile("TabPage1.layout"));
      tc->addTab(wmgr.loadLayoutFromFile("TabPage2.layout"));

      MultiColumnList* mcl = static_cast<MultiColumnList*>(rootWindow->getChild("TabControl/Page1/MultiColumnList"));

      //MultiColumnList* mcl = static_cast<CEGUI::MultiColumnList*>(
      //  wmgr.createWindow("TaharezLook/MultiColumnList", "WidgetPropertiesDisplay")
      //);
      //Create the properties display window
      //mcl->setSize(CEGUI::USize(cegui_reldim(0.9f), cegui_reldim(0.9f)));
      //mcl->setPosition(CEGUI::UVector2(cegui_reldim(0.05f), cegui_reldim(0.05f)));
      //rootWindow->addChild(mcl);
      dumpWindows(rootWindow);



      //mcl->setShowHorzScrollbar(false);
      //mcl->setUserColumnDraggingEnabled(false);
      //mcl->setUserColumnSizingEnabled(true);

      //mcl->addColumn("Name", 0, cegui_reldim(0.45f));
      //mcl->addColumn("Type ", 1, cegui_reldim(0.25f));
      //mcl->addColumn("Value", 2, cegui_reldim(0.8f));


      //d_widgetPropertiesDisplayWindow->setSortColumnByID(0);
      //d_widgetPropertiesDisplayWindow->setSortDirection(CEGUI::ListHeaderSegment::Ascending);

      mcl->addColumn("Id", 0, cegui_reldim(0.05f));
      mcl->addColumn("Type", 1, cegui_reldim(0.07f));
      mcl->addColumn("Player (White)", 2, cegui_reldim(0.15f));
      mcl->addColumn("Rating", 3, cegui_reldim(0.07f));
      mcl->addColumn("Player (Black)", 4, cegui_reldim(0.15f));
      mcl->addColumn("Rating", 5, cegui_reldim(0.07f));
      mcl->addColumn("Private", 6, cegui_reldim(0.05f));
      mcl->addColumn("Rated", 7, cegui_reldim(0.05f));
      for (int i = 0; i < gameList.size(); ++i) {
        Fics::GameSummary & g = gameList[i];
        
        mcl->addRow();
        mcl->setItem(new ListboxTextItem(Platform::format("%d", g.id)), 0, i);
        mcl->setItem(new ListboxTextItem(g.private_ ? "Y" : "N"), 6, i);
        mcl->setItem(new ListboxTextItem(g.rated ? "Y" : "N"), 7, i);
        mcl->setItem(new ListboxTextItem(Chess::getTypeName(g.type)), 1, i);
        for (int j = 0; j < 2; ++j) {
          mcl->setItem(new ListboxTextItem(g.players[j]), 2 + (j * 2), i);
          mcl->setItem(new ListboxTextItem(Platform::format("%d", g.ratings[j])), 3 + (j * 2), i);
        }
      }
      // Add some empty rows to the MCL
      //multilineColumnList->addRow();
      //multilineColumnList->addRow();
      //multilineColumnList->addRow();
      //multilineColumnList->addRow();
      //multilineColumnList->addRow();

      //// Set first row item texts for the MCL
      //multilineColumnList->setItem(new MyListItem("Laggers World"), 0, 0);
      //multilineColumnList->setItem(new MyListItem("yourgame.some-server.com"), 1, 0);
      //multilineColumnList->setItem(new MyListItem("[colour='FFFF0000']1000ms"), 2, 0);

      //// Set second row item texts for the MCL
      //multilineColumnList->setItem(new MyListItem("Super-Server"), 0, 1);
      //multilineColumnList->setItem(new MyListItem("whizzy.fakenames.net"), 1, 1);
      //multilineColumnList->setItem(new MyListItem("[colour='FF00FF00']8ms"), 2, 1);

      //// Set third row item texts for the MCL
      //multilineColumnList->setItem(new MyListItem("Cray-Z-Eds"), 0, 2);
      //multilineColumnList->setItem(new MyListItem("crayzeds.notarealserver.co.uk"), 1, 2);
      //multilineColumnList->setItem(new MyListItem("[colour='FF00FF00']43ms"), 2, 2);

      //// Set fourth row item texts for the MCL
      //multilineColumnList->setItem(new MyListItem("Fake IPs"), 0, 3);
      //multilineColumnList->setItem(new MyListItem("123.320.42.242"), 1, 3);
      //multilineColumnList->setItem(new MyListItem("[colour='FFFFFF00']63ms"), 2, 3);

      //// Set fifth row item texts for the MCL
      //multilineColumnList->setItem(new MyListItem("Yet Another Game Server"), 0, 4);
      //multilineColumnList->setItem(new MyListItem("abc.abcdefghijklmn.org"), 1, 4);
      //multilineColumnList->setItem(new MyListItem("[colour='FFFF6600']284ms"), 2, 4);
      //FrameWindow* fWnd = static_cast<FrameWindow*>(
      //wmgr.createWindow("TaharezLook/FrameWindow", "testWindow"));
      //myRoot->addChild(fWnd);

      //FrameWindow * frame = static_cast<FrameWindow*>(rootWindow->getChild("Frame"));
      //fWnd->setPosition(UVector2(UDim(0.25f, 0.0f), UDim(0.25f, 0.0f)));
      //fWnd->setSize(USize(UDim(0.5f, 0.0f), UDim(0.5f, 0.0f)));
      //fWnd->setText("Hello World!");
#endif
    } catch (CEGUI::Exception & ex) {
      SAY(ex.getMessage().c_str());
    }
  }
Пример #3
0
static void init_sdlgui(char * skin_layout,int fullscreen)
{
	SDL_Surface * screen;
// 	atexit (SDL_Quit);
	SDL_Init (SDL_INIT_VIDEO);
	int videoFlags;
	const SDL_VideoInfo *videoInfo;
	videoInfo = SDL_GetVideoInfo( );

	if ( !videoInfo )
	{
	    fprintf( stderr, "Video query failed: %s\n",
		     SDL_GetError( ) );
	}

	/* the flags to pass to SDL_SetVideoMode */
	videoFlags  = SDL_OPENGL;          /* Enable OpenGL in SDL */
	videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
	videoFlags |= SDL_HWPALETTE;       /* Store the palette in hardware */
	videoFlags |= SDL_RESIZABLE;       /* Enable window resizing */
	
	/* This checks to see if surfaces can be stored in memory */
	if ( videoInfo->hw_available )
		videoFlags |= SDL_HWSURFACE;
	else
		videoFlags |= SDL_SWSURFACE;
	
	/* This checks if hardware blits can be done */
	if ( videoInfo->blit_hw )
		videoFlags |= SDL_HWACCEL;
	
	/* Sets up OpenGL double buffering */
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

	SDL_WM_SetCaption("NavIt - The OpenSource vector based navigation engine", NULL);

	/* get a SDL surface */
	screen = SDL_SetVideoMode( XRES, YRES, 32,
					videoFlags );

	if (screen == NULL) {
		fprintf (stderr, "Can't set SDL: %s\n", SDL_GetError ());
		exit (1);
	}
	if(fullscreen){
		SDL_WM_ToggleFullScreen(screen);
	}
	SDL_ShowCursor (SDL_ENABLE);
	SDL_EnableUNICODE (1);
	SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);

	init_GL();
	
// 	sdl_audio_init();

	try
	{
		renderer = new CEGUI::OpenGLRenderer(0,XRES,YRES);
		new CEGUI::System(renderer);

		using namespace CEGUI;

		SDL_ShowCursor(SDL_ENABLE);
		SDL_EnableUNICODE(1);
		SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
		
		CEGUI::DefaultResourceProvider* rp = static_cast<CEGUI::DefaultResourceProvider*>
		(System::getSingleton().getResourceProvider());
		

		// FIXME This should maybe move to navit.xml
		static char *datafiles_path[]={
			"./gui/sdl/datafiles",
			"/usr/share/navit/datafiles",
			"/usr/local/share/navit/datafiles",
			NULL,
		};

		char **filename=datafiles_path;

		while (*filename) {	
			if (FILE * file = fopen(*filename, "r"))
			{
				fclose(file);
				break;
			}
			filename++;
		}

		if(*filename==NULL){
			// FIXME Elaborate the possible solutions
			printf("Can't find the datafiles directory for CEGUI files. Navit will probably crash :)\n");
		} else {
			printf("Loading SDL datafiles from %s\n",*filename);
		}

		rp->setResourceGroupDirectory("schemes", g_strdup_printf("%s/schemes/",*filename));
		rp->setResourceGroupDirectory("imagesets", g_strdup_printf("%s/imagesets/",*filename));
		rp->setResourceGroupDirectory("fonts", g_strdup_printf("%s/fonts/",*filename));
		rp->setResourceGroupDirectory("layouts", g_strdup_printf("%s/layouts/",*filename));
		rp->setResourceGroupDirectory("looknfeels", g_strdup_printf("%s/looknfeel/",*filename));
		rp->setResourceGroupDirectory("lua_scripts", g_strdup_printf("%s/lua_scripts/",*filename));


		CEGUI::Imageset::setDefaultResourceGroup("imagesets");
		CEGUI::Font::setDefaultResourceGroup("fonts");
		CEGUI::Scheme::setDefaultResourceGroup("schemes");
		CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeels");
		CEGUI::WindowManager::setDefaultResourceGroup("layouts");
		CEGUI::ScriptModule::setDefaultResourceGroup("lua_scripts");

		char buffer [50];
		sprintf (buffer, "%s.scheme", skin_layout);
		dbg(1,"Loading scheme : %s\n",buffer);

		CEGUI::SchemeManager::getSingleton().loadScheme(buffer);

		CEGUI::FontManager::getSingleton().createFont("DejaVuSans-10.font");
		CEGUI::FontManager::getSingleton().createFont("DejaVuSans-14.font");

		CEGUI::System::getSingleton().setDefaultFont("DejaVuSans-10");

		CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();

		dbg(1,"Loading layout : %s\n",buffer);

		sprintf (buffer, "%s.layout", skin_layout);

		myRoot = CEGUI::WindowManager::getSingleton().loadWindowLayout(buffer);

 		CEGUI::System::getSingleton().setGUISheet(myRoot);

		try {

		CEGUI::WindowManager::getSingleton().getWindow("OSD/Quit")->subscribeEvent(PushButton::EventClicked, Event::Subscriber(ButtonQuit));
// 		CEGUI::WindowManager::getSingleton().getWindow("OSD/Quit")->setText(_("Quit"));

		CEGUI::WindowManager::getSingleton().getWindow("ZoomInButton")->subscribeEvent(PushButton::EventClicked, Event::Subscriber(ZoomIn));
// 		CEGUI::WindowManager::getSingleton().getWindow("ZoomInButton")->setText(_("ZoomIn"));

		CEGUI::WindowManager::getSingleton().getWindow("ZoomOutButton")->subscribeEvent(PushButton::EventClicked, Event::Subscriber(ZoomOut));
// 		CEGUI::WindowManager::getSingleton().getWindow("ZoomOutButton")->setText(_("ZoomOut"));

		CEGUI::WindowManager::getSingleton().getWindow("DestinationWindow/CountryEditbox")->subscribeEvent(Window::EventKeyUp, Event::Subscriber(DestinationEntryChange));
 		CEGUI::WindowManager::getSingleton().getWindow("DestinationWindow/CountryEditbox")->subscribeEvent(Window::EventMouseButtonDown, Event::Subscriber(handleMouseEnters));
		CEGUI::WindowManager::getSingleton().getWindow("DestinationWindow/TownEditbox")->subscribeEvent(Window::EventKeyUp, Event::Subscriber(DestinationEntryChange));
 		CEGUI::WindowManager::getSingleton().getWindow("DestinationWindow/TownEditbox")->subscribeEvent(Window::EventMouseButtonDown, Event::Subscriber(handleMouseEnters));
		CEGUI::WindowManager::getSingleton().getWindow("DestinationWindow/StreetEditbox")->subscribeEvent(Window::EventKeyUp, Event::Subscriber(DestinationEntryChange));
 		CEGUI::WindowManager::getSingleton().getWindow("DestinationWindow/StreetEditbox")->subscribeEvent(Window::EventMouseButtonDown, Event::Subscriber(handleMouseEnters));

		CEGUI::WindowManager::getSingleton().getWindow("DestinationButton")->subscribeEvent(PushButton::EventClicked, Event::Subscriber(DialogWindowSwitch));

		CEGUI::WindowManager::getSingleton().getWindow("OSD/ViewMode")->subscribeEvent(PushButton::EventClicked, Event::Subscriber(ToggleView));

		CEGUI::WindowManager::getSingleton().getWindow("DestinationWindow/GO")->subscribeEvent(PushButton::EventClicked, Event::Subscriber(ButtonGo));
		CEGUI::WindowManager::getSingleton().getWindow("DestinationWindow/KB")->subscribeEvent(PushButton::EventClicked, Event::Subscriber(ShowKeyboard));

		CEGUI::WindowManager::getSingleton().getWindow("DestinationWindow/Listbox")->subscribeEvent(MultiColumnList::EventSelectionChanged, Event::Subscriber(ItemSelect));


		// Translation for StaticTexts (labels)
		CEGUI::WindowManager::getSingleton().getWindow("DestinationWindow/Country")->setText(_("Country"));
		CEGUI::WindowManager::getSingleton().getWindow("DestinationWindow/Town")->setText(_("City"));
		CEGUI::WindowManager::getSingleton().getWindow("DestinationWindow/Street")->setText(_("Street"));

 		MultiColumnList* mcl = static_cast<MultiColumnList*>(WindowManager::getSingleton().getWindow("DestinationWindow/Listbox"));

		mcl->setSelectionMode(MultiColumnList::RowSingle) ;
		mcl->addColumn("Value", 0, cegui_absdim(200.0));
		mcl->addColumn("ID", 1, cegui_absdim(70.0));
		mcl->addColumn("Assoc", 2, cegui_absdim(70.0));
		mcl->addColumn("x", 3, cegui_absdim(70.0));
		mcl->addColumn("y", 4, cegui_absdim(70.0));

 		MultiColumnList* mcl2 = static_cast<MultiColumnList*>(WindowManager::getSingleton().getWindow("Roadbook"));

		mcl2->setSelectionMode(MultiColumnList::RowSingle) ;
		mcl2->addColumn("Instructions", 0, cegui_absdim(700.0));

 		BuildKeyboard();

		CEGUI::WindowManager::getSingleton().getWindow("OSD/Scrollbar1")->subscribeEvent(Scrollbar::EventScrollPositionChanged, Event::Subscriber(MoveCamera));

		CEGUI::WindowManager::getSingleton().getWindow("OSD/RoadbookButton")->subscribeEvent(PushButton::EventClicked, Event::Subscriber(RoadBookSwitch));
		CEGUI::WindowManager::getSingleton().getWindow("OSD/RoadbookButton")->setText(_("RoadBook"));

		CEGUI::WindowManager::getSingleton().getWindow("OSD/nGhostButton")->subscribeEvent(PushButton::EventClicked, Event::Subscriber(Switch_to_nGhost));
		// this one is maybe not needed anymore
		CEGUI::WindowManager::getSingleton().getWindow("OSD/RoadbookButton2")->subscribeEvent(PushButton::EventClicked, Event::Subscriber(RoadBookSwitch));

		}
		catch (CEGUI::Exception& e)
		{
			fprintf(stderr,"CEGUI Exception occured: \n%s\n", e.getMessage().c_str());
			printf("Missing control!...\n");
		}

	}
	catch (CEGUI::Exception& e)
	{
		fprintf(stderr,"CEGUI Exception occured: \n%s\n", e.getMessage().c_str());
		printf("quiting...\n");
		exit(1);
	}
	
}