Minor improvements

This commit is contained in:
CreepyCrafter24 2019-11-10 13:25:27 +01:00
parent a60e2893fc
commit 033d0e4cc6
4 changed files with 78 additions and 58 deletions

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Data; using System.Data;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using CC_Functions.W32; using CC_Functions.W32;
@ -22,7 +23,7 @@ namespace Resizor
InitializeComponent(); InitializeComponent();
Program.kh.OnKeyPress += onKeyDown; Program.kh.OnKeyPress += onKeyDown;
Rectangle tmp = window.position; Rectangle tmp = window.position;
forcePos.Location = new Point(tmp.X + tmp.Width / 2 - forcePos.Width / 2, tmp.Y); forcePos.Location = new Point((tmp.X + (tmp.Width / 2)) - (forcePos.Width / 2), tmp.Y);
forcePos.Checked = Program.ctx.windowSizeSetters.Where(Window => Window.Window == window).ToArray().Length > 0; forcePos.Checked = Program.ctx.windowSizeSetters.Where(Window => Window.Window == window).ToArray().Length > 0;
} }
@ -44,6 +45,11 @@ namespace Resizor
private void Form1_Paint(object sender, PaintEventArgs e) private void Form1_Paint(object sender, PaintEventArgs e)
{ {
Graphics g = e.Graphics; Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.None;
g.InterpolationMode = InterpolationMode.Low;
g.CompositingMode = CompositingMode.SourceCopy;
g.CompositingQuality = CompositingQuality.HighSpeed;
g.PixelOffsetMode = PixelOffsetMode.None;
PointF divisor = Settings.Default.ResizeDividor; PointF divisor = Settings.Default.ResizeDividor;
Rectangle rect; Rectangle rect;
if (down) if (down)
@ -62,6 +68,7 @@ namespace Resizor
g.DrawLine(gridPen, 0, y * div.Y, screen.Width, y * div.Y); g.DrawLine(gridPen, 0, y * div.Y, screen.Width, y * div.Y);
} }
g.DrawRectangle(new Pen(Color.Blue, 2), rect); g.DrawRectangle(new Pen(Color.Blue, 2), rect);
g.DrawRectangle(new Pen(Color.Red, 2), window.position);
} }
PointF getDiv() => new PointF(screen.Width / Settings.Default.ResizeDividor.X, screen.Height / Settings.Default.ResizeDividor.Y); PointF getDiv() => new PointF(screen.Width / Settings.Default.ResizeDividor.X, screen.Height / Settings.Default.ResizeDividor.Y);
Rectangle CRect() => p2r(f2s(MousePosition, getDiv()), c2s(MousePosition, getDiv())); Rectangle CRect() => p2r(f2s(MousePosition, getDiv()), c2s(MousePosition, getDiv()));
@ -106,19 +113,27 @@ namespace Resizor
private void Form1_MouseUp(object sender, MouseEventArgs e) private void Form1_MouseUp(object sender, MouseEventArgs e)
{ {
Rectangle rect = FRect(); window.position = FRect();
window.position = rect;
if (forcePos.Checked)
WindowSizeSetter.make(window, rect);
Close(); Close();
} }
private void ForcePos_CheckedChanged(object sender, EventArgs e) private void ForcePos_CheckedChanged(object sender, EventArgs e)
{ {
if ((!forcePos.Checked) && Program.ctx.windowSizeSetters.Where(Window => Window.Window == window).ToArray().Length > 0) if (forcePos.Checked)
{ {
WindowSizeSetter.TryRemove(window); if (Program.ctx.windowSizeSetters.Where(Window => Window.Window == window).ToArray().Length == 0)
Close(); {
WindowSizeSetter.make(window, window.position);
Close();
}
}
else
{
if (Program.ctx.windowSizeSetters.Where(Window => Window.Window == window).ToArray().Length > 0)
{
WindowSizeSetter.TryRemove(window);
Close();
}
} }
} }
} }

View File

@ -1,8 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security.AccessControl; using System.Security.AccessControl;
@ -49,7 +46,7 @@ namespace Resizor
#endif #endif
hasHandle = true; hasHandle = true;
} }
notifyIcon1 = new NotifyIcon(); notifyIcon = new NotifyIcon();
ContextMenu contextMenu = new ContextMenu(); ContextMenu contextMenu = new ContextMenu();
MenuItem settings = new MenuItem(); MenuItem settings = new MenuItem();
MenuItem exititem = new MenuItem(); MenuItem exititem = new MenuItem();
@ -60,15 +57,16 @@ namespace Resizor
exititem.Index = 1; exititem.Index = 1;
exititem.Text = "Exit"; exititem.Text = "Exit";
exititem.Click += new EventHandler(exit); exititem.Click += new EventHandler(exit);
notifyIcon1.Icon = Resources.Resizor; notifyIcon.Icon = Resources.Resizor;
notifyIcon1.Text = "Resizor"; notifyIcon.Text = "Resizor";
notifyIcon1.ContextMenu = contextMenu; notifyIcon.ContextMenu = contextMenu;
notifyIcon1.Visible = true; notifyIcon.Visible = true;
kh = new KeyboardHook(); kh = new KeyboardHook();
kh.OnKeyPress += keyDown; kh.OnKeyPress += keyDown;
ctx = new NIApplicationContext(); ctx = new NIApplicationContext();
Application.Run(ctx); Application.Run(ctx);
kh.Dispose(); kh.Dispose();
notifyIcon.Visible = false;
} }
finally finally
{ {
@ -87,7 +85,7 @@ namespace Resizor
} }
} }
private static NotifyIcon notifyIcon1; private static NotifyIcon notifyIcon;
private static void openSettings(object sender, EventArgs e) => new SettingsForm().Show(); private static void openSettings(object sender, EventArgs e) => new SettingsForm().Show();
private static void exit(object Sender, EventArgs e) => Application.Exit(); private static void exit(object Sender, EventArgs e) => Application.Exit();
public class NIApplicationContext : ApplicationContext public class NIApplicationContext : ApplicationContext
@ -116,45 +114,4 @@ namespace Resizor
} }
} }
} }
class WindowSizeSetter
{
public readonly Wnd32 Window;
public Rectangle Pos;
WindowSizeSetter(Wnd32 window, Rectangle pos)
{
Window = window;
Pos = pos;
}
public static void make(Wnd32 window, Rectangle pos)
{
WindowSizeSetter[] match = Program.ctx.windowSizeSetters.Where(Window => Window.Window == window).ToArray();
switch (match.Length)
{
case 0:
Program.ctx.windowSizeSetters.Add(new WindowSizeSetter(window, pos));
break;
case 1:
match[0].Pos = pos;
break;
default:
for (int i = 0; i < match.Length; i++)
{
if (i == match.Length - 1)
match[0].Pos = pos;
else
Program.ctx.windowSizeSetters.Remove(match[i]);
}
break;
}
}
public static void TryRemove(Wnd32 window)
{
WindowSizeSetter[] match = Program.ctx.windowSizeSetters.Where(Window => Window.Window == window).ToArray();
if (match.Length > 0)
Program.ctx.windowSizeSetters.RemoveAll(Window => Window.Window == window);
}
}
} }

View File

@ -63,6 +63,7 @@
<Compile Include="SettingsForm.Designer.cs"> <Compile Include="SettingsForm.Designer.cs">
<DependentUpon>SettingsForm.cs</DependentUpon> <DependentUpon>SettingsForm.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="WindowSizeSetter.cs" />
<EmbeddedResource Include="Immediate Resize.resx"> <EmbeddedResource Include="Immediate Resize.resx">
<DependentUpon>Immediate Resize.cs</DependentUpon> <DependentUpon>Immediate Resize.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>

View File

@ -0,0 +1,47 @@
using System.Drawing;
using System.Linq;
using CC_Functions.W32;
namespace Resizor
{
internal class WindowSizeSetter
{
public readonly Wnd32 Window;
public Rectangle Pos;
WindowSizeSetter(Wnd32 window, Rectangle pos)
{
Window = window;
Pos = pos;
}
public static void make(Wnd32 window, Rectangle pos)
{
WindowSizeSetter[] match = Program.ctx.windowSizeSetters.Where(Window => Window.Window == window).ToArray();
switch (match.Length)
{
case 0:
Program.ctx.windowSizeSetters.Add(new WindowSizeSetter(window, pos));
break;
case 1:
match[0].Pos = pos;
break;
default:
for (int i = 0; i < match.Length; i++)
{
if (i == match.Length - 1)
match[0].Pos = pos;
else
Program.ctx.windowSizeSetters.Remove(match[i]);
}
break;
}
}
public static void TryRemove(Wnd32 window)
{
WindowSizeSetter[] match = Program.ctx.windowSizeSetters.Where(Window => Window.Window == window).ToArray();
if (match.Length > 0)
Program.ctx.windowSizeSetters.RemoveAll(Window => Window.Window == window);
}
}
}