Exemple #1
0
        public override void RenderWay(RenderCallback renderCallback, RenderContext renderContext, PolylineContainer way)
        {
            if (Display.Never == this.display)
            {
                return;
            }

            string caption = this.textKey.GetValue(way.Tags);

            if (string.ReferenceEquals(caption, null))
            {
                return;
            }

            float horizontalOffset = 0f;
            float verticalOffset   = this.dyScaled[renderContext.rendererJob.tile.ZoomLevel] ?? this.dy;

            if (this.bitmap != null)
            {
                horizontalOffset = ComputeHorizontalOffset();
                verticalOffset   = ComputeVerticalOffset(renderContext.rendererJob.tile.ZoomLevel);
            }

            renderCallback.RenderAreaCaption(renderContext, this.display, this.priority, caption, horizontalOffset, verticalOffset, getFillPaint(renderContext.rendererJob.tile.ZoomLevel), getStrokePaint(renderContext.rendererJob.tile.ZoomLevel), this.position, this.maxTextWidth, way);
        }
        private void MatchWay(RenderCallback renderCallback, RenderContext renderContext, Closed closed, PolylineContainer way)
        {
            lock (this)
            {
                MatchingCacheKey matchingCacheKey = new MatchingCacheKey(way.Tags, way.Tile.ZoomLevel, closed);

                IList <RenderInstruction> matchingList = this.wayMatchingCache.Get(matchingCacheKey);
                if (matchingList != null)
                {
                    // cache hit
                    for (int i = 0, n = matchingList.Count; i < n; ++i)
                    {
                        matchingList[i].RenderWay(renderCallback, renderContext, way);
                    }
                    return;
                }

                // cache miss
                matchingList = new List <RenderInstruction>();
                for (int i = 0, n = this.rulesList.Count; i < n; ++i)
                {
                    this.rulesList[i].MatchWay(renderCallback, way, way.Tile, closed, matchingList, renderContext);
                }

                this.wayMatchingCache.Add(matchingCacheKey, matchingList);
            }
        }
        public override void RenderWay(RenderCallback renderCallback, RenderContext renderContext, PolylineContainer way)
        {
            if (Display.NEVER == this.display)
            {
                return;
            }

            if (this.bitmap == null && !this.bitmapInvalid)
            {
                try
                {
                    this.bitmap = CreateBitmap(relativePathPrefix, src);
                }
                catch (IOException)
                {
                    this.bitmapInvalid = true;
                }
            }

            float dyScale = this.dyScaled[renderContext.rendererJob.tile.ZoomLevel] ?? this.dy;

            if (this.bitmap != null)
            {
                renderCallback.RenderWaySymbol(renderContext, this.display, this.priority, this.bitmap, dyScale, this.alignCenter, this.repeat, this.repeatGap, this.repeatStart, this.rotate, way);
            }
        }
Exemple #4
0
        public override void RenderWay(RenderCallback renderCallback, RenderContext renderContext, PolylineContainer way)
        {
            lock (this)
            {
                // this needs to be synchronized as we potentially set a shift in the shader and
                // the shift is particular to the tile when rendered in multi-thread mode
                IPaint fillPaint = getFillPaint(renderContext.rendererJob.tile.ZoomLevel);
                if (shaderBitmap == null && !bitmapInvalid)
                {
                    try
                    {
                        shaderBitmap = CreateBitmap(relativePathPrefix, src);
                        if (shaderBitmap != null)
                        {
                            fillPaint.BitmapShader = shaderBitmap;
                            shaderBitmap.DecrementRefCount();
                        }
                    }
                    catch (IOException)
                    {
                        bitmapInvalid = true;
                    }
                }

                fillPaint.BitmapShaderShift = way.Tile.Origin;

                renderCallback.RenderArea(renderContext, fillPaint, getStrokePaint(renderContext.rendererJob.tile.ZoomLevel), this.level, way);
            }
        }
Exemple #5
0
        public override void RenderWay(RenderCallback renderCallback, RenderContext renderContext, PolylineContainer way)
        {
            lock (this)
            {
                if (!bitmapCreated)
                {
                    try
                    {
                        shaderBitmap = CreateBitmap(relativePathPrefix, src);
                    }
                    catch (IOException)
                    {
                        // no-op
                    }
                    bitmapCreated = true;
                }

                IPaint strokePaint = getStrokePaint(renderContext.rendererJob.tile.ZoomLevel);

                if (shaderBitmap != null)
                {
                    strokePaint.BitmapShader         = shaderBitmap;
                    strokePaint.SetBitmapShaderShift = way.Tile.Origin;
                }

                float dyScale = this.dyScaled[renderContext.rendererJob.tile.ZoomLevel] ?? this.dy;

                renderCallback.RenderWay(renderContext, strokePaint, dyScale, this.level, way);
            }
        }
Exemple #6
0
        private void UseFormattedText(RenderCallback renderCallback)
        {
            Brush           textBrush       = new SolidColorBrush(ForeColor.ToWpfColor());
            FontDescription fontDescription = Font.GetFontDescription();
            var             formattedText   = new FormattedText(
                Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                fontDescription.Typeface, fontDescription.Size, textBrush);

            formattedText.SetTextDecorations(fontDescription.TextDecorations);
            if (Width != null)
            {
                formattedText.MaxTextWidth = Width.Value;
            }
            if (Height != null)
            {
                formattedText.MaxTextHeight = Height.Value;
            }
            if (!Multiline)
            {
                formattedText.MaxLineCount = 1;
            }
            formattedText.Trimming = TextTrimming.None;
            //formattedText.TextAlignment = HorizontalTextAlignment;

            renderCallback(formattedText);
        }
        /// <summary>
        /// Matches a node with the given parameters against this RenderTheme. </summary>
        ///  <param name="renderCallback">
        ///            the callback implementation which will be executed on each match. </param>
        /// <param name="renderContext"> </param>
        /// <param name="poi">
        ///            the point of interest. </param>
        public virtual void MatchNode(RenderCallback renderCallback, RenderContext renderContext, PointOfInterest poi)
        {
            lock (this)
            {
                MatchingCacheKey matchingCacheKey = new MatchingCacheKey(poi.Tags, renderContext.rendererJob.tile.ZoomLevel, Closed.NO);

                IList <RenderInstruction> matchingList = this.poiMatchingCache.Get(matchingCacheKey);
                if (matchingList != null)
                {
                    // cache hit
                    for (int i = 0, n = matchingList.Count; i < n; ++i)
                    {
                        matchingList[i].RenderNode(renderCallback, renderContext, poi);
                    }
                    return;
                }

                // cache miss
                matchingList = new List <RenderInstruction>();

                for (int i = 0, n = this.rulesList.Count; i < n; ++i)
                {
                    this.rulesList[i].MatchNode(renderCallback, renderContext, matchingList, poi);
                }
                this.poiMatchingCache.Add(matchingCacheKey, matchingList);
            }
        }
Exemple #8
0
 public GoWrapper(RenderCallback onGUI = null, DisposeCallback onDispose = null) : base()
 {
     this._onGUI     = onGUI;
     this._onDispose = onDispose;
     this._width     = 1024;
     this._height    = 1024;
 }
        /////////////////////////////////////////////////////////////////////////////////
        private void RenderEvent(int eventId)
        {
#if UNITY_4_6 || UNITY_5_0 || UNITY_5_1
            UnityEngine.GL.IssuePluginEvent(eventId);
#else
            UnityEngine.GL.IssuePluginEvent(RenderCallback.Get(), eventId);
#endif
        }
Exemple #10
0
 public RenderItem(
     RenderableComponent renderable,
     Effect effect,
     EffectPipelineStateHandle pipelineStateHandle,
     RenderCallback renderCallback)
     : base(effect, pipelineStateHandle, renderCallback)
 {
     Renderable = renderable;
 }
Exemple #11
0
 protected RenderItemBase(
     Effect effect,
     EffectPipelineStateHandle pipelineStateHandle,
     RenderCallback renderCallback)
 {
     Effect = effect;
     PipelineStateHandle = pipelineStateHandle;
     RenderCallback      = renderCallback;
 }
Exemple #12
0
 public InstancedRenderItem(
     RenderInstanceData instanceData,
     Effect effect,
     EffectPipelineStateHandle pipelineStateHandle,
     RenderCallback renderCallback)
     : base(effect, pipelineStateHandle, renderCallback)
 {
     InstanceData = instanceData;
 }
        /// <summary>
        /// Registers the render callback.
        /// </summary>
        /// <param name="callback">The callback.</param>
        /// <param name="priority">The priority.</param>
        /// <param name="tieBreaker">if set to <c>true</c> [tie breaker].</param>
        public void RegisterRenderCallback(RenderCallback callback, int priority, bool tieBreaker = false)
        {
            Monitor.Enter(syncRoot);
            var prio = priority * 100;

            AdjustPriority(ref prio, tieBreaker);
            renderCallbacks.Add(prio, callback);
            Monitor.Exit(syncRoot);
        }
        /// <summary>
        /// Registers the render callback.
        /// </summary>
        /// <param name="callback">The callback.</param>
        /// <param name="priority">The priority.</param>
        /// <param name="tieBreaker">if set to <c>true</c> [tie breaker].</param>
        public void RegisterRenderCallback(RenderCallback callback, int priority, bool tieBreaker = false)
        {
            var prio = priority * 100;

            lock (renderCallbacks)
            {
                AdjustPriority(ref prio, tieBreaker);
                renderCallbacks.Add(prio, callback);
            }
        }
Exemple #15
0
 public override void Dispose()
 {
     base.Dispose();
     this._onGUI = null;
     if (this._onDispose != null)
     {
         this._onDispose();
     }
     this._onDispose = null;
 }
Exemple #16
0
        public override void RenderNode(RenderCallback renderCallback, RenderContext renderContext, PointOfInterest poi)
        {
            if (Display.NEVER == this.display)
            {
                return;
            }

            if (Bitmap != null)
            {
                renderCallback.RenderPointOfInterestSymbol(renderContext, this.display, this.priority, this.bitmap, poi);
            }
        }
Exemple #17
0
        public override void RenderWay(RenderCallback renderCallback, RenderContext renderContext, PolylineContainer way)
        {
            if (Display.NEVER == this.display)
            {
                return;
            }

            if (this.Bitmap != null)
            {
                renderCallback.RenderAreaSymbol(renderContext, this.display, this.priority, this.bitmap, way);
            }
        }
Exemple #18
0
        public void RenderLoop(Func <bool> cancel)
        {
            var sample = 0;

            while (!cancel())
            {
                RenderCallback?.Invoke();
                var stats = _backBuffer.WriteTo(_frontBuffer);
                SampleCallback?.Invoke(sample++, stats);
                Invalidate();
                Thread.Sleep(10);
            }
        }
 /// <summary>
 /// Removes the render callback.
 /// </summary>
 /// <param name="callback">The callback.</param>
 public void RemoveRenderCallback(RenderCallback callback)
 {
     lock (renderCallbacks)
     {
         var exists = renderCallbacks.Values.Contains(callback);
         if (!exists)
         {
             return;
         }
         var kvp = renderCallbacks.FirstOrDefault(k => k.Value == callback);
         renderCallbacks.Remove(kvp.Key);
     }
 }
Exemple #20
0
 internal virtual void MatchWay(RenderCallback renderCallback, PolylineContainer way, Tile tile, Closed closed, IList <RenderInstruction> matchingList, RenderContext renderContext)
 {
     if (MatchesWay(way.Tags, tile.ZoomLevel, closed))
     {
         for (int i = 0, n = this.renderInstructions.Count; i < n; ++i)
         {
             this.renderInstructions[i].RenderWay(renderCallback, renderContext, way);
             matchingList.Add(this.renderInstructions[i]);
         }
         for (int i = 0, n = this.subRules.Count; i < n; ++i)
         {
             this.subRules[i].MatchWay(renderCallback, way, tile, closed, matchingList, renderContext);
         }
     }
 }
 /// <summary>
 /// Removes the render callback.
 /// </summary>
 /// <param name="callback">The callback.</param>
 public void RemoveRenderCallback(RenderCallback callback)
 {
     Monitor.Enter(syncRoot);
     try
     {
         var exists = renderCallbacks.Values.Contains(callback);
         if (!exists)
         {
             return;
         }
         var kvp = renderCallbacks.FirstOrDefault(k => k.Value == callback);
         renderCallbacks.Remove(kvp.Key);
     }
     finally { Monitor.Exit(syncRoot); }
 }
Exemple #22
0
 internal virtual void MatchNode(RenderCallback renderCallback, RenderContext renderContext, IList <RenderInstruction> matchingList, PointOfInterest pointOfInterest)
 {
     if (MatchesNode(pointOfInterest.Tags, renderContext.rendererJob.tile.ZoomLevel))
     {
         for (int i = 0, n = this.renderInstructions.Count; i < n; ++i)
         {
             this.renderInstructions[i].RenderNode(renderCallback, renderContext, pointOfInterest);
             matchingList.Add(this.renderInstructions[i]);
         }
         for (int i = 0, n = this.subRules.Count; i < n; ++i)
         {
             this.subRules[i].MatchNode(renderCallback, renderContext, matchingList, pointOfInterest);
         }
     }
 }
        public void CreatePipelineIsCalledOnStartStreamForFile()
        {
            Streamer streamer = new Streamer(_mediaDeviceWrapperMock.Object, new IntPtr(12345));

            int            width, height;
            IntPtr         surface;
            RenderCallback callback = (int x, int y) => { };

            streamer.StartStream("foo", out width, out height, out surface, callback);

            _mediaDeviceWrapperMock.Verify(m => m.CreatePipeline(
                                               It.Is <string>(s => s == "foo"),
                                               out surface,
                                               ref width,
                                               ref height,
                                               It.Is <RenderCallback>(c => c == callback)));
        }
Exemple #24
0
            /// <summary>
            /// Private rendering loop
            /// </summary>
            public void Run(RenderCallback renderCallback)
            {
                _wndProc = new Win32Native.WndProc(WndProc);

                // Set our own private wndproc in order to catch NCDestroy message
                Win32Native.SetWindowLong(new HandleRef(this, _windowHandle), Win32Native.WindowLongType.WndProc, _wndProc);

                // Show the form
                _form.Show();

                // Main rendering loop);
                while (_isAlive)
                {
                    if (UseCustomDoEvents)
                    {
                        // Previous code not compatible with Application.AddMessageFilter but faster then DoEvents
                        Win32Native.NativeMessage msg;
                        while (Win32Native.PeekMessage(out msg, _windowHandle, 0, 0, 0) != 0)
                        {
                            if (Win32Native.GetMessage(out msg, _windowHandle, 0, 0) == -1)
                            {
                                throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture,
                                                                                  "An error happened in rendering loop while processing windows messages. Error: {0}",
                                                                                  Marshal.GetLastWin32Error()));
                            }

                            Win32Native.TranslateMessage(ref msg);
                            Win32Native.DispatchMessage(ref msg);
                        }
                    }
                    else
                    {
                        // Revert back to Application.DoEvents in order to support Application.AddMessageFilter
                        // Seems that DoEvents is compatible with Mono unlike Application.Run that was not running
                        // correctly.
                        Application.DoEvents();
                    }
                    if (_isAlive)
                    {
                        renderCallback();
                    }
                }

                _form.Disposed -= _form_Disposed;
            }
Exemple #25
0
        public override void RenderWay(RenderCallback renderCallback, RenderContext renderContext, PolylineContainer way)
        {
            if (Display.Never == this.display)
            {
                return;
            }

            string caption = this.textKey.GetValue(way.Tags);

            if (string.ReferenceEquals(caption, null))
            {
                return;
            }

            float dyScale = this.dyScaled[renderContext.rendererJob.tile.ZoomLevel] ?? this.dy;

            renderCallback.RenderWayText(renderContext, this.display, this.priority, caption, dyScale, GetFillPaint(renderContext.rendererJob.tile.ZoomLevel), getStrokePaint(renderContext.rendererJob.tile.ZoomLevel), way);
        }
Exemple #26
0
 static extern void Noesis_Win32Display_RegisterCallbacks(
     LocationChangedCallback locationChangedCallback,
     SizeChangedCallback sizeChangedCallback,
     StateChangedCallback stateChangedCallback,
     FileDroppedCallback fileDroppedCallback,
     ActivatedCallback activatedCallback,
     DeactivatedCallback deactivatedCallback,
     RenderCallback renderCallback,
     MouseMoveCallback mouseMoveCallback,
     MouseButtonDownCallback mouseButtonDownCallback,
     MouseButtonUpCallback mouseButtonUpCallback,
     MouseDoubleClickCallback mouseDoubleClickCallback,
     MouseWheelCallback mouseWheelCallback,
     KeyDownCallback keyDownCallback,
     KeyUpCallback keyUpCallback,
     CharCallback charCallback,
     TouchMoveCallback touchMoveCallback,
     TouchDownCallback touchDownCallback,
     TouchUpCallback touchUpCallback);
        public void CreateCamStreamIsCalledOnStartStreamFromCamera()
        {
            Streamer streamer = new Streamer(_mediaDeviceWrapperMock.Object, new IntPtr(12345));

            int            width, height;
            bool           isHwEnabled;
            IntPtr         surface;
            RenderCallback callback = (int x, int y) => { };

            streamer.StartStream(12345, out width, out height, out surface, out isHwEnabled, callback);

            _mediaDeviceWrapperMock.Verify(m => m.CreateCamStream(
                                               It.Is <int>(i => i == 12345),
                                               out surface,
                                               ref width,
                                               ref height,
                                               ref isHwEnabled,
                                               It.Is <RenderCallback>(c => c == callback)));
        }
Exemple #28
0
        public static void Run(Control form, RenderCallback renderCallback, bool useDoEvents = false)
        {
            if (form == null || renderCallback == null)
            {
                throw new ArgumentNullException();
            }

            form.Show();

            using (var render = new RenderLoop(form))
            {
                render.UseDoEvents = useDoEvents;

                while (render.NextFrame())
                {
                    renderCallback();
                }
            }
        }
Exemple #29
0
        /// <summary>
        /// Runs the specified main loop for the specified windows form.
        /// </summary>
        /// <param name="form">The form.</param>
        /// <param name="renderCallback">The rendering callback.</param>
        /// <exception cref="System.ArgumentNullException">form
        /// or
        /// renderCallback</exception>
        public static void Run(Window form, RenderCallback renderCallback)
        {
            if (form == null)
            {
                throw new ArgumentNullException(nameof(form));
            }
            if (renderCallback == null)
            {
                throw new ArgumentNullException(nameof(renderCallback));
            }

            form.Show();
            using (var renderLoop = new SDLMessageLoop(form))
            {
                while (renderLoop.NextFrame())
                {
                    renderCallback();
                }
            }
        }
Exemple #30
0
        /// <summary>
        /// Runs the specified main loop for the specified windows form.
        /// </summary>
        /// <param name="form">The form.</param>
        /// <param name="renderCallback">The rendering callback.</param>
        public static void Run(Control form, RenderCallback renderCallback)
        {
            if (form == null)
            {
                throw new ArgumentNullException("form");
            }
            if (renderCallback == null)
            {
                throw new ArgumentNullException("renderCallback");
            }

            form.Show();
            using (var renderLoop = new RenderLoop(form))
            {
                while (renderLoop.NextFrame())
                {
                    renderCallback();
                }
            }
        }
Exemple #31
0
        /// <summary>
        /// Runs the specified main loop for the specified windows form.
        /// </summary>
        /// <param name="form">The form.</param>
        /// <param name="renderCallback">The rendering callback.</param>
        /// <exception cref="System.ArgumentNullException">form
        /// or
        /// renderCallback</exception>
        public static void Run(Window form, RenderCallback renderCallback)
        {
            if(form == null) throw new ArgumentNullException(nameof(form));
            if(renderCallback == null) throw new ArgumentNullException(nameof(renderCallback));

            form.Show();
            using (var renderLoop = new SdlMessageLoop(form))
            {
                while(renderLoop.NextFrame())
                {
                    renderCallback();
                }
            }
        }
Exemple #32
0
        /// <summary>
        /// Runs the specified main loop for the specified windows form.
        /// </summary>
        /// <param name="form">The form.</param>
        /// <param name="renderCallback">The rendering callback.</param>
        public static void Run(Control form, RenderCallback renderCallback)
        {
            if(form == null) throw new ArgumentNullException("form");
            if(renderCallback == null) throw new ArgumentNullException("renderCallback");

            form.Show();
            using(var renderLoop = new RenderLoop(form))
            {
                while(renderLoop.NextFrame())
                {
                    renderCallback();
                }
            }
        }
Exemple #33
0
		public void Render(RenderCallback pRenderCallback)
		{
			// loop through all of the effect's passes
			foreach (EffectPass pEffectPass in m_pEffect.CurrentTechnique.Passes)
			{
				// set state for the current effect pass
				pEffectPass.Apply();

				// render
				pRenderCallback(this, pEffectPass);
			}
		}
Exemple #34
0
		public mupen64plusApi(N64 bizhawkCore, byte[] rom, VideoPluginSettings video_settings, int SaveType, int CoreType, bool DisableExpansionSlot)
		{
			// There can only be one core (otherwise breaks mupen64plus)
			if (AttachedCore != null)
			{
				AttachedCore.Dispose();
				AttachedCore = null;
			}
			this.bizhawkCore = bizhawkCore;

			CoreDll = LoadLibrary("mupen64plus.dll");
			if (CoreDll == IntPtr.Zero)
				throw new InvalidOperationException(string.Format("Failed to load mupen64plus.dll"));

			connectFunctionPointers();

			// Start up the core
			m64p_error result = m64pCoreStartup(0x20001, "", "", "Core",
				null, "", IntPtr.Zero);

			// Set the savetype if needed
			if (DisableExpansionSlot)
			{
				IntPtr core_section = IntPtr.Zero;
				int disable = 1;
				m64pConfigOpenSection("Core", ref core_section);
				m64pConfigSetParameter(core_section, "DisableExtraMem", m64p_type.M64TYPE_INT, ref disable);
			}

			// Set the savetype if needed
			if (SaveType != 0)
			{
				IntPtr core_section = IntPtr.Zero;
				m64pConfigOpenSection("Core", ref core_section);
				m64pConfigSetParameter(core_section, "SaveType", m64p_type.M64TYPE_INT, ref SaveType);
			}

			IntPtr coreSection = IntPtr.Zero;
			m64pConfigOpenSection("Core", ref coreSection);
			m64pConfigSetParameter(coreSection, "R4300Emulator", m64p_type.M64TYPE_INT, ref CoreType);

			// Pass the rom to the core
			result = m64pCoreDoCommandByteArray(m64p_command.M64CMD_ROM_OPEN, rom.Length, rom);

			// Open the general video settings section in the config system
			IntPtr video_section = IntPtr.Zero;
			m64pConfigOpenSection("Video-General", ref video_section);

			// Set the desired width and height for mupen64plus
			result = m64pConfigSetParameter(video_section, "ScreenWidth", m64p_type.M64TYPE_INT, ref video_settings.Width);
			result = m64pConfigSetParameter(video_section, "ScreenHeight", m64p_type.M64TYPE_INT, ref video_settings.Height);

			set_video_parameters(video_settings);

			InitSaveram();

			// Initialize event invoker
			m64pFrameCallback = new FrameCallback(FireFrameFinishedEvent);
			result = m64pCoreDoCommandFrameCallback(m64p_command.M64CMD_SET_FRAME_CALLBACK, 0, m64pFrameCallback);
			m64pVICallback = new VICallback(FireVIEvent);
			result = m64pCoreDoCommandVICallback(m64p_command.M64CMD_SET_VI_CALLBACK, 0, m64pVICallback);
			m64pRenderCallback = new RenderCallback(FireRenderEvent);
			result = m64pCoreDoCommandRenderCallback(m64p_command.M64CMD_SET_RENDER_CALLBACK, 0, m64pRenderCallback);

			// Prepare to start the emulator in a different thread
			m64pEmulator = new Thread(ExecuteEmulator);

			AttachedCore = this;
		}
 /// <summary>
 /// Registers the render callback.
 /// </summary>
 /// <param name="callback">The callback.</param>
 /// <param name="priority">The priority.</param>
 /// <param name="tieBreaker">if set to <c>true</c> [tie breaker].</param>
 public void RegisterRenderCallback(RenderCallback callback, int priority, bool tieBreaker = false)
 {
     Monitor.Enter(syncRoot);
     var prio = priority * 100;
     AdjustPriority(ref prio, tieBreaker);
     renderCallbacks.Add(prio, callback);
     Monitor.Exit(syncRoot);
 }
 /// <summary>
 /// Removes the render callback.
 /// </summary>
 /// <param name="callback">The callback.</param>
 public void RemoveRenderCallback(RenderCallback callback)
 {
     Monitor.Enter(syncRoot);
     try
     {
         var exists = renderCallbacks.Values.Contains(callback);
         if (!exists) return;
         var kvp = renderCallbacks.FirstOrDefault(k => k.Value == callback);
         renderCallbacks.Remove(kvp.Key);
     }
     finally { Monitor.Exit(syncRoot); }
 }
Exemple #37
0
        private void UseFormattedText(RenderCallback renderCallback)
        {
            Brush textBrush = new SolidColorBrush(ForeColour);
            FontDescription fontDescription = Font.GetFontDescription();
            FormattedText formattedText = new FormattedText(Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                                                            fontDescription.Typeface, fontDescription.Size, textBrush);
            formattedText.SetTextDecorations(fontDescription.TextDecorations);
            if (Width != null)
                formattedText.MaxTextWidth = Width.Value;
            if (Height != null)
                formattedText.MaxTextHeight = Height.Value;
            if (!Multiline)
                formattedText.MaxLineCount = 1;
            formattedText.Trimming = TextTrimming.None;
            //formattedText.TextAlignment = HorizontalTextAlignment;

            renderCallback(formattedText);
        }
Exemple #38
0
            /// <summary>
            /// Private rendering loop
            /// </summary>
            public void Run(RenderCallback renderCallback)
            {
                // Show the form
                _form.Show();

                // Main rendering loop);
                while (_isAlive)
                {
                    if (UseCustomDoEvents)
                    {
                        // Previous code not compatible with Application.AddMessageFilter but faster then DoEvents
                        Win32Native.NativeMessage msg;
                        while (Win32Native.PeekMessage(out msg, _windowHandle, 0, 0, 0) != 0)
                        {
                            if (Win32Native.GetMessage(out msg, _windowHandle, 0, 0) == -1)
                            {
                                throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture,
                                    "An error happened in rendering loop while processing windows messages. Error: {0}",
                                    Marshal.GetLastWin32Error()));
                            }

                            Win32Native.TranslateMessage(ref msg);
                            Win32Native.DispatchMessage(ref msg);
                        }
                    }
                    else
                    {
                        // Revert back to Application.DoEvents in order to support Application.AddMessageFilter
                        // Seems that DoEvents is compatible with Mono unlike Application.Run that was not running
                        // correctly.
                        Application.DoEvents();
                    }
                    if (_isAlive)
                        renderCallback();
                }

                _form.Disposed -= _form_Disposed;

                MessageFilterHook.RemoveMessageFilter(_windowHandle, this);
            }
Exemple #39
0
 /// <summary>
 /// Runs the specified main loop for the specified windows form.
 /// </summary>
 /// <param name="form">The form.</param>
 /// <param name="renderCallback">The rendering callback.</param>
 public static void Run(Control form, RenderCallback renderCallback)
 {
     var proxyWindow = new ProxyNativeWindow(form);
     proxyWindow.Run(renderCallback);
 }
        /// <summary>
        /// Runs the specified main loop for the specified windows form.
        /// </summary>
        /// <param name="form">The form.</param>
        /// <param name="renderCallback">The rendering callback.</param>
        /// <param name="useApplicationDoEvents">if set to <c>true</c> indicating whether the render loop should use the default <see cref="Application.DoEvents"/> instead of a custom window message loop lightweight for GC. Default is false.</param>
        /// <exception cref="System.ArgumentNullException">form
        /// or
        /// renderCallback</exception>
        public static void Run(Control form, RenderCallback renderCallback, bool useApplicationDoEvents = false)
        {
            if(form == null) throw new ArgumentNullException("form");
            if(renderCallback == null) throw new ArgumentNullException("renderCallback");

            form.Show();
            using (var renderLoop = new RenderLoop(form) { UseApplicationDoEvents = useApplicationDoEvents })
            {
                while(renderLoop.NextFrame())
                {
                    renderCallback();
                }
            }
        }
 /// <summary>
 /// Runs the specified main loop in the specified context.
 /// </summary>
 public static void Run(ApplicationContext context, RenderCallback renderCallback)
 {
     Run(context.MainForm, renderCallback);
 }