public MainForm() { InitializeComponent(); ResizeRedraw = true; DoubleBuffered = true; // Add SKCanvas skcGame = new SKControl() { Top = this.DisplayRectangle.Top + this.menuStrip1.Height, Left = this.DisplayRectangle.Left, Width = this.DisplayRectangle.Width, Height = this.DisplayRectangle.Height - this.menuStrip1.Height }; skcGame.Click += Skc_Click; skcGame.PaintSurface += Skc_PaintSurface; this.Controls.Add(skcGame); // Start basic game //StartNewGame(); // Set up timer timer1.Interval = 32; timer1.Tick += timer1_Tick; timer1.Start(); }
public EmulatorUI() { InitializeComponent(); var menuStrip = new MenuStrip(); var fileMenuItem = new ToolStripMenuItem("File"); var openRomItem = new ToolStripMenuItem("Open"); openRomItem.Click += OpenRomSelectionDialog; fileMenuItem.DropDownItems.Add(openRomItem); menuStrip.Items.Add(fileMenuItem); Controls.Add(menuStrip); _menuHeight = menuStrip.Size.Height; _gameScreen = new SKControl() { Location = new Point(0, menuStrip.ClientRectangle.Bottom), Size = GetGameScreen() }; _gameScreen.PaintSurface += OnPaintSurface; _gameScreen.KeyDown += EmulatorUI_KeyDown; _gameScreen.KeyUp += EmulatorUI_KeyUp; _gameScreen.PreviewKeyDown += EmulatorUI_PreviewKeyDown; Controls.Add(_gameScreen); }
public MazeGenerator() { Text = "Maze Generator"; AutoScaleMode = AutoScaleMode.Font; StartPosition = FormStartPosition.CenterScreen; ClientSize = new Size(1547, 897); var splitContainer = new SplitContainer() { FixedPanel = FixedPanel.Panel1, SplitterDistance = 600, Dock = DockStyle.Fill, IsSplitterFixed = true }; var skiaView = new SKControl() { Dock = DockStyle.Fill }; //skiaView.MouseDown += DoMouseClick; //skiaView.MouseMove += DoMouseClick; //skiaView.Resize += (s, e) => _game.SetSize(skiaView.Width, skiaView.Height); skiaView.PaintSurface += (s, e) => { var grid = new Grid(40, 40); new BinaryTreeAlgorithm(grid).Run(); new GridRenderer(grid).Render(e.Surface); }; //splitContainer.Panel1.Controls.Add(buttonPanel); splitContainer.Panel2.Controls.Add(skiaView); splitContainer.Panel2.Padding = new Padding(5); Controls.Add(splitContainer); }
/// <summary> /// Default constructor. /// </summary> public Surface() { InitializeComponent(); SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); UpdateStyles(); // Create the control. _skcontrol = new SKControl(); Controls.Add(_skcontrol); }
void Init() { var skcontrol = new SKControl(); skcontrol.PaintSurfaceAction = ((surface) => Tests.PaintStuff(surface)); Title = "SKControl Demo (CPU Renderer)"; ClientSize = new Drawing.Size(500, 500); Content = skcontrol; }
public WindowsDesktopEvents( SKControl skiaControl, LoplaGuiEventProcessor eventsConsumer) { _eventsConsumer = eventsConsumer; skiaControl.Click += C_Click; skiaControl.KeyUp += C_KeyUp; skiaControl.KeyDown += C_KeyDown; skiaControl.SizeChanged += C_SizeChanged; skiaControl.PaintSurface += C_PaintSurface; }
public WhiteBoard(MainForm parent, int w, int h, SKControl controller, ToolStripStatusLabel status, ToolStripStatusLabel mouse) { BoardSize = new SKSize((float)w, (float)h); StatusLabel = status; MouseLabel = mouse; mainControl = controller; mainControl.PaintSurface += PaintSurface; mainControl.MouseMove += MouseLocation; mainControl.MouseLeave += MouseLeave; mainControl.MouseDown += MouseDown; mainControl.MouseUp += MouseUp; mainControl.MouseDoubleClick += mouseDoubleClick; Parent = parent; BoardBorder = new SKPaint { Style = SKPaintStyle.Stroke, Color = SKColors.Black, StrokeWidth = 2 }; gMoves = new SKPaint { Style = SKPaintStyle.Stroke, Color = SKColors.Red, StrokeWidth = 1.0f }; gLines = new SKPaint { Style = SKPaintStyle.Stroke, Color = SKColors.DarkGray, StrokeWidth = 1.5f }; gLinesSelected = new SKPaint { Style = SKPaintStyle.Stroke, Color = SKColors.Black, StrokeWidth = 1.5f }; AllDrawings = new List <GcodeDrawing>(); headLocation = new SKPoint(0, 0); }
private void Form1_Load(object sender, EventArgs e) { const float ptSize = 80; const string text = "𝑑"; const int windowWidth = 350; const int windowHeight = 300; var t = new OpenFontReader().Read(GetType().Assembly.GetManifestResourceStream(Array.Find(GetType().Assembly.GetManifestResourceNames(), n => n.EndsWith(".otf")))); var g = t.Lookup(char.ConvertToUtf32(text, 0)); Size = new Size(windowWidth, windowHeight); Text = "Typography -> SkiaSharp"; var view = new SKControl(); view.PaintSurface += (_, E) => { var tx = new SkiaTx(); var c = E.Surface.Canvas; c.Scale(1, -1); c.Translate(0, -Height / 4); tx.Read(g._ownerCffFont, g._cff1GlyphData, t.CalculateScaleToPixelFromPointSize(ptSize)); c.DrawPath(tx.Path, new SKPaint { Color = SKColors.Black, Style = SKPaintStyle.Stroke }); }; view.Dock = DockStyle.Fill; Controls.Add(view); var gdi = new Form { Text = "Typography -> Gdi+", Size = new Size(windowWidth, windowHeight) }; gdi.Paint += (_, E) => { var tx = new GdiTx(); var G = E.Graphics; G.ScaleTransform(1, -1); G.TranslateTransform(0, -Height / 4); tx.Read(g._ownerCffFont, g._cff1GlyphData, t.CalculateScaleToPixelFromPointSize(ptSize)); G.DrawPath(Pens.Black, tx.Path); }; gdi.Show(); }
public void AttachEvents(Panel skWorkspaceParent, Panel propGridParent) { // this.skWorkspace = new SKControl(); this.skWorkspace.Dock = DockStyle.Fill; this.skWorkspace.PaintSurface += OnPaintSurface; this.skWorkspace.MouseDown += MouseEvents; skWorkspaceParent.Controls.Add(this.skWorkspace); // this.propGrid = new PropertyGrid(); this.propGrid.Dock = DockStyle.Fill; this.propGrid.PropertyValueChanged += (s, e) => this.skWorkspace.Invalidate(); this.propGrid.PropertySort = PropertySort.Categorized; this.propGrid.ToolbarVisible = false; this.propGrid.LineColor = Color.FromArgb(230, 230, 230); propGridParent.Controls.Add(this.propGrid); }
private void DrawForm_Load(object sender, System.EventArgs e) { labelRecvTip.Text = string.Empty; checkBoxDraw.Checked = true; DrawForm_SizeChanged(this, e); //skiaView _skiaView = new SKControl(); _skiaView.Dock = DockStyle.Fill; _skiaView.Location = new Point(0, 0); //_skiaView.Margin = new Padding(48, 24, 48, 24); _skiaView.Name = "skiaView"; //_skiaView.Size = new Size(784, 561); _skiaView.TabIndex = 0; _skiaView.Text = "skControl1"; _skiaView.PaintSurface += skiaView_PaintSurface; panelDrawArea.Controls.Add(_skiaView); }
public MainForm(IGame game) { _game = game; this.Text = "Trains.NET"; this.AutoScaleMode = AutoScaleMode.Font; this.StartPosition = FormStartPosition.Manual; this.Location = new Point(1086, 559); this.ClientSize = new System.Drawing.Size(1547, 897); var splitContainer = new SplitContainer() { FixedPanel = FixedPanel.Panel1, SplitterDistance = 400, Dock = DockStyle.Fill, IsSplitterFixed = true }; var buttonPanel = new Panel() { Dock = DockStyle.Fill, Padding = new Padding(5) }; foreach (Tool tool in ((Tool[])Enum.GetValues(typeof(Tool))).Reverse()) { buttonPanel.Controls.Add(CreateButton(tool)); } var skiaView = new SKControl() { Dock = DockStyle.Fill }; skiaView.MouseDown += DoMouseClick; skiaView.MouseMove += DoMouseClick; skiaView.Resize += (s, e) => _game.SetSize(skiaView.Width, skiaView.Height); skiaView.PaintSurface += (s, e) => _game.Render(e.Surface); splitContainer.Panel1.Controls.Add(buttonPanel); splitContainer.Panel2.Controls.Add(skiaView); splitContainer.Panel2.Padding = new Padding(5); this.Controls.Add(splitContainer); void DoMouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.None) { return; } if ((e.Button & MouseButtons.Middle) == MouseButtons.Middle) { return; } bool isRightMouseButton = (e.Button & MouseButtons.Right) == MouseButtons.Right; _game.OnMouseDown(e.X, e.Y, isRightMouseButton); skiaView.Refresh(); } RadioButton CreateButton(Tool tool) { var button = new RadioButton() { Text = tool.ToString(), Dock = DockStyle.Top, Height = 50, Appearance = Appearance.Button, TextAlign = ContentAlignment.MiddleCenter, Checked = tool == (Tool)0 }; button.Click += (s, e) => _game.CurrentTool = tool; return(button); } }
public MainForm(IGame game, IEnumerable <IBoardRenderer> renderers, ITrackParameters parameters) { _game = game; _parameters = parameters; this.Text = "Trains.NET"; this.AutoScaleMode = AutoScaleMode.Font; this.StartPosition = FormStartPosition.Manual; this.Location = new Point(1086, 559); this.ClientSize = new Size(1547, 897); var splitContainer = new SplitContainer() { FixedPanel = FixedPanel.Panel1, SplitterDistance = 400, Dock = DockStyle.Fill, IsSplitterFixed = true }; var buttonPanel = new Panel() { Dock = DockStyle.Top, Padding = new Padding(5), AutoSize = true }; var rendererPanel = new Panel() { Dock = DockStyle.Top, Padding = new Padding(5), AutoSize = true }; foreach (Tool tool in ((Tool[])Enum.GetValues(typeof(Tool))).Reverse()) { buttonPanel.Controls.Add(CreateButton(tool)); } var button = new CheckBox { Text = "Configure", Height = 30, TextAlign = ContentAlignment.MiddleCenter, Dock = DockStyle.Top, Appearance = Appearance.Button }; buttonPanel.Controls.Add(button); button.CheckedChanged += (s, e) => { if (_debugForm == null) { _debugForm = CreateDebugForm(); } if (button.Checked) { _debugForm.Show(); } else { _debugForm.Hide(); } }; _skiaView = new SKControl() { Dock = DockStyle.Fill }; _skiaView.MouseDown += DoMouseClick; _skiaView.MouseMove += DoMouseClick; _skiaView.Resize += (s, e) => _game.SetSize(_skiaView.Width, _skiaView.Height); _skiaView.PaintSurface += (s, e) => _game.Render(e.Surface); foreach (IBoardRenderer renderer in renderers) { rendererPanel.Controls.Add(CreateRendererCheckbox(renderer)); } splitContainer.Panel1.Controls.Add(rendererPanel); splitContainer.Panel1.Controls.Add(buttonPanel); splitContainer.Panel2.Controls.Add(_skiaView); splitContainer.Panel2.Padding = new Padding(5); this.Controls.Add(splitContainer); void DoMouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.None) { return; } if ((e.Button & MouseButtons.Middle) == MouseButtons.Middle) { return; } bool isRightMouseButton = (e.Button & MouseButtons.Right) == MouseButtons.Right; _game.OnMouseDown(e.X, e.Y, isRightMouseButton); _skiaView.Refresh(); } RadioButton CreateButton(Tool tool) { var button = new RadioButton() { Text = tool.ToString(), Dock = DockStyle.Top, Height = 50, Appearance = Appearance.Button, TextAlign = ContentAlignment.MiddleCenter, Checked = tool == (Tool)0 }; button.Click += (s, e) => _game.CurrentTool = tool; return(button); } Control CreateRendererCheckbox(IBoardRenderer renderer) { var checkbox = new CheckBox { Text = renderer.Name, Dock = DockStyle.Top, Height = 50, Appearance = Appearance.Button, TextAlign = ContentAlignment.MiddleCenter, Checked = renderer.Enabled }; checkbox.CheckedChanged += (s, e) => { renderer.Enabled = checkbox.Checked; _skiaView.Refresh(); }; return(checkbox); } }
public LoplaRequests(SKControl skiaControl) { _skiaControl = skiaControl; }
public MainForm(IGame game, IPixelMapper pixelMapper, IEnumerable <ITool> tools, IEnumerable <ILayerRenderer> renderers, ITrackParameters parameters) { _game = game; _parameters = parameters; _currentTool = tools.First(); this.Text = "Trains.NET"; this.AutoScaleMode = AutoScaleMode.Font; this.StartPosition = FormStartPosition.Manual; this.Location = new Point(1086, 559); this.ClientSize = new Size(1547, 897); var splitContainer = new SplitContainer() { FixedPanel = FixedPanel.Panel1, SplitterDistance = 400, Dock = DockStyle.Fill, IsSplitterFixed = true }; var buttonPanel = new Panel() { Dock = DockStyle.Top, Padding = new Padding(5), AutoSize = true }; var rendererPanel = new Panel() { Dock = DockStyle.Top, Padding = new Padding(5), AutoSize = true }; foreach (ITool tool in tools) { buttonPanel.Controls.Add(CreateButton(tool)); } var button = new CheckBox { Text = "Configure", Height = 30, TextAlign = ContentAlignment.MiddleCenter, Dock = DockStyle.Top, Appearance = Appearance.Button }; buttonPanel.Controls.Add(button); button.CheckedChanged += (s, e) => { if (_debugForm == null) { _debugForm = CreateDebugForm(); } if (button.Checked) { _debugForm.Location = new Point(this.Left - _debugForm.Width, this.Top); _debugForm.Show(); } else { _debugForm.Hide(); } }; var skiaView = new SKControl() { Dock = DockStyle.Fill }; skiaView.MouseDown += DoMouseClick; skiaView.MouseMove += DoMouseClick; skiaView.Resize += (s, e) => _game.SetSize(skiaView.Width, skiaView.Height); skiaView.PaintSurface += (s, e) => _game.Render(e.Surface.Canvas); foreach (ILayerRenderer renderer in renderers) { rendererPanel.Controls.Add(CreateRendererCheckbox(renderer)); } splitContainer.Panel1.Controls.Add(rendererPanel); splitContainer.Panel1.Controls.Add(buttonPanel); splitContainer.Panel2.Controls.Add(skiaView); splitContainer.Panel2.Padding = new Padding(5); _timer = new Timer(); _timer.Tick += (s, e) => skiaView.Refresh(); _timer.Interval = 16; _timer.Start(); this.Controls.Add(splitContainer); void DoMouseClick(object sender, MouseEventArgs e) { if ((e.Button & MouseButtons.Left) == MouseButtons.Left) { (int column, int row) = pixelMapper.PixelsToCoords(e.X, e.Y); _currentTool.Execute(column, row); } } RadioButton CreateButton(ITool tool) { var button = new RadioButton() { Text = tool.Name, Dock = DockStyle.Top, Height = 50, Appearance = Appearance.Button, TextAlign = ContentAlignment.MiddleCenter, Checked = _currentTool == tool }; button.Click += (s, e) => _currentTool = tool; return(button); } Control CreateRendererCheckbox(ILayerRenderer renderer) { var checkbox = new CheckBox { Text = renderer.Name, Dock = DockStyle.Top, Height = 50, Appearance = Appearance.Button, TextAlign = ContentAlignment.MiddleCenter, Checked = renderer.Enabled }; checkbox.CheckedChanged += (s, e) => { renderer.Enabled = checkbox.Checked; }; return(checkbox); } }