OSDN Git Service

クラス名をリネームする
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / View / Scaler.cs
1 // Copyright (C) 2019 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
2 //\r
3 // Licensed under the Apache License, Version 2.0 (the "License");\r
4 // you may not use this file except in compliance with the License.\r
5 // You may obtain a copy of the License at\r
6 //\r
7 //    http://www.apache.org/licenses/LICENSE-2.0\r
8 //\r
9 // Unless required by applicable law or agreed to in writing, software\r
10 // distributed under the License is distributed on an "AS IS" BASIS,\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 // See the License for the specific language governing permissions and\r
13 // limitations under the License.\r
14 \r
15 using System;\r
16 using System.Drawing;\r
17 using System.Windows.Forms;\r
18 \r
19 namespace KancolleSniffer.View\r
20 {\r
21     public static class Scaler\r
22     {\r
23         public static SizeF Factor { private get; set; } = new SizeF(1, 1);\r
24 \r
25         public static void Scale(Control control)\r
26         {\r
27             control.Scale(Factor);\r
28         }\r
29 \r
30         public static float ScaleWidth(float width)\r
31         {\r
32             return width * Factor.Width;\r
33         }\r
34 \r
35         public static float ScaleHeight(float height)\r
36         {\r
37             return height * Factor.Height;\r
38         }\r
39 \r
40         public static int ScaleWidth(int width)\r
41         {\r
42             return (int)Math.Round(width * Factor.Width);\r
43         }\r
44 \r
45         public static int ScaleHeight(int height)\r
46         {\r
47             return (int)Math.Round(height * Factor.Height);\r
48         }\r
49 \r
50         public static Size Scale(int width, int height)\r
51         {\r
52             return new Size(ScaleWidth(width), ScaleHeight(height));\r
53         }\r
54 \r
55         public static SizeF Scale(float width, float height)\r
56         {\r
57             return new SizeF(ScaleWidth(width), ScaleHeight(height));\r
58         }\r
59 \r
60         public static Point Move(int x, int y, int width, int height)\r
61         {\r
62             return new Point(x + ScaleWidth(width), y + ScaleHeight(height));\r
63         }\r
64 \r
65         public static int DownWidth(int width)\r
66         {\r
67             return (int)(width / Factor.Width);\r
68         }\r
69     }\r
70 }