mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-30 05:34:06 +02:00
Replace Math.Round calls with a more convenient custom method
This commit is contained in:
parent
7f3bd2715c
commit
d9e6afbf36
Core
Plugins/Controls
@ -67,12 +67,13 @@ protected Point PrimaryLocation{
|
||||
public Func<bool> CanMoveWindow = () => true;
|
||||
protected override bool ShowWithoutActivation => true;
|
||||
|
||||
protected double SizeScale => dpiScale*Program.UserConfig.ZoomMultiplier;
|
||||
|
||||
protected readonly Form owner;
|
||||
protected readonly ChromiumWebBrowser browser;
|
||||
|
||||
protected float dpiScale;
|
||||
|
||||
|
||||
private readonly ResourceHandlerNotification resourceHandler = new ResourceHandlerNotification();
|
||||
private readonly float dpiScale;
|
||||
|
||||
private string currentColumn;
|
||||
private int pauseCounter;
|
||||
@ -181,7 +182,7 @@ protected virtual void LoadTweet(TweetNotification tweet){
|
||||
}
|
||||
|
||||
protected virtual void SetNotificationSize(int width, int height){
|
||||
browser.ClientSize = ClientSize = new Size((int)Math.Round(width*dpiScale*Program.UserConfig.ZoomMultiplier), (int)Math.Round(height*dpiScale*Program.UserConfig.ZoomMultiplier));
|
||||
browser.ClientSize = ClientSize = new Size(BrowserUtils.Scale(width, SizeScale), BrowserUtils.Scale(height, SizeScale));
|
||||
}
|
||||
|
||||
protected virtual void OnNotificationReady(){
|
||||
|
@ -55,16 +55,16 @@ 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);
|
||||
int width = level == 0 ? 284 : BrowserUtils.Scale(284, 1.0+0.05*level);
|
||||
return BrowserUtils.Scale(width, SizeScale);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
int height = level == 0 ? 118 : BrowserUtils.Scale(118, 1.0+0.075*level);
|
||||
return BrowserUtils.Scale(height, SizeScale);
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,9 +104,7 @@ private IntPtr MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam){
|
||||
int eventType = wParam.ToInt32();
|
||||
|
||||
if (eventType == NativeMethods.WM_MOUSEWHEEL && browser.Bounds.Contains(PointToClient(Cursor.Position))){
|
||||
int distance = (int)Math.Round(NativeMethods.GetMouseHookData(lParam)*(Program.UserConfig.NotificationScrollSpeed/100.0));
|
||||
|
||||
browser.SendMouseWheelEvent(0, 0, 0, distance, CefEventFlags.None);
|
||||
browser.SendMouseWheelEvent(0, 0, 0, BrowserUtils.Scale(NativeMethods.GetMouseHookData(lParam), Program.UserConfig.NotificationScrollSpeed/100.0), CefEventFlags.None);
|
||||
return NativeMethods.HOOK_HANDLED;
|
||||
}
|
||||
else if (eventType == NativeMethods.WM_XBUTTONDOWN && DesktopBounds.Contains(Cursor.Position)){
|
||||
@ -177,7 +175,7 @@ private void timerHideProgress_Tick(object sender, EventArgs e){
|
||||
|
||||
timeLeft -= timerProgress.Interval;
|
||||
|
||||
int value = (int)Math.Round(1025.0*(totalTime-timeLeft)/totalTime);
|
||||
int value = BrowserUtils.Scale(1025, (totalTime-timeLeft)/(double)totalTime);
|
||||
progressBarTimer.SetValueInstant(Math.Min(1000, Math.Max(0, Program.UserConfig.NotificationTimerCountDown ? 1000-value : value)));
|
||||
|
||||
if (timeLeft <= 0){
|
||||
|
@ -5,6 +5,7 @@
|
||||
using TweetDuck.Core.Controls;
|
||||
using TweetDuck.Core.Other.Settings;
|
||||
using TweetDuck.Core.Other.Settings.Dialogs;
|
||||
using TweetDuck.Core.Utils;
|
||||
using TweetDuck.Plugins;
|
||||
using TweetDuck.Updates;
|
||||
|
||||
@ -28,7 +29,7 @@ public FormSettings(FormBrowser browser, PluginManager plugins, UpdateHandler up
|
||||
|
||||
this.plugins = plugins;
|
||||
|
||||
this.buttonHeight = (int)Math.Round(39*this.GetDPIScale()) | 1;
|
||||
this.buttonHeight = BrowserUtils.Scale(39, this.GetDPIScale()) | 1;
|
||||
|
||||
AddButton("General", () => new TabSettingsGeneral(updates));
|
||||
AddButton("Notifications", () => new TabSettingsNotifications(browser.CreateNotificationForm(false)));
|
||||
|
@ -93,6 +93,10 @@ public static WebClient DownloadFileAsync(string url, string target, Action onSu
|
||||
return client;
|
||||
}
|
||||
|
||||
public static int Scale(int baseValue, double scaleFactor){
|
||||
return (int)Math.Round(baseValue*scaleFactor);
|
||||
}
|
||||
|
||||
public static void SetZoomLevel(IBrowser browser, int percentage){
|
||||
browser.GetHost().SetZoomLevel(Math.Log(percentage/100.0, 1.2));
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public PluginControl(PluginManager pluginManager, Plugin plugin) : this(){
|
||||
this.labelAuthor.Text = plugin.Author;
|
||||
this.labelWebsite.Text = plugin.Website;
|
||||
|
||||
this.labelType.LineHeight = (int)Math.Round(9*dpiScale);
|
||||
this.labelType.LineHeight = BrowserUtils.Scale(9, dpiScale);
|
||||
|
||||
UpdatePluginState();
|
||||
|
||||
@ -47,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+(int)Math.Round(9*dpiScale)+labelDescription.Height, MaximumSize.Height);
|
||||
Height = Math.Min(MinimumSize.Height+BrowserUtils.Scale(9, dpiScale)+labelDescription.Height, MaximumSize.Height);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user