diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2017-01-27 00:21:48 +0100 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2017-01-27 00:21:48 +0100 |
| commit | 8a25a19ee73e8b7c0c9726bbb2ce4ec918f4e905 (patch) | |
| tree | 8098ec3d8137c0dcc569db78fbdb4d6921187e28 /src | |
| parent | a519d07929a490ac9bfade86355865744787f311 (diff) | |
icon menuitem, PopWidth and PopHeight, commands
Diffstat (limited to 'src')
| -rw-r--r-- | src/Command.cs | 34 | ||||
| -rw-r--r-- | src/GraphicObjects/Button.cs | 15 | ||||
| -rw-r--r-- | src/GraphicObjects/Image.cs | 79 | ||||
| -rw-r--r-- | src/GraphicObjects/Menu.cs | 6 | ||||
| -rw-r--r-- | src/GraphicObjects/MenuItem.cs | 67 | ||||
| -rw-r--r-- | src/GraphicObjects/Popper.cs | 33 |
6 files changed, 170 insertions, 64 deletions
diff --git a/src/Command.cs b/src/Command.cs index 35a7facc..f7a12465 100644 --- a/src/Command.cs +++ b/src/Command.cs @@ -35,16 +35,20 @@ namespace Crow #endregion #region CTOR - public Command () + public Command (Action _executeAction) { + execute = _executeAction; } #endregion + Action execute; + string caption; + Picture icon; bool isEnabled; - - [XmlAttributeAttribute()][DefaultValue(true)] + #region Public properties + [XmlAttributeAttribute][DefaultValue(true)] public virtual bool IsEnabled { get { return isEnabled; } set { @@ -54,7 +58,7 @@ namespace Crow NotifyValueChanged ("IsEnabled", isEnabled); } } - [XmlAttributeAttribute()][DefaultValue("Unamed Command")] + [XmlAttributeAttribute][DefaultValue("Unamed Command")] public virtual string Caption { get { return caption; } set { @@ -65,5 +69,27 @@ namespace Crow } } + [XmlAttributeAttribute] + public Picture Icon { + get { return icon; } + set { + if (icon == value) + return; + icon = value; + NotifyValueChanged ("Icon", icon); + } + } + #endregion + + public void Execute(){ + if (execute != null) + execute (); + } + internal void raiseAllValuesChanged(){ + NotifyValueChanged ("IsEnabled", isEnabled); + NotifyValueChanged ("Icon", icon); + NotifyValueChanged ("Caption", caption); + } + } } diff --git a/src/GraphicObjects/Button.cs b/src/GraphicObjects/Button.cs index 1cfbe85c..c73062f0 100644 --- a/src/GraphicObjects/Button.cs +++ b/src/GraphicObjects/Button.cs @@ -26,7 +26,6 @@ namespace Crow public event EventHandler Pressed; public event EventHandler Released; - public event EventHandler Clicked; #region TemplatedContainer overrides public override GraphicObject Content { @@ -34,7 +33,7 @@ namespace Crow return _contentContainer == null ? null : _contentContainer.Child; } set { - if (_contentContainer != null) + if (_contentContainer != null) _contentContainer.SetChild(value); } } @@ -69,24 +68,24 @@ namespace Crow [XmlAttributeAttribute][DefaultValue("Button")] public string Caption { - get { return caption; } + get { return caption; } set { if (caption == value) return; - caption = value; + caption = value; NotifyValueChanged ("Caption", caption); } - } + } [XmlAttributeAttribute][DefaultValue("#Crow.Images.button.svg")] public string Image { - get { return image; } + get { return image; } set { if (image == value) return; - image = value; + image = value; NotifyValueChanged ("Image", image); } - } + } [XmlAttributeAttribute][DefaultValue(false)] public bool IsPressed { diff --git a/src/GraphicObjects/Image.cs b/src/GraphicObjects/Image.cs index fa036b97..281011ad 100644 --- a/src/GraphicObjects/Image.cs +++ b/src/GraphicObjects/Image.cs @@ -11,66 +11,81 @@ namespace Crow { Picture _pic; string _svgSub; - bool scaled; - [XmlAttributeAttribute()][DefaultValue(true)] + bool scaled, keepProps; + + #region Public properties + [XmlAttributeAttribute][DefaultValue(true)] public virtual bool Scaled { get { return scaled; } set { if (scaled == value) return; - scaled = value; + scaled = value; NotifyValueChanged ("Scaled", scaled); if (_pic == null) return; _pic.Scaled = scaled; RegisterForGraphicUpdate (); } - } - bool keepProps; - [XmlAttributeAttribute()][DefaultValue(true)] + } + [XmlAttributeAttribute][DefaultValue(true)] public virtual bool KeepProportions { get { return keepProps; } set { if (keepProps == value) return; - keepProps = value; + keepProps = value; NotifyValueChanged ("KeepProportions", keepProps); if (_pic == null) return; _pic.KeepProportions = keepProps; RegisterForGraphicUpdate (); } - } - [XmlAttributeAttribute("Path")] + } + [XmlAttributeAttribute] public string Path { - get { return _pic == null ? null : _pic.Path; } - set { + get { return _pic == null ? "" : _pic.Path; } + set { + if (value == Path) + return; try { - if (string.IsNullOrEmpty(value)){ - _pic = null; - return; - } - lock(CurrentInterface.LayoutMutex){ - LoadImage (value); - _pic.Scaled = scaled; - _pic.KeepProportions = keepProps; + if (string.IsNullOrEmpty(value)) + Picture = null; + else { + lock(CurrentInterface.LayoutMutex){ + LoadImage (value); + } } } catch (Exception ex) { Debug.WriteLine (ex.Message); _pic = null; } + NotifyValueChanged ("Path", Path); } } - - [XmlAttributeAttribute()][DefaultValue(null)] + [XmlAttributeAttribute] public string SvgSub { get { return _svgSub; } set { + if (_svgSub == value) + return; _svgSub = value; RegisterForGraphicUpdate (); } } - + [XmlAttributeAttribute] + public Picture Picture { + get { return _pic; } + set { + if (_pic == value) + return; + _pic = value; + NotifyValueChanged ("Picture", _pic); + RegisterForGraphicUpdate (); + } + } + #endregion + #region CTOR public Image () : base() { @@ -80,14 +95,17 @@ namespace Crow #region Image Loading public void LoadImage (string path) { + Picture pic; + if (path.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture)) + pic = new SvgPicture (); + else + pic = new BmpPicture (); - if (path.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture)) - _pic = new SvgPicture (); - else - _pic = new BmpPicture (); + pic.LoadImage (path); + pic.Scaled = scaled; + pic.KeepProportions = keepProps; - _pic.LoadImage (path); - RegisterForGraphicUpdate (); + Picture = pic; } #endregion @@ -95,12 +113,13 @@ namespace Crow protected override int measureRawSize (LayoutingType lt) { if (_pic == null) - _pic = "#Crow.Images.Icons.IconAlerte.svg"; + return 2 * Margin; + //_pic = "#Crow.Images.Icons.IconAlerte.svg"; //TODO:take scalling in account if (lt == LayoutingType.Width) return _pic.Dimensions.Width + 2 * Margin; else - return _pic.Dimensions.Height + 2 * Margin; + return _pic.Dimensions.Height + 2 * Margin; } protected override void onDraw (Context gr) { diff --git a/src/GraphicObjects/Menu.cs b/src/GraphicObjects/Menu.cs index 1a7a3f95..66d23194 100644 --- a/src/GraphicObjects/Menu.cs +++ b/src/GraphicObjects/Menu.cs @@ -31,8 +31,10 @@ namespace Crow #endregion Orientation orientation; + bool autoOpen = false; - [XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)] + #region Public properties + [XmlAttributeAttribute][DefaultValue(Orientation.Horizontal)] public Orientation Orientation { get { return orientation; } set { @@ -42,12 +44,12 @@ namespace Crow NotifyValueChanged ("Orientation", orientation); } } - bool autoOpen = false; [XmlIgnore]public bool AutomaticOpenning { get { return autoOpen; } set { autoOpen = value; } } + #endregion public override void AddItem (GraphicObject g) { diff --git a/src/GraphicObjects/MenuItem.cs b/src/GraphicObjects/MenuItem.cs index 80b5759d..adec326f 100644 --- a/src/GraphicObjects/MenuItem.cs +++ b/src/GraphicObjects/MenuItem.cs @@ -32,12 +32,14 @@ namespace Crow public event EventHandler Open; public event EventHandler Close; - public event EventHandler Execute; string caption; - Command command;//TODO + Command command; + Picture icon; bool isOpened; + Measure popWidth, popHeight; + #region Public properties [XmlAttributeAttribute][DefaultValue(false)] public bool IsOpened { get { return isOpened; } @@ -54,38 +56,87 @@ namespace Crow onClose (this, null); } } - [XmlAttributeAttribute][DefaultValue(null)] public virtual Command Command { get { return command; } set { if (command == value) return; + + if (command != null) { + command.raiseAllValuesChanged (); + command.ValueChanged -= Command_ValueChanged; + } + command = value; + + if (command != null) { + command.ValueChanged += Command_ValueChanged; + command.raiseAllValuesChanged (); + } + NotifyValueChanged ("Command", command); } } - [XmlAttributeAttribute][DefaultValue("MenuItem")] public string Caption { - get { return caption; } + get { return Command == null ? caption : Command.Caption; } set { if (caption == value) return; caption = value; - NotifyValueChanged ("Caption", caption); + + if (command == null)//raise value changed only if not bound to a command + NotifyValueChanged ("Caption", caption); + } + } + [XmlAttributeAttribute] + public Picture Icon { + get { return Command == null ? icon : Command.Icon;; } + set { + if (icon == value) + return; + icon = value; + if (command == null) + NotifyValueChanged ("Icon", icon); } } - + [XmlAttributeAttribute()][DefaultValue("Fit")] + public virtual Measure PopWidth { + get { return popWidth; } + set { + if (popWidth == value) + return; + popWidth = value; + NotifyValueChanged ("PopWidth", popWidth); + } + } + [XmlAttributeAttribute()][DefaultValue("Fit")] + public virtual Measure PopHeight { + get { return popHeight; } + set { + if (popHeight == value) + return; + popHeight = value; + NotifyValueChanged ("PopHeight", popHeight); + } + } + #endregion + public override void AddItem (GraphicObject g) { base.AddItem (g); g.NotifyValueChanged ("PopDirection", Alignment.Right); } + void Command_ValueChanged (object sender, ValueChangeEventArgs e) + { + NotifyValueChanged (e.MemberName, e.NewValue); + } void onMI_Click (object sender, MouseButtonEventArgs e) { - Execute.Raise (this, null); + if (command != null) + command.Execute (); if(!IsOpened) (LogicalParent as Menu).AutomaticOpenning = false; } diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs index 84088355..8c79ce24 100644 --- a/src/GraphicObjects/Popper.cs +++ b/src/GraphicObjects/Popper.cs @@ -38,6 +38,7 @@ namespace Crow string caption; Alignment popDirection; GraphicObject _content; + Measure popWidth, popHeight; public event EventHandler Pop; public event EventHandler Unpop; @@ -53,6 +54,26 @@ namespace Crow NotifyValueChanged ("Caption", caption); } } + [XmlAttributeAttribute()][DefaultValue("Fit")] + public virtual Measure PopWidth { + get { return popWidth; } + set { + if (popWidth == value) + return; + popWidth = value; + NotifyValueChanged ("PopWidth", popWidth); + } + } + [XmlAttributeAttribute()][DefaultValue("Fit")] + public virtual Measure PopHeight { + get { return popHeight; } + set { + if (popHeight == value) + return; + popHeight = value; + NotifyValueChanged ("PopHeight", popHeight); + } + } [XmlAttributeAttribute()][DefaultValue(false)] public bool IsPopped { @@ -164,18 +185,6 @@ namespace Crow } #region GraphicObject overrides - public override void OnLayoutChanges (LayoutingType layoutType) - { - base.OnLayoutChanges (layoutType); - - if (_content == null) - return; - - if (layoutType == LayoutingType.Width) - _content.MinimumSize = new Size (this.Slot.Width, _content.MinimumSize.Height); - } - - public override void onMouseClick (object sender, MouseButtonEventArgs e) { if (_canPop) |