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;
21 using Tizen.NUI.UIComponents;
22 using Tizen.NUI.BaseComponents;
23 using Tizen.NUI.Constants;
25 namespace ImageViewTest
27 class Example : NUIApplication
30 private const string resources = "/home/owner/apps_rw/NUISamples.TizenTV/res";
31 public static void Log(string str)
33 Tizen.Log.Debug("NUI", "[DALI C# SAMPLE] " + str);
36 private Animation _animation;
37 private ImageView _imageView;
38 private bool _isAniFinised = true;
39 private Layer layer, _layer1, _layer2;
40 private PushButton _pushButton1, _pushButton2;
41 private Window window;
43 public Example() : base()
47 public Example(string stylesheet) : base(stylesheet)
51 public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
55 protected override void OnCreate()
61 public void Initialize()
63 Log("Customized Application Initialize event handler");
64 window = Window.Instance;
65 window.BackgroundColor = Color.Cyan;
66 window.TouchEvent += OnWindowTouched;
67 window.WheelEvent += OnWindowWheelMoved;
68 window.KeyEvent += OnWindowKeyPressed;
69 //window.EventProcessingFinished += OnWindowEventProcessingFinished;
71 layer = window.GetDefaultLayer();
72 _layer1 = new Layer();
73 _layer2 = new Layer();
74 window.AddLayer(_layer1);
75 window.AddLayer(_layer2);
76 Log("_layer1.Behavior =" + _layer1.Behavior);
77 if (_layer1.Behavior == Layer.LayerBehavior.LayerUI)
79 _layer1.Behavior = Layer.LayerBehavior.Layer2D;
80 Log("again _layer1.Behavior =" + _layer1.Behavior);
82 // Add a ImageView to the window
83 // PropertyMap map = new PropertyMap();
84 // map.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
85 // map.Add(NpatchImageVisualProperty.URL, new PropertyValue(resources+"/images/00_popup_bg.9.png"));
86 // map.Add(NpatchImageVisualProperty.Border, new PropertyValue(new Rectangle(100, 100, 100, 100)));
87 _imageView = new ImageView();
88 //_imageView.ImageMap = map;
89 _imageView.ResourceUrl = resources+"/images/00_popup_bg.9.png";
90 //_imageView.Border = new Rectangle(100, 100, 100, 100);
91 _imageView.ParentOrigin = ParentOrigin.TopLeft;
92 _imageView.PivotPoint = PivotPoint.TopLeft;
93 _imageView.Position = new Position(5.0f, 5.0f, 0.0f);
94 _imageView.PixelArea = new Vector4(0.0f, 0.0f, 0.5f, 0.5f);
95 _imageView.Size2D = new Size2D(200, 80);
96 //_imageView.SetResizePolicy(ResizePolicyType.USE_NATURAL_SIZE, DimensionType.ALL_DIMENSIONS);
97 layer.Add(_imageView);
99 _pushButton1 = new PushButton();
100 _pushButton1.ParentOrigin = ParentOrigin.BottomLeft;
101 _pushButton1.PivotPoint = PivotPoint.BottomLeft;
102 _pushButton1.LabelText = "start animation";
103 _pushButton1.Position = new Vector3(0.0f, window.Size.Height * 0.1f, 0.0f);
104 _pushButton1.Clicked += OnPushButtonClicked1;
105 _layer1.Add(_pushButton1);
107 _pushButton2 = new PushButton();
108 _pushButton2.ParentOrigin = ParentOrigin.BottomLeft;
109 _pushButton2.PivotPoint = PivotPoint.BottomLeft;
110 _pushButton2.LabelText = "reload image with same URL";
111 _pushButton2.Position = new Vector3(0.0f, window.Size.Height * 0.2f, 0.0f);
112 _pushButton2.Clicked += OnPushButtonClicked2;
113 _layer2.Add(_pushButton2);
115 ImageView syncImage = new ImageView();
116 syncImage.ParentOrigin = ParentOrigin.CenterLeft;
117 syncImage.PivotPoint = PivotPoint.CenterLeft;
118 syncImage.PositionUsesPivotPoint = true;
119 syncImage.Size2D = new Size2D(150, 150);
120 syncImage.ResourceUrl = resources+"/images/gallery-3.jpg";
121 syncImage.SynchronosLoading = true;
122 layer.Add(syncImage);
124 PropertyMap _map = new PropertyMap();
125 _map.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
126 _map.Add(NpatchImageVisualProperty.URL, new PropertyValue(resources+"/images/00_popup_bg.9.png"));
127 _map.Add(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue(true));
128 ImageView nPatchImage = new ImageView();
129 nPatchImage.ParentOrigin = ParentOrigin.BottomLeft;
130 nPatchImage.PivotPoint = PivotPoint.BottomLeft;
131 nPatchImage.PositionUsesPivotPoint = true;
132 nPatchImage.Size2D = new Size2D(300, 100);
133 nPatchImage.ImageMap = _map;
134 layer.Add(nPatchImage);
136 ImageView syncNineImage = new ImageView();
137 syncNineImage.ParentOrigin = ParentOrigin.CenterLeft;
138 syncNineImage.PivotPoint = PivotPoint.CenterLeft;
139 syncNineImage.Position2D = new Position2D(0, 200);
140 syncNineImage.PositionUsesPivotPoint = true;
141 syncNineImage.Size2D = new Size2D(150, 150);
142 syncNineImage.ResourceUrl = resources+"/images/00_popup_bg.9.png";
143 syncNineImage.SynchronosLoading = true;
144 syncNineImage.Border = new Rectangle(0, 0, 0, 0);
145 layer.Add(syncNineImage);
148 public bool OnPushButtonClicked2(object sender, EventArgs e)
152 Log("OnPushButtonClicked2()!");
153 layer.Remove(_imageView);
154 _imageView = new ImageView();
155 _imageView.ResourceUrl = resources+"/images/gallery-3.jpg";
156 _imageView.ParentOrigin = ParentOrigin.Center;
157 _imageView.PivotPoint = PivotPoint.Center;
158 _imageView.PixelArea = new Vector4(0.0f, 0.0f, 0.5f, 0.5f);
159 //_imageView.SetResizePolicy(ResizePolicyType.USE_NATURAL_SIZE, DimensionType.ALL_DIMENSIONS);
160 layer.Add(_imageView);
166 public bool OnPushButtonClicked1(object sender, EventArgs e)
168 if (_isAniFinised == true)
170 _isAniFinised = false;
171 Log("OnPushButtonClicked1()!");
173 // Create a new _animation
176 //_animation.Stop(Tizen.NUI.Constants.Animation.EndAction.Stop);
180 _animation = new Animation();
181 _animation.AnimateTo(_imageView, "PixelArea", new Vector4(0.5f, 0.0f, 0.5f, 0.5f), 0, 1000);
182 _animation.AnimateTo(_imageView, "PixelArea", new Vector4(0.5f, 0.5f, 0.5f, 0.5f), 1000, 2000);
183 _animation.AnimateTo(_imageView, "PixelArea", new Vector4(0.0f, 0.0f, 1.0f, 1.0f), 2000, 3000);
184 _animation.AnimateTo(_imageView, "PixelArea", new Vector4(0.5f, 0.5f, 0.5f, 0.5f), 3000, 4000);
186 KeyFrames _keyFrames = new KeyFrames();
187 _keyFrames.Add(0.0f, new Size(0.0f, 0.0f, 0.0f));
188 _keyFrames.Add(0.3f, new Size(window.Size.Width * 0.7f, window.Size.Height * 0.7f, 0.0f));
189 _keyFrames.Add(1.0f, new Size(window.Size));
190 _animation.AnimateBetween(_imageView, "Size", _keyFrames, 4000, 6000, Animation.Interpolation.Linear);
192 _animation.EndAction = Animation.EndActions.Discard;
194 // Connect the signal callback for animaiton finished signal
195 _animation.Finished += AnimationFinished;
196 _animation.Finished += AnimationFinished2;
198 // Play the _animation
205 // Callback for _animation finished signal handling
206 public void AnimationFinished(object sender, EventArgs e)
208 Log("AnimationFinished()!");
211 // Callback for second _animation finished signal handling
212 public void AnimationFinished2(object sender, EventArgs e)
214 Log("AnimationFinished2()!");
217 Log("Duration= " + _animation.Duration);
218 Log("EndAction= " + _animation.EndAction);
219 _isAniFinised = true;
223 public void OnWindowEventProcessingFinished(object sender, EventArgs e)
225 Log("OnWindowEventProcessingFinished()!");
232 public void OnWindowKeyPressed(object sender, Window.KeyEventArgs e)
234 Log("OnWindowKeyEventOccured()!");
235 Log("keyPressedName=" + e.Key.KeyPressedName);
236 Log("state=" + e.Key.State);
239 public void OnWindowWheelMoved(object sender, Window.WheelEventArgs e)
241 Log("OnWindowWheelEventOccured()!");
242 Log("direction=" + e.Wheel.Direction);
243 Log("type=" + e.Wheel.Type);
246 // Callback for window touched signal handling
247 public void OnWindowTouched(object sender, Window.TouchEventArgs e)
249 Log("OnWindowTouched()! e.TouchData.GetState(0)=" + e.Touch.GetState(0));
253 /// The main entry point for the application.
256 static void _Main(string[] args)
258 Log("Main() called!");
260 Example example = new Example();