Beispiel #1
0
 public static void InitDebugMode(DpiAwareForm form)
 {
     form.FormBorderStyle = FormBorderStyle.Sizable;
     form.Size            = new System.Drawing.Size(1000, 1000);
     form.StartPosition   = FormStartPosition.CenterScreen;
     form.FpsProfiler
     .GetAverageFramesPerSecond(40)
     .Subscribe(fps => form.Text = fps.ToString());
     form.Show();
 }
Beispiel #2
0
        public UnoControl(DpiAwareForm form, IReport log)
        {
            _form = form;
            _log  = log;

            SetStyle(ControlStyles.Opaque, true);
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            DoubleBuffered = false;
            Dock           = DockStyle.Fill;

            // set up an OpenTK context
            Toolkit.Init(new ToolkitOptions {
                Backend = PlatformBackend.PreferNative
            });
            var windowInfo = Utilities.CreateWindowsWindowInfo(Handle);

            _glContext = ContextFactory.CreateContext(windowInfo);
            _glContext.SwapInterval = 0;

            _unoWindow   = new PlatformWindowHandleImpl(this);
            _unoGraphics = new GraphicsContextHandleImpl(_unoWindow);


            _form.PreviewKeyDown += (sender, e) =>
            {
                // TODO: By doing this the tab key will not be sent to wpf at all, it should be treated as IsInputKey only when not handled by Uno. A better solution could be done by reading http://msdn.microsoft.com/en-us/library/ms742474%28v=vs.110%29.aspx and http://blogs.msdn.com/b/nickkramer/archive/2006/06/09/623203.aspx

                var codeWithoutModifiers = e.KeyCode & (~Keys.Control) & (~Keys.Shift);

                switch (codeWithoutModifiers)
                {
                case Keys.Left:
                case Keys.Right:
                case Keys.Up:
                case Keys.Down:
                case Keys.Tab:
                    e.IsInputKey = true;
                    break;
                }
            };

            Focus();
        }
Beispiel #3
0
        static void Main(string[] argsArray)
        {
            var shell     = new Shell();
            var systemId  = SystemGuidLoader.LoadOrCreateOrEmpty();
            var sessionId = Guid.NewGuid();
            var log       = ReportFactory.GetReporter(systemId, sessionId, "UnoHost");

            AppDomain.CurrentDomain.ReportUnhandledExceptions(log);

            DpiAwareness.SetDpiAware(DpiAwareness.ProcessDpiAwareness.SystemAware);

            NativeResources.Load();

            var args = UnoHostArgs.RemoveFrom(argsArray.ToList(), shell);

            // Load metadata
            var unoHostProject = UnoHostProject.Load(args.MetadataPath, shell);

            var form = new DpiAwareForm()
            {
                FormBorderStyle = FormBorderStyle.None,
                ShowInTaskbar   = false
            };

            //if (args.IsDebug)
            //	InitDebugMode(form);

            var unoControl = new UnoControl(form, log);

            form.Controls.Add(unoControl);
            form.ShowIcon = false;


            var openGlVersion   = new Subject <OpenGlVersion>();
            var backgroundQueue = new QueuedDispatcher();
            var lostFocus       = Observable.FromEventPattern(unoControl, "LostFocus").ObserveOn(backgroundQueue);

            var messagesTo = new Subject <IBinaryMessage>();

            var output = Observable.Merge(
                messagesTo.Do(message => Console.WriteLine(message.Type)),
                openGlVersion.Select(OpenGlVersionMessage.Compose),
                Observable.FromEventPattern(unoControl, "GotFocus").Select(_ => WindowFocusMessage.Compose(FocusState.Focused)),
                lostFocus.Select(_ => WindowFocusMessage.Compose(FocusState.Blurred)),
                lostFocus.Select(_ => WindowContextMenuMessage.Compose(false)),
                Observable.FromEventPattern <MouseEventArgs>(unoControl, "MouseUp")
                .Where(m => m.EventArgs.Button == System.Windows.Forms.MouseButtons.Right)
                .Select(_ => WindowContextMenuMessage.Compose(true)),
                Observable.FromEventPattern <MouseEventArgs>(unoControl, "MouseDown")
                .Select(_ => WindowContextMenuMessage.Compose(false)),
                Observable.FromEventPattern <MouseEventArgs>(unoControl, "MouseWheel")
                .Select(m => WindowMouseScrollMessage.Compose(m.EventArgs.Delta)),
                Observable.FromEventPattern <KeyEventArgs>(unoControl, "KeyDown")
                .Select(m => WindowKeyDown.Compose(m.EventArgs.KeyCode)),
                Observable.FromEventPattern <KeyEventArgs>(unoControl, "KeyUp")
                .Select(m => WindowKeyUp.Compose(m.EventArgs.KeyCode)));

            args.OutputPipe.BeginWritingMessages(
                "Designer",
                ex => Console.WriteLine("UnoHost failed to write message to designer: " + ex),
                output.ObserveOn(new QueuedDispatcher()));

            unoControl.Initialize(unoHostProject, openGlVersion);

            // Set hand cursor so we know when we're interacting with the UnoHost and not in the designer
            unoControl.Cursor = System.Windows.Forms.Cursors.Hand;

            // notify studio about the window
            messagesTo.OnNext(WindowCreatedMessage.Compose(form.Handle));

            var dispatcher = new PollingDispatcher(Thread.CurrentThread);

            unoControl.PerFrame.Subscribe(f => dispatcher.DispatchCurrent());


            var density = Observable.Return(new Ratio <Points, Pixels>(1));

            var size = Observable.FromEventPattern(unoControl, "SizeChanged")
                       .StartWith(new EventPattern <object>(null, null))
                       .Select(_ => unoControl.Size.ToSize())
                       .CombineLatest(density, (s, d) => s.Mul(d))
                       .Transpose();



            var messagesFrom = args.InputPipe
                               .ReadMessages("Designer")
                               .RefCount()
                               .ObserveOn(dispatcher)
                               .Publish();

            messagesFrom.Subscribe(next => { }, e => form.Exit(1), () => form.Exit(0));

            // Run the uno entrypoints, this initializes Uno.Application.Current

            unoHostProject.ExecuteStartupCode();
            var app = Uno.Application.Current as dynamic;


            // Init plugins

            FusionImplementation.Initialize(dispatcher, args.UserDataPath, app.Reflection);
            var overlay = PluginManager.Initialize(messagesFrom, messagesTo, dispatcher, unoControl.PerFrame, size);

            app.ResetEverything(true, overlay);


            // Ready to go

            messagesFrom.Connect();
            messagesTo.OnNext(new Ready());

            unoControl.Run();
        }