-// Copyright (c) 2017 Samsung Electronics Co., Ltd.
+// Copyright (c) 2017 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// This File has been auto-generated by SWIG and then modified using DALi Ruby Scripts
// Some have been manually changed
-\r
-using System;\r
-using System.Runtime.InteropServices;\r
-using Tizen.NUI;\r
-\r
-// A spin control (for continously changing values when users can easily predict a set of values)\r
-\r
-namespace Tizen.NUI\r
-{\r
- ///<summary>\r
- ///Spin CustomView class\r
- /// </summary>\r
- public class Spin : CustomView\r
- {\r
- private VisualBase _arrowVisual;\r
- private TextField _textField;\r
- private int _arrowVisualPropertyIndex;\r
- private string _arrowImage;\r
- private int _currentValue;\r
- private int _minValue;\r
- private int _maxValue;\r
- private int _singleStep;\r
- private bool _wrappingEnabled;\r
- private string _fontFamily;\r
- private string _fontStyle;\r
- private int _pointSize;\r
- private Color _textColor;\r
- private Color _textBackgroundColor;\r
- private int _maxTextLength;\r
-\r
- // Called by DALi Builder if it finds a Spin control in a JSON file\r
- static CustomView CreateInstance()\r
- {\r
- return new Spin();\r
- }\r
-\r
- // static constructor registers the control type (only runs once)\r
- static Spin()\r
- {\r
- // ViewRegistry registers control type with DALi type registery\r
- // also uses introspection to find any properties that need to be registered with type registry\r
- ViewRegistry.Instance.Register(CreateInstance, typeof(Spin));\r
- }\r
-\r
- public Spin() : base(typeof(Spin).Name, CustomViewBehaviour.RequiresKeyboardNavigationSupport)\r
- {\r
-\r
- }\r
-\r
- /// <summary>\r
- /// Override method of OnInitialize() for CustomView class.\r
- /// This method is called after the Control has been initialized.\r
- /// Derived classes should do any second phase initialization by overriding this method.\r
- /// </summary>\r
- public override void OnInitialize()\r
- {\r
- // Initialize the propertiesControl\r
- _arrowImage = "/home/owner/apps_rw/NUISamples.TizenTV/res/images/arrow.png";\r
- _textBackgroundColor = new Color(0.6f, 0.6f, 0.6f, 1.0f);\r
- _currentValue = 0;\r
- _minValue = 0;\r
- _maxValue = 0;\r
- _singleStep = 1;\r
- _maxTextLength = 0;\r
-\r
- // Create image visual for the arrow keys\r
- _arrowVisualPropertyIndex = RegisterProperty("ArrowImage", new PropertyValue(_arrowImage), Tizen.NUI.PropertyAccessMode.ReadWrite);\r
- _arrowVisual = VisualFactory.Get().CreateVisual(_arrowImage, new Uint16Pair(150, 150));\r
- RegisterVisual(_arrowVisualPropertyIndex, _arrowVisual);\r
-\r
- // Create a text field\r
- _textField = new TextField();\r
- _textField.ParentOrigin = Tizen.NUI.ParentOrigin.Center;\r
- _textField.AnchorPoint = Tizen.NUI.AnchorPoint.Center;\r
- _textField.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;\r
- _textField.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;\r
- _textField.SizeModeFactor = new Vector3(1.0f, 0.45f, 1.0f);\r
- _textField.PlaceholderText = "----";\r
- _textField.BackgroundColor = _textBackgroundColor;\r
- _textField.HorizontalAlignment = "Center";\r
- _textField.VerticalAlignment = "Center";\r
- _textField.Focusable = (true);\r
- _textField.Name = "_textField";\r
-\r
- this.Add(_textField);\r
-\r
- _textField.FocusGained += TextFieldKeyInputFocusGained;\r
- _textField.FocusLost += TextFieldKeyInputFocusLost;\r
- }\r
-\r
- /// <summary>\r
- /// Override method of GetNaturalSize() for CustomView class.\r
- /// Return the natural size of the actor.\r
- /// </summary>\r
- /// <returns> Natural size of this Spin itself</returns>\r
- public override Size GetNaturalSize()\r
- {\r
- return new Size(150.0f, 150.0f, 0.0f);\r
- }\r
-\r
- /// <summary>\r
- /// Event handler when the TextField in Spin gets the Key focus\r
- /// Make sure when the current spin that takes input focus also takes the keyboard focus\r
- /// For example, when you tap the spin directly\r
- /// </summary>\r
- /// <param name="source">Sender of this event</param>\r
- /// <param name="e">Event arguments</param>\r
- public void TextFieldKeyInputFocusGained(object source, EventArgs e)\r
- {\r
- FocusManager.Instance.SetCurrentFocusView(_textField);\r
- }\r
-\r
- /// <summary>\r
- /// Event handler when the TextField in Spin looses it's Key focus\r
- /// </summary>\r
- /// <param name="source"></param>\r
- /// <param name="e"></param>\r
- public void TextFieldKeyInputFocusLost(object source, EventArgs e)\r
- {\r
- int previousValue = _currentValue;\r
-\r
- // If the input value is invalid, change it back to the previous valid value\r
- if (int.TryParse(_textField.Text, out _currentValue))\r
- {\r
- if (_currentValue < _minValue || _currentValue > _maxValue)\r
- {\r
- _currentValue = previousValue;\r
- }\r
- }\r
- else\r
- {\r
- _currentValue = previousValue;\r
- }\r
-\r
- // Otherwise take the new value\r
- this.Value = _currentValue;\r
- }\r
-\r
- /// <summary>\r
- /// Override method of GetNextKeyboardFocusableActor() for CustomView class.\r
- /// Gets the next key focusable actor in this View towards the given direction.\r
- /// A View needs to override this function in order to support two dimensional key navigation.\r
- /// </summary>\r
- /// <param name="currentFocusedActor">The current focused actor</param>\r
- /// <param name="direction">The direction to move the focus towards</param>\r
- /// <param name="loopEnabled">Whether the focus movement should be looped within the control</param>\r
- /// <returns>The next keyboard focusable actor in this control or an empty handle if no actor can be focused</returns>\r
- public override Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, View.FocusDirection direction, bool loopEnabled)\r
- {\r
- // Respond to Up/Down keys to change the value while keeping the current spin focused\r
- Actor nextFocusedActor = currentFocusedActor;\r
- if (direction == View.FocusDirection.Up)\r
- {\r
- this.Value += this.Step;\r
- nextFocusedActor = _textField;\r
- }\r
- else if (direction == View.FocusDirection.Down)\r
- {\r
- this.Value -= this.Step;\r
- nextFocusedActor = _textField;\r
- }\r
- else\r
- {\r
- // Return a native empty handle as nothing can be focused in the left or right\r
- nextFocusedActor = new Actor();\r
- nextFocusedActor.Reset();\r
- }\r
-\r
- return nextFocusedActor;\r
- }\r
-\r
- /// <summary>\r
- /// Value to be set in Spin\r
- /// </summary>\r
- [ScriptableProperty()]\r
- public int Value\r
- {\r
- get\r
- {\r
- return _currentValue;\r
- }\r
- set\r
- {\r
-\r
- Console.WriteLine("Value set to " + value);\r
- _currentValue = value;\r
-\r
- // Make sure no invalid value is accepted\r
- if (_currentValue < _minValue)\r
- {\r
- _currentValue = _minValue;\r
- }\r
-\r
- if (_currentValue > _maxValue)\r
- {\r
- _currentValue = _maxValue;\r
- }\r
-\r
- _textField.Text = _currentValue.ToString();\r
- }\r
- }\r
- \r
- /// <summary>\r
- /// Minimum Value of Spin Value\r
- /// </summary>\r
- // MinValue property of type int:\r
- [ScriptableProperty()]\r
- public int MinValue\r
- {\r
- get\r
- {\r
- return _minValue;\r
- }\r
- set\r
- {\r
- _minValue = value;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Maximum Value of Spin Value\r
- /// </summary>\r
- // MaxValue property of type int:\r
- [ScriptableProperty()]\r
- public int MaxValue\r
- {\r
- get\r
- {\r
- return _maxValue;\r
- }\r
- set\r
- {\r
- _maxValue = value;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Increasing, decresing step of Spin Value when Up or Down key is pressed\r
- /// </summary>\r
- // Step property of type int:\r
- [ScriptableProperty()]\r
- public int Step\r
- {\r
- get\r
- {\r
- return _singleStep;\r
- }\r
- set\r
- {\r
- _singleStep = value;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Wrapping enabled status\r
- /// </summary>\r
- // WrappingEnabled property of type bool:\r
- [ScriptableProperty()]\r
- public bool WrappingEnabled\r
- {\r
- get\r
- {\r
- return _wrappingEnabled;\r
- }\r
- set\r
- {\r
- _wrappingEnabled = value;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Text point size of Spin Value\r
- /// </summary>\r
- // TextPointSize property of type int:\r
- [ScriptableProperty()]\r
- public int TextPointSize\r
- {\r
- get\r
- {\r
- return _pointSize;\r
- }\r
- set\r
- {\r
- _pointSize = value;\r
- _textField.PointSize = _pointSize;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// The color of Spin Value\r
- /// </summary>\r
- // TextColor property of type Color:\r
- [ScriptableProperty()]\r
- public Color TextColor\r
- {\r
- get\r
- {\r
- return _textColor;\r
- }\r
- set\r
- {\r
- Console.WriteLine("TextColor set to " + value.R + "," + value.G + "," + value.B);\r
-\r
- _textColor = value;\r
- _textField.TextColor = _textColor;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Maximum text lengh of Spin Value\r
- /// </summary>\r
- // MaxTextLength property of type int:\r
- [ScriptableProperty()]\r
- public int MaxTextLength\r
- {\r
- get\r
- {\r
- return _maxTextLength;\r
- }\r
- set\r
- {\r
- _maxTextLength = value;\r
- _textField.MaxLength = _maxTextLength;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Reference of TextField of Spin\r
- /// </summary>\r
- public TextField SpinText\r
- {\r
- get\r
- {\r
- return _textField;\r
- }\r
- set\r
- {\r
- _textField = value;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Show indicator image, for example Up/Down Arrow image.\r
- /// </summary>\r
- // Indicator property of type string:\r
- public string IndicatorImage\r
- {\r
- get\r
- {\r
- return _arrowImage;\r
- }\r
- set\r
- {\r
- _arrowImage = value;\r
- _arrowVisual = VisualFactory.Get().CreateVisual(_arrowImage, new Uint16Pair(150, 150));\r
- RegisterVisual(_arrowVisualPropertyIndex, _arrowVisual);\r
- }\r
- }\r
- }\r
+
+using System;
+using System.Runtime.InteropServices;
+using Tizen.NUI;
+
+// A spin control (for continously changing values when users can easily predict a set of values)
+
+namespace Tizen.NUI
+{
+ ///<summary>
+ ///Spin CustomView class
+ /// </summary>
+ public class Spin : CustomView
+ {
+ private VisualBase _arrowVisual;
+ private TextField _textField;
+ private int _arrowVisualPropertyIndex;
+ private string _arrowImage;
+ private int _currentValue;
+ private int _minValue;
+ private int _maxValue;
+ private int _singleStep;
+ private bool _wrappingEnabled;
+ private string _fontFamily;
+ private string _fontStyle;
+ private int _pointSize;
+ private Color _textColor;
+ private Color _textBackgroundColor;
+ private int _maxTextLength;
+
+ // Called by DALi Builder if it finds a Spin control in a JSON file
+ static CustomView CreateInstance()
+ {
+ return new Spin();
+ }
+
+ // static constructor registers the control type (only runs once)
+ static Spin()
+ {
+ // ViewRegistry registers control type with DALi type registery
+ // also uses introspection to find any properties that need to be registered with type registry
+ ViewRegistry.Instance.Register(CreateInstance, typeof(Spin));
+ }
+
+ public Spin() : base(typeof(Spin).Name, CustomViewBehaviour.RequiresKeyboardNavigationSupport)
+ {
+
+ }
+
+ /// <summary>
+ /// Override method of OnInitialize() for CustomView class.
+ /// This method is called after the Control has been initialized.
+ /// Derived classes should do any second phase initialization by overriding this method.
+ /// </summary>
+ public override void OnInitialize()
+ {
+ // Initialize the propertiesControl
+ _arrowImage = "/home/owner/apps_rw/NUISamples.TizenTV/res/images/arrow.png";
+ _textBackgroundColor = new Color(0.6f, 0.6f, 0.6f, 1.0f);
+ _currentValue = 0;
+ _minValue = 0;
+ _maxValue = 0;
+ _singleStep = 1;
+ _maxTextLength = 0;
+
+ // Create image visual for the arrow keys
+ _arrowVisualPropertyIndex = RegisterProperty("ArrowImage", new PropertyValue(_arrowImage), Tizen.NUI.PropertyAccessMode.ReadWrite);
+ _arrowVisual = VisualFactory.Get().CreateVisual(_arrowImage, new Uint16Pair(150, 150));
+ RegisterVisual(_arrowVisualPropertyIndex, _arrowVisual);
+
+ // Create a text field
+ _textField = new TextField();
+ _textField.ParentOrigin = Tizen.NUI.ParentOrigin.Center;
+ _textField.AnchorPoint = Tizen.NUI.AnchorPoint.Center;
+ _textField.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;
+ _textField.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
+ _textField.SizeModeFactor = new Vector3(1.0f, 0.45f, 1.0f);
+ _textField.PlaceholderText = "----";
+ _textField.BackgroundColor = _textBackgroundColor;
+ _textField.HorizontalAlignment = "Center";
+ _textField.VerticalAlignment = "Center";
+ _textField.Focusable = (true);
+ _textField.Name = "_textField";
+
+ this.Add(_textField);
+
+ _textField.FocusGained += TextFieldKeyInputFocusGained;
+ _textField.FocusLost += TextFieldKeyInputFocusLost;
+ }
+
+ /// <summary>
+ /// Override method of GetNaturalSize() for CustomView class.
+ /// Return the natural size of the actor.
+ /// </summary>
+ /// <returns> Natural size of this Spin itself</returns>
+ public override Size GetNaturalSize()
+ {
+ return new Size(150.0f, 150.0f, 0.0f);
+ }
+
+ /// <summary>
+ /// Event handler when the TextField in Spin gets the Key focus
+ /// Make sure when the current spin that takes input focus also takes the keyboard focus
+ /// For example, when you tap the spin directly
+ /// </summary>
+ /// <param name="source">Sender of this event</param>
+ /// <param name="e">Event arguments</param>
+ public void TextFieldKeyInputFocusGained(object source, EventArgs e)
+ {
+ FocusManager.Instance.SetCurrentFocusView(_textField);
+ }
+
+ /// <summary>
+ /// Event handler when the TextField in Spin looses it's Key focus
+ /// </summary>
+ /// <param name="source"></param>
+ /// <param name="e"></param>
+ public void TextFieldKeyInputFocusLost(object source, EventArgs e)
+ {
+ int previousValue = _currentValue;
+
+ // If the input value is invalid, change it back to the previous valid value
+ if (int.TryParse(_textField.Text, out _currentValue))
+ {
+ if (_currentValue < _minValue || _currentValue > _maxValue)
+ {
+ _currentValue = previousValue;
+ }
+ }
+ else
+ {
+ _currentValue = previousValue;
+ }
+
+ // Otherwise take the new value
+ this.Value = _currentValue;
+ }
+
+ /// <summary>
+ /// Override method of GetNextKeyboardFocusableView() for CustomView class.
+ /// Gets the next key focusable view in this View towards the given direction.
+ /// A View needs to override this function in order to support two dimensional key navigation.
+ /// </summary>
+ /// <param name="currentFocusedView">The current focused view</param>
+ /// <param name="direction">The direction to move the focus towards</param>
+ /// <param name="loopEnabled">Whether the focus movement should be looped within the control</param>
+ /// <returns>The next keyboard focusable view in this control or an empty handle if no view can be focused</returns>
+ public override View GetNextKeyboardFocusableView(View currentFocusedView, View.FocusDirection direction, bool loopEnabled)
+ {
+ // Respond to Up/Down keys to change the value while keeping the current spin focused
+ View nextFocusedView = currentFocusedView;
+ if (direction == View.FocusDirection.Up)
+ {
+ this.Value += this.Step;
+ nextFocusedView = _textField;
+ }
+ else if (direction == View.FocusDirection.Down)
+ {
+ this.Value -= this.Step;
+ nextFocusedView = _textField;
+ }
+ else
+ {
+ // Return a native empty handle as nothing can be focused in the left or right
+ nextFocusedView = new View();
+ nextFocusedView.Reset();
+ }
+
+ return nextFocusedView;
+ }
+
+ /// <summary>
+ /// Value to be set in Spin
+ /// </summary>
+ [ScriptableProperty()]
+ public int Value
+ {
+ get
+ {
+ return _currentValue;
+ }
+ set
+ {
+
+ Console.WriteLine("Value set to " + value);
+ _currentValue = value;
+
+ // Make sure no invalid value is accepted
+ if (_currentValue < _minValue)
+ {
+ _currentValue = _minValue;
+ }
+
+ if (_currentValue > _maxValue)
+ {
+ _currentValue = _maxValue;
+ }
+
+ _textField.Text = _currentValue.ToString();
+ }
+ }
+
+ /// <summary>
+ /// Minimum Value of Spin Value
+ /// </summary>
+ // MinValue property of type int:
+ [ScriptableProperty()]
+ public int MinValue
+ {
+ get
+ {
+ return _minValue;
+ }
+ set
+ {
+ _minValue = value;
+ }
+ }
+
+ /// <summary>
+ /// Maximum Value of Spin Value
+ /// </summary>
+ // MaxValue property of type int:
+ [ScriptableProperty()]
+ public int MaxValue
+ {
+ get
+ {
+ return _maxValue;
+ }
+ set
+ {
+ _maxValue = value;
+ }
+ }
+
+ /// <summary>
+ /// Increasing, decresing step of Spin Value when Up or Down key is pressed
+ /// </summary>
+ // Step property of type int:
+ [ScriptableProperty()]
+ public int Step
+ {
+ get
+ {
+ return _singleStep;
+ }
+ set
+ {
+ _singleStep = value;
+ }
+ }
+
+ /// <summary>
+ /// Wrapping enabled status
+ /// </summary>
+ // WrappingEnabled property of type bool:
+ [ScriptableProperty()]
+ public bool WrappingEnabled
+ {
+ get
+ {
+ return _wrappingEnabled;
+ }
+ set
+ {
+ _wrappingEnabled = value;
+ }
+ }
+
+ /// <summary>
+ /// Text point size of Spin Value
+ /// </summary>
+ // TextPointSize property of type int:
+ [ScriptableProperty()]
+ public int TextPointSize
+ {
+ get
+ {
+ return _pointSize;
+ }
+ set
+ {
+ _pointSize = value;
+ _textField.PointSize = _pointSize;
+ }
+ }
+
+ /// <summary>
+ /// The color of Spin Value
+ /// </summary>
+ // TextColor property of type Color:
+ [ScriptableProperty()]
+ public Color TextColor
+ {
+ get
+ {
+ return _textColor;
+ }
+ set
+ {
+ Console.WriteLine("TextColor set to " + value.R + "," + value.G + "," + value.B);
+
+ _textColor = value;
+ _textField.TextColor = _textColor;
+ }
+ }
+
+ /// <summary>
+ /// Maximum text lengh of Spin Value
+ /// </summary>
+ // MaxTextLength property of type int:
+ [ScriptableProperty()]
+ public int MaxTextLength
+ {
+ get
+ {
+ return _maxTextLength;
+ }
+ set
+ {
+ _maxTextLength = value;
+ _textField.MaxLength = _maxTextLength;
+ }
+ }
+
+ /// <summary>
+ /// Reference of TextField of Spin
+ /// </summary>
+ public TextField SpinText
+ {
+ get
+ {
+ return _textField;
+ }
+ set
+ {
+ _textField = value;
+ }
+ }
+
+ /// <summary>
+ /// Show indicator image, for example Up/Down Arrow image.
+ /// </summary>
+ // Indicator property of type string:
+ public string IndicatorImage
+ {
+ get
+ {
+ return _arrowImage;
+ }
+ set
+ {
+ _arrowImage = value;
+ _arrowVisual = VisualFactory.Get().CreateVisual(_arrowImage, new Uint16Pair(150, 150));
+ RegisterVisual(_arrowVisualPropertyIndex, _arrowVisual);
+ }
+ }
+ }
}
\ No newline at end of file
-// Copyright (c) 2017 Samsung Electronics Co., Ltd.\r
-//\r
-// Licensed under the Apache License, Version 2.0 (the "License");\r
-// you may not use this file except in compliance with the License.\r
-// You may obtain a copy of the License at\r
-//\r
-// http://www.apache.org/licenses/LICENSE-2.0\r
-//\r
-// Unless required by applicable law or agreed to in writing, software\r
-// distributed under the License is distributed on an "AS IS" BASIS,\r
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-// See the License for the specific language governing permissions and\r
-// limitations under the License.\r
-//\r
-\r
-namespace Tizen.NUI\r
-{\r
- using System;\r
- using System.Runtime.InteropServices;\r
- using System.Collections.Generic;\r
- using System.Linq;\r
-\r
- /// <summary>\r
- /// A visual view control for user add any visual to it.\r
- /// Example:\r
- /// VisualView _visualView = new VisualView();\r
- /// ImageVisualMap imageVisualMap1 = new ImageVisualMap();\r
- /// imageVisualMap1.URL = "./NUISample/res/images/image-1.jpg";\r
- /// imageVisualMap1.VisualSize = new Vector2( 300.0f, 300.0f );\r
- /// imageVisualMap1.Offset = new Vector2( 50.0f, 50.0f );\r
- /// imageVisualMap1.OffsetSizeMode = new Vector4( 1.0f, 1.0f, 1.0f, 1.0f );\r
- /// imageVisualMap1.Origin = AlignType.TOP_BEGIN;\r
- /// imageVisualMap1.AnchorPoint = AlignType.TOP_BEGIN;\r
- /// _visualView.AddVisual("imageVisual1", imageVisualMap1);\r
- /// </summary>\r
- public class VisualView : CustomView\r
- {\r
- //private LinkedList<VisualBase> _visualList = null;\r
- private Dictionary<int, VisualBase> _visualDictionary = null;\r
- private Dictionary<int, PropertyMap> _tranformDictionary = null;\r
-\r
- static CustomView CreateInstance()\r
- {\r
- return new VisualView();\r
- }\r
-\r
- // static constructor registers the control type (for user can add kinds of visuals to it)\r
- static VisualView()\r
- {\r
- // ViewRegistry registers control type with DALi type registery\r
- // also uses introspection to find any properties that need to be registered with type registry\r
- ViewRegistry.Instance.Register(CreateInstance, typeof(VisualView));\r
- }\r
-\r
- public VisualView() : base(typeof(VisualView).Name, CustomViewBehaviour.ViewBehaviourDefault)\r
- {\r
- }\r
-\r
- /// <summary>\r
- /// Override the parent method.\r
- /// </summary>\r
- public override void OnInitialize()\r
- {\r
- //Initialize empty\r
- _visualDictionary = new Dictionary<int, VisualBase>();\r
- _tranformDictionary = new Dictionary<int, PropertyMap>();\r
- }\r
-\r
- /// <summary>\r
- /// Add or update a visual to visual view.\r
- /// </summary>\r
- /// <param name="visualName"> The name of visual to add. If add a existed visual name, the visual will be replaced. </param>\r
- /// <param name="visualMap"> The property map of visual to create. </param>\r
- public void AddVisual(string visualName, VisualMap visualMap)\r
- {\r
- VisualBase visual = null;\r
- int visualIndex = -1;\r
-\r
- /* If the visual had added, then replace it using RegisterVusal. */\r
- //visual.Name = name;\r
- foreach (var item in _visualDictionary)\r
- {\r
- if (item.Value.Name == visualName)\r
- {\r
- /* Find a existed visual, its key also exited. */\r
- visualIndex = item.Key;\r
- UnregisterVisual(visualIndex);\r
- _visualDictionary.Remove(visualIndex);\r
- _tranformDictionary.Remove(visualIndex);\r
- break;\r
- }\r
- }\r
-\r
- if (visualIndex == -1) // The visual is a new one, create index for it. */\r
- {\r
- visualIndex = RegisterProperty(visualName, new PropertyValue(visualName), PropertyAccessMode.ReadWrite);\r
- }\r
-\r
- if (visualIndex > 0)\r
- {\r
- visual = VisualFactory.Get().CreateVisual(visualMap.OutputVisualMap); // Create a visual for the new one.\r
- visual.Name = visualName;\r
- visual.DepthIndex = visualMap.DepthIndex;\r
-\r
- RegisterVisual(visualIndex, visual);\r
-\r
- _visualDictionary.Add(visualIndex, visual);\r
- _tranformDictionary.Add(visualIndex, visualMap.OutputTransformMap);\r
-\r
- RelayoutRequest();\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Remove a visual by name.\r
- /// </summary>\r
- /// <param name="visualName"> The name of visual to remove. </param>\r
- public void RemoveVisual(string visualName)\r
- {\r
- foreach (var item in _visualDictionary)\r
- {\r
- if (item.Value.Name == visualName)\r
- {\r
- EnableVisual(item.Key, false);\r
- UnregisterVisual(item.Key);\r
- _visualDictionary.Remove(item.Key);\r
- }\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// A visual view control for user add any visual to it.\r
- /// </summary>\r
- /// <returns> The number of visuals. </returns>\r
- public int NumberOfVisuals()\r
- {\r
- return _visualDictionary.Count;\r
- }\r
-\r
- /// <summary>\r
- /// Remove all visuals of visual view.\r
- /// </summary>\r
- public void RemoveAll()\r
- {\r
- _visualDictionary.Clear();\r
- }\r
-\r
- /// <summary>\r
- /// Override method of OnRelayout() for CustomView class.\r
- /// Called after the size negotiation has been finished for this control.\r
- /// The control is expected to assign this given size to itself/its children.\r
- /// Should be overridden by derived classes if they need to layout actors differently after certain operations like add or remove actors, resize or after changing specific properties.\r
- /// Note! As this function is called from inside the size negotiation algorithm, you cannot call RequestRelayout (the call would just be ignored)\r
- /// </summary>\r
- /// <param name="size">The allocated size</param>\r
- /// <param name="container">The control should add actors to this container that it is not able to allocate a size for.</param>\r
- public override void OnRelayout(Vector2 size, RelayoutContainer container)\r
- {\r
- foreach (var item in _visualDictionary)\r
- {\r
- item.Value.SetTransformAndSize(_tranformDictionary[item.Key], size);\r
- EnableVisual(item.Key, true);\r
- }\r
- }\r
- }\r
-\r
-}\r
+// Copyright (c) 2017 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+namespace Tizen.NUI
+{
+ using System;
+ using System.Runtime.InteropServices;
+ using System.Collections.Generic;
+ using System.Linq;
+
+ /// <summary>
+ /// A visual view control for user add any visual to it.
+ /// Example:
+ /// VisualView _visualView = new VisualView();
+ /// ImageVisualMap imageVisualMap1 = new ImageVisualMap();
+ /// imageVisualMap1.URL = "./NUISample/res/images/image-1.jpg";
+ /// imageVisualMap1.VisualSize = new Vector2( 300.0f, 300.0f );
+ /// imageVisualMap1.Offset = new Vector2( 50.0f, 50.0f );
+ /// imageVisualMap1.OffsetSizeMode = new Vector4( 1.0f, 1.0f, 1.0f, 1.0f );
+ /// imageVisualMap1.Origin = AlignType.TOP_BEGIN;
+ /// imageVisualMap1.AnchorPoint = AlignType.TOP_BEGIN;
+ /// _visualView.AddVisual("imageVisual1", imageVisualMap1);
+ /// </summary>
+ public class VisualView : CustomView
+ {
+ //private LinkedList<VisualBase> _visualList = null;
+ private Dictionary<int, VisualBase> _visualDictionary = null;
+ private Dictionary<int, PropertyMap> _tranformDictionary = null;
+
+ static CustomView CreateInstance()
+ {
+ return new VisualView();
+ }
+
+ // static constructor registers the control type (for user can add kinds of visuals to it)
+ static VisualView()
+ {
+ // ViewRegistry registers control type with DALi type registery
+ // also uses introspection to find any properties that need to be registered with type registry
+ ViewRegistry.Instance.Register(CreateInstance, typeof(VisualView));
+ }
+
+ public VisualView() : base(typeof(VisualView).Name, CustomViewBehaviour.ViewBehaviourDefault)
+ {
+ }
+
+ /// <summary>
+ /// Override the parent method.
+ /// </summary>
+ public override void OnInitialize()
+ {
+ //Initialize empty
+ _visualDictionary = new Dictionary<int, VisualBase>();
+ _tranformDictionary = new Dictionary<int, PropertyMap>();
+ }
+
+ /// <summary>
+ /// Add or update a visual to visual view.
+ /// </summary>
+ /// <param name="visualName"> The name of visual to add. If add a existed visual name, the visual will be replaced. </param>
+ /// <param name="visualMap"> The property map of visual to create. </param>
+ public void AddVisual(string visualName, VisualMap visualMap)
+ {
+ VisualBase visual = null;
+ int visualIndex = -1;
+
+ /* If the visual had added, then replace it using RegisterVusal. */
+ //visual.Name = name;
+ foreach (var item in _visualDictionary)
+ {
+ if (item.Value.Name == visualName)
+ {
+ /* Find a existed visual, its key also exited. */
+ visualIndex = item.Key;
+ UnregisterVisual(visualIndex);
+ _visualDictionary.Remove(visualIndex);
+ _tranformDictionary.Remove(visualIndex);
+ break;
+ }
+ }
+
+ if (visualIndex == -1) // The visual is a new one, create index for it. */
+ {
+ visualIndex = RegisterProperty(visualName, new PropertyValue(visualName), PropertyAccessMode.ReadWrite);
+ }
+
+ if (visualIndex > 0)
+ {
+ visual = VisualFactory.Get().CreateVisual(visualMap.OutputVisualMap); // Create a visual for the new one.
+ visual.Name = visualName;
+ visual.DepthIndex = visualMap.DepthIndex;
+
+ RegisterVisual(visualIndex, visual);
+
+ _visualDictionary.Add(visualIndex, visual);
+ _tranformDictionary.Add(visualIndex, visualMap.OutputTransformMap);
+
+ RelayoutRequest();
+ }
+ }
+
+ /// <summary>
+ /// Remove a visual by name.
+ /// </summary>
+ /// <param name="visualName"> The name of visual to remove. </param>
+ public void RemoveVisual(string visualName)
+ {
+ foreach (var item in _visualDictionary)
+ {
+ if (item.Value.Name == visualName)
+ {
+ EnableVisual(item.Key, false);
+ UnregisterVisual(item.Key);
+ _visualDictionary.Remove(item.Key);
+ }
+ }
+ }
+
+ /// <summary>
+ /// A visual view control for user add any visual to it.
+ /// </summary>
+ /// <returns> The number of visuals. </returns>
+ public int NumberOfVisuals()
+ {
+ return _visualDictionary.Count;
+ }
+
+ /// <summary>
+ /// Remove all visuals of visual view.
+ /// </summary>
+ public void RemoveAll()
+ {
+ _visualDictionary.Clear();
+ }
+
+ /// <summary>
+ /// Override method of OnRelayout() for CustomView class.
+ /// Called after the size negotiation has been finished for this control.
+ /// The control is expected to assign this given size to itself/its children.
+ /// Should be overridden by derived classes if they need to layout actors differently after certain operations like add or remove actors, resize or after changing specific properties.
+ /// Note! As this function is called from inside the size negotiation algorithm, you cannot call RequestRelayout (the call would just be ignored)
+ /// </summary>
+ /// <param name="size">The allocated size</param>
+ /// <param name="container">The control should add actors to this container that it is not able to allocate a size for.</param>
+ public override void OnRelayout(Vector2 size, RelayoutContainer container)
+ {
+ foreach (var item in _visualDictionary)
+ {
+ item.Value.SetTransformAndSize(_tranformDictionary[item.Key], size);
+ EnableVisual(item.Key, true);
+ }
+ }
+ }
+
+}