Skip to content

Commit

Permalink
Better Overlay and AppVeyor Happifier
Browse files Browse the repository at this point in the history
  • Loading branch information
marcussacana committed Jul 21, 2018
1 parent 770c6f0 commit 0b7cfb9
Show file tree
Hide file tree
Showing 10 changed files with 623 additions and 56 deletions.
Binary file modified Help/How To.txt
Binary file not shown.
106 changes: 74 additions & 32 deletions Overlay/Functions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
//#define DEBUG
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.InteropServices;
Expand All @@ -12,6 +13,13 @@
#pragma warning disable 1591
namespace Overlay {
public static class Exports {

public static bool TextOnly = false;
internal static IOverlay DefaultInstance {
get {
return (TextOnly ? (IOverlay)TextOverlay.DefaultInstance : Overlay.DefaultInstance);
}
}
public static string SetDialogue(string text) {
try {
if (text.StartsWith("::EVENT")) {
Expand All @@ -32,7 +40,7 @@ public static string SetDialogue(string text) {
}

if (EventList.Length == 0 || HookText)
Overlay.DefaultInstance.ShowText(text);
DefaultInstance.Text = text;
} catch (Exception ex) {
#if DEBUG
MessageBox.Show(ex.ToString());
Expand All @@ -56,16 +64,16 @@ public static void SendMouseClick(IntPtr WindowHandler, int X, int Y) {

static bool Minimized = false;
internal static void UpdateWindow(IntPtr WindowHandler) {
if (!Overlay.DefaultInstance.CanInvoke())
if (!DefaultInstance.CanInvoke())
return;

var Rst = new WINDOWPLACEMENT();
GetWindowPlacement(WindowHandler, ref Rst);
if (Rst.showCmd == WMinimized) {
if (Overlay.DefaultInstance.WindowState == FormWindowState.Normal) {
if (DefaultInstance.WindowState == FormWindowState.Normal) {
Minimized = true;
Overlay.DefaultInstance.Invoke(new MethodInvoker(() => {
Overlay.DefaultInstance.WindowState = FormWindowState.Minimized;
DefaultInstance.Invoke(new MethodInvoker(() => {
DefaultInstance.WindowState = FormWindowState.Minimized;
}));
}

Expand All @@ -75,18 +83,22 @@ internal static void UpdateWindow(IntPtr WindowHandler) {

if (Minimized) {
Minimized = false;
Overlay.DefaultInstance.Invoke(new MethodInvoker(() => {
Overlay.DefaultInstance.WindowState = FormWindowState.Normal;
DefaultInstance.Invoke(new MethodInvoker(() => {
DefaultInstance.WindowState = FormWindowState.Normal;
}));
}

Overlay.DefaultInstance.Invoke(new MethodInvoker(() => {
DefaultInstance.Invoke(new MethodInvoker(() => {
try {
GetPoint(WindowHandler, out Size Size, out Point Point);
Overlay.DefaultInstance.Size = Size;
Overlay.DefaultInstance.Location = Point;
DefaultInstance.Size = Size;
DefaultInstance.Location = Point;
DefaultInstance.Focus();
SetWindowPos(DefaultInstance.Handle, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
SetWindowPos(DefaultInstance.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
Overlay.DefaultInstance.Focus();
SetForegroundWindow(WindowHandler);
} catch { }
}));
Expand Down Expand Up @@ -125,7 +137,7 @@ public static bool HookWindow(IntPtr WindowHandler) {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Overlay.DefaultInstance.Show();
DefaultInstance.Show();
new Thread(() => { SetDialogue("::EVENT0::"); }).Start();
Expand All @@ -139,15 +151,15 @@ public static bool HookWindow(IntPtr WindowHandler) {
}
try {
for (int i = 0; i < 50; i++) {
for (int i = 0; i < 25; i++) {
Application.DoEvents();
Thread.Sleep(10);
}
} catch { }
}
//Maybe Envoriment.Exit will bee needed.
Overlay.DefaultInstance.Close();
DefaultInstance.Close();
});

OverlayThread.SetApartmentState(ApartmentState.STA);
Expand Down Expand Up @@ -176,6 +188,15 @@ internal static class Imports {
internal const int WMinimized = 2;
internal const int WMaximized = 3;

[DllImport("user32.dll")]
internal static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

internal static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
internal static readonly IntPtr HWND_TOP = new IntPtr(0);
internal const uint SWP_NOSIZE = 0x0001;
internal const uint SWP_NOMOVE = 0x0002;
internal const uint SWP_SHOWWINDOW = 0x0040;

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
Expand Down Expand Up @@ -276,54 +297,52 @@ internal static void TriggerEvent(uint ID) {
case "subtitle":
case "set text":
case "text":
Overlay.DefaultInstance.ShowText(CMDV.Replace("\\n", "\n"));
DefaultInstance.Text = CMDV.Replace("\\n", "\n");
break;
case "clear":
case "clear text":
case "remove text":
case "cls":
Overlay.DefaultInstance.ShowText(string.Empty);
DefaultInstance.Text = string.Empty;
break;
case "hide":
case "close":
case "hide overlay":
case "close overlay":
Overlay.DefaultInstance.Invoke(new MethodInvoker(() => {
Overlay.DefaultInstance.Opacity = 1.0d;
Overlay.DefaultInstance.Hide();
DefaultInstance.Invoke(new MethodInvoker(() => {
DefaultInstance.Opacity = 1.0d;
DefaultInstance.Hide();
}));
break;
case "show":
case "open":
case "show overlay":
case "open overlay":
Overlay.DefaultInstance.Invoke(new MethodInvoker(() => {
Overlay.DefaultInstance.Opacity = 1.0d;
Overlay.DefaultInstance.Show();
DefaultInstance.Invoke(new MethodInvoker(() => {
DefaultInstance.Opacity = 1.0d;
DefaultInstance.Show();
}));
break;
case "window opacity":
case "overlay opacity":
case "global opacity":
case "opacity":
double Opacity = double.Parse(CMDV);
Overlay.DefaultInstance.Invoke(new MethodInvoker(() => {
Overlay.DefaultInstance.Opacity = Opacity;
DefaultInstance.Invoke(new MethodInvoker(() => {
DefaultInstance.Opacity = Opacity;
}));
break;
case "set background color":
case "background color":
case "back color":
case "backcolor":
Overlay.DefaultInstance.TranslatePanel.BackColor = LoadColor(CMDV, Color.FromArgb(40, 40, 40));
Overlay.DefaultInstance.ButtonPanel.BackColor = LoadColor(CMDV, Color.FromArgb(40, 40, 40));
Overlay.DefaultInstance.DialogueBox.BackColor = LoadColor(CMDV, Color.FromArgb(40, 40, 40));
DefaultInstance.TextBackColor = LoadColor(CMDV, Color.Black);
break;
case "text color":
case "set text color":
case "fore color":
case "forecolor":
Overlay.DefaultInstance.DialogueBox.ForeColor = LoadColor(CMDV, Color.FromArgb(40, 40, 40));
DefaultInstance.TextForeColor = LoadColor(CMDV, Color.FromArgb(40, 40, 40));
break;
case "set padding":
case "force padding":
Expand Down Expand Up @@ -371,13 +390,13 @@ internal static void TriggerEvent(uint ID) {
case "set font size":
case "font resize":
case "resize font":
Overlay.DefaultInstance.FixedFontSize = float.Parse(CMDV);
DefaultInstance.Font = new Font(DefaultInstance.Font.FontFamily, float.Parse(CMDV), DefaultInstance.Font.Style);
break;
case "auto font size":
case "auto resize text":
case "auto font resize":
case "resize text":
Overlay.DefaultInstance.AutoFontSize = CMDV.ToLower() == "true";
DefaultInstance.AutoSize = CMDV.ToLower() == "true";
break;
case "set dock":
case "change dock":
Expand All @@ -395,6 +414,18 @@ internal static void TriggerEvent(uint ID) {
break;
}
break;
case "text only":
case "no background":
case "subtitle mode":
case "hide background":
string Text = DefaultInstance?.Text;
DefaultInstance?.Close();
DefaultInstance?.Dispose();
TextOnly = CMDV.ToLower() == "true";
DefaultInstance.Show();
DefaultInstance.Text = Text;
UpdateWindow(HookHandler);
break;
case "hook text":
case "enable hook":
case "auto show":
Expand All @@ -407,6 +438,18 @@ internal static void TriggerEvent(uint ID) {
case "run":
TriggerEvent(uint.Parse(CMDV));
break;
case "call async":
case "async":
case "async invoke":
case "invoke async":
new Thread(() => { TriggerEvent(uint.Parse(CMDV)); }).Start();
break;
case "wait":
case "sleep":
case "delay":
case "suspend":
Thread.Sleep(int.Parse(CMDV));
break;
case "continue to event":
case "jump to event":
case "go to":
Expand All @@ -427,7 +470,6 @@ internal static void TriggerEvent(uint ID) {
}
}


internal static Color LoadColor(string ColorName, Color Default) {
try {
if (ColorName.StartsWith("#")) {
Expand Down
35 changes: 35 additions & 0 deletions Overlay/IOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Overlay {
internal interface IOverlay {

bool AutoSize { get; set; }
string Text { get; set; }
Font Font { get; set; }

Size Size { get; set; }
Point Location { get; set; }

Color TextBackColor { get; set; }
Color TextForeColor { get; set; }

IntPtr Handle { get; }

FormWindowState WindowState { get; set; }
double Opacity { get; set; }

bool CanInvoke();

void Invoke(Delegate Method);
void Close();
void Show();
void Dispose();
void Hide();
void Focus();
}
}
3 changes: 2 additions & 1 deletion Overlay/Overlay.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0b7cfb9

Please sign in to comment.