Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Button.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System.Diagnostics;
4 
5 using SiliconStudio.Core;
6 
7 namespace SiliconStudio.Paradox.UI.Controls
8 {
9  /// <summary>
10  /// Represents a Windows button control, which reacts to the Click event.
11  /// </summary>
12  [DebuggerDisplay("Button - Name={Name}")]
13  public class Button : ButtonBase
14  {
15  /// <summary>
16  /// The key to the NotPressedImage dependency property.
17  /// </summary>
18  public static readonly PropertyKey<UIImage> NotPressedImagePropertyKey = new PropertyKey<UIImage>("NotPressedImageKey", typeof(Button), DefaultValueMetadata.Static<UIImage>(null), ObjectInvalidationMetadata.New<UIImage>(OnAspectImageInvalidated));
19 
20  /// <summary>
21  /// The key to the PressedImage dependency property.
22  /// </summary>
23  public static readonly PropertyKey<UIImage> PressedImagePropertyKey = new PropertyKey<UIImage>("PressedImageKey", typeof(Button), DefaultValueMetadata.Static<UIImage>(null), ObjectInvalidationMetadata.New<UIImage>(OnAspectImageInvalidated));
24 
25  /// <summary>
26  /// The key to the MouseOverImage dependency property.
27  /// </summary>
28  public static readonly PropertyKey<UIImage> MouseOverImagePropertyKey = new PropertyKey<UIImage>("MouseOverImageKey", typeof(Button), DefaultValueMetadata.Static<UIImage>(null), ObjectInvalidationMetadata.New<UIImage>(OnAspectImageInvalidated));
29 
30  public Button()
31  {
32  DrawLayerNumber += 1; // (button design image)
33  Padding = new Thickness(10, 5, 10, 7);
34  }
35 
36  private static void OnAspectImageInvalidated(object propertyOwner, PropertyKey<UIImage> propertyKey, UIImage propertyOldValue)
37  {
38  var button = (Button)propertyOwner;
39  button.OnAspectImageInvalidated();
40  }
41 
42  /// <summary>
43  /// Function triggered when one of the <see cref="PressedImage"/> and <see cref="NotPressedImage"/> images are invalidated.
44  /// This function can be overridden in inherited classes.
45  /// </summary>
46  protected virtual void OnAspectImageInvalidated()
47  {
48  }
49 
50  /// <summary>
51  /// Gets or sets the image that the button displays when pressed
52  /// </summary>
53  public UIImage PressedImage
54  {
55  get { return DependencyProperties.Get(PressedImagePropertyKey); }
56  set { DependencyProperties.Set(PressedImagePropertyKey, value); }
57  }
58 
59  /// <summary>
60  /// Gets or sets the image that the button displays when not pressed
61  /// </summary>
62  public UIImage NotPressedImage
63  {
64  get { return DependencyProperties.Get(NotPressedImagePropertyKey); }
65  set { DependencyProperties.Set(NotPressedImagePropertyKey, value); }
66  }
67 
68  /// <summary>
69  /// Gets or sets the image that the button displays when the mouse is over it
70  /// </summary>
71  public UIImage MouseOverImage
72  {
73  get { return DependencyProperties.Get(MouseOverImagePropertyKey); }
74  set { DependencyProperties.Set(MouseOverImagePropertyKey, value); }
75  }
76  }
77 }
Represents the base primitive for all the button-like controls
Definition: ButtonBase.cs:15
Represents a Windows button control, which reacts to the Click event.
Definition: Button.cs:13
Describes the thickness of a frame around a cuboid. Six float values describe the Left...
Definition: Thickness.cs:12
Class holding all the data required to define an UI image.
Definition: UIImage.cs:15
A class that represents a tag propety.
Definition: PropertyKey.cs:17
virtual void OnAspectImageInvalidated()
Function triggered when one of the PressedImage and NotPressedImage images are invalidated. This function can be overridden in inherited classes.
Definition: Button.cs:46