//! Adds a context menu to the environment.
IGUIContextMenu* CGUIEnvironment::addContextMenu(const core::rect<s32>& rectangle,
                                                 IGUIElement* parent, s32 id)
{
	IGUIContextMenu* c = new CGUIContextMenu(this,
	                                         parent ? parent : this, id, rectangle);
	c->drop();
	return c;
}
Exemple #2
0
bool Editor::OnEvent(const SEvent& event)
{
	if (event.EventType == irr::EET_MOUSE_INPUT_EVENT &&
		event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP ){
		GetState()->mousedown=false;
	}else if (event.EventType == irr::EET_MOUSE_INPUT_EVENT &&
		event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN ){
		GetState()->mousedown=true;
	}else if (event.EventType == irr::EET_MOUSE_INPUT_EVENT &&
		event.MouseInput.Event == EMIE_MOUSE_MOVED ){
		GetState()->mouse_position.X=event.MouseInput.X;
		GetState()->mouse_position.Y=event.MouseInput.Y;
	}

	if (GetState()->Mode()){
		if (GetState()->Mode()->OnEvent(event)){
			return true;
		}
	}

	if (GetState()->Menu()){
		if (GetState()->Menu()->OnEvent(event)){
			return true;
		}
	}

	if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.Key < NUMBER_OF_KEYS){
		if (event.KeyInput.PressedDown){
			GetState()->keys[event.KeyInput.Key] = EKS_DOWN;
		}else{
			GetState()->keys[event.KeyInput.Key] = EKS_UP;
		}
	}
	if (event.EventType == EET_GUI_EVENT){
		if (event.GUIEvent.EventType == EGET_MENU_ITEM_SELECTED){
			IGUIContextMenu* menu = (IGUIContextMenu*)event.GUIEvent.Caller;
			switch (menu->getItemCommandId(menu->getSelectedItem())){
			case GUI_VIEW_SP_ALL:
				currentWindow = -1;
				break;
			case GUI_VIEW_SP_PER:
				currentWindow = 0;
				break;
			case GUI_VIEW_SP_TOP:
				currentWindow = 1;
				break;
			case GUI_VIEW_SP_FRT:
				currentWindow = 2;
				break;
			case GUI_VIEW_SP_RHT:
				currentWindow = 3;
				break;
			}
		}
	}
	return false;
}
extern "C" CAMLprim value ml_IGUIContextMenu_addItem_native(
		value v_cm, value v_text, value v_cmd_id, value v_enabled,
		value v_has_submenu, value v_checked, value v_auto_checking) {
	int text_size = caml_string_length(v_text);
	IGUIContextMenu* cm = (IGUIContextMenu*) v_cm;
	wchar_t text[text_size + 1];
	u32 idx;
	mbstowcs(text, String_val(v_text), text_size);
	idx = cm->addItem(text, Bool_val(v_enabled), Bool_val(v_has_submenu),
		Bool_val(v_checked), Bool_val(v_auto_checking));
	return Val_int(idx);
}
//! Adds a menu to the environment.
IGUIContextMenu* CGUIEnvironment::addMenu(IGUIElement* parent, s32 id)
{
	if (!parent)
		parent = this;

	IGUIContextMenu* c = new CGUIMenu(this,
	                                  parent, id, core::rect<s32>(0,0,
	                                                              parent->getAbsolutePosition().getWidth(),
	                                                              parent->getAbsolutePosition().getHeight()));

	c->drop();
	return c;
}
Exemple #5
0
bool Desktop::OnGUIMenuItemSelected(irr::SEvent::SGUIEvent event)
{
  IGUIContextMenu* pMenu = (IGUIContextMenu*)event.Caller;
  s32 selItem = pMenu->getSelectedItem();

  switch ( pMenu->getItemCommandId(selItem) )
  {
  case  MENUITEM_SOFTWAREMGR:   // Software Manager
    {
      OpenSoftwareManagerWindow();
    }
    break;

  case  MENUITEM_ITEMMGR:       // Item Manager
    {
      OpenItemManagerWindow();
    }
    break;

  case	MENUITEM_CHARINFO:			// Character Info
	  {
	  }
	  break;

  case	MENUITEM_SYSTEMINFO:	  // System Info
	  {
	  }
	  break;

  case	MENUITEM_ABOUT:					// About FireCell
	  {
      Environment->addMessageBox( ResourceManager::instance().GetClientString(STR_ABOUT_CAPTION).c_str(),
                                  ResourceManager::instance().GetClientString(STR_ABOUT_TEXT).c_str() );
	  }
	  break;

  case	MENUITEM_EXIT:					// Quit FireCell
	  {
		  FCViewEvent e(VE_ClientExit);
		  m_owner.GetContainer()->GetController()->OnViewEvent(e);
	  }
	  break;

  default:
	  break;
  }

  return false;
}
Exemple #6
0
/** Debug menu handling */
bool onEvent(const SEvent &event)
{
    // Only activated in artist debug mode
    if(!UserConfigParams::m_artist_debug_mode)
        return true;    // keep handling the events

    if(event.EventType == EET_MOUSE_INPUT_EVENT)
    {
        // Create the menu (only one menu at a time)
        if(event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN &&
             !g_debug_menu_visible)
        {
            irr_driver->getDevice()->getCursorControl()->setVisible(true);

            // root menu
            gui::IGUIEnvironment* guienv = irr_driver->getGUI();
            core::rect<s32> r(100, 50, 150, 500);
            IGUIContextMenu* mnu = guienv->addContextMenu(r, NULL);
            int graphicsMenuIndex = mnu->addItem(L"Graphics >",-1,true,true);

            // graphics menu
            IGUIContextMenu* sub = mnu->getSubMenu(graphicsMenuIndex);

            sub->addItem(L"Reload shaders", DEBUG_GRAPHICS_RELOAD_SHADERS );
            sub->addItem(L"Wireframe", DEBUG_GRAPHICS_WIREFRAME );
            sub->addItem(L"Mipmap viz", DEBUG_GRAPHICS_MIPMAP_VIZ );
            sub->addItem(L"Normals viz", DEBUG_GRAPHICS_NORMALS_VIZ );
            sub->addItem(L"SSAO viz", DEBUG_GRAPHICS_SSAO_VIZ );
            sub->addItem(L"RSM viz", DEBUG_GRAPHICS_RSM_VIZ);
            sub->addItem(L"RH viz", DEBUG_GRAPHICS_RH_VIZ);
            sub->addItem(L"GI viz", DEBUG_GRAPHICS_GI_VIZ);
            sub->addItem(L"Shadow viz", DEBUG_GRAPHICS_SHADOW_VIZ );
            sub->addItem(L"Light viz", DEBUG_GRAPHICS_LIGHT_VIZ );
            sub->addItem(L"Distort viz", DEBUG_GRAPHICS_DISTORT_VIZ );
            sub->addItem(L"Physics debug", DEBUG_GRAPHICS_BULLET_1);
            sub->addItem(L"Physics debug (no kart)", DEBUG_GRAPHICS_BULLET_2);
            sub->addItem(L"Bounding Boxes viz", DEBUG_GRAPHICS_BOUNDING_BOXES_VIZ);
            sub->addItem(L"Reset debug views", DEBUG_GRAPHICS_RESET );

            mnu->addItem(L"Items >",-1,true,true);
            sub = mnu->getSubMenu(1);
            sub->addItem(L"Basketball", DEBUG_POWERUP_RUBBERBALL );
            sub->addItem(L"Bowling", DEBUG_POWERUP_BOWLING );
            sub->addItem(L"Bubblegum", DEBUG_POWERUP_BUBBLEGUM );
            sub->addItem(L"Cake", DEBUG_POWERUP_CAKE );
            sub->addItem(L"Parachute", DEBUG_POWERUP_PARACHUTE );
            sub->addItem(L"Plunger", DEBUG_POWERUP_PLUNGER );
            sub->addItem(L"Swatter", DEBUG_POWERUP_SWATTER );
            sub->addItem(L"Switch", DEBUG_POWERUP_SWITCH );
            sub->addItem(L"Zipper", DEBUG_POWERUP_ZIPPER );
            sub->addItem(L"Nitro", DEBUG_POWERUP_NITRO );

            mnu->addItem(L"Attachments >",-1,true, true);
            sub = mnu->getSubMenu(2);
            sub->addItem(L"Bomb", DEBUG_ATTACHMENT_BOMB);
            sub->addItem(L"Anvil", DEBUG_ATTACHMENT_ANVIL);
            sub->addItem(L"Parachute", DEBUG_ATTACHMENT_PARACHUTE);

            mnu->addItem(L"GUI >",-1,true, true);
            sub = mnu->getSubMenu(3);
            sub->addItem(L"Toggle GUI", DEBUG_GUI_TOGGLE);
            sub->addItem(L"Hide karts", DEBUG_GUI_HIDE_KARTS);
            sub->addItem(L"Top view", DEBUG_GUI_CAM_TOP);
            sub->addItem(L"Behind wheel view", DEBUG_GUI_CAM_WHEEL);
            sub->addItem(L"Behind kart view", DEBUG_GUI_CAM_BEHIND_KART);
            sub->addItem(L"Side of kart view", DEBUG_GUI_CAM_SIDE_OF_KART);
            sub->addItem(L"First person view (Ctrl + F1)", DEBUG_GUI_CAM_FREE);
            sub->addItem(L"Normal view (Ctrl + F2)", DEBUG_GUI_CAM_NORMAL);
            sub->addItem(L"Toggle smooth camera", DEBUG_GUI_CAM_SMOOTH);
            sub->addItem(L"Attach fps camera to kart", DEBUG_GUI_CAM_ATTACH);

            mnu->addItem(L"Change camera target >",-1,true, true);
            sub = mnu->getSubMenu(4);
            sub->addItem(L"To kart one", DEBUG_VIEW_KART_ONE);
            sub->addItem(L"To kart two", DEBUG_VIEW_KART_TWO);
            sub->addItem(L"To kart three", DEBUG_VIEW_KART_THREE);
            sub->addItem(L"To kart four", DEBUG_VIEW_KART_FOUR);
            sub->addItem(L"To kart five", DEBUG_VIEW_KART_FIVE);
            sub->addItem(L"To kart six", DEBUG_VIEW_KART_SIX);
            sub->addItem(L"To kart seven", DEBUG_VIEW_KART_SEVEN);
            sub->addItem(L"To kart eight", DEBUG_VIEW_KART_EIGHT);

            mnu->addItem(L"Font >",-1,true, true);
            sub = mnu->getSubMenu(5);
            sub->addItem(L"Dump glyph pages of fonts", DEBUG_FONT_DUMP_GLYPH_PAGE);
            sub->addItem(L"Reload all fonts", DEBUG_FONT_RELOAD);

            mnu->addItem(L"Adjust values", DEBUG_VISUAL_VALUES);

            mnu->addItem(L"Profiler", DEBUG_PROFILER);
            if (UserConfigParams::m_profiler_enabled)
                mnu->addItem(L"Toggle capture profiler report",
                             DEBUG_PROFILER_GENERATE_REPORT);
            mnu->addItem(L"Do not limit FPS", DEBUG_THROTTLE_FPS);
            mnu->addItem(L"Toggle FPS", DEBUG_FPS);
            mnu->addItem(L"Save replay", DEBUG_SAVE_REPLAY);
            mnu->addItem(L"Save history", DEBUG_SAVE_HISTORY);
            mnu->addItem(L"Print position", DEBUG_PRINT_START_POS);
            mnu->addItem(L"Adjust Lights", DEBUG_ADJUST_LIGHTS);
            mnu->addItem(L"Scripting console", DEBUG_SCRIPT_CONSOLE);

            g_debug_menu_visible = true;
            irr_driver->showPointer();
        }

        // Let Irrlicht handle the event while the menu is visible.
        // Otherwise in a race the GUI events won't be generated
        if(g_debug_menu_visible)
            return false;
    }

    if (event.EventType == EET_GUI_EVENT)
    {
        if (event.GUIEvent.Caller != NULL &&
            event.GUIEvent.Caller->getType() == EGUIET_CONTEXT_MENU )
        {
            IGUIContextMenu *menu = (IGUIContextMenu*)event.GUIEvent.Caller;
            s32 cmdID = menu->getItemCommandId(menu->getSelectedItem());

            if (event.GUIEvent.EventType == EGET_ELEMENT_CLOSED)
            {
                g_debug_menu_visible = false;
            }
            else if (event.GUIEvent.EventType == gui::EGET_MENU_ITEM_SELECTED)
            {
                return handleContextMenuAction(cmdID);
            }
            return false;
        }
    }
    return true;    // continue event handling
}   // onEvent
bool MenuState::OnEvent(const SEvent& event) {
    if (event.EventType == EET_GUI_EVENT) {
        if (event.GUIEvent.EventType == EGET_MENU_ITEM_SELECTED) {
            IGUIContextMenu* menu = (IGUIContextMenu*)event.GUIEvent.Caller;
            switch (menu->getItemCommandId(menu->getSelectedItem())) {
            case GUI_FILE_OPEN_PROJECT:
            {
                NBEFileParser parser(GetState());
                Project* tmp = parser.open("save.nbe");

                if (tmp) {
                    delete GetState()->project;
                    GetState()->project = tmp;
                    GetState()->project->SelectNode(0);
                    GetState()->Mode()->unload();
                    init();
                    GetState()->Mode()->load();
                }
                return true;
            }
            break;
            case GUI_FILE_SAVE_PROJECT:
            {
                NBEFileParser parser(GetState());
                parser.save(GetState()->project,"save.nbe");
                return true;
            }
            break;
            case GUI_FILE_EXPORT:
            {
                LUAFileParser parser(GetState());
                parser.save(GetState()->project,"export.lua");
                return true;
            }
            break;
            case GUI_FILE_EXIT:
            {
                IGUIEnvironment* guienv = GetState()->GetDevice()->getGUIEnvironment();
                IGUIWindow* win = guienv->addWindow(rect<irr::s32>(100,100,356,215),true,L"Are you sure?");
                guienv->addButton(rect<irr::s32>(128-40,80,128+40,105),win,GUI_FILE_EXIT,L"Close",L"Close the editor");
                return true;
            }
            break;
            case GUI_EDIT_SNAP:
            {
                if (menu->isItemChecked(menu->getSelectedItem()))
                    GetState()->Settings()->setStringSetting("snapping","true");
                else
                    GetState()->Settings()->setStringSetting("snapping","false");

                menu->setItemChecked(menu->getSelectedItem(),GetState()->Settings()->getSettingAsBool("snapping"));
            }
            break;
            case GUI_EDIT_LIMIT:
            {
                if (menu->isItemChecked(menu->getSelectedItem()))
                    GetState()->Settings()->setStringSetting("limiting","true");
                else
                    GetState()->Settings()->setStringSetting("limiting","false");

                menu->setItemChecked(menu->getSelectedItem(),GetState()->Settings()->getSettingAsBool("limiting"));
            }
            break;
            case GUI_HELP_ABOUT:
            {
                core::stringw msg = L"The Nodebox Editor\n"
                                    L"Version: ";

                msg.append(EDITOR_TEXT_VERSION);
                msg.append(
                    L"\n\n"
                    L"This free nodebox editor was made by rubenwardy in C++ and Irrlicht.\n"
                    L"You can download newer versions from the Minetest forum."
                );

                GetState()->GetDevice()->getGUIEnvironment()->addMessageBox(L"About",msg.c_str());
                return true;
            }
            break;
            }
        } else if(event.GUIEvent.EventType == EGET_BUTTON_CLICKED) {
            if (event.GUIEvent.Caller->getID() == GUI_FILE_EXIT) {
                NBEFileParser parser(GetState());
                parser.save(GetState()->project,"exit.nbe");
                GetState()->CloseEditor();
                return true;
            }
        }
    }
    return false;
}
Exemple #8
0
bool EditorEventReceiver::OnEvent(const SEvent &event)
{
	if (!device || !env)
		return false;

	gui::IGUIElement* root = env->getRootGUIElement();
	core::stringc s = "";

	// Mouse
	if (event.EventType == EET_MOUSE_INPUT_EVENT)
	{
		scene::ICameraSceneNode * activeCam = smgr->getActiveCamera();

		/*if (event.MouseInput.Control || event.MouseInput.Shift)
			activeCam->setInputReceiverEnabled( false );
		else
			activeCam->setInputReceiverEnabled( true );*/


		if (event.MouseInput.isLeftPressed() && event.MouseInput.Control)
		{
			editor->selectNode();
		}
		else if (event.MouseInput.Shift && event.MouseInput.Event == EMIE_MOUSE_MOVED)
		{
			position2di mousePos;
			mousePos.X = event.MouseInput.X;
            mousePos.Y = event.MouseInput.Y; 
			if ((oldMousePos - mousePos).getLength() > 10)
				oldMousePos = mousePos;
			editor->moveSelectedNode(vector3df(
				(mousePos.X - oldMousePos.X) * cos(activeCam->getRotation().Y) + (mousePos.Y - oldMousePos.Y) * sin(activeCam->getRotation().Y),
				0,
				(mousePos.X - oldMousePos.X) * sin(activeCam->getRotation().Y) + (mousePos.Y - oldMousePos.Y) * cos(activeCam->getRotation().Y)));
			oldMousePos = mousePos;
		}
	}


	// Key pressed once
	if (event.EventType == EET_KEY_INPUT_EVENT &&
		event.KeyInput.PressedDown == false)
	{
		switch(event.KeyInput.Key)
		{
		// press escape to go back to maya view
		case KEY_ESCAPE:
			{
				setActiveCamera(camera[0]);
				if (root->getElementFromId(GUI_ID_STATIC_TEXT_CAMERA_FPS, true))
					root->getElementFromId(GUI_ID_STATIC_TEXT_CAMERA_FPS, true)->remove();
				break;
			}
		}
	}

	// Key pressed
	if (event.EventType == EET_KEY_INPUT_EVENT &&
		event.KeyInput.PressedDown == true)
	{
		switch(event.KeyInput.Key)
		{
		case KEY_UP:
			break;
		}
	}

	// GUI
	if (event.EventType == EET_GUI_EVENT)
	{
		s32 id = event.GUIEvent.Caller->getID();

		switch(event.GUIEvent.EventType)
		{
		case EGET_MENU_ITEM_SELECTED:
			{
				// a menu item was clicked

				IGUIContextMenu* menu = (IGUIContextMenu*)event.GUIEvent.Caller;
				s32 id = menu->getItemCommandId(menu->getSelectedItem());

				switch(id)
				{
				case GUI_ID_NEW_SCENE: // File -> New
					editor->stop();
					editor->start();
					break;
				case GUI_ID_OPEN_SCENE: // File -> Open scene
					opening = OPENING_SCENE;
					env->addFileOpenDialog(L"Please select a scene file to open");
					break;
				case GUI_ID_SAVE_SCENE: // File -> Save scene
					editor->askForFileName();
					break;
				case GUI_ID_TETRAHEDRALIZE_AND_SIMULATE_SCENE: // File -> Tetrahedralize scene
					askForParameters();
					break;
				case GUI_ID_OPEN_MODEL: // File -> Open Model
					opening = OPENING_MODEL;
					env->addFileOpenDialog(L"Please select a model file to open");
					break;
				case GUI_ID_SWITCH_TO_PLAYER: // File -> Switch to player
					editor->switchToPlayer();
					break;
				case GUI_ID_QUIT: // File -> Quit
					device->closeDevice();
					break;
				case GUI_ID_DEBUG_OFF: // View -> Debug Information
					menu->setItemChecked(menu->getSelectedItem()+1, false);
					menu->setItemChecked(menu->getSelectedItem()+2, false);
					menu->setItemChecked(menu->getSelectedItem()+3, false);
					menu->setItemChecked(menu->getSelectedItem()+4, false);
					menu->setItemChecked(menu->getSelectedItem()+5, false);
					menu->setItemChecked(menu->getSelectedItem()+6, false);
					editor->setDebugDataVisible(scene::EDS_OFF);
					break;
				case GUI_ID_DEBUG_BOUNDING_BOX: // View -> Debug Information
					menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem()));
					editor->setDebugDataVisible((scene::E_DEBUG_SCENE_TYPE)(editor->isDebugDataVisible()^scene::EDS_BBOX));
					break;
				case GUI_ID_DEBUG_NORMALS: // View -> Debug Information
					menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem()));
					editor->setDebugDataVisible((scene::E_DEBUG_SCENE_TYPE)(editor->isDebugDataVisible()^scene::EDS_NORMALS));
					break;
				case GUI_ID_DEBUG_WIRE_OVERLAY: // View -> Debug Information
					menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem()));
					editor->setDebugDataVisible((scene::E_DEBUG_SCENE_TYPE)(editor->isDebugDataVisible()^scene::EDS_MESH_WIRE_OVERLAY));
					break;
				case GUI_ID_DEBUG_HALF_TRANSPARENT: // View -> Debug Information
					menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem()));
					editor->setDebugDataVisible((scene::E_DEBUG_SCENE_TYPE)(editor->isDebugDataVisible()^scene::EDS_HALF_TRANSPARENCY));
					break;
				case GUI_ID_DEBUG_BUFFERS_BOUNDING_BOXES: // View -> Debug Information
					menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem()));
					editor->setDebugDataVisible((scene::E_DEBUG_SCENE_TYPE)(editor->isDebugDataVisible()^scene::EDS_BBOX_BUFFERS));
					break;
				case GUI_ID_DEBUG_ALL: // View -> Debug Information
					menu->setItemChecked(menu->getSelectedItem()-1, true);
					menu->setItemChecked(menu->getSelectedItem()-2, true);
					menu->setItemChecked(menu->getSelectedItem()-3, true);
					menu->setItemChecked(menu->getSelectedItem()-4, true);
					menu->setItemChecked(menu->getSelectedItem()-5, true);
					menu->setItemChecked(menu->getSelectedItem()-6, true);
					editor->setDebugDataVisible(scene::EDS_FULL);
					break;
				case GUI_ID_ABOUT: // Help->About
					showHelp();
					break;

				case GUI_ID_CAMERA_MAYA:
					setActiveCamera(camera[0]);
					if (root->getElementFromId(GUI_ID_STATIC_TEXT_CAMERA_FPS, true))
						root->getElementFromId(GUI_ID_STATIC_TEXT_CAMERA_FPS, true)->remove();
					break;
				case GUI_ID_CAMERA_FIRST_PERSON:
					setActiveCamera(camera[1]);
					env->addStaticText(L"Press Escape to go back to maya-style camera mode.", core::rect<s32>(20,60,220,75), true, true, 0, GUI_ID_STATIC_TEXT_CAMERA_FPS);
					break;

				}
			break;
			}

		case EGET_FILE_SELECTED:
			{
				// load the model file, selected in the file open dialog
				IGUIFileOpenDialog* dialog =
					(IGUIFileOpenDialog*)event.GUIEvent.Caller;
				if (opening == OPENING_MODEL)
					editor->add3DModel(core::stringc(dialog->getFileName()).c_str());
				else if (opening == OPENING_SCENE)
					editor->load(core::stringc(dialog->getFileName()).c_str());
			}
			break;

		case EGET_SCROLL_BAR_CHANGED:
			break;

		case EGET_COMBO_BOX_CHANGED:
			break;

		case EGET_BUTTON_CLICKED:
			switch(id)
			{
			case GUI_ID_TOOL_BOX_SET_BUTTON:
				editor->setPositionRotationScaleOfSelectedNode();
				break;
			case GUI_ID_TOOL_BOX_DELETE_BUTTON:
				showConfirmDeleteNode();
				break;
			case GUI_ID_FORCE_FIELD_TOOL_BOX_SET_BUTTON:
				editor->setForceField();
				break;
			case GUI_ID_ASK_FILENAME_OK_BUTTON:
				s = root->getElementFromId(GUI_ID_ASK_FILENAME_NAME, true)->getText();
				if (s.size() == 0)
					s = "untitled.xml";
				editor->save(s.c_str());
				if (root->getElementFromId(GUI_ID_ASK_FILENAME_WINDOW, true))
					root->getElementFromId(GUI_ID_ASK_FILENAME_WINDOW, true)->remove();
				break;
			case GUI_ID_CONFIRM_DELETE_BUTTON:
				editor->remove3DModel();
				if (root->getElementFromId(GUI_ID_CONFIRM_DELETE_WINDOW, true))
					root->getElementFromId(GUI_ID_CONFIRM_DELETE_WINDOW, true)->remove();
				break;
			case GUI_ID_ASK_FILENAME_CANCEL_BUTTON:
				if (root->getElementFromId(GUI_ID_ASK_FILENAME_WINDOW, true))
					root->getElementFromId(GUI_ID_ASK_FILENAME_WINDOW, true)->remove();
				break;
			case GUI_ID_CANCEL_DELETE_BUTTON:
				if (root->getElementFromId(GUI_ID_CONFIRM_DELETE_WINDOW, true))
					root->getElementFromId(GUI_ID_CONFIRM_DELETE_WINDOW, true)->remove();
				break;
			case GUI_ID_ASK_PARAMETERS_GO_BUTTON:
				editor->quickTetAndSimulate();
				break;
			case GUI_ID_ASK_PARAMETERS_CANCEL_BUTTON:
				if (root->getElementFromId(GUI_ID_ASK_PARAMETERS_WINDOW, true))
					root->getElementFromId(GUI_ID_ASK_PARAMETERS_WINDOW, true)->remove();
				break;
			case GUI_ID_ASK_SWITCH_YES_BUTTON:
				if (root->getElementFromId(GUI_ID_ASK_SWITCH_WINDOW, true))
					root->getElementFromId(GUI_ID_ASK_SWITCH_WINDOW, true)->remove();
				editor->switchToPlayer(editor->getLastSimulatedSceneOutDir());;
				break;
			case GUI_ID_ASK_SWITCH_NO_BUTTON:
				if (root->getElementFromId(GUI_ID_ASK_SWITCH_WINDOW, true))
					root->getElementFromId(GUI_ID_ASK_SWITCH_WINDOW, true)->remove();
				break;
			case GUI_ID_OPEN_DIALOG_BUTTON:
				opening = OPENING_MODEL;
				env->addFileOpenDialog(L"Please select a model file to open");
				break;
			case GUI_ID_FORCE_FIELD_BUTTON:
				editor->createForceFieldToolBox();
				break;
			case GUI_ID_HELP_BUTTON:
				showHelp();
				break;
			case GUI_ID_TOOL_BOX_INCREASE_POSITION_X:
				s = root->getElementFromId(GUI_ID_TOOL_BOX_X_POSITION, true)->getText();
				root->getElementFromId(GUI_ID_TOOL_BOX_X_POSITION, true)->setText(stringw( 1.0f + (f32)atof(s.c_str()) ).c_str());
				editor->setPositionRotationScaleOfSelectedNode();
				break;
			case GUI_ID_TOOL_BOX_DECREASE_POSITION_X:
				s = root->getElementFromId(GUI_ID_TOOL_BOX_X_POSITION, true)->getText();
				root->getElementFromId(GUI_ID_TOOL_BOX_X_POSITION, true)->setText(stringw( -1.0f + (f32)atof(s.c_str()) ).c_str());
				editor->setPositionRotationScaleOfSelectedNode();
				break;
			case GUI_ID_TOOL_BOX_INCREASE_POSITION_Y:
				s = root->getElementFromId(GUI_ID_TOOL_BOX_Y_POSITION, true)->getText();
				root->getElementFromId(GUI_ID_TOOL_BOX_Y_POSITION, true)->setText(stringw( 1.0f + (f32)atof(s.c_str()) ).c_str());
				editor->setPositionRotationScaleOfSelectedNode();
				break;
			case GUI_ID_TOOL_BOX_DECREASE_POSITION_Y:
				s = root->getElementFromId(GUI_ID_TOOL_BOX_Y_POSITION, true)->getText();
				root->getElementFromId(GUI_ID_TOOL_BOX_Y_POSITION, true)->setText(stringw( -1.0f + (f32)atof(s.c_str()) ).c_str());
				editor->setPositionRotationScaleOfSelectedNode();
				break;
			case GUI_ID_TOOL_BOX_INCREASE_POSITION_Z:
				s = root->getElementFromId(GUI_ID_TOOL_BOX_Z_POSITION, true)->getText();
				root->getElementFromId(GUI_ID_TOOL_BOX_Z_POSITION, true)->setText(stringw( 1.0f + (f32)atof(s.c_str()) ).c_str());
				editor->setPositionRotationScaleOfSelectedNode();
				break;
			case GUI_ID_TOOL_BOX_DECREASE_POSITION_Z:
				s = root->getElementFromId(GUI_ID_TOOL_BOX_Z_POSITION, true)->getText();
				root->getElementFromId(GUI_ID_TOOL_BOX_Z_POSITION, true)->setText(stringw( -1.0f + (f32)atof(s.c_str()) ).c_str());
				editor->setPositionRotationScaleOfSelectedNode();
				break;

			case GUI_ID_TOOL_BOX_INCREASE_ROTATION_X:
				s = root->getElementFromId(GUI_ID_TOOL_BOX_X_ROTATION, true)->getText();
				root->getElementFromId(GUI_ID_TOOL_BOX_X_ROTATION, true)->setText(stringw( 1.0f + (f32)atof(s.c_str()) ).c_str());
				editor->setPositionRotationScaleOfSelectedNode();
				break;
			case GUI_ID_TOOL_BOX_DECREASE_ROTATION_X:
				s = root->getElementFromId(GUI_ID_TOOL_BOX_X_ROTATION, true)->getText();
				root->getElementFromId(GUI_ID_TOOL_BOX_X_ROTATION, true)->setText(stringw( -1.0f + (f32)atof(s.c_str()) ).c_str());
				editor->setPositionRotationScaleOfSelectedNode();
				break;
			case GUI_ID_TOOL_BOX_INCREASE_ROTATION_Y:
				s = root->getElementFromId(GUI_ID_TOOL_BOX_Y_ROTATION, true)->getText();
				root->getElementFromId(GUI_ID_TOOL_BOX_Y_ROTATION, true)->setText(stringw( 1.0f + (f32)atof(s.c_str()) ).c_str());
				editor->setPositionRotationScaleOfSelectedNode();
				break;
			case GUI_ID_TOOL_BOX_DECREASE_ROTATION_Y:
				s = root->getElementFromId(GUI_ID_TOOL_BOX_Y_ROTATION, true)->getText();
				root->getElementFromId(GUI_ID_TOOL_BOX_Y_ROTATION, true)->setText(stringw( -1.0f + (f32)atof(s.c_str()) ).c_str());
				editor->setPositionRotationScaleOfSelectedNode();
				break;
			case GUI_ID_TOOL_BOX_INCREASE_ROTATION_Z:
				s = root->getElementFromId(GUI_ID_TOOL_BOX_Z_ROTATION, true)->getText();
				root->getElementFromId(GUI_ID_TOOL_BOX_Z_ROTATION, true)->setText(stringw( 1.0f + (f32)atof(s.c_str()) ).c_str());
				editor->setPositionRotationScaleOfSelectedNode();
				break;
			case GUI_ID_TOOL_BOX_DECREASE_ROTATION_Z:
				s = root->getElementFromId(GUI_ID_TOOL_BOX_Z_ROTATION, true)->getText();
				root->getElementFromId(GUI_ID_TOOL_BOX_Z_ROTATION, true)->setText(stringw( -1.0f + (f32)atof(s.c_str()) ).c_str());
				editor->setPositionRotationScaleOfSelectedNode();
				break;

			case GUI_ID_TOOL_BOX_INCREASE_SCALE_X:
				s = root->getElementFromId(GUI_ID_TOOL_BOX_X_SCALE, true)->getText();
				root->getElementFromId(GUI_ID_TOOL_BOX_X_SCALE, true)->setText(stringw( 0.01f + (f32)atof(s.c_str()) ).c_str());
				editor->setPositionRotationScaleOfSelectedNode();
				break;
			case GUI_ID_TOOL_BOX_DECREASE_SCALE_X:
				s = root->getElementFromId(GUI_ID_TOOL_BOX_X_SCALE, true)->getText();
				root->getElementFromId(GUI_ID_TOOL_BOX_X_SCALE, true)->setText(stringw( -0.01f + (f32)atof(s.c_str()) ).c_str());
				editor->setPositionRotationScaleOfSelectedNode();
				break;
			case GUI_ID_TOOL_BOX_INCREASE_SCALE_Y:
				s = root->getElementFromId(GUI_ID_TOOL_BOX_Y_SCALE, true)->getText();
				root->getElementFromId(GUI_ID_TOOL_BOX_Y_SCALE, true)->setText(stringw( 0.01f + (f32)atof(s.c_str()) ).c_str());
				editor->setPositionRotationScaleOfSelectedNode();
				break;
			case GUI_ID_TOOL_BOX_DECREASE_SCALE_Y:
				s = root->getElementFromId(GUI_ID_TOOL_BOX_Y_SCALE, true)->getText();
				root->getElementFromId(GUI_ID_TOOL_BOX_Y_SCALE, true)->setText(stringw( -0.01f + (f32)atof(s.c_str()) ).c_str());
				editor->setPositionRotationScaleOfSelectedNode();
				break;
			case GUI_ID_TOOL_BOX_INCREASE_SCALE_Z:
				s = root->getElementFromId(GUI_ID_TOOL_BOX_Z_SCALE, true)->getText();
				root->getElementFromId(GUI_ID_TOOL_BOX_Z_SCALE, true)->setText(stringw( 0.01f + (f32)atof(s.c_str()) ).c_str());
				editor->setPositionRotationScaleOfSelectedNode();
				break;
			case GUI_ID_TOOL_BOX_DECREASE_SCALE_Z:
				s = root->getElementFromId(GUI_ID_TOOL_BOX_Z_SCALE, true)->getText();
				root->getElementFromId(GUI_ID_TOOL_BOX_Z_SCALE, true)->setText(stringw( -0.01f + (f32)atof(s.c_str()) ).c_str());
				editor->setPositionRotationScaleOfSelectedNode();
				break;

			}

			break;
		default:
			break;
		}
	}

	return false;
}
Exemple #9
0
// -----------------------------------------------------------------------------
// Debug menu handling
bool onEvent(const SEvent &event)
{
    // Only activated in artist debug mode
    if(!UserConfigParams::m_artist_debug_mode)
        return true;    // keep handling the events

    if(event.EventType == EET_MOUSE_INPUT_EVENT)
    {
        // Create the menu (only one menu at a time)
        if(event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN && !g_debug_menu_visible)
        {
            // root menu
            gui::IGUIEnvironment* guienv = irr_driver->getGUI();
            IGUIContextMenu* mnu = guienv->addContextMenu(
                core::rect<s32>(event.MouseInput.X, event.MouseInput.Y, event.MouseInput.Y+100, event.MouseInput.Y+100),NULL);
            int graphicsMenuIndex = mnu->addItem(L"Graphics >",-1,true,true);
            
            // graphics menu
            IGUIContextMenu* sub = mnu->getSubMenu(graphicsMenuIndex);

            sub->addItem(L"Reload shaders", DEBUG_GRAPHICS_RELOAD_SHADERS );
            sub->addItem(L"Reset debug views", DEBUG_GRAPHICS_RESET );
            sub->addItem(L"Wireframe", DEBUG_GRAPHICS_WIREFRAME );
            sub->addItem(L"Mipmap viz", DEBUG_GRAPHICS_MIPMAP_VIZ );
            sub->addItem(L"Normals viz", DEBUG_GRAPHICS_NORMALS_VIZ );
            sub->addItem(L"SSAO viz", DEBUG_GRAPHICS_SSAO_VIZ );
            sub->addItem(L"RSM viz", DEBUG_GRAPHICS_RSM_VIZ);
            sub->addItem(L"RH viz", DEBUG_GRAPHICS_RH_VIZ);
            sub->addItem(L"GI viz", DEBUG_GRAPHICS_GI_VIZ);
            sub->addItem(L"Shadow viz", DEBUG_GRAPHICS_SHADOW_VIZ );
            sub->addItem(L"Light viz", DEBUG_GRAPHICS_LIGHT_VIZ );
            sub->addItem(L"Distort viz", DEBUG_GRAPHICS_DISTORT_VIZ );
            sub->addItem(L"Physics debug", DEBUG_GRAPHICS_BULLET_1);
            sub->addItem(L"Physics debug (no kart)", DEBUG_GRAPHICS_BULLET_2);

            mnu->addItem(L"Items >",-1,true,true);
            sub = mnu->getSubMenu(1);
            sub->addItem(L"Basketball", DEBUG_POWERUP_RUBBERBALL );
            sub->addItem(L"Bowling", DEBUG_POWERUP_BOWLING );
            sub->addItem(L"Bubblegum", DEBUG_POWERUP_BUBBLEGUM );
            sub->addItem(L"Cake", DEBUG_POWERUP_CAKE );
            sub->addItem(L"Parachute", DEBUG_POWERUP_PARACHUTE );
            sub->addItem(L"Plunger", DEBUG_POWERUP_PLUNGER );
            sub->addItem(L"Swatter", DEBUG_POWERUP_SWATTER );
            sub->addItem(L"Switch", DEBUG_POWERUP_SWITCH );
            sub->addItem(L"Zipper", DEBUG_POWERUP_ZIPPER );
            sub->addItem(L"Nitro", DEBUG_POWERUP_NITRO );
            
            mnu->addItem(L"Attachments >",-1,true, true);
            sub = mnu->getSubMenu(2);
            sub->addItem(L"Bomb", DEBUG_ATTACHMENT_BOMB);
            sub->addItem(L"Anvil", DEBUG_ATTACHMENT_ANVIL);
            sub->addItem(L"Parachute", DEBUG_ATTACHMENT_PARACHUTE);

            mnu->addItem(L"Adjust values", DEBUG_VISUAL_VALUES);

            mnu->addItem(L"Profiler",DEBUG_PROFILER);
            if (UserConfigParams::m_profiler_enabled)
                mnu->addItem(L"Toggle capture profiler report", DEBUG_PROFILER_GENERATE_REPORT);
            mnu->addItem(L"Do not limit FPS", DEBUG_THROTTLE_FPS);
            mnu->addItem(L"FPS",DEBUG_FPS);
            mnu->addItem(L"Save replay", DEBUG_SAVE_REPLAY);
            mnu->addItem(L"Save history", DEBUG_SAVE_HISTORY);
            mnu->addItem(L"Toggle GUI", DEBUG_TOGGLE_GUI);
            mnu->addItem(L"Hide karts", DEBUG_HIDE_KARTS);


            g_debug_menu_visible = true;
            irr_driver->showPointer();
        }

        // Let Irrlicht handle the event while the menu is visible - otherwise in a race the GUI events won't be generated
        if(g_debug_menu_visible)
            return false;
    }

    if (event.EventType == EET_GUI_EVENT)
    {
        if (event.GUIEvent.Caller != NULL && event.GUIEvent.Caller->getType() == EGUIET_CONTEXT_MENU )
        {
            IGUIContextMenu *menu = (IGUIContextMenu*)event.GUIEvent.Caller;
            s32 cmdID = menu->getItemCommandId(menu->getSelectedItem());

            if(event.GUIEvent.EventType == EGET_ELEMENT_CLOSED)
            {
                g_debug_menu_visible = false;
            }

            if (event.GUIEvent.EventType == gui::EGET_MENU_ITEM_SELECTED)
            {
                if(cmdID == DEBUG_GRAPHICS_RELOAD_SHADERS)
                {
                    Log::info("Debug", "Reloading shaders...");
                    irr_driver->updateShaders();
                }
                else if (cmdID == DEBUG_GRAPHICS_RESET)
                {
                    World* world = World::getWorld();
                    if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);

                    irr_driver->resetDebugModes();
                }
                else if (cmdID == DEBUG_GRAPHICS_WIREFRAME)
                {
                    World* world = World::getWorld();
                    if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);

                    irr_driver->resetDebugModes();
                    irr_driver->toggleWireframe();
                }
                else if (cmdID == DEBUG_GRAPHICS_MIPMAP_VIZ)
                {
                    World* world = World::getWorld();
                    if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);

                    irr_driver->resetDebugModes();
                    irr_driver->toggleMipVisualization();
                }
                else if (cmdID == DEBUG_GRAPHICS_NORMALS_VIZ)
                {
                    World* world = World::getWorld();
                    if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);

                    irr_driver->resetDebugModes();
                    irr_driver->toggleNormals();
                }
                else if (cmdID == DEBUG_GRAPHICS_SSAO_VIZ)
                {
                    World* world = World::getWorld();
                    if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);

                    irr_driver->resetDebugModes();
                    irr_driver->toggleSSAOViz();
                }
                else if (cmdID == DEBUG_GRAPHICS_RSM_VIZ)
                {
                    World* world = World::getWorld();
                    if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);

                    irr_driver->resetDebugModes();
                    irr_driver->toggleRSM();
                }
                else if (cmdID == DEBUG_GRAPHICS_RH_VIZ)
                {
                    World* world = World::getWorld();
                    if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);

                    irr_driver->resetDebugModes();
                    irr_driver->toggleRH();
                }
                else if (cmdID == DEBUG_GRAPHICS_GI_VIZ)
                {
                    World* world = World::getWorld();
                    if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);

                    irr_driver->resetDebugModes();
                    irr_driver->toggleGI();
                }
                else if (cmdID == DEBUG_GRAPHICS_SHADOW_VIZ)
                {
                    World* world = World::getWorld();
                    if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);

                    irr_driver->resetDebugModes();
                    irr_driver->toggleShadowViz();
                }
                else if (cmdID == DEBUG_GRAPHICS_LIGHT_VIZ)
                {
                    World* world = World::getWorld();
                    if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);

                    irr_driver->resetDebugModes();
                    irr_driver->toggleLightViz();
                }
                else if (cmdID == DEBUG_GRAPHICS_DISTORT_VIZ)
                {
                    World* world = World::getWorld();
                    if (world != NULL) world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NONE);

                    irr_driver->resetDebugModes();
                    irr_driver->toggleDistortViz();
                }
                else if (cmdID == DEBUG_GRAPHICS_BULLET_1)
                {
                    irr_driver->resetDebugModes();

                    World* world = World::getWorld();
                    if (world == NULL) return false;
                    world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_KARTS_PHYSICS);
                }
                else if (cmdID == DEBUG_GRAPHICS_BULLET_2)
                {
                    irr_driver->resetDebugModes();

                    World* world = World::getWorld();
                    if (world == NULL) return false;
                    world->getPhysics()->setDebugMode(IrrDebugDrawer::DM_NO_KARTS_GRAPHICS);
                }
                else if (cmdID == DEBUG_PROFILER)
                {
                    UserConfigParams::m_profiler_enabled =
                                            !UserConfigParams::m_profiler_enabled;
                }
                else if (cmdID == DEBUG_PROFILER_GENERATE_REPORT)
                {
                    profiler.setCaptureReport(!profiler.getCaptureReport());
                }
                else if (cmdID == DEBUG_THROTTLE_FPS)
                {
                    main_loop->setThrottleFPS(false);
                }
                else if (cmdID == DEBUG_FPS)
                {
                    UserConfigParams::m_display_fps =
                                        !UserConfigParams::m_display_fps;
                }
                else if (cmdID == DEBUG_SAVE_REPLAY)
                {
                    ReplayRecorder::get()->Save();
                }
                else if (cmdID == DEBUG_SAVE_HISTORY)
                {
                    history->Save();
                }
                else if (cmdID == DEBUG_POWERUP_BOWLING)
                {
                    addPowerup(PowerupManager::POWERUP_BOWLING);
                }
                else if (cmdID == DEBUG_POWERUP_BUBBLEGUM)
                {
                    addPowerup(PowerupManager::POWERUP_BUBBLEGUM);
                }
                else if (cmdID == DEBUG_POWERUP_CAKE)
                {
                    addPowerup(PowerupManager::POWERUP_CAKE);
                }
                else if (cmdID == DEBUG_POWERUP_PARACHUTE)
                {
                    addPowerup(PowerupManager::POWERUP_PARACHUTE);
                }
                else if (cmdID == DEBUG_POWERUP_PLUNGER)
                {
                    addPowerup(PowerupManager::POWERUP_PLUNGER);
                }
                else if (cmdID == DEBUG_POWERUP_RUBBERBALL)
                {
                    addPowerup(PowerupManager::POWERUP_RUBBERBALL);
                }
                else if (cmdID == DEBUG_POWERUP_SWATTER)
                {
                    addPowerup(PowerupManager::POWERUP_SWATTER);
                }
                else if (cmdID == DEBUG_POWERUP_SWITCH)
                {
                    addPowerup(PowerupManager::POWERUP_SWITCH);
                }
                else if (cmdID == DEBUG_POWERUP_ZIPPER)
                {
                    addPowerup(PowerupManager::POWERUP_ZIPPER);
                }
                else if (cmdID == DEBUG_POWERUP_NITRO)
                {
                    World* world = World::getWorld();
                    if (world == NULL) return false;
                    for(unsigned int i = 0; i < race_manager->getNumLocalPlayers(); i++)
                    {
                        AbstractKart* kart = world->getLocalPlayerKart(i);
                        kart->setEnergy(100.0f);
                    }
                }
                else if (cmdID == DEBUG_ATTACHMENT_ANVIL)
                {
                    addAttachment(Attachment::ATTACH_ANVIL);
                }
                else if (cmdID == DEBUG_ATTACHMENT_BOMB)
                {
                    addAttachment(Attachment::ATTACH_BOMB);
                }
                else if (cmdID == DEBUG_ATTACHMENT_PARACHUTE)
                {
                    addAttachment(Attachment::ATTACH_PARACHUTE);
                }
                else if (cmdID == DEBUG_TOGGLE_GUI)
                {
                    World* world = World::getWorld();
                    if (world == NULL) return false;
                    RaceGUIBase* gui = world->getRaceGUI();
                    if (gui != NULL) gui->m_enabled = !gui->m_enabled;
                }
                else if (cmdID == DEBUG_HIDE_KARTS)
                {
                    World* world = World::getWorld();
                    if (world == NULL) return false;
                    const int count = World::getWorld()->getNumKarts();
                    for (int n = 0; n<count; n++)
                    {
                        AbstractKart* kart = world->getKart(n);
                        if (kart->getController()->isPlayerController())
                            kart->getNode()->setVisible(false);
                    }
                }
                else if (cmdID == DEBUG_VISUAL_VALUES)
                {
#if !defined(__APPLE__)
                    DebugSliderDialog *dsd = new DebugSliderDialog();
                    dsd->setSliderHook( "red_slider", 0, 255, [](){ return irr_driver->getAmbientLight().r * 255.f; },
                        [](int v){
                            video::SColorf ambient = irr_driver->getAmbientLight();
                            ambient.setColorComponentValue(0, v / 255.f);
                            irr_driver->setAmbientLight(ambient); }
                    );
                    dsd->setSliderHook("green_slider", 0, 255, [](){ return irr_driver->getAmbientLight().g * 255.f; },
                        [](int v){
                        video::SColorf ambient = irr_driver->getAmbientLight();
                        ambient.setColorComponentValue(1, v / 255.f);
                        irr_driver->setAmbientLight(ambient); }
                    );
                    dsd->setSliderHook("blue_slider", 0, 255, [](){ return irr_driver->getAmbientLight().b * 255.f; },
                        [](int v){
                        video::SColorf ambient = irr_driver->getAmbientLight();
                        ambient.setColorComponentValue(2, v / 255.f);
                        irr_driver->setAmbientLight(ambient); }
                    );
                    dsd->setSliderHook("ssao_radius", 0, 100, [](){ return irr_driver->getSSAORadius() * 10.f; },
                        [](int v){irr_driver->setSSAORadius(v / 10.f); }
                    );
                    dsd->setSliderHook("ssao_k", 0, 100, [](){ return irr_driver->getSSAOK() * 10.f; },
                        [](int v){irr_driver->setSSAOK(v / 10.f); }
                    );
                    dsd->setSliderHook("ssao_sigma", 0, 100, [](){ return irr_driver->getSSAOSigma() * 10.f; },
                        [](int v){irr_driver->setSSAOSigma(v / 10.f); }
                    );
#endif
                }
            }

            return false;   // event has been handled
        }
    }
    return true;    // continue event handling
}
Exemple #10
0
bool Editor::OnEvent(const SEvent& event)
{
	if (event.EventType == irr::EET_MOUSE_INPUT_EVENT) {
		if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) {
			state->mousedown = false;
			click_handled = true;
		} else if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) {
			state->mousedown = true;
			click_handled = false;
		} else if (event.MouseInput.Event == EMIE_MOUSE_MOVED) {
			state->mouse_position.X = event.MouseInput.X;
			state->mouse_position.Y = event.MouseInput.Y;
		} else if (event.MouseInput.Event == EMIE_MMOUSE_LEFT_UP) {
			viewport_drag = VIEW_NONE;
			middle_click_handled = true;
		} else if (event.MouseInput.Event == EMIE_MMOUSE_PRESSED_DOWN) {
			middle_click_handled = false;
		}
	}

	if (state->Mode()) {
		if (state->Mode()->OnEvent(event)) {
			return true;
		}
	}

	if (state->menu) {
		if (state->menu->OnEvent(event)) {
			return true;
		}
	}

	if (event.EventType == EET_KEY_INPUT_EVENT &&
			event.KeyInput.Key < NUMBER_OF_KEYS) {
		if (event.KeyInput.PressedDown) {
			state->keys[event.KeyInput.Key] = EKS_DOWN;
		} else {
			state->keys[event.KeyInput.Key] = EKS_UP;
		}

		if (event.KeyInput.PressedDown &&
				event.KeyInput.Key == KEY_KEY_W &&
				state->keys[164] == EKS_DOWN) {
			if (currentWindow == -1) {
				IVideoDriver *driver = state->device->getVideoDriver();
				int ResX = driver->getScreenSize().Width;
				if (!state->settings->getBool("hide_sidebar"))
					ResX -= 256;
				int ResY = driver->getScreenSize().Height;

				if (state->mouse_position.X > ResX / 2)
					if (state->mouse_position.Y > ResY / 2)
						currentWindow = 3;
					else
						currentWindow = 1;
				else
					if (state->mouse_position.Y > ResY / 2)
						currentWindow = 2;
					else
						currentWindow = 0;
			} else
				currentWindow = -1;
		}

		if (state->device->getGUIEnvironment()->getFocus() &&
				state->device->getGUIEnvironment()->getFocus()->getType() == EGUIET_EDIT_BOX)
			return false;

		switch (event.KeyInput.Key) {
		case KEY_KEY_S:
			pivot->setRotation(vector3df(pivot->getRotation().X - 1,
					pivot->getRotation().Y, pivot->getRotation().Z));
			break;
		case KEY_KEY_W:
			pivot->setRotation(vector3df(pivot->getRotation().X + 1,
					pivot->getRotation().Y, pivot->getRotation().Z));
			break;
		case KEY_KEY_A:
			pivot->setRotation(vector3df(pivot->getRotation().X,
					pivot->getRotation().Y + 1, pivot->getRotation().Z));
			break;
		case KEY_KEY_D:
			pivot->setRotation(vector3df(pivot->getRotation().X,
					pivot->getRotation().Y - 1, pivot->getRotation().Z));
			break;
		case KEY_KEY_B:
			if (!event.KeyInput.PressedDown)
				state->SelectMode(0);
			break;
		case KEY_KEY_N:
			if (!event.KeyInput.PressedDown)
				state->SelectMode(1);
			break;
		case KEY_KEY_T:
			if (!event.KeyInput.PressedDown)
				state->SelectMode(2);
			break;
		}
	}
	if (event.EventType == EET_GUI_EVENT) {
		if (event.GUIEvent.EventType == EGET_MENU_ITEM_SELECTED) {
			IGUIContextMenu* menu = (IGUIContextMenu*)event.GUIEvent.Caller;
			switch (menu->getItemCommandId(menu->getSelectedItem())) {
			case GUI_VIEW_SP_ALL:
				currentWindow = -1;
				break;
			case GUI_VIEW_SP_PER:
				currentWindow = 0;
				break;
			case GUI_VIEW_SP_TOP:
				currentWindow = 1;
				break;
			case GUI_VIEW_SP_FRT:
				currentWindow = 2;
				break;
			case GUI_VIEW_SP_RHT:
				currentWindow = 3;
				break;
			}
		}
	}
	return false;
}
Exemple #11
0
bool TextureDialog::OnEvent(const SEvent &event)
{
    if (event.EventType != EET_GUI_EVENT)
        return false;

    if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED) {
        switch (event.GUIEvent.Caller->getID()) {
        case ETD_GUI_ID_APPLY: {
            if (lb->getSelected() == 0) {
                node->setTexture(face, NULL);
                node->remesh();
                return true;
            }

            int count = 0;
            Media *media = &state->project->media;
            std::map<std::string, Media::Image*>& images = media->getList();
            for (std::map<std::string, Media::Image*>::const_iterator it = images.begin();
                    it != images.end();
                    ++it) {
                if (count == lb->getSelected()-1) {
                    node->setTexture(face, it->second);
                    node->remesh();
                    break;
                }
                count++;
            }


            close();
            return true;
        }
        case ETD_GUI_ID_IMPORT: {
            ImageDialog::show(state, node, face);
            return false;
        }
        case ETD_GUI_ID_ACTIONS:
            context->setVisible(true);
            state->device->getGUIEnvironment()->setFocus(context);
            return false;
        }
    } else if (event.GUIEvent.EventType == EGET_MENU_ITEM_SELECTED) {
        IGUIContextMenu *menu = (IGUIContextMenu *)event.GUIEvent.Caller;
        switch (menu->getItemCommandId(menu->getSelectedItem())) {
        case ETD_GUI_ID_EXPORT: {
            if (lb->getSelected() == 0)
                return true;

            int count = 0;
            Media *media = &state->project->media;
            Media::Image *image = NULL;
            std::map<std::string, Media::Image*>& images = media->getList();
            for (std::map<std::string, Media::Image*>::const_iterator it = images.begin();
                    it != images.end();
                    ++it) {
                if (count == lb->getSelected() - 1) {
                    image = it->second;
                    break;
                }
                count++;
            }

            if (!image)
                return true;

            std::string path = getSaveLoadDirectory(state->settings->get("save_directory"),
                                                    state->isInstalled);
            path += image->name;

            const char *filters[] = {"*.png"};
            const char *cfilename = tinyfd_saveFileDialog("Save Image", path.c_str(),
                                    1, filters);
            if (!cfilename)
                return true;

            std::string filename = cfilename;

            if (filename == "")
                return true;

            state->device->getVideoDriver()->writeImageToFile(image->get(),
                    filename.c_str());

            return true;
        }
        } // end of switch
    } else if (event.GUIEvent.EventType == EGET_LISTBOX_CHANGED && event.GUIEvent.Caller == lb) {
        if (lb->getSelected() == 0) {
            the_image = NULL;
            return true;
        }

        int count = 0;
        Media *media = &state->project->media;
        std::map<std::string, Media::Image*>& images = media->getList();
        for (std::map<std::string, Media::Image*>::const_iterator it = images.begin();
                it != images.end();
                ++it) {
            if (count == lb->getSelected()-1) {
                the_image = state->device->getVideoDriver()->addTexture("tmpicon.png", it->second->get());
                break;
            }
            count++;
        }
        return true;
    } else if (event.GUIEvent.EventType == EGET_ELEMENT_CLOSED && event.GUIEvent.Caller == win) {
        if (canClose())
            close();
        return true;
    }
    return false;
}
bool Editor::OnEvent(const SEvent& event)
{
	if (event.EventType == irr::EET_MOUSE_INPUT_EVENT &&
			event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) {
		state->mousedown = false;
	} else if (event.EventType == irr::EET_MOUSE_INPUT_EVENT &&
			event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) {
		state->mousedown = true;
	} else if (event.EventType == irr::EET_MOUSE_INPUT_EVENT &&
			event.MouseInput.Event == EMIE_MOUSE_MOVED) {
		state->mouse_position.X = event.MouseInput.X;
		state->mouse_position.Y = event.MouseInput.Y;
	}

	if (state->Mode()){
		if (state->Mode()->OnEvent(event)){
			return true;
		}
	}

	if (state->menu){
		if (state->menu->OnEvent(event)){
			return true;
		}
	}

	if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.Key < NUMBER_OF_KEYS){
		if (event.KeyInput.PressedDown) {
			state->keys[event.KeyInput.Key] = EKS_DOWN;
		} else {
			state->keys[event.KeyInput.Key] = EKS_UP;
		}

		if (
			state->device->getGUIEnvironment()->getFocus() &&
			state->device->getGUIEnvironment()->getFocus()->getType() == EGUIET_EDIT_BOX
			)
			return false;

		switch (event.KeyInput.Key) {
		case KEY_KEY_S:
			pivot->setRotation(vector3df(pivot->getRotation().X - 1,
					pivot->getRotation().Y, pivot->getRotation().Z));
			break;
		case KEY_KEY_W:
			pivot->setRotation(vector3df(pivot->getRotation().X + 1,
					pivot->getRotation().Y, pivot->getRotation().Z));
			break;
		case KEY_KEY_A:
			pivot->setRotation(vector3df(pivot->getRotation().X,
					pivot->getRotation().Y + 1, pivot->getRotation().Z));
			break;
		case KEY_KEY_D:
			pivot->setRotation(vector3df(pivot->getRotation().X,
					pivot->getRotation().Y - 1, pivot->getRotation().Z));
			break;
		case KEY_KEY_B:
			if (!event.KeyInput.PressedDown)
				state->SelectMode(0);
			break;
		case KEY_KEY_N:
			if (!event.KeyInput.PressedDown)
				state->SelectMode(1);
			break;
		}
	}
	if (event.EventType == EET_GUI_EVENT) {
		if (event.GUIEvent.EventType == EGET_MENU_ITEM_SELECTED) {
			IGUIContextMenu* menu = (IGUIContextMenu*)event.GUIEvent.Caller;
			switch (menu->getItemCommandId(menu->getSelectedItem())) {
				case GUI_VIEW_SP_ALL:
					currentWindow = -1;
					break;
				case GUI_VIEW_SP_PER:
					currentWindow = 0;
					break;
				case GUI_VIEW_SP_TOP:
					currentWindow = 1;
					break;
				case GUI_VIEW_SP_FRT:
					currentWindow = 2;
					break;
				case GUI_VIEW_SP_RHT:
					currentWindow = 3;
					break;
			}
		}
	}
	return false;
}