1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
18 using System.Runtime.InteropServices;
22 namespace ImageViewExample
27 public static void Log(string str)
29 Console.WriteLine("[DALI C# SAMPLE] " + str);
32 private Dali.Application _application;
33 private Animation _animation;
34 private ImageView _imageView;
35 private bool _isAniFinised = true;
36 private Layer layer, _layer1, _layer2;
37 private PushButton _pushButton1, _pushButton2;
40 public Example(Dali.Application application)
42 _application = application;
43 _application.Initialized += Initialize;
46 public void Initialize(object source, NUIApplicationInitEventArgs e)
48 Log("Customized Application Initialize event handler");
49 stage = Stage.Instance;
50 stage.BackgroundColor = Color.Cyan;
51 stage.Touch += OnStageTouched;
52 stage.Wheel += OnStageWheelMoved;
53 stage.Key += OnStageKeyPressed;
54 //stage.EventProcessingFinished += OnStageEventProcessingFinished;
56 layer = stage.GetDefaultLayer();
57 _layer1 = new Layer();
58 _layer2 = new Layer();
59 stage.AddLayer(_layer1);
60 stage.AddLayer(_layer2);
61 Log("_layer1.Behavior =" + _layer1.Behavior);
62 if (_layer1.Behavior == Layer.LayerBehavior.LAYER_UI)
64 _layer1.Behavior = Layer.LayerBehavior.LAYER_2D;
65 Log("again _layer1.Behavior =" + _layer1.Behavior);
67 // Add a ImageView to the stage
68 _imageView = new ImageView();
69 _imageView.ResourceUrl = "./images/gallery-3.jpg";
70 _imageView.ParentOrigin = ParentOrigin.Center;
71 _imageView.AnchorPoint = AnchorPoint.Center;
72 _imageView.PixelArea = new Vector4(0.0f, 0.0f, 0.5f, 0.5f);
73 //_imageView.SetResizePolicy(ResizePolicyType.USE_NATURAL_SIZE, DimensionType.ALL_DIMENSIONS);
74 layer.Add(_imageView);
76 _pushButton1 = new PushButton();
77 _pushButton1.ParentOrigin = ParentOrigin.BottomLeft;
78 _pushButton1.AnchorPoint = AnchorPoint.BottomLeft;
79 _pushButton1.LabelText = "start animation";
80 _pushButton1.Position = new Vector3(0.0f, stage.Size.Height * 0.1f, 0.0f);
81 _pushButton1.Clicked += OnPushButtonClicked1;
82 _layer1.Add(_pushButton1);
84 _pushButton2 = new PushButton();
85 _pushButton2.ParentOrigin = ParentOrigin.BottomLeft;
86 _pushButton2.AnchorPoint = AnchorPoint.BottomLeft;
87 _pushButton2.LabelText = "reload image with same URL";
88 _pushButton2.Position = new Vector3(0.0f, stage.Size.Height * 0.2f, 0.0f);
89 _pushButton2.Clicked += OnPushButtonClicked2;
90 _layer2.Add(_pushButton2);
94 public bool OnPushButtonClicked2(object sender, Button.ClickedEventArgs e)
98 Log("OnPushButtonClicked2()!");
99 layer.Remove(_imageView);
100 _imageView = new ImageView();
101 _imageView.ResourceUrl = "./images/gallery-3.jpg";
102 _imageView.ParentOrigin = ParentOrigin.Center;
103 _imageView.AnchorPoint = AnchorPoint.Center;
104 _imageView.PixelArea = new Vector4(0.0f, 0.0f, 0.5f, 0.5f);
105 //_imageView.SetResizePolicy(ResizePolicyType.USE_NATURAL_SIZE, DimensionType.ALL_DIMENSIONS);
106 layer.Add(_imageView);
113 public bool OnPushButtonClicked1(object sender, Button.ClickedEventArgs e)
115 if (_isAniFinised == true)
117 _isAniFinised = false;
118 Log("OnPushButtonClicked1()!");
120 // Create a new _animation
123 //_animation.Stop(Dali.Constants.Animation.EndAction.Stop);
127 _animation = new Animation();
128 _animation.StartTime = 0;
129 _animation.EndTime = 1000;
130 _animation.TargetProperty = "PixelArea";
131 _animation.Destination = new Vector4(0.5f, 0.0f, 0.5f, 0.5f);
132 _animation.AnimateTo(_imageView);
134 _animation.StartTime = 1000;
135 _animation.EndTime = 2000;
136 _animation.TargetProperty = "PixelArea";
137 _animation.Destination = new Vector4(0.5f, 0.5f, 0.5f, 0.5f);
138 _animation.AnimateTo(_imageView);
140 _animation.StartTime = 2000;
141 _animation.EndTime = 3000;
142 _animation.TargetProperty = "PixelArea";
143 _animation.Destination = new Vector4(0.0f, 0.0f, 1.0f, 1.0f);
144 _animation.AnimateTo(_imageView);
146 _animation.StartTime = 3000;
147 _animation.EndTime = 4000;
148 _animation.TargetProperty = "PixelArea";
149 _animation.Destination = new Vector4(0.5f, 0.5f, 0.5f, 0.5f);
150 _animation.AnimateTo(_imageView);
152 _animation.StartTime = 4000;
153 _animation.EndTime = 6000;
154 _animation.TargetProperty = "Size";
155 KeyFrames _keyFrames = new KeyFrames();
156 _keyFrames.Add(0.0f, new Size3D(0.0f, 0.0f, 0.0f));
157 _keyFrames.Add(0.3f, new Size3D((stage.Size * 0.7f)));
158 _keyFrames.Add(1.0f, new Size3D(stage.Size));
159 _animation.AnimateBetween(_imageView, _keyFrames, Animation.Interpolation.Linear);
161 _animation.EndAction = Animation.EndActions.Discard;
163 // Connect the signal callback for animaiton finished signal
164 _animation.Finished += AnimationFinished;
165 _animation.Finished += AnimationFinished2;
167 // Play the _animation
174 // Callback for _animation finished signal handling
175 public void AnimationFinished(object sender, EventArgs e)
177 Log("AnimationFinished()!");
180 // Callback for second _animation finished signal handling
181 public void AnimationFinished2(object sender, EventArgs e)
183 Log("AnimationFinished2()!");
186 Log("Duration= " + _animation.Duration);
187 Log("EndAction= " + _animation.EndAction);
188 _isAniFinised = true;
192 public void OnStageEventProcessingFinished(object sender, EventArgs e)
194 Log("OnStageEventProcessingFinished()!");
201 public void OnStageKeyPressed(object sender, Stage.KeyEventArgs e)
203 Log("OnStageKeyEventOccured()!");
204 Log("keyPressedName=" + e.Key.KeyPressedName);
205 Log("state=" + e.Key.State);
208 public void OnStageWheelMoved(object sender, Stage.WheelEventArgs e)
210 Log("OnStageWheelEventOccured()!");
211 Log("direction=" + e.Wheel.Direction);
212 Log("type=" + e.Wheel.Type);
215 // Callback for stage touched signal handling
216 public void OnStageTouched(object sender, Stage.TouchEventArgs e)
218 Log("OnStageTouched()! e.TouchData.GetState(0)=" + e.Touch.GetState(0));
221 public void MainLoop()
223 _application.MainLoop();
227 /// The main entry point for the application.
230 static void Main(string[] args)
232 Log("Main() called!");
234 Example example = new Example(Application.NewApplication());