示例#1
0
UIMenuBarEntry *UIMenuBar::addMenuBarEntry(String name) {
	UIMenuBarEntry *newEntry = new UIMenuBarEntry(name);
	entries.push_back(newEntry);
	addChild(newEntry);
	newEntry->setPosition(entryOffset, 0);
	entryOffset += newEntry->width;

	newEntry->bg->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
	newEntry->bg->addEventListener(this, InputEvent::EVENT_MOUSEUP);
	newEntry->bg->addEventListener(this, InputEvent::EVENT_MOUSEUP_OUTSIDE);
	newEntry->bg->addEventListener(this, InputEvent::EVENT_MOUSEMOVE);

	return newEntry;
}
示例#2
0
PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
	core = new POLYCODE_CORE(view, 900,700,false,true, 0, 0,30, -1);	
//	core->pauseOnLoseFocus = true;
	
	runNextFrame = false;
	
	core->addEventListener(this, Core::EVENT_CORE_RESIZE);
	core->addEventListener(this, Core::EVENT_LOST_FOCUS);
	core->addEventListener(this, Core::EVENT_GAINED_FOCUS);
			
	globalClipboard = new PolycodeClipboard();
	
	CoreServices::getInstance()->getRenderer()->setTextureFilteringMode(Renderer::TEX_FILTERING_NEAREST);
				
	CoreServices::getInstance()->getResourceManager()->addArchive("default.pak");
	CoreServices::getInstance()->getResourceManager()->addDirResource("default");	

	CoreServices::getInstance()->getResourceManager()->addArchive("hdr.pak");
	CoreServices::getInstance()->getResourceManager()->addDirResource("hdr");	


	CoreServices::getInstance()->getResourceManager()->addArchive("api.pak");
	CoreServices::getInstance()->getResourceManager()->addArchive("Physics2D.pak");
	CoreServices::getInstance()->getResourceManager()->addArchive("Physics3D.pak");
	CoreServices::getInstance()->getResourceManager()->addArchive("UI.pak");
			
	CoreServices::getInstance()->getConfig()->loadConfig("Polycode", "UIThemes/default/theme.xml");
	CoreServices::getInstance()->getResourceManager()->addArchive("UIThemes/default/");
	CoreServices::getInstance()->getResourceManager()->addArchive("Images/");	

	CoreServices::getInstance()->getFontManager()->registerFont("section", "Fonts/Roboto-Thin.ttf");

	CoreServices::getInstance()->getRenderer()->clearColor.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiBgColor"));

//	CoreServices::getInstance()->getRenderer()->setTextureFilteringMode(Renderer::TEX_FILTERING_LINEAR);
	CoreServices::getInstance()->getRenderer()->setTextureFilteringMode(Renderer::TEX_FILTERING_NEAREST);
	
	willRunProject = false;

	globalMenu	= new UIGlobalMenu();
		
	printf("creating font editor\n"); 
	
	Screen *screen = new Screen();	
	screen->rootEntity.setDefaultScreenOptions(true);
	
	editorManager = new PolycodeEditorManager();
	
	frame = new PolycodeFrame();
	frame->setPositionMode(ScreenEntity::POSITION_TOPLEFT);

	frame->editorManager = editorManager;
	editorManager->addEventListener(frame, Event::CHANGE_EVENT);

	frame->console->backtraceWindow->addEventListener(this, BackTraceEvent::EVENT_BACKTRACE_SELECTED);

	frame->textInputPopup->addEventListener(this, UIEvent::OK_EVENT);	

	frame->yesNoPopup->addEventListener(this, UIEvent::OK_EVENT);
	frame->yesNoPopup->addEventListener(this, UIEvent::CANCEL_EVENT);

	frame->yesNoCancelPopup->addEventListener(this, UIEvent::YES_EVENT);
	frame->yesNoCancelPopup->addEventListener(this, UIEvent::NO_EVENT);

	
	frame->newProjectWindow->addEventListener(this, UIEvent::OK_EVENT);
	frame->exportProjectWindow->addEventListener(this, UIEvent::OK_EVENT);
	frame->newFileWindow->addEventListener(this, UIEvent::OK_EVENT);	
	frame->exampleBrowserWindow->addEventListener(this, UIEvent::OK_EVENT);
	
	frame->playButton->addEventListener(this, UIEvent::CLICK_EVENT);
	frame->stopButton->addEventListener(this, UIEvent::CLICK_EVENT);

	screen->addChild(frame);

	
	projectManager = new PolycodeProjectManager();
	projectManager->setProjectBrowser(frame->getProjectBrowser());
	
	frame->projectManager = projectManager;

	projectManager->addEventListener(frame, Event::CHANGE_EVENT);
	
	frame->getProjectBrowser()->addEventListener(this, Event::CHANGE_EVENT);
	frame->getProjectBrowser()->addEventListener(this, PolycodeProjectBrowserEvent::HANDLE_MENU_COMMAND);
	
	frame->Resize(core->getXRes(), core->getYRes());	

	
	debugger = new PolycodeRemoteDebugger(projectManager);
	frame->console->setDebugger(debugger);
	
	editorManager->registerEditorFactory(new PolycodeImageEditorFactory());
	editorManager->registerEditorFactory(new PolycodeMaterialEditorFactory());	
	editorManager->registerEditorFactory(new PolycodeScreenEditorFactory());	
	editorManager->registerEditorFactory(new PolycodeFontEditorFactory());
	editorManager->registerEditorFactory(new PolycodeTextEditorFactory());
	editorManager->registerEditorFactory(new PolycodeProjectEditorFactory(projectManager));
	editorManager->registerEditorFactory(new PolycodeSpriteEditorFactory());

		
	screen->addChild(globalMenu);	
				
	loadConfigFile();
	frame->console->applyTheme();

#ifdef USE_POLYCODEUI_MENUBAR
	menuBar = new UIMenuBar(100, globalMenu);

	UIMenuBarEntry *fileEntry = menuBar->addMenuBarEntry("File");
	fileEntry->addItem("New File", "new_file", KEY_n);
	fileEntry->addItem("New Project", "new_project", KEY_LSHIFT, KEY_n);
	fileEntry->addItem("New Folder", "new_folder", KEY_LSHIFT, KEY_f);
	fileEntry->addItem("Open Project", "open_project", KEY_LSHIFT, KEY_o);
	fileEntry->addItem("Close Project", "close_project", KEY_LSHIFT, KEY_w);
	fileEntry->addItem("Remove File", "remove_file");
	fileEntry->addItem("Refresh Project", "refresh_project");
	fileEntry->addItem("Save File", "save_file", KEY_s);
	fileEntry->addItem("Browse Examples", "browse_examples", KEY_LSHIFT, KEY_e);
	fileEntry->addItem("Quit", "quit");

	UIMenuBarEntry *editEntry = menuBar->addMenuBarEntry("Edit");
	editEntry->addItem("Undo", "undo");
	editEntry->addItem("Redo", "redo");
	editEntry->addItem("Cut", "cut");
	editEntry->addItem("Copy", "copy");

	UIMenuBarEntry *projectEntry = menuBar->addMenuBarEntry("Project");
	projectEntry->addItem("Run Project", "run_project", KEY_r);
	projectEntry->addItem("Publish Project", "export_project");

	UIMenuBarEntry *helpEntry = menuBar->addMenuBarEntry("Help");
	helpEntry->addItem("API Reference", "show_api");
	helpEntry->addItem("About Polycode", "show_about");


	menuBar->addEventListener(this, UIEvent::OK_EVENT);

	screen->addChild(menuBar);
	frame->position.y = 25;
#else
	menuBar = NULL;
#endif
	core->setVideoMode(1100, 700, false, true, 0, 0);

	needsRedraw = false;
	lastConnected = false;
}
示例#3
0
PolycodeIDEApp::PolycodeIDEApp(PolycodeViewBase *view) : EventDispatcher() {
#else
PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
#endif
	core = new POLYCODE_CORE((PolycodeView*)view, 1100, 700,false,false, 0, 0,60, -1, true);
//	core->pauseOnLoseFocus = true;
    
	printf("DIR: %s\n", core->getDefaultWorkingDirectory().c_str());

    Entity::defaultBlendingMode = Renderer::BLEND_MODE_NONE;
	
    ResourcePool::defaultReloadResourcesOnModify = true;
    Resource::defaultReloadOnFileModify = true;
    
	CoreServices::getInstance()->getResourceManager()->getGlobalPool()->reloadResourcesOnModify = true;
	
    
	runNextFrame = false;
	
	core->addEventListener(this, Core::EVENT_CORE_RESIZE);
	core->addEventListener(this, Core::EVENT_LOST_FOCUS);
	core->addEventListener(this, Core::EVENT_GAINED_FOCUS);
			
	globalClipboard = new PolycodeClipboard();
	
	CoreServices::getInstance()->getRenderer()->setTextureFilteringMode(Renderer::TEX_FILTERING_NEAREST);
				
	CoreServices::getInstance()->getResourceManager()->addArchive("default.pak");
	CoreServices::getInstance()->getResourceManager()->addDirResource("default");	

	CoreServices::getInstance()->getResourceManager()->addArchive("hdr.pak");
	CoreServices::getInstance()->getResourceManager()->addDirResource("hdr");


	CoreServices::getInstance()->getResourceManager()->addArchive("api.pak");
	CoreServices::getInstance()->getResourceManager()->addArchive("Physics2D.pak");
	CoreServices::getInstance()->getResourceManager()->addArchive("Physics3D.pak");
	CoreServices::getInstance()->getResourceManager()->addArchive("UI.pak");

	CoreServices::getInstance()->getResourceManager()->addDirResource("Materials");	
			
	CoreServices::getInstance()->getFontManager()->registerFont("section", "Fonts/RobotoCondensed-Bold.ttf");


	CoreServices::getInstance()->getRenderer()->setTextureFilteringMode(Renderer::TEX_FILTERING_LINEAR);
//	CoreServices::getInstance()->getRenderer()->setTextureFilteringMode(Renderer::TEX_FILTERING_NEAREST);
	
	loadConfigFile();	

	String themeName = CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiTheme");
	
    if(core->getBackingXRes() == core->getXRes()) {
        CoreServices::getInstance()->getResourceManager()->addArchive("Images");
    } else {
        CoreServices::getInstance()->getResourceManager()->addArchive("ImagesRetina");
        if(OSBasics::fileExists("UIThemes/"+themeName+"_retina")) {
            themeName = themeName + "_retina";
        }
    }
    
    printf("LOADING THEME: %s\n", themeName.c_str());
    
	CoreServices::getInstance()->getConfig()->loadConfig("Polycode", "UIThemes/"+themeName+"/theme.xml");
	CoreServices::getInstance()->getResourceManager()->addArchive("UIThemes/"+themeName+"/");
    
	
	willRunProject = false;

	SceneLabel::defaultAnchor = Vector3(-1.0, -1.0, 0.0);
	SceneLabel::defaultPositionAtBaseline = true;
	SceneLabel::defaultSnapToPixels = true;
	SceneLabel::createMipmapsForLabels = false;
			
	globalMenu	= new UIGlobalMenu();
	UITextInput::setMenuSingleton(globalMenu);
			
	
	Scene *screen = new Scene(Scene::SCENE_2D_TOPLEFT);
    
    screen->doVisibilityChecking(false);
    screen->getDefaultCamera()->frustumCulling = false;
    
    globalScene = screen;
    
	screen->rootEntity.processInputEvents = true;
//	screen->rootEntity.setDefaultScreenOptions(true);

	screen->clearColor.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiBgColor"));	
	screen->useClearColor = true;
	
	editorManager = new PolycodeEditorManager();
	globalEditorManager = editorManager;
	
	frame = new PolycodeFrame(editorManager);
	frame->setAnchorPoint(-1.0, -1.0, 0.0);

	editorManager->addEventListener(frame, Event::CHANGE_EVENT);

	frame->console->backtraceWindow->addEventListener(this, BackTraceEvent::EVENT_BACKTRACE_SELECTED);

	frame->textInputPopup->addEventListener(this, UIEvent::OK_EVENT);	

	frame->yesNoPopup->addEventListener(this, UIEvent::OK_EVENT);
	frame->yesNoPopup->addEventListener(this, UIEvent::CANCEL_EVENT);

	frame->yesNoCancelPopup->addEventListener(this, UIEvent::YES_EVENT);
	frame->yesNoCancelPopup->addEventListener(this, UIEvent::NO_EVENT);
	
	frame->newProjectWindow->addEventListener(this, UIEvent::OK_EVENT);
	frame->exportProjectWindow->addEventListener(this, UIEvent::OK_EVENT);
	frame->newFileWindow->addEventListener(this, UIEvent::OK_EVENT);	
	frame->exampleBrowserWindow->addEventListener(this, UIEvent::OK_EVENT);
	frame->settingsWindow->addEventListener(this, UIEvent::OK_EVENT);
	frame->settingsWindow->addEventListener(this, UIEvent::CLOSE_EVENT);
	
	frame->playButton->addEventListener(this, UIEvent::CLICK_EVENT);
	frame->stopButton->addEventListener(this, UIEvent::CLICK_EVENT);
	
	frame->addEventListener(this, UIEvent::CLOSE_EVENT);
	frame->addEventListener(this, Event::CHANGE_EVENT);	
	screen->addChild(frame);
	
	projectManager = new PolycodeProjectManager();
	editorManager->setProjectManager(projectManager);
		
	frame->projectManager = projectManager;
	projectManager->addEventListener(frame, Event::CHANGE_EVENT);
	projectManager->addEventListener(this, Event::CHANGE_EVENT);
			
//	frame->Resize(core->getXRes(), core->getYRes());	
	
	debugger = new PolycodeRemoteDebugger(projectManager);
	frame->console->setDebugger(debugger);
	
	editorManager->registerEditorFactory(new PolycodeImageEditorFactory());
	editorManager->registerEditorFactory(new PolycodeMaterialEditorFactory());	
	editorManager->registerEditorFactory(new PolycodeFontEditorFactory());
	editorManager->registerEditorFactory(new PolycodeTextEditorFactory());
	editorManager->registerEditorFactory(new PolycodeProjectEditorFactory(projectManager));
	editorManager->registerEditorFactory(new PolycodeSpriteEditorFactory());
	editorManager->registerEditorFactory(new PolycodeMeshEditorFactory());
	editorManager->registerEditorFactory(new PolycodeEntityEditorFactory());
			
	screen->addChild(globalMenu);	
				
	frame->console->applyTheme();

#ifdef USE_POLYCODEUI_MENUBAR
	menuBar = new UIMenuBar(100, globalMenu);

	UIMenuBarEntry *fileEntry = menuBar->addMenuBarEntry("File");
	fileEntry->addItem("New File", "new_file", KEY_n);
	fileEntry->addItem("New Project", "new_project", KEY_LSHIFT, KEY_n);
	fileEntry->addItem("New Folder", "new_folder", KEY_LSHIFT, KEY_f);
	fileEntry->addItem("Open Project", "open_project", KEY_LSHIFT, KEY_o);
	fileEntry->addItem("Close Project", "close_project", KEY_LSHIFT, KEY_w);
	fileEntry->addItem("Close File", "close_file", KEY_w);
	fileEntry->addItem("Remove File", "remove_file");
	fileEntry->addItem("Refresh Project", "refresh_project");
	fileEntry->addItem("Save File", "save_file", KEY_s);
	fileEntry->addItem("Browse Examples", "browse_examples", KEY_LSHIFT, KEY_e);
	fileEntry->addItem("Quit", "quit");

	UIMenuBarEntry *editEntry = menuBar->addMenuBarEntry("Edit");
	editEntry->addItem("Undo", "undo");
	editEntry->addItem("Redo", "redo");
	editEntry->addItem("Cut", "cut");
	editEntry->addItem("Copy", "copy");
	editEntry->addItem("Find", "find", KEY_f);
	editEntry->addItem("Settings", "settings");

	UIMenuBarEntry *viewEntry = menuBar->addMenuBarEntry("View");
	viewEntry->addItem("Toggle Console", "toggle_console", KEY_LSHIFT, KEY_t);

	UIMenuBarEntry *projectEntry = menuBar->addMenuBarEntry("Project");
	projectEntry->addItem("Run Project", "run_project", KEY_r);
	projectEntry->addItem("Publish Project", "export_project");

	UIMenuBarEntry *helpEntry = menuBar->addMenuBarEntry("Help");
	helpEntry->addItem("API Reference", "show_api");
	helpEntry->addItem("About Polycode", "show_about");


	menuBar->addEventListener(this, UIEvent::OK_EVENT);

	screen->addChild(menuBar);
	frame->setPositionY(25);
#else
	menuBar = NULL;
#endif

	needsRedraw = false;
	lastConnected = false;
	
	quittingApp = false;
	
	CoreServices::getInstance()->getCore()->getInput()->addEventListener(this, InputEvent::EVENT_KEYDOWN);
	
	applyFinalConfig();
    
    core->updateAndRender();
    frame->Resize(core->getXRes(), core->getYRes());

}

void PolycodeIDEApp::renameFile() {
	if(projectManager->selectedFile != "") {
		frame->textInputPopup->action = "renameFile";
		frame->textInputPopup->setCaption("Enter new filename");
		frame->textInputPopup->setValue(projectManager->selectedFileEntry.name);
		frame->showModal(frame->textInputPopup);
	}
}

void PolycodeIDEApp::showAbout() {
	frame->showModal(frame->aboutWindow);
}