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.Constants;
23 namespace ImageViewTest
25 class Example : NUIApplication
27 public static void Log(string str)
29 Console.WriteLine("[DALI C# SAMPLE] " + str);
32 private Animation _animation;
33 private ImageView _imageView;
34 private bool _isAniFinised = true;
35 private Layer layer, _layer1, _layer2;
36 private PushButton _pushButton1, _pushButton2;
39 public Example() : base()
43 public Example(string stylesheet) : base(stylesheet)
47 public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
51 protected override void OnCreate()
57 public void Initialize()
59 Log("Customized Application Initialize event handler");
60 stage = Stage.Instance;
61 stage.BackgroundColor = Color.Cyan;
62 stage.Touch += OnStageTouched;
63 stage.Wheel += OnStageWheelMoved;
64 stage.Key += OnStageKeyPressed;
65 //stage.EventProcessingFinished += OnStageEventProcessingFinished;
67 layer = stage.GetDefaultLayer();
68 _layer1 = new Layer();
69 _layer2 = new Layer();
70 stage.AddLayer(_layer1);
71 stage.AddLayer(_layer2);
72 Log("_layer1.Behavior =" + _layer1.Behavior);
73 if (_layer1.Behavior == Layer.LayerBehavior.LayerUI)
75 _layer1.Behavior = Layer.LayerBehavior.Layer2D;
76 Log("again _layer1.Behavior =" + _layer1.Behavior);
78 // Add a ImageView to the stage
79 _imageView = new ImageView();
80 _imageView.ResourceUrl = "./images/gallery-3.jpg";
81 _imageView.ParentOrigin = ParentOrigin.Center;
82 _imageView.AnchorPoint = AnchorPoint.Center;
83 _imageView.PixelArea = new Vector4(0.0f, 0.0f, 0.5f, 0.5f);
84 //_imageView.SetResizePolicy(ResizePolicyType.USE_NATURAL_SIZE, DimensionType.ALL_DIMENSIONS);
85 layer.Add(_imageView);
87 _pushButton1 = new PushButton();
88 _pushButton1.ParentOrigin = ParentOrigin.BottomLeft;
89 _pushButton1.AnchorPoint = AnchorPoint.BottomLeft;
90 _pushButton1.LabelText = "start animation";
91 _pushButton1.Position = new Vector3(0.0f, stage.Size.Height * 0.1f, 0.0f);
92 _pushButton1.Clicked += OnPushButtonClicked1;
93 _layer1.Add(_pushButton1);
95 _pushButton2 = new PushButton();
96 _pushButton2.ParentOrigin = ParentOrigin.BottomLeft;
97 _pushButton2.AnchorPoint = AnchorPoint.BottomLeft;
98 _pushButton2.LabelText = "reload image with same URL";
99 _pushButton2.Position = new Vector3(0.0f, stage.Size.Height * 0.2f, 0.0f);
100 _pushButton2.Clicked += OnPushButtonClicked2;
101 _layer2.Add(_pushButton2);
105 public bool OnPushButtonClicked2(object sender, EventArgs e)
109 Log("OnPushButtonClicked2()!");
110 layer.Remove(_imageView);
111 _imageView = new ImageView();
112 _imageView.ResourceUrl = "./images/gallery-3.jpg";
113 _imageView.ParentOrigin = ParentOrigin.Center;
114 _imageView.AnchorPoint = AnchorPoint.Center;
115 _imageView.PixelArea = new Vector4(0.0f, 0.0f, 0.5f, 0.5f);
116 //_imageView.SetResizePolicy(ResizePolicyType.USE_NATURAL_SIZE, DimensionType.ALL_DIMENSIONS);
117 layer.Add(_imageView);
123 public bool OnPushButtonClicked1(object sender, EventArgs e)
125 if (_isAniFinised == true)
127 _isAniFinised = false;
128 Log("OnPushButtonClicked1()!");
130 // Create a new _animation
133 //_animation.Stop(Tizen.NUI.Constants.Animation.EndAction.Stop);
137 _animation = new Animation();
138 _animation.AnimateTo(_imageView, "PixelArea", new Vector4(0.5f, 0.0f, 0.5f, 0.5f), 0, 1000);
139 _animation.AnimateTo(_imageView, "PixelArea", new Vector4(0.5f, 0.5f, 0.5f, 0.5f), 1000, 2000);
140 _animation.AnimateTo(_imageView, "PixelArea", new Vector4(0.0f, 0.0f, 1.0f, 1.0f), 2000, 3000);
141 _animation.AnimateTo(_imageView, "PixelArea", new Vector4(0.5f, 0.5f, 0.5f, 0.5f), 3000, 4000);
143 KeyFrames _keyFrames = new KeyFrames();
144 _keyFrames.Add(0.0f, new Size(0.0f, 0.0f, 0.0f));
145 _keyFrames.Add(0.3f, new Size(stage.Size.Width * 0.7f, stage.Size.Height * 0.7f, 0.0f));
146 _keyFrames.Add(1.0f, new Size(stage.Size));
147 _animation.AnimateBetween(_imageView, "Size", _keyFrames, 4000, 6000, Animation.Interpolation.Linear);
149 _animation.EndAction = Animation.EndActions.Discard;
151 // Connect the signal callback for animaiton finished signal
152 _animation.Finished += AnimationFinished;
153 _animation.Finished += AnimationFinished2;
155 // Play the _animation
162 // Callback for _animation finished signal handling
163 public void AnimationFinished(object sender, EventArgs e)
165 Log("AnimationFinished()!");
168 // Callback for second _animation finished signal handling
169 public void AnimationFinished2(object sender, EventArgs e)
171 Log("AnimationFinished2()!");
174 Log("Duration= " + _animation.Duration);
175 Log("EndAction= " + _animation.EndAction);
176 _isAniFinised = true;
180 public void OnStageEventProcessingFinished(object sender, EventArgs e)
182 Log("OnStageEventProcessingFinished()!");
189 public void OnStageKeyPressed(object sender, Stage.KeyEventArgs e)
191 Log("OnStageKeyEventOccured()!");
192 Log("keyPressedName=" + e.Key.KeyPressedName);
193 Log("state=" + e.Key.State);
196 public void OnStageWheelMoved(object sender, Stage.WheelEventArgs e)
198 Log("OnStageWheelEventOccured()!");
199 Log("direction=" + e.Wheel.Direction);
200 Log("type=" + e.Wheel.Type);
203 // Callback for stage touched signal handling
204 public void OnStageTouched(object sender, Stage.TouchEventArgs e)
206 Log("OnStageTouched()! e.TouchData.GetState(0)=" + e.Touch.GetState(0));
210 /// The main entry point for the application.
213 static void _Main(string[] args)
215 Log("Main() called!");
217 Example example = new Example();