1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-06 14:34:05 +02:00

Enable high DPI support and fix all known DPI-related UI issues

Closes 
This commit is contained in:
chylex 2017-06-26 17:08:51 +02:00
parent c81cb393e9
commit 7f3bd2715c
12 changed files with 49 additions and 42 deletions

View File

@ -21,6 +21,12 @@ public static void InvokeAsyncSafe(this Control control, Action func){
control.BeginInvoke(func);
}
public static float GetDPIScale(this Control control){
using(Graphics graphics = control.CreateGraphics()){
return graphics.DpiY/96F;
}
}
public static bool IsFullyOutsideView(this Form form){
return !Screen.AllScreens.Any(screen => screen.WorkingArea.IntersectsWith(form.Bounds));
}

View File

@ -70,6 +70,8 @@ protected Point PrimaryLocation{
protected readonly Form owner;
protected readonly ChromiumWebBrowser browser;
protected float dpiScale;
private readonly ResourceHandlerNotification resourceHandler = new ResourceHandlerNotification();
private string currentColumn;
@ -103,6 +105,8 @@ public FormNotificationBase(Form owner, bool enableContextMenu){
this.browser.ConsoleMessage += BrowserUtils.HandleConsoleMessage;
#endif
this.dpiScale = this.GetDPIScale();
DefaultResourceHandlerFactory handlerFactory = (DefaultResourceHandlerFactory)browser.ResourceHandlerFactory;
handlerFactory.RegisterHandler("https://tweetdeck.twitter.com", this.resourceHandler);
@ -177,7 +181,7 @@ protected virtual void LoadTweet(TweetNotification tweet){
}
protected virtual void SetNotificationSize(int width, int height){
browser.ClientSize = ClientSize = new Size((int)Math.Round(width*Program.UserConfig.ZoomMultiplier), (int)Math.Round(height*Program.UserConfig.ZoomMultiplier));
browser.ClientSize = ClientSize = new Size((int)Math.Round(width*dpiScale*Program.UserConfig.ZoomMultiplier), (int)Math.Round(height*dpiScale*Program.UserConfig.ZoomMultiplier));
}
protected virtual void OnNotificationReady(){

View File

@ -22,22 +22,6 @@ static FormNotificationMain(){
NotificationJS = ScriptLoader.LoadResource(NotificationScriptFile);
PluginJS = ScriptLoader.LoadResource(PluginManager.PluginNotificationScriptFile);
}
private static int BaseClientWidth{
get{
int level = TweetNotification.FontSizeLevel;
int width = level == 0 ? 284 : (int)Math.Round(284.0*(1.0+0.05*level));
return (int)Math.Round(width*Program.UserConfig.ZoomMultiplier);
}
}
private static int BaseClientHeight{
get{
int level = TweetNotification.FontSizeLevel;
int height = level == 0 ? 118 : (int)Math.Round(118.0*(1.0+0.075*level));
return (int)Math.Round(height*Program.UserConfig.ZoomMultiplier);
}
}
private readonly PluginManager plugins;
@ -68,6 +52,22 @@ private bool RequiresResize{
}
}
private int BaseClientWidth{
get{
int level = TweetNotification.FontSizeLevel;
int width = level == 0 ? 284 : (int)Math.Round(284.0*(1.0+0.05*level));
return (int)Math.Round(width*dpiScale*Program.UserConfig.ZoomMultiplier);
}
}
private int BaseClientHeight{
get{
int level = TweetNotification.FontSizeLevel;
int height = level == 0 ? 118 : (int)Math.Round(118.0*(1.0+0.075*level));
return (int)Math.Round(height*dpiScale*Program.UserConfig.ZoomMultiplier);
}
}
public FormNotificationMain(FormBrowser owner, PluginManager pluginManager, bool enableContextMenu) : base(owner, enableContextMenu){
InitializeComponent();

View File

@ -13,6 +13,8 @@ sealed partial class FormSettings : Form{
private readonly FormBrowser browser;
private readonly PluginManager plugins;
private readonly int buttonHeight;
private readonly Dictionary<Type, SettingsTab> tabs = new Dictionary<Type, SettingsTab>(4);
private SettingsTab currentTab;
@ -25,6 +27,8 @@ public FormSettings(FormBrowser browser, PluginManager plugins, UpdateHandler up
this.browser.PauseNotification();
this.plugins = plugins;
this.buttonHeight = (int)Math.Round(39*this.GetDPIScale()) | 1;
AddButton("General", () => new TabSettingsGeneral(updates));
AddButton("Notifications", () => new TabSettingsNotifications(browser.CreateNotificationForm(false)));
@ -63,14 +67,12 @@ private void btnClose_Click(object sender, EventArgs e){
}
private void AddButton<T>(string title, Func<T> constructor) where T : BaseTabSettings{
const int btnHeight = 39;
FlatButton btn = new FlatButton{
BackColor = SystemColors.Control,
FlatStyle = FlatStyle.Flat,
Location = new Point(0, (btnHeight+1)*(panelButtons.Controls.Count/2)),
Location = new Point(0, (buttonHeight+1)*(panelButtons.Controls.Count/2)),
Margin = new Padding(0),
Size = new Size(panelButtons.Width, btnHeight),
Size = new Size(panelButtons.Width, buttonHeight),
Text = title,
UseVisualStyleBackColor = true
};
@ -83,7 +85,7 @@ private void AddButton<T>(string title, Func<T> constructor) where T : BaseTabSe
panelButtons.Controls.Add(new Panel{
BackColor = Color.DimGray,
Location = new Point(0, panelButtons.Controls[panelButtons.Controls.Count-1].Location.Y+btnHeight),
Location = new Point(0, panelButtons.Controls[panelButtons.Controls.Count-1].Location.Y+buttonHeight),
Margin = new Padding(0),
Size = new Size(panelButtons.Width, 1)
});

View File

@ -42,16 +42,14 @@ private void InitializeComponent() {
//
// textBoxBrowserCSS
//
this.textBoxBrowserCSS.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBoxBrowserCSS.Dock = System.Windows.Forms.DockStyle.Bottom;
this.textBoxBrowserCSS.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.textBoxBrowserCSS.Location = new System.Drawing.Point(0, 16);
this.textBoxBrowserCSS.Margin = new System.Windows.Forms.Padding(0, 3, 0, 0);
this.textBoxBrowserCSS.Multiline = true;
this.textBoxBrowserCSS.Name = "textBoxBrowserCSS";
this.textBoxBrowserCSS.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBoxBrowserCSS.Size = new System.Drawing.Size(373, 253);
this.textBoxBrowserCSS.Size = new System.Drawing.Size(378, 253);
this.textBoxBrowserCSS.TabIndex = 1;
this.textBoxBrowserCSS.WordWrap = false;
this.textBoxBrowserCSS.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBoxBrowserCSS_KeyUp);
@ -100,7 +98,7 @@ private void InitializeComponent() {
this.splitContainer.Panel2.Controls.Add(this.textBoxNotificationCSS);
this.splitContainer.Panel2MinSize = 64;
this.splitContainer.Size = new System.Drawing.Size(760, 269);
this.splitContainer.SplitterDistance = 373;
this.splitContainer.SplitterDistance = 378;
this.splitContainer.SplitterWidth = 5;
this.splitContainer.TabIndex = 0;
//
@ -126,16 +124,14 @@ private void InitializeComponent() {
//
// textBoxNotificationCSS
//
this.textBoxNotificationCSS.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBoxNotificationCSS.Dock = System.Windows.Forms.DockStyle.Bottom;
this.textBoxNotificationCSS.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.textBoxNotificationCSS.Location = new System.Drawing.Point(0, 16);
this.textBoxNotificationCSS.Margin = new System.Windows.Forms.Padding(0, 3, 0, 0);
this.textBoxNotificationCSS.Multiline = true;
this.textBoxNotificationCSS.Name = "textBoxNotificationCSS";
this.textBoxNotificationCSS.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBoxNotificationCSS.Size = new System.Drawing.Size(372, 253);
this.textBoxNotificationCSS.Size = new System.Drawing.Size(377, 253);
this.textBoxNotificationCSS.TabIndex = 1;
this.textBoxNotificationCSS.WordWrap = false;
//
@ -152,7 +148,6 @@ private void InitializeComponent() {
// btnOpenWiki
//
this.btnOpenWiki.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnOpenWiki.AutoSize = true;
this.btnOpenWiki.Location = new System.Drawing.Point(12, 287);
this.btnOpenWiki.Name = "btnOpenWiki";
this.btnOpenWiki.Padding = new System.Windows.Forms.Padding(3, 0, 3, 0);

View File

@ -69,7 +69,6 @@ private void InitializeComponent() {
// btnHelp
//
this.btnHelp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnHelp.AutoSize = true;
this.btnHelp.Location = new System.Drawing.Point(12, 227);
this.btnHelp.Name = "btnHelp";
this.btnHelp.Padding = new System.Windows.Forms.Padding(3, 0, 3, 0);

View File

@ -42,7 +42,6 @@ private void InitializeComponent() {
// btnCancel
//
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnCancel.AutoSize = true;
this.btnCancel.Location = new System.Drawing.Point(176, 97);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Padding = new System.Windows.Forms.Padding(3, 0, 3, 0);
@ -56,7 +55,6 @@ private void InitializeComponent() {
//
this.btnContinue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnContinue.AutoSize = true;
this.btnContinue.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.btnContinue.Enabled = false;
this.btnContinue.Location = new System.Drawing.Point(125, 97);
this.btnContinue.Name = "btnContinue";

View File

@ -38,7 +38,6 @@ private void InitializeComponent() {
// btnCancel
//
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnCancel.AutoSize = true;
this.btnCancel.Location = new System.Drawing.Point(160, 171);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Padding = new System.Windows.Forms.Padding(3, 0, 3, 0);
@ -51,7 +50,6 @@ private void InitializeComponent() {
// btnRestart
//
this.btnRestart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnRestart.AutoSize = true;
this.btnRestart.Location = new System.Drawing.Point(97, 171);
this.btnRestart.Name = "btnRestart";
this.btnRestart.Padding = new System.Windows.Forms.Padding(3, 0, 3, 0);

View File

@ -152,7 +152,6 @@ private void InitializeComponent() {
| System.Windows.Forms.AnchorStyles.Left)));
this.labelType.BackColor = System.Drawing.Color.DarkGray;
this.labelType.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.labelType.LineHeight = 9;
this.labelType.Location = new System.Drawing.Point(0, 0);
this.labelType.Name = "labelType";
this.labelType.Size = new System.Drawing.Size(18, 109);

View File

@ -3,6 +3,7 @@
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using TweetDuck.Core.Controls;
using TweetDuck.Core.Utils;
using TweetDuck.Plugins.Enums;
@ -11,6 +12,8 @@ partial class PluginControl : UserControl{
private readonly PluginManager pluginManager;
private readonly Plugin plugin;
private readonly float dpiScale;
public PluginControl(){
InitializeComponent();
}
@ -19,11 +22,15 @@ public PluginControl(PluginManager pluginManager, Plugin plugin) : this(){
this.pluginManager = pluginManager;
this.plugin = plugin;
this.dpiScale = this.GetDPIScale();
this.labelName.Text = plugin.Name;
this.labelDescription.Text = plugin.CanRun ? plugin.Description : "This plugin requires "+Program.BrandName+" "+plugin.RequiredVersion+" or newer.";
this.labelVersion.Text = plugin.Version;
this.labelAuthor.Text = plugin.Author;
this.labelWebsite.Text = plugin.Website;
this.labelType.LineHeight = (int)Math.Round(9*dpiScale);
UpdatePluginState();
@ -40,7 +47,7 @@ private void panelDescription_Resize(object sender, EventArgs e){
}
else{
labelDescription.MaximumSize = new Size(panelDescription.Width-SystemInformation.VerticalScrollBarWidth, 0);
Height = Math.Min(MinimumSize.Height+9+labelDescription.Height, MaximumSize.Height);
Height = Math.Min(MinimumSize.Height+(int)Math.Round(9*dpiScale)+labelDescription.Height, MaximumSize.Height);
}
}

View File

@ -161,7 +161,8 @@ private static void Main(){
settings.CefCommandLineArgs["disable-extensions"] = "1";
settings.CefCommandLineArgs["disable-plugins-discovery"] = "1";
settings.CefCommandLineArgs["enable-system-flash"] = "0";
Cef.EnableHighDPISupport();
Cef.Initialize(settings, false, new BrowserProcessHandler());
Application.ApplicationExit += (sender, args) => ExitCleanup();

View File

@ -33,8 +33,6 @@ private void InitializeComponent() {
// btnCancel
//
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnCancel.AutoSize = true;
this.btnCancel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.btnCancel.Location = new System.Drawing.Point(195, 34);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Padding = new System.Windows.Forms.Padding(3, 0, 3, 0);