Пример #1
0
        void IView.SetViewModel(IViewModel viewModel)
        {
            this.viewModel = viewModel;

            this.graphicsResources = new GraphicsResources(
                viewModel,
                (fontData) => new LJD.Font(fontData.Name ?? "monaco",
                                           (float)NSFont.SystemFontSizeForControlSize(NSControlSize.Small)),
                textFormat: null,
                images: (
                    error: new LJD.Image(NSImage.ImageNamed("ErrorLogSeverity.png")),
                    warn: new LJD.Image(NSImage.ImageNamed("WarnLogSeverity.png")),
                    bookmark: new LJD.Image(NSImage.ImageNamed("Bookmark.png")),
                    focusedMark: new LJD.Image(NSImage.ImageNamed("FocusedMsg.png"))
                    ),
                graphicsForMeasurmentFactory: () => graphicsForMeasurment
                );
            this.viewDrawing = new ViewDrawing(viewModel,
                                               graphicsResources,
                                               1f,
                                               () => 0,
                                               () => viewWidth
                                               );
            this.drawingPerfCounters       = new Profiling.Counters(viewModel.Trace, "drawing");
            this.graphicsCounters          = LJD.Graphics.CreateCounters(drawingPerfCounters);
            this.controlPaintTimeCounter   = this.drawingPerfCounters.AddCounter("paint", unit: "ms");
            this.controlPaintWidthCounter  = this.drawingPerfCounters.AddCounter("width", unit: "pixel");
            this.controlPaintHeightCounter = this.drawingPerfCounters.AddCounter("height", unit: "pixel");
            var viewUpdater = Updaters.Create(
                () => viewModel.ViewLines,
                () => viewModel.FocusedMessageMark,
                (_1, _2) => { this.InnerView.NeedsDisplay = true; }
                );
            var emptyViewMessageUpdater = Updaters.Create(
                () => viewModel.EmptyViewMessage,
                value => {
                drawDropMessage         = value;
                DragDropIconView.Hidden = value == null;
            }
                );
            var vScrollUpdater = Updaters.Create(
                () => viewModel.VerticalScrollerPosition,
                value => {
                VertScroller.Enabled        = value.HasValue;
                VertScroller.KnobProportion = 0.0001f;
                VertScroller.DoubleValue    = value.GetValueOrDefault();
            }
                );

            viewModel.ChangeNotification.CreateSubscription(() => {
                viewUpdater();
                emptyViewMessageUpdater();
                vScrollUpdater();
            });
        }
Пример #2
0
        public BasicMaterial(GraphicsDevice graphics)
        {
            effect = GraphicsResources <BasicEffect> .GetInstance(graphics, typeof(BasicMaterial));

            pass           = effect.CurrentTechnique.Passes[0];
            GraphicsDevice = graphics;
        }
Пример #3
0
        public AlphaTestMaterial(GraphicsDevice graphics)
        {
            GraphicsDevice = graphics;
            effect         = GraphicsResources <AlphaTestEffect> .GetInstance(graphics, typeof(AlphaTestMaterial));

            effect.ReferenceAlpha = Constants.ReferenceAlpha;
        }
Пример #4
0
        public TextureMaterial(GraphicsDevice graphics)
        {
            effect = GraphicsResources <BasicEffect> .GetInstance(graphics, typeof(TextureMaterial));

            effect.LightingEnabled = false;
            pass           = effect.CurrentTechnique.Passes[0];
            GraphicsDevice = graphics;
        }
Пример #5
0
 /// <summary>
 /// The main constructor for the class.
 /// </summary>
 public FrameRate(GraphicsDevice graphics, SpriteFont font)
 {
     this.Font            = font;
     this.GraphicsDevice  = graphics;
     this.UpdateFrequency = TimeSpan.FromSeconds(1);
     this.Color           = new Color(255, 255, 0, 255);
     this.Visible         = true;
     this.Scale           = 1;
     this.spriteBatch     = GraphicsResources <SpriteBatch> .GetInstance(GraphicsDevice);
 }
Пример #6
0
        public void Draw(float elapsedTime)
        {
            if (Font == null)
            {
                return;
            }

            SpriteBatch spriteBatch = GraphicsResources <SpriteBatch> .GetInstance(GraphicsDevice);

            spriteBatch.Begin();

            const int Border = 8;

            // Compute number of lines to be rendered
            int height    = (int)(FontSize + LineSpacing);
            int lineCount = messages.Count + 1;

            if (lineCount > MaxLines)
            {
                lineCount = MaxLines;
            }

            // Use Graphics.Clear to draw a background quad
            int y = GraphicsDevice.PresentationParameters.BackBufferHeight - lineCount * height - Border;

            // Draw text
            float fontScale = 1.0f * FontSize / (Font.MeasureString("A").Y - 10);
            int   i         = messages.Count - (lineCount - 1);

            if (i < 0)
            {
                i = 0;
            }

            for (; i < messages.Count; ++i)
            {
                spriteBatch.DrawString(
                    Font, messages[i], new Vector2(Border + 2, y), ForegroundColor, 0,
                    Vector2.Zero, fontScale, SpriteEffects.None, 0);

                y += height;
            }

            // Update text cursor
            currentBlinkTime += elapsedTime;

            if (currentBlinkTime > CursorBlinkInterval)
            {
                currentBlinkTime = -CursorBlinkInterval;
            }

            // Draw last line and text cursor
            // FIXME: Timing not working when game is paused
            if (currentBlinkTime < 0)
            {
                spriteBatch.DrawString(
                    Font, lastLine, new Vector2(Border + 2, y), ForegroundColor, 0,
                    Vector2.Zero, fontScale, SpriteEffects.None, 0);
            }
            else
            {
                spriteBatch.DrawString(
                    Font, lastLine + CursorText, new Vector2(Border + 2, y), ForegroundColor, 0,
                    Vector2.Zero, fontScale, SpriteEffects.None, 0);
            }

            spriteBatch.End();
        }
Пример #7
0
 public DualTextureMaterial(GraphicsDevice graphics)
 {
     GraphicsDevice = graphics;
     effect         = GraphicsResources <DualTextureEffect> .GetInstance(graphics, typeof(DualTextureMaterial));
 }
Пример #8
0
 public SkinnedMaterial(GraphicsDevice graphics)
 {
     GraphicsDevice = graphics;
     effect         = GraphicsResources <SkinnedEffect> .GetInstance(graphics, typeof(SkinnedMaterial));
 }
Пример #9
0
        private static SpriteBatch PrepareSprite(GraphicsDevice graphics, Effect effect)
        {
            SetViewport(effect as IEffectMatrices, graphics.Viewport.Bounds);

            return(GraphicsResources <SpriteBatch> .GetInstance(graphics));
        }
Пример #10
0
        public static void DrawModel(RenderMesh modelToRender, int width, int height, GraphicsResources graphicsResources, int renderModeIndex)
        {
            if (!graphicsResources.objModelShader.LinkStatusIsOk)
            {
                return;
            }

            var camera = new Camera()
            {
                RenderWidth   = width,
                RenderHeight  = height,
                NearClipPlane = 0.01f,
            };

            camera.FrameBoundingSphere(modelToRender.BoundingSphere);

            graphicsResources.objModelShader.UseProgram();
            graphicsResources.objModelShader.SetMatrix4x4("mvpMatrix", camera.MvpMatrix);
            graphicsResources.objModelShader.SetInt("attributeIndex", renderModeIndex);

            GL.Clear(ClearBufferMask.DepthBufferBit);

            SFGenericModel.RenderState.GLRenderSettings.SetFaceCulling(new SFGenericModel.RenderState.FaceCullingSettings(true, CullFaceMode.Back));
            SFGenericModel.RenderState.GLRenderSettings.SetDepthTesting(new SFGenericModel.RenderState.DepthTestSettings(true, true, DepthFunction.Lequal));

            modelToRender.Draw(graphicsResources.objModelShader);
        }
Пример #11
0
 public SpriteBatchRenderer(GraphicsDevice graphics)
     : base(graphics)
 {
     spriteBatch = GraphicsResources <SpriteBatch> .GetInstance(graphics);
 }
Пример #12
0
        void IView.SetViewModel(IViewModel viewModel)
        {
            this.viewModel = viewModel;

            var prototypeStringFormat = (StringFormat)StringFormat.GenericDefault.Clone();

            prototypeStringFormat.SetTabStops(0, new float[] { 20 });
            prototypeStringFormat.FormatFlags |=
                StringFormatFlags.MeasureTrailingSpaces |
                StringFormatFlags.NoFontFallback;                 // this is to treat \0002 and \0003 as regular characters

            graphicsResources = new GraphicsResources(viewModel,
                                                      fontData => new LJD.Font(GetFontFamily(fontData.Name).Name, ToFontEmSize(fontData.Size)),
                                                      textFormat: new LJD.StringFormat(prototypeStringFormat),
                                                      (error: new LJD.Image(Properties.Resources.ErrorLogSeverity),
                                                       warn: new LJD.Image(Properties.Resources.WarnLogSeverity),
                                                       bookmark: new LJD.Image(Properties.Resources.Bookmark),
                                                       focusedMark: new LJD.Image(Properties.Resources.FocusedMsg)),
                                                      () => new LJD.Graphics(this.CreateGraphics(), ownsGraphics: true)
                                                      );

            viewDrawing = new ViewDrawing(
                viewModel,
                graphicsResources,
                dpiScale: UIUtils.Dpi.Scale(1f),
                scrollPosXSelector: () => scrollPosXCache,
                viewWidthSelector: () => viewWidthCache
                );

            viewWidthCache = this.ClientRectangle.Width;

            var viewUpdater = Updaters.Create(
                () => viewModel.ViewLines,
                () => viewModel.FocusedMessageMark,
                (_1, _2) =>
            {
                Invalidate();
            }
                );
            var vScrollerUpdater = Updaters.Create(
                () => viewModel.VerticalScrollerPosition,
                value =>
            {
                scrollBarsInfo.scrollSize.Height = value != null ? ScrollBarsInfo.virtualVScrollSize : 0;
                SetScrollPos(posY: (int)(value.GetValueOrDefault() * (double)(ScrollBarsInfo.virtualVScrollSize - ClientRectangle.Height + 1)));
            }
                );
            var emptyViewMessageUpdater = Updaters.Create(
                () => viewModel.EmptyViewMessage,
                value =>
            {
                if (emptyMessagesCollectionMessage == null)
                {
                    Controls.Add(emptyMessagesCollectionMessage = new EmptyMessagesCollectionMessage {
                        Dock = DockStyle.Fill
                    });
                }
                emptyMessagesCollectionMessage.Visible = value != null;
                emptyMessagesCollectionMessage.SetMessage(value ?? "");
            }
                );

            viewModel.ChangeNotification.CreateSubscription(() =>
            {
                viewUpdater();
                vScrollerUpdater();
                emptyViewMessageUpdater();
            });
        }
Пример #13
0
 public EnvironmentMapMaterial(GraphicsDevice graphics)
 {
     GraphicsDevice = graphics;
     effect         = GraphicsResources <EnvironmentMapEffect> .GetInstance(graphics, typeof(EnvironmentMapMaterial));
 }
Пример #14
0
        public static void Draw(this SpriteBatch spriteBatch, Rectangle rect, Color color)
        {
            var texture = GraphicsResources <BlankTexture> .GetInstance(spriteBatch.GraphicsDevice);

            spriteBatch.Draw(texture.Texture, rect, color);
        }
Пример #15
0
        public static void Draw(this SpriteBatch spriteBatch, Vector2 position, Vector2 scale, float rotation, Color color)
        {
            var texture = GraphicsResources <BlankTexture> .GetInstance(spriteBatch.GraphicsDevice);

            spriteBatch.Draw(texture.Texture, position, null, color, rotation, Vector2.Zero, scale, SpriteEffects.None, 0);
        }