Skip to content

Commit aa2cb39

Browse files
committed
Custom canvas size
1 parent c3038ba commit aa2cb39

File tree

5 files changed

+188
-27
lines changed

5 files changed

+188
-27
lines changed

Hotkeys.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ private ScreenshotTask GetParamteresFromUI()
116116
_settings.saveInactiveLightCheckbox,
117117
_settings.saveMaskCheckbox,
118118
_settings.saveActiveTransparentCheckbox,
119-
_settings.saveInactiveTransparentCheckbox);
119+
_settings.saveInactiveTransparentCheckbox,
120+
_settings.canvasSizeCheckbox,
121+
_settings.canvasWidth,
122+
_settings.canvasHeight);
120123
}
121124
}
122125
}

Main.Designer.cs

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

Main.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public MainForm()
4646
resizeCheckbox.Checked = _settings.resizeCheckbox;
4747
windowWidth.Value = _settings.windowWidth;
4848
windowHeight.Value = _settings.windowHeight;
49+
canvasSizeCheckbox.Checked = _settings.canvasSizeCheckbox;
50+
canvasWidth.Value = _settings.canvasWidth;
51+
canvasHeight.Value = _settings.canvasHeight;
4952
opaqueCheckbox.Checked = _settings.opaqueCheckbox;
5053
opaqueType.SelectedIndex = _settings.opaqueType;
5154
checkerValue.Value = _settings.checkerValue;
@@ -330,6 +333,21 @@ private void OkButtonClick(object sender, EventArgs e)
330333
long data = BitConverter.ToInt64(b, 0);
331334
_registryKey.SetValue("WindowSize", data, RegistryValueKind.QWord);
332335

336+
// Save canvas settings in an 8-byte long
337+
b = new byte[8];
338+
b[0] = (byte)(canvasSizeCheckbox.Checked ? 1 : 0);
339+
340+
b[3] = (byte)((int)canvasWidth.Value & 0xff);
341+
b[2] = (byte)(((int)canvasWidth.Value >> 8) & 0xff);
342+
b[1] = (byte)(((int)canvasWidth.Value >> 16) & 0xff);
343+
344+
b[6] = (byte)((int)canvasHeight.Value & 0xff);
345+
b[5] = (byte)(((int)canvasHeight.Value >> 8) & 0xff);
346+
b[4] = (byte)(((int)canvasHeight.Value >> 16) & 0xff);
347+
348+
data = BitConverter.ToInt64(b, 0);
349+
_registryKey.SetValue("CanvasSize", data, RegistryValueKind.QWord);
350+
333351
// Save background color settings in an 8-byte long
334352
b = new byte[8];
335353
b[0] = (byte)(opaqueCheckbox.Checked ? 1 : 0);

Screenshot.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public enum BackgroundType
4949
public bool DoResize;
5050
public int ResizeX;
5151
public int ResizeY;
52+
public bool DoCanvas;
53+
public int CanvasX;
54+
public int CanvasY;
5255
public bool DisableShadow;
5356
public IntPtr WindowHandle;
5457
public bool SaveActiveDark;
@@ -66,14 +69,18 @@ public ScreenshotTask(IntPtr window, bool clipboard, string file,
6669
bool mouse, bool clearType, bool shadow,
6770
bool saveActiveDark, bool saveActiveLight, bool saveInactiveDark,
6871
bool saveInactiveLight, bool saveMask, bool saveActiveTransparent,
69-
bool saveInactiveTransparent)
72+
bool saveInactiveTransparent,
73+
bool canvas, int canvasX, int canvasY)
7074
{
7175
WindowHandle = window;
7276
ClipboardNotDisk = clipboard;
7377
DiskSaveDirectory = file;
7478
DoResize = resize;
7579
ResizeX = resizeX;
7680
ResizeY = resizeY;
81+
DoCanvas = canvas;
82+
CanvasX = canvasX;
83+
CanvasY = canvasY;
7784
Background = backType;
7885
BackgroundColor = backColor;
7986
CheckerboardSize = checkerSize;
@@ -629,7 +636,7 @@ private static unsafe Bitmap[] CaptureCompositeScreenshot(ref ScreenshotTask dat
629636

630637
if (data.CaptureMouse)
631638
DrawCursorToBitmap(transparentImage, new Point(rct.Left, rct.Top));
632-
Bitmap[] final = CropEmptyEdges(new[] { transparentImage, transparentInactiveImage, transparentWhiteImage, transparentWhiteInactiveImage, transparentMaskImage, transparentTransparentImage, transparentTransparentInactiveImage }, Color.FromArgb(0, 0, 0, 0));
639+
Bitmap[] final = CropEmptyEdges(new[] { transparentImage, transparentInactiveImage, transparentWhiteImage, transparentWhiteInactiveImage, transparentMaskImage, transparentTransparentImage, transparentTransparentInactiveImage }, Color.FromArgb(0, 0, 0, 0), ref data);
633640

634641

635642
//TODO: checkerboard support
@@ -724,7 +731,7 @@ private static unsafe Bitmap GenerateChecker(int s)
724731
return b1;
725732
}
726733

727-
private static unsafe Bitmap[] CropEmptyEdges(Bitmap[] b1, Color trimColor)
734+
private static unsafe Bitmap[] CropEmptyEdges(Bitmap[] b1, Color trimColor, ref ScreenshotTask data)
728735
{
729736
if (b1 == null)
730737
return null;
@@ -836,6 +843,16 @@ private static unsafe Bitmap[] CropEmptyEdges(Bitmap[] b1, Color trimColor)
836843
if (b1[i] == null)
837844
continue;
838845
final[i] = b1[i].Clone(new Rectangle(left, top, rightSize, bottomSize), b1[i].PixelFormat);
846+
if (data.DoCanvas)
847+
{
848+
Bitmap temp = new Bitmap(data.CanvasX, data.CanvasY);
849+
using (Graphics grD = Graphics.FromImage(temp))
850+
{
851+
grD.DrawImage(final[i], new Rectangle(0, 0, final[i].Width, final[i].Height), new Rectangle(0, 0, final[i].Width, final[i].Height), GraphicsUnit.Pixel);
852+
}
853+
final[i].Dispose();
854+
final[i] = temp;
855+
}
839856
b1[i].Dispose();
840857
}
841858

Settings.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ public class Settings
3333
public bool aeroColorCheckbox;
3434
public string aeroColorHexBox;
3535
public bool resizeCheckbox;
36-
public int windowHeight = 640;
37-
public int windowWidth = 480;
36+
public bool canvasSizeCheckbox;
37+
public int windowHeight = 480;
38+
public int windowWidth = 640;
39+
public int canvasHeight = 720;
40+
public int canvasWidth = 1280;
3841
public bool diskButton;
3942
public bool clipboardButton;
4043
public bool mouseCheckbox;
@@ -92,6 +95,16 @@ public Settings()
9295
windowHeight = b[4] << 16 | b[5] << 8 | b[6];
9396
}
9497

98+
if ((value = _registryKey.GetValue("CanvasSize")) != null && value.GetType() == (typeof(long)))
99+
{
100+
var b = new byte[8];
101+
for (int i = 0; i < 8; i++)
102+
b[i] = (byte)(((long)value >> (i * 8)) & 0xff);
103+
canvasSizeCheckbox = (b[0] & 1) == 1;
104+
canvasWidth = b[1] << 16 | b[2] << 8 | b[3];
105+
canvasHeight = b[4] << 16 | b[5] << 8 | b[6];
106+
}
107+
95108
if ((value = _registryKey.GetValue("Opaque")) != null && value.GetType() == (typeof(long)))
96109
{
97110
var b = new byte[8];

0 commit comments

Comments
 (0)