Пример #1
0
        public GameWindow(DrunkSpock ds, bool bResizable, string title,
                          int width, int height, int monitorIndex, bool bCenter)
        {
            //set GLFW_NO_API
            Glfw.WindowHint(Hint.ClientApi, 0);
            Glfw.WindowHint(Hint.Resizable, bResizable);

            if (monitorIndex < 0 || monitorIndex >= Glfw.Monitors.Length)
            {
                monitorIndex = 0;
            }

            //my linux implementation has no monitor work area function
            List <int> xCoords = new List <int>();
            List <int> yCoords = new List <int>();

            for (int i = 0; i < Glfw.Monitors.Length; i++)
            {
                int mx, my;
                Glfw.GetMonitorPosition(Glfw.Monitors[i], out mx, out my);

                xCoords.Add(mx);
                yCoords.Add(my);
            }

            mWnd = Glfw.CreateWindow(width, height, title,
                                     Monitor.None, Window.None);

            int x, y;

            Glfw.GetWindowPosition(mWnd, out x, out y);

            //figure out which monitor the window is on
            int bestMonitorIndex = -1;
            int bestDist         = Int32.MaxValue;

            for (int i = 0; i < Glfw.Monitors.Length; i++)
            {
                if (x > xCoords[i])
                {
                    int dist = x - xCoords[i];
                    if (dist < bestDist)
                    {
                        bestMonitorIndex = i;
                    }
                }
            }

            //get current vidmode of monitors
            List <VideoMode> modes = new List <VideoMode>();

            for (int i = 0; i < Glfw.Monitors.Length; i++)
            {
                modes.Add(Glfw.GetVideoMode(Glfw.Monitors[i]));
            }

            if (bCenter)
            {
                //center of desired monitor
                x = modes[monitorIndex].Width / 2;
                y = modes[monitorIndex].Height / 2;

                //adjust back by half window size
                x -= width / 2;
                y -= height / 2;
            }
            else
            {
                //adjust to local coordiates
                x -= xCoords[bestMonitorIndex];
                y -= yCoords[bestMonitorIndex];
            }

            //add desired monitor xy
            x += xCoords[monitorIndex];
            y += yCoords[monitorIndex];

            Console.WriteLine(Glfw.VersionString);

            Glfw.SetWindowPosition(mWnd, x, y);

            ds.CreateWindowSurface(mWnd);

            Glfw.SetWindowSizeCallback(mWnd, OnReSize);

            mLastFrame = Stopwatch.GetTimestamp();
        }