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); }
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); }
/* * 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; }
public void ReadTextResourceWithCallback(string path, Interpreter.Structs.Value cb) { string value = ReadTextResource(path); ((Interpreter.Vm.EventLoop) this.Vm.environment.platformEventLoop).ExecuteFunctionPointerNativeArgs(cb, new object[] { value }); }
public void ReadBinaryResourceWithCallback(string path, bool isText, bool useBase64, List <Interpreter.Structs.Value> bytesOut, Interpreter.Structs.Value[] integers, Interpreter.Structs.Value callback) { string output = ReadBinaryResource(path, isText, useBase64, bytesOut, integers); Interpreter.Vm.EventLoop evLoop = (Interpreter.Vm.EventLoop) this.Vm.environment.platformEventLoop; if (output == null) { evLoop.ExecuteFunctionPointerNativeArgs(callback, new object[] { null }); } else { evLoop.ExecuteFunctionPointerNativeArgs(callback, new object[] { output }); } }