Exemplo n.º 1
0
        void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));

            this.xnaControl = new Boku.XNAControl();
            this.SuspendLayout();

            // 800x600 is our minimum allowable size.
            System.Drawing.Size size = new System.Drawing.Size(800, 600);

            //
            // xnaControl
            //
            this.xnaControl.Location = new System.Drawing.Point(0, 0);
            this.xnaControl.Name     = "xnaControl";
            this.xnaControl.Size     = size;
            this.xnaControl.TabIndex = 2;
            this.xnaControl.Text     = "XNAControl";
            this.xnaControl.Click   += new System.EventHandler(this.xnaControl1_Click);
            //
            // MainForm
            //
            this.Icon        = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.ClientSize  = size;
            this.WindowState = FormWindowState.Maximized;
            this.Controls.Add(this.xnaControl);
            this.MinimumSize = new System.Drawing.Size(size.Width + 16, size.Height + 39);
            this.Name        = "MainForm";

            this.ResumeLayout(false);

            // To handle Alt-Enter for full screen toggle.
            this.KeyPreview = true;
            this.KeyDown   += new KeyEventHandler(MainForm_KeyDown);

            //this.ResizeRedraw = false;
            this.ResizeEnd += new System.EventHandler(ResizeEndHandler);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the control.
        /// </summary>
        protected override void Initialize()
        {
            Instance = this;
            Device   = GraphicsDevice;

            // Create app's content manager.
            ContentManager = new ContentManager(Services, "");

            // Grab Loading texture and Microsoft logo so we can not have a blank screen.
            Texture2D loadingTexture = ContentManager.Load <Texture2D>(@"Content\Textures\Loading");

            Device.Clear(Color.Black);
            Vector2     screenSize     = new Vector2(Device.Viewport.Width, Device.Viewport.Height);
            Vector2     backgroundSize = new Vector2(loadingTexture.Width, loadingTexture.Height);
            SpriteBatch batch          = new SpriteBatch(Device);

            batch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
            {
                Vector2 position = (screenSize - backgroundSize) / 2.0f;
                // Clamp to pixels.
                position.X = (int)position.X;
                position.Y = (int)position.Y;
                batch.Draw(loadingTexture, position, Color.White);
            }
            batch.End();

            // Set up KoiLibrary
            // CLICK_ONCE allows the framework to change from having the
            // content in a seperate content project vs having it tied
            // into the project as Content (which is what is needed in
            // order to get ClickOnce deployment to work).
            // For development, this should be off.  Turn it one when
            // it's time to do deployable builds.
            // AppContent is the folder where content should live
            // for ClickOnce builds.  Files added to this folder should
            // actually be copied into it.  No clue why links don't work.
            // Mark files as Content and Copy If Newer (or always)
            // TODO Figure this out, or at least automate it.

            font = ContentManager.Load <SpriteFont>(@"Content\Fonts\SegoeUI20");

            // Create main.
            main = new Main();

            // Hook the idle event to constantly redraw our animation.
            Application.Idle += delegate { Invalidate(); };

            // Be sure to kill off worker threads when leaving.
            //Application.ApplicationExit += delegate { TerrainMap.KillWorkerThread(); };
            Application.ApplicationExit += delegate
            {
                if (BokuGame.bokuGame != null)
                {
                    BokuGame.bokuGame.EndRun();
                }
                Boku.Common.MouseInput.StopMouseWorkerThread();
            };

            // TODO (****) ??? Add drag and drop support.
            // this.AllowDrop = true;

            // this.DragEnter += new DragEventHandler(XNAControl_DragEnter);
            // this.DragDrop += new DragEventHandler(XNAControl_DragDrop);

            // Initialize BokuGame.
            BokuGame game = new BokuGame();

            BokuGame.bokuGame.Initialize();
            BokuGame.bokuGame.LoadContent();
            BokuGame.bokuGame.BeginRun();

            bokuGameInitialized = true;
        }   // end of Initialize()