static void createToolBox() { GUIEnvironment env = device.GUIEnvironment; GUIElement root = env.RootElement; // remove tool box if already there GUIElement e = root.GetElementFromID((int)guiID.DialogRootWindow, true); if (e != null) { e.Remove(); } // create the toolbox window GUIWindow w = env.AddWindow(new Recti(600, 45, 800, 480), false, "Toolset", null, (int)guiID.DialogRootWindow); // create tab control and tabs GUITabControl tab = env.AddTabControl(new Recti(2, 20, 800 - 602, 480 - 7), w, -1, true, true); GUITab t1 = tab.AddTab("Config"); // add some edit boxes and a button to tab one env.AddStaticText("Scale:", new Recti(10, 20, 60, 45), false, false, t1); env.AddStaticText("X:", new Recti(22, 48, 40, 66), false, false, t1); env.AddEditBox("1.0", new Recti(40, 46, 130, 66), true, t1, (int)guiID.XScale); env.AddStaticText("Y:", new Recti(22, 78, 40, 96), false, false, t1); env.AddEditBox("1.0", new Recti(40, 76, 130, 96), true, t1, (int)guiID.YScale); env.AddStaticText("Z:", new Recti(22, 108, 40, 126), false, false, t1); env.AddEditBox("1.0", new Recti(40, 106, 130, 126), true, t1, (int)guiID.ZScale); env.AddButton(new Recti(10, 134, 85, 165), t1, (int)guiID.ButtonSetScale, "Set"); // quick scale buttons env.AddButton(new Recti(65, 20, 95, 40), t1, (int)guiID.ButtonScaleMul10, "* 10"); env.AddButton(new Recti(100, 20, 130, 40), t1, (int)guiID.ButtonScaleDiv10, "* 0.1"); updateScaleInfo(model); // add transparency control env.AddStaticText("GUI Transparency Control:", new Recti(10, 200, 150, 225), true, false, t1); GUIScrollBar b = env.AddScrollBar(true, new Recti(10, 225, 150, 240), t1, (int)guiID.SkinTransparency); b.MaxValue = 255; b.Position = 255; // add framerate control env.AddStaticText("Framerate:", new Recti(10, 240, 150, 265), true, false, t1); b = env.AddScrollBar(true, new Recti(10, 265, 150, 280), t1, (int)guiID.SkinAnimationFPS); b.MaxValue = MaxFramerate; b.MinValue = -MaxFramerate; b.Position = DefaultFramerate; // bring irrlicht engine logo to front, because it now may be below the newly created toolbox root.BringToFront(root.GetElementFromID((int)guiID.Logo, true)); }
public MyEventReceiver(IrrlichtDevice device, SceneNode room, SceneNode earth) { device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); // store pointer to room so we can change its drawing mode this.driver = device.VideoDriver; this.room = room; this.earth = earth; GUIEnvironment env = device.GUIEnvironment; // set a nicer font GUIFont font = env.GetFont("../../media/fonthaettenschweiler.bmp"); if (font != null) { env.Skin.SetFont(font); } // add window and listbox GUIWindow window = env.AddWindow(new Recti(460, 375, 630, 470), false, "Use 'E' + 'R' to change"); this.listBox = env.AddListBox(new Recti(2, 22, 165, 88), window); this.listBox.AddItem("Diffuse"); this.listBox.AddItem("Bump mapping"); this.listBox.AddItem("Parallax mapping"); this.listBox.SelectedIndex = 1; // create problem text this.problemText = env.AddStaticText( "Your hardware or this renderer is not able to use the needed shaders for this material. Using fall back materials.", new Recti(150, 20, 470, 80)); this.problemText.OverrideColor = new Color(255, 255, 255, 100); // set start material (prefer parallax mapping if available) MaterialRenderer renderer = this.driver.GetMaterialRenderer(MaterialType.ParallaxMapSolid); if (renderer != null && renderer.Capability == 0) { this.listBox.SelectedIndex = 2; } // set the material which is selected in the listbox setMaterial(); }
private void initGUI(int size) { GUIEnvironment gui = device.GUIEnvironment; VideoDriver drv = gui.VideoDriver; gui.Clear(); gui.AddImage( drv.GetTexture("../../media/lime_logo_alpha.png"), new Vector2Di(30, 0)); guiWindow = gui.AddWindow(new Recti(20, 120, size + 20 + 20, size + 120 + 20 + 20 + 30), false, "Paint"); guiSize128 = gui.AddButton(new Recti(10, 30, 40, 30 + 20), guiWindow, -1, "128"); guiSize256 = gui.AddButton(new Recti(50, 30, 80, 30 + 20), guiWindow, -1, "256"); guiSize512 = gui.AddButton(new Recti(90, 30, 120, 30 + 20), guiWindow, -1, "512"); guiImage = gui.AddImage(new Recti(10, 30 + 30, size + 10 - 1, size + 30 - 1 + 30), true, guiWindow); gui.Focus = guiImage; }
static bool device_OnEvent(Event evnt) { if (evnt.Type == EventType.Mouse && evnt.Mouse.Type == MouseEventType.Move) { Vector2Di m = new Vector2Di(evnt.Mouse.X, evnt.Mouse.Y); Line3Df l = device.SceneManager.SceneCollisionManager.GetRayFromScreenCoordinates(m); Plane3Df p = new Plane3Df(new Vector3Df(0, 0, 0), new Vector3Df(100, 0, 0), new Vector3Df(0, 0, 100)); Vector3Df i = p.GetIntersectionWithLimitedLine(l.Start, l.End); if (i != null) { camera.Target = game.CenterOfTheBoard + new Vector3Df( (m.Y - device.VideoDriver.ScreenSize.Height / 2) / 100.0f, 0, (m.X - device.VideoDriver.ScreenSize.Width / 2) / 100.0f); i.Y += 25; // we want light to be a little bit above light.Position = i; } } if (window == null && evnt.Type == EventType.Mouse && (evnt.Mouse.Type == MouseEventType.LeftDown || evnt.Mouse.Type == MouseEventType.RightDown)) { text.Visible = false; // if user started to play - remove the gui text game.MouseClick(evnt.Mouse.X, evnt.Mouse.Y, evnt.Mouse.Type == MouseEventType.RightDown); if (game.StateOfTheGame != Game.State.Playing) { text.Visible = true; text.Text = game.StateOfTheGame == Game.State.Won ? TextWon : TextLost; } return(true); } if (evnt.Type == EventType.Key && evnt.Key.PressedDown && evnt.Key.Key == KeyCode.Esc) { if (window != null) { window.Remove(); window = null; return(true); } GUIEnvironment gui = device.GUIEnvironment; window = gui.AddWindow(new Recti(100, 100, 400, 400), true, "GAME MENU"); gui.AddButton(new Recti(20, 40, window.ClientRect.Width - 20, 60), window, 1510, "NEW GAME 5x5"); gui.AddButton(new Recti(20, 60, window.ClientRect.Width - 20, 80), window, 1520, "NEW GAME 10x10"); gui.AddButton(new Recti(20, 80, window.ClientRect.Width - 20, 100), window, 1530, "NEW GAME 15x15"); gui.AddButton(new Recti(20, 100, window.ClientRect.Width - 20, 120), window, 1540, "NEW GAME 20x20"); gui.AddCheckBox(optionShadows, new Recti(20, 140, window.ClientRect.Width - 20, 160), "SHOW REALTIME SHADOWS", window, 1710); gui.AddCheckBox(optionBackground, new Recti(20, 160, window.ClientRect.Width - 20, 180), "SHOW BACKGROUND", window, 1720); gui.AddCheckBox(optionFPS, new Recti(20, 180, window.ClientRect.Width - 20, 200), "SHOW FPS", window, 1730); gui.AddButton(new Recti(20, 260, window.ClientRect.Width - 20, 280), window, 1590, "EXIT GAME"); return(true); } if (window != null && evnt.Type == EventType.GUI) { if (evnt.GUI.Caller == window && evnt.GUI.Type == GUIEventType.ElementClosed) { window.Remove(); window = null; return(true); } if (evnt.GUI.Caller.ID == 1510 && evnt.GUI.Type == GUIEventType.ButtonClicked) { window.Remove(); window = null; game.NewGame(5, 5); setupCameraPositionAndTarget(); return(true); } if (evnt.GUI.Caller.ID == 1520 && evnt.GUI.Type == GUIEventType.ButtonClicked) { window.Remove(); window = null; game.NewGame(10, 10); setupCameraPositionAndTarget(); return(true); } if (evnt.GUI.Caller.ID == 1530 && evnt.GUI.Type == GUIEventType.ButtonClicked) { window.Remove(); window = null; game.NewGame(15, 15); setupCameraPositionAndTarget(); return(true); } if (evnt.GUI.Caller.ID == 1540 && evnt.GUI.Type == GUIEventType.ButtonClicked) { window.Remove(); window = null; game.NewGame(20, 20); setupCameraPositionAndTarget(); return(true); } if (evnt.GUI.Caller.ID == 1590 && evnt.GUI.Type == GUIEventType.ButtonClicked) { device.Close(); return(true); } if (evnt.GUI.Caller.ID == 1710 && evnt.GUI.Type == GUIEventType.CheckBoxChanged) { optionShadows = (evnt.GUI.Caller as GUICheckBox).Checked; light.CastShadows = optionShadows; return(true); } if (evnt.GUI.Caller.ID == 1720 && evnt.GUI.Type == GUIEventType.CheckBoxChanged) { optionBackground = (evnt.GUI.Caller as GUICheckBox).Checked; device.SceneManager.GetSceneNodeFromID(7777).Visible = optionBackground; return(true); } if (evnt.GUI.Caller.ID == 1730 && evnt.GUI.Type == GUIEventType.CheckBoxChanged) { optionFPS = (evnt.GUI.Caller as GUICheckBox).Checked; return(true); } } return(false); }
static bool device_OnEvent(Event e) { if (e.Type == EventType.GUI) { int id = e.GUI.Caller.ID; GUIEnvironment env = device.GUIEnvironment; switch (e.GUI.Type) { case GUIEventType.ScrollBarChanged: if (id == GUI_ID_ScrollbarTransparency) { int pos = ((GUIScrollBar)e.GUI.Caller).Position; foreach (GUIDefaultColor which in Enum.GetValues(typeof(GUIDefaultColor))) { Color color = env.Skin.GetColor(which); color.Alpha = pos; env.Skin.SetColor(color, which); } } break; case GUIEventType.ButtonClicked: switch (id) { case GUI_ID_ButtonQuit: device.Close(); return(true); case GUI_ID_ButtonWindowNew: listbox.AddItem("Window created"); winPosCounter += 30; if (winPosCounter > 200) { winPosCounter = 0; } int c = winPosCounter; GUIWindow window = env.AddWindow(new Recti(100 + c, 100 + c, 300 + c, 200 + c), false, "Test window"); env.AddStaticText("Please close me", new Recti(35, 35, 140, 50), true, false, window); return(true); case GUI_ID_ButtonFileOpen: listbox.AddItem("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("Please choose a file", true, null, -1, true); return(true); default: return(false); } case GUIEventType.FileDialogFileSelected: { // show the filename, selected in the file dialog GUIFileOpenDialog d = e.GUI.Caller as GUIFileOpenDialog; listbox.AddItem(d.FileName); break; } default: break; } } return(false); }