Example #1
0
        public static void Main(string[] args)
        {
            Actor scroll, info;
            Stage stage;

            Application.Init();

            stage               = new Stage();
            stage.Title         = "Pan Action";
            stage.UserResizable = true;

            scroll = CreateScrollActor(stage);
            stage.AddChild(scroll);

            info = new Text(null, "Press <space> to reset the image position.");
            stage.AddChild(info);
            info.SetPosition(12, 12);

            stage.Destroyed  += (sender, e) => Application.MainQuit();
            stage.KeyPressed += OnKeyPress;

            stage.Show();

            Clutter.Application.Main();
        }
Example #2
0
        static void Main(String[] args)
        {
            if (Application.Init() != InitError.Success)
            {
                return;
            }

            var stage = new Stage();

            stage.Name            = "stage";
            stage.Title           = "Snap Constraint";
            stage.BackgroundColor = Clutter.Color.New(0xee, 0xee, 0xee, 0xff);
            stage.UserResizable   = true;
            stage.Destroyed      += (sender, e) => Application.MainQuit();

            var layerA = new Actor();

            layerA.BackgroundColor = Clutter.Color.New(0xcc, 0x00, 0x00, 0xff);
            layerA.Name            = "layerA";
            layerA.SetSize(100f, 25f);
            stage.AddChild(layerA);

            layerA.AddConstraint(new AlignConstraint(stage, AlignAxis.Both, 0.5f));

            var layerB = new Actor();

            layerB.BackgroundColor = Clutter.Color.New(0xc4, 0xa0, 0x00, 0xff);
            layerB.Name            = "layerB";
            stage.AddChild(layerB);

            layerB.AddConstraint(new BindConstraint(layerA, BindCoordinate.X, 0f));
            layerB.AddConstraint(new BindConstraint(layerA, BindCoordinate.Width, 0f));

            layerB.AddConstraint(new SnapConstraint(layerA, SnapEdge.Top, SnapEdge.Bottom, 10f));
            layerB.AddConstraint(new SnapConstraint(stage, SnapEdge.Bottom, SnapEdge.Bottom, -10f));

            var layerC = new Actor();

            layerC.BackgroundColor = Clutter.Color.New(0x8a, 0xe2, 0x34, 0xff);
            layerC.Name            = "layerC";
            stage.AddChild(layerC);

            layerC.AddConstraint(new BindConstraint(layerA, BindCoordinate.X, 0f));
            layerC.AddConstraint(new BindConstraint(layerA, BindCoordinate.Width, 0f));

            layerC.AddConstraint(new SnapConstraint(layerA, SnapEdge.Bottom, SnapEdge.Top, -10f));
            layerC.AddConstraint(new SnapConstraint(stage, SnapEdge.Top, SnapEdge.Top, 10f));

            stage.Show();

            Application.Main();
        }
Example #3
0
        private static void Main()
        {
            game   = new Stage(new RenderWindow(new VideoMode(800, 600, 32), "TomajEngine"));
            bitmap = new Bitmap("resources\\devices.png", new IntRect(0, 0, 96, 96));
            game.AddChild(bitmap);
            var textField = new TextField(new Text("Tomaj Engine", new Font("resources\\sansation.ttf"), 20));

            game.AddChild(textField);
            bitmap.Position = new Vector2f(100, 100);
            Tweener.To(textField, TimeSpan.FromSeconds(2), new TweenedPropertyVector2f("Position", new Vector2f(200, 200), new Vector2f(400, 400)));
            Tweener.To(textField, TimeSpan.FromSeconds(2), new TweenedPropertyFloat("Rotation", 0, 90));
            tweener_Complete(null);
            game.Run();
        }
Example #4
0
        public static void Start(uint width, uint height, Type rootType)
        {
            GPUInfo.PrintGPUInfo();
#if DEBUG
            OpenGLDebugCallback.Init();
#endif
            if (rootType == null)
            {
                throw new InvalidOperationException("Root cannot be null!");
            }

            if (Root != null)
            {
                throw new InvalidOperationException("App already initialized!");
            }
            RenderSupport.HasOpenGLError = false;

            Stage          = new Stage(width, height);
            DefaultJuggler = new Juggler();
            Context        = new Context();
            renderSupport  = new RenderSupport();

            Root = (DisplayObject)Activator.CreateInstance(rootType);
            Stage.AddChild(Root);
        }
Example #5
0
        public void TestRootAndStage()
        {
            Sprite object1 = new Sprite();
            Sprite object2 = new Sprite();
            Sprite object3 = new Sprite();

            object1.AddChild(object2);
            object2.AddChild(object3);

            Assert.AreEqual(null, object1.Root);
            Assert.AreEqual(null, object2.Root);
            Assert.AreEqual(null, object3.Root);
            Assert.AreEqual(null, object1.Stage);
            Assert.AreEqual(null, object2.Stage);
            Assert.AreEqual(null, object3.Stage);

            Stage stage = CreateInstance <Stage>(100, 100);

            stage.AddChild(object1);

            Assert.AreEqual(object1, object1.Root);
            Assert.AreEqual(object1, object2.Root);
            Assert.AreEqual(object1, object3.Root);
            Assert.AreEqual(stage, object1.Stage);
            Assert.AreEqual(stage, object2.Stage);
            Assert.AreEqual(stage, object3.Stage);
        }
Example #6
0
        public static void Main(string[] args)
        {
            Application.Init();

            Stage stage;
            Actor vase;

            Actor[] flowers = new Actor[3];


            stage = new Stage();

            stage.Destroyed += (sender, evnt) => Application.MainQuit();


            stage.Title         = "Three Flowers in a Vase";
            stage.UserResizable = true;

            vase = new Actor();
            vase.LayoutManager   = new BoxLayout();
            vase.BackgroundColor = Color.New(150, 150, 255, 255);
            vase.AddConstraint(new AlignConstraint(stage, AlignAxis.Both, 0.5f));
            stage.AddChild(vase);

            flowers[0]      = new Actor();
            flowers[0].Name = "flower.1";
            flowers[0].SetSize(128, 128);
            flowers[0].MarginLeft      = 12;
            flowers[0].BackgroundColor = Color.New(255, 0, 0, 255);
            flowers[0].Reactive        = true;
            vase.AddChild(flowers[0]);
            flowers[0].ButtonPressed += animateColor;

            flowers[1]      = new Actor();
            flowers[1].Name = "flower.2";
            flowers[1].SetSize(128, 128);
            flowers[1].MarginTop       = 12;
            flowers[1].MarginRight     = 6;
            flowers[1].MarginLeft      = 6;
            flowers[1].MarginBottom    = 12;
            flowers[1].BackgroundColor = Color.New(255, 255, 0, 255);
            flowers[1].Reactive        = true;
            vase.AddChild(flowers[1]);
            flowers[1].Entered    += onCrossing;
            flowers[1].LeaveEvent += onCrossing;

            flowers[2]      = new Actor();
            flowers[2].Name = "flower.3";
            flowers[2].SetSize(128, 128);
            flowers[2].MarginRight     = 12;
            flowers[2].BackgroundColor = Color.New(0, 255, 0, 255);
            flowers[2].Reactive        = true;
            vase.AddChild(flowers[2]);
            flowers[2].ButtonPressed += animateRotation;

            stage.Show();
            Application.Main();
        }
Example #7
0
        static void Main(String[] args)
        {
            if (Application.Init() != InitError.Success)
            {
                return;
            }

            var stage  = new Stage();
            var image  = (Image)Image.New();
            var action = new TapAction();
            var text   = new Text();
            var pixbuf = new Pixbuf("redhand.png");

            stage.Name          = "Stage";
            stage.Title         = "Content Box";
            stage.UserResizable = true;
            stage.Destroyed    += (sender, e) => Application.MainQuit();
            stage.MarginTop     = 12;
            stage.MarginBottom  = 12;
            stage.MarginLeft    = 12;
            stage.MarginRight   = 12;
            stage.Show();

            image.SetData(pixbuf.Pixels,
                          pixbuf.HasAlpha ? Cogl.PixelFormat.Rgba8888 : Cogl.PixelFormat.Rgb888,
                          (uint)pixbuf.Width, (uint)pixbuf.Height, (uint)pixbuf.Rowstride);

            stage.SetContentScalingFilters(ScalingFilter.Trilinear, ScalingFilter.Linear);
            stage.ContentGravity = gravities.Last <ContentGravity>();
            stage.Content        = image;

            text.TextProp = "Content gravity: " + gravities.Last <ContentGravity>();
            text.AddConstraint(new AlignConstraint(stage, AlignAxis.Both, 0.5f));
            stage.AddChild(text);

            action.Tapped += (object o, TappedArgs arg) => {
                var actor = arg.Actor;

                actor.SaveEasingState();
                actor.ContentGravity = gravities [currentGravity];
                actor.RestoreEasingState();

                text.TextProp = "Content gravity: " + gravities [currentGravity];

                currentGravity++;
                if (currentGravity >= gravities.Count)
                {
                    currentGravity = 0;
                }
            };
            stage.AddAction(action);

            Application.Main();
        }
        private void AddStageNode()
        {
            TreeNode newSt     = new Stage(parent.ActivatedWorkSpaceData);
            TreeNode newTask   = new TaskNode(parent.ActivatedWorkSpaceData);
            TreeNode newFolder = new Folder(parent.ActivatedWorkSpaceData, "Initialize");

            newFolder.AddChild(new StageBG(parent.ActivatedWorkSpaceData));
            newTask.AddChild(newFolder);
            newTask.AddChild(new TaskWait(parent.ActivatedWorkSpaceData, "240"));
            newSt.AddChild(newTask);
            parent.Insert(newSt);
        }
        protected override void LoadContent()
        {
            stage             = new Stage();
            stage.StageWidth  = graphics.GraphicsDevice.Viewport.Width;
            stage.StageHeight = graphics.GraphicsDevice.Viewport.Height;
            stage.stage       = stage;

            stage.AddChild(rootSprite);

            #if __MOBILE__ || DEBUG
            debugFont = Content.Load <SpriteFont>("assets/MainFont");
            #endif

            spriteBatch = new SpriteBatch(GraphicsDevice);
        }
Example #10
0
        private void AddStageNode()
        {
            TreeNode newSt     = new Stage(parent.ActivatedWorkSpaceData);
            TreeNode newTask   = new TaskNode(parent.ActivatedWorkSpaceData);
            TreeNode newFolder = new Folder(parent.ActivatedWorkSpaceData, "Initialize");

            newFolder.AddChild(new Code(parent.ActivatedWorkSpaceData,
                                        "LoadMusic(\'spellcard\',\'THlib\\\\music\\\\spellcard.ogg\',75,0xc36e80/44100/4)"));
            newFolder.AddChild(new StageBG(parent.ActivatedWorkSpaceData, "bamboo_background"));
            newTask.AddChild(newFolder);
            newTask.AddChild(new TaskWait(parent.ActivatedWorkSpaceData, "60"));
            newTask.AddChild(new PlayBGM(parent.ActivatedWorkSpaceData, "\"spellcard\"", "", "false"));
            newTask.AddChild(new TaskWait(parent.ActivatedWorkSpaceData, "180"));
            newSt.AddChild(newTask);
            parent.Insert(newSt);
        }
Example #11
0
        static void Main(String[] args)
        {
            if (Clutter.Application.Init() != InitError.Success)
            {
                return;
            }

            Gst.Application.Init();

            var stage = new Stage();

            stage.Destroyed += (sender, e) => Clutter.Application.MainQuit();

            var timeline = new Timeline(1000);

            timeline.Loop = true;

            var texture = new Texture();

            texture.SizeChanged += OnSizeChanged;

            var pipeline = new Pipeline();

            var src        = ElementFactory.Make("videotestsrc");
            var warp       = ElementFactory.Make("warptv");
            var colorspace = ElementFactory.Make("videoconvert");
            var sink       = ElementFactory.Make("cluttersink");

            sink ["texture"] = texture;

            pipeline.Add(src);
            pipeline.Add(warp);
            pipeline.Add(colorspace);
            pipeline.Add(sink);
            Element.Link(src, warp, colorspace, sink);
            pipeline.SetState(Gst.State.Playing);

            timeline.Start();
            stage.AddChild(texture);
            stage.Show();

            Clutter.Application.Main();
        }
Example #12
0
        static void Main(String[] args)
        {
            Actor      actor;
            Stage      stage;
            Canvas     canvas;
            Transition transition;

            if (Application.Init() != InitError.Success)
            {
                return;
            }

            stage                 = new Stage();
            stage.Title           = "Rectangle with rounded corners";
            stage.BackgroundColor = Clutter.Color.New(255, 255, 255, 255);
            stage.SetSize(500, 500);
            stage.Show();

            canvas = (Canvas)Canvas.New();
            canvas.SetSize(300, 300);

            actor                = new Actor();
            actor.Content        = canvas;
            actor.ContentGravity = ContentGravity.Center;
            actor.SetContentScalingFilters(ScalingFilter.Trilinear, ScalingFilter.Linear);
            actor.SetPivotPoint(0.5f, 0.5f);
            actor.AddConstraint(new BindConstraint(stage, BindCoordinate.Size, 0f));
            stage.AddChild(actor);

            transition                         = new PropertyTransition("rotation-angle-y");
            transition.FromValue               = new GLib.Value(0.0);
            transition.ToValue                 = new GLib.Value(360.0);
            ((Timeline)transition).Duration    = 2000;
            ((Timeline)transition).RepeatCount = -1;
            actor.AddTransition("rotateActor", transition);

            stage.Destroyed += (sender, e) => Application.MainQuit();
            canvas.Drawn    += DrawContent;

            canvas.Invalidate();
            Application.Main();
        }
Example #13
0
        public Sandbox()
        {
            Stage = new Stage(0x00FFFF);

            Renderer = Pixi.AutoDetectRenderer(1024, 768);

            Global.document.body.appendChild(Renderer.View);

            var texture = Texture.FromImage("assets/spacesloth.png");

            Sloth = new Sprite(texture);

            Sloth.Anchor.X   = Sloth.Anchor.Y = 0.5f;
            Sloth.Position.X = 512;
            Sloth.Position.Y = 384;

            Stage.AddChild(Sloth);

            Js.de.requestAnimationFrame(new Action(Render));
        }
Example #14
0
        public static void Main(string[] args)
        {
            Actor  actor;
            Stage  stage;
            Canvas canvas;

            Application.Init();

            stage                 = new Stage();
            stage.Title           = "2d clock";
            stage.UserResizable   = true;
            stage.BackgroundColor = Clutter.Color.New(114, 159, 207, 255);
            stage.SetSize(300, 300);
            stage.Show();

            canvas = (Canvas)Canvas.New();
            canvas.SetSize(300, 300);

            actor         = new Actor();
            actor.Content = canvas;
            actor.SetContentScalingFilters(ScalingFilter.Trilinear, ScalingFilter.Linear);
            stage.AddChild(actor);

            actor.AddConstraint(new BindConstraint(stage, BindCoordinate.Size, 0));


            actor.AllocationChanged += OnActorResize;

            stage.Destroyed += (o, e) => Application.MainQuit();

            canvas.Drawn += DrawClock;

            canvas.Invalidate();

            Threads.AddTimeoutFull(10, 1000, delegate {
                canvas.Invalidate();
                return(true);
            });

            Clutter.Application.Main();
        }
Example #15
0
        /// <summary>
        /// Shows a small debug statistic overlay on one of the corners.
        /// </summary>
        public static void ShowStats(HorizontalAlignment horizontalAlign = HorizontalAlignment.Left,
                                     VerticalAlignment verticalAlign     = VerticalAlignment.Top, float scale = 1f)
        {
            float stageWidth  = Stage.Width;
            float stageHeight = Stage.Height;

            if (_statsDisplay == null)
            {
                _statsDisplay = new StatsDisplay();
                //_statsDisplay.Touchable = false;
            }

            Stage.AddChild(_statsDisplay);// TODO now things can be added above it, prevent this
            _statsDisplay.ScaleX = _statsDisplay.ScaleY = scale;

            if (horizontalAlign == HorizontalAlignment.Left)
            {
                _statsDisplay.X = 0f;
            }
            else if (horizontalAlign == HorizontalAlignment.Right)
            {
                _statsDisplay.X = stageWidth - _statsDisplay.WidthScaled;
            }
            else if (horizontalAlign == HorizontalAlignment.Center)
            {
                _statsDisplay.X = (stageWidth - _statsDisplay.WidthScaled) / 2;
            }

            if (verticalAlign == VerticalAlignment.Top)
            {
                _statsDisplay.Y = 0f;
            }
            else if (verticalAlign == VerticalAlignment.Bottom)
            {
                _statsDisplay.Y = stageHeight - _statsDisplay.HeightScaled;
            }
            else if (verticalAlign == VerticalAlignment.Center)
            {
                _statsDisplay.Y = (stageHeight - _statsDisplay.HeightScaled) / 2;
            }
        }
Example #16
0
        public static void ShowStats(HAlign horizontalAlign = HAlign.Left,
                                     VAlign verticalAlign   = VAlign.Top, float scale = 1f)
        {
            float stageWidth  = Stage.StageWidth;
            float stageHeight = Stage.StageHeight;

            if (_statsDisplay == null)
            {
                _statsDisplay           = new StatsDisplay();
                _statsDisplay.Touchable = false;
            }

            Stage.AddChild(_statsDisplay);
            _statsDisplay.ScaleX = _statsDisplay.ScaleY = scale;

            if (horizontalAlign == HAlign.Left)
            {
                _statsDisplay.X = 0f;
            }
            else if (horizontalAlign == HAlign.Right)
            {
                _statsDisplay.X = stageWidth - _statsDisplay.Width;
            }
            else if (horizontalAlign == HAlign.Center)
            {
                _statsDisplay.X = (stageWidth - _statsDisplay.Width) / 2;
            }

            if (verticalAlign == VAlign.Top)
            {
                _statsDisplay.Y = 0f;
            }
            else if (verticalAlign == VAlign.Bottom)
            {
                _statsDisplay.Y = stageHeight - _statsDisplay.Height;
            }
            else if (verticalAlign == VAlign.Center)
            {
                _statsDisplay.Y = (stageHeight - _statsDisplay.Height) / 2;
            }
        }
Example #17
0
        static void Main(String[] args)
        {
            Stage stage;

            if (Application.Init() != InitError.Success)
            {
                return;
            }

            stage                 = new Stage();
            stage.Title           = "Scroll Actor";
            stage.UserResizable   = true;
            stage.BackgroundColor = Clutter.Color.New(255, 255, 255, 255);
            stage.SetSize(500, 500);

            stage.Destroyed  += (sender, e) => Application.MainQuit();
            stage.KeyPressed += OnKeyPress;

            stage.AddChild(CreateScrollActor(stage));

            stage.Show();

            Application.Main();
        }
Example #18
0
 /// <summary>
 /// Adds a child to stage
 /// </summary>
 /// <param name="child"></param>
 /// <returns></returns>
 public DisplayListMember AddChild(DisplayListMember child)
 {
     return(Stage.AddChild(child));
 }
Example #19
0
        //private void RemoveHandler(Event e)
        //{
        //    DisplayObject popup = e.Target as DisplayObject;
        //    if (null != popup)
        //    {
        //        popup.RemoveEventListener(MouseEvent.MOUSE_DOWN_OUTSIDE, RemoveHandler);
        //        popup.RemoveEventListener(MouseEvent.MOUSE_WHEEL_OUTSIDE, RemoveHandler);
        //        TerminatePopup(popup);
        //    }
        //    if (_popups.Count == 0 && SystemManager.Instance.HasEventListener(ResizeEvent.RESIZE))
        //        SystemManager.Instance.RemoveEventListener(ResizeEvent.RESIZE, RemoveHandler);
        //}

        //private static void TerminatePopup(DisplayObject popup)
        //{
        //    //Debug.Log("TerminatePopup");

        //    var dlm = popup as DisplayListMember;

        //    if (null != dlm)
        //    {
        //        Instance.RemovePopup(dlm);
        //        // TODO: SystemManager.Instance.RemoveEventListener(ResizeEvent.RESIZE, ...);
        //        dlm.Dispose();
        //    }
        //}

        #endregion

        #region Add

        /// <summary>
        /// Adds a popup to popup stage
        /// </summary>
        /// <param name="popup">A popup to add</param>
        /// <param name="options">Popup options</param>
        public void AddPopup(DisplayListMember popup, params PopupOption[] options)
        {
            Event e = new Event(OPENING, popup, false, true); // cancelable

            DispatchEvent(e);

            if (e.Canceled)
            {
                return;
            }

            if (IsDefaultPrevented(OPENING))
            {
                return;
            }

            if (_popups.Contains(popup))
            {
                return;
            }
#if DEBUG
            if (DebugMode)
            {
                Debug.Log("AddPopup");
            }
#endif

            DisplayObjectContainer parent = null;
            bool  modal      = true;
            bool  centered   = true;
            bool  keepCenter = false;
            bool  removeOnMouseDownOutside  = false;
            bool  removeOnMouseWheelOutside = false;
            bool  removeOnScreenResize      = false;
            bool  autoFocus           = true;
            bool  focusPreviousOnHide = true;
            Stage stage = _stage;

            bool visibleFlag = popup.Visible;
            popup.Visible = false;

            int len = options.Length;
            for (int i = 0; i < len; i++)
            {
                PopupOption option = options[i];
                switch (option.Type)
                {
                case PopupOptionType.Parent:
                    parent = (DisplayObjectContainer)option.Value;
                    break;

                case PopupOptionType.Modal:
                    modal = (bool)option.Value;
                    break;

                case PopupOptionType.Centered:
                    centered = (bool)option.Value;
                    break;

                case PopupOptionType.KeepCenter:
                    keepCenter = (bool)option.Value;
                    break;

                case PopupOptionType.RemoveOnMouseDownOutside:
                    removeOnMouseDownOutside = (bool)option.Value;
                    break;

                case PopupOptionType.RemoveOnMouseWheelOutside:
                    removeOnMouseWheelOutside = (bool)option.Value;
                    break;

                case PopupOptionType.RemoveOnScreenResize:
                    removeOnScreenResize = (bool)option.Value;
                    break;

                case PopupOptionType.AutoFocus:
                    autoFocus = (bool)option.Value;
                    break;

                case PopupOptionType.FocusPreviousOnHide:
                    focusPreviousOnHide = (bool)option.Value;
                    break;

                case PopupOptionType.Stage:
                    //Debug.Log("Exotic stage: " + option.Value);
                    stage = (Stage)option.Value;
                    break;

                default:
                    throw new Exception("Unknown option");
                }
            }

            _popups.Add(popup);

            if (null == parent)
            {
                parent = stage;
            }

            DisplayListMember overlay   = null;
            Group             popupRoot = null;

            InvalidationManagerClient imc = popup as InvalidationManagerClient;
            Component comp = popup as Component;
            if (null != comp)
            {
                comp.IsPopUp = true;
            }

            if (modal)
            {
                overlay = (DisplayListMember)Activator.CreateInstance(ModalOverlayType);
                overlay.AddEventListener(MouseEvent.MOUSE_DOWN, OnOverlayMouseDown);

                // we are packing both the overlay and the popup to into an aditional container
                popupRoot = new Group();
                stage.AddChild(popupRoot);

                // BUG BUG BUG! If we do _stage.AddChild(popupRoot); AFTER the children are added, we get a null exception
                // this is the major problem when adding children, started appearing since 10.1.2012
                // solved. This had to to with the creationcomplete method, which has to be run after the complete invalidation pass

                popupRoot.AddChild(overlay);
                popupRoot.AddChild(popup);

                // popup has been added to popup stage
                // invalidation methods have been called upon the addition
                // now we want to run measure (to validate dimensions)
                // because we want to center the popup
                // now, the absolute layout won't do it on his own
                //overlay.Bounds = (Rectangle)parent.Bounds.Clone();

                overlay.Width  = PopupManagerStage.Instance.Width;
                overlay.Height = PopupManagerStage.Instance.Height;

                /*var client = overlay as InvalidationManagerClient;
                 * if (client != null)
                 * {
                 *  /*var imc2 = client;
                 *  imc2.SetActualSize(
                 *      PopupManagerStage.Instance.Width,
                 *      PopupManagerStage.Instance.Height/*,
                 *      Math.Max(imc2.GetExplicitOrMeasuredWidth(), imc2.MinWidth),
                 *      Math.Max(imc2.GetExplicitOrMeasuredHeight(), imc2.MinHeight)#2#
                 *  );#1#
                 *  client.Width = PopupManagerStage.Instance.Width;
                 *  client.Height = PopupManagerStage.Instance.Height;
                 *  //imc2.InvalidateTransform();
                 * }
                 * else
                 * {
                 *  overlay.X = parent.X;
                 *  overlay.Y = parent.Y;
                 *  /*overlay.X = parent.X;
                 *  overlay.Y = parent.Y;#1#
                 * }*/
            }
            else
            {
                stage.AddChild(popup);
            }

            if (null != imc)
            {
                //InvalidationManager.Instance.ValidateClient(imc, true);
                imc.ValidateNow();
                //Debug.Log(string.Format("imc.Width:{0}, imc.Height:{1}", imc.Width, imc.Height));
                //Debug.Log(string.Format("imc.GetExplicitOrMeasuredWidth():{0}, imc.GetExplicitOrMeasuredHeight():{1}", imc.GetExplicitOrMeasuredWidth(), imc.GetExplicitOrMeasuredHeight()));
                //imc.SetActualSize(imc.GetExplicitOrMeasuredWidth(), imc.GetExplicitOrMeasuredHeight());

                imc.SetActualSize(
                    Math.Min(Math.Max(imc.GetExplicitOrMeasuredWidth(), imc.MinWidth), imc.MaxWidth),
                    Math.Min(Math.Max(imc.GetExplicitOrMeasuredHeight(), imc.MinHeight), imc.MaxHeight)
                    );
            }

            var descriptor = new PopupDescriptor(parent, overlay, popupRoot)
            {
                Popup      = popup,
                PopupRoot  = modal ? popupRoot : popup,
                Owner      = parent,
                Modal      = modal,
                Centered   = centered,
                KeepCenter = keepCenter,
                RemoveOnMouseDownOutside  = removeOnMouseDownOutside,
                RemoveOnMouseWheelOutside = removeOnMouseWheelOutside,
                RemoveOnScreenResize      = removeOnScreenResize,
                FocusPreviousOnHide       = focusPreviousOnHide,
                Stage = stage
            };

            _descriptors.Add(popup, descriptor);

            if (centered)
            {
                CenterPopUp(popup);
            }

            InteractiveComponent ic = popup as InteractiveComponent;
            if (autoFocus && null != ic)
            {
                ic.SetFocus(); // TEMP disabled, 2.1.2012.
                //FocusManager.Instance.SetFocus(ic);

                /*ic.Defer(delegate
                 * {
                 *  //ic.SetFocus();
                 *  FocusManager.Instance.SetFocus(ic);
                 * }, 1);*/
            }


            // connect if not connected
            if (_descriptors.Count > 0)
            {
                SystemManager.Instance.ResizeSignal.Connect(ResizeSlot);
                SystemManager.Instance.MouseDownSignal.Connect(MouseDownSlot);
                SystemManager.Instance.RightMouseDownSignal.Connect(MouseDownSlot);
                SystemManager.Instance.MiddleMouseDownSignal.Connect(MouseDownSlot);
                SystemManager.Instance.MouseWheelSignal.Connect(MouseWheelSlot);

                // subscribe to stage to see if some component has been mouse-downed
                // NOTE: some components (i.e. window close button) could cancel the event, this is by design

                // note: it is safe ta call it multiple times, it is checked internally
                stage.AddEventListener(MouseEvent.MOUSE_DOWN, MouseDownHandler);
            }
            else
            {
                SystemManager.Instance.ResizeSignal.Disconnect(ResizeSlot);
                SystemManager.Instance.MouseDownSignal.Disconnect(MouseDownSlot);
                SystemManager.Instance.RightMouseDownSignal.Disconnect(MouseDownSlot);
                SystemManager.Instance.MiddleMouseDownSignal.Disconnect(MouseDownSlot);
                SystemManager.Instance.MouseWheelSignal.Disconnect(MouseWheelSlot);

                //MouseEventDispatcher.Instance.RemoveEventListener(MouseEvent.MOUSE_DOWN, MouseDownHandler);
                stage.RemoveEventListener(MouseEvent.MOUSE_DOWN, MouseDownHandler);
            }

            // NOTE: This is needed when having effects because of the flicker (?):
            //descriptor.PopupRoot.SkipRender(100);

            // bring the popup root to front
            descriptor.PopupRoot.BringToFront();

            popup.Visible = visibleFlag;

            DispatchEvent(new Event(OPEN, popup));
        }
Example #20
0
        /// <summary>
        /// Start your app.
        /// </summary>
        /// <param name="width">Stage width</param>
        /// <param name="height">Stage height</param>
        /// <param name="viewportHeight"></param>
        /// <param name="viewportWidth"></param>
        /// <param name="rootType">The root class of your app</param>
        /// <exception cref="InvalidOperationException">When rootType is null or this function is called twice</exception>
        /// <exception cref="NotSupportedException">When the OpenGL framebuffer creation fails.</exception>
        /// <exception cref="ArgumentException">When width or height are less than 32.</exception>
        public static void Start(uint width, uint height, uint viewportWidth, uint viewportHeight, Type rootType)
        {
            Debug.WriteLine("Sparrow starting");
            if (width < 32 || height < 32 || viewportWidth < 32 || viewportHeight < 32)
            {
                throw new ArgumentException($"Invalid dimensions: {width}x{height}");
            }

            var ver = Gl.CurrentVersion;

            if (ver.Api == "gl")
            {
                if (ver.Major < 4)
                {
                    throw new NotSupportedException("You need at least OpenGL 4.0 to run Sparrow!");
                }
            }
            else
            {
                if (ver.Major < 3)
                {
                    throw new NotSupportedException("You need at least OpenGL ES 3.0 to run Sparrow!");
                }
                IsRunningOpenGLES = true;
            }

            Gl.Disable(EnableCap.CullFace);
            Gl.Disable(EnableCap.Dither);

            Gl.Enable(EnableCap.DepthTest);
            Gl.DepthFunc(DepthFunction.Always);

            BlendMode.Get(BlendMode.NORMAL).Activate();

            FramebufferStatus status = Gl.CheckFramebufferStatus(FramebufferTarget.Framebuffer);

            if (status != FramebufferStatus.FramebufferComplete)
            {
                throw new NotSupportedException("GL Framebuffer creation error. Status: " + status);
            }
            _viewPort         = Rectangle.Create(0, 0, viewportWidth, viewportHeight);
            _previousViewPort = Rectangle.Create();
            GPUInfo.PrintGPUInfo();

            // Desktop GL core profile needs a VAO for vertex attrib pointers to work.
            uint vao = Gl.GenVertexArray();

            Gl.BindVertexArray(vao);

            if (rootType == null)
            {
                throw new InvalidOperationException("Root cannot be null!");
            }

            if (Root != null)
            {
                throw new InvalidOperationException("App already initialized!");
            }

            _painter       = new Painter(width, height);
            Stage          = new Stage(width, height);
            DefaultJuggler = new Juggler();

            UpdateViewPort(true);

            Root = (DisplayObject)Activator.CreateInstance(rootType);
            Stage.AddChild(Root);
            _frameId = 1; // starts with 1, so things on the first frame are cached
        }