Minor improvements
This commit is contained in:
parent
a60e2893fc
commit
033d0e4cc6
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using CC_Functions.W32;
|
||||
|
@ -22,7 +23,7 @@ namespace Resizor
|
|||
InitializeComponent();
|
||||
Program.kh.OnKeyPress += onKeyDown;
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -44,6 +45,11 @@ namespace Resizor
|
|||
private void Form1_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
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;
|
||||
Rectangle rect;
|
||||
if (down)
|
||||
|
@ -62,6 +68,7 @@ namespace Resizor
|
|||
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.Red, 2), window.position);
|
||||
}
|
||||
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()));
|
||||
|
@ -106,19 +113,27 @@ namespace Resizor
|
|||
|
||||
private void Form1_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
Rectangle rect = FRect();
|
||||
window.position = rect;
|
||||
if (forcePos.Checked)
|
||||
WindowSizeSetter.make(window, rect);
|
||||
window.position = FRect();
|
||||
Close();
|
||||
}
|
||||
|
||||
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);
|
||||
Close();
|
||||
if (Program.ctx.windowSizeSetters.Where(Window => Window.Window == window).ToArray().Length == 0)
|
||||
{
|
||||
WindowSizeSetter.make(window, window.position);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Program.ctx.windowSizeSetters.Where(Window => Window.Window == window).ToArray().Length > 0)
|
||||
{
|
||||
WindowSizeSetter.TryRemove(window);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.AccessControl;
|
||||
|
@ -49,7 +46,7 @@ namespace Resizor
|
|||
#endif
|
||||
hasHandle = true;
|
||||
}
|
||||
notifyIcon1 = new NotifyIcon();
|
||||
notifyIcon = new NotifyIcon();
|
||||
ContextMenu contextMenu = new ContextMenu();
|
||||
MenuItem settings = new MenuItem();
|
||||
MenuItem exititem = new MenuItem();
|
||||
|
@ -60,15 +57,16 @@ namespace Resizor
|
|||
exititem.Index = 1;
|
||||
exititem.Text = "Exit";
|
||||
exititem.Click += new EventHandler(exit);
|
||||
notifyIcon1.Icon = Resources.Resizor;
|
||||
notifyIcon1.Text = "Resizor";
|
||||
notifyIcon1.ContextMenu = contextMenu;
|
||||
notifyIcon1.Visible = true;
|
||||
notifyIcon.Icon = Resources.Resizor;
|
||||
notifyIcon.Text = "Resizor";
|
||||
notifyIcon.ContextMenu = contextMenu;
|
||||
notifyIcon.Visible = true;
|
||||
kh = new KeyboardHook();
|
||||
kh.OnKeyPress += keyDown;
|
||||
ctx = new NIApplicationContext();
|
||||
Application.Run(ctx);
|
||||
kh.Dispose();
|
||||
notifyIcon.Visible = false;
|
||||
}
|
||||
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 exit(object Sender, EventArgs e) => Application.Exit();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@
|
|||
<Compile Include="SettingsForm.Designer.cs">
|
||||
<DependentUpon>SettingsForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="WindowSizeSetter.cs" />
|
||||
<EmbeddedResource Include="Immediate Resize.resx">
|
||||
<DependentUpon>Immediate Resize.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue