Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Program.cs « UVtools.GUI - github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 675c1fae867445991a449bd3852ab95f0102aa53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 *                     GNU AFFERO GENERAL PUBLIC LICENSE
 *                       Version 3, 19 November 2007
 *  Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
 *  Everyone is permitted to copy and distribute verbatim copies
 *  of this license document, but changing it is not allowed.
 */
using System;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Threading;
using System.Windows.Forms;
using ApplicationManagement;
using Emgu.CV;
using UVtools.Core;
using UVtools.GUI.Forms;

namespace UVtools.GUI
{
    static class Program
    {
        /// <summary>
        /// Changes fonts of controls contained in font collection recursively. <br/>
        /// <b>Usage:</b> <c><br/>
        /// SetAllControlsFont(this.Controls, 20); // This makes fonts 20% bigger. <br/>
        /// SetAllControlsFont(this.Controls, -4, false); // This makes fonts smaller by 4.</c>
        /// </summary>
        /// <param name="ctrls">Control collection containing controls</param>
        /// <param name="amount">Amount to change: posive value makes it bigger, 
        /// negative value smaller</param>
        /// <param name="amountInPercent">True - grow / shrink in percent, 
        /// False - grow / shrink absolute</param>
        /// <param name="amountType">0 = Absolute | 1 = Partial | 2 = Percent</param>
        public static void SetAllControlsFontSize(
            Control.ControlCollection ctrls,
            int amount = 0, byte amountType = 0)
        {
            if (amount == 0) return;
            foreach (Control ctrl in ctrls)
            {
                // recursive
                SetAllControlsFontSize(ctrl.Controls, amount, amountType);

                var oldSize = ctrl.Font.Size;
                float newSize;
                switch (amountType)
                {
                    case 1:
                        newSize = oldSize + amount;
                        break;
                    case 2:
                        newSize = oldSize + oldSize * (amount / 100);
                        break;
                    default:
                        newSize = amount;
                        break;
                }
                
                if (newSize < 8) newSize = 8; // don't allow less than 8
                var fontFamilyName = ctrl.Font.FontFamily.Name;
                var fontStyle = ctrl.Font.Style;
                ctrl.Font = new Font(fontFamilyName, newSize, fontStyle);
            };
        }

        public static Matrix<byte> KernelStar3x3 { get; } = new Matrix<byte>(new byte[,]
        {
            { 0, 1, 0 },
            { 1, 0, 1 }, 
            { 0, 1, 0 }
        });

        public static Matrix<sbyte> KernelFindIsolated { get; } = new Matrix<sbyte>(new sbyte[,]
        {
            { 0, 1, 0 },
            { 1, -1, 1 },
            { 0, 1, 0 }
        });

        public static FileFormat SlicerFile { get; set; }
        public static FrmMain FrmMain { get; private set; }
        public static FrmAbout FrmAbout { get; private set; }

        public static ExceptionHandler ExceptionHandler { get; private set; }

        public static string[] Args { get; private set; }
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Args = args;
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            ExceptionHandler = new ExceptionHandler {MessageBoxButtons = MessageBoxButtons.OK};
            ExceptionHandler.StartHandlingExceptions();

            FrmMain = new FrmMain();
            FrmAbout = new FrmAbout();

            Application.Run(FrmMain);
        }

        public static void NewInstance(string filePath)
        {
            var info = new ProcessStartInfo(Application.ExecutablePath, $"\"{filePath}\"");
            Process.Start(info);
        }
    }
}