Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1452 | chris | 1 | #region --- License --- |
| 2 | /* Licensed under the MIT/X11 license. |
||
| 3 | * Copyright (c) 2006-2008 the OpenTK Team. |
||
| 4 | * This notice may not be removed from any source distribution. |
||
| 5 | * See license.txt for licensing details. |
||
| 6 | */ |
||
| 7 | #endregion |
||
| 8 | |||
| 9 | using System; |
||
| 10 | using System.Collections.Generic; |
||
| 11 | using System.Text; |
||
| 12 | using System.Drawing; |
||
| 13 | |||
| 14 | using OpenTK; |
||
| 15 | using OpenTK.Input; |
||
| 16 | |||
| 17 | namespace Examples |
||
| 18 | { |
||
| 19 | public static class Utilities |
||
| 20 | { |
||
| 21 | /// <summary> |
||
| 22 | /// Converts a System.Drawing.Color to a System.Int32. |
||
| 23 | /// </summary> |
||
| 24 | /// <param name="c">The System.Drawing.Color to convert.</param> |
||
| 25 | /// <returns>A System.Int32 containing the R, G, B, A values of the |
||
| 26 | /// given System.Drawing.Color in the Rbga32 format.</returns> |
||
| 27 | public static int ColorToRgba32(Color c) |
||
| 28 | { |
||
| 29 | return (int)((c.A << 24) | (c.B << 16) | (c.G << 8) | c.R); |
||
| 30 | } |
||
| 31 | |||
| 32 | /// <summary> |
||
| 33 | /// Sets the window title to the name of the sample. |
||
| 34 | /// </summary> |
||
| 35 | /// <param name="window"></param> |
||
| 36 | public static void SetWindowTitle(GameWindow window) |
||
| 37 | { |
||
| 38 | ExampleAttribute info = GetExampleAttribute(window.GetType()); |
||
| 39 | window.Title = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title); |
||
| 40 | window.Icon = OpenTK.Examples.Properties.Resources.App; |
||
| 41 | } |
||
| 42 | |||
| 43 | /// <summary> |
||
| 44 | /// Sets the window title to the name of the sample. |
||
| 45 | /// </summary> |
||
| 46 | /// <param name="window"></param> |
||
| 47 | public static void SetWindowTitle(System.Windows.Forms.Form window) |
||
| 48 | { |
||
| 49 | ExampleAttribute info = GetExampleAttribute(window.GetType()); |
||
| 50 | window.Text = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title); |
||
| 51 | window.Icon = OpenTK.Examples.Properties.Resources.App; |
||
| 52 | } |
||
| 53 | |||
| 54 | static ExampleAttribute GetExampleAttribute(Type type) |
||
| 55 | { |
||
| 56 | object[] attributes = type.GetCustomAttributes(false); |
||
| 57 | foreach (object attr in attributes) |
||
| 58 | if (attr is ExampleAttribute) |
||
| 59 | return attr as ExampleAttribute; |
||
| 60 | |||
| 61 | return null; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | } |