|
| 1 | +// COPYRIGHT 2009, 2010, 2011, 2012, 2013, 2014, 2015 by the Open Rails project. |
| 2 | +// |
| 3 | +// This file is part of Open Rails. |
| 4 | +// |
| 5 | +// Open Rails is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU General Public License as published by |
| 7 | +// the Free Software Foundation, either version 3 of the License, or |
| 8 | +// (at your option) any later version. |
| 9 | +// |
| 10 | +// Open Rails is distributed in the hope that it will be useful, |
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +// GNU General Public License for more details. |
| 14 | +// |
| 15 | +// You should have received a copy of the GNU General Public License |
| 16 | +// along with Open Rails. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +using System; |
| 19 | +using System.Collections.Generic; |
| 20 | +using System.Drawing; |
| 21 | +using System.Linq; |
| 22 | +using System.Text; |
| 23 | +using System.Threading.Tasks; |
| 24 | +using System.Windows.Forms; |
| 25 | + |
| 26 | +namespace ORTS |
| 27 | +{ |
| 28 | + public class Notification |
| 29 | + { |
| 30 | + public List<NDetail> NDetailList = new List<NDetail>(); |
| 31 | + |
| 32 | + public class NDetail |
| 33 | + { |
| 34 | + public static readonly int TopPadding = 20; |
| 35 | + public static readonly int VerticalSpacing = 10; |
| 36 | + public static readonly int LeftPadding = 10; |
| 37 | + public static readonly int LeftPaddingIndented = 20; |
| 38 | + public static readonly int TitleHeight = 20; |
| 39 | + public static readonly int HeadingHeight = 30; |
| 40 | + public static readonly int TextHeight = 18; |
| 41 | + public static readonly int ButtonHeight = 30; |
| 42 | + public static readonly int RecordHeight = 15; |
| 43 | + public const int ScrollBarWidth = 20; |
| 44 | + |
| 45 | + public Label Control; |
| 46 | + |
| 47 | + public void Add(Notification notification) |
| 48 | + { |
| 49 | + notification.NDetailList.Add(this); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + /// <summary> |
| 54 | + /// Title for the notification |
| 55 | + /// </summary> |
| 56 | + public class NTitleControl : NDetail |
| 57 | + { |
| 58 | + public NTitleControl(Panel panelDetails, DateTime date, string text) |
| 59 | + { |
| 60 | + var title = $"Notification 1/1: {date:dd-MMM-yyyy} - {text}"; |
| 61 | + var left = LeftPadding; |
| 62 | + Control = new Label |
| 63 | + { |
| 64 | + Text = title, |
| 65 | + UseMnemonic = false, |
| 66 | + Font = new Font(panelDetails.Font, FontStyle.Bold), |
| 67 | + TextAlign = ContentAlignment.BottomLeft, |
| 68 | + Height = TitleHeight, |
| 69 | + Width = panelDetails.Width - ScrollBarWidth - left, |
| 70 | + Left = LeftPadding |
| 71 | + }; |
| 72 | + panelDetails.Controls.Add(Control); |
| 73 | + } |
| 74 | + } |
| 75 | + public class NHeadingControl : NDetail |
| 76 | + { |
| 77 | + public NHeadingControl(Panel panelDetails, string text, Color color = default) |
| 78 | + { |
| 79 | + var left = LeftPadding; |
| 80 | + Control = new Label |
| 81 | + { |
| 82 | + ForeColor = color, |
| 83 | + Text = text, |
| 84 | + UseMnemonic = false, |
| 85 | + Font = new Font(panelDetails.Font, FontStyle.Bold), |
| 86 | + TextAlign = ContentAlignment.BottomLeft, |
| 87 | + Height = HeadingHeight, |
| 88 | + Width = panelDetails.Width - ScrollBarWidth - left, |
| 89 | + Left = left, |
| 90 | + Top = TopPadding, |
| 91 | + }; |
| 92 | + panelDetails.Controls.Add(Control); |
| 93 | + } |
| 94 | + } |
| 95 | + public class NTextControl : NDetail |
| 96 | + { |
| 97 | + public NTextControl(Panel panelDetails, string text) |
| 98 | + { |
| 99 | + var left = LeftPaddingIndented; |
| 100 | + Control = new Label |
| 101 | + { |
| 102 | + Text = text, |
| 103 | + UseMnemonic = false, |
| 104 | + Font = new Font(panelDetails.Font, FontStyle.Regular), |
| 105 | + TextAlign = ContentAlignment.BottomLeft, |
| 106 | + Height = TextHeight, |
| 107 | + Width = panelDetails.Width - ScrollBarWidth - left, |
| 108 | + Left = left, |
| 109 | + }; |
| 110 | + panelDetails.Controls.Add(Control); |
| 111 | + } |
| 112 | + } |
| 113 | + public class NButtonControl : NDetail |
| 114 | + { |
| 115 | + public Button Button; |
| 116 | + public NButtonControl(Panel panelDetails, string legend, int width, string description) |
| 117 | + { |
| 118 | + var buttonLeft = LeftPaddingIndented; |
| 119 | + Button = new Button |
| 120 | + { |
| 121 | + Margin = new Padding(20), |
| 122 | + Text = legend, |
| 123 | + UseMnemonic = false, |
| 124 | + Font = new Font(panelDetails.Font, FontStyle.Regular), |
| 125 | + TextAlign = ContentAlignment.MiddleCenter, |
| 126 | + Height = ButtonHeight, |
| 127 | + Width = width, |
| 128 | + Left = buttonLeft, |
| 129 | + Top = TopPadding, |
| 130 | + BackColor = SystemColors.ButtonFace |
| 131 | + }; |
| 132 | + panelDetails.Controls.Add(Button); |
| 133 | + |
| 134 | + var labelLeft = Button.Left + Button.Width + LeftPaddingIndented; |
| 135 | + Control = new Label |
| 136 | + { |
| 137 | + Margin = new Padding(20), |
| 138 | + Text = description, |
| 139 | + UseMnemonic = false, |
| 140 | + Font = new Font(panelDetails.Font, FontStyle.Regular), |
| 141 | + TextAlign = ContentAlignment.MiddleLeft, |
| 142 | + Height = ButtonHeight, |
| 143 | + Width = panelDetails.Width - ScrollBarWidth - labelLeft, |
| 144 | + Top = TopPadding, |
| 145 | + Left = labelLeft |
| 146 | + }; |
| 147 | + panelDetails.Controls.Add(Control); |
| 148 | + } |
| 149 | + } |
| 150 | + public class NRecordControl : NDetail |
| 151 | + { |
| 152 | + public Label Field; |
| 153 | + public NRecordControl(Panel panelDetails, string label, int width, string field) |
| 154 | + { |
| 155 | + Control = new Label |
| 156 | + { |
| 157 | + Text = label + ":", |
| 158 | + UseMnemonic = false, |
| 159 | + Font = new Font(panelDetails.Font, FontStyle.Bold), |
| 160 | + TextAlign = ContentAlignment.BottomRight, |
| 161 | + Width = width, |
| 162 | + Height = RecordHeight, |
| 163 | + Left = LeftPadding, |
| 164 | + Top = TopPadding |
| 165 | + }; |
| 166 | + panelDetails.Controls.Add(Control); |
| 167 | + |
| 168 | + var left = width + LeftPadding; |
| 169 | + Field = new Label |
| 170 | + { |
| 171 | + Text = field, |
| 172 | + UseMnemonic = false, |
| 173 | + Font = new Font(panelDetails.Font, FontStyle.Regular), |
| 174 | + TextAlign = ContentAlignment.BottomLeft, |
| 175 | + Width = panelDetails.Width - ScrollBarWidth - left, |
| 176 | + Height = RecordHeight, |
| 177 | + Left = left, |
| 178 | + Top = TopPadding |
| 179 | + }; |
| 180 | + panelDetails.Controls.Add(Field); |
| 181 | + } |
| 182 | + } |
| 183 | + |
| 184 | + public void FlowNDetails() |
| 185 | + { |
| 186 | + var top = 2; |
| 187 | + foreach (var nDetail in NDetailList) |
| 188 | + { |
| 189 | + nDetail.Control.Top = top; |
| 190 | + |
| 191 | + // Adjust details that have a second part. |
| 192 | + if (nDetail is NButtonControl) |
| 193 | + { |
| 194 | + ((NButtonControl)nDetail).Button.Top = top; |
| 195 | + } |
| 196 | + if (nDetail is NRecordControl) |
| 197 | + { |
| 198 | + ((NRecordControl)nDetail).Field.Top = top; |
| 199 | + } |
| 200 | + |
| 201 | + top += nDetail.Control.Height + NDetail.VerticalSpacing; |
| 202 | + } |
| 203 | + } |
| 204 | + } |
| 205 | + |
| 206 | +} |
0 commit comments