Beispiel #1
0
        static bool device_OnEvent(Event e)
        {
            // Escape swaps Camera Input
            if (e.Type == EventType.Key && !e.Key.PressedDown && OnKeyUp(e.Key.Key))
            {
                return(true);
            }

            if (e.Type == EventType.GUI)
            {
                guiID          id  = (guiID)e.GUI.Caller.ID;
                GUIEnvironment env = device.GUIEnvironment;

                switch (e.GUI.Type)
                {
                case GUIEventType.MenuItemSelected:
                    // a menu item was clicked
                    OnMenuItemSelected(e.GUI.Caller as GUIContextMenu);
                    break;

                case GUIEventType.FileDialogFileSelected:
                    // load the model file, selected in the file open dialog
                    loadModel((e.GUI.Caller as GUIFileOpenDialog).FileName);
                    break;

                case GUIEventType.ScrollBarChanged:
                    if (id == guiID.SkinTransparency)
                    {
                        // control skin transparency
                        int p = (e.GUI.Caller as GUIScrollBar).Position;
                        setSkinTransparency(p, env.Skin);
                    }
                    else if (id == guiID.SkinAnimationFPS)
                    {
                        // control animation speed
                        int p = (e.GUI.Caller as GUIScrollBar).Position;
                        if (model.Type == SceneNodeType.AnimatedMesh)
                        {
                            (model as AnimatedMeshSceneNode).AnimationSpeed = p;
                        }
                    }

                    break;

                case GUIEventType.ComboBoxChanged:
                    if (id == guiID.TextureFilter)
                    {
                        // control anti-aliasing/filtering
                        OnTextureFilterSelected(e.GUI.Caller as GUIComboBox);
                    }

                    break;

                case GUIEventType.ButtonClicked:
                    switch (id)
                    {
                    case guiID.ButtonSetScale:
                        // set scale
                        GUIElement r = env.RootElement;
                        Vector3Df  s = new Vector3Df(
                            Convert.ToSingle(r.GetElementFromID((int)guiID.XScale, true).Text),
                            Convert.ToSingle(r.GetElementFromID((int)guiID.YScale, true).Text),
                            Convert.ToSingle(r.GetElementFromID((int)guiID.ZScale, true).Text));

                        if (model != null)
                        {
                            model.Scale = s;
                        }

                        updateScaleInfo(model);
                        break;

                    case guiID.ButtonScaleMul10:
                        if (model != null)
                        {
                            model.Scale *= 10;
                        }

                        updateScaleInfo(model);
                        break;

                    case guiID.ButtonScaleDiv10:
                        if (model != null)
                        {
                            model.Scale *= 0.1f;
                        }

                        updateScaleInfo(model);
                        break;

                    case guiID.ButtonOpenModel:
                        env.AddFileOpenDialog("Please select a model file to open");
                        break;

                    case guiID.ButtonSelectArchive:
                        env.AddFileOpenDialog("Please select your game archive/directory");
                        break;

                    case guiID.ButtonShowAbout:
                        showAboutText();
                        break;

                    case guiID.ButtonShowToolbox:
                        createToolBox();
                        break;
                    }

                    break;                             // case GUIEventType.ButtonClicked:
                }
            }

            return(false);
        }
Beispiel #2
0
        static void OnMenuItemSelected(GUIContextMenu menu)
        {
            guiID          id  = (guiID)menu.SelectedCommandID;
            GUIEnvironment env = device.GUIEnvironment;

            switch (id)
            {
            case guiID.OpenModel:                     // FilOnButtonSetScalinge -> Open Model
                env.AddFileOpenDialog("Please select a model file to open");
                break;

            case guiID.SetModelArchive:                     // File -> Set Model Archive
                env.AddFileOpenDialog("Please select your game archive/directory");
                break;

            case guiID.LoadAsOctree:                     // File -> LoadAsOctree
                octree = !octree;
                menu.SetItemChecked(menu.SelectedIndex, octree);
                break;

            case guiID.Quit:                     // File -> Quit
                device.Close();
                break;

            case guiID.SkyBoxVisible:                     // View -> Skybox
                menu.SetItemChecked(menu.SelectedIndex, !menu.GetItemChecked(menu.SelectedIndex));
                skybox.Visible = !skybox.Visible;
                break;

            case guiID.DebugOff:                     // View -> Debug Information -> Off
                for (int i = 1; i <= 6; i++)
                {
                    menu.SetItemChecked(menu.SelectedIndex + i, false);
                }

                if (model != null)
                {
                    model.DebugDataVisible = DebugSceneType.Off;
                }

                break;

            case guiID.DebugBoundingBox:                     // View -> Debug Information -> Bounding Box
                menu.SetItemChecked(menu.SelectedIndex, !menu.GetItemChecked(menu.SelectedIndex));

                if (model != null)
                {
                    model.DebugDataVisible ^= DebugSceneType.BBox;
                }

                break;

            case guiID.DebugNormals:                     // View -> Debug Information -> Normals
                menu.SetItemChecked(menu.SelectedIndex, !menu.GetItemChecked(menu.SelectedIndex));

                if (model != null)
                {
                    model.DebugDataVisible ^= DebugSceneType.Normals;
                }

                break;

            case guiID.DebugSkeleton:                     // View -> Debug Information -> Skeleton
                menu.SetItemChecked(menu.SelectedIndex, !menu.GetItemChecked(menu.SelectedIndex));

                if (model != null)
                {
                    model.DebugDataVisible ^= DebugSceneType.Skeleton;
                }

                break;

            case guiID.DebugWireOverlay:                     // View -> Debug Information -> Wire overlay
                menu.SetItemChecked(menu.SelectedIndex, !menu.GetItemChecked(menu.SelectedIndex));

                if (model != null)
                {
                    model.DebugDataVisible ^= DebugSceneType.MeshWireOverlay;
                }

                break;

            case guiID.DebugHalfTransparent:                     // View -> Debug Information -> Half-Transparent
                menu.SetItemChecked(menu.SelectedIndex, !menu.GetItemChecked(menu.SelectedIndex));

                if (model != null)
                {
                    model.DebugDataVisible ^= DebugSceneType.HalfTransparency;
                }

                break;

            case guiID.DebugBuffersBoundingBoxes:                     // View -> Debug Information -> Buffers bounding boxes
                menu.SetItemChecked(menu.SelectedIndex, !menu.GetItemChecked(menu.SelectedIndex));

                if (model != null)
                {
                    model.DebugDataVisible ^= DebugSceneType.BBoxBuffers;
                }

                break;

            case guiID.DebugAll:                     // View -> Debug Information -> All
                for (int i = 1; i <= 6; i++)
                {
                    menu.SetItemChecked(menu.SelectedIndex - i, true);
                }

                if (model != null)
                {
                    model.DebugDataVisible = DebugSceneType.Full;
                }

                break;

            case guiID.About:                     // Help->About
                showAboutText();
                break;

            case guiID.ModelMaterialSolid:                     // View -> Material -> Solid
                if (model != null)
                {
                    model.SetMaterialType(MaterialType.Solid);
                }

                break;

            case guiID.ModelMaterialTransparent:                     // View -> Material -> Transparent
                if (model != null)
                {
                    model.SetMaterialType(MaterialType.TransparentAddColor);
                }

                break;

            case guiID.ModelMaterialReflection:                     // View -> Material -> Reflection
                if (model != null)
                {
                    model.SetMaterialType(MaterialType.SphereMap);
                }

                break;

            case guiID.CameraMaya:
                setActiveCamera(camera[0]);
                break;

            case guiID.CameraFirstPerson:
                setActiveCamera(camera[1]);
                break;
            }
        }
Beispiel #3
0
        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);
        }