2 * Copyright (c) 2016 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.Constants;
24 namespace ImageViewTest
26 class Example : NUIApplication
29 private const string resources = "/home/owner/apps_rw/NUISamples.TizenTV/res";
30 public static void Log(string str)
32 Tizen.Log.Debug("NUI", "[DALI C# SAMPLE] " + str);
35 private Animation _animation;
36 private ImageView _imageView;
37 private bool _isAniFinised = true;
38 private Layer layer, _layer1, _layer2;
39 private PushButton _pushButton1, _pushButton2;
42 public Example() : base()
46 public Example(string stylesheet) : base(stylesheet)
50 public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
54 protected override void OnCreate()
60 public void Initialize()
62 Log("Customized Application Initialize event handler");
63 stage = Stage.Instance;
64 stage.BackgroundColor = Color.Cyan;
65 stage.Touch += OnStageTouched;
66 stage.Wheel += OnStageWheelMoved;
67 stage.Key += OnStageKeyPressed;
68 //stage.EventProcessingFinished += OnStageEventProcessingFinished;
70 layer = stage.GetDefaultLayer();
71 _layer1 = new Layer();
72 _layer2 = new Layer();
73 stage.AddLayer(_layer1);
74 stage.AddLayer(_layer2);
75 Log("_layer1.Behavior =" + _layer1.Behavior);
76 if (_layer1.Behavior == Layer.LayerBehavior.LayerUI)
78 _layer1.Behavior = Layer.LayerBehavior.Layer2D;
79 Log("again _layer1.Behavior =" + _layer1.Behavior);
81 // Add a ImageView to the stage
82 _imageView = new ImageView();
83 _imageView.ResourceUrl = resources+"/images/gallery-3.jpg";
84 _imageView.ParentOrigin = ParentOrigin.Center;
85 _imageView.AnchorPoint = AnchorPoint.Center;
86 _imageView.PixelArea = new Vector4(0.0f, 0.0f, 0.5f, 0.5f);
87 //_imageView.SetResizePolicy(ResizePolicyType.USE_NATURAL_SIZE, DimensionType.ALL_DIMENSIONS);
88 layer.Add(_imageView);
90 _pushButton1 = new PushButton();
91 _pushButton1.ParentOrigin = ParentOrigin.BottomLeft;
92 _pushButton1.AnchorPoint = AnchorPoint.BottomLeft;
93 _pushButton1.LabelText = "start animation";
94 _pushButton1.Position = new Vector3(0.0f, stage.Size.Height * 0.1f, 0.0f);
95 _pushButton1.Clicked += OnPushButtonClicked1;
96 _layer1.Add(_pushButton1);
98 _pushButton2 = new PushButton();
99 _pushButton2.ParentOrigin = ParentOrigin.BottomLeft;
100 _pushButton2.AnchorPoint = AnchorPoint.BottomLeft;
101 _pushButton2.LabelText = "reload image with same URL";
102 _pushButton2.Position = new Vector3(0.0f, stage.Size.Height * 0.2f, 0.0f);
103 _pushButton2.Clicked += OnPushButtonClicked2;
104 _layer2.Add(_pushButton2);
108 public bool OnPushButtonClicked2(object sender, EventArgs e)
112 Log("OnPushButtonClicked2()!");
113 layer.Remove(_imageView);
114 _imageView = new ImageView();
115 _imageView.ResourceUrl = resources+"/images/gallery-3.jpg";
116 _imageView.ParentOrigin = ParentOrigin.Center;
117 _imageView.AnchorPoint = AnchorPoint.Center;
118 _imageView.PixelArea = new Vector4(0.0f, 0.0f, 0.5f, 0.5f);
119 //_imageView.SetResizePolicy(ResizePolicyType.USE_NATURAL_SIZE, DimensionType.ALL_DIMENSIONS);
120 layer.Add(_imageView);
126 public bool OnPushButtonClicked1(object sender, EventArgs e)
128 if (_isAniFinised == true)
130 _isAniFinised = false;
131 Log("OnPushButtonClicked1()!");
133 // Create a new _animation
136 //_animation.Stop(Tizen.NUI.Constants.Animation.EndAction.Stop);
140 _animation = new Animation();
141 _animation.AnimateTo(_imageView, "PixelArea", new Vector4(0.5f, 0.0f, 0.5f, 0.5f), 0, 1000);
142 _animation.AnimateTo(_imageView, "PixelArea", new Vector4(0.5f, 0.5f, 0.5f, 0.5f), 1000, 2000);
143 _animation.AnimateTo(_imageView, "PixelArea", new Vector4(0.0f, 0.0f, 1.0f, 1.0f), 2000, 3000);
144 _animation.AnimateTo(_imageView, "PixelArea", new Vector4(0.5f, 0.5f, 0.5f, 0.5f), 3000, 4000);
146 KeyFrames _keyFrames = new KeyFrames();
147 _keyFrames.Add(0.0f, new Size(0.0f, 0.0f, 0.0f));
148 _keyFrames.Add(0.3f, new Size(stage.Size.Width * 0.7f, stage.Size.Height * 0.7f, 0.0f));
149 _keyFrames.Add(1.0f, new Size(stage.Size));
150 _animation.AnimateBetween(_imageView, "Size", _keyFrames, 4000, 6000, Animation.Interpolation.Linear);
152 _animation.EndAction = Animation.EndActions.Discard;
154 // Connect the signal callback for animaiton finished signal
155 _animation.Finished += AnimationFinished;
156 _animation.Finished += AnimationFinished2;
158 // Play the _animation
165 // Callback for _animation finished signal handling
166 public void AnimationFinished(object sender, EventArgs e)
168 Log("AnimationFinished()!");
171 // Callback for second _animation finished signal handling
172 public void AnimationFinished2(object sender, EventArgs e)
174 Log("AnimationFinished2()!");
177 Log("Duration= " + _animation.Duration);
178 Log("EndAction= " + _animation.EndAction);
179 _isAniFinised = true;
183 public void OnStageEventProcessingFinished(object sender, EventArgs e)
185 Log("OnStageEventProcessingFinished()!");
192 public void OnStageKeyPressed(object sender, Stage.KeyEventArgs e)
194 Log("OnStageKeyEventOccured()!");
195 Log("keyPressedName=" + e.Key.KeyPressedName);
196 Log("state=" + e.Key.State);
199 public void OnStageWheelMoved(object sender, Stage.WheelEventArgs e)
201 Log("OnStageWheelEventOccured()!");
202 Log("direction=" + e.Wheel.Direction);
203 Log("type=" + e.Wheel.Type);
206 // Callback for stage touched signal handling
207 public void OnStageTouched(object sender, Stage.TouchEventArgs e)
209 Log("OnStageTouched()! e.TouchData.GetState(0)=" + e.Touch.GetState(0));
213 /// The main entry point for the application.
216 static void _Main(string[] args)
218 Log("Main() called!");
220 Example example = new Example();