Exemplo n.º 1
0
		public Control()
		{
			this.DesignMode = this.DesignMode;
			this.SuspendLayout();
			// 
			// backend
			// 
			if (!this.DesignMode)
			{
				this.backend = Backend.Control.Create();
				this.backend.Initialized += () => this.Initialized.Call();
				#region Pointer Events Hookup
				this.backend.MouseClick += (sender, arguments) =>
				{
					Error.Log.Call((Action<System.Windows.Forms.MouseEventArgs>)(e =>
					{
						Geometry2D.Single.Point position = new Geometry2D.Single.Point(e.X, e.Y);
						switch (e.Button)
						{
							case System.Windows.Forms.MouseButtons.Left:
								this.PointerLeftClicked(position);
								break;
							case System.Windows.Forms.MouseButtons.Middle:
								this.PointerMiddleClicked(position);
								break;
							case System.Windows.Forms.MouseButtons.Right:
								this.PointerRightClicked(position);
								break;
						}
					}), arguments);
				};
				this.backend.MouseMove += (sender, arguments) =>
				{
					Error.Log.Call((Action<System.Windows.Forms.MouseEventArgs>)(e =>
					{
						Geometry2D.Single.Point currentPosition = new Geometry2D.Single.Point(e.X, e.Y);
						this.PointerMoved((Geometry2D.Single.Size)(currentPosition - this.lastPointerPosition), currentPosition, e.Button == System.Windows.Forms.MouseButtons.Left, e.Button == System.Windows.Forms.MouseButtons.Middle, e.Button == System.Windows.Forms.MouseButtons.Right);
						this.lastPointerPosition = currentPosition;
					}), arguments);
				};
				this.backend.MouseWheel += (sender, arguments) => Error.Log.Call((Action<System.Windows.Forms.MouseEventArgs>)(e => this.PointerWheelChanged(e.Delta / 120f, new Geometry2D.Single.Point(e.X, e.Y))), arguments);
				#endregion
				this.backend.Draw += renderer =>
				{
					using (Surface surface = new Surface(renderer))
					{
						surface.Use();
						surface.Transform = Geometry2D.Single.Transform.CreateTranslation(surface.Size / 2);
						this.Draw(surface);
						surface.Unuse();
					}
				};
				this.backend.AutoSize = true;
				this.backend.BackColor = System.Drawing.Color.Transparent;
				this.backend.Dock = System.Windows.Forms.DockStyle.Fill;
				this.backend.Location = new System.Drawing.Point(0, 0);
				this.backend.Name = "backend";
				this.backend.Size = new System.Drawing.Size(150, 150);
				this.backend.TabIndex = 0;
				this.backend.VSync = false;
				this.Controls.Add(this.backend);
			}
			// 
			// Control
			// 
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Name = "Viewer";
			this.ResumeLayout(false);
			this.PerformLayout();
		}
Exemplo n.º 2
0
		protected override void Dispose(bool disposing)
		{
			if (this.backend.NotNull())
			{
				this.backend.Dispose();
				this.backend = null;
			}
		}