Skip to content

Commit

Permalink
dpi nonsense
Browse files Browse the repository at this point in the history
  • Loading branch information
factubsio committed Mar 19, 2022
1 parent 2894940 commit fee3951
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 64 deletions.
29 changes: 25 additions & 4 deletions BlueprintExplorer/BlueprintControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ private string CalculatePath()
}
}

public int RowHeight { get; set; } = 36;
public int RowHeight
{
get { return (Regular?.Height ?? 32) + 4; }
set { }
}

protected override CreateParams CreateParams
{
Expand Down Expand Up @@ -206,6 +210,18 @@ public BlueprintControl()
};
ToastTimer.Interval = 33;
ToastTimer.Start();

Regular = new Font(Font.FontFamily, (float)BubblePrints.Settings.BlueprintFontSize, FontStyle.Regular);
Bold = new Font(Font.FontFamily, (float)BubblePrints.Settings.BlueprintFontSize, FontStyle.Bold);

BubblePrints.OnSettingsChanged += BubblePrints_OnSettingsChanged;
}

private void BubblePrints_OnSettingsChanged()
{
Regular = new Font(Font.FontFamily, (float)BubblePrints.Settings.BlueprintFontSize, FontStyle.Regular);
Bold = new Font(Font.FontFamily, (float)BubblePrints.Settings.BlueprintFontSize, FontStyle.Bold);
ValidateBlueprint(false);
}

protected override void OnBackColorChanged(EventArgs e) => UpdateRowHoverColor();
Expand Down Expand Up @@ -288,6 +304,8 @@ private void ValidateBlueprint(bool scroll)
int strWidthAllowed = StringWidthAllowed;
currentHover = -1;
int totalRows = 0;
if (DisplayedObject == null) return;

if (DisplayedObject != null)
{
Elements.Add(new ()
Expand Down Expand Up @@ -823,15 +841,18 @@ protected override void OnMouseMove(MouseEventArgs e)

}
}
private Font Regular;
private Font Bold;

protected override void OnPaint(PaintEventArgs e)
{
var g = e.Graphics;


DrawParams drawing = new()
{
Bold = new Font(Font, FontStyle.Bold),
Regular = Font,
Regular = Regular,
Bold = Bold,
Graphics = g,
};

Expand Down Expand Up @@ -867,7 +888,7 @@ protected override void OnPaint(PaintEventArgs e)

}

public Font LinkFont { get => linkFont ?? Font; set => linkFont = value; }
public Font LinkFont { get => Regular; set => linkFont = value; }
private SolidBrush RowHoverColor;
private Pen RowLineGuide;
private SolidBrush RowPreviewHoverColor;
Expand Down
96 changes: 63 additions & 33 deletions BlueprintExplorer/BlueprintViewer.Designer.cs

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

28 changes: 27 additions & 1 deletion BlueprintExplorer/BlueprintViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ public BlueprintViewer()
}
};

BubblePrints.OnTemplatesChanged += BubblePrints_OnTemplatesChanged;
BubblePrints_OnTemplatesChanged(0, BubblePrints.Settings.GeneratorTemplate?.Length ?? 0);
if (templatesList.Items.Count > 0)
templatesList.SelectedIndex = 0;

copyTemplate.Click += (sender, e) =>
{
var availableTemplates = BubblePrints.Settings.GeneratorTemplate;
if (templatesList.SelectedIndex == -1) return;
if (templatesList.SelectedIndex >= availableTemplates.Length) return;

var template = availableTemplates[templatesList.SelectedIndex];
var result = TemplateRunner.Execute(template.Value, view.Blueprint as BlueprintHandle);
Clipboard.SetText(result);
};

view.OnPathHovered += path =>
{
currentPath.Text = path ?? "-";
Expand All @@ -67,7 +83,7 @@ public BlueprintViewer()
filter.TextChanged += (sender, e) => view.Filter = filter.Text;
if (Form1.Dark)
{
BubbleTheme.DarkenControls(view, filter, references, openExternal, currentPath);
BubbleTheme.DarkenControls(view, filter, references, openExternal, copyTemplate, templatesList, currentPath);
BubbleTheme.DarkenStyles(references.DefaultCellStyle, references.ColumnHeadersDefaultCellStyle);
}

Expand All @@ -77,6 +93,16 @@ public BlueprintViewer()

this.AddMouseClickRecursively(HandleXbuttons);
}

private void BubblePrints_OnTemplatesChanged(int oldCount, int newCount)
{
templatesList.Items.Clear();
foreach (var template in BubblePrints.Settings.GeneratorTemplate)
{
templatesList.Items.Add(template.Name);
}
}

private void HandleXbuttons(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.XButton1)
Expand Down
38 changes: 35 additions & 3 deletions BlueprintExplorer/BubblePrints.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.IO;
Expand All @@ -11,6 +13,12 @@ namespace BlueprintExplorer
{
public static class BubblePrints
{
public delegate void TemplatesChangedDelegate(int oldCount, int newCount);
public static event TemplatesChangedDelegate OnTemplatesChanged;

public delegate void SettingsChangedDelegate();
public static event SettingsChangedDelegate OnSettingsChanged;

public static SettingsProxy Settings = new();
private static string StoredWrathPath = null;
public static bool TryGetWrathPath(out string path)
Expand Down Expand Up @@ -64,7 +72,7 @@ internal static void SetWrathPath()

if (folderBrowser.ShowDialog() != DialogResult.OK)
return;

path = folderBrowser.SelectedPath;

var exePath = Path.Combine(path, "Wrath.exe");
Expand All @@ -87,8 +95,12 @@ internal static void SetWrathPath()
public static string MakeDataPath(string subpath) => Path.Combine(DataPath, subpath);
public static string SettingsPath => MakeDataPath("settings.json");


internal static void SaveSettings() => File.WriteAllText(SettingsPath, JsonSerializer.Serialize(Settings));
internal static void SaveSettings()
{
File.WriteAllText(SettingsPath, JsonSerializer.Serialize(Settings));
OnSettingsChanged?.Invoke();
}
internal static void NotifyTemplatesChanged(int oldCount, int newCount) => OnTemplatesChanged?.Invoke(oldCount, newCount);
}

public enum ExportMode
Expand All @@ -102,12 +114,16 @@ public class SettingsProxy
{
public void Sync()
{
int oldCount = BubblePrints.Settings.GeneratorTemplate?.Length ?? 0;

var settings = BubblePrints.Settings;
foreach (var p in GetType().GetProperties())
{
p.SetValue(settings, p.GetValue(this));
}
BubblePrints.SaveSettings();

BubblePrints.NotifyTemplatesChanged(oldCount, GeneratorTemplate?.Length ?? 0);
}


Expand Down Expand Up @@ -174,5 +190,21 @@ public SettingsProxy(SettingsProxy settings)
[Description("This path will be used if the 'check for updates' is false, or if there is no connectivity to check for any later version")]
[DisplayName("Most recent blueprints loaded")]
public string LastLoaded { get; set; }

[Description("Size of the font for the blueprint viewer")]
[DisplayName("Blueprint font size")]
public int BlueprintFontSize { get; set; } = 12;

[Description("Template string for blueprint template generation - see help for more details")]
[DisplayName("Generator template")]
//[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Template[] GeneratorTemplate { get; set; }
}

public class Template
{
public string Name { get; set; }
public string Value { get; set; }

}
}
Loading

0 comments on commit fee3951

Please sign in to comment.