/// <summary> /// Sets up the device to run in a <see cref="Control"/> with the specified <see cref="Irrlicht.Video.DriverType"/>. /// </summary> /// <param name="c">Winforms <see cref="Control"/> that Irrlicht is to render in.</param> /// <param name="driver"><see cref="Irrlicht.Video.DriverType"/> to use when setting up the IrrlichtDevice.</param> /// <returns>True if the setup went well, False otherwise.</returns> private bool SetDevice(Control c, video.DriverType driverType) { if (quitting) { return(false); } if (device != null) { device.CloseDevice(); } CreatePanel(); device = new IrrlichtDevice(driverType, new core.Dimension2D(c.ClientRectangle.Width, c.ClientRectangle.Height), 32, false, false, false, true, c.Handle); if (device == null) { return(false); } device.ResizeAble = true; gui.IGUIEnvironment env = device.GUIEnvironment; video.IVideoDriver driver = device.VideoDriver; scene.ISceneManager smgr = device.SceneManager; driver.SetTextureCreationFlag(video.TextureCreationFlag.ALWAYS_32_BIT, true); // This sets the gui font from a bmp file. gui.IGUISkin skin = env.Skin; gui.IGUIFont font = env.GetFont(path + "fonthaettenschweiler.bmp"); if (font != null) { skin.Font = font; } // This is loaded with the default values for the native engine. smgr.AddCameraSceneNodeMaya(null, -1500, 500, 1500, -1); irrLogo = driver.GetTexture(path + "irrlichtlogoaligned.jpg"); caption = captBase + " (using " + driver.Name + " driver)"; this.Text = caption; return(true); }
public bool OnEvent(Event p_e) { if (node != null && p_e.Type == EventType.KeyInput && !p_e.KeyPressedDown) { switch (p_e.Key) { case KeyCode.KEY_ESCAPE: device.CloseDevice(); break; case KeyCode.KEY_KEY_W: case KeyCode.KEY_KEY_S: { Vector3D v = node.Position; v.Y += p_e.Key == KeyCode.KEY_KEY_W ? 2.0f : -2.0f; node.Position = v; } return(true); } } return(false); }
public void displayMainMenu() { device = new IrrlichtDevice(DriverType.SOFTWARE, new Dimension2D(512, 384), 16, false, false, false); // set event receiver device.EventReceiver = this; // set text device.WindowCaption = "Irrlicht .NET test demos - main menu"; // load font IGUIFont font = device.GUIEnvironment.GetFont("../../media/fonthaettenschweiler.bmp"); if (font != null) { device.GUIEnvironment.Skin.Font = font; } // add images device.GUIEnvironment.AddImage(device.VideoDriver.GetTexture("../../media/dotnetback.jpg"), new Position2D(0, 0), false, null, -1, ""); // add list box Rect pos = new Rect(150, 60, 350, 135); IGUIListBox box = device.GUIEnvironment.AddListBox(pos, null, -1, true); box.AddItem("Irrlicht Software Renderer 1.0"); box.AddItem("Apfelbaum Software Renderer 1.0"); box.AddItem("Direct3D 8.1"); box.AddItem("Direct3D 9.0c"); box.AddItem("OpenGL 1.5"); box.Selected = ((int)SelectedDriverType) - 1; // add terrain button pos.LowerRightCorner.Y += 50; pos.UpperLeftCorner.Y += 100; device.GUIEnvironment.AddButton(pos, null, (int)TestScenarios.TERRAIN_TEST, "Start Terrain Test"); // add indoor button pos.LowerRightCorner.Y += 30; pos.UpperLeftCorner.Y += 30; device.GUIEnvironment.AddButton(pos, null, (int)TestScenarios.INDOOR_TEST, "Start Indoor Test"); // add windows forms button pos.LowerRightCorner.Y += 30; pos.UpperLeftCorner.Y += 30; device.GUIEnvironment.AddButton(pos, null, (int)TestScenarios.WINDOWS_FORMS_TEST, "Start Windows.Forms Test"); // add shader test button pos.LowerRightCorner.Y += 30; pos.UpperLeftCorner.Y += 30; device.GUIEnvironment.AddButton(pos, null, (int)TestScenarios.SHADER_TEST, "Start Shader Test"); // add copyright stuff IGUIStaticText text = device.GUIEnvironment.AddStaticText( "Background 3D scene created by Alvaro F. Celis, rendered using Irrlicht", new Rect(2, 368, 500, 384), false, false, null, -1); text.OverrideColor = new Color(100, 150, 150, 150); // draw everything while (device.Run() && ClickedButton == TestScenarios.NONE) { if (device.WindowActive) { device.VideoDriver.BeginScene(true, true, new Color(255, 0, 0, 50)); device.SceneManager.DrawAll(); device.GUIEnvironment.DrawAll(); device.VideoDriver.EndScene(); } } device.CloseDevice(); return; }
public void displayMainMenu() { device = new IrrlichtDevice(DriverType.SOFTWARE, new Dimension2D(512, 384), 16, false, false, false); // set event receiver device.EventReceiver = this; // set text device.WindowCaption = "Irrlicht .NET test demos - main menu"; // load font IGUIFont font = device.GUIEnvironment.GetFont("../../media/fonthaettenschweiler.bmp"); if (font != null) device.GUIEnvironment.Skin.Font = font; // add images device.GUIEnvironment.AddImage( device.VideoDriver.GetTexture("../../media/dotnetback.jpg"), new Position2D(0,0), false, null, -1, ""); // add list box Rect pos = new Rect(150,60,350,135); IGUIListBox box = device.GUIEnvironment.AddListBox( pos, null, -1, true ); box.AddItem("Irrlicht Software Renderer 1.0"); box.AddItem("Apfelbaum Software Renderer 1.0"); box.AddItem("Direct3D 8.1"); box.AddItem("Direct3D 9.0c"); box.AddItem("OpenGL 1.5"); box.Selected = ((int)SelectedDriverType)-1; // add terrain button pos.LowerRightCorner.Y += 50; pos.UpperLeftCorner.Y += 100; device.GUIEnvironment.AddButton( pos, null, (int)TestScenarios.TERRAIN_TEST, "Start Terrain Test" ); // add indoor button pos.LowerRightCorner.Y += 30; pos.UpperLeftCorner.Y += 30; device.GUIEnvironment.AddButton( pos, null, (int)TestScenarios.INDOOR_TEST, "Start Indoor Test" ); // add windows forms button pos.LowerRightCorner.Y += 30; pos.UpperLeftCorner.Y += 30; device.GUIEnvironment.AddButton( pos, null, (int)TestScenarios.WINDOWS_FORMS_TEST, "Start Windows.Forms Test" ); // add shader test button pos.LowerRightCorner.Y += 30; pos.UpperLeftCorner.Y += 30; device.GUIEnvironment.AddButton( pos, null, (int)TestScenarios.SHADER_TEST, "Start Shader Test" ); // add copyright stuff IGUIStaticText text = device.GUIEnvironment.AddStaticText( "Background 3D scene created by Alvaro F. Celis, rendered using Irrlicht", new Rect(2,368,500,384), false, false, null, -1); text.OverrideColor = new Color(100,150,150,150); // draw everything while(device.Run() && ClickedButton == TestScenarios.NONE) if (device.WindowActive) { device.VideoDriver.BeginScene(true, true, new Color(255,0,0,50)); device.SceneManager.DrawAll(); device.GUIEnvironment.DrawAll(); device.VideoDriver.EndScene(); } device.CloseDevice(); return; }
/*The Event Receiver is not only capable of getting keyboard and mouse input events, * but also events of the graphical user interface (gui). There are events for almost * everything: Button click, Listbox selection change, events that say that a element * was hovered and so on. To be able to react to some of these events, we create an * event receiver. We only react to gui events, and if it's such an event, we get the * id of the caller (the gui element which caused the event) and get the pointer to the * gui environment.*/ public bool OnEvent(Event p_e) { if (p_e.Type == EventType.GUIEvent) { int id = p_e.GUIEventCaller.ID; IGUIEnvironment env = device.GUIEnvironment; switch (p_e.GUIEventType) { case (GUIEvent.SCROLL_BAR_CHANGED): if (id == 104) { // I think this is still not implemented //int pos=p_e.GUIEventCaller.Position; } 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 (GUIEvent.BUTTON_CLICKED): if (id == 101) { device.CloseDevice(); return(true); } if (id == 102) { listbox.AddItem("Window Created"); cnt += 30; if (cnt > 200) { cnt = 0; } IGUIElement window = env.AddWindow( new Rect(100 + cnt, 100 + cnt, 300 + cnt, 200 + cnt), false, //modal? "Test Window", null, //parent 0); // id env.AddStaticText("Please close me", new Rect(35, 35, 140, 50), true, //border false, //wordwrap window, //parent 0); //id return(true); } if (id == 103) { listbox.AddItem("File open"); env.AddFileOpenDialog("Please choose a file", false, null, 0); return(true); } break; } } return(false); }