Esempio n. 1
0
        public Window()
        {
            IPlatformRenderInterface factory = Locator.Current.GetService <IPlatformRenderInterface>();

            this.CreateWindow();
            Size clientSize = this.ClientSize;

            this.LayoutManager = new LayoutManager(this);
            this.RenderManager = new RenderManager();
            this.renderer      = factory.CreateRenderer(this.Handle, (int)clientSize.Width, (int)clientSize.Height);
            this.inputManager  = Locator.Current.GetService <IInputManager>();
            this.Template      = ControlTemplate.Create <Window>(this.DefaultTemplate);

            this.LayoutManager.LayoutNeeded.Subscribe(x =>
            {
                WindowsDispatcher.CurrentDispatcher.BeginInvoke(
                    DispatcherPriority.Render,
                    () =>
                {
                    this.LayoutManager.ExecuteLayoutPass();
                    this.renderer.Render(this);
                    this.RenderManager.RenderFinished();
                });
            });

            this.RenderManager.RenderNeeded
            .Where(_ => !this.LayoutManager.LayoutQueued)
            .Subscribe(x =>
            {
                WindowsDispatcher.CurrentDispatcher.BeginInvoke(
                    DispatcherPriority.Render,
                    () =>
                {
                    if (!this.LayoutManager.LayoutQueued)
                    {
                        this.renderer.Render(this);
                        this.RenderManager.RenderFinished();
                    }
                });
            });
        }
Esempio n. 2
0
        public Form1()
        {
            InitializeComponent();

            _render = new PlatformRenderInterface();
            PerspexLocator.CurrentMutable.Bind <IPlatformRenderInterface>().ToConstant(_render);
            _geometry     = new StreamGeometry();
            _rbitmap      = new RenderTargetBitmap(50, 50);
            _renderTarget = _render.CreateRenderer(new PlatformHandle(Handle, "HWND"), ClientSize.Width,
                                                   ClientSize.Height);
            var timer = new Timer()
            {
                Interval = 20
            };

            timer.Tick += delegate { Invalidate(); };
            timer.Start();
            components.Add(timer);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            using (var ctx = _geometry.Open())
            {
                ctx.BeginFigure(new Point(10, 10), true);
                ctx.LineTo(new Point(40, 25));
                ctx.BezierTo(new Point(50, 45), new Point(43, 48), new Point(20, 90));
                ctx.LineTo(new Point(10, 60));
                ctx.EndFigure(true);
            }

            _text =
                new FormattedText(
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum",
                    "Arial", 25, FontStyle.Normal, TextAlignment.Left, FontWeight.Normal);

            _text.Constraint = new Size(400, double.PositiveInfinity);

            using (var ctx = _rbitmap.CreateDrawingContext())
                ctx.DrawRectangle(new Pen(new SolidColorBrush(Colors.Aqua)), new Rect(10, 10, 30, 30), 5);

            _bitmap = new Bitmap(@"C:\Users\keks\Desktop\phoenix.png");
        }
Esempio n. 3
0
        public Form1()
        {
            InitializeComponent();

            _render = new PlatformRenderInterface();
            PerspexLocator.CurrentMutable.Bind<IPlatformRenderInterface>().ToConstant(_render);
            _geometry =  new StreamGeometry();
            _rbitmap = new RenderTargetBitmap(50, 50);
            _renderTarget = _render.CreateRenderer(new PlatformHandle(Handle, "HWND"), ClientSize.Width,
                ClientSize.Height);
            var timer = new Timer() {Interval = 20};
            timer.Tick += delegate { Invalidate(); };
            timer.Start();
            components.Add(timer);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            using (var ctx = _geometry.Open())
            {
                ctx.BeginFigure(new Point(10,10), true);
                ctx.LineTo(new Point(40,25));
                ctx.BezierTo(new Point(50, 45), new Point(43, 48), new Point(20, 90));
                ctx.LineTo(new Point(10, 60));
                ctx.EndFigure(true);
            }

            _text =
                new FormattedText(
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum",
                    "Arial", 25, FontStyle.Normal, TextAlignment.Left, FontWeight.Normal);

            _text.Constraint = new Size(400, double.PositiveInfinity);

            using (var ctx = _rbitmap.CreateDrawingContext())
                ctx.DrawRectangle(new Pen(new SolidColorBrush(Colors.Aqua)), new Rect(10, 10, 30, 30), 5);

            _bitmap = new Bitmap(@"C:\Users\keks\Desktop\phoenix.png");
        }
Esempio n. 4
0
        public Window()
        {
            IPlatformRenderInterface renderInterface = Locator.Current.GetService <IPlatformRenderInterface>();

            this.impl          = Locator.Current.GetService <IWindowImpl>();
            this.inputManager  = Locator.Current.GetService <IInputManager>();
            this.LayoutManager = Locator.Current.GetService <ILayoutManager>();
            this.renderManager = Locator.Current.GetService <IRenderManager>();

            if (renderInterface == null)
            {
                throw new InvalidOperationException(
                          "Could not create an interface to the rendering subsystem: maybe no rendering subsystem was initialized?");
            }

            if (this.impl == null)
            {
                throw new InvalidOperationException(
                          "Could not create window implementation: maybe no windowing subsystem was initialized?");
            }

            if (this.inputManager == null)
            {
                throw new InvalidOperationException(
                          "Could not create input manager: maybe Application.RegisterServices() wasn't called?");
            }

            if (this.LayoutManager == null)
            {
                throw new InvalidOperationException(
                          "Could not create layout manager: maybe Application.RegisterServices() wasn't called?");
            }

            if (this.renderManager == null)
            {
                throw new InvalidOperationException(
                          "Could not create render manager: maybe Application.RegisterServices() wasn't called?");
            }

            this.impl.SetOwner(this);
            this.impl.Activated = this.HandleActivated;
            this.impl.Closed    = this.HandleClosed;
            this.impl.Input     = this.HandleInput;
            this.impl.Paint     = this.HandlePaint;
            this.impl.Resized   = this.HandleResized;

            Size clientSize = this.ClientSize = this.impl.ClientSize;

            this.dispatcher = Dispatcher.UIThread;
            this.renderer   = renderInterface.CreateRenderer(this.impl.Handle, clientSize.Width, clientSize.Height);

            this.LayoutManager.Root = this;
            this.LayoutManager.LayoutNeeded.Subscribe(_ => this.HandleLayoutNeeded());
            this.renderManager.RenderNeeded.Subscribe(_ => this.HandleRenderNeeded());

            this.GetObservable(TitleProperty).Subscribe(s => this.impl.SetTitle(s));

            IStyler styler = Locator.Current.GetService <IStyler>();

            styler.ApplyStyles(this);
        }