// ---------------------------------------------------------------------------- void Editor::dataDirLocDlg() { IGUIFileOpenDialog* ofd = m_gui_env->addFileOpenDialog( L"Pls. select data directory (folder containing textures, tracks, etc.):", true, 0, -1, true); ofd->setMinSize(dimension2du(600, 512)); ofd->setRelativePosition(position2di(m_screen_size.Width / 2 - 300, 100)); } // dataDirLocDlg
//! adds a file open dialog. The returned pointer must not be dropped. IGUIFileOpenDialog* CGUIEnvironment::addFileOpenDialog(const wchar_t* title, bool modal, IGUIElement* parent, s32 id) { parent = parent ? parent : this; if (modal) { parent = new CGUIModalScreen(this, parent, -1); parent->drop(); } IGUIFileOpenDialog* d = new CGUIFileOpenDialog(FileSystem, title, this, parent, id); d->drop(); return d; }
virtual bool OnEvent(const SEvent& event) { if (event.EventType == EET_GUI_EVENT) { s32 id = event.GUIEvent.Caller->getID(); IGUIEnvironment* env = Context.device->getGUIEnvironment(); switch(event.GUIEvent.EventType) { /* If a scrollbar changed its scroll position, and it is 'our' scrollbar (the one with id GUI_ID_TRANSPARENCY_SCROLL_BAR), then we change the transparency of all gui elements. This is an easy task: There is a skin object, in which all color settings are stored. We simply go through all colors stored in the skin and change their alpha value. */ case EGET_SCROLL_BAR_CHANGED: if (id == GUI_ID_TRANSPARENCY_SCROLL_BAR) { s32 pos = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos(); setSkinTransparency(pos, env->getSkin()); } break; /* If a button was clicked, it could be one of 'our' three buttons. If it is the first, we shut down the engine. If it is the second, we create a little window with some text on it. We also add a string to the list box to log what happened. And if it is the third button, we create a file open dialog, and add also this as string to the list box. That's all for the event receiver. */ case EGET_BUTTON_CLICKED: switch(id) { case GUI_ID_QUIT_BUTTON: Context.device->closeDevice(); return true; case GUI_ID_NEW_WINDOW_BUTTON: { Context.listbox->addItem(L"Window created"); Context.counter += 30; if (Context.counter > 200) Context.counter = 0; IGUIWindow* window = env->addWindow( rect<s32>(100 + Context.counter, 100 + Context.counter, 300 + Context.counter, 200 + Context.counter), false, // modal? L"Test window"); env->addStaticText(L"Please close me", rect<s32>(35,35,140,50), true, // border? false, // wordwrap? window); } return true; case GUI_ID_FILE_OPEN_BUTTON: Context.listbox->addItem(L"File open"); // There are some options for the file open dialog // We set the title, make it a modal window, and make sure // that the working directory is restored after the dialog // is finished. env->addFileOpenDialog(L"Please choose a file.", true, 0, -1, true); return true; default: return false; } break; case EGET_FILE_SELECTED: { // show the event and the selected model filename from the file dialog IGUIFileOpenDialog* dialog = (IGUIFileOpenDialog*)event.GUIEvent.Caller; Context.listbox->addItem(L"EGET_FILE_SELECTED"); Context.listbox->addItem(dialog->getFileName()); } break; case EGET_DIRECTORY_SELECTED: { // show the event and the selected directory name from the file dialog IGUIFileOpenDialog* dialog = (IGUIFileOpenDialog*)event.GUIEvent.Caller; Context.listbox->addItem(L"EGET_DIRECTORY_SELECTED"); Context.listbox->addItem(dialog->getDirectoryNameW()); } break; default: break; } } return false; }
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; }
virtual bool OnEvent(const SEvent& event) { // Escape swaps Camera Input if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown == false) { if ( OnKeyUp(event.KeyInput.Key) ) return true; } if (event.EventType == EET_GUI_EVENT) { s32 id = event.GUIEvent.Caller->getID(); IGUIEnvironment* env = Device->getGUIEnvironment(); switch(event.GUIEvent.EventType) { case EGET_MENU_ITEM_SELECTED: // a menu item was clicked OnMenuItemSelected( (IGUIContextMenu*)event.GUIEvent.Caller ); break; case EGET_FILE_SELECTED: { // load the model file, selected in the file open dialog IGUIFileOpenDialog* dialog = (IGUIFileOpenDialog*)event.GUIEvent.Caller; loadModel(core::stringc(dialog->getFileName()).c_str()); } break; case EGET_SCROLL_BAR_CHANGED: // control skin transparency if (id == GUI_ID_SKIN_TRANSPARENCY) { const s32 pos = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos(); setSkinTransparency(pos, env->getSkin()); } // control animation speed else if (id == GUI_ID_SKIN_ANIMATION_FPS) { const s32 pos = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos(); if (scene::ESNT_ANIMATED_MESH == Model->getType()) ((scene::IAnimatedMeshSceneNode*)Model)->setAnimationSpeed((f32)pos); } break; case EGET_COMBO_BOX_CHANGED: // control anti-aliasing/filtering if (id == GUI_ID_TEXTUREFILTER) { OnTextureFilterSelected( (IGUIComboBox*)event.GUIEvent.Caller ); } break; case EGET_BUTTON_CLICKED: switch(id) { case GUI_ID_BUTTON_SET_SCALE: { // set scale gui::IGUIElement* root = env->getRootGUIElement(); core::vector3df scale; core::stringc s; s = root->getElementFromId(GUI_ID_X_SCALE, true)->getText(); scale.X = (f32)atof(s.c_str()); s = root->getElementFromId(GUI_ID_Y_SCALE, true)->getText(); scale.Y = (f32)atof(s.c_str()); s = root->getElementFromId(GUI_ID_Z_SCALE, true)->getText(); scale.Z = (f32)atof(s.c_str()); if (Model) Model->setScale(scale); updateScaleInfo(Model); } break; case GUI_ID_BUTTON_SCALE_MUL10: if (Model) Model->setScale(Model->getScale()*10.f); updateScaleInfo(Model); break; case GUI_ID_BUTTON_SCALE_DIV10: if (Model) Model->setScale(Model->getScale()*0.1f); updateScaleInfo(Model); break; case GUI_ID_BUTTON_OPEN_MODEL: env->addFileOpenDialog(L"Please select a model file to open"); break; case GUI_ID_BUTTON_SHOW_ABOUT: showAboutText(); break; case GUI_ID_BUTTON_SHOW_TOOLBOX: createToolBox(); break; case GUI_ID_BUTTON_SELECT_ARCHIVE: env->addFileOpenDialog(L"Please select your game archive/directory"); break; } break; default: break; } } return false; }