diff --git a/Eve-O-Mock/Eve-O-Mock.csproj b/Eve-O-Mock/Eve-O-Mock.csproj index 1b48ffa..6c0f85f 100644 --- a/Eve-O-Mock/Eve-O-Mock.csproj +++ b/Eve-O-Mock/Eve-O-Mock.csproj @@ -8,7 +8,7 @@ WinExe Properties EveOMock - exefile + ExeFile v4.5 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} @@ -23,6 +23,7 @@ DEBUG;TRACE prompt 4 + false AnyCPU diff --git a/Eve-O-Preview/DwmAPI/DwmApiNativeMethods.cs b/Eve-O-Preview/DwmAPI/DwmApiNativeMethods.cs index 027f6ac..445252a 100644 --- a/Eve-O-Preview/DwmAPI/DwmApiNativeMethods.cs +++ b/Eve-O-Preview/DwmAPI/DwmApiNativeMethods.cs @@ -51,8 +51,10 @@ namespace EveOPreview public const int WM_NCLBUTTONDOWN = 0xA1; public const int HTCAPTION = 0x2; + [DllImport("User32.dll")] public static extern bool ReleaseCapture(); + [DllImport("User32.dll")] public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); diff --git a/Eve-O-Preview/DwmAPI/RECT.cs b/Eve-O-Preview/DwmAPI/RECT.cs index 68eee6a..bc9f5ec 100644 --- a/Eve-O-Preview/DwmAPI/RECT.cs +++ b/Eve-O-Preview/DwmAPI/RECT.cs @@ -5,17 +5,17 @@ namespace EveOPreview [StructLayout(LayoutKind.Sequential)] struct RECT { - public int left; - public int top; - public int right; - public int bottom; + public int Left; + public int Top; + public int Right; + public int Bottom; public RECT(int left, int top, int right, int bottom) { - this.left = left; - this.top = top; - this.right = right; - this.bottom = bottom; + this.Left = left; + this.Top = top; + this.Right = right; + this.Bottom = bottom; } } } \ No newline at end of file diff --git a/Eve-O-Preview/Eve-O-Preview.csproj b/Eve-O-Preview/Eve-O-Preview.csproj index 71ecbe9..2a654c5 100644 --- a/Eve-O-Preview/Eve-O-Preview.csproj +++ b/Eve-O-Preview/Eve-O-Preview.csproj @@ -82,6 +82,13 @@ true + + false + + + + + @@ -100,6 +107,9 @@ + + + @@ -140,7 +150,6 @@ Designer - SettingsSingleFileGenerator diff --git a/Eve-O-Preview/GUI/ClientLocation.cs b/Eve-O-Preview/GUI/ClientLocation.cs new file mode 100644 index 0000000..6f66438 --- /dev/null +++ b/Eve-O-Preview/GUI/ClientLocation.cs @@ -0,0 +1,10 @@ +namespace EveOPreview +{ + public struct ClientLocation + { + public int X; + public int Y; + public int Width; + public int Height; + } +} \ No newline at end of file diff --git a/Eve-O-Preview/GUI/GuiNativeMethods.cs b/Eve-O-Preview/GUI/GuiNativeMethods.cs new file mode 100644 index 0000000..d46dfb1 --- /dev/null +++ b/Eve-O-Preview/GUI/GuiNativeMethods.cs @@ -0,0 +1,22 @@ +using System; +using System.Runtime.InteropServices; + +namespace EveOPreview +{ + // TODO This is a really bad name for this class + static class GuiNativeMethods + { + public const int WM_SIZE = 5; + public const int SIZE_RESTORED = 0; + public const int SIZE_MINIMIZED = 1; + public const int SIZE_MAXIMIZED = 2; + public const int SIZE_MAXSHOW = 3; + public const int SIZE_MAXHIDE = 4; + + [DllImport("user32.dll")] + public static extern int GetWindowRect(IntPtr hwnd, out RECT rect); + + [DllImport("user32.dll")] + public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); + } +} \ No newline at end of file diff --git a/Eve-O-Preview/GUI/MainForm.cs b/Eve-O-Preview/GUI/MainForm.cs index 21af088..389ea25 100644 --- a/Eve-O-Preview/GUI/MainForm.cs +++ b/Eve-O-Preview/GUI/MainForm.cs @@ -2,943 +2,893 @@ using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; -using System.Runtime.InteropServices; using System.Diagnostics; +using System.Globalization; using System.Windows.Threading; using System.Xml.Linq; using System.IO; namespace EveOPreview { - public partial class MainForm : Form - { - private const int WM_SIZE = 5; - private const int SIZE_RESTORED = 0; - private const int SIZE_MINIMIZED = 1; - private const int SIZE_MAXIMIZED = 2; - private const int SIZE_MAXSHOW = 3; - private const int SIZE_MAXHIDE = 4; - - public event EventHandler Minimized; - public event EventHandler Maximized; - public event EventHandler Restored; + public partial class MainForm : Form + { + public event EventHandler Minimized; + public event EventHandler Maximized; + public event EventHandler Restored; - private readonly Dictionary _previews; - private DispatcherTimer _dispatcherTimer; + private readonly Dictionary _previews; + private DispatcherTimer _dispatcherTimer; - private IntPtr _activeClientHandle; - private String _activeClientTitle; + private IntPtr _activeClientHandle; + private string _activeClientTitle; - private Dictionary> unique_layouts; - private Dictionary flat_layout; - private Dictionary flat_layout_shortcuts; - private Dictionary client_layout; + private readonly Dictionary> _uniqueLayouts; + private readonly Dictionary _flatLayout; + private readonly Dictionary _flatLayoutShortcuts; + private readonly Dictionary _clientLayout; - private bool is_initialized; + private readonly bool _isInitialized; - private Stopwatch ignoring_size_sync; + private readonly Stopwatch _ignoringSizeSync; - Dictionary xml_bad_to_ok_chars; + private readonly Dictionary _xmlBadToOkChars; - [DllImport("user32.dll")] - private static extern int GetWindowRect(IntPtr hwnd, out Rect rect); + private Dictionary _zoomAnchorButtonMap; - [DllImport("user32.dll")] - public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); - - private struct Rect - { - public int Left; - public int Top; - public int Right; - public int Bottom; - } - - private struct ClientLocation - { - public int X; - public int Y; - public int Width; - public int Height; - } - - public enum zoom_anchor_t - { - NW = 0, - N, - NE, - W, - C, - E, - SW, - S, - SE - }; - - private Dictionary zoom_anchor_button_map; - - public MainForm() - { - is_initialized = false; + public MainForm() + { + _isInitialized = false; this._activeClientHandle = (IntPtr)0; this._activeClientTitle = ""; - _previews = new Dictionary(); + _previews = new Dictionary(); - xml_bad_to_ok_chars = new Dictionary(); - xml_bad_to_ok_chars["<"] = "---lt---"; - xml_bad_to_ok_chars["&"] = "---amp---"; - xml_bad_to_ok_chars[">"] = "---gt---"; - xml_bad_to_ok_chars["\""] = "---quot---"; - xml_bad_to_ok_chars["\'"] = "---apos---"; - xml_bad_to_ok_chars[","] = "---comma---"; - xml_bad_to_ok_chars["."] = "---dot---"; + _xmlBadToOkChars = new Dictionary(); + _xmlBadToOkChars["<"] = "---lt---"; + _xmlBadToOkChars["&"] = "---amp---"; + _xmlBadToOkChars[">"] = "---gt---"; + _xmlBadToOkChars["\""] = "---quot---"; + _xmlBadToOkChars["\'"] = "---apos---"; + _xmlBadToOkChars[","] = "---comma---"; + _xmlBadToOkChars["."] = "---dot---"; - unique_layouts = new Dictionary>(); - flat_layout = new Dictionary(); - flat_layout_shortcuts = new Dictionary(); - client_layout = new Dictionary(); + _uniqueLayouts = new Dictionary>(); + _flatLayout = new Dictionary(); + _flatLayoutShortcuts = new Dictionary(); + _clientLayout = new Dictionary(); - ignoring_size_sync = new Stopwatch(); - ignoring_size_sync.Start(); + _ignoringSizeSync = new Stopwatch(); + _ignoringSizeSync.Start(); - InitializeComponent(); - init_options(); + InitializeComponent(); + init_options(); - // DispatcherTimer setup - _dispatcherTimer = new DispatcherTimer(); - _dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); - _dispatcherTimer.Interval = new TimeSpan(0, 0, 1); - _dispatcherTimer.Start(); + // DispatcherTimer setup + _dispatcherTimer = new DispatcherTimer(); + _dispatcherTimer.Tick += dispatcherTimer_Tick; + _dispatcherTimer.Interval = new TimeSpan(0, 0, 1); + _dispatcherTimer.Start(); - is_initialized = true; + _isInitialized = true; - previews_check_listbox.DisplayMember = "Text"; + previews_check_listbox.DisplayMember = "Text"; - } + } - private void GlassForm_Load(object sender, EventArgs e) - { - refresh_thumbnails(); - } - - private void init_options() - { - this.Minimized += new EventHandler(MainForm_Minimized); + private void GlassForm_Load(object sender, EventArgs e) + { + refresh_thumbnails(); + } + + private void init_options() + { + this.Minimized += MainForm_Minimized; - option_zoom_on_hover.Checked = Properties.Settings.Default.zoom_on_hover; - zoom_anchor_button_map = new Dictionary(); - zoom_anchor_button_map[zoom_anchor_t.NW] = option_zoom_anchor_NW; - zoom_anchor_button_map[zoom_anchor_t.N] = option_zoom_anchor_N; - zoom_anchor_button_map[zoom_anchor_t.NE] = option_zoom_anchor_NE; - zoom_anchor_button_map[zoom_anchor_t.W] = option_zoom_anchor_W; - zoom_anchor_button_map[zoom_anchor_t.C] = option_zoom_anchor_C; - zoom_anchor_button_map[zoom_anchor_t.E] = option_zoom_anchor_E; - zoom_anchor_button_map[zoom_anchor_t.SW] = option_zoom_anchor_SW; - zoom_anchor_button_map[zoom_anchor_t.S] = option_zoom_anchor_S; - zoom_anchor_button_map[zoom_anchor_t.SE] = option_zoom_anchor_SE; - zoom_anchor_button_map[(zoom_anchor_t)Properties.Settings.Default.zoom_anchor].Checked = true; - option_zoom_factor.Text = Properties.Settings.Default.zoom_amount.ToString(); - - option_always_on_top.Checked = Properties.Settings.Default.always_on_top; - option_hide_active.Checked = Properties.Settings.Default.hide_active; - option_hide_all_if_not_right_type.Checked = Properties.Settings.Default.hide_all; - - option_unique_layout.Checked = Properties.Settings.Default.unique_layout; - - option_sync_size.Checked = Properties.Settings.Default.sync_resize; - option_sync_size_x.Text = Properties.Settings.Default.sync_resize_x.ToString(); - option_sync_size_y.Text = Properties.Settings.Default.sync_resize_y.ToString(); - - option_show_thumbnail_frames.Checked = Properties.Settings.Default.show_thumb_frames; - - option_show_overlay.Checked = Properties.Settings.Default.show_overlay; - - option_track_client_windows.Checked = Properties.Settings.Default.track_client_windows; - - option_minToTray.Checked = Properties.Settings.Default.minimizeToTray; - - // disable/enable zoom suboptions - option_zoom_factor.Enabled = Properties.Settings.Default.zoom_on_hover; - foreach (var kv in zoom_anchor_button_map) - { - kv.Value.Enabled = Properties.Settings.Default.zoom_on_hover; - } - - opacity_bar.Value = Math.Min(100, (int)(100.0 * Properties.Settings.Default.opacity)); - - load_layout(); - } - - - private void spawn_and_kill_previews() - { - if (!is_initialized) { return; } - - Process[] processes = Process.GetProcessesByName("ExeFile"); - List processHandles = new List(); - - // pop new previews - - foreach (Process process in processes) - { - processHandles.Add(process.MainWindowHandle); - - Size sync_size = new Size(); - sync_size.Width = (int)Properties.Settings.Default.sync_resize_x; - sync_size.Height = (int)Properties.Settings.Default.sync_resize_y; - - if (!_previews.ContainsKey(process.MainWindowHandle) && process.MainWindowTitle != "") - { - _previews[process.MainWindowHandle] = new Preview(process.MainWindowHandle, "...", this, sync_size); - _previews[process.MainWindowHandle].set_render_area_size(sync_size); - - // apply more thumbnail specific options - _previews[process.MainWindowHandle].MakeTopMost(Properties.Settings.Default.always_on_top); - set_thumbnail_frame_style(_previews[process.MainWindowHandle], Properties.Settings.Default.show_thumb_frames); - - // add a preview also - previews_check_listbox.BeginUpdate(); - previews_check_listbox.Items.Add(_previews[process.MainWindowHandle]); - previews_check_listbox.EndUpdate(); - - refresh_client_window_locations(process); - } - - else if (_previews.ContainsKey(process.MainWindowHandle) && process.MainWindowTitle != _previews[process.MainWindowHandle].Text) //or update the preview titles - { - _previews[process.MainWindowHandle].SetLabel(process.MainWindowTitle); - string key = _previews[process.MainWindowHandle].Text; - string value; - if (flat_layout_shortcuts.TryGetValue(key, out value)) - { - _previews[process.MainWindowHandle].registerShortcut(value); - } - refresh_client_window_locations(process); - } - - if (process.MainWindowHandle == DwmApiNativeMethods.GetForegroundWindow()) - { - _activeClientHandle = process.MainWindowHandle; - _activeClientTitle = process.MainWindowTitle; - } - - } - - // clean up old previews - List to_be_pruned = new List(); - foreach (IntPtr processHandle in _previews.Keys) - { - if (!(processHandles.Contains(processHandle))) - { - to_be_pruned.Add(processHandle); - } - } - - foreach (IntPtr processHandle in to_be_pruned) - { - previews_check_listbox.BeginUpdate(); - previews_check_listbox.Items.Remove(_previews[processHandle]); - previews_check_listbox.EndUpdate(); - - _previews[processHandle].overlay.Close(); - _previews[processHandle].Close(); - _previews.Remove(processHandle); - } - - previews_check_listbox.Update(); - - } - - private void refresh_client_window_locations(Process process) - { - if (Properties.Settings.Default.track_client_windows && client_layout.ContainsKey(process.MainWindowTitle)) - { - MoveWindow( - process.MainWindowHandle, - client_layout[process.MainWindowTitle].X, - client_layout[process.MainWindowTitle].Y, - client_layout[process.MainWindowTitle].Width, - client_layout[process.MainWindowTitle].Height, - true); - } - } - - - private string remove_nonconform_xml_characters(string entry) - { - foreach (var kv in xml_bad_to_ok_chars) - { - entry = entry.Replace(kv.Key, kv.Value); - } - return entry; - } - - private string restore_nonconform_xml_characters(string entry) - { - foreach (var kv in xml_bad_to_ok_chars) - { - entry = entry.Replace(kv.Value, kv.Key); - } - return entry; - } - - private XElement MakeXElement(string input) - { - string clean = remove_nonconform_xml_characters(input).Replace(" ", "_"); - return new XElement(clean); - } - - private string ParseXElement(XElement input) - { - return restore_nonconform_xml_characters(input.Name.ToString()).Replace("_", " "); - } - - private void load_layout() - { - if (File.Exists("layout.xml")) - { - XElement rootElement = XElement.Load("layout.xml"); - foreach (var el in rootElement.Elements()) - { - Dictionary inner = new Dictionary(); - foreach (var inner_el in el.Elements()) - { - inner[ParseXElement(inner_el)] = new Point(Convert.ToInt32(inner_el.Element("x").Value), Convert.ToInt32(inner_el.Element("y").Value)); - } - unique_layouts[ParseXElement(el)] = inner; - } - } - - if (File.Exists("flat_layout.xml")) - { - XElement rootElement = XElement.Load("flat_layout.xml"); - foreach (var el in rootElement.Elements()) - { - flat_layout[ParseXElement(el)] = new Point(Convert.ToInt32(el.Element("x").Value), Convert.ToInt32(el.Element("y").Value)); - flat_layout_shortcuts[ParseXElement(el)] = ""; - - if (el.Element("shortcut") != null) - { - flat_layout_shortcuts[ParseXElement(el)] = el.Element("shortcut").Value; - } - } - } - - if (File.Exists("client_layout.xml")) - { - XElement rootElement = XElement.Load("client_layout.xml"); - foreach (var el in rootElement.Elements()) - { - ClientLocation clientLocation = new ClientLocation(); - clientLocation.X = Convert.ToInt32(el.Element("x").Value); - clientLocation.Y = Convert.ToInt32(el.Element("y").Value); - clientLocation.Width = Convert.ToInt32(el.Element("width").Value); - clientLocation.Height = Convert.ToInt32(el.Element("height").Value); - - client_layout[ParseXElement(el)] = clientLocation; - } - } - } - - private void store_layout() - { - XElement el = new XElement("layouts"); - foreach (var client in unique_layouts.Keys) - { - if (client == "") - { - continue; - } - XElement layout = MakeXElement(client); - foreach (var thumbnail_ in unique_layouts[client]) - { - String thumbnail = thumbnail_.Key; - if (thumbnail == "" || thumbnail == "...") - { - continue; - } - XElement position = MakeXElement(thumbnail); - position.Add(new XElement("x", thumbnail_.Value.X)); - position.Add(new XElement("y", thumbnail_.Value.Y)); - layout.Add(position); - } - el.Add(layout); - } - - el.Save("layout.xml"); - - XElement el2 = new XElement("flat_layout"); - foreach (var clientKV in flat_layout) - { - if (clientKV.Key == "" || clientKV.Key == "...") - { - continue; - } - XElement layout = MakeXElement(clientKV.Key); - layout.Add(new XElement("x", clientKV.Value.X)); - layout.Add(new XElement("y", clientKV.Value.Y)); - - string shortcut; - if (flat_layout_shortcuts.TryGetValue(clientKV.Key, out shortcut)) - { - layout.Add(new XElement("shortcut", shortcut)); - } - el2.Add(layout); - } - - el2.Save("flat_layout.xml"); - - XElement el3 = new XElement("client_layout"); - foreach (var clientKV in client_layout) - { - if (clientKV.Key == "" || clientKV.Key == "...") - { - continue; - } - XElement layout = MakeXElement(clientKV.Key); - layout.Add(new XElement("x", clientKV.Value.X)); - layout.Add(new XElement("y", clientKV.Value.Y)); - layout.Add(new XElement("width", clientKV.Value.Width)); - layout.Add(new XElement("height", clientKV.Value.Height)); - el3.Add(layout); - } - - el3.Save("client_layout.xml"); - } - - private void handle_unique_layout(Preview preview, String last_known_active_window) - { - Dictionary layout; - if (unique_layouts.TryGetValue(last_known_active_window, out layout)) - { - Point new_loc; - if (Properties.Settings.Default.unique_layout && layout.TryGetValue(preview.Text, out new_loc)) - { - preview.doMove(new_loc); - } - else - { - // create inner dict - layout[preview.Text] = preview.Location; - } - } - else if (last_known_active_window != "") - { - // create outer dict - unique_layouts[last_known_active_window] = new Dictionary(); - unique_layouts[last_known_active_window][preview.Text] = preview.Location; - } - } - - - private void update_client_locations() - { - Process[] processes = Process.GetProcessesByName("ExeFile"); - List processHandles = new List(); - - foreach (Process process in processes) - { - Rect rect = new Rect(); - GetWindowRect(process.MainWindowHandle, out rect); - - int left = Math.Abs(rect.Left); - int right = Math.Abs(rect.Right); - int client_width = Math.Abs(left - right); - - int top = Math.Abs(rect.Top); - int bottom = Math.Abs(rect.Bottom); - int client_height = Math.Abs(top - bottom); - - ClientLocation clientLocation = new ClientLocation(); - clientLocation.X = rect.Left; - clientLocation.Y = rect.Top; - clientLocation.Width = client_width; - clientLocation.Height = client_height; - - - client_layout[process.MainWindowTitle] = clientLocation; - } - } - - - public void preview_did_switch() - { - update_client_locations(); - store_layout(); //todo: check if it actually changed ... - foreach (KeyValuePair entry in _previews) - { - entry.Value.MakeTopMost(Properties.Settings.Default.always_on_top); - //makes the PreviewOverlay topmost - entry.Value.overlay.makeTopMost(); - } - } - - - private void handle_flat_layout(Preview preview) - { - Point layout; - if (flat_layout.TryGetValue(preview.Text, out layout)) - { - preview.doMove(layout); - } - else if (preview.Text != "") - { - flat_layout[preview.Text] = preview.Location; - } - } - - private bool window_is_preview_or_client(IntPtr window) - { - bool active_window_is_right_type = false; - foreach (KeyValuePair entry in _previews) - { - if (entry.Key == window || entry.Value.Handle == window || this.Handle == window || entry.Value.overlay.Handle == window) - { - active_window_is_right_type = true; - } - } - return active_window_is_right_type; - } - - - private void refresh_thumbnails() - { - - IntPtr active_window = DwmApiNativeMethods.GetForegroundWindow(); - - // hide, show, resize and move - foreach (KeyValuePair entry in _previews) - { - if (!window_is_preview_or_client(active_window) && Properties.Settings.Default.hide_all) - { - entry.Value.Hide(); - } - else if (entry.Key == _activeClientHandle && Properties.Settings.Default.hide_active) - { - entry.Value.Hide(); - } - else - { - entry.Value.Show(); - if (Properties.Settings.Default.unique_layout) - { - handle_unique_layout(entry.Value, _activeClientTitle); - } - else - { - handle_flat_layout(entry.Value); - } - } - entry.Value.hover_zoom = Properties.Settings.Default.zoom_on_hover; - entry.Value.show_overlay = Properties.Settings.Default.show_overlay; - //makes the PreviewOverlay TopMost - entry.Value.overlay.makeTopMost(); - if (!entry.Value.is_hovered_over) - { - entry.Value.Opacity = Properties.Settings.Default.opacity; - } - } - - DwmApiNativeMethods.DwmIsCompositionEnabled(); - } - - - public void syncronize_preview_size(Size sync_size) - { - if (!is_initialized) { return; } - - if (Properties.Settings.Default.sync_resize && - Properties.Settings.Default.show_thumb_frames && - ignoring_size_sync.ElapsedMilliseconds > 500) - { - ignoring_size_sync.Stop(); - - option_sync_size_x.Text = sync_size.Width.ToString(); - option_sync_size_y.Text = sync_size.Height.ToString(); - - foreach (KeyValuePair entry in _previews) - { - if (entry.Value.Handle != DwmApiNativeMethods.GetForegroundWindow()) - { - entry.Value.set_render_area_size(sync_size); - } - } - - } - - } - - - public void register_preview_position(String preview_title, Point position) - { - - if (Properties.Settings.Default.unique_layout) - { - Dictionary layout; - if (unique_layouts.TryGetValue(_activeClientTitle, out layout)) - { - layout[preview_title] = position; - } - else if (_activeClientTitle == "") - { - unique_layouts[_activeClientTitle] = new Dictionary(); - unique_layouts[_activeClientTitle][preview_title] = position; - } - } - else - { - flat_layout[preview_title] = position; - } - - } - - - private void dispatcherTimer_Tick(object sender, EventArgs e) - { - spawn_and_kill_previews(); - refresh_thumbnails(); - if (ignoring_size_sync.ElapsedMilliseconds > 500) { ignoring_size_sync.Stop(); }; - - if (DwmApiNativeMethods.DwmIsCompositionEnabled()) - { - aero_status_label.Text = "AERO is ON"; - aero_status_label.ForeColor = Color.Black; - } - else - { - aero_status_label.Text = "AERO is OFF"; - aero_status_label.ForeColor = Color.Red; - } - - } - - - private void option_hide_all_if_noneve_CheckedChanged(object sender, EventArgs e) - { - Properties.Settings.Default.hide_all = option_hide_all_if_not_right_type.Checked; - Properties.Settings.Default.Save(); - refresh_thumbnails(); - } - - - private void option_unique_layout_CheckedChanged(object sender, EventArgs e) - { - Properties.Settings.Default.unique_layout = option_unique_layout.Checked; - Properties.Settings.Default.Save(); - refresh_thumbnails(); - } - - - private void option_hide_active_CheckedChanged(object sender, EventArgs e) - { - Properties.Settings.Default.hide_active = option_hide_active.Checked; - Properties.Settings.Default.Save(); - refresh_thumbnails(); - } - - - private void option_sync_size_CheckedChanged(object sender, EventArgs e) - { - Properties.Settings.Default.sync_resize = option_sync_size.Checked; - Properties.Settings.Default.Save(); - refresh_thumbnails(); - } - - - private void parse_size_entry() - { - UInt32 x = 0, y = 0; - - try - { - y = Convert.ToUInt32(option_sync_size_y.Text); - x = Convert.ToUInt32(option_sync_size_x.Text); - } - catch (System.FormatException) - { - return; - } - - if (x < 64 || y < 64) - { - return; - } - - Properties.Settings.Default.sync_resize_y = y; - Properties.Settings.Default.sync_resize_x = x; - Properties.Settings.Default.Save(); - - // resize - syncronize_preview_size(new Size((int)Properties.Settings.Default.sync_resize_x, - (int)Properties.Settings.Default.sync_resize_y)); - } - - - private void option_sync_size_x_TextChanged(object sender, EventArgs e) - { - parse_size_entry(); - } - - - private void option_sync_size_y_TextChanged(object sender, EventArgs e) - { - parse_size_entry(); - } - - - private void option_always_on_top_CheckedChanged(object sender, EventArgs e) - { - Properties.Settings.Default.always_on_top = option_always_on_top.Checked; - Properties.Settings.Default.Save(); - refresh_thumbnails(); - } - - - void set_thumbnail_frame_style(Preview preview, bool show_frames) - { - if (show_frames) - { - preview.FormBorderStyle = FormBorderStyle.SizableToolWindow; - } - else - { - preview.FormBorderStyle = FormBorderStyle.None; - } - } - - private void option_show_thumbnail_frames_CheckedChanged(object sender, EventArgs e) - { - Properties.Settings.Default.show_thumb_frames = option_show_thumbnail_frames.Checked; - Properties.Settings.Default.Save(); - - if (Properties.Settings.Default.show_thumb_frames) - { - ignoring_size_sync.Stop(); - ignoring_size_sync.Reset(); - ignoring_size_sync.Start(); - } - - foreach (var thumbnail in _previews) - { - set_thumbnail_frame_style(thumbnail.Value, Properties.Settings.Default.show_thumb_frames); - } - - } - - - private void list_running_clients_SelectedIndexChanged(object sender, EventArgs e) { } - - - private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) - { - string url = "https://bitbucket.org/ulph/eve-o-preview-git"; - ProcessStartInfo sInfo = new ProcessStartInfo(new Uri(url).AbsoluteUri); - Process.Start(sInfo); - } - - - private void previewToyMainBindingSource_CurrentChanged(object sender, EventArgs e) - { - - } - - private void option_zoom_on_hover_CheckedChanged(object sender, EventArgs e) - { - Properties.Settings.Default.zoom_on_hover = option_zoom_on_hover.Checked; - Properties.Settings.Default.Save(); - refresh_thumbnails(); - option_zoom_factor.Enabled = Properties.Settings.Default.zoom_on_hover; - if (is_initialized) - { - foreach (var kv in zoom_anchor_button_map) - { - kv.Value.Enabled = Properties.Settings.Default.zoom_on_hover; - } - } - } - - private void option_show_overlay_CheckedChanged(object sender, EventArgs e) - { - Properties.Settings.Default.show_overlay = option_show_overlay.Checked; - Properties.Settings.Default.Save(); - refresh_thumbnails(); - } - - - private void handle_zoom_anchor_setting() - { - foreach (var kv in zoom_anchor_button_map) - { - if (kv.Value.Checked == true) - Properties.Settings.Default.zoom_anchor = (byte)kv.Key; - } - } - - private void option_zoom_anchor_X_CheckedChanged(object sender, EventArgs e) - { - handle_zoom_anchor_setting(); - Properties.Settings.Default.Save(); - } - - private void option_zoom_factor_TextChanged(object sender, EventArgs e) - { - try - { - float tmp = (float)Convert.ToDouble(option_zoom_factor.Text); - if (tmp < 1) - { - tmp = 1; - } - else if (tmp > 10) - { - tmp = 10; - } - Properties.Settings.Default.zoom_amount = tmp; - option_zoom_factor.Text = tmp.ToString(); - Properties.Settings.Default.Save(); - } - catch - { - // do naught - } - } - - private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e) - { - refresh_thumbnails(); - } - - private void checkedListBox1_SelectedIndexChanged2(object sender, EventArgs e) - { - System.Windows.Forms.ItemCheckEventArgs arg = (System.Windows.Forms.ItemCheckEventArgs)e; - ((Preview)this.previews_check_listbox.Items[arg.Index]).MakeHidden(arg.NewValue == System.Windows.Forms.CheckState.Checked); - refresh_thumbnails(); - } - - private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e) - { - - } - - private void checkBox1_CheckedChanged(object sender, EventArgs e) - { - Properties.Settings.Default.track_client_windows = option_track_client_windows.Checked; - Properties.Settings.Default.Save(); - refresh_thumbnails(); - } - - - private void opacity_bar_Scroll(object sender, ScrollEventArgs e) - { - // fire off opacity change - Properties.Settings.Default.opacity = Math.Min((float)e.NewValue / 100.0f, 1.0f); - Properties.Settings.Default.Save(); - refresh_thumbnails(); - } - - - private void OnMinimized(EventArgs e) - { - if (Minimized != null && Properties.Settings.Default.minimizeToTray) - { - this.Hide(); - } - else if (Minimized != null && !Properties.Settings.Default.minimizeToTray) - { - Minimized(this, e); - } - } - - private void OnMaximized(EventArgs e) - { - if (Maximized != null) - { - Maximized(this, e); - } - } - - private void OnRestored(EventArgs e) - { - if (Restored != null) - { - Restored(this, e); - } - } - - protected override void WndProc(ref Message m) - { - switch (m.Msg) - { - case WM_SIZE: - switch (m.WParam.ToInt32()) - { - case SIZE_RESTORED: - OnRestored(EventArgs.Empty); - break; - case SIZE_MINIMIZED: - OnMinimized(EventArgs.Empty); - break; - case SIZE_MAXIMIZED: - OnMaximized(EventArgs.Empty); - break; - } - break; - default: - break; - } - base.WndProc(ref m); - } - - void MainForm_Minimized(object sender, EventArgs e) - { - // TODO: do something here - } - - private void option_minToTray_CheckedChanged(object sender, EventArgs e) - { - Properties.Settings.Default.minimizeToTray = option_minToTray.Checked; - Properties.Settings.Default.Save(); - } - - private void exitToolStripMenuItem_Click(object sender, EventArgs e) - { - Application.Exit(); - } - - private void restoreToolStripMenuItem_Click(object sender, EventArgs e) - { - if (!this.Visible) - { - this.Show(); - } - else if (Restored != null) - { - Restored(this, e); - } - else - { - this.BringToFront(); - } - } - - private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) - { - if (!this.Visible) - { - this.Show(); - } - else if (Restored != null) - { - Restored(this, e); - } - else - { - this.BringToFront(); - } - } - } + option_zoom_on_hover.Checked = Properties.Settings.Default.zoom_on_hover; + _zoomAnchorButtonMap = new Dictionary(); + _zoomAnchorButtonMap[ZoomAnchor.NW] = option_zoom_anchor_NW; + _zoomAnchorButtonMap[ZoomAnchor.N] = option_zoom_anchor_N; + _zoomAnchorButtonMap[ZoomAnchor.NE] = option_zoom_anchor_NE; + _zoomAnchorButtonMap[ZoomAnchor.W] = option_zoom_anchor_W; + _zoomAnchorButtonMap[ZoomAnchor.C] = option_zoom_anchor_C; + _zoomAnchorButtonMap[ZoomAnchor.E] = option_zoom_anchor_E; + _zoomAnchorButtonMap[ZoomAnchor.SW] = option_zoom_anchor_SW; + _zoomAnchorButtonMap[ZoomAnchor.S] = option_zoom_anchor_S; + _zoomAnchorButtonMap[ZoomAnchor.SE] = option_zoom_anchor_SE; + _zoomAnchorButtonMap[(ZoomAnchor)Properties.Settings.Default.zoom_anchor].Checked = true; + option_zoom_factor.Text = Properties.Settings.Default.zoom_amount.ToString(CultureInfo.InvariantCulture); + + option_always_on_top.Checked = Properties.Settings.Default.always_on_top; + option_hide_active.Checked = Properties.Settings.Default.hide_active; + option_hide_all_if_not_right_type.Checked = Properties.Settings.Default.hide_all; + + option_unique_layout.Checked = Properties.Settings.Default.unique_layout; + + option_sync_size.Checked = Properties.Settings.Default.sync_resize; + option_sync_size_x.Text = Properties.Settings.Default.sync_resize_x.ToString(); + option_sync_size_y.Text = Properties.Settings.Default.sync_resize_y.ToString(); + + option_show_thumbnail_frames.Checked = Properties.Settings.Default.show_thumb_frames; + + option_show_overlay.Checked = Properties.Settings.Default.show_overlay; + + option_track_client_windows.Checked = Properties.Settings.Default.track_client_windows; + + option_minToTray.Checked = Properties.Settings.Default.minimizeToTray; + + // disable/enable zoom suboptions + option_zoom_factor.Enabled = Properties.Settings.Default.zoom_on_hover; + foreach (var kv in _zoomAnchorButtonMap) + { + kv.Value.Enabled = Properties.Settings.Default.zoom_on_hover; + } + + opacity_bar.Value = Math.Min(100, (int)(100.0 * Properties.Settings.Default.opacity)); + + load_layout(); + } + + + private void spawn_and_kill_previews() + { + if (!_isInitialized) { return; } + + Process[] processes = Process.GetProcessesByName("ExeFile"); + List processHandles = new List(); + + // pop new previews + + foreach (Process process in processes) + { + processHandles.Add(process.MainWindowHandle); + + Size sync_size = new Size(); + sync_size.Width = (int)Properties.Settings.Default.sync_resize_x; + sync_size.Height = (int)Properties.Settings.Default.sync_resize_y; + + if (!_previews.ContainsKey(process.MainWindowHandle) && process.MainWindowTitle != "") + { + _previews[process.MainWindowHandle] = new Preview(process.MainWindowHandle, "...", this, sync_size); + _previews[process.MainWindowHandle].set_render_area_size(sync_size);// TODO Remove + + // apply more thumbnail specific options + _previews[process.MainWindowHandle].MakeTopMost(Properties.Settings.Default.always_on_top); + set_thumbnail_frame_style(_previews[process.MainWindowHandle], Properties.Settings.Default.show_thumb_frames); + + // add a preview also + previews_check_listbox.BeginUpdate(); + previews_check_listbox.Items.Add(_previews[process.MainWindowHandle]); + previews_check_listbox.EndUpdate(); + + refresh_client_window_locations(process); + } + + else if (_previews.ContainsKey(process.MainWindowHandle) && process.MainWindowTitle != _previews[process.MainWindowHandle].Text) //or update the preview titles + { + _previews[process.MainWindowHandle].SetLabel(process.MainWindowTitle); + string key = _previews[process.MainWindowHandle].Text; + string value; + if (_flatLayoutShortcuts.TryGetValue(key, out value)) + { + _previews[process.MainWindowHandle].registerShortcut(value); + } + refresh_client_window_locations(process); + } + + if (process.MainWindowHandle == DwmApiNativeMethods.GetForegroundWindow()) + { + _activeClientHandle = process.MainWindowHandle; + _activeClientTitle = process.MainWindowTitle; + } + + } + + // clean up old previews + List to_be_pruned = new List(); + foreach (IntPtr processHandle in _previews.Keys) + { + if (!(processHandles.Contains(processHandle))) + { + to_be_pruned.Add(processHandle); + } + } + + foreach (IntPtr processHandle in to_be_pruned) + { + previews_check_listbox.BeginUpdate(); + previews_check_listbox.Items.Remove(_previews[processHandle]); + previews_check_listbox.EndUpdate(); + + _previews[processHandle].overlay.Close(); + _previews[processHandle].Close(); + _previews.Remove(processHandle); + } + + previews_check_listbox.Update(); + + } + + private void refresh_client_window_locations(Process process) + { + if (Properties.Settings.Default.track_client_windows && _clientLayout.ContainsKey(process.MainWindowTitle)) + { + GuiNativeMethods.MoveWindow(process.MainWindowHandle, _clientLayout[process.MainWindowTitle].X, + _clientLayout[process.MainWindowTitle].Y, _clientLayout[process.MainWindowTitle].Width, + _clientLayout[process.MainWindowTitle].Height, true); + } + } + + + private string remove_nonconform_xml_characters(string entry) + { + foreach (var kv in _xmlBadToOkChars) + { + entry = entry.Replace(kv.Key, kv.Value); + } + return entry; + } + + private string restore_nonconform_xml_characters(string entry) + { + foreach (var kv in _xmlBadToOkChars) + { + entry = entry.Replace(kv.Value, kv.Key); + } + return entry; + } + + private XElement MakeXElement(string input) + { + string clean = remove_nonconform_xml_characters(input).Replace(" ", "_"); + return new XElement(clean); + } + + private string ParseXElement(XElement input) + { + return restore_nonconform_xml_characters(input.Name.ToString()).Replace("_", " "); + } + + private void load_layout() + { + if (File.Exists("layout.xml")) + { + XElement rootElement = XElement.Load("layout.xml"); + foreach (var el in rootElement.Elements()) + { + Dictionary inner = new Dictionary(); + foreach (var inner_el in el.Elements()) + { + inner[ParseXElement(inner_el)] = new Point(Convert.ToInt32(inner_el.Element("x")?.Value), Convert.ToInt32(inner_el.Element("y")?.Value)); + } + _uniqueLayouts[ParseXElement(el)] = inner; + } + } + + if (File.Exists("flat_layout.xml")) + { + XElement rootElement = XElement.Load("flat_layout.xml"); + foreach (var el in rootElement.Elements()) + { + _flatLayout[ParseXElement(el)] = new Point(Convert.ToInt32(el.Element("x").Value), Convert.ToInt32(el.Element("y").Value)); + _flatLayoutShortcuts[ParseXElement(el)] = ""; + + if (el.Element("shortcut") != null) + { + _flatLayoutShortcuts[ParseXElement(el)] = el.Element("shortcut").Value; + } + } + } + + if (File.Exists("client_layout.xml")) + { + XElement rootElement = XElement.Load("client_layout.xml"); + foreach (var el in rootElement.Elements()) + { + ClientLocation clientLocation = new ClientLocation(); + clientLocation.X = Convert.ToInt32(el.Element("x").Value); + clientLocation.Y = Convert.ToInt32(el.Element("y").Value); + clientLocation.Width = Convert.ToInt32(el.Element("width").Value); + clientLocation.Height = Convert.ToInt32(el.Element("height").Value); + + _clientLayout[ParseXElement(el)] = clientLocation; + } + } + } + + private void store_layout() + { + XElement el = new XElement("layouts"); + foreach (var client in _uniqueLayouts.Keys) + { + if (client == "") + { + continue; + } + XElement layout = MakeXElement(client); + foreach (var thumbnail_ in _uniqueLayouts[client]) + { + string thumbnail = thumbnail_.Key; + if (thumbnail == "" || thumbnail == "...") + { + continue; + } + XElement position = MakeXElement(thumbnail); + position.Add(new XElement("x", thumbnail_.Value.X)); + position.Add(new XElement("y", thumbnail_.Value.Y)); + layout.Add(position); + } + el.Add(layout); + } + + el.Save("layout.xml"); + + XElement el2 = new XElement("flat_layout"); + foreach (var clientKV in _flatLayout) + { + if (clientKV.Key == "" || clientKV.Key == "...") + { + continue; + } + XElement layout = MakeXElement(clientKV.Key); + layout.Add(new XElement("x", clientKV.Value.X)); + layout.Add(new XElement("y", clientKV.Value.Y)); + + string shortcut; + if (_flatLayoutShortcuts.TryGetValue(clientKV.Key, out shortcut)) + { + layout.Add(new XElement("shortcut", shortcut)); + } + el2.Add(layout); + } + + el2.Save("flat_layout.xml"); + + XElement el3 = new XElement("client_layout"); + foreach (var clientKV in _clientLayout) + { + if (clientKV.Key == "" || clientKV.Key == "...") + { + continue; + } + XElement layout = MakeXElement(clientKV.Key); + layout.Add(new XElement("x", clientKV.Value.X)); + layout.Add(new XElement("y", clientKV.Value.Y)); + layout.Add(new XElement("width", clientKV.Value.Width)); + layout.Add(new XElement("height", clientKV.Value.Height)); + el3.Add(layout); + } + + el3.Save("client_layout.xml"); + } + + private void handle_unique_layout(Preview preview, string last_known_active_window) + { + Dictionary layout; + if (_uniqueLayouts.TryGetValue(last_known_active_window, out layout)) + { + Point new_loc; + if (Properties.Settings.Default.unique_layout && layout.TryGetValue(preview.Text, out new_loc)) + { + preview.doMove(new_loc); + } + else + { + // create inner dict + layout[preview.Text] = preview.Location; + } + } + else if (last_known_active_window != "") + { + // create outer dict + _uniqueLayouts[last_known_active_window] = new Dictionary(); + _uniqueLayouts[last_known_active_window][preview.Text] = preview.Location; + } + } + + + private void update_client_locations() + { + Process[] processes = Process.GetProcessesByName("ExeFile"); + List processHandles = new List(); + + foreach (Process process in processes) + { + RECT rect = new RECT(); + GuiNativeMethods.GetWindowRect(process.MainWindowHandle, out rect); + + int left = Math.Abs(rect.Left); + int right = Math.Abs(rect.Right); + int client_width = Math.Abs(left - right); + + int top = Math.Abs(rect.Top); + int bottom = Math.Abs(rect.Bottom); + int client_height = Math.Abs(top - bottom); + + ClientLocation clientLocation = new ClientLocation(); + clientLocation.X = rect.Left; + clientLocation.Y = rect.Top; + clientLocation.Width = client_width; + clientLocation.Height = client_height; + + + _clientLayout[process.MainWindowTitle] = clientLocation; + } + } + + + public void preview_did_switch() + { + update_client_locations(); + store_layout(); //todo: check if it actually changed ... + foreach (KeyValuePair entry in _previews) + { + entry.Value.MakeTopMost(Properties.Settings.Default.always_on_top); + //makes the PreviewOverlay topmost + entry.Value.overlay.MakeTopMost(); + } + } + + + private void handle_flat_layout(Preview preview) + { + Point layout; + if (_flatLayout.TryGetValue(preview.Text, out layout)) + { + preview.doMove(layout); + } + else if (preview.Text != "") + { + _flatLayout[preview.Text] = preview.Location; + } + } + + private bool window_is_preview_or_client(IntPtr window) + { + bool active_window_is_right_type = false; + foreach (KeyValuePair entry in _previews) + { + if (entry.Key == window || entry.Value.Handle == window || this.Handle == window || entry.Value.overlay.Handle == window) + { + active_window_is_right_type = true; + } + } + return active_window_is_right_type; + } + + + private void refresh_thumbnails() + { + + IntPtr active_window = DwmApiNativeMethods.GetForegroundWindow(); + + // hide, show, resize and move + foreach (KeyValuePair entry in _previews) + { + if (!window_is_preview_or_client(active_window) && Properties.Settings.Default.hide_all) + { + entry.Value.Hide(); + } + else if (entry.Key == _activeClientHandle && Properties.Settings.Default.hide_active) + { + entry.Value.Hide(); + } + else + { + entry.Value.Show(); + if (Properties.Settings.Default.unique_layout) + { + handle_unique_layout(entry.Value, _activeClientTitle); + } + else + { + handle_flat_layout(entry.Value); + } + } + entry.Value.hover_zoom = Properties.Settings.Default.zoom_on_hover; + entry.Value.show_overlay = Properties.Settings.Default.show_overlay; + //makes the PreviewOverlay TopMost + entry.Value.overlay.MakeTopMost(); + if (!entry.Value.is_hovered_over) + { + entry.Value.Opacity = Properties.Settings.Default.opacity; + } + } + + DwmApiNativeMethods.DwmIsCompositionEnabled(); + } + + + public void syncronize_preview_size(Size sync_size) + { + if (!_isInitialized) { return; } + + if (Properties.Settings.Default.sync_resize && + Properties.Settings.Default.show_thumb_frames && + _ignoringSizeSync.ElapsedMilliseconds > 500) + { + _ignoringSizeSync.Stop(); + + option_sync_size_x.Text = sync_size.Width.ToString(); + option_sync_size_y.Text = sync_size.Height.ToString(); + + foreach (KeyValuePair entry in _previews) + { + if (entry.Value.Handle != DwmApiNativeMethods.GetForegroundWindow()) + { + entry.Value.set_render_area_size(sync_size); + } + } + + } + + } + + + public void register_preview_position(string preview_title, Point position) + { + + if (Properties.Settings.Default.unique_layout) + { + Dictionary layout; + if (_uniqueLayouts.TryGetValue(_activeClientTitle, out layout)) + { + layout[preview_title] = position; + } + else if (_activeClientTitle == "") + { + _uniqueLayouts[_activeClientTitle] = new Dictionary(); + _uniqueLayouts[_activeClientTitle][preview_title] = position; + } + } + else + { + _flatLayout[preview_title] = position; + } + + } + + + private void dispatcherTimer_Tick(object sender, EventArgs e) + { + spawn_and_kill_previews(); + refresh_thumbnails(); + if (_ignoringSizeSync.ElapsedMilliseconds > 500) { _ignoringSizeSync.Stop(); }; + + if (DwmApiNativeMethods.DwmIsCompositionEnabled()) + { + aero_status_label.Text = "AERO is ON"; + aero_status_label.ForeColor = Color.Black; + } + else + { + aero_status_label.Text = "AERO is OFF"; + aero_status_label.ForeColor = Color.Red; + } + + } + + + private void option_hide_all_if_noneve_CheckedChanged(object sender, EventArgs e) + { + Properties.Settings.Default.hide_all = option_hide_all_if_not_right_type.Checked; + Properties.Settings.Default.Save(); + refresh_thumbnails(); + } + + + private void option_unique_layout_CheckedChanged(object sender, EventArgs e) + { + Properties.Settings.Default.unique_layout = option_unique_layout.Checked; + Properties.Settings.Default.Save(); + refresh_thumbnails(); + } + + + private void option_hide_active_CheckedChanged(object sender, EventArgs e) + { + Properties.Settings.Default.hide_active = option_hide_active.Checked; + Properties.Settings.Default.Save(); + refresh_thumbnails(); + } + + + private void option_sync_size_CheckedChanged(object sender, EventArgs e) + { + Properties.Settings.Default.sync_resize = option_sync_size.Checked; + Properties.Settings.Default.Save(); + refresh_thumbnails(); + } + + + private void parse_size_entry() + { + UInt32 x = 0, y = 0; + + try + { + y = Convert.ToUInt32(option_sync_size_y.Text); + x = Convert.ToUInt32(option_sync_size_x.Text); + } + catch (System.FormatException) + { + return; + } + + if (x < 64 || y < 64) + { + return; + } + + Properties.Settings.Default.sync_resize_y = y; + Properties.Settings.Default.sync_resize_x = x; + Properties.Settings.Default.Save(); + + // resize + syncronize_preview_size(new Size((int)Properties.Settings.Default.sync_resize_x, + (int)Properties.Settings.Default.sync_resize_y)); + } + + + private void option_sync_size_x_TextChanged(object sender, EventArgs e) + { + parse_size_entry(); + } + + + private void option_sync_size_y_TextChanged(object sender, EventArgs e) + { + parse_size_entry(); + } + + + private void option_always_on_top_CheckedChanged(object sender, EventArgs e) + { + Properties.Settings.Default.always_on_top = option_always_on_top.Checked; + Properties.Settings.Default.Save(); + refresh_thumbnails(); + } + + + void set_thumbnail_frame_style(Preview preview, bool show_frames) + { + if (show_frames) + { + preview.FormBorderStyle = FormBorderStyle.SizableToolWindow; + } + else + { + preview.FormBorderStyle = FormBorderStyle.None; + } + } + + private void option_show_thumbnail_frames_CheckedChanged(object sender, EventArgs e) + { + Properties.Settings.Default.show_thumb_frames = option_show_thumbnail_frames.Checked; + Properties.Settings.Default.Save(); + + if (Properties.Settings.Default.show_thumb_frames) + { + _ignoringSizeSync.Stop(); + _ignoringSizeSync.Reset(); + _ignoringSizeSync.Start(); + } + + foreach (var thumbnail in _previews) + { + set_thumbnail_frame_style(thumbnail.Value, Properties.Settings.Default.show_thumb_frames); + } + + } + + + private void list_running_clients_SelectedIndexChanged(object sender, EventArgs e) { } + + + private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + string url = "https://bitbucket.org/ulph/eve-o-preview-git"; + ProcessStartInfo sInfo = new ProcessStartInfo(new Uri(url).AbsoluteUri); + Process.Start(sInfo); + } + + + private void previewToyMainBindingSource_CurrentChanged(object sender, EventArgs e) + { + + } + + private void option_zoom_on_hover_CheckedChanged(object sender, EventArgs e) + { + Properties.Settings.Default.zoom_on_hover = option_zoom_on_hover.Checked; + Properties.Settings.Default.Save(); + refresh_thumbnails(); + option_zoom_factor.Enabled = Properties.Settings.Default.zoom_on_hover; + if (_isInitialized) + { + foreach (var kv in _zoomAnchorButtonMap) + { + kv.Value.Enabled = Properties.Settings.Default.zoom_on_hover; + } + } + } + + private void option_show_overlay_CheckedChanged(object sender, EventArgs e) + { + Properties.Settings.Default.show_overlay = option_show_overlay.Checked; + Properties.Settings.Default.Save(); + refresh_thumbnails(); + } + + + private void handle_zoom_anchor_setting() + { + foreach (var kv in _zoomAnchorButtonMap) + { + if (kv.Value.Checked == true) + Properties.Settings.Default.zoom_anchor = (byte)kv.Key; + } + } + + private void option_zoom_anchor_X_CheckedChanged(object sender, EventArgs e) + { + handle_zoom_anchor_setting(); + Properties.Settings.Default.Save(); + } + + private void option_zoom_factor_TextChanged(object sender, EventArgs e) + { + try + { + float tmp = (float)Convert.ToDouble(option_zoom_factor.Text); + if (tmp < 1) + { + tmp = 1; + } + else if (tmp > 10) + { + tmp = 10; + } + Properties.Settings.Default.zoom_amount = tmp; + option_zoom_factor.Text = tmp.ToString(); + Properties.Settings.Default.Save(); + } + catch + { + // do naught + } + } + + private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e) + { + refresh_thumbnails(); + } + + private void checkedListBox1_SelectedIndexChanged2(object sender, EventArgs e) + { + System.Windows.Forms.ItemCheckEventArgs arg = (System.Windows.Forms.ItemCheckEventArgs)e; + ((Preview)this.previews_check_listbox.Items[arg.Index]).MakeHidden(arg.NewValue == System.Windows.Forms.CheckState.Checked); + refresh_thumbnails(); + } + + private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e) + { + + } + + private void checkBox1_CheckedChanged(object sender, EventArgs e) + { + Properties.Settings.Default.track_client_windows = option_track_client_windows.Checked; + Properties.Settings.Default.Save(); + refresh_thumbnails(); + } + + + private void opacity_bar_Scroll(object sender, ScrollEventArgs e) + { + // fire off opacity change + Properties.Settings.Default.opacity = Math.Min((float)e.NewValue / 100.0f, 1.0f); + Properties.Settings.Default.Save(); + refresh_thumbnails(); + } + + + private void OnMinimized(EventArgs e) + { + if (Minimized != null && Properties.Settings.Default.minimizeToTray) + { + this.Hide(); + } + else if (Minimized != null && !Properties.Settings.Default.minimizeToTray) + { + Minimized(this, e); + } + } + + private void OnMaximized(EventArgs e) + { + if (Maximized != null) + { + Maximized(this, e); + } + } + + private void OnRestored(EventArgs e) + { + Restored?.Invoke(this, e); + } + + protected override void WndProc(ref Message m) + { + switch (m.Msg) + { + case GuiNativeMethods.WM_SIZE: + switch (m.WParam.ToInt32()) + { + case GuiNativeMethods.SIZE_RESTORED: + OnRestored(EventArgs.Empty); + break; + case GuiNativeMethods.SIZE_MINIMIZED: + OnMinimized(EventArgs.Empty); + break; + case GuiNativeMethods.SIZE_MAXIMIZED: + OnMaximized(EventArgs.Empty); + break; + } + break; + } + + base.WndProc(ref m); + } + + void MainForm_Minimized(object sender, EventArgs e) + { + // TODO: do something here + } + + private void option_minToTray_CheckedChanged(object sender, EventArgs e) + { + Properties.Settings.Default.minimizeToTray = option_minToTray.Checked; + Properties.Settings.Default.Save(); + } + + private void exitToolStripMenuItem_Click(object sender, EventArgs e) + { + Application.Exit(); + } + + private void restoreToolStripMenuItem_Click(object sender, EventArgs e) + { + if (!this.Visible) + { + this.Show(); + } + else if (Restored != null) + { + Restored(this, e); + } + else + { + this.BringToFront(); + } + } + + private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) + { + if (!this.Visible) + { + this.Show(); + } + else if (Restored != null) + { + Restored(this, e); + } + else + { + this.BringToFront(); + } + } + } } \ No newline at end of file diff --git a/Eve-O-Preview/GUI/ZoomAnchor.cs b/Eve-O-Preview/GUI/ZoomAnchor.cs new file mode 100644 index 0000000..ebfcb97 --- /dev/null +++ b/Eve-O-Preview/GUI/ZoomAnchor.cs @@ -0,0 +1,15 @@ +namespace EveOPreview +{ + public enum ZoomAnchor + { + NW = 0, + N, + NE, + W, + C, + E, + SW, + S, + SE + } +} \ No newline at end of file diff --git a/Eve-O-Preview/Preview/Preview.Designer.cs b/Eve-O-Preview/Preview/Preview.Designer.cs index c6d52dc..9a83820 100644 --- a/Eve-O-Preview/Preview/Preview.Designer.cs +++ b/Eve-O-Preview/Preview/Preview.Designer.cs @@ -14,53 +14,53 @@ namespace EveOPreview /// private void InitializeComponent() { - this.render_area = new System.Windows.Forms.PictureBox(); - ((System.ComponentModel.ISupportInitialize)(this.render_area)).BeginInit(); - this.SuspendLayout(); - // - // render_area - // - this.render_area.BackColor = System.Drawing.Color.Transparent; - this.render_area.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; - this.render_area.Cursor = System.Windows.Forms.Cursors.Hand; - this.render_area.Dock = System.Windows.Forms.DockStyle.Fill; - this.render_area.Location = new System.Drawing.Point(0, 0); - this.render_area.Margin = new System.Windows.Forms.Padding(0); - this.render_area.Name = "render_area"; - this.render_area.Size = new System.Drawing.Size(153, 89); - this.render_area.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.render_area.TabIndex = 0; - this.render_area.TabStop = false; - this.render_area.MouseUp += new System.Windows.Forms.MouseEventHandler(this.render_area_Click); - // - // Preview - // - this.AccessibleRole = System.Windows.Forms.AccessibleRole.None; - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(153, 89); - this.ControlBox = false; - this.Controls.Add(this.render_area); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; - this.MaximizeBox = false; - this.MinimizeBox = false; - this.MinimumSize = new System.Drawing.Size(64, 64); - this.Name = "Preview"; - this.Opacity = 0.1D; - this.ShowIcon = false; - this.ShowInTaskbar = false; - this.Text = "Preview"; - this.TopMost = true; - this.Load += new System.EventHandler(this.Preview_Load); - ((System.ComponentModel.ISupportInitialize)(this.render_area)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); + this.RenderAreaPictureBox = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)(this.RenderAreaPictureBox)).BeginInit(); + this.SuspendLayout(); + // + // RenderAreaPictureBox + // + this.RenderAreaPictureBox.BackColor = System.Drawing.Color.Transparent; + this.RenderAreaPictureBox.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; + this.RenderAreaPictureBox.Cursor = System.Windows.Forms.Cursors.Hand; + this.RenderAreaPictureBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.RenderAreaPictureBox.Location = new System.Drawing.Point(0, 0); + this.RenderAreaPictureBox.Margin = new System.Windows.Forms.Padding(0); + this.RenderAreaPictureBox.Name = "RenderAreaPictureBox"; + this.RenderAreaPictureBox.Size = new System.Drawing.Size(153, 89); + this.RenderAreaPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.RenderAreaPictureBox.TabIndex = 0; + this.RenderAreaPictureBox.TabStop = false; + this.RenderAreaPictureBox.MouseUp += new System.Windows.Forms.MouseEventHandler(this.render_area_Click); + // + // Preview + // + this.AccessibleRole = System.Windows.Forms.AccessibleRole.None; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(153, 89); + this.ControlBox = false; + this.Controls.Add(this.RenderAreaPictureBox); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.MinimumSize = new System.Drawing.Size(64, 64); + this.Name = "Preview"; + this.Opacity = 0.1D; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.Text = "Preview"; + this.TopMost = true; + this.Load += new System.EventHandler(this.Preview_Load); + ((System.ComponentModel.ISupportInitialize)(this.RenderAreaPictureBox)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); } #endregion - private System.Windows.Forms.PictureBox render_area; + private System.Windows.Forms.PictureBox RenderAreaPictureBox; } diff --git a/Eve-O-Preview/Preview/Preview.cs b/Eve-O-Preview/Preview/Preview.cs index 53823b7..23806db 100644 --- a/Eve-O-Preview/Preview/Preview.cs +++ b/Eve-O-Preview/Preview/Preview.cs @@ -4,346 +4,342 @@ using System.Windows.Forms; namespace EveOPreview { - public partial class Preview : Form - { - public bool show_overlay = true; - public bool hover_zoom = true; - public bool is_zoomed = false; - public bool is_hovered_over = false; + public partial class Preview : Form + { + public bool show_overlay = true; + public bool hover_zoom = true; + public bool is_zoomed = false; + public bool is_hovered_over = false; - private bool mouse_over_lock = false; - private Size old_size; - private Point old_position; + private bool mouse_over_lock = false; + private Size old_size; + private Point old_position; - private IntPtr m_hThumbnail; - public IntPtr sourceWindow; - private DWM_THUMBNAIL_PROPERTIES m_ThumbnailProperties; - private bool has_been_set_up = false; - private bool thumbnail_has_been_set_up = false; - private MainForm spawner; - private Hotkey hotkey; + private IntPtr m_hThumbnail; + public IntPtr sourceWindow; + private DWM_THUMBNAIL_PROPERTIES m_ThumbnailProperties; + private bool has_been_set_up = false; + private bool thumbnail_has_been_set_up = false; + private MainForm spawner; + private Hotkey hotkey; - private bool hide = false; + private bool hide = false; - public PreviewOverlay overlay; - - public void MakeHidden(bool wha) - { - hide = wha; - } - - public override string ToString() - { - return this.Text; - } + public PreviewOverlay overlay; + public Preview(IntPtr sourceWindow, String title, MainForm spawner, Size size) + { + has_been_set_up = false; - public void MakeTopMost(bool topmost) - { - this.TopMost = topmost && !(this.hide); - } + this.sourceWindow = sourceWindow; + this.spawner = spawner; - public Preview(IntPtr sourceWindow, String title, MainForm spawner, Size size) - { - has_been_set_up = false; + InitializeComponent(); - this.sourceWindow = sourceWindow; - this.spawner = spawner; + this.Text = title; - InitializeComponent(); + this.overlay = new PreviewOverlay(this); - this.Text = title; + this.RenderAreaPictureBox.MouseHover += new System.EventHandler(this.preview_MouseHover); + this.RenderAreaPictureBox.MouseLeave += new System.EventHandler(this.preview_MouseLeave); - this.overlay = new PreviewOverlay(this); + this.old_size = this.Size; + this.old_position = this.Location; - this.render_area.MouseHover += new System.EventHandler(this.preview_MouseHover); - this.render_area.MouseLeave += new System.EventHandler(this.preview_MouseLeave); + has_been_set_up = true; + } - this.old_size = this.Size; - this.old_position = this.Location; + public void MakeHidden(bool wha) + { + hide = wha; + } - has_been_set_up = true; + public override string ToString() + { + return this.Text; + } + public void MakeTopMost(bool topmost) + { + this.TopMost = topmost && !(this.hide); + } - } + public void preview_MouseHover(object sender, System.EventArgs e) + { + if (!mouse_over_lock) + { + mouse_over_lock = true; + if (hover_zoom) + doZoom(); - public void preview_MouseHover(object sender, System.EventArgs e) - { - if (!mouse_over_lock) - { - mouse_over_lock = true; - if (hover_zoom) - doZoom(); + TopMost = true; + overlay.TopMost = true; + } + this.Opacity = 1.0f; + this.is_hovered_over = true; + RefreshPreview(); + } - TopMost = true; - overlay.TopMost = true; - } - this.Opacity = 1.0f; - this.is_hovered_over = true; - RefreshPreview(); - } + protected override CreateParams CreateParams + { + get + { + var Params = base.CreateParams; + Params.ExStyle |= 0x80; + return Params; + } + } - protected override CreateParams CreateParams - { - get - { - var Params = base.CreateParams; - Params.ExStyle |= 0x80; - return Params; - } - } + public void registerShortcut(string shortcut) + { + if (shortcut == "") + return; + var cvt = new KeysConverter(); + var key = (Keys)cvt.ConvertFrom(shortcut); - public void registerShortcut(string shortcut) - { - if (shortcut == "") - return; - var cvt = new KeysConverter(); - var key = (Keys)cvt.ConvertFrom(shortcut); + Hotkey hotkey = new Hotkey(); - Hotkey hotkey = new Hotkey(); + if ((key & Keys.Shift) == Keys.Shift) + { + hotkey.Shift = true; + } + if ((key & Keys.Alt) == Keys.Alt) + { + hotkey.Alt = true; + } + if ((key & Keys.Control) == Keys.Control) + { + hotkey.Control = true; + } - if ((key & Keys.Shift) == Keys.Shift) - { - hotkey.Shift = true; - } - if ((key & Keys.Alt) == Keys.Alt) - { - hotkey.Alt = true; - } - if ((key & Keys.Control) == Keys.Control) - { - hotkey.Control = true; - } + key = key & ~Keys.Shift & ~Keys.Alt & ~Keys.Control; + hotkey.KeyCode = key; + hotkey.Register(this); + hotkey.Pressed += delegate { bring_client_to_foreground(); spawner.preview_did_switch(); }; - key = key & ~Keys.Shift & ~Keys.Alt & ~Keys.Control; - hotkey.KeyCode = key; - hotkey.Register(this); - hotkey.Pressed += delegate { bring_client_to_foreground(); spawner.preview_did_switch(); }; + this.hotkey = hotkey; + } - this.hotkey = hotkey; - } + public void doZoom() + { + if (is_zoomed) + return; - public void doZoom() - { - if (is_zoomed) - return; - - is_zoomed = true; + is_zoomed = true; - float hover_zoom_factor = Properties.Settings.Default.zoom_amount; + float hover_zoom_factor = Properties.Settings.Default.zoom_amount; - old_size = Size; - old_position = Location; + old_size = Size; + old_position = Location; - Size = new Size((int)(hover_zoom_factor * (float)Size.Width), (int)(hover_zoom_factor * (float)Size.Height)); + Size = new Size((int)(hover_zoom_factor * (float)Size.Width), (int)(hover_zoom_factor * (float)Size.Height)); - switch ((MainForm.zoom_anchor_t)Properties.Settings.Default.zoom_anchor) - { - case (MainForm.zoom_anchor_t.NW): - break; - case (MainForm.zoom_anchor_t.N): - Location = new Point(Location.X - Size.Width / 2 + old_size.Width / 2, Location.Y); - break; - case (MainForm.zoom_anchor_t.NE): - Location = new Point(Location.X - Size.Width + old_size.Width, Location.Y); - break; + switch ((ZoomAnchor)Properties.Settings.Default.zoom_anchor) + { + case (ZoomAnchor.NW): + break; + case (ZoomAnchor.N): + Location = new Point(Location.X - Size.Width / 2 + old_size.Width / 2, Location.Y); + break; + case (ZoomAnchor.NE): + Location = new Point(Location.X - Size.Width + old_size.Width, Location.Y); + break; - case (MainForm.zoom_anchor_t.W): - Location = new Point(Location.X, Location.Y - Size.Height / 2 + old_size.Height / 2); - break; - case (MainForm.zoom_anchor_t.C): - Location = new Point(Location.X - Size.Width / 2 + old_size.Width / 2, Location.Y - Size.Height / 2 + old_size.Height / 2); - break; - case (MainForm.zoom_anchor_t.E): - Location = new Point(Location.X - Size.Width + old_size.Width, Location.Y - Size.Height / 2 + old_size.Height / 2); - break; + case (ZoomAnchor.W): + Location = new Point(Location.X, Location.Y - Size.Height / 2 + old_size.Height / 2); + break; + case (ZoomAnchor.C): + Location = new Point(Location.X - Size.Width / 2 + old_size.Width / 2, Location.Y - Size.Height / 2 + old_size.Height / 2); + break; + case (ZoomAnchor.E): + Location = new Point(Location.X - Size.Width + old_size.Width, Location.Y - Size.Height / 2 + old_size.Height / 2); + break; - case (MainForm.zoom_anchor_t.SW): - Location = new Point(Location.X, Location.Y - Size.Height + old_size.Height); - break; - case (MainForm.zoom_anchor_t.S): - Location = new Point(Location.X - Size.Width / 2 + old_size.Width / 2, Location.Y - Size.Height + old_size.Height); - break; - case (MainForm.zoom_anchor_t.SE): - Location = new Point(Location.X - Size.Width + old_size.Width, Location.Y - Size.Height + old_size.Height); - break; - } - } + case (ZoomAnchor.SW): + Location = new Point(Location.X, Location.Y - Size.Height + old_size.Height); + break; + case (ZoomAnchor.S): + Location = new Point(Location.X - Size.Width / 2 + old_size.Width / 2, Location.Y - Size.Height + old_size.Height); + break; + case (ZoomAnchor.SE): + Location = new Point(Location.X - Size.Width + old_size.Width, Location.Y - Size.Height + old_size.Height); + break; + } + } - public void restoreZoom() - { - if (!is_zoomed) - return; + public void restoreZoom() + { + if (!is_zoomed) + return; - Size = old_size; - Location = old_position; - is_zoomed = false; - } + Size = old_size; + Location = old_position; + is_zoomed = false; + } - public void preview_MouseLeave(object sender, System.EventArgs e) - { - if (mouse_over_lock) - { - if (hover_zoom) - { - restoreZoom(); - } - mouse_over_lock = false; - } - this.is_hovered_over = false; - this.Opacity = Properties.Settings.Default.opacity; - RefreshPreview(); - } + public void preview_MouseLeave(object sender, System.EventArgs e) + { + if (mouse_over_lock) + { + if (hover_zoom) + { + restoreZoom(); + } + mouse_over_lock = false; + } + this.is_hovered_over = false; + this.Opacity = Properties.Settings.Default.opacity; + RefreshPreview(); + } - protected override void OnResize(EventArgs e) - { - RefreshPreview(); - base.OnResize(e); - if (has_been_set_up && !mouse_over_lock) - this.spawner.syncronize_preview_size(this.Size); - } + protected override void OnResize(EventArgs e) + { + RefreshPreview(); + base.OnResize(e); + if (has_been_set_up && !mouse_over_lock) + this.spawner.syncronize_preview_size(this.Size); + } - protected override void OnMove(EventArgs e) - { - base.OnMove(e); - if (has_been_set_up && !mouse_over_lock) - this.spawner.register_preview_position(this.Text, this.Location); + protected override void OnMove(EventArgs e) + { + base.OnMove(e); + if (has_been_set_up && !mouse_over_lock) + this.spawner.register_preview_position(this.Text, this.Location); - RefreshPreview(); - } + RefreshPreview(); + } - public void doMove(Point position) - { - if (has_been_set_up && !mouse_over_lock) - Location = position; + public void doMove(Point position) + { + if (has_been_set_up && !mouse_over_lock) + Location = position; - RefreshPreview(); - } + RefreshPreview(); + } - public void SetLabel(String label) - { - this.Text = label; - this.overlay.client_label.Text = label; - } + public void SetLabel(String label) + { + this.Text = label; + this.overlay.SetOverlayLabel(label); + } - public void RefreshPreview() - { - if (has_been_set_up) - { - if (DwmApiNativeMethods.DwmIsCompositionEnabled()) - { - if (thumbnail_has_been_set_up == false) - { - this.SetUpThumbnail(); - } - m_ThumbnailProperties.rcDestination = new RECT(0, 0, ClientRectangle.Right, ClientRectangle.Bottom); - DwmApiNativeMethods.DwmUpdateThumbnailProperties(m_hThumbnail, m_ThumbnailProperties); - } - else - { - thumbnail_has_been_set_up = false; - } + public void RefreshPreview() + { + if (has_been_set_up) + { + if (DwmApiNativeMethods.DwmIsCompositionEnabled()) + { + if (thumbnail_has_been_set_up == false) + { + this.SetUpThumbnail(); + } + m_ThumbnailProperties.rcDestination = new RECT(0, 0, ClientRectangle.Right, ClientRectangle.Bottom); + DwmApiNativeMethods.DwmUpdateThumbnailProperties(m_hThumbnail, m_ThumbnailProperties); + } + else + { + thumbnail_has_been_set_up = false; + } - Size overlay_size = this.render_area.Size; - overlay_size.Width -= 2 * 5; - overlay_size.Height -= 2 * 5; + Size overlay_size = this.RenderAreaPictureBox.Size; + overlay_size.Width -= 2 * 5; + overlay_size.Height -= 2 * 5; - Point overlay_location = this.Location; - overlay_location.X += 5 + (this.Size.Width - this.render_area.Size.Width) / 2; - overlay_location.Y += 5 + (this.Size.Height - this.render_area.Size.Height) - (this.Size.Width - this.render_area.Size.Width) / 2; + Point overlay_location = this.Location; + overlay_location.X += 5 + (this.Size.Width - this.RenderAreaPictureBox.Size.Width) / 2; + overlay_location.Y += 5 + (this.Size.Height - this.RenderAreaPictureBox.Size.Height) - (this.Size.Width - this.RenderAreaPictureBox.Size.Width) / 2; - this.overlay.Size = overlay_size; - this.overlay.Location = overlay_location; + this.overlay.Size = overlay_size; + this.overlay.Location = overlay_location; - } - } + } + } - new public void Show() - { - if (!hide) - { - base.Show(); - if (show_overlay) - this.overlay.Show(); - else - this.overlay.Hide(); - } - else - { - this.Hide(); - this.overlay.Hide(); - } - } + new public void Show() + { + if (!hide) + { + base.Show(); + if (show_overlay) + this.overlay.Show(); + else + this.overlay.Hide(); + } + else + { + this.Hide(); + this.overlay.Hide(); + } + } - new public void Hide() - { - base.Hide(); - this.overlay.Hide(); - } + new public void Hide() + { + base.Hide(); + this.overlay.Hide(); + } - private void SetUpThumbnail() - { - if (DwmApiNativeMethods.DwmIsCompositionEnabled() && !thumbnail_has_been_set_up) - { - m_hThumbnail = DwmApiNativeMethods.DwmRegisterThumbnail(this.Handle, sourceWindow); + private void SetUpThumbnail() + { + if (DwmApiNativeMethods.DwmIsCompositionEnabled() && !thumbnail_has_been_set_up) + { + m_hThumbnail = DwmApiNativeMethods.DwmRegisterThumbnail(this.Handle, sourceWindow); - m_ThumbnailProperties = new DWM_THUMBNAIL_PROPERTIES(); - m_ThumbnailProperties.dwFlags = DWM_THUMBNAIL_PROPERTIES.DWM_TNP_VISIBLE - + DWM_THUMBNAIL_PROPERTIES.DWM_TNP_OPACITY - + DWM_THUMBNAIL_PROPERTIES.DWM_TNP_RECTDESTINATION - + DWM_THUMBNAIL_PROPERTIES.DWM_TNP_SOURCECLIENTAREAONLY; - m_ThumbnailProperties.opacity = 255; - m_ThumbnailProperties.fVisible = true; - m_ThumbnailProperties.fSourceClientAreaOnly = true; - m_ThumbnailProperties.rcDestination = new RECT(0, 0, ClientRectangle.Right, ClientRectangle.Bottom); + m_ThumbnailProperties = new DWM_THUMBNAIL_PROPERTIES(); + m_ThumbnailProperties.dwFlags = DWM_THUMBNAIL_PROPERTIES.DWM_TNP_VISIBLE + + DWM_THUMBNAIL_PROPERTIES.DWM_TNP_OPACITY + + DWM_THUMBNAIL_PROPERTIES.DWM_TNP_RECTDESTINATION + + DWM_THUMBNAIL_PROPERTIES.DWM_TNP_SOURCECLIENTAREAONLY; + m_ThumbnailProperties.opacity = 255; + m_ThumbnailProperties.fVisible = true; + m_ThumbnailProperties.fSourceClientAreaOnly = true; + m_ThumbnailProperties.rcDestination = new RECT(0, 0, ClientRectangle.Right, ClientRectangle.Bottom); - DwmApiNativeMethods.DwmUpdateThumbnailProperties(m_hThumbnail, m_ThumbnailProperties); + DwmApiNativeMethods.DwmUpdateThumbnailProperties(m_hThumbnail, m_ThumbnailProperties); - thumbnail_has_been_set_up = true; - } - } + thumbnail_has_been_set_up = true; + } + } - private void Preview_Load(object sender, EventArgs e) - { + private void Preview_Load(object sender, EventArgs e) + { - } + } - public void bring_client_to_foreground() - { - DwmApiNativeMethods.SetForegroundWindow(sourceWindow); - int style = DwmApiNativeMethods.GetWindowLong(sourceWindow, DwmApiNativeMethods.GWL_STYLE); - if ((style & DwmApiNativeMethods.WS_MAXIMIZE) == DwmApiNativeMethods.WS_MAXIMIZE) - { - //It's maximized - } - else if ((style & DwmApiNativeMethods.WS_MINIMIZE) == DwmApiNativeMethods.WS_MINIMIZE) - { - DwmApiNativeMethods.ShowWindowAsync(sourceWindow, DwmApiNativeMethods.SW_SHOWNORMAL); - } - } + public void bring_client_to_foreground() + { + DwmApiNativeMethods.SetForegroundWindow(sourceWindow); + int style = DwmApiNativeMethods.GetWindowLong(sourceWindow, DwmApiNativeMethods.GWL_STYLE); + if ((style & DwmApiNativeMethods.WS_MAXIMIZE) == DwmApiNativeMethods.WS_MAXIMIZE) + { + //It's maximized + } + else if ((style & DwmApiNativeMethods.WS_MINIMIZE) == DwmApiNativeMethods.WS_MINIMIZE) + { + DwmApiNativeMethods.ShowWindowAsync(sourceWindow, DwmApiNativeMethods.SW_SHOWNORMAL); + } + } - public void render_area_Click(object sender, MouseEventArgs e) - { - if (e.Button == MouseButtons.Left) - { - bring_client_to_foreground(); - spawner.preview_did_switch(); - } - if (e.Button == MouseButtons.Right) - { - // do smth cool? - } - if (e.Button == MouseButtons.Middle) - { - // do smth cool? - } - } + public void render_area_Click(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Left) + { + bring_client_to_foreground(); + spawner.preview_did_switch(); + } + if (e.Button == MouseButtons.Right) + { + // do smth cool? + } + if (e.Button == MouseButtons.Middle) + { + // do smth cool? + } + } - public void set_render_area_size(Size size) - { - this.Size = size; - } - - } + public void set_render_area_size(Size size) + { + this.Size = size; + } + } } \ No newline at end of file diff --git a/Eve-O-Preview/Preview/PreviewOverlay.Designer.cs b/Eve-O-Preview/Preview/PreviewOverlay.Designer.cs index c02c9a0..d49b54f 100644 --- a/Eve-O-Preview/Preview/PreviewOverlay.Designer.cs +++ b/Eve-O-Preview/Preview/PreviewOverlay.Designer.cs @@ -28,66 +28,63 @@ /// private void InitializeComponent() { - this.overlay_area = new System.Windows.Forms.PictureBox(); - this.client_label = new System.Windows.Forms.Label(); - ((System.ComponentModel.ISupportInitialize)(this.overlay_area)).BeginInit(); - this.SuspendLayout(); - // - // overlay_area - // - this.overlay_area.BackColor = System.Drawing.Color.Transparent; - this.overlay_area.Cursor = System.Windows.Forms.Cursors.Hand; - this.overlay_area.Dock = System.Windows.Forms.DockStyle.Fill; - this.overlay_area.Location = new System.Drawing.Point(0, 0); - this.overlay_area.Name = "overlay_area"; - this.overlay_area.Size = new System.Drawing.Size(284, 262); - this.overlay_area.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.overlay_area.TabIndex = 0; - this.overlay_area.TabStop = false; - this.overlay_area.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_Click); - // - // client_label - // - this.client_label.AutoSize = true; - this.client_label.Dock = System.Windows.Forms.DockStyle.Top; - this.client_label.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.client_label.ForeColor = System.Drawing.Color.DarkGray; - this.client_label.Location = new System.Drawing.Point(0, 0); - this.client_label.Name = "client_label"; - this.client_label.Size = new System.Drawing.Size(25, 13); - this.client_label.TabIndex = 1; - this.client_label.Text = "..."; - this.client_label.Click += new System.EventHandler(this.client_label_Click); - // - // PreviewOverlay - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.BackColor = System.Drawing.Color.Black; - this.ClientSize = new System.Drawing.Size(284, 262); - this.ControlBox = false; - this.Controls.Add(this.client_label); - this.Controls.Add(this.overlay_area); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "PreviewOverlay"; - this.ShowIcon = false; - this.ShowInTaskbar = false; - this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; - this.Text = "PreviewOverlay"; - this.TransparencyKey = System.Drawing.Color.Black; - this.Load += new System.EventHandler(this.PreviewOverlay_Load); - ((System.ComponentModel.ISupportInitialize)(this.overlay_area)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); + System.Windows.Forms.PictureBox OverlayAreaPictureBox; + this.OverlayLabel = new System.Windows.Forms.Label(); + OverlayAreaPictureBox = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)(OverlayAreaPictureBox)).BeginInit(); + this.SuspendLayout(); + // + // OverlayAreaPictureBox + // + OverlayAreaPictureBox.BackColor = System.Drawing.Color.Transparent; + OverlayAreaPictureBox.Cursor = System.Windows.Forms.Cursors.Hand; + OverlayAreaPictureBox.Dock = System.Windows.Forms.DockStyle.Fill; + OverlayAreaPictureBox.Location = new System.Drawing.Point(0, 0); + OverlayAreaPictureBox.Name = "OverlayAreaPictureBox"; + OverlayAreaPictureBox.Size = new System.Drawing.Size(284, 262); + OverlayAreaPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + OverlayAreaPictureBox.TabIndex = 0; + OverlayAreaPictureBox.TabStop = false; + OverlayAreaPictureBox.MouseUp += new System.Windows.Forms.MouseEventHandler(this.OverlayArea_Click); + // + // OverlayLabel + // + this.OverlayLabel.AutoSize = true; + this.OverlayLabel.Dock = System.Windows.Forms.DockStyle.Top; + this.OverlayLabel.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.OverlayLabel.ForeColor = System.Drawing.Color.DarkGray; + this.OverlayLabel.Location = new System.Drawing.Point(0, 0); + this.OverlayLabel.Name = "OverlayLabel"; + this.OverlayLabel.Size = new System.Drawing.Size(25, 13); + this.OverlayLabel.TabIndex = 1; + this.OverlayLabel.Text = "..."; + // + // PreviewOverlay + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.Black; + this.ClientSize = new System.Drawing.Size(284, 262); + this.ControlBox = false; + this.Controls.Add(this.OverlayLabel); + this.Controls.Add(OverlayAreaPictureBox); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "PreviewOverlay"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.Text = "PreviewOverlay"; + this.TransparencyKey = System.Drawing.Color.Black; + ((System.ComponentModel.ISupportInitialize)(OverlayAreaPictureBox)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); } - #endregion + #endregion - public System.Windows.Forms.PictureBox overlay_area; - public System.Windows.Forms.Label client_label; - - } + private System.Windows.Forms.Label OverlayLabel; + } } \ No newline at end of file diff --git a/Eve-O-Preview/Preview/PreviewOverlay.cs b/Eve-O-Preview/Preview/PreviewOverlay.cs index b1f0aab..b3a11d5 100644 --- a/Eve-O-Preview/Preview/PreviewOverlay.cs +++ b/Eve-O-Preview/Preview/PreviewOverlay.cs @@ -1,55 +1,40 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +using System.Windows.Forms; namespace EveOPreview { - public partial class PreviewOverlay : Form - { - private Preview parent; - private Color original_color; - public PreviewOverlay(Preview parent) - { - this.parent = parent; - InitializeComponent(); - original_color = overlay_area.BackColor; - } + public partial class PreviewOverlay : Form + { + private readonly Preview _parent; - private void PreviewOverlay_Load(object sender, EventArgs e) - { + public PreviewOverlay(Preview parent) + { + this._parent = parent; + InitializeComponent(); + } - } + private void OverlayArea_Click(object sender, MouseEventArgs e) + { + this._parent.render_area_Click(sender, e); + } - private void pictureBox1_Click(object sender, MouseEventArgs e) - { - this.parent.render_area_Click(sender, e); - } + public void MakeTopMost() + { + this.TopMost = true; + } - public void makeTopMost() - { - this.TopMost = true; - } + public void SetOverlayLabel(string label) + { + this.OverlayLabel.Text = label; + } - private void client_label_Click(object sender, EventArgs e) - { - - } - - protected override CreateParams CreateParams - { - get - { - var Params = base.CreateParams; - Params.ExStyle |= 0x80; - return Params; - } - } - - } + protected override CreateParams CreateParams + { + get + { + var Params = base.CreateParams; + Params.ExStyle |= 0x80; + return Params; + } + } + } } diff --git a/Eve-O-Preview/Preview/PreviewOverlay.resx b/Eve-O-Preview/Preview/PreviewOverlay.resx index 29dcb1b..6a0cc5e 100644 --- a/Eve-O-Preview/Preview/PreviewOverlay.resx +++ b/Eve-O-Preview/Preview/PreviewOverlay.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + False + \ No newline at end of file diff --git a/Eve-O-Preview/Properties/AssemblyInfo.cs b/Eve-O-Preview/Properties/AssemblyInfo.cs index d272cb5..5d9a712 100644 --- a/Eve-O-Preview/Properties/AssemblyInfo.cs +++ b/Eve-O-Preview/Properties/AssemblyInfo.cs @@ -1,16 +1,18 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -[assembly: AssemblyTitle("PreviewToy")] +[assembly: AssemblyTitle("EVE-O Preview")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("?")] -[assembly: AssemblyProduct("PreviewToy")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("EVE-O Preview")] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] [assembly: Guid("04f08f8d-9e98-423b-acdb-4effb31c0d35")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.18.0.0")] +[assembly: AssemblyFileVersion("1.18.0.0")] + +// Provide your own key name to build the app locally +[assembly: AssemblyKeyName("Phrynohyas")] diff --git a/Eve-O-Preview/preview toy_TemporaryKey.pfx b/Eve-O-Preview/preview toy_TemporaryKey.pfx deleted file mode 100644 index 007e110..0000000 Binary files a/Eve-O-Preview/preview toy_TemporaryKey.pfx and /dev/null differ