GUI cleanup

This commit is contained in:
Anton Kasyanov
2016-05-09 20:50:31 +03:00
parent 793fc8cd06
commit 95b10a352c
11 changed files with 69 additions and 73 deletions

View File

@@ -102,25 +102,25 @@
<Compile Include="DwmAPI\RECT.cs" /> <Compile Include="DwmAPI\RECT.cs" />
<Compile Include="Hotkeys\Hotkey.cs" /> <Compile Include="Hotkeys\Hotkey.cs" />
<Compile Include="Hotkeys\HotkeyNativeMethods.cs" /> <Compile Include="Hotkeys\HotkeyNativeMethods.cs" />
<Compile Include="PreviewHandler.cs"> <Compile Include="GUI\MainForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="PreviewHandler.Designer.cs"> <Compile Include="GUI\MainForm.Designer.cs">
<DependentUpon>PreviewHandler.cs</DependentUpon> <DependentUpon>MainForm.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="PreviewOverlay.cs"> <Compile Include="Preview\PreviewOverlay.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="PreviewOverlay.Designer.cs"> <Compile Include="Preview\PreviewOverlay.Designer.cs">
<DependentUpon>PreviewOverlay.cs</DependentUpon> <DependentUpon>PreviewOverlay.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="PreviewHandler.resx"> <EmbeddedResource Include="GUI\MainForm.resx">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<DependentUpon>PreviewHandler.cs</DependentUpon> <DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="PreviewOverlay.resx"> <EmbeddedResource Include="Preview\PreviewOverlay.resx">
<DependentUpon>PreviewOverlay.cs</DependentUpon> <DependentUpon>PreviewOverlay.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
@@ -128,7 +128,7 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Preview.resx"> <EmbeddedResource Include="Preview\Preview.resx">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<DependentUpon>Preview.cs</DependentUpon> <DependentUpon>Preview.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
@@ -151,10 +151,10 @@
<DependentUpon>Settings.settings</DependentUpon> <DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput> <DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile> </Compile>
<Compile Include="Preview.cs"> <Compile Include="Preview\Preview.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="Preview.Designer.cs"> <Compile Include="Preview\Preview.Designer.cs">
<DependentUpon>Preview.cs</DependentUpon> <DependentUpon>Preview.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="DwmAPI\DwmApiNativeMethods.cs" /> <Compile Include="DwmAPI\DwmApiNativeMethods.cs" />

View File

@@ -8,7 +8,7 @@ using System.Diagnostics;
namespace EveOPreview namespace EveOPreview
{ {
partial class PreviewToyHandler partial class MainForm
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
@@ -37,7 +37,7 @@ namespace EveOPreview
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container(); this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PreviewToyHandler)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.option_hide_active = new System.Windows.Forms.CheckBox(); this.option_hide_active = new System.Windows.Forms.CheckBox();
this.option_hide_all_if_not_right_type = new System.Windows.Forms.CheckBox(); this.option_hide_all_if_not_right_type = new System.Windows.Forms.CheckBox();
this.option_unique_layout = new System.Windows.Forms.CheckBox(); this.option_unique_layout = new System.Windows.Forms.CheckBox();
@@ -566,7 +566,7 @@ namespace EveOPreview
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Margin = new System.Windows.Forms.Padding(0); this.Margin = new System.Windows.Forms.Padding(0);
this.MaximizeBox = false; this.MaximizeBox = false;
this.Name = "PreviewToyHandler"; this.Name = "MainForm";
this.Text = "EVE Online previewer"; this.Text = "EVE Online previewer";
this.TopMost = true; this.TopMost = true;
this.WindowState = System.Windows.Forms.FormWindowState.Minimized; this.WindowState = System.Windows.Forms.FormWindowState.Minimized;

View File

@@ -1,23 +1,16 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing.Text;
using System.Windows.Threading; using System.Windows.Threading;
using System.Xml.Linq; using System.Xml.Linq;
using System.Linq;
using System.IO; using System.IO;
namespace EveOPreview namespace EveOPreview
{ {
public partial class MainForm : Form
public partial class PreviewToyHandler : Form
{ {
private const int WM_SIZE = 5; private const int WM_SIZE = 5;
private const int SIZE_RESTORED = 0; private const int SIZE_RESTORED = 0;
@@ -31,11 +24,11 @@ namespace EveOPreview
public event EventHandler Restored; public event EventHandler Restored;
private Dictionary<IntPtr, Preview> previews; private readonly Dictionary<IntPtr, Preview> _previews;
private DispatcherTimer dispatcherTimer; private DispatcherTimer _dispatcherTimer;
private IntPtr active_client_handle = (IntPtr)0; private IntPtr _activeClientHandle;
private String active_client_title = ""; private String _activeClientTitle;
private Dictionary<String, Dictionary<String, Point>> unique_layouts; private Dictionary<String, Dictionary<String, Point>> unique_layouts;
private Dictionary<String, Point> flat_layout; private Dictionary<String, Point> flat_layout;
@@ -85,11 +78,14 @@ namespace EveOPreview
private Dictionary<zoom_anchor_t, RadioButton> zoom_anchor_button_map; private Dictionary<zoom_anchor_t, RadioButton> zoom_anchor_button_map;
public PreviewToyHandler() public MainForm()
{ {
is_initialized = false; is_initialized = false;
previews = new Dictionary<IntPtr, Preview>(); this._activeClientHandle = (IntPtr)0;
this._activeClientTitle = "";
_previews = new Dictionary<IntPtr, Preview>();
xml_bad_to_ok_chars = new Dictionary<string, string>(); xml_bad_to_ok_chars = new Dictionary<string, string>();
xml_bad_to_ok_chars["<"] = "---lt---"; xml_bad_to_ok_chars["<"] = "---lt---";
@@ -112,10 +108,10 @@ namespace EveOPreview
init_options(); init_options();
// DispatcherTimer setup // DispatcherTimer setup
dispatcherTimer = new DispatcherTimer(); _dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); _dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 1); _dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer.Start(); _dispatcherTimer.Start();
is_initialized = true; is_initialized = true;
@@ -195,46 +191,46 @@ namespace EveOPreview
sync_size.Width = (int)Properties.Settings.Default.sync_resize_x; sync_size.Width = (int)Properties.Settings.Default.sync_resize_x;
sync_size.Height = (int)Properties.Settings.Default.sync_resize_y; sync_size.Height = (int)Properties.Settings.Default.sync_resize_y;
if (!previews.ContainsKey(process.MainWindowHandle) && process.MainWindowTitle != "") if (!_previews.ContainsKey(process.MainWindowHandle) && process.MainWindowTitle != "")
{ {
previews[process.MainWindowHandle] = new Preview(process.MainWindowHandle, "...", this, sync_size); _previews[process.MainWindowHandle] = new Preview(process.MainWindowHandle, "...", this, sync_size);
previews[process.MainWindowHandle].set_render_area_size(sync_size); _previews[process.MainWindowHandle].set_render_area_size(sync_size);
// apply more thumbnail specific options // apply more thumbnail specific options
previews[process.MainWindowHandle].MakeTopMost(Properties.Settings.Default.always_on_top); _previews[process.MainWindowHandle].MakeTopMost(Properties.Settings.Default.always_on_top);
set_thumbnail_frame_style(previews[process.MainWindowHandle], Properties.Settings.Default.show_thumb_frames); set_thumbnail_frame_style(_previews[process.MainWindowHandle], Properties.Settings.Default.show_thumb_frames);
// add a preview also // add a preview also
previews_check_listbox.BeginUpdate(); previews_check_listbox.BeginUpdate();
previews_check_listbox.Items.Add(previews[process.MainWindowHandle]); previews_check_listbox.Items.Add(_previews[process.MainWindowHandle]);
previews_check_listbox.EndUpdate(); previews_check_listbox.EndUpdate();
refresh_client_window_locations(process); refresh_client_window_locations(process);
} }
else if (previews.ContainsKey(process.MainWindowHandle) && process.MainWindowTitle != previews[process.MainWindowHandle].Text) //or update the preview titles else if (_previews.ContainsKey(process.MainWindowHandle) && process.MainWindowTitle != _previews[process.MainWindowHandle].Text) //or update the preview titles
{ {
previews[process.MainWindowHandle].SetLabel(process.MainWindowTitle); _previews[process.MainWindowHandle].SetLabel(process.MainWindowTitle);
string key = previews[process.MainWindowHandle].Text; string key = _previews[process.MainWindowHandle].Text;
string value; string value;
if (flat_layout_shortcuts.TryGetValue(key, out value)) if (flat_layout_shortcuts.TryGetValue(key, out value))
{ {
previews[process.MainWindowHandle].registerShortcut(value); _previews[process.MainWindowHandle].registerShortcut(value);
} }
refresh_client_window_locations(process); refresh_client_window_locations(process);
} }
if (process.MainWindowHandle == DwmApiNativeMethods.GetForegroundWindow()) if (process.MainWindowHandle == DwmApiNativeMethods.GetForegroundWindow())
{ {
active_client_handle = process.MainWindowHandle; _activeClientHandle = process.MainWindowHandle;
active_client_title = process.MainWindowTitle; _activeClientTitle = process.MainWindowTitle;
} }
} }
// clean up old previews // clean up old previews
List<IntPtr> to_be_pruned = new List<IntPtr>(); List<IntPtr> to_be_pruned = new List<IntPtr>();
foreach (IntPtr processHandle in previews.Keys) foreach (IntPtr processHandle in _previews.Keys)
{ {
if (!(processHandles.Contains(processHandle))) if (!(processHandles.Contains(processHandle)))
{ {
@@ -245,12 +241,12 @@ namespace EveOPreview
foreach (IntPtr processHandle in to_be_pruned) foreach (IntPtr processHandle in to_be_pruned)
{ {
previews_check_listbox.BeginUpdate(); previews_check_listbox.BeginUpdate();
previews_check_listbox.Items.Remove(previews[processHandle]); previews_check_listbox.Items.Remove(_previews[processHandle]);
previews_check_listbox.EndUpdate(); previews_check_listbox.EndUpdate();
previews[processHandle].overlay.Close(); _previews[processHandle].overlay.Close();
previews[processHandle].Close(); _previews[processHandle].Close();
previews.Remove(processHandle); _previews.Remove(processHandle);
} }
previews_check_listbox.Update(); previews_check_listbox.Update();
@@ -473,7 +469,7 @@ namespace EveOPreview
{ {
update_client_locations(); update_client_locations();
store_layout(); //todo: check if it actually changed ... store_layout(); //todo: check if it actually changed ...
foreach (KeyValuePair<IntPtr, Preview> entry in previews) foreach (KeyValuePair<IntPtr, Preview> entry in _previews)
{ {
entry.Value.MakeTopMost(Properties.Settings.Default.always_on_top); entry.Value.MakeTopMost(Properties.Settings.Default.always_on_top);
//makes the PreviewOverlay topmost //makes the PreviewOverlay topmost
@@ -498,7 +494,7 @@ namespace EveOPreview
private bool window_is_preview_or_client(IntPtr window) private bool window_is_preview_or_client(IntPtr window)
{ {
bool active_window_is_right_type = false; bool active_window_is_right_type = false;
foreach (KeyValuePair<IntPtr, Preview> entry in previews) foreach (KeyValuePair<IntPtr, Preview> entry in _previews)
{ {
if (entry.Key == window || entry.Value.Handle == window || this.Handle == window || entry.Value.overlay.Handle == window) if (entry.Key == window || entry.Value.Handle == window || this.Handle == window || entry.Value.overlay.Handle == window)
{ {
@@ -515,13 +511,13 @@ namespace EveOPreview
IntPtr active_window = DwmApiNativeMethods.GetForegroundWindow(); IntPtr active_window = DwmApiNativeMethods.GetForegroundWindow();
// hide, show, resize and move // hide, show, resize and move
foreach (KeyValuePair<IntPtr, Preview> entry in previews) foreach (KeyValuePair<IntPtr, Preview> entry in _previews)
{ {
if (!window_is_preview_or_client(active_window) && Properties.Settings.Default.hide_all) if (!window_is_preview_or_client(active_window) && Properties.Settings.Default.hide_all)
{ {
entry.Value.Hide(); entry.Value.Hide();
} }
else if (entry.Key == active_client_handle && Properties.Settings.Default.hide_active) else if (entry.Key == _activeClientHandle && Properties.Settings.Default.hide_active)
{ {
entry.Value.Hide(); entry.Value.Hide();
} }
@@ -530,7 +526,7 @@ namespace EveOPreview
entry.Value.Show(); entry.Value.Show();
if (Properties.Settings.Default.unique_layout) if (Properties.Settings.Default.unique_layout)
{ {
handle_unique_layout(entry.Value, active_client_title); handle_unique_layout(entry.Value, _activeClientTitle);
} }
else else
{ {
@@ -564,7 +560,7 @@ namespace EveOPreview
option_sync_size_x.Text = sync_size.Width.ToString(); option_sync_size_x.Text = sync_size.Width.ToString();
option_sync_size_y.Text = sync_size.Height.ToString(); option_sync_size_y.Text = sync_size.Height.ToString();
foreach (KeyValuePair<IntPtr, Preview> entry in previews) foreach (KeyValuePair<IntPtr, Preview> entry in _previews)
{ {
if (entry.Value.Handle != DwmApiNativeMethods.GetForegroundWindow()) if (entry.Value.Handle != DwmApiNativeMethods.GetForegroundWindow())
{ {
@@ -583,14 +579,14 @@ namespace EveOPreview
if (Properties.Settings.Default.unique_layout) if (Properties.Settings.Default.unique_layout)
{ {
Dictionary<String, Point> layout; Dictionary<String, Point> layout;
if (unique_layouts.TryGetValue(active_client_title, out layout)) if (unique_layouts.TryGetValue(_activeClientTitle, out layout))
{ {
layout[preview_title] = position; layout[preview_title] = position;
} }
else if (active_client_title == "") else if (_activeClientTitle == "")
{ {
unique_layouts[active_client_title] = new Dictionary<String, Point>(); unique_layouts[_activeClientTitle] = new Dictionary<String, Point>();
unique_layouts[active_client_title][preview_title] = position; unique_layouts[_activeClientTitle][preview_title] = position;
} }
} }
else else
@@ -726,7 +722,7 @@ namespace EveOPreview
ignoring_size_sync.Start(); ignoring_size_sync.Start();
} }
foreach (var thumbnail in previews) foreach (var thumbnail in _previews)
{ {
set_thumbnail_frame_style(thumbnail.Value, Properties.Settings.Default.show_thumb_frames); set_thumbnail_frame_style(thumbnail.Value, Properties.Settings.Default.show_thumb_frames);
} }

View File

@@ -20,7 +20,7 @@ namespace EveOPreview
private DWM_THUMBNAIL_PROPERTIES m_ThumbnailProperties; private DWM_THUMBNAIL_PROPERTIES m_ThumbnailProperties;
private bool has_been_set_up = false; private bool has_been_set_up = false;
private bool thumbnail_has_been_set_up = false; private bool thumbnail_has_been_set_up = false;
private PreviewToyHandler spawner; private MainForm spawner;
private Hotkey hotkey; private Hotkey hotkey;
private bool hide = false; private bool hide = false;
@@ -44,7 +44,7 @@ namespace EveOPreview
this.TopMost = topmost && !(this.hide); this.TopMost = topmost && !(this.hide);
} }
public Preview(IntPtr sourceWindow, String title, PreviewToyHandler spawner, Size size) public Preview(IntPtr sourceWindow, String title, MainForm spawner, Size size)
{ {
has_been_set_up = false; has_been_set_up = false;
@@ -138,34 +138,34 @@ namespace EveOPreview
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 ((PreviewToyHandler.zoom_anchor_t)Properties.Settings.Default.zoom_anchor) switch ((MainForm.zoom_anchor_t)Properties.Settings.Default.zoom_anchor)
{ {
case (PreviewToyHandler.zoom_anchor_t.NW): case (MainForm.zoom_anchor_t.NW):
break; break;
case (PreviewToyHandler.zoom_anchor_t.N): case (MainForm.zoom_anchor_t.N):
Location = new Point(Location.X - Size.Width / 2 + old_size.Width / 2, Location.Y); Location = new Point(Location.X - Size.Width / 2 + old_size.Width / 2, Location.Y);
break; break;
case (PreviewToyHandler.zoom_anchor_t.NE): case (MainForm.zoom_anchor_t.NE):
Location = new Point(Location.X - Size.Width + old_size.Width, Location.Y); Location = new Point(Location.X - Size.Width + old_size.Width, Location.Y);
break; break;
case (PreviewToyHandler.zoom_anchor_t.W): case (MainForm.zoom_anchor_t.W):
Location = new Point(Location.X, Location.Y - Size.Height / 2 + old_size.Height / 2); Location = new Point(Location.X, Location.Y - Size.Height / 2 + old_size.Height / 2);
break; break;
case (PreviewToyHandler.zoom_anchor_t.C): 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); Location = new Point(Location.X - Size.Width / 2 + old_size.Width / 2, Location.Y - Size.Height / 2 + old_size.Height / 2);
break; break;
case (PreviewToyHandler.zoom_anchor_t.E): 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); Location = new Point(Location.X - Size.Width + old_size.Width, Location.Y - Size.Height / 2 + old_size.Height / 2);
break; break;
case (PreviewToyHandler.zoom_anchor_t.SW): case (MainForm.zoom_anchor_t.SW):
Location = new Point(Location.X, Location.Y - Size.Height + old_size.Height); Location = new Point(Location.X, Location.Y - Size.Height + old_size.Height);
break; break;
case (PreviewToyHandler.zoom_anchor_t.S): 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); Location = new Point(Location.X - Size.Width / 2 + old_size.Width / 2, Location.Y - Size.Height + old_size.Height);
break; break;
case (PreviewToyHandler.zoom_anchor_t.SE): case (MainForm.zoom_anchor_t.SE):
Location = new Point(Location.X - Size.Width + old_size.Width, Location.Y - Size.Height + old_size.Height); Location = new Point(Location.X - Size.Width + old_size.Width, Location.Y - Size.Height + old_size.Height);
break; break;
} }

View File

@@ -11,7 +11,7 @@ namespace EveOPreview
{ {
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(true); Application.SetCompatibleTextRenderingDefault(true);
Application.Run(new PreviewToyHandler()); Application.Run(new MainForm());
} }
} }
} }