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;
23 namespace ImageViewExample
28 public static void Log(string str)
30 Console.WriteLine("[DALI C# SAMPLE] " + str);
33 private Dali.Application _application;
34 private Animation _animation;
35 private ImageView _imageView;
36 private bool _isAniFinised = true;
37 private Layer layer, _layer1, _layer2;
38 private PushButton _pushButton1, _pushButton2;
41 public Example(Dali.Application application)
43 _application = application;
44 _application.Initialized += Initialize;
47 public void Initialize(object source, NUIApplicationInitEventArgs e)
49 Log("Customized Application Initialize event handler");
50 stage = Stage.Instance;
51 stage.BackgroundColor = Color.Cyan;
52 stage.TouchEvent += OnStageTouched;
53 stage.WheelEvent += OnStageWheelMoved;
54 stage.KeyEvent += OnStageKeyPressed;
55 //stage.EventProcessingFinished += OnStageEventProcessingFinished;
57 layer = stage.GetDefaultLayer();
58 _layer1 = new Layer();
59 _layer2 = new Layer();
60 stage.AddLayer(_layer1);
61 stage.AddLayer(_layer2);
62 Log("_layer1.Behavior =" + _layer1.Behavior );
63 if( _layer1.Behavior == Layer.LayerBehavior.LAYER_UI )
65 _layer1.Behavior = Layer.LayerBehavior.LAYER_2D;
66 Log("again _layer1.Behavior =" + _layer1.Behavior );
68 // Add a ImageView to the stage
69 _imageView = new ImageView();
70 _imageView.ResourceUrl = "./images/gallery-3.jpg";
71 _imageView.ParentOrigin = ParentOrigin.Center;
72 _imageView.AnchorPoint = AnchorPoint.Center;
73 _imageView.PixelArea = new Vector4(0.0f, 0.0f, 0.5f, 0.5f);
74 //_imageView.SetResizePolicy(ResizePolicyType.USE_NATURAL_SIZE, DimensionType.ALL_DIMENSIONS);
75 layer.Add(_imageView);
77 _pushButton1 = new PushButton();
78 _pushButton1.ParentOrigin = ParentOrigin.BottomLeft;
79 _pushButton1.AnchorPoint = AnchorPoint.BottomLeft;
80 _pushButton1.LabelText = "start animation";
81 _pushButton1.Position = new Vector3(0.0f, stage.Size.Height * 0.1f, 0.0f);
82 _pushButton1.Clicked += OnPushButtonClicked1;
83 _layer1.Add(_pushButton1);
85 _pushButton2 = new PushButton();
86 _pushButton2.ParentOrigin = ParentOrigin.BottomLeft;
87 _pushButton2.AnchorPoint = AnchorPoint.BottomLeft;
88 _pushButton2.LabelText = "reload image with same URL";
89 _pushButton2.Position = new Vector3(0.0f, stage.Size.Height * 0.2f, 0.0f);
90 _pushButton2.Clicked += OnPushButtonClicked2;
91 _layer2.Add(_pushButton2);
95 public bool OnPushButtonClicked2(object sender, Button.ClickedEventArgs e)
99 Log("OnPushButtonClicked2()!");
100 layer.Remove(_imageView);
101 _imageView = new ImageView();
102 _imageView.ResourceUrl = "./images/gallery-3.jpg";
103 _imageView.ParentOrigin = ParentOrigin.Center;
104 _imageView.AnchorPoint = AnchorPoint.Center;
105 _imageView.PixelArea = new Vector4(0.0f, 0.0f, 0.5f, 0.5f);
106 //_imageView.SetResizePolicy(ResizePolicyType.USE_NATURAL_SIZE, DimensionType.ALL_DIMENSIONS);
107 layer.Add(_imageView);
114 public bool OnPushButtonClicked1(object sender, Button.ClickedEventArgs e)
116 if( _isAniFinised == true )
118 _isAniFinised = false;
119 Log("OnPushButtonClicked1()!");
121 // Create a new _animation
124 //_animation.Stop(Dali.Constants.Animation.EndAction.Stop);
128 _animation = new Animation();
129 _animation.StartTime = 0;
130 _animation.EndTime = 1000;
131 _animation.TargetProperty = "PixelArea";
132 _animation.Destination = new Vector4(0.5f, 0.0f, 0.5f, 0.5f);
133 _animation.AnimateTo(_imageView);
135 _animation.StartTime = 1000;
136 _animation.EndTime = 2000;
137 _animation.TargetProperty = "PixelArea";
138 _animation.Destination = new Vector4(0.5f, 0.5f, 0.5f, 0.5f);
139 _animation.AnimateTo(_imageView);
141 _animation.StartTime = 2000;
142 _animation.EndTime = 3000;
143 _animation.TargetProperty = "PixelArea";
144 _animation.Destination = new Vector4(0.0f, 0.0f, 1.0f, 1.0f);
145 _animation.AnimateTo(_imageView);
147 _animation.StartTime = 3000;
148 _animation.EndTime = 4000;
149 _animation.TargetProperty = "PixelArea";
150 _animation.Destination = new Vector4(0.5f, 0.5f, 0.5f, 0.5f);
151 _animation.AnimateTo(_imageView);
153 _animation.StartTime = 4000;
154 _animation.EndTime = 6000;
155 _animation.TargetProperty = "Size";
156 KeyFrames _keyFrames = new KeyFrames();
157 _keyFrames.Add(0.0f, new Size3D(0.0f, 0.0f, 0.0f) );
158 _keyFrames.Add(0.3f, new Size3D( (stage.Size * 0.7f) ) );
159 _keyFrames.Add(1.0f, new Size3D( stage.Size ) );
160 _animation.AnimateBetween(_imageView, _keyFrames, Animation.Interpolation.Linear);
162 _animation.EndAction = Animation.EndActions.Discard;
164 // Connect the signal callback for animaiton finished signal
165 _animation.Finished += AnimationFinished;
166 _animation.Finished += AnimationFinished2;
168 // Play the _animation
175 // Callback for _animation finished signal handling
176 public void AnimationFinished(object sender, EventArgs e)
178 Log("AnimationFinished()!");
181 // Callback for second _animation finished signal handling
182 public void AnimationFinished2(object sender, EventArgs e)
184 Log("AnimationFinished2()!");
187 Log("Duration= " + _animation.Duration);
188 Log("EndAction= " + _animation.EndAction);
189 _isAniFinised = true;
193 public void OnStageEventProcessingFinished(object sender, EventArgs e)
195 Log("OnStageEventProcessingFinished()!");
202 public void OnStageKeyPressed(object sender, Stage.KeyEventArgs e)
204 Log("OnStageKeyEventOccured()!");
205 Log("keyPressedName=" + e.KeyEvent.keyPressedName);
206 Log("state=" + e.KeyEvent.state);
209 public void OnStageWheelMoved(object sender, Stage.WheelEventArgs e)
211 Log("OnStageWheelEventOccured()!");
212 Log("direction=" + e.WheelEvent.direction);
213 Log("type=" + e.WheelEvent.type);
216 // Callback for stage touched signal handling
217 public void OnStageTouched(object sender, Stage.TouchEventArgs e)
219 Log("OnStageTouched()! e.TouchData.GetState(0)=" + e.TouchData.GetState(0) );
222 public void MainLoop()
224 _application.MainLoop ();
228 /// The main entry point for the application.
231 static void Main(string[] args)
233 Log("Main() called!");
235 Example example = new Example(Application.NewApplication());