Esempio n. 1
0
        public static object ShowFrame(Interpreter.Structs.Value crayonObj, string title, int width, int height, string uiData, int execId)
        {
            NoriFrame frame = NoriFrame.CreateAndShow(crayonObj, title, width, height, uiData, execId);

            activeFrames.Add(frame);
            return(frame);
        }
Esempio n. 2
0
        public static bool FlushUpdatesToFrame(object nativeFrameHandle, string uiData)
        {
            NoriFrame frame = (NoriFrame)nativeFrameHandle;

            frame.SendUiData(uiData);
            return(true);
        }
Esempio n. 3
0
        public static bool CloseFrame(object nativeFrameHandle)
        {
            NoriFrame frame = (NoriFrame)nativeFrameHandle;

            frame.Close();
            return(true);
        }
Esempio n. 4
0
 public static void QueueCloseWindowNotification(NoriFrame sender)
 {
     lock (eventQueue)
     {
         eventQueue.Add("CLOSE");
         eventQueue.Add(sender);
         eventQueue.Add(0);
         eventQueue.Add("");
         eventQueue.Add("");
     }
 }
Esempio n. 5
0
 public static void QueueEventMessage(NoriFrame sender, int elementId, string eventName, string value)
 {
     lock (eventQueue)
     {
         eventQueue.Add("EVENT");
         eventQueue.Add(sender);
         eventQueue.Add(elementId);
         eventQueue.Add(eventName);
         eventQueue.Add(value);
     }
 }
Esempio n. 6
0
        public static NoriFrame CreateAndShow(
            Interpreter.Structs.Value crayonObj,
            string title,
            int width,
            int height,
            string uiData,
            int resumeExecId)
        {
            NoriFrame frame = new NoriFrame(title, width, height, uiData);

            frame.CrayonObjectRef = crayonObj;
            frame.ResumeExecId    = resumeExecId;
            frame.Show();
            return(frame);
        }
Esempio n. 7
0
        public static void SendImageToRenderer(object frameObj, int id, object nativeImageData, int x, int y, int width, int height)
        {
            NoriFrame       frame = (NoriFrame)frameObj;
            UniversalBitmap atlas = (UniversalBitmap)nativeImageData;
            UniversalBitmap cropped;

            if (atlas.Width == width && atlas.Height == height)
            {
                cropped = atlas;
            }
            else
            {
                cropped = new UniversalBitmap(width, height);
                UniversalBitmap.DrawingSession session = cropped.GetActiveDrawingSession();
                session.Draw(atlas, 0, 0, x, y, width, height);
                session.Flush();
            }
            byte[] pngBytes    = cropped.GetBytesAsPng();
            string base64Image = UniversalBitmap.ToBase64("data:image/png;base64,", pngBytes);

            frame.SendImageToBrowser(id, width, height, base64Image);
        }
Esempio n. 8
0
        /*
         *  Called by a CNI function after the frame is shown and just blocks and waits for
         *  events from the queue.
         *  If a window close event is generated, then blocking ends.
         */
        public static void EventWatcher(
            Interpreter.Structs.VmContext vmContext,
            int resumingExecutionContextId,
            Interpreter.Structs.Value openedFrameAsValue,
            Interpreter.Structs.Value noriHandlerFunctionPointer,
            Interpreter.Structs.Value postShowFunctionPointer)
        {
            Interpreter.Vm.CrayonWrapper.runInterpreterWithFunctionPointer(
                vmContext,
                postShowFunctionPointer,
                new Interpreter.Structs.Value[] { openedFrameAsValue });

            // TODO: find a better way.
            while (activeFrames.Count > 0)
            {
                object[] events = null;
                lock (eventQueue)
                {
                    if (eventQueue.Count > 0)
                    {
                        events = eventQueue.ToArray();
                        eventQueue.Clear();
                    }
                }

                if (events != null)
                {
                    for (int i = 0; i < events.Length; i += 5)
                    {
                        string    type   = events[i].ToString();
                        NoriFrame sender = (NoriFrame)events[i + 1];
                        if (type == "EVENT")
                        {
                            int    elementId = (int)events[i + 2];
                            string eventName = (string)events[i + 3];
                            string args      = (string)events[i + 4];
                            Interpreter.Vm.CrayonWrapper.runInterpreterWithFunctionPointer(
                                vmContext,
                                noriHandlerFunctionPointer,
                                new Interpreter.Structs.Value[] {
                                sender.CrayonObjectRef,
                                Interpreter.Vm.CrayonWrapper.buildInteger(vmContext.globals, elementId),
                                Interpreter.Vm.CrayonWrapper.buildString(vmContext.globals, eventName),
                                Interpreter.Vm.CrayonWrapper.buildString(vmContext.globals, args)
                            });
                        }
                        else if (type == "CLOSE")
                        {
                            if (activeFrames.Contains(sender))
                            {
                                activeFrames.Remove(sender);
                            }

                            if (resumingExecutionContextId != sender.ResumeExecId)
                            {
                                Interpreter.Vm.CrayonWrapper.runInterpreter(vmContext, sender.ResumeExecId);
                            }
                        }
                    }
                }
                else
                {
                    System.Threading.Thread.Sleep(System.TimeSpan.FromMilliseconds(0.1));
                }
            }

            Structs.ExecutionContext ec = Interpreter.Vm.CrayonWrapper.getExecutionContext(vmContext, resumingExecutionContextId);
            ec.activeInterrupt      = null;
            ec.executionStateChange = false;
        }