2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Runtime.InteropServices;
20 using System.Collections.Generic;
24 // A contentView control (for use can add image or text to it.)
28 public class ContentView : CustomView
30 private int _iconVisualIndex;
31 private string _iconVisualUrl;
32 private bool _activeContent = false;
33 private bool _transitionInProgress = false;
35 private VisualBase _iconVisual;
36 private Animation _animation;
37 private TransitionData _growTransitionData;
38 private TransitionData _shrinkTransitionData;
\r
41 // Called by DALi Builder if it finds a ContentView control in a JSON file
42 static CustomView CreateInstance()
44 return new ContentView();
47 // static constructor registers the control type (only runs once)
50 // ViewRegistry registers control type with DALi type registery
51 // also uses introspection to find any properties that need to be registered with type registry
52 ViewRegistry.Instance.Register(CreateInstance, typeof(ContentView));
55 public ContentView() : base(typeof(ContentView).Name, ViewBehaviour.ViewBehaviourDefault | ViewBehaviour.RequiresKeyboardNavigationSupport)
60 public override void OnInitialize()
62 _iconVisualIndex = RegisterProperty("iconVisual", new PropertyValue("./image/application-icon-0.png"), PropertyAccessMode.ReadWrite);
64 PropertyMap animator = new PropertyMap();
65 animator.Add("alphaFunction", new PropertyValue("LINEAR"));
67 PropertyMap timePeriod = new PropertyMap();
68 timePeriod.Add("duration", new PropertyValue(0.8f));
69 timePeriod.Add("delay", new PropertyValue(0.0f));
70 animator.Add("timePeriod", new PropertyValue(timePeriod));
72 PropertyMap growTransition = new PropertyMap();
73 growTransition.Add("target", new PropertyValue("iconVisual"));
74 growTransition.Add("property", new PropertyValue("size"));
75 growTransition.Add("targetValue", new PropertyValue(new Vector2(100.0f, 100.0f)));
76 growTransition.Add("animator", new PropertyValue(animator));
77 _growTransitionData = new TransitionData(growTransition);
80 PropertyMap shrinkTransition = new PropertyMap();
81 shrinkTransition.Add("target", new PropertyValue("iconVisual"));
82 shrinkTransition.Add("property", new PropertyValue("size"));
83 shrinkTransition.Add("targetValue", new PropertyValue(new Vector2(50.0f, 50.0f)));
84 shrinkTransition.Add("animator", new PropertyValue(animator));
85 _shrinkTransitionData = new TransitionData(shrinkTransition);
\r
88 /*public virtual void OnRelayout(Vector2 size, RelayoutContainer container)
90 Console.WriteLine ("--------------OnRelayout.");
91 RelayoutVisuals( size);
94 private void RelayoutVisuals(Vector2 size)
96 if (!_transitionInProgress)
100 PropertyMap iconVisualTransform = new PropertyMap();
101 iconVisualTransform.Add((int)VisualTransformPropertyType.SIZE, new PropertyValue(new Vector2(50.0f, 50.0f)));
102 iconVisualTransform.Add((int)VisualTransformPropertyType.OFFSET, new PropertyValue(new Vector2(5.0f, 5.0f)));
103 iconVisualTransform.Add((int)VisualTransformPropertyType.OFFSET_SIZE_MODE, new PropertyValue(new Vector4(1.0f, 1.0f, 1.0f, 1.0f)));
104 iconVisualTransform.Add((int)VisualTransformPropertyType.ORIGIN, new PropertyValue((int)AlignType.TOP_BEGIN));
105 iconVisualTransform.Add((int)VisualTransformPropertyType.ANCHOR_POINT, new PropertyValue((int)AlignType.TOP_BEGIN));
106 _iconVisual.SetTransformAndSize(iconVisualTransform, size);
111 [ScriptableProperty()]
112 public string IconVisual
116 return _iconVisualUrl;
120 _iconVisualUrl = value;
124 EnableVisual(_iconVisualIndex, false);
125 UnregisterVisual(_iconVisualIndex);
128 PropertyMap iconVisualMap = new PropertyMap(); ;
129 iconVisualMap.Add(Tizen.NUI.Constants.Visual.Property.Type, new PropertyValue((int)Tizen.NUI.Constants.Visual.Type.Image));
130 iconVisualMap.Add(Tizen.NUI.Constants.ImageVisualProperty.URL, new PropertyValue(_iconVisualUrl));
131 _iconVisual = VisualFactory.Get().CreateVisual(iconVisualMap);
132 _iconVisual.Name = ("iconVisual");
134 RelayoutVisuals(new Vector2(250.0f, 250.0f));
135 RegisterVisual(_iconVisualIndex, _iconVisual);
136 _iconVisual.DepthIndex = (1.0f);
143 [ScriptableProperty()]
144 public bool ActiveContent
148 return _activeContent;
152 _activeContent = value;
153 StartTransition(_activeContent);
157 private void StartTransition(bool activate)
162 _animation.Finished += OnTransitionFinished;
166 _animation = CreateTransition(_growTransitionData);
170 _animation = CreateTransition(_shrinkTransitionData);
175 _animation.Finished += OnTransitionFinished;
176 _transitionInProgress = true;
181 private void OnTransitionFinished(object sender, EventArgs e)
183 _transitionInProgress = false;
186 _animation.Finished += OnTransitionFinished;
191 public ImageVisualMap ImageVisual
\r
197 VisualBase _imageVisual;
\r
198 int _imageVisualIndex = RegisterProperty("ImageVisual", new PropertyValue(value.URL), PropertyAccessMode.ReadWrite);
\r
199 _imageVisual = VisualFactory.Get().CreateVisual(value.OutputMap);
\r
200 RegisterVisual(_imageVisualIndex, _imageVisual);
\r
201 _imageVisual.DepthIndex = value.DepthIndex;
206 public TextVisualMap TextVisual
\r
210 if (value.Text != "" && value.PointSize != 0)
212 Tizen.Log.Debug("NUI", "p2 !!!!!");
\r
214 PropertyMap _outputMap = new PropertyMap(); ;
\r
215 _outputMap.Add(Tizen.NUI.Constants.Visual.Property.Type, new PropertyValue((int)Tizen.NUI.Constants.Visual.Type.WireFrame + 1));
\r
216 _outputMap.Add(Tizen.NUI.Constants.TextVisualProperty.Text, new PropertyValue("ABCD"));
\r
217 _outputMap.Add(Tizen.NUI.Constants.TextVisualProperty.PointSize, new PropertyValue(10.0f));
\r
219 VisualBase _textVisual;
\r
220 int _textVisualIndex = RegisterProperty("TextVisual", new PropertyValue(_outputMap), PropertyAccessMode.ReadWrite);
\r
221 _textVisual = VisualFactory.Get().CreateVisual(_outputMap);
\r
222 RegisterVisual(_textVisualIndex, _textVisual, true);
\r
223 _textVisual.DepthIndex = value.DepthIndex;
224 Tizen.Log.Debug("NUI", "p2 !!!!! _textVisualIndex=" + _textVisualIndex + "is enabled?=" + IsVisualEnabled(_textVisualIndex));