private void UdpListen() { try { IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, 0); while (true) { byte[] bytes = udpListener.Receive(ref endPoint); MemoryStream memoryStream = new MemoryStream(bytes); Packet packet = new BinaryFormatter().Deserialize(memoryStream) as Packet; foreach (KeyValuePair <int, Client> c in clients) { if (endPoint.ToString() != c.Value.endPoint.ToString()) { switch (packet.packetType) { case PacketType.PAINT: PaintPacket paintPacket = (PaintPacket)packet; UdpSend(c.Value, paintPacket); break; } } } } } catch (SocketException e) { Console.WriteLine("Server UDP Read Method Exception: " + e.Message); } }
protected override void OnPaint(ref PaintPacket packet) { PaintStruct ps; var hdc = this.BeginPaint(out ps); User32Methods.FillRect(hdc, ref ps.PaintRect, Gdi32Helpers.GetStockObject(StockObject.WHITE_BRUSH)); this.EndPaint(ref ps); base.OnPaint(ref packet); }
protected override void OnPaint(ref PaintPacket packet) { PaintStruct ps; var hdc = this.BeginPaint(out ps); if (!this.m_isInit) { this.m_isInit = true; this.Init(); } this.OnGlPaint(ref ps); this.EndPaint(ref ps); }
protected override void OnPaint(ref PaintPacket packet) { Dx.EnsureInitialized(); try { OnDxPaint(Dx); Dx.D3D.SwapChain.Present(1, 0); } catch (SharpDXException ex) { if (!Dx.PerformResetOnException(ex)) { throw; } } }
protected override void OnPaint(ref PaintPacket packet) { var rand = new Random(); var size = this.GetClientSize(); var w = size.Width; var h = size.Height; this.m_dx.EnsureInitialized(); try { var context = this.m_dx.D2D.Context; context.BeginDraw(); context.Clear(new RawColor4(0, 0, 0, 0f)); var b = new SolidColorBrush(context, new RawColor4(rand.NextFloat(), rand.NextFloat(), rand.NextFloat(), 0.4f)); context.FillRectangle(new RawRectangleF(200, 200, 500, 700), b); for (var i = 0; i < 10; i++) { b.Color = new RawColor4(rand.NextFloat(), rand.NextFloat(), rand.NextFloat(), 0.4f); context.FillEllipse( new Ellipse(new RawVector2(rand.NextFloat(0, w), rand.NextFloat(0, h)), rand.NextFloat(0, w), rand.Next(0, h)), b); context.FillRectangle( new RawRectangleF(rand.NextFloat(0, w), rand.NextFloat(0, h), rand.NextFloat(0, w), rand.NextFloat(0, h)), b); } b.Dispose(); context.EndDraw(); this.m_dx.D3D.SwapChain.Present(1, 0); this.Validate(); } catch (SharpDXException ex) { if (!this.m_dx.PerformResetOnException(ex)) { throw; } } }
public static void ProcessPaint(ref PaintPacket packet, NativePixelBuffer pixelBuffer, Action <SKSurface> handler) { var hwnd = packet.Hwnd; Rectangle clientRect; User32Methods.GetClientRect(hwnd, out clientRect); var size = clientRect.Size; pixelBuffer.EnsureSize(size.Width, size.Height); PaintStruct ps; var hdc = User32Methods.BeginPaint(hwnd, out ps); var skPainted = false; try { using (var surface = SKSurface.Create( size.Width, size.Height, SKColorType.Bgra8888, SKAlphaType.Premul, pixelBuffer.Handle, pixelBuffer.Stride)) { if (surface != null) { handler(surface); skPainted = true; } } } finally { if (skPainted) { Gdi32Helpers.SetRgbBitsToDevice(hdc, size.Width, size.Height, pixelBuffer.Handle); } User32Methods.EndPaint(hwnd, ref ps); } }
private void UdpProcessServerResponse() { try { IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, 0); while (true) { byte[] bytes = udpClient.Receive(ref endPoint); MemoryStream memoryStream = new MemoryStream(bytes); Packet packet = formatter.Deserialize(memoryStream) as Packet; switch (packet.packetType) { case PacketType.PAINT: PaintPacket paintPacket = (PaintPacket)packet; paintForm.UpdateCanvas(paintPacket.xPos, paintPacket.yPos, paintPacket.mouseLocation); break; } } } catch (SocketException exception) { Console.WriteLine("Client UDP Read Method Exception: " + exception.Message); } }
protected override void OnPaint(ref PaintPacket packet) { SkiaPainter.ProcessPaint(ref packet, this.m_pixelBuffer, this.OnSkiaPaint); }
public static unsafe void ProcessPaint(ref PaintPacket packet, NativePixelBuffer pixelBuffer, Action <SKSurface> handler) { var hwnd = packet.Hwnd; Rectangle clientRect; User32Methods.GetClientRect(hwnd, out clientRect); var size = clientRect.Size; pixelBuffer.EnsureSize(size.Width, size.Height); PaintStruct ps; var hdc = User32Methods.BeginPaint(hwnd, out ps); var skPainted = false; try { using (var surface = SKSurface.Create( size.Width, size.Height, SKColorType.Bgra8888, SKAlphaType.Premul, pixelBuffer.Handle, pixelBuffer.Stride)) { if (surface != null) { handler(surface); /* * foreach (var VARIABLE in Enumerable.Range(0, pixelBuffer.Stride * size.Height / 4)) * { * var value = Marshal.ReadInt32(pixelBuffer.Handle, VARIABLE*4); * // ABGR >> ARGB * unchecked * { * value = ((value & (int)0xff000000) >> 0) + * ((value & 0xff0000) >> 16 )+ * ((value & 0xff00) << 0) + * ((value & 0xff) << 16); * } * * Marshal.WriteInt32(pixelBuffer.Handle, VARIABLE * 4, value); * }*/ var max = pixelBuffer.Stride * size.Height / 4; int *arr = (int *)pixelBuffer.Handle.ToPointer(); unchecked { var a = 0; while (a < max) {/* * arr = ((*arr & (int) 0xff000000) >> 0) + * ((*arr & 0xff0000) >> 16) + * ((*arr & 0xff00) << 0) + * ((*arr & 0xff) << 16); * arr++;*/ a++; } } skPainted = true; } } } finally { if (skPainted) { Gdi32Helpers.SetRgbBitsToDevice(hdc, size.Width, size.Height, pixelBuffer.Handle); } User32Methods.EndPaint(hwnd, ref ps); } }
protected override void OnPaint(ref PaintPacket packet) { _renderEvent?.Publish(new RenderEventData()); Validate(); }
protected override void OnPaint(ref PaintPacket packet) { DxPainter.HandlePaint(this, this.Dx, this.OnDxPaint); }