Пример #1
0
        public MainWindow(SimModel model)
        {
            InitializeComponent();
            this.DataContext = this;

            _app = (App)Application.Current;
            _model = model;

            //// タイトル
            this.Title = Properties.Resources.Str_AppName;

            //// アイコン
            System.IO.MemoryStream memStream = new System.IO.MemoryStream();
            (Properties.Resources.Ico_App as System.Drawing.Icon).Save(memStream);
            this.Icon = BitmapFrame.Create(memStream);

            // タスクトレイアイコン表示
            _notifyIconManager = new NotifyIconManager(this);

            // input関係初期化
            InitInput();

            // Load後の処理
            this.Loaded += (s, e) =>
            {
                // スクリーンサイズ取得
                System.Drawing.Rectangle r = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
                _scrRect32 = new Int32Rect(r.X, r.Y, r.Width, r.Height);
                _scrRect = new Rect(r.X, r.Y, r.Width, r.Height);

                // 最大化する
                // (AllosTransParency=True で Maximized だと何故か隙間ができるので手動で大きさ設定)
                this.Left = r.X; this.Top = r.Y;
                this.Width = r.Width; this.Height = r.Height;

                // pourSrcViewにPourSourceを結びつける
                pourSrcView.ViewModel.setPourSource(_model.PourSrc);

                //キャンバス初期化
                InitCanvas();

                HwndSource hwndSource = (HwndSource)HwndSource.FromVisual(this);
                _model.Start(_scrRect32, hwndSource.Handle);
            };

            // 閉じた後の処理
            this.Closing += (s, e) =>
            {
                _model.Stop();
                if (_configWin != null) _configWin.Close();
                _isClosed = true;
                if (_notifyIconManager != null) _notifyIconManager.Dispose();
            };
        }
Пример #2
0
        /// <summary>メイン処理を開始する</summary>
        private void Start()
        {
            // 設定読み込み
            Model.Config.Instance.Load();

            // フック開始
            GlobalHook.Hook();

            // モデル
            Model.SimModel _model = new Model.SimModel();

            // 窓の表示
            _win = new View.MainWindow(_model);
            _win.Show();

            // メインループ
            while (!_win.IsClosed)
            {
                _currentTick = Environment.TickCount;
                double diffms = Math.Floor(1000.0 / Model.Config.Instance.FrameRate);

                if (_currentTick < _nextTick)
                {
                    // 待ち
                }
                else
                {
                    // 処理
                    _model.Update();

                    if (Environment.TickCount >= _nextTick + diffms)
                    {
                        // フレームスキップ
                    }
                    else
                    {
                        // 描画
                        _win.Draw();
                    }

                    _frameCount++;
                    _lastCountTick = _currentTick;
                    while (_currentTick >= _nextTick)
                    {
                        _nextTick += (long)diffms;
                    }
                }

                // frame rate 計算
                if (_currentTick - _lastFpsTick >= 1000)
                {
                    _frameRate = _frameCount * 1000 / (double)(_currentTick - _lastFpsTick);
                    _frameCount = 0;
                    _lastFpsTick = _currentTick;
                }

                // UIメッセージ処理
                DoEvents();
            }

            // フック終了
            GlobalHook.Unhook();

            // 設定保存
            Model.Config.Instance.Save();
        }