public void Add()
        {
            #region ...

            SPDisplayObject child1 = new SPQuad(32.0f, 32.0f);
            SPDisplayObject child2 = new SPQuad(32.0f, 32.0f);
            SPDisplayObject child3 = new SPQuad(32.0f, 32.0f);
            SPDisplayObject child4 = new SPQuad(32.0f, 32.0f);

            Assert.True(child1 != child2);
            Assert.True(child2 != child3);

            SPDisplayObjectContainer container = new SPStage();
            container.Add(child1);

            Assert.True(container.Count == 1);

            Assert.True(container.IndexOf(child1) == 0);
            Assert.True(container.IndexOf(child2) == -1);

            Assert.True(container[0] == child1);
            Assert.False(container[0] == child2);

            Assert.True(container.Contains(child1));
            Assert.False(container.Contains(child2));

            container.Add(child3);
            container.Add(child2);

            Assert.True(container.Count == 3);

            Assert.True(container.IndexOf(child1) == 0);
            Assert.True(container.IndexOf(child2) == 2);
            Assert.True(container.IndexOf(child3) == 1);

            Assert.True(container[0] == child1);
            Assert.True(container[1] == child3);
            Assert.True(container[2] == child2);

            Assert.True(container.Contains(child1));
            Assert.True(container.Contains(child2));
            Assert.True(container.Contains(child3));

            container[1] = child4;

            Assert.True(container.Contains(child1));
            Assert.True(container.Contains(child2));
            Assert.False(container.Contains(child3));
            Assert.True(container.Contains(child4));

            Assert.True(container.Count == 3);

            #endregion
        }
        public void BoundsInSpace()
        {
            #region ...

            SPStage stage = new SPStage();
            SPDisplayObject obj = new SPQuad();

            stage.Add(obj);

            SPRectangle b = obj.BoundsInSpace(stage);

            Assert.NotNull(b);

            #endregion
        }
        public void BroadcastEvent()
        {
            #region ...

            bool myEventReceived = false;
            SPStage stage = new SPStage();
            SPDisplayObject obj1 = new SPQuad();

            stage.Add(obj1);

            obj1.AddEventListener("myEvent", (SPEventHandler)delegate(SPEventDispatcher source, SPEventArgs e) {
                myEventReceived = true;
            });

            stage.BroadcastEvent(new SPEvent("myEvent"));

            Assert.True(myEventReceived);

            #endregion
        }
Ejemplo n.º 4
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            Console.WriteLine("finished loading");

            RectangleF frame = UIScreen.MainScreen.Bounds;

            // create a new window instance based on the screen size
            window = new UIWindow(frame);

            //SPAudioEngine.StartWithCategory(Sparrow.SPAudioSessionCategory.AmbientSound);
            SPStage.SupportHighResolutions = true; // use @2x textures on suitable hardware
            SPStage.DoubleResolutionsOnPad = true; // use @2x on iPad 1+2, @4x on iPad 3

            // create sparrow view
            sparrowView = new SPView(frame);
            sparrowView.MultipleTouchEnabled = true;
            sparrowView.FrameRate = 30;

            // create a root view controller
            rootViewController = new UIViewController();
            rootViewController.View = sparrowView;

            // set root view controller
            window.RootViewController = rootViewController;

            // create a stage
            SPStage stage = new SPStage(frame.Size.Width, frame.Size.Height);
            stage.Color = 0x2000a0;
            sparrowView.Stage = stage;

            // create and add our hello world text field to the stage
            SPTextField text = new SPTextField(frame.Size.Width, 50.0f, "Hello World!", "Helvetica", 30.0f, SPColor.White);
            text.Y = (frame.Size.Height - 50.0f) / 2.0f; // vertical center
            stage.Add(text);

            // make the window visible
            window.MakeKeyAndVisible();

            return true;
        }
        public void Enumerator()
        {
            #region ...

            SPDisplayObjectContainer container = new SPStage();

            SPDisplayObject obj1 = new SPQuad(32.0f, 32.0f);
            SPDisplayObject obj2 = new SPQuad(32.0f, 32.0f);
            SPDisplayObject obj3 = new SPQuad(32.0f, 32.0f);
            SPDisplayObject obj4 = new SPQuad(32.0f, 32.0f);

            obj1.Name = "Apple";
            obj2.Name = "Pear";
            obj3.Name = "Banana";
            obj4.Name = "Peach";

            container.Add(obj1);
            container.Add(obj2);
            container.Add(obj3);
            container.Add(obj4);

            int counter = 0;
            string names = null;

            foreach (SPDisplayObject obj in container)
            {
                counter++;
                names = names == null ? obj.Name : names + "," + obj.Name;
            }

            Assert.True(counter == 4);
            Assert.True(names == "Apple,Pear,Banana,Peach");

            #endregion
        }
        public void Swap()
        {
            #region ...

            SPDisplayObjectContainer container = new SPStage();

            SPDisplayObject obj1 = new SPQuad(32.0f, 32.0f);
            SPDisplayObject obj2 = new SPQuad(32.0f, 32.0f);
            SPDisplayObject obj3 = new SPQuad(32.0f, 32.0f);
            SPDisplayObject obj4 = new SPQuad(32.0f, 32.0f);

            container.Add(obj1);
            container.Add(obj2);
            container.Add(obj3);
            container.Add(obj4);

            container.Swap(obj1, obj4);
            container.Swap(2, 1);

            Assert.True(container.IndexOf(obj1) == 3);
            Assert.True(container.IndexOf(obj2) == 2);
            Assert.True(container.IndexOf(obj3) == 1);
            Assert.True(container.IndexOf(obj4) == 0);

            #endregion
        }
        public void Sort()
        {
            #region ...

            SPDisplayObjectContainer container = new SPStage();

            SPDisplayObject obj1 = new SPQuad(32.0f, 32.0f);
            SPDisplayObject obj2 = new SPQuad(32.0f, 32.0f);
            SPDisplayObject obj3 = new SPQuad(32.0f, 32.0f);
            SPDisplayObject obj4 = new SPQuad(32.0f, 32.0f);

            obj1.Name = "Apple";
            obj2.Name = "Pear";
            obj3.Name = "Banana";
            obj4.Name = "Peach";

            container.Add(obj1);
            container.Add(obj2);
            container.Add(obj3);
            container.Add(obj4);

            Console.WriteLine("BEFORE");
            Console.WriteLine("{0}: {1}", 0, container[0].Name);
            Console.WriteLine("{0}: {1}", 1, container[1].Name);
            Console.WriteLine("{0}: {1}", 2, container[2].Name);
            Console.WriteLine("{0}: {1}", 3, container[3].Name);

            container.Sort(delegate(SPDisplayObject o1, SPDisplayObject o2) {
                return o1.Name.CompareTo(o2.Name);
            });

            Console.WriteLine("AFTER:");
            Console.WriteLine("{0}: {1}", 0, container[0].Name);
            Console.WriteLine("{0}: {1}", 1, container[1].Name);
            Console.WriteLine("{0}: {1}", 2, container[2].Name);
            Console.WriteLine("{0}: {1}", 3, container[3].Name);

            Assert.True(container[0] == obj1);
            Assert.True(container[1] == obj3);
            Assert.True(container[2] == obj4);
            Assert.True(container[3] == obj2);

            #endregion
        }
        public void MoveAndRemove()
        {
            #region ...

            SPDisplayObjectContainer container = new SPStage();

            SPDisplayObject obj1 = new SPQuad(32.0f, 32.0f);
            SPDisplayObject obj2 = new SPQuad(32.0f, 32.0f);
            SPDisplayObject obj3 = new SPQuad(32.0f, 32.0f);
            SPDisplayObject obj4 = new SPQuad(32.0f, 32.0f);

            container.Add(obj1);
            container.Add(obj2);
            container.Add(obj3);
            container.Add(obj4);

            Assert.True(container.Count == 4);
            Assert.True(container.IndexOf(obj4) == 3);

            container.Move(1, obj4);

            Assert.True(container.Count == 4);
            Assert.True(container.IndexOf(obj4) == 1);
            Assert.True(container.IndexOf(obj2) == 2);

            Assert.True(container.Remove(obj3));
            Assert.False(container.Remove(obj3));

            Assert.True(container.Count == 3);
            Assert.False(container.Contains(obj3));

            container.RemoveAt(1);

            Assert.True(container.Count == 2);
            Assert.False(container.Contains(obj4));

            container.Clear();

            Assert.True(container.Count == 0);

            #endregion
        }
        public void Insert()
        {
            #region ...

            SPDisplayObject child1 = new SPQuad(32.0f, 32.0f);
            SPDisplayObject child2 = new SPQuad(32.0f, 32.0f);
            SPDisplayObject child3 = new SPQuad(32.0f, 32.0f);

            SPDisplayObjectContainer container = new SPStage();
            container.Add(child1);
            container.Add(child3);
            container.Insert(1, child2);

            Assert.True(container.Count == 3);

            Assert.True(container.IndexOf(child1) == 0);
            Assert.True(container.IndexOf(child2) == 1);
            Assert.True(container.IndexOf(child3) == 2);

            #endregion
        }
        public void Stage()
        {
            #region ...

            SPStage root = new SPStage();
            SPStage parent = new SPStage();
            SPDisplayObject obj = new SPQuad(32.0f, 32.0f);

            parent.Add(obj);
            root.Add(parent);

            Assert.True(obj.Stage == root);

            #endregion
        }
        public void TransformationMatrixToSpace()
        {
            #region ...

            SPStage stage = new SPStage();
            SPDisplayObject obj = new SPQuad();

            stage.Add(obj);
            SPMatrix m = obj.TransformationMatrixToSpace(stage);

            Assert.NotNull(m);

            #endregion
        }
        public void RemoveFromParent()
        {
            #region ...

            SPStage parent = new SPStage();
            SPDisplayObject child = new SPQuad();

            parent.Add(child);

            Assert.NotNull(child.Parent);

            child.RemoveFromParent();

            Assert.Null(child.Parent);

            #endregion
        }
        public void Parent()
        {
            #region ...

            SPStage parent = new SPStage();
            SPDisplayObject obj = new SPQuad(32.0f, 32.0f);

            Assert.Null(obj.Parent);

            parent.Add(obj);

            Assert.True(obj.Parent == parent);

            #endregion
        }
        public void Name()
        {
            #region ...

            SPStage parent = new SPStage();
            SPDisplayObject obj = new SPQuad(32.0f, 32.0f);

            Assert.Null(obj.Name);
            obj.Name = "TestObject";

            Assert.True(obj.Name == "TestObject");

            parent.Add(obj);

            Assert.True(parent["TestObject"] == obj);

            #endregion
        }
        public void LocalToGlobal()
        {
            #region ...

            SPStage stage = new SPStage();
            SPDisplayObject obj = new SPQuad();
            SPPoint p1 = new SPPoint(5.0f, 5.0f);

            stage.Add(obj);

            SPPoint p2 = obj.LocalToGlobal(p1);

            Assert.NotNull(p2);

            #endregion
        }
        public void HitTestPoint()
        {
            #region ...

            SPStage stage = new SPStage();
            SPDisplayObject obj1 = new SPQuad();
            SPPoint p1 = new SPPoint(5.0f, 5.0f);

            stage.Add(obj1);

            SPDisplayObject obj2 = stage.HitTest(p1, true);

            Assert.NotNull(obj2);

            #endregion
        }