X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=plugins%2Fdali-sharp%2Fexamples%2Fscroll-view.cs;h=9c199d2e360e3949de737d03984af353690b6dff;hp=a7d99b3722565809f4578c44b756cf7efa2fd210;hb=7cca1061ed3db08d2e7f511a8f6ef707e688703d;hpb=d375dceca213569317d81d17cd2d2a4b45122cda diff --git a/plugins/dali-sharp/examples/scroll-view.cs b/plugins/dali-sharp/examples/scroll-view.cs index a7d99b3..9c199d2 100755 --- a/plugins/dali-sharp/examples/scroll-view.cs +++ b/plugins/dali-sharp/examples/scroll-view.cs @@ -21,182 +21,176 @@ using Dali; namespace MyCSharpExample { - class Example - { - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - delegate void CallbackDelegate(IntPtr data); - - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - delegate void ActorCallbackDelegate(IntPtr data); - - private Dali.Application _application; - private ScrollView _scrollView; - private ScrollBar _scrollBar; - private Animation _animation; - private TextLabel _text; - - public Example(Dali.Application application) + class Example { - _application = application; - _application.Initialized += Initialize; - } + private Dali.Application _application; + private ScrollView _scrollView; + private ScrollBar _scrollBar; + private Animation _animation; + private TextLabel _text; + public Example(Dali.Application application) + { + _application = application; + _application.Initialized += Initialize; + } - public void Initialize(object source, NUIApplicationInitEventArgs e) - { - CreateScrollView(); - } + public void Initialize(object source, NUIApplicationInitEventArgs e) + { + CreateScrollView(); + } - private void CreateScrollView() - { - Stage stage = Stage.GetCurrent(); - stage.BackgroundColor = Color.White; - - // Create a scroll view - _scrollView = new ScrollView(); - Size2D stageSize = stage.Size; - _scrollView.Size = new Position(stageSize.Width, stageSize.Height, 0.0f); - _scrollView.ParentOrigin = NDalic.ParentOriginCenter; - _scrollView.AnchorPoint = NDalic.AnchorPointCenter; - stage.Add(_scrollView); - - // Add actors to a scroll view with 3 pages - int pageRows = 1; - int pageColumns = 3; - for(int pageRow = 0; pageRow < pageRows; pageRow++) - { - for(int pageColumn = 0; pageColumn < pageColumns; pageColumn++) + private void CreateScrollView() { - View pageActor = new View(); - pageActor.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.ALL_DIMENSIONS); - pageActor.ParentOrigin = NDalic.ParentOriginCenter; - pageActor.AnchorPoint = NDalic.AnchorPointCenter; - pageActor.Position = new Position(pageColumn * stageSize.Width, pageRow * stageSize.Height, 0.0f); - - // Add images in a 3x4 grid layout for each page - int imageRows = 4; - int imageColumns = 3; - float margin = 10.0f; - Position imageSize = new Position((stageSize.Width / imageColumns) - margin, (stageSize.Height/ imageRows) - margin, 0.0f); - - for(int row = 0; row < imageRows; row++) - { - for(int column = 0; column < imageColumns;column++) + Window window = Window.Instance; + window.BackgroundColor = Color.White; + + // Create a scroll view + _scrollView = new ScrollView(); + Size2D windowSize = window.Size; + _scrollView.Size = new Position(windowSize.Width, windowSize.Height, 0.0f); + _scrollView.ParentOrigin = NDalic.ParentOriginCenter; + _scrollView.PivotPoint = NDalic.AnchorPointCenter; + window.Add(_scrollView); + + // Add actors to a scroll view with 3 pages + int pageRows = 1; + int pageColumns = 3; + for (int pageRow = 0; pageRow < pageRows; pageRow++) { - int imageId = (row * imageColumns + column) % 2 + 1; - ImageView imageView = new ImageView("images/image-" + imageId + ".jpg"); - imageView.ParentOrigin = NDalic.ParentOriginCenter; - imageView.AnchorPoint = NDalic.AnchorPointCenter; - imageView.Size = imageSize; - imageView.Position = new Position( margin * 0.5f + (imageSize.X + margin) * column - stageSize.Width * 0.5f + imageSize.X * 0.5f, - margin * 0.5f + (imageSize.Y + margin) * row - stageSize.Height * 0.5f + imageSize.Y * 0.5f, 0.0f ); - pageActor.Add(imageView); + for (int pageColumn = 0; pageColumn < pageColumns; pageColumn++) + { + View pageActor = new View(); + pageActor.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.AllDimensions); + pageActor.ParentOrigin = NDalic.ParentOriginCenter; + pageActor.PivotPoint = NDalic.AnchorPointCenter; + pageActor.Position = new Position(pageColumn * windowSize.Width, pageRow * windowSize.Height, 0.0f); + + // Add images in a 3x4 grid layout for each page + int imageRows = 4; + int imageColumns = 3; + float margin = 10.0f; + Position imageSize = new Position((windowSize.Width / imageColumns) - margin, (windowSize.Height / imageRows) - margin, 0.0f); + + for (int row = 0; row < imageRows; row++) + { + for (int column = 0; column < imageColumns; column++) + { + int imageId = (row * imageColumns + column) % 2 + 1; + ImageView imageView = new ImageView("images/image-" + imageId + ".jpg"); + imageView.ParentOrigin = NDalic.ParentOriginCenter; + imageView.PivotPoint = NDalic.AnchorPointCenter; + imageView.Size = imageSize; + imageView.Position = new Position(margin * 0.5f + (imageSize.X + margin) * column - windowSize.Width * 0.5f + imageSize.X * 0.5f, + margin * 0.5f + (imageSize.Y + margin) * row - windowSize.Height * 0.5f + imageSize.Y * 0.5f, 0.0f); + pageActor.Add(imageView); + } + } + + _scrollView.Add(pageActor); + } } - } - _scrollView.Add(pageActor); + _scrollView.SetAxisAutoLock(true); + + // Set scroll view to have 3 pages in X axis and allow page snapping, + // and also disable scrolling in Y axis. + Property.Map rulerMap = new Property.Map(); + rulerMap.Add((int)Dali.Constants.ScrollModeType.XAxisScrollEnabled, new Property.Value(true)); + rulerMap.Add((int)Dali.Constants.ScrollModeType.XAxisSnapToInterval, new Property.Value(windowSize.Width)); + rulerMap.Add((int)Dali.Constants.ScrollModeType.XAxisScrollBoundary, new Property.Value(windowSize.Width * pageColumns ) ); + rulerMap.Add((int)Dali.Constants.ScrollModeType.YAxisScrollEnabled, new Property.Value( false ) ); + _scrollView.ScrollMode = rulerMap; + + // Create a horizontal scroll bar in the bottom of scroll view (which is optional) + _scrollBar = new ScrollBar(); + _scrollBar.ParentOrigin = NDalic.ParentOriginBottomLeft; + _scrollBar.PivotPoint = NDalic.AnchorPointTopLeft; + _scrollBar.SetResizePolicy(ResizePolicyType.FIT_TO_CHILDREN, DimensionType.Width); + _scrollBar.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.Height); + _scrollBar.Orientation = new Rotation(new Radian(new Degree(270.0f)), Vector3.ZAXIS); + _scrollBar.SetScrollDirection(ScrollBar.Direction.Horizontal); + _scrollView.Add(_scrollBar); + + // Connect to the OnRelayout signal + _scrollView.Relayout += OnScrollViewRelayout; + _scrollView.Touched += OnTouch; + _scrollView.WheelRolled += Onwheel; + _scrollView.FocusGained += OnKey; + _text = new TextLabel("View Touch Event Handler Test"); + _text.PivotPoint = NDalic.AnchorPointTopLeft; + _text.HorizontalAlignment = "CENTER"; + _text.PointSize = 48.0f; + + _scrollView.Add(_text); } - } - - _scrollView.SetAxisAutoLock(true); - - // Set scroll view to have 3 pages in X axis and allow page snapping, - // and also disable scrolling in Y axis. - RulerPtr scrollRulerX = new RulerPtr(new FixedRuler(stageSize.Width)); - RulerPtr scrollRulerY = new RulerPtr(new DefaultRuler()); - scrollRulerX.SetDomain(new RulerDomain(0.0f, stageSize.Width * pageColumns, true)); - scrollRulerY.Disable(); - _scrollView.SetRulerX(scrollRulerX); - _scrollView.SetRulerY(scrollRulerY); - - // Create a horizontal scroll bar in the bottom of scroll view (which is optional) - _scrollBar = new ScrollBar(); - _scrollBar.ParentOrigin = NDalic.ParentOriginBottomLeft; - _scrollBar.AnchorPoint = NDalic.AnchorPointTopLeft; - _scrollBar.SetResizePolicy(ResizePolicyType.FIT_TO_CHILDREN, DimensionType.WIDTH); - _scrollBar.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.HEIGHT); - _scrollBar.Orientation = new Rotation( new Radian( new Degree( 270.0f ) ), Vector3.ZAXIS ); - _scrollBar.SetScrollDirection(ScrollBar.Direction.Horizontal); - _scrollView.Add(_scrollBar); - - // Connect to the OnRelayout signal - _scrollView.OnRelayoutEvent += OnScrollViewRelayout; - _scrollView.Touched += OnTouch; - _scrollView.WheelMoved += Onwheel; - _scrollView.KeyInputFocusGained += OnKey; - _text = new TextLabel("View Touch Event Handler Test"); - _text.AnchorPoint = NDalic.AnchorPointTopLeft; - _text.HorizontalAlignment = "CENTER"; - _text.PointSize = 48.0f; - - _scrollView.Add(_text); - } - // Callback for _animation finished signal handling - public void AnimationFinished(object sender, EventArgs e) - { - Console.WriteLine("Customized Animation Finished Event handler"); - } - private void OnKey(object source, View.KeyInputFocusGainedEventArgs e) - { - Console.WriteLine("View Keyevent EVENT callback...."); - } + // Callback for _animation finished signal handling + public void AnimationFinished(object sender, EventArgs e) + { + Console.WriteLine("Customized Animation Finished Event handler"); + } - private bool Onwheel(object source, View.WheelEventArgs e) - { - Console.WriteLine("View Wheel EVENT callback...."); - return true; - } + private void OnKey(object source, View.KeyInputFocusGainedEventArgs e) + { + Console.WriteLine("View Keyevent EVENT callback...."); + } - private bool OnTouch(object source, View.TouchEventArgs e) - { - Console.WriteLine("View TOUCH EVENT callback...."); - - // Only animate the _text label when touch down happens - if( e.Touch.GetState(0) == PointStateType.DOWN ) - { - Console.WriteLine("Customized Stage Touch event handler"); - // Create a new _animation - if( _animation ) + private bool Onwheel(object source, View.WheelEventArgs e) { - _animation.Reset(); + Console.WriteLine("View Wheel EVENT callback...."); + return true; } - _animation = new Animation(1.0f); // 1 second of duration + private bool OnTouch(object source, View.TouchEventArgs e) + { + Console.WriteLine("View TOUCH EVENT callback...."); - _animation.AnimateTo(new Property(_text, Actor.Property.ORIENTATION), new Property.Value(new Rotation( new Radian( new Degree( 180.0f ) ), Vector3.XAXIS )), new AlphaFunction(AlphaFunction.BuiltinFunction.Linear), new TimePeriod(0.0f, 0.5f)); - _animation.AnimateTo(new Property(_text, Actor.Property.ORIENTATION), new Property.Value(new Rotation( new Radian( new Degree( 0.0f ) ), Vector3.XAXIS )), new AlphaFunction(AlphaFunction.BuiltinFunction.Linear), new TimePeriod(0.5f, 0.5f)); + // Only animate the _text label when touch down happens + if (e.Touch.GetState(0) == PointStateType.DOWN) + { + Console.WriteLine("Customized Window Touch event handler"); + // Create a new _animation + if (_animation) + { + _animation.Reset(); + } - // Connect the signal callback for animaiton finished signal - _animation.Finished += AnimationFinished; + _animation = new Animation(1.0f); // 1 second of duration - // Play the _animation - _animation.Play(); - } - return true; - } + _animation.AnimateTo(new Property(_text, View.Property.ORIENTATION), new Property.Value(new Rotation(new Radian(new Degree(180.0f)), Vector3.XAXIS)), new AlphaFunction(AlphaFunction.BuiltinFunction.Linear), new TimePeriod(0.0f, 0.5f)); + _animation.AnimateTo(new Property(_text, View.Property.ORIENTATION), new Property.Value(new Rotation(new Radian(new Degree(0.0f)), Vector3.XAXIS)), new AlphaFunction(AlphaFunction.BuiltinFunction.Linear), new TimePeriod(0.5f, 0.5f)); - private void OnScrollViewRelayout(object source, View.OnRelayoutEventArgs e) - { - Console.WriteLine("View OnRelayoutEventArgs EVENT callback...."); + // Connect the signal callback for animaiton finished signal + _animation.Finished += AnimationFinished; - // Set the correct scroll bar size after size negotiation of scroll view is done - _scrollBar.Size = new Position(0.0f, _scrollView.GetRelayoutSize(DimensionType.WIDTH), 0.0f); - } + // Play the _animation + _animation.Play(); + } + return true; + } - public void MainLoop() - { - _application.MainLoop (); - } + private void OnScrollViewRelayout(object source, View.OnRelayoutEventArgs e) + { + Console.WriteLine("View OnRelayoutEventArgs EVENT callback...."); + + // Set the correct scroll bar size after size negotiation of scroll view is done + _scrollBar.Size = new Position(0.0f, _scrollView.GetRelayoutSize(DimensionType.Width), 0.0f); + } + + public void MainLoop() + { + _application.MainLoop(); + } - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main(string[] args) - { - Example example = new Example(Application.NewApplication()); - example.MainLoop (); - } - } + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main(string[] args) + { + Example example = new Example(Application.NewApplication()); + example.MainLoop(); + } + } }