Skip to content

Commit

Permalink
Disabled DPI scaling. Added Eyedropper. Added live label overlay. Add…
Browse files Browse the repository at this point in the history
…ed filter box to shortcuts
  • Loading branch information
Jonno12345 committed Jun 16, 2016
1 parent bd55870 commit 7c1d03c
Show file tree
Hide file tree
Showing 28 changed files with 788 additions and 123 deletions.
17 changes: 8 additions & 9 deletions TileIconifier.Core/Custom/Steam/KeyValues/KeyValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != typeof (KeyValues)) return false;
return Equals((KeyValues) obj);
return obj is KeyValues && Equals((KeyValues) obj);
}

/// <summary>
Expand Down Expand Up @@ -510,7 +509,7 @@ public bool ExistsSubKey(string subKeyName)
/// <param name="line">Current Line to parse.</param>
/// <param name="wasQuoted">True if Key have quotes " so is not a { or }.</param>
/// <param name="wasComment">True if Current line is a comment.</param>
private static KeyValuePair<string, string> ReadToken(string line, ref bool wasQuoted, ref bool wasComment)
private static KeyValuePair<string, string> ReadToken(string line, out bool wasQuoted, out bool wasComment)
{
wasQuoted = false;
wasComment = false;
Expand Down Expand Up @@ -624,11 +623,11 @@ private static KeyValuePair<string, string> ReadToken(string line, ref bool wasQ
private uint RetriveIndex(List<string> lines, string search, uint startIndex)
{
if (string.IsNullOrEmpty(search)) return 0;
var wasQuote = false;
var wasComment = false;
for (var i = (int) startIndex; i < lines.Count; i++)
{
var kvPair = ReadToken(lines[i], ref wasQuote, ref wasComment);
bool wasQuote;
bool wasComment;
var kvPair = ReadToken(lines[i], out wasQuote, out wasComment);
if (kvPair.Key == search && !wasComment && !wasQuote)
return (uint) i;
}
Expand Down Expand Up @@ -663,14 +662,14 @@ public bool LoadFromFile(string fileName)
private bool LoadFromList(List<string> stream, uint startPos, ref uint endPos)
{
if (stream == null) return false;
var wasQuoted = false;
var wasComment = false;
string lastComment = null;
var wasName = false;
endPos = 0;
for (var i = startPos; i < stream.Count; i++)
{
var kvPair = ReadToken(stream[(int) i], ref wasQuoted, ref wasComment);
bool wasQuoted;
bool wasComment;
var kvPair = ReadToken(stream[(int) i], out wasQuoted, out wasComment);
if (string.IsNullOrEmpty(kvPair.Key)) continue;
endPos = i;
// Is the end of KeyValues Class?
Expand Down
10 changes: 5 additions & 5 deletions TileIconifier.Core/IconExtractor/IconExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public class IconExtractor

// Flags for LoadLibraryEx().

private const uint LoadLibraryAsDatafile = 0x00000002;
private const uint LOAD_LIBRARY_AS_DATAFILE = 0x00000002;

private const int MaxPath = 260;
private const int MAX_PATH = 260;

// Resource types for EnumResourceNames().

Expand Down Expand Up @@ -119,7 +119,7 @@ private void Initialize(string fileName)
var hModule = IntPtr.Zero;
try
{
hModule = NativeMethods.LoadLibraryEx(fileName, IntPtr.Zero, LoadLibraryAsDatafile);
hModule = NativeMethods.LoadLibraryEx(fileName, IntPtr.Zero, LOAD_LIBRARY_AS_DATAFILE);
if (hModule == IntPtr.Zero)
throw new Win32Exception();

Expand Down Expand Up @@ -228,7 +228,7 @@ private string GetFileName(IntPtr hModule)

string fileName;
{
var buf = new StringBuilder(MaxPath);
var buf = new StringBuilder(MAX_PATH);
var len = NativeMethods.GetMappedFileName(
NativeMethods.GetCurrentProcess(), hModule, buf, buf.Capacity);
if (len == 0)
Expand All @@ -243,7 +243,7 @@ private string GetFileName(IntPtr hModule)
for (var c = 'A'; c <= 'Z'; ++c)
{
var drive = c + ":";
var buf = new StringBuilder(MaxPath);
var buf = new StringBuilder(MAX_PATH);
var len = NativeMethods.QueryDosDevice(drive, buf, buf.Capacity);
if (len == 0)
continue;
Expand Down
14 changes: 7 additions & 7 deletions TileIconifier.Core/Utilities/ShortcutUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ public static void CreateLnkFile(string shortcutPath, string targetPath, string

private static string ResolveMsiShortcut(string file)
{
var product = new StringBuilder(NativeMethods.MaxGuidLength + 1);
var feature = new StringBuilder(NativeMethods.MaxFeatureLength + 1);
var component = new StringBuilder(NativeMethods.MaxGuidLength + 1);
var product = new StringBuilder(NativeMethods.MAX_GUID_LENGTH + 1);
var feature = new StringBuilder(NativeMethods.MAX_FEATURE_LENGTH + 1);
var component = new StringBuilder(NativeMethods.MAX_GUID_LENGTH + 1);

NativeMethods.MsiGetShortcutTarget(file, product, feature, component);

var pathLength = NativeMethods.MaxPathLength;
var pathLength = NativeMethods.MAX_PATH_LENGTH;
var path = new StringBuilder(pathLength);

var installState = NativeMethods.MsiGetComponentPath(product.ToString(), component.ToString(), path,
Expand Down Expand Up @@ -139,9 +139,9 @@ public enum InstallState
Default = 5*/
}

public const int MaxFeatureLength = 38;
public const int MaxGuidLength = 38;
public const int MaxPathLength = 1024;
public const int MAX_FEATURE_LENGTH = 38;
public const int MAX_GUID_LENGTH = 38;
public const int MAX_PATH_LENGTH = 1024;

[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiGetShortcutTarget(string targetFile, StringBuilder productCode,
Expand Down
8 changes: 4 additions & 4 deletions TileIconifier/Controls/AllOrCurrentUserRadios.Designer.cs

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

154 changes: 154 additions & 0 deletions TileIconifier/Controls/Eyedropper/EyedropColorPicker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
The original source for this control was created by jkristia @ http://www.codeproject.com/Articles/21965/Color-Picker-with-Color-Wheel-and-Eye-Dropper
licenced under The Code Project Open License (CPOL).
Minor modifications have been made to fit in with the requirements of this application:
- Image for eyedropper altered
- Border removed
- Changed some variable names and cleaned up to fit with coding practices throughout this solution
*/

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using TileIconifier.Core.Utilities;
using TileIconifier.Properties;

namespace TileIconifier.Controls.Eyedropper
{
internal sealed class EyedropColorPicker : Control
{
private readonly Bitmap _mIcon;

private bool _iscapturing;

private Bitmap _mSnapshot;
private float _mZoom = 4;

public EyedropColorPicker()
{
DoubleBuffered = true;
var eyedropperIcon = new Bitmap(Resources.Actions_color_picker_black_icon);
_mIcon = ImageUtils.ResizeImage(eyedropperIcon, 20, 20);
eyedropperIcon.Dispose();
}

public int Zoom
{
get { return (int) _mZoom; }
set
{
_mZoom = value;
RecalcSnapshotSize();
}
}

public Color SelectedColor { get; set; }

private RectangleF ImageRect => Util.Rect(ClientRectangle);
public event EventHandler SelectedColorChanged;

protected override void OnResize(EventArgs e)
{
base.OnResize(e);
RecalcSnapshotSize();
}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);

if (_mSnapshot == null) return;
e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
var r = RectangleF.Empty;
r.Width = _mSnapshot.Size.Width*Zoom;
r.Height = _mSnapshot.Size.Height*Zoom;
r.X = 0;
r.Y = 0;
e.Graphics.DrawImage(_mSnapshot, r);

if (_iscapturing)
{
var center = Util.Center(r);
var centerrect = new Rectangle(Util.Point(center), new Size(0, 0));
centerrect.X -= Zoom/2 - 1;
centerrect.Y -= Zoom/2 - 1;
centerrect.Width = Zoom;
centerrect.Height = Zoom;
e.Graphics.DrawRectangle(Pens.Black, centerrect);
}
else
{
const int offset = 3;

e.Graphics.FillRectangle(SystemBrushes.Control, new Rectangle(new Point(0, 0), Size));
e.Graphics.DrawImage(_mIcon, offset, offset);
}
//
//draws a border - removed for now.
//
//var rr = ClientRectangle;
//Pen pen = new Pen(BackColor, 3);
//rr.Inflate(-1, -1);
//e.Graphics.DrawRectangle(pen, rr);
//Util.DrawFrame(e.Graphics, rr, 6, Color.CadetBlue);
}

protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if ((e.Button & MouseButtons.Left) != MouseButtons.Left) return;
Cursor = Cursors.Cross;
_iscapturing = true;
Invalidate();
}

protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
GetSnapshot();
}

protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
{
Cursor = Cursors.Arrow;
_iscapturing = false;
Invalidate();
}
}

private void RecalcSnapshotSize()
{
_mSnapshot?.Dispose();
var r = ImageRect;
var w = (int) Math.Floor(r.Width/Zoom);
var h = (int) Math.Floor(r.Height/Zoom);
_mSnapshot = new Bitmap(w, h);
}

private void GetSnapshot()
{
var p = MousePosition;
p.X -= _mSnapshot.Width/2;
p.Y -= _mSnapshot.Height/2;

using (var dc = Graphics.FromImage(_mSnapshot))
{
dc.CopyFromScreen(p, new Point(0, 0), _mSnapshot.Size);
Refresh(); //Invalidate();

var center = Util.Center(new RectangleF(0, 0, _mSnapshot.Size.Width, _mSnapshot.Size.Height));
var c = _mSnapshot.GetPixel((int) Math.Round(center.X), (int) Math.Round(center.Y));
if (c == SelectedColor) return;
SelectedColor = c;
SelectedColorChanged?.Invoke(this, null);
}
}
}
}
Loading

0 comments on commit 7c1d03c

Please sign in to comment.