Exemple #1
0
    public MainForm(ScreenManager screenManager)
    {
      _adaptToSizeEnabled = false;
      _screenManager = screenManager;

      ServiceRegistration.Get<ILogger>().Debug("SkinEngine MainForm: Registering DirectX MainForm as IScreenControl service");
      ServiceRegistration.Set<IScreenControl>(this);

      InitializeComponent();

      // Use the native method because the Icon.ExtractAssociatedIcon throws an exception when running from UNC paths
      ushort uicon;
      IntPtr handle = NativeMethods.ExtractAssociatedIcon(Handle, ServiceRegistration.Get<IPathManager>().GetPath("<APPLICATION_PATH>"), out uicon);
      Icon = Icon.FromHandle(handle);

      CheckForIllegalCrossThreadCalls = false;

      StartupSettings startupSettings = ServiceRegistration.Get<ISettingsManager>().Load<StartupSettings>();
      AppSettings appSettings = ServiceRegistration.Get<ISettingsManager>().Load<AppSettings>();

      _previousMousePosition = new Point(-1, -1);

      Size desiredWindowedSize = new Size(SkinContext.SkinResources.SkinWidth, SkinContext.SkinResources.SkinHeight);

      // Default screen for splashscreen is the one from where MP2 was started.
      System.Windows.Forms.Screen preferredScreen = System.Windows.Forms.Screen.FromControl(this);
      int numberOfScreens = System.Windows.Forms.Screen.AllScreens.Length;
      int validScreenNum = GetScreenNum();

      // Force the splashscreen to be displayed on a specific screen.
      if (startupSettings.StartupScreenNum >= 0 && startupSettings.StartupScreenNum < numberOfScreens)
      {
        validScreenNum = startupSettings.StartupScreenNum;
        preferredScreen = System.Windows.Forms.Screen.AllScreens[validScreenNum];
        StartPosition = FormStartPosition.Manual;
      }

      Location = new Point(preferredScreen.WorkingArea.X, preferredScreen.WorkingArea.Y);

      _previousWindowLocation = Location;
      _previousWindowClientSize = desiredWindowedSize;
      _previousWindowState = FormWindowState.Normal;

      if (appSettings.FullScreen)
        SwitchToFullscreen(validScreenNum);
      else
        SwitchToWindowedSize(Location, desiredWindowedSize, false);

      SkinContext.WindowSize = ClientSize;

      // GraphicsDevice has to be initialized after the form was sized correctly
      ServiceRegistration.Get<ILogger>().Debug("SkinEngine MainForm: Initialize DirectX");
      GraphicsDevice.Initialize_MainThread(this);

      // Read and apply ScreenSaver settings
      _screenSaverTimeOut = TimeSpan.FromMinutes(appSettings.ScreenSaverTimeoutMin);
      _isScreenSaverEnabled = appSettings.ScreenSaverEnabled;

      _applicationSuspendLevel = appSettings.SuspendLevel;
      UpdateSystemSuspendLevel_MainThread(); // Don't use UpdateSystemSuspendLevel() here because the window handle was not created yet

      Application.Idle += OnApplicationIdle;
      _adaptToSizeEnabled = true;

      VideoPlayerSynchronizationStrategy = new SynchronizeToPrimaryPlayer();

      // Register touch events
      TouchDown += MainForm_OnTouchDown;
      TouchMove += MainForm_OnTouchMove;
      TouchUp += MainForm_OnTouchUp;
    }
Exemple #2
0
    public MainForm(ScreenManager screenManager)
    {
      _adaptToSizeEnabled = false;
      _screenManager = screenManager;

      ServiceRegistration.Get<ILogger>().Debug("SkinEngine MainForm: Registering DirectX MainForm as IScreenControl service");
      ServiceRegistration.Set<IScreenControl>(this);

      InitializeComponent();
      CheckForIllegalCrossThreadCalls = false;

      AppSettings settings = ServiceRegistration.Get<ISettingsManager>().Load<AppSettings>();

      _previousMousePosition = new Point(-1, -1);

      Size desiredWindowedSize = new Size(SkinContext.SkinResources.SkinWidth, SkinContext.SkinResources.SkinHeight);

      _previousWindowLocation = Location;
      _previousWindowClientSize = desiredWindowedSize;
      _previousWindowState = FormWindowState.Normal;

      if (settings.FullScreen)
        SwitchToFullscreen(settings.FSScreenNum);
      else
        SwitchToWindowedSize(Location, desiredWindowedSize, false);

      SkinContext.WindowSize = ClientSize;

      // GraphicsDevice has to be initialized after the form was sized correctly
      ServiceRegistration.Get<ILogger>().Debug("SkinEngine MainForm: Initialize DirectX");
      GraphicsDevice.Initialize_MainThread(this);

      // Read and apply ScreenSaver settings
      _screenSaverTimeOut = TimeSpan.FromMinutes(settings.ScreenSaverTimeoutMin);
      _isScreenSaverEnabled = settings.ScreenSaverEnabled;

      _applicationSuspendLevel = settings.SuspendLevel;
      UpdateSystemSuspendLevel_MainThread(); // Don't use UpdateSystemSuspendLevel() here because the window handle was not created yet

      Application.Idle += OnApplicationIdle;
      _adaptToSizeEnabled = true;

      VideoPlayerSynchronizationStrategy = new SynchronizeToPrimaryPlayer();
    }