欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

mainform.cs

功能:基于windows mobile 的地图查看器。使用vs2005开发
CS
第 1 页 / 共 3 页
字号:
			{
				boundary.RenderVertex(device, bCanadian);
			}
			if (Settings.BoundNor == true)
			{
				boundary.RenderVertex(device, bNorwegian);
			}
			if (Settings.BoundSwe == true)
			{
				boundary.RenderVertex(device, bSwedish);
			}
			if (Settings.BoundUs == true)
			{
				boundary.RenderVertex(device, bUsState);
			}

			if (Settings.Placename == true)
			{
				placename.RenderVertex(device, camera);
			}

			if (Settings.Landmark == true)
			{
				landmark.RenderVertex(device, camera, landmarkSize);
			}

			if (Settings.Flag == true)
			{
				flag.RenderVertex(device, camera, flagSize);
			}

			if (Settings.LatLonLines == true)
			{
				if (camera.Altitude >= 4500000)
				{
					latLon.RenderLatLonLines(device, alLatLon10);
				}
				else if(camera.Altitude < 4500000 && camera.Altitude >= 2500000)
				{
					latLon.RenderLatLonLines(device, alLatLon5);
				}
				else if (camera.Altitude < 2500000 && camera.Altitude >= 500000)
				{
					latLon.RenderLatLonLines(device, alLatLon2);
				}
				else
				{
					//world.RenderLatLonLines(device, alLatLon1);
					latLon.RenderLatLonLines(device, alLatLon2);
				}
			}

			if (Settings.Equator == true)
			{
				tropics.RenderVertex(device, camera);
			}

			if (Settings.Crosshairs == true)
			{
				//crosshairs.Render(graphics); //GDI+
				crosshairs.RenderVertex(device);
				//crosshairs.RenderVertex(device, Color.White);
			}

			if (Settings.Positions == true)
			{
				position.Render();
			}

			if (Settings.FramesPerSecond == true)
			{
				fpsTimer.Render();
			}

			if (Settings.Diagnostics == true)
			{
				diagnostic.Render();
			}

            //End the scene
            device.EndScene();
            device.Present();

			fpsTimer.StopFrame();
        }

        /// <summary>
        /// Called whenever the window needs to be repainted
        /// </summary>
        /// <param name="e">Ignored</param>
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
			try
			{
				//TODO is this  necessary
				if (splashForm != null)
					return;

				// Render the mesh to the screen
				Render();
			}
			catch (Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.ToString());
				if (Settings.RenderException == true)
				{
					throw;
				}
			}
            
            // Invalidating the window will cause it to be redrawn in
            // the future
            Invalidate();
        }

        /// <summary>
        /// Called whenever the background of the window needs to be repainted
        /// </summary>
        /// <param name="e">Ignored</param>
        protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs e)
        {
            // Doing nothing ensures the background will never overdraw
            // the previous rendering
        }

		/// <summary>
		/// Called whenever the window is being resized
		/// </summary>
		/// <param name="e">Ignored</param>
		protected override void OnResize(System.EventArgs e)
		{
			if (Screen.PrimaryScreen.Bounds.Height < Screen.PrimaryScreen.Bounds.Width)
			{
				MessageBox.Show("this will not work in Landscape mode");
			}
			else
			{
				base.OnResize(e);
			}
		}

		protected override void OnClosing(CancelEventArgs e)
		{
			DialogResult dr = MessageBox.Show("are you sure", "closing", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
			if (dr == DialogResult.No)
			{
				e.Cancel = true;
				return;
			}
		}

		protected override void OnClosed(EventArgs e)
		{
			DisposeFlags();
			DisposeBoundaries(Settings.BoundaryType.Country);
			DisposeBoundaries(Settings.BoundaryType.Canadian);
			DisposeBoundaries(Settings.BoundaryType.Norwegian);
			DisposeBoundaries(Settings.BoundaryType.Swedish);
			DisposeBoundaries(Settings.BoundaryType.UsState);
			DisposeLandmarks();
			DisposePlacenames();

			axis.Dispose();
			crosshairs.Dispose();
			diagnostic.Dispose();
			latLon.Dispose(alLatLon10);
			latLon.Dispose(alLatLon5);
			latLon.Dispose(alLatLon2);
			position.Dispose();
			tropics.Dispose();
			world.Dispose();
			//camera
			if (device != null)
			{
				device.Dispose();
				device = null;
			}
		}

		InputMode inputMode = InputMode.SpinWorld;
		private enum InputMode
		{
			SpinWorld,
			ZoomRoll,
			YawPitch,
		}

		private void NextInputMode()
		{
			if(inputMode == InputMode.SpinWorld)
			{
				inputMode = InputMode.ZoomRoll;
				miControls.Text = "Zoom/Roll World";
			}
			else if (inputMode == InputMode.ZoomRoll)
			{
				inputMode = InputMode.YawPitch;
				miControls.Text = "Tilt Camera";
			}
			else if (inputMode == InputMode.YawPitch)
			{
				inputMode = InputMode.SpinWorld;
				miControls.Text = "Spin World";
			}
		}

		private void miControls_Click(object sender, EventArgs e)
		{
			NextInputMode();
		}

		protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
		{
			// if Escape was pressed then shutdown
			if ((int)e.KeyChar == (int)System.Windows.Forms.Keys.Escape)
				this.Close();
		}

		Point lastMousePosition;
		protected override void OnMouseUp(MouseEventArgs e)
		{
			lastMousePosition = new Point(e.X, e.Y);

			if (e.Button == MouseButtons.Left)
			{
				Angle targetLatitude;
				Angle targetLongitude;
				camera.PickingRayIntersection(this.lastMousePosition.X, this.lastMousePosition.Y, out targetLatitude, out targetLongitude);
				if (!Angle.IsNaN(targetLatitude))
				{
					//mod
					//Angle modAngle = Angle.FromDegrees(180);
					//camera.PointGoto(targetLatitude, targetLongitude + modAngle);
					camera.PointGoto(targetLatitude, targetLongitude);
				}
			}

			this.Invalidate();
			base.OnMouseUp(e);
		}

		protected override void OnKeyDown(KeyEventArgs e)
		{
			switch ((HardwareKeys)e.KeyCode)
			{
				case HardwareKeys.ApplicationKey1: //193
					//NextInputMode();
					break;
				case HardwareKeys.ApplicationKey4: //196
					break;
				default:
					break;
			}

			switch (inputMode)
			{
				case InputMode.SpinWorld:
					switch (e.KeyCode)
					{
						case Keys.Left:
							camera.Longitude += 5f;
							break;
						case Keys.Right:
							camera.Longitude -= 5f;
							break;
						case Keys.Up:
							camera.Latitude -= 2.5f;
							break;
						case Keys.Down:
							camera.Latitude += 2.5f;
							break;
						default:
							break;
					}
					break;
				case InputMode.ZoomRoll:
					switch (e.KeyCode)
					{
						case Keys.Left:
							camera.Roll += .1f;
							break;
						case Keys.Right:
							camera.Roll -= .1f;
							break;
						case Keys.Up:
							camera.Distance *= .97f;
							break;
						case Keys.Down:
							camera.Distance *= 1.03f;
							break;
						default:
							break;
					}
					break;
				case InputMode.YawPitch:
					switch (e.KeyCode)
					{
						case Keys.Left:
							camera.Yaw -= .05f;
							break;
						case Keys.Right:
							camera.Yaw += .05f;
							break;
						case Keys.Up:
							camera.Pitch -= .05f;
							break;
						case Keys.Down:
							camera.Pitch += .05f;
							break;
						default:
							break;
					}
					break;
				default:
					break;
			}
			base.OnKeyDown(e);
		}

		private void miFileGps_Click(object sender, EventArgs e)
		{
			GpsForm gpsForm = new GpsForm(this.gpsReader);
			gpsForm.ShowDialog();
		}

		private void gpsReader_OnGPSMessageLatLon(object sender, GPSEventArgs arg)
		{
			if (arg.MessageType == "GPGGA")
			{
				camera.Latitude = (float)arg.Lat;
				camera.Longitude = (float)arg.Lon;
			}
		}

		private void miFileFindPlace_Click(object sender, EventArgs e)
		{
			if (placename.PlaceListCount == 0)
			{
				MessageBox.Show("places not loaded");
				return;
			}
			PlaceForm pf = new PlaceForm();
			pf.Init(camera, placename);
			pf.ShowDialog();
		}

		/*
		private int screenCapCount = 0;
		private string GetScreenCapName(string dir)
		{
			string name = dir + "printScreen" + screenCapCount.ToString() + ".bmp";
			while (File.Exists(name) == true)
			{
				screenCapCount = screenCapCount + 1;
				name = dir + "printScreen" + screenCapCount.ToString() + ".bmp";
			}
			return name;
		}
		 */

		private void miFileScreenshot_Click(object sender, EventArgs e)
		{
			try
			{
				SaveFileDialog dialog = new SaveFileDialog();
				string dir = Path.GetDirectoryName(dialog.FileName) + @"\";
				dialog.FileName = "ww" + DateTime.Now.Ticks.ToString() + ".bmp";  //"printScreen.bmp";
				dialog.Filter = "BMP (*.bmp)|*.bmp";
				if (dialog.ShowDialog() == DialogResult.OK)
				{
					// Note that for this to work, you have to have SwapEffect.Flip or SwapEffect.
					//Copy set in the PresentationParameters set at device creation. 
					Surface backBuffer = device.GetBackBuffer(0, BackBufferType.Mono);
					Rectangle rect = new Rectangle(device.Viewport.X, device.Viewport.Y,
					   device.Viewport.Width, device.Viewport.Height);
					Surface imageSurface = device.CreateImageSurface(device.Viewport.Width, device.Viewport.Height, backBuffer.Description.Format);
					Point destinationPoint = new Point(0, 0); //TODO?
					device.CopyRects(backBuffer, rect, imageSurface, destinationPoint);
					int pitch;
					GraphicsStream gs = imageSurface.LockRectangle(rect, LockFlags.ReadOnly, out pitch);
					Bitmap b = new Bitmap(device.Viewport.Width, device.Viewport.Height, PixelFormat.Format16bppRgb565);
					BitmapData bd = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.WriteOnly, PixelFormat.Format16bppRgb565);
					byte[] baGs = new byte[gs.Length];
					gs.Read(baGs, 0, baGs.Length);
					gs.Close();
					gs.Dispose();
					IntPtr ptr = bd.Scan0;
					int bytes = b.Width * b.Height * 2; // 3;
					System.Runtime.InteropServices.Marshal.Copy(baGs, 0, ptr, bytes);
					b.UnlockBits(bd);
					b.Save(dialog.FileName, ImageFormat.Bmp);
					b.Dispose();
					imageSurface.UnlockRectangle();
					imageSurface.Dispose();
					backBuffer.Dispose();
				}
			}
			catch (Exception ex)
			{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -