Skip to content

Commit

Permalink
Change icons of bottom part
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon-0609 committed Jan 2, 2022
1 parent 916827e commit 68e9937
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 73 deletions.
42 changes: 41 additions & 1 deletion Yuki Theme Plugin/IconManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using Svg;
using VisualPascalABC;
using WeifenLuo.WinFormsUI.Docking;
using Yuki_Theme.Core;

namespace Yuki_Theme_Plugin
Expand All @@ -10,12 +12,14 @@ class IconManager
{
private ToolStrip tools;
private MenuStrip menu;
private Form1 fm;
private const string IconFolder = "Yuki_Theme_Plugin.Resources.icons";

public IconManager (ToolStrip toolStrip, MenuStrip menuStrip)
public IconManager (ToolStrip toolStrip, MenuStrip menuStrip, Form1 form)
{
tools = toolStrip;
menu = menuStrip;
fm = form;
Init ();
}

Expand Down Expand Up @@ -47,6 +51,12 @@ public void Init ()
}
}
}

foreach (IDockContent content in fm.BottomPane.Contents)
{
// MessageBox.Show (content.DockHandler.Form.Name);
content.DockHandler.Form.AccessibleDescription = GetIconName (content.DockHandler.Form.Name);
}
}

public void UpdateColors ()
Expand All @@ -73,6 +83,14 @@ public void UpdateColors ()
}
}
}


foreach (IDockContent content in fm.BottomPane.Contents)
{
if (content.DockHandler.Form.AccessibleDescription != null &&
content.DockHandler.Form.AccessibleDescription.Length > 2)
UpdateIcon (content.DockHandler.Form);
}
}

private string GetIconName (string str)
Expand Down Expand Up @@ -223,6 +241,7 @@ private string GetIconName (string str)

case "tsOutputWindow" :
case "tsShowOutputWindow" :
case "OutputWindowForm" :
{
res = "console";
}
Expand Down Expand Up @@ -280,6 +299,7 @@ private string GetIconName (string str)

case "miReplace" :
case "tsShowFindSymbolsResultWindow" :
case "FindSymbolsResultWindowForm" :
{
res = "replace";
}
Expand All @@ -292,30 +312,35 @@ private string GetIconName (string str)
break;

case "tsShowErrorsListWindow" :
case "ErrorsListWindowForm" :
{
res = "notificationError";
}
break;

case "tsShowCompilerConsoleWindow" :
case "CompilerConsoleWindowForm" :
{
res = "toolWindowMessages";
}
break;

case "tsShowDebugVariablesListWindow" :
case "DebugVariablesListWindowForm" :
{
res = "dynamicUsages";
}
break;

case "tsShowDebugWatchListWindow" :
case "DebugWatchListWindowForm" :
{
res = "showHiddens";
}
break;

case "tsDisassembly" :
case "DisassemblyWindow" :
{
res = "MoveTo2";
}
Expand Down Expand Up @@ -399,6 +424,21 @@ private void UpdateIcon (ToolStripMenuItem btn)
false, Size.Empty, true, YukiTheme_VisualPascalABCPlugin.bgBorder);
}

private void UpdateIcon (Form btn)
{
string add = "";
if (hasDark (btn.AccessibleDescription))
{
bool isDark = Helper.isDark (YukiTheme_VisualPascalABCPlugin.bg);
add = isDark ? "" : "_dark";
}

var a = Assembly.GetExecutingAssembly ();
// MessageBox.Show (btn.Name);
Helper.renderSVG (btn, Helper.loadsvg (btn.AccessibleDescription + add, a, IconFolder),
false, Size.Empty, true, YukiTheme_VisualPascalABCPlugin.bgBorder);
}

private bool hasDark (string str)
{
bool s = false;
Expand Down
168 changes: 96 additions & 72 deletions Yuki Theme Plugin/YukiTheme_VisualPascalABCPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,19 @@ public class YukiTheme_VisualPascalABCPlugin : IVisualPascalABCPlugin
private Image sticker;
private CustomPicture stickerControl;

private ToolStripMenuItem menu_settings;
private ToolStripMenuItem quiet;
private ToolStripMenuItem stick;
private ToolStripMenuItem backimage;
private ToolStripMenuItem switchTheme;
private Image quietImage;
private Image wallpaperImage;
private Image switchImage;
private Size defaultSize;
private Panel panel_bg;
private CustomList lst;
private Image tmpImage1;
private Image tmpImage2;
private ToolStripMenuItem menu_settings;
private ToolStripMenuItem quiet;
private ToolStripMenuItem stick;
private ToolStripMenuItem backimage;
private ToolStripMenuItem switchTheme;
private Image quietImage;
private Image wallpaperImage;
private Image switchImage;
private Size defaultSize;
private Panel panel_bg;
private CustomList lst;
private Image tmpImage1;
private Image tmpImage2;

private bool isMoving = false; // true while dragging the image
private Point movingPicturePosition = new Point(80, 20); // the position of the moving image
Expand Down Expand Up @@ -245,7 +245,8 @@ private void Initialize ()
textEditor.Parent.BackColor = bg;
textEditor.Controls [1].Paint += CtrlOnPaint;
textEditor.Controls [1].Invalidate();



textEditor.ActiveTextAreaControl.TextArea.Caret.PositionChanged += CaretPositionChangedEventHandler;
textEditor.ActiveTextAreaControl.TextArea.Caret.PositionChanged += CaretOnPositionChanged;

Expand Down Expand Up @@ -314,7 +315,7 @@ private void Initialize ()
menu.Renderer = renderer;
context.Renderer = renderer;
context2.Renderer = renderer;
manager = new IconManager (tools, menu);
manager = new IconManager (tools, menu, fm);

UpdateColors ();

Expand Down Expand Up @@ -533,9 +534,27 @@ private void RefreshEditor ()
private void PaintBG (object sender, PaintEventArgs e)
{
if(margin != null)
e.Graphics.FillRectangle (new SolidBrush (bgdef), margin.DrawingPosition.X,
margin.DrawingPosition.Y,
margin.DrawingPosition.Width, margin.DrawingPosition.Height);
{
e.Graphics.FillRectangle (new SolidBrush (bgdef), margin.DrawingPosition.X,
margin.DrawingPosition.Y,
margin.DrawingPosition.Width, margin.DrawingPosition.Height);
var inside =
typeof (IconBarMargin).GetMethod ("IsLineInsideRegion",
BindingFlags.Static | BindingFlags.NonPublic);
// paint icons
foreach (Bookmark mark in textArea.Document.BookmarkManager.Marks) {
int lineNumber = textArea.Document.GetVisibleLine(mark.LineNumber);
int lineHeight = textArea.TextView.FontHeight;
int yPos = (int)(lineNumber * lineHeight) - textArea.VirtualTop.Y;
if ((bool) inside.Invoke(null,new object[] {yPos, yPos + lineHeight, margin.DrawingPosition.Y, margin.DrawingPosition.Height})) {
if (lineNumber == textArea.Document.GetVisibleLine(mark.LineNumber - 1)) {
// marker is inside folded region, do not draw it
continue;
}
mark.Draw(margin, e.Graphics, new Point(0, yPos));
}
}
}

if(img != null && bgImage)
{
Expand Down Expand Up @@ -799,61 +818,65 @@ private void ToggleWallpaper (object sender, EventArgs e)

private void SwitchTheme (object sender, EventArgs e)
{
if(mf == null || mf.IsDisposed)
if(!fm.Controls.ContainsKey ("Custom Panel Switcher"))
{
panel_bg = new CustomPanel ();

Font fnt = new Font (FontFamily.GenericSansSerif, 10, GraphicsUnit.Point);

Label lbl = new Label ();
lbl.BackColor = bg;
lbl.ForeColor = clr;
lbl.Font = fnt;
lbl.Text = "Themes";
lbl.TextAlign = ContentAlignment.MiddleCenter;
lbl.Size = new Size (200, 25);

lst = new CustomList ();
lst.BackColor = bgdef;
lst.ForeColor = clr;
lst.BorderStyle = BorderStyle.None;
lst.Items.AddRange (CLI.schemes.ToArray ());
lst.BorderStyle = BorderStyle.None;
lst.Font = fnt;
lst.ItemHeight = lst.Font.Height;
lst.Size = new Size (200, 300);
lst.MouseMove += Lst_MouseHover;


panel_bg.Location = Point.Empty;
panel_bg.Size = fm.ClientSize;
lst.DrawMode = DrawMode.OwnerDrawFixed;
lst.DrawItem += list_1_DrawItem;
int x = (panel_bg.Width / 2) - (lst.Width / 2);
int y = (panel_bg.Height / 2) - (lst.Height / 2);

lbl.Location = new Point (x, y - 13);
lst.Location = new Point (x,y + 12);

if (lst.Items.Contains (Helper.CurrentTheme))
lst.SelectedItem = Helper.CurrentTheme;
else
lst.SelectedIndex = 0;
lst.SelectedIndexChanged += LstOnSelectedIndexChanged;
lst.AccessibleName = lst.SelectedItem.ToString ();
panel_bg.Click += CloseOnClick;

panel_bg.Controls.Add (lst);
panel_bg.Controls.Add (lbl);

setBorder (lst, lbl);

fm.Controls.Add (panel_bg);
panel_bg.BringToFront ();
panel_bg.Focus ();
} else
{
MessageBox.Show ("Please, close Yuki Theme window to activate 'Switch theme'");
if (mf == null || mf.IsDisposed)
{
panel_bg = new CustomPanel ();
panel_bg.Name = "Custom Panel Switcher";

Font fnt = new Font (FontFamily.GenericSansSerif, 10, GraphicsUnit.Point);

Label lbl = new Label ();
lbl.BackColor = bg;
lbl.ForeColor = clr;
lbl.Font = fnt;
lbl.Text = "Themes";
lbl.TextAlign = ContentAlignment.MiddleCenter;
lbl.Size = new Size (200, 25);

lst = new CustomList ();
lst.BackColor = bgdef;
lst.ForeColor = clr;
lst.BorderStyle = BorderStyle.None;
lst.Items.AddRange (CLI.schemes.ToArray ());
lst.BorderStyle = BorderStyle.None;
lst.Font = fnt;
lst.ItemHeight = lst.Font.Height;
lst.Size = new Size (200, 300);
lst.MouseMove += Lst_MouseHover;


panel_bg.Location = Point.Empty;
panel_bg.Size = fm.ClientSize;
lst.DrawMode = DrawMode.OwnerDrawFixed;
lst.DrawItem += list_1_DrawItem;
int x = (panel_bg.Width / 2) - (lst.Width / 2);
int y = (panel_bg.Height / 2) - (lst.Height / 2);

lbl.Location = new Point (x, y - 13);
lst.Location = new Point (x, y + 12);

if (lst.Items.Contains (Helper.CurrentTheme))
lst.SelectedItem = Helper.CurrentTheme;
else
lst.SelectedIndex = 0;
lst.SelectedIndexChanged += LstOnSelectedIndexChanged;
lst.AccessibleName = lst.SelectedItem.ToString ();
panel_bg.Click += CloseOnClick;

panel_bg.Controls.Add (lst);
panel_bg.Controls.Add (lbl);

setBorder (lst, lbl);

fm.Controls.Add (panel_bg);
panel_bg.BringToFront ();
panel_bg.Focus ();
} else
{
MessageBox.Show ("Please, close Yuki Theme window to activate 'Switch theme'");
}
}
}

Expand Down Expand Up @@ -1293,5 +1316,6 @@ private void addSettings ()
OptionsContentEngine options = (OptionsContentEngine) getopt.GetValue (fm);
options.AddContent (new PluginOptionsContent (this));
}

}
}
16 changes: 16 additions & 0 deletions Yuki Theme.Core/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using System.Xml;
Expand All @@ -30,6 +31,11 @@ public static class Helper
public static Color bgColor, bgClick, bgBorder, fgColor, fgHover, fgKeyword;

public static ProductMode mode;

private static Size Standart32 = new Size (32, 32);

[DllImport("user32.dll", CharSet = CharSet.Auto)]
extern static bool DestroyIcon(IntPtr handle);

public static Rectangle getSizes (Size ima, int mWidth, int mHeight, Alignment align)
{
Expand Down Expand Up @@ -410,6 +416,16 @@ public static void renderSVG (ToolStripButton im, SvgDocument svg, bool custom =
im.Image = renderSVG (im.Size, svg, custom, cSize, customColor, clr);
}

public static void renderSVG (Form im, SvgDocument svg, bool custom = false, Size cSize = default,
bool customColor = false, Color clr = default)
{
// im.Icon?.Dispose ();
IntPtr ptr = ((Bitmap) renderSVG (Standart32, svg, custom, cSize, customColor, clr)).GetHicon ();

im.Icon = Icon.FromHandle (ptr);
// DestroyIcon (ptr);
}

public static void renderSVG (ToolStripMenuItem im, SvgDocument svg, bool custom = false, Size cSize = default, bool customColor = false, Color clr = default)
{
im.Image?.Dispose ();
Expand Down

0 comments on commit 68e9937

Please sign in to comment.