Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 1af53fd

Browse files
committed
Fix bugs and add features
1 parent 4f4f7a5 commit 1af53fd

File tree

3 files changed

+104
-27
lines changed

3 files changed

+104
-27
lines changed

changelog.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
~ v2.1.0.0
2+
- Increased max drawing quality at the cost of speed (100 is now equivalent to around 200)
3+
- Added option to fix color luminance
4+
- Added pause feature
5+
- Minor bug fixes
6+
17
~ v2.0.0.0
28
- Greatly improved the efficiency of the drawing and color matching algorithms
39
- New UI Look

src/DrawBot/program.Designer.cs

Lines changed: 33 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/DrawBot/program.cs

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Diagnostics;
66
using System.Windows.Forms;
77
using System.Runtime.InteropServices;
8+
using static System.Windows.Forms.Keys;
89

910
namespace DrawBot
1011
{
@@ -35,6 +36,12 @@ public partial class program : Form
3536
// 0x1B = esc
3637
private bool keyDetect(int key)
3738
{
39+
/*Keys keyCode = (Keys)Enum.Parse(typeof(Keys), "Escape");
40+
KeysConverter converter = new KeysConverter();
41+
Keys key = (Keys)converter.ConvertFrom(keyCode.ToString());
42+
string hexValue = ((int)key).ToString("X2");
43+
MessageBox.Show("Key: " + keyCode.ToString() + " | Keycode: 0x" + hexValue);*/
44+
3845
short keyState = GetAsyncKeyState(key);
3946
bool keyPressed = ((keyState >> 15) & 0x0001) == 0x0001;
4047

@@ -44,24 +51,32 @@ private bool keyDetect(int key)
4451
return false;
4552
}
4653

47-
const string version = "v2.0.0";
54+
const string version = "v2.1.0";
55+
56+
public struct colorInfo
57+
{
58+
public int x, y, r, g, b;
59+
}
4860

4961
// region
5062
int x_region_start = 0;
5163
int y_region_start = 0;
5264
int x_region_end = 0;
5365
int y_region_end = 0;
5466

67+
// color correction
68+
const double r_luma_fix = 0.299;
69+
const double g_luma_fix = 0.587;
70+
const double b_luma_fix = 0.114;
71+
double r_luma = r_luma_fix;
72+
double g_luma = g_luma_fix;
73+
double b_luma = b_luma_fix;
74+
5575
// preset creator
5676
string colorsTemp = "";
5777
int colorsIndex = 0;
5878
bool hasSavedPalette = false;
5979

60-
public struct colorInfo
61-
{
62-
public int x, y, r, g, b;
63-
}
64-
6580
// palette storage
6681
public colorInfo[] colorPalette { get; set; }
6782
int paletteAmount;
@@ -119,7 +134,7 @@ private void startButton_Click(object sender, EventArgs e)
119134

120135
TopMost = true;
121136

122-
int quality_step = 500 / (Int32.Parse(qualityBox.Text) + 1);
137+
int quality_step = 200 / Int32.Parse(qualityBox.Text);
123138
double speed = 0.1 / double.Parse(speedBox.Text);
124139

125140
int x_bound = (x_region_end - x_region_start) / quality_step;
@@ -185,7 +200,16 @@ private int drawUsingStrips(int x_bound, int y_bound, int quality_step, double s
185200
for (int i = 0; i < area; i++)
186201
{
187202
// abort draw
188-
if (keyDetect(0x1B) == true) return 1;
203+
if (keyDetect(0x1B) == true)
204+
{
205+
int x_pause_temp = Cursor.Position.X;
206+
int y_pause_temp = Cursor.Position.Y;
207+
208+
DialogResult prompt = MessageBox.Show("Drawing paused.\n\nPress OK to continue\nPress CANCEL to abort", "", MessageBoxButtons.OKCancel);
209+
if (prompt == DialogResult.Cancel) return 1;
210+
211+
moveCursor(x_pause_temp, y_pause_temp);
212+
}
189213

190214
// calculate future color
191215
Color colorNext = new Color();
@@ -334,7 +358,16 @@ private int drawUsingBlobs(int x_bound, int y_bound, int quality_step, double sp
334358
for (int i = 0; i < area; i++)
335359
{
336360
// abort draw
337-
if (keyDetect(0x1B) == true) return 1;
361+
if (keyDetect(0x1B) == true)
362+
{
363+
int x_pause_temp = Cursor.Position.X;
364+
int y_pause_temp = Cursor.Position.Y;
365+
366+
DialogResult prompt = MessageBox.Show("Drawing paused.\n\nPress OK to continue\nPress CANCEL to abort", "", MessageBoxButtons.OKCancel);
367+
if (prompt == DialogResult.Cancel) return 1;
368+
369+
moveCursor(x_pause_temp, y_pause_temp);
370+
}
338371

339372
// calculate new line
340373
if (x_index == x_bound)
@@ -372,9 +405,9 @@ private int getDist(int r1, int r2, int g1, int g2, int b1, int b2)
372405
{
373406
return (int)Math.Sqrt
374407
(
375-
Math.Pow(r1 - r2, 2) +
376-
Math.Pow(g1 - g2, 2) +
377-
Math.Pow(b1 - b2, 2)
408+
r_luma * Math.Pow(r1 - r2, 2) +
409+
g_luma * Math.Pow(g1 - g2, 2) +
410+
b_luma * Math.Pow(b1 - b2, 2)
378411
);
379412
}
380413
private void moveCursor(int x, int y)
@@ -472,8 +505,11 @@ private void undoColorButton_Click(object sender, EventArgs e)
472505
{
473506
if (colorsTemp == "") return;
474507

475-
colorsTemp = colorsTemp.Remove(colorsTemp.LastIndexOf('|'));
476508
colorsIndex--;
509+
if (colorsIndex == 0)
510+
colorsTemp = "";
511+
else
512+
colorsTemp = colorsTemp.Remove(colorsTemp.LastIndexOf('|'));
477513

478514
colorIndexLabel.Text = "Color " + colorsIndex;
479515
colorLabel.Text = "(0, 0, 0)";
@@ -560,6 +596,22 @@ private void speedBar_Scroll(object sender, EventArgs e)
560596
speedBox.Text = speedBar.Value.ToString();
561597
}
562598

599+
private void luminanceFixCheckBox_CheckedChanged_1(object sender, EventArgs e)
600+
{
601+
if (luminanceFixCheckBox.Checked == true)
602+
{
603+
r_luma = r_luma_fix;
604+
g_luma = g_luma_fix;
605+
b_luma = b_luma_fix;
606+
}
607+
else
608+
{
609+
r_luma = 1.0;
610+
g_luma = 1.0;
611+
b_luma = 1.0;
612+
}
613+
}
614+
563615
private void program_MouseEnter(object sender, EventArgs e)
564616
{
565617
TopMost = false;

0 commit comments

Comments
 (0)