102 lines
3.4 KiB
C#
102 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Specialized;
|
|
using System.Drawing;
|
|
using System.Net;
|
|
using System.Windows.Forms;
|
|
|
|
namespace networkPaint
|
|
{
|
|
public partial class MainForm : Form
|
|
{
|
|
Color color;
|
|
Random r = new Random();
|
|
WebClient client = new WebClient();
|
|
Bitmap bitmap;
|
|
Graphics graphics;
|
|
string url = "http://kawaiizenbo.me/toys/networkpaint/";
|
|
public MainForm()
|
|
{
|
|
InitializeComponent();
|
|
color = intToRGB(r.Next(0, 0xFFFFFF));
|
|
bitmap = new Bitmap(640, 480);
|
|
paintArea.Image = bitmap;
|
|
graphics = Graphics.FromImage(bitmap);
|
|
}
|
|
|
|
private void paintArea_Click(object sender, EventArgs e)
|
|
{
|
|
MouseEventArgs em = (MouseEventArgs)e;
|
|
NameValueCollection values = new NameValueCollection();
|
|
values["color"] = rgbToInt(color).ToString();
|
|
values["x"] = em.X.ToString();
|
|
values["y"] = em.Y.ToString();
|
|
values["size"] = brushSizeNumericUpDown.Value.ToString();
|
|
client.UploadValues(url + "post.php", values);
|
|
}
|
|
|
|
private void MainForm_Load(object sender, EventArgs e)
|
|
{
|
|
timer.Start();
|
|
}
|
|
|
|
private void timer_Tick(object sender, EventArgs e)
|
|
{
|
|
string responseString = client.DownloadString(url + "data.ppf");
|
|
client.Dispose();
|
|
if (responseString.Trim() == "") return;
|
|
foreach (string packet in responseString.Split(';'))
|
|
{
|
|
try
|
|
{
|
|
if (packet.Trim() == "") continue;
|
|
int color = int.Parse(packet.Split(',')[0]);
|
|
int x = int.Parse(packet.Split(',')[1]);
|
|
int y = int.Parse(packet.Split(',')[2]);
|
|
int size = int.Parse(packet.Split(',')[3]);
|
|
graphics.FillEllipse(new SolidBrush(intToRGB(color)), new Rectangle(x - size / 2, y - size / 2, size, size));
|
|
}
|
|
catch (Exception)
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
paintArea.Image = bitmap;
|
|
}
|
|
|
|
public static int rgbToInt(Color color)
|
|
{
|
|
return ((255 & 0x0ff) << 24) | ((color.R & 0x0ff) << 16) | ((color.G & 0x0ff) << 8) | (color.B & 0x0ff);
|
|
}
|
|
|
|
public static Color intToRGB(int color)
|
|
{
|
|
return Color.FromArgb(0xFF, (color & 0x00FF0000) >> 16, (color & 0x0000FF00) >> 8, color & 0x000000FF);
|
|
}
|
|
|
|
private void changeColorButton_Click(object sender, EventArgs e)
|
|
{
|
|
colorDialog.ShowDialog();
|
|
color = colorDialog.Color;
|
|
}
|
|
|
|
private void setUrlButton_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (client.DownloadString(urlTextBox.Text + "/valid.txt").Trim() != "networkPaint") throw new Exception();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
MessageBox.Show("This is not a valid networkPaint endpoint.");
|
|
urlTextBox.Text = url;
|
|
return;
|
|
}
|
|
string tempURL = urlTextBox.Text;
|
|
if (!tempURL.EndsWith("")) tempURL += "/";
|
|
url = tempURL;
|
|
bitmap = new Bitmap(640, 480);
|
|
paintArea.Image = bitmap;
|
|
graphics = Graphics.FromImage(bitmap);
|
|
}
|
|
}
|
|
}
|