/// <summary> /// Helper used by BeginDraw. This checks the graphics device status, /// making sure it is big enough for drawing the current control, and /// that the device is not lost. Returns an error string if the device /// could not be reset. /// </summary> string HandleDeviceReset() { bool deviceNeedsReset = false; switch (GraphicsDevice.GraphicsDeviceStatus) { case GraphicsDeviceStatus.Lost: // If the graphics device is lost, we cannot use it at all. return("Graphics device lost"); case GraphicsDeviceStatus.NotReset: // If device is in the not-reset state, we should try to reset it. deviceNeedsReset = true; break; default: // If the device state is ok, check whether it is big enough. PresentationParameters pp = GraphicsDevice.PresentationParameters; deviceNeedsReset = (ClientSize.Width > pp.BackBufferWidth) || (ClientSize.Height > pp.BackBufferHeight); break; } // Do we need to reset the device? if (deviceNeedsReset) { try { graphicsDeviceService.ResetDevice(ClientSize.Width, ClientSize.Height); } catch (Exception e) { return("Graphics device reset failed\n\n" + e); } } return(null); }
/// <summary> /// BeginDraw により使用されるヘルパー。これは、グラフィック デバイスのステータスを /// チェックして、現在のコントロールの描画に十分大きく、デバイスがロストしていない /// ことを確認します。デバイスをリセットできなかった場合、エラー文字列を返します。 /// </summary> string HandleDeviceReset() { bool deviceNeedsReset = false; switch (GraphicsDevice.GraphicsDeviceStatus) { case GraphicsDeviceStatus.Lost: // グラフィック デバイスがロストしている場合は、まったく使用できません。 return("Graphics device lost"); case GraphicsDeviceStatus.NotReset: // デバイスがリセットされていない状態の場合は、リセットを試みる必要があります。 deviceNeedsReset = true; break; default: // デバイスの状態が問題ない場合、十分に大きいかどうかをチェックします。 PresentationParameters pp = GraphicsDevice.PresentationParameters; deviceNeedsReset = (ClientSize.Width > pp.BackBufferWidth) || (ClientSize.Height > pp.BackBufferHeight); break; } // デバイスをリセットする必要がありますか。 if (deviceNeedsReset) { try { graphicsDeviceService.ResetDevice(ClientSize.Width, ClientSize.Height); } catch (Exception e) { return("Graphics device reset failed\n\n" + e); } } return(null); }