public static bool UpdateGameLogic(CKeys Keys, CMouse Mouse) { bool _Run = true; _Cursor.CursorVisible = Mouse.Visible; Mouse.CopyEvents(); Keys.CopyEvents(); CSound.Update(); CBackgroundMusic.Update(); CInput.Update(); if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC && _CurrentScreen != EScreens.ScreenSing) { CSongs.LoadCover(30L, 1); } if (CSettings.GameState != EGameState.EditTheme) { _Run &= HandleInputs(Keys, Mouse); _Run &= Update(); } else { _Run &= HandleInputThemeEditor(Keys, Mouse); _Run &= Update(); } return(_Run); }
public CDrawWinForm() { this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon)); _Textures = new List <STexture>(); _Bitmaps = new List <Bitmap>(); _Keys = new CKeys(); _Mouse = new CMouse(); this.ClientSize = new Size(1280, 720); this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.Opaque, true); // Create the backbuffer _backbuffer = new Bitmap(CSettings.iRenderW, CSettings.iRenderH); _g = Graphics.FromImage(_backbuffer); _g.Clear(Color.DarkBlue); this.Paint += new PaintEventHandler(this.OnPaintEvent); this.Closing += new CancelEventHandler(this.OnClosingEvent); this.KeyDown += new KeyEventHandler(this.OnKeyDownEvent); this.KeyPress += new KeyPressEventHandler(this.OnKeyPressEvent); this.KeyUp += new KeyEventHandler(this.OnKeyUpEvent); this.Resize += new EventHandler(this.OnResizeEvent); this.MouseMove += new MouseEventHandler(this.OnMouseMove); this.MouseDown += new MouseEventHandler(this.OnMouseDown); this.MouseUp += new MouseEventHandler(this.OnMouseUp); FlipBuffer(); Cursor.Show(); }
public CDrawWinForm() { Icon = new Icon(Path.Combine(CSettings.ProgramFolder, CSettings.FileNameIcon)); _Keys = new CKeys(); _Mouse = new CMouse(); ClientSize = new Size(1280, 720); SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.Opaque, true); // Create the backbuffer _Backbuffer = new Bitmap(CSettings.RenderW, CSettings.RenderH); _G = Graphics.FromImage(_Backbuffer); _G.Clear(Color.DarkBlue); Closing += _OnClosingEvent; KeyDown += _OnKeyDownEvent; KeyPress += _OnKeyPressEvent; KeyUp += _OnKeyUpEvent; Resize += _OnResizeEvent; MouseMove += _OnMouseMove; MouseDown += _OnMouseDown; MouseUp += _OnMouseUp; _FlipBuffer(); Cursor.Show(); }
public CDrawWinForm() { this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon)); _Textures = new List<STexture>(); _Bitmaps = new List<Bitmap>(); _Keys = new CKeys(); _Mouse = new CMouse(); this.ClientSize = new Size(1280, 720); this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.Opaque, true); // Create the backbuffer _backbuffer = new Bitmap(CSettings.iRenderW, CSettings.iRenderH); _g = Graphics.FromImage(_backbuffer); _g.Clear(Color.DarkBlue); this.Paint += new PaintEventHandler(this.OnPaintEvent); this.Closing += new CancelEventHandler(this.OnClosingEvent); this.KeyDown += new KeyEventHandler(this.OnKeyDownEvent); this.KeyPress += new KeyPressEventHandler(this.OnKeyPressEvent); this.KeyUp += new KeyEventHandler(this.OnKeyUpEvent); this.Resize += new EventHandler(this.OnResizeEvent); this.MouseMove += new MouseEventHandler(this.OnMouseMove); this.MouseDown += new MouseEventHandler(this.OnMouseDown); this.MouseUp += new MouseEventHandler(this.OnMouseUp); FlipBuffer(); Cursor.Show(); }
public COpenGL() { this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon)); _Textures = new List<STexture>(); //Check AA Mode CConfig.AAMode = (EAntiAliasingModes)CheckAntiAliasingMode((int)CConfig.AAMode); OpenTK.Graphics.ColorFormat cf = new OpenTK.Graphics.ColorFormat(32); OpenTK.Graphics.GraphicsMode gm; bool ok = false; try { gm = new OpenTK.Graphics.GraphicsMode(cf, 24, 0, (int)CConfig.AAMode); control = new GLControl(gm, 2, 1, OpenTK.Graphics.GraphicsContextFlags.Default); if (control.GraphicsMode != null) ok = true; } catch (Exception) { ok = false; } if (!ok) control = new GLControl(); control.MakeCurrent(); control.VSync = (CConfig.VSync == EOffOn.TR_CONFIG_ON); this.Controls.Add(control); _Keys = new CKeys(); this.Paint += new PaintEventHandler(this.OnPaintEvent); this.Closing += new CancelEventHandler(this.OnClosingEvent); this.Resize += new EventHandler(this.OnResizeEvent); control.KeyDown += new KeyEventHandler(this.OnKeyDownEvent); control.PreviewKeyDown += new PreviewKeyDownEventHandler(this.OnPreviewKeyDownEvent); control.KeyPress += new KeyPressEventHandler(this.OnKeyPressEvent); control.KeyUp += new KeyEventHandler(this.OnKeyUpEvent); _Mouse = new CMouse(); control.MouseMove += new MouseEventHandler(this.OnMouseMove); control.MouseWheel += new MouseEventHandler(this.OnMouseWheel); control.MouseDown += new MouseEventHandler(this.OnMouseDown); control.MouseUp += new MouseEventHandler(this.OnMouseUp); control.MouseLeave += new EventHandler(this.OnMouseLeave); control.MouseEnter += new EventHandler(this.OnMouseEnter); this.ClientSize = new Size(CConfig.ScreenW, CConfig.ScreenH); //this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.Opaque, true); this.CenterToScreen(); }
private static bool HandleInputs(CKeys keys, CMouse Mouse) { KeyEvent KeyEvent = new KeyEvent(); MouseEvent MouseEvent = new MouseEvent(); bool Resume = true; while (keys.PollEvent(ref KeyEvent)) { if (KeyEvent.Key == Keys.Left || KeyEvent.Key == Keys.Right || KeyEvent.Key == Keys.Up || KeyEvent.Key == Keys.Down) { CSettings.MouseInacive(); _Cursor.FadeOut(); } if (KeyEvent.ModSHIFT && (KeyEvent.Key == Keys.F1)) { CSettings.GameState = EGameState.EditTheme; } else if (KeyEvent.ModALT && (KeyEvent.Key == Keys.Enter)) { CSettings.bFullScreen = !CSettings.bFullScreen; } else if (KeyEvent.ModALT && (KeyEvent.Key == Keys.P)) { CDraw.MakeScreenShot(); } else { if (!_Fading) { Resume &= Screens[(int)ActualScreen].HandleInput(KeyEvent); } } } while (Mouse.PollEvent(ref MouseEvent)) { if (MouseEvent.Wheel != 0) { CSettings.MouseActive(); _Cursor.FadeIn(); } UpdateMousePosition(MouseEvent.X, MouseEvent.Y); if (!_Fading && (_Cursor.IsActive || MouseEvent.LB || MouseEvent.RB)) { Resume &= Screens[(int)ActualScreen].HandleMouse(MouseEvent); } } return(Resume); }
/// <summary> /// 获取键盘按下的键值 /// </summary> /// <returns></returns> private CKeys getCurKeyboardDownKey() { CKeys vKye = CKeys.None; foreach (Int32 key in Enum.GetValues(typeof(CKeys))) { if (isKeyDown((CKeys)key)) { vKye = (CKeys)key; break; } } return(vKye); }
/// <summary> /// 键盘事件处理 /// </summary> public void keyboardEventsHandler() { CKeyboardEventArgs e; CKeys vKeyDown = getCurKeyboardDownKey(); if (vKeyDown != CKeys.None) { this.m_oldKey = vKeyDown; e = new CKeyboardEventArgs(vKeyDown); this.onKeyDown(e); } else if (m_oldKey != CKeys.None && !isKeyDown(this.m_oldKey)) { e = new CKeyboardEventArgs(this.m_oldKey); this.onKeyUp(e); this.m_oldKey = CKeys.None; } }
private static bool HandleInputThemeEditor(CKeys keys, CMouse Mouse) { KeyEvent KeyEvent = new KeyEvent(); MouseEvent MouseEvent = new MouseEvent(); while (keys.PollEvent(ref KeyEvent)) { if (KeyEvent.ModSHIFT && (KeyEvent.Key == Keys.F1)) { CSettings.GameState = EGameState.Normal; _Screens[(int)_CurrentScreen].NextInteraction(); } else if (KeyEvent.ModALT && (KeyEvent.Key == Keys.Enter)) { CSettings.bFullScreen = !CSettings.bFullScreen; } else if (KeyEvent.ModALT && (KeyEvent.Key == Keys.P)) { CDraw.MakeScreenShot(); } else { if (!_Fading) { _Screens[(int)_CurrentScreen].HandleInputThemeEditor(KeyEvent); } } } while (Mouse.PollEvent(ref MouseEvent)) { if (!_Fading) { _Screens[(int)_CurrentScreen].HandleMouseThemeEditor(MouseEvent); } UpdateMousePosition(MouseEvent.X, MouseEvent.Y); } return(true); }
private static bool HandleInputs(CKeys keys, CMouse Mouse) { KeyEvent KeyEvent = new KeyEvent(); MouseEvent MouseEvent = new MouseEvent(); bool Resume = true; while (keys.PollEvent(ref KeyEvent)) { if (KeyEvent.Key == Keys.Left || KeyEvent.Key == Keys.Right || KeyEvent.Key == Keys.Up || KeyEvent.Key == Keys.Down) { CSettings.MouseInacive(); _Cursor.FadeOut(); } if (KeyEvent.ModSHIFT && (KeyEvent.Key == Keys.F1)) { CSettings.GameState = EGameState.EditTheme; } else if (KeyEvent.ModALT && (KeyEvent.Key == Keys.Enter )) { CSettings.bFullScreen = !CSettings.bFullScreen; } else if (KeyEvent.ModALT && (KeyEvent.Key == Keys.P)) { CDraw.MakeScreenShot(); } else { if (!_Fading) Resume &= Screens[(int)ActualScreen].HandleInput(KeyEvent); } } while (Mouse.PollEvent(ref MouseEvent)) { UpdateMousePosition(MouseEvent.X, MouseEvent.Y); if (!_Fading && (_Cursor.IsActive || MouseEvent.LB || MouseEvent.RB)) Resume &= Screens[(int)ActualScreen].HandleMouse(MouseEvent); } return Resume; }
private static bool HandleInputs(CKeys keys, CMouse Mouse) { KeyEvent KeyEvent = new KeyEvent(); MouseEvent MouseEvent = new MouseEvent(); KeyEvent InputKeyEvent = new KeyEvent(); MouseEvent InputMouseEvent = new MouseEvent(); bool PopupPlayerControlAllowed = _CurrentScreen != EScreens.ScreenOptionsRecord && _CurrentScreen != EScreens.ScreenSing && _CurrentScreen != EScreens.ScreenSong && _CurrentScreen != EScreens.ScreenCredits; bool PopupVolumeControlAllowed = _CurrentScreen != EScreens.ScreenCredits; bool Resume = true; bool EventsAvailable = false; bool InputEventsAvailable = CInput.PollKeyEvent(ref InputKeyEvent); while ((EventsAvailable = keys.PollEvent(ref KeyEvent)) || InputEventsAvailable) { if (!EventsAvailable) KeyEvent = InputKeyEvent; if (KeyEvent.Key == Keys.Left || KeyEvent.Key == Keys.Right || KeyEvent.Key == Keys.Up || KeyEvent.Key == Keys.Down) { CSettings.MouseInactive(); _Cursor.FadeOut(); } if (PopupPlayerControlAllowed && KeyEvent.Key == Keys.Tab) { if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) ShowPopup(EPopupScreens.PopupPlayerControl); else HidePopup(EPopupScreens.PopupPlayerControl); } if (KeyEvent.ModSHIFT && (KeyEvent.Key == Keys.F1)) { CSettings.GameState = EGameState.EditTheme; } else if (KeyEvent.ModALT && (KeyEvent.Key == Keys.Enter )) { CSettings.bFullScreen = !CSettings.bFullScreen; } else if (KeyEvent.ModALT && (KeyEvent.Key == Keys.P)) { CDraw.MakeScreenShot(); } else { if (!_Fading) { bool handled = false; if (_CurrentPopupScreen != EPopupScreens.NoPopup) handled = _PopupScreens[(int)_CurrentPopupScreen].HandleInput(KeyEvent); if (!handled) Resume &= _Screens[(int)_CurrentScreen].HandleInput(KeyEvent); } } if (!EventsAvailable) InputEventsAvailable = CInput.PollKeyEvent(ref InputKeyEvent); } InputEventsAvailable = CInput.PollMouseEvent(ref InputMouseEvent); while ((EventsAvailable = Mouse.PollEvent(ref MouseEvent)) || InputEventsAvailable) { if (!EventsAvailable) MouseEvent = InputMouseEvent; if (MouseEvent.Wheel != 0) { CSettings.MouseActive(); _Cursor.FadeIn(); } UpdateMousePosition(MouseEvent.X, MouseEvent.Y); bool isOverPopupPlayerControl = CHelper.IsInBounds(_PopupScreens[(int)EPopupScreens.PopupPlayerControl].ScreenArea, MouseEvent); if (PopupPlayerControlAllowed && isOverPopupPlayerControl) { if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) ShowPopup(EPopupScreens.PopupPlayerControl); } if (!isOverPopupPlayerControl && _CurrentPopupScreen == EPopupScreens.PopupPlayerControl) HidePopup(EPopupScreens.PopupPlayerControl); bool isOverPopupVolumeControl = CHelper.IsInBounds(_PopupScreens[(int)EPopupScreens.PopupVolumeControl].ScreenArea, MouseEvent); if (PopupVolumeControlAllowed && isOverPopupVolumeControl) { if (_CurrentPopupScreen == EPopupScreens.NoPopup) { ShowPopup(EPopupScreens.PopupVolumeControl); _VolumePopupTimer.Reset(); } } if (!isOverPopupVolumeControl && _CurrentPopupScreen == EPopupScreens.PopupVolumeControl) { HidePopup(EPopupScreens.PopupVolumeControl); _VolumePopupTimer.Reset(); } bool handled = false; if (_CurrentPopupScreen != EPopupScreens.NoPopup) handled = _PopupScreens[(int)_CurrentPopupScreen].HandleMouse(MouseEvent); if (handled && _CurrentPopupScreen == EPopupScreens.PopupVolumeControl) _Screens[(int)_CurrentScreen].ApplyVolume(); if (!handled && !_Fading && (_Cursor.IsActive || MouseEvent.LB || MouseEvent.RB || MouseEvent.MB)) Resume &= _Screens[(int)_CurrentScreen].HandleMouse(MouseEvent); if (!EventsAvailable) InputEventsAvailable = CInput.PollMouseEvent(ref InputMouseEvent); } return Resume; }
private static bool HandleInputs(CKeys keys, CMouse Mouse) { KeyEvent KeyEvent = new KeyEvent(); MouseEvent MouseEvent = new MouseEvent(); KeyEvent InputKeyEvent = new KeyEvent(); MouseEvent InputMouseEvent = new MouseEvent(); bool PopupPlayerControlAllowed = _CurrentScreen != EScreens.ScreenOptionsRecord && _CurrentScreen != EScreens.ScreenSing && _CurrentScreen != EScreens.ScreenSong && _CurrentScreen != EScreens.ScreenCredits; bool PopupVolumeControlAllowed = _CurrentScreen != EScreens.ScreenCredits; bool Resume = true; bool EventsAvailable = false; bool InputEventsAvailable = CInput.PollKeyEvent(ref InputKeyEvent); while ((EventsAvailable = keys.PollEvent(ref KeyEvent)) || InputEventsAvailable) { if (!EventsAvailable) { KeyEvent = InputKeyEvent; } if (KeyEvent.Key == Keys.Left || KeyEvent.Key == Keys.Right || KeyEvent.Key == Keys.Up || KeyEvent.Key == Keys.Down) { CSettings.MouseInactive(); _Cursor.FadeOut(); } if (PopupPlayerControlAllowed && KeyEvent.Key == Keys.Tab) { if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) { ShowPopup(EPopupScreens.PopupPlayerControl); } else { HidePopup(EPopupScreens.PopupPlayerControl); } } if (KeyEvent.ModSHIFT && (KeyEvent.Key == Keys.F1)) { CSettings.GameState = EGameState.EditTheme; } else if (KeyEvent.ModALT && (KeyEvent.Key == Keys.Enter)) { CSettings.bFullScreen = !CSettings.bFullScreen; } else if (KeyEvent.ModALT && (KeyEvent.Key == Keys.P)) { CDraw.MakeScreenShot(); } else { if (!_Fading) { bool handled = false; if (_CurrentPopupScreen != EPopupScreens.NoPopup) { handled = _PopupScreens[(int)_CurrentPopupScreen].HandleInput(KeyEvent); } if (!handled) { Resume &= _Screens[(int)_CurrentScreen].HandleInput(KeyEvent); } } } if (!EventsAvailable) { InputEventsAvailable = CInput.PollKeyEvent(ref InputKeyEvent); } } InputEventsAvailable = CInput.PollMouseEvent(ref InputMouseEvent); while ((EventsAvailable = Mouse.PollEvent(ref MouseEvent)) || InputEventsAvailable) { if (!EventsAvailable) { MouseEvent = InputMouseEvent; } if (MouseEvent.Wheel != 0) { CSettings.MouseActive(); _Cursor.FadeIn(); } UpdateMousePosition(MouseEvent.X, MouseEvent.Y); bool isOverPopupPlayerControl = CHelper.IsInBounds(_PopupScreens[(int)EPopupScreens.PopupPlayerControl].ScreenArea, MouseEvent); if (PopupPlayerControlAllowed && isOverPopupPlayerControl) { if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) { ShowPopup(EPopupScreens.PopupPlayerControl); } } if (!isOverPopupPlayerControl && _CurrentPopupScreen == EPopupScreens.PopupPlayerControl) { HidePopup(EPopupScreens.PopupPlayerControl); } bool isOverPopupVolumeControl = CHelper.IsInBounds(_PopupScreens[(int)EPopupScreens.PopupVolumeControl].ScreenArea, MouseEvent); if (PopupVolumeControlAllowed && isOverPopupVolumeControl) { if (_CurrentPopupScreen == EPopupScreens.NoPopup) { ShowPopup(EPopupScreens.PopupVolumeControl); _VolumePopupTimer.Reset(); } } if (!isOverPopupVolumeControl && _CurrentPopupScreen == EPopupScreens.PopupVolumeControl) { HidePopup(EPopupScreens.PopupVolumeControl); _VolumePopupTimer.Reset(); } bool handled = false; if (_CurrentPopupScreen != EPopupScreens.NoPopup) { handled = _PopupScreens[(int)_CurrentPopupScreen].HandleMouse(MouseEvent); } if (handled && _CurrentPopupScreen == EPopupScreens.PopupVolumeControl) { _Screens[(int)_CurrentScreen].ApplyVolume(); } if (!handled && !_Fading && (_Cursor.IsActive || MouseEvent.LB || MouseEvent.RB || MouseEvent.MB)) { Resume &= _Screens[(int)_CurrentScreen].HandleMouse(MouseEvent); } if (!EventsAvailable) { InputEventsAvailable = CInput.PollMouseEvent(ref InputMouseEvent); } } return(Resume); }
public CKeyboardEventArgs(CKeys keys) { this.keys = keys; }
/// <summary> /// Creates a new Instance of the CDirect3D Class /// </summary> public CDirect3D() { this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon)); _Textures = new List<STexture>(); _D3DTextures = new List<Texture>(); _Queque = new List<STextureQueque>(); _Keys = new CKeys(); _D3D = new Direct3D(); this.Paint += new PaintEventHandler(this.OnPaintEvent); this.Closing += new CancelEventHandler(this.OnClosingEvent); this.Resize += new EventHandler(this.OnResizeEvent); this.KeyDown += new KeyEventHandler(this.OnKeyDown); this.PreviewKeyDown += new PreviewKeyDownEventHandler(this.OnPreviewKeyDown); this.KeyPress += new KeyPressEventHandler(this.OnKeyPress); this.KeyUp += new KeyEventHandler(this.OnKeyUp); _Mouse = new CMouse(); this.MouseMove += new MouseEventHandler(this.OnMouseMove); this.MouseWheel += new MouseEventHandler(this.OnMouseWheel); this.MouseDown += new MouseEventHandler(this.OnMouseDown); this.MouseUp += new MouseEventHandler(this.OnMouseUp); this.MouseLeave += new EventHandler(this.OnMouseLeave); this.MouseEnter += new EventHandler(this.OnMouseEnter); this.ClientSize = new Size(CConfig.ScreenW, CConfig.ScreenH); _SizeBeforeMinimize = ClientSize; _PresentParameters = new PresentParameters(); _PresentParameters.Windowed = true; _PresentParameters.SwapEffect = SwapEffect.Discard; _PresentParameters.BackBufferHeight = CConfig.ScreenH; _PresentParameters.BackBufferWidth = CConfig.ScreenW; _PresentParameters.BackBufferFormat = _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format; _PresentParameters.Multisample = MultisampleType.None; _PresentParameters.MultisampleQuality = 0; //Apply antialiasing and check if antialiasing mode is supported #region Antialiasing int quality = 0; if (CConfig.AAMode == EAntiAliasingModes.x0) { _PresentParameters.Multisample = MultisampleType.None; _PresentParameters.MultisampleQuality = quality; } else if (CConfig.AAMode == EAntiAliasingModes.x2) { if (_D3D.CheckDeviceMultisampleType(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, false, MultisampleType.TwoSamples, out quality)) { _PresentParameters.Multisample = MultisampleType.TwoSamples; _PresentParameters.MultisampleQuality = quality - 1; } else CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA"); } else if (CConfig.AAMode == EAntiAliasingModes.x4) { if (_D3D.CheckDeviceMultisampleType(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, false, MultisampleType.FourSamples, out quality)) { _PresentParameters.Multisample = MultisampleType.FourSamples; _PresentParameters.MultisampleQuality = quality - 1; } else CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA"); } else if (CConfig.AAMode == EAntiAliasingModes.x8) { if (_D3D.CheckDeviceMultisampleType(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, false, MultisampleType.EightSamples, out quality)) { _PresentParameters.Multisample = MultisampleType.EightSamples; _PresentParameters.MultisampleQuality = quality - 1; } else CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA"); } else if (CConfig.AAMode == EAntiAliasingModes.x16 || CConfig.AAMode == EAntiAliasingModes.x32) //x32 is not supported, fallback to x16 { if (_D3D.CheckDeviceMultisampleType(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, false, MultisampleType.SixteenSamples, out quality)) { _PresentParameters.Multisample = MultisampleType.SixteenSamples; _PresentParameters.MultisampleQuality = quality - 1; } else CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA"); } #endregion Antialiasing //Apply the VSync configuration if (CConfig.VSync == EOffOn.TR_CONFIG_ON) _PresentParameters.PresentationInterval = PresentInterval.Default; else _PresentParameters.PresentationInterval = PresentInterval.Immediate; //GMA 950 graphics devices can only process vertices in software mode Capabilities caps = _D3D.GetDeviceCaps(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware); CreateFlags flags = CreateFlags.None; if ((caps.DeviceCaps & DeviceCaps.HWTransformAndLight) != 0) flags = CreateFlags.HardwareVertexProcessing; else flags = CreateFlags.SoftwareVertexProcessing; _Device = new Device(_D3D, _D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, Handle, flags, _PresentParameters); this.CenterToScreen(); //This creates a new white texture and adds it to the texture pool //This texture is used for the DrawRect method blankMap = new Bitmap(1, 1); Graphics g = Graphics.FromImage(blankMap); g.Clear(Color.White); g.Dispose(); blankTexture = AddTexture(blankMap); transparentTexture = new Texture(_Device, 1, 1, 0, Usage.None, Format.A8R8G8B8, Pool.Managed); blankMap.Dispose(); }
/// <summary> /// Creates a new Instance of the CDirect3D Class /// </summary> public CDirect3D() { this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon)); _Textures = new Dictionary<int, STexture>(); _D3DTextures = new Dictionary<int, Texture>(); _Queque = new List<STextureQueque>(); _IDs = new Queue<int>(); //Fill Queue with 100000 IDs for (int i = 0; i < 100000; i++) _IDs.Enqueue(i); _Vertices = new Queue<TexturedColoredVertex>(); _VerticesTextures = new Queue<Texture>(); _VerticesRotationMatrices = new Queue<Matrix>(); _Keys = new CKeys(); try { _D3D = new Direct3D(); } catch (Direct3D9NotFoundException e) { MessageBox.Show("No DirectX runtimes were found, please download and install them " + "from http://www.microsoft.com/download/en/details.aspx?id=8109", CSettings.sProgramName, MessageBoxButtons.OK, MessageBoxIcon.Error); CLog.LogError(e.Message + " - No DirectX runtimes were found, please download and install them from http://www.microsoft.com/download/en/details.aspx?id=8109"); Environment.Exit(Environment.ExitCode); } this.Paint += new PaintEventHandler(this.OnPaintEvent); this.Closing += new CancelEventHandler(this.OnClosingEvent); this.Resize += new EventHandler(this.OnResizeEvent); this.KeyDown += new KeyEventHandler(this.OnKeyDown); this.PreviewKeyDown += new PreviewKeyDownEventHandler(this.OnPreviewKeyDown); this.KeyPress += new KeyPressEventHandler(this.OnKeyPress); this.KeyUp += new KeyEventHandler(this.OnKeyUp); _Mouse = new CMouse(); this.MouseMove += new MouseEventHandler(this.OnMouseMove); this.MouseWheel += new MouseEventHandler(this.OnMouseWheel); this.MouseDown += new MouseEventHandler(this.OnMouseDown); this.MouseUp += new MouseEventHandler(this.OnMouseUp); this.MouseLeave += new EventHandler(this.OnMouseLeave); this.MouseEnter += new EventHandler(this.OnMouseEnter); this.ClientSize = new Size(CConfig.ScreenW, CConfig.ScreenH); _SizeBeforeMinimize = ClientSize; _PresentParameters = new PresentParameters(); _PresentParameters.Windowed = true; _PresentParameters.SwapEffect = SwapEffect.Discard; _PresentParameters.BackBufferHeight = CConfig.ScreenH; _PresentParameters.BackBufferWidth = CConfig.ScreenW; _PresentParameters.BackBufferFormat = _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format; _PresentParameters.Multisample = MultisampleType.None; _PresentParameters.MultisampleQuality = 0; //Apply antialiasing and check if antialiasing mode is supported #region Antialiasing int quality = 0; if (CConfig.AAMode == EAntiAliasingModes.x0) { _PresentParameters.Multisample = MultisampleType.None; _PresentParameters.MultisampleQuality = quality; } else if (CConfig.AAMode == EAntiAliasingModes.x2) { if (_D3D.CheckDeviceMultisampleType(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, false, MultisampleType.TwoSamples, out quality)) { _PresentParameters.Multisample = MultisampleType.TwoSamples; _PresentParameters.MultisampleQuality = quality - 1; } else CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA"); } else if (CConfig.AAMode == EAntiAliasingModes.x4) { if (_D3D.CheckDeviceMultisampleType(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, false, MultisampleType.FourSamples, out quality)) { _PresentParameters.Multisample = MultisampleType.FourSamples; _PresentParameters.MultisampleQuality = quality - 1; } else CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA"); } else if (CConfig.AAMode == EAntiAliasingModes.x8) { if (_D3D.CheckDeviceMultisampleType(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, false, MultisampleType.EightSamples, out quality)) { _PresentParameters.Multisample = MultisampleType.EightSamples; _PresentParameters.MultisampleQuality = quality - 1; } else CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA"); } else if (CConfig.AAMode == EAntiAliasingModes.x16 || CConfig.AAMode == EAntiAliasingModes.x32) //x32 is not supported, fallback to x16 { if (_D3D.CheckDeviceMultisampleType(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, false, MultisampleType.SixteenSamples, out quality)) { _PresentParameters.Multisample = MultisampleType.SixteenSamples; _PresentParameters.MultisampleQuality = quality - 1; } else CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA"); } #endregion Antialiasing //Apply the VSync configuration if (CConfig.VSync == EOffOn.TR_CONFIG_ON) _PresentParameters.PresentationInterval = PresentInterval.Default; else _PresentParameters.PresentationInterval = PresentInterval.Immediate; //GMA 950 graphics devices can only process vertices in software mode Capabilities caps = _D3D.GetDeviceCaps(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware); CreateFlags flags = CreateFlags.None; if ((caps.DeviceCaps & DeviceCaps.HWTransformAndLight) != 0) flags = CreateFlags.HardwareVertexProcessing; else flags = CreateFlags.SoftwareVertexProcessing; try { _Device = new Device(_D3D, _D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, Handle, flags, _PresentParameters); } catch (Exception e) { MessageBox.Show("Something went wrong during device creating, please check if your DirectX redistributables " + "and graphic card drivers are up to date. You can download the DirectX runtimes at http://www.microsoft.com/download/en/details.aspx?id=8109", CSettings.sProgramName, MessageBoxButtons.OK, MessageBoxIcon.Error); CLog.LogError(e.Message + " - Something went wrong during device creating, please check if your DirectX redistributables and grafic card drivers are up to date. You can download the DirectX runtimes at http://www.microsoft.com/download/en/details.aspx?id=8109"); Environment.Exit(Environment.ExitCode); } finally { if (_Device == null || _Device.Disposed) { MessageBox.Show("Something went wrong during device creating, please check if your DirectX redistributables " + "and graphic card drivers are up to date. You can download the DirectX runtimes at http://www.microsoft.com/download/en/details.aspx?id=8109", CSettings.sProgramName, MessageBoxButtons.OK, MessageBoxIcon.Error); CLog.LogError("Something went wrong during device creating, please check if your DirectX redistributables and grafic card drivers are up to date. You can download the DirectX runtimes at http://www.microsoft.com/download/en/details.aspx?id=8109"); Environment.Exit(Environment.ExitCode); } } this.CenterToScreen(); }
private static bool HandleInputThemeEditor(CKeys keys, CMouse Mouse) { KeyEvent KeyEvent = new KeyEvent(); MouseEvent MouseEvent = new MouseEvent(); while (keys.PollEvent(ref KeyEvent)) { if (KeyEvent.ModSHIFT && (KeyEvent.Key == Keys.F1)) { CSettings.GameState = EGameState.Normal; Screens[(int)ActualScreen].NextInteraction(); } else if (KeyEvent.ModALT && (KeyEvent.Key == Keys.Enter)) { CSettings.bFullScreen = !CSettings.bFullScreen; } else if (KeyEvent.ModALT && (KeyEvent.Key == Keys.P)) { CDraw.MakeScreenShot(); } else { if (!_Fading) Screens[(int)ActualScreen].HandleInputThemeEditor(KeyEvent); } } while (Mouse.PollEvent(ref MouseEvent)) { if (!_Fading) Screens[(int)ActualScreen].HandleMouseThemeEditor(MouseEvent); UpdateMousePosition(MouseEvent.X, MouseEvent.Y); } return true; }
public CKeyboardEventArgs(CKeys keys) { this.m_keys = keys; }
public static bool UpdateGameLogic(CKeys Keys, CMouse Mouse) { bool _Run = true; _Cursor.CursorVisible = Mouse.Visible; Mouse.CopyEvents(); Keys.CopyEvents(); CSound.Update(); if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC && ActualScreen != EScreens.ScreenSing) CSongs.LoadCover(30L); if (CSettings.GameState != EGameState.EditTheme) { _Run &= HandleInputs(Keys, Mouse); _Run &= Update(); } else { _Run &= HandleInputThemeEditor(Keys, Mouse); _Run &= Update(); } return _Run; }
/// <summary> /// 是否按下键 /// </summary> /// <param name="vKey"></param> /// <returns></returns> private Boolean isKeyDown(CKeys vKey) { return(0 != (GetAsyncKeyState((Int32)vKey) & KEY_STATE)); }