Ejemplo n.º 1
0
        public virtual void Draw(SpriteBatch spriteBatch)
        {
            if (!Enabled || !Visible)
            {
                return;
            }
            UpdateTransform();
            if (DrawBounds && Size != Vector2.Zero)
            {
                spriteBatch.Draw(Engine.Texture1x1, Bounds, null, Color, 0f, Vector2.Zero, SpriteEffect, LayerDepth);
                //spriteBatch.Draw(Engine.Texture1x1, DrawPosition, sourceRect.ToRectangle(), Color, 0f, Origin, Scale, SpriteEffect, LayerDepth);
            }

            if (HasDecorations)
            {
                foreach (var d in decorations)
                {
                    if (d.Visible)
                    {
                        d.Draw(spriteBatch);
                    }
                    ;
                }
            }

            if (UIManager.DrawDebug)
            {
                PRect rect = new PRect(Bounds, 1);
                rect.Color = DebugColor;
                rect.Draw();
            }
        }
Ejemplo n.º 2
0
        public void UpdateGraphLine()
        {
            SetGraphVisible(true);

            PVector2 dGraph01Size = DGraph01Size;
            PRect    dGraphRect   = DGraphRect;

            //Update Inside lines
            for (int graphLineI = 0; graphLineI < graphLines.Length; ++graphLineI)
            {
                float motionValue     = GetLineMotionValue(graphLineI);
                float nextMotionValue = GetLineMotionValue(graphLineI + 1);

                Line line = graphLines[graphLineI];
                line.X1 = dGraphRect.xMin + graphLineI * dGraph01Size.x / GraphResolution;
                line.X2 = dGraphRect.xMin + (graphLineI + 1) * dGraph01Size.x / GraphResolution;
                line.Y1 = dGraphRect.yMax - motionValue * dGraph01Size.y;
                line.Y2 = dGraphRect.yMax - nextMotionValue * dGraph01Size.y;

                float GetLineMotionValue(int index)
                {
                    float linearValue = (float)index / graphLines.Length;

                    return(EditingMotionData.GetMotionValue(linearValue));
                }
            }

            //Update Outside lines
            float outsideLeftY  = NormalToDisplayY(EditingMotionData.GetMotionValue(0f));
            float outsideRightY = NormalToDisplayY(EditingMotionData.GetMotionValue(1f));

            outsideLines[0].SetLinePosition(new Vector2(Mathf.Min(dGraphRect.xMin, 0f), outsideLeftY), new Vector2(dGraphRect.xMin, outsideLeftY));
            outsideLines[1].SetLinePosition(new Vector2(dGraphRect.xMax, outsideRightY), new Vector2(Mathf.Max(dGraphRect.xMax, (float)GraphContext.ActualWidth), outsideRightY));
        }
Ejemplo n.º 3
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);

            RectangleF clip;
            RectangleF destRect   = Bounds;
            Rectangle? sourceRect = null;

            if (HasClip(out clip))
            {
                RectangleF inter = RectangleF.Empty;
                inter.Left   = Math.Max(clip.Left, destRect.Left);
                inter.Top    = Math.Max(clip.Top, destRect.Top);
                inter.Right  = Math.Min(clip.Right, destRect.Right);
                inter.Bottom = Math.Min(clip.Bottom, destRect.Bottom);

                int leftClip      = (int)(inter.Left - DrawPosition.X);
                int rightClip     = (int)(inter.Right - (DrawPosition.X + Width));
                int topClip       = (int)(inter.Top - DrawPosition.Y);
                int bottomClip    = (int)(inter.Bottom - (DrawPosition.Y + Height));
                int clippedWidth  = rightClip - leftClip;
                int clippedHeight = bottomClip - topClip;

                Rectangle source = Rectangle.Empty;
                source.X      = leftClip;
                source.Y      = topClip;
                source.Width  = (int)Width + clippedWidth;
                source.Height = (int)Height + clippedHeight;
                sourceRect    = source;

                destRect.X     += leftClip;
                destRect.Y     += topClip;
                destRect.Width  = Math.Max(destRect.Width + clippedWidth, 0);
                destRect.Height = Math.Max(destRect.Height + clippedHeight, 0);

                if (UIManager.DrawDebug)
                {
                    PrimitiveBatch.Begin();
                    PRect rect = new PRect(clip, 1);
                    rect.Color = Color.Yellow;
                    rect.Draw();
                    PrimitiveBatch.End();

                    PrimitiveBatch.Begin();
                    rect       = new PRect(inter, 1);
                    rect.Color = Color.Magenta;
                    rect.Draw();
                    PrimitiveBatch.End();
                }

                //int rC = (int)(  inter.Right - ( DrawPosition.X + Width ) - location.X + location.X);
                //int lC = (int)( location.X + inter.Left - DrawPosition.X - location.X );
                //int bC = (int)( location.Y + inter.Bottom - ( DrawPosition.Y + Height ) - location.Y );
                //int tC = (int)( location.Y + inter.Top - DrawPosition.Y - location.Y );
            }

            spriteBatch.Draw(texture, destRect, sourceRect, Color, 0f, Vector2.Zero, SpriteEffect, LayerDepth);
        }
Ejemplo n.º 4
0
        public void UpdatePlaybackRadar(float time, float maxOverTime)
        {
            PlaybackRadar.Height = PreviewContext.ActualHeight;

            PRect dGraphRect = DGraphRect;
            float x          = dGraphRect.xMin + dGraphRect.Width * time;
            float overTime   = time > 0f ? Mathf.Max(0f, time - 1f) : -time;

            PlaybackRadar.Opacity = 1f - overTime / maxOverTime;
            Canvas.SetLeft(PlaybackRadar, x - PlaybackRadar.Width);
        }
Ejemplo n.º 5
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);

            RectangleF clip;
            RectangleF destRect = Bounds;
            Rectangle? sourceRect = null;

            if (HasClip(out clip))
            {
                RectangleF inter = RectangleF.Empty;
                inter.Left = Math.Max(clip.Left, destRect.Left);
                inter.Top = Math.Max(clip.Top, destRect.Top);
                inter.Right = Math.Min(clip.Right, destRect.Right);
                inter.Bottom = Math.Min(clip.Bottom, destRect.Bottom);

                float leftClip = inter.Left - DrawPosition.X;
                float rightClip = inter.Right - (DrawPosition.X + Width);
                float topClip = inter.Top - DrawPosition.Y;
                float bottomClip = inter.Bottom - (DrawPosition.Y + Height);
                float clippedWidth = rightClip - leftClip;
                float clippedHeight = bottomClip - topClip;

                Rectangle source = Rectangle.Empty;
                source.X = (int)leftClip;
                source.Y = (int)topClip;
                source.Width = (int)(Width + clippedWidth);
                source.Height = (int)(Height + clippedHeight);
                sourceRect = source;

                destRect.X += leftClip;
                destRect.Y += topClip;
                destRect.Width = Math.Max(destRect.Width + clippedWidth, 0);
                destRect.Height = Math.Max(destRect.Height + clippedHeight, 0);

                if (UIManager.DrawDebug)
                {
                    PRect rect = new PRect(clip, 1);
                    rect.Color = Color.Yellow;
                    rect.Draw();

                    rect = new PRect(inter, 1);
                    rect.Color = Color.Magenta;
                    rect.Draw();
                }

                //int rC = (int)(  inter.Right - ( DrawPosition.X + Width ) - location.X + location.X);
                //int lC = (int)( location.X + inter.Left - DrawPosition.X - location.X );
                //int bC = (int)( location.Y + inter.Bottom - ( DrawPosition.Y + Height ) - location.Y );
                //int tC = (int)( location.Y + inter.Top - DrawPosition.Y - location.Y );
            }

            spriteBatch.Draw(texture, destRect, sourceRect, Color, 0f, Vector2.Zero, SpriteEffect, LayerDepth);
        }
Ejemplo n.º 6
0
        public override void Initialize()
        {
            PRect n1 = new PRect(new RectangleFx(1, 0, 100, 80));

            n1.Brush = Color.Red;
            //PNode n2 = PPath.CreateRectangle(0, 0, 100, 80);;

            Canvas.Layer.AddChild(n1);
            //Canvas.Layer.AddChild(n2);

            //n2.ScaleBy(2.0f);
            //n2.RotateBy(90);
            //n2.Scale = 2.0f;
            //n2.Scale = 1.0f;
            //n2.ScaleBy(0.5f);
            //n2.Brush = Color.Red;

            n1.OffsetBy(100, 0);
            //n2.OffsetBy(100, 0);
        }
Ejemplo n.º 7
0
        public virtual void Draw(SpriteBatch spriteBatch)
        {
            UpdateTransform();
            if (DrawBounds && Size != Vector2.Zero)
            {
                spriteBatch.Draw(Engine.Texture1x1, Bounds, null, Color, 0f, Vector2.Zero, SpriteEffect, LayerDepth);
            }

            if (HasDecorations)
            {
                decorations.ForEach(d => d.Draw(spriteBatch));
            }

            if (UIManager.DrawDebug)
            {
                PrimitiveBatch.Begin();
                PRect rect = new PRect(Bounds, 3);
                rect.Color = DebugColor;
                rect.Draw();
                PrimitiveBatch.End();
            }
        }
Ejemplo n.º 8
0
        // Special case of drawimage intended only to draw text for overlay in OBS
        private void DrawOBS(Graphics g)
        {
            // Draw phrases
            foreach (PhraseRect PRect in PhraseRects)
            {
                g.FillRectangle(new SolidBrush(Color.FromArgb(180, 0, 0, 0)), PRect.Location); // Background

                string TextToRender  = PRect.atrans.rawText;
                Brush  ColorToRender = Brushes.Gray;
                if (PRect.atrans.isDone)
                {
                    // Draw translated text if available
                    TextToRender  = PRect.atrans.translatedText;
                    ColorToRender = Brushes.White;
                }

                // Draw text

                // Fit font to bounding box
                //Font LargeFont = GetAdjustedFont(g, TextToRender, DefaultFont, PRect.Location, 32, 6, true);
                Font LargeFont = PRect.FitFont(g, DefaultFont, 32, 6);

                // Center-justify text
                // TODO: Currently disabled to enable wordwrap, fix this
                int       JustifySpace     = (int)(PRect.Location.Width - g.MeasureString(TextToRender, LargeFont).Width) / 2;
                Rectangle AdjustedPosition = new Rectangle(
                    PRect.Location.Left + JustifySpace, PRect.Location.Top,
                    PRect.Location.Width, PRect.Location.Height);

                // Draw translated text
                g.DrawString(
                    TextToRender,
                    LargeFont,
                    ColorToRender,
                    PRect.Location);
            }
        }
Ejemplo n.º 9
0
        private void UpdateGrid()
        {
            PRect    graphRect   = DGraphRect;
            PVector2 graph01Size = DGraph01Size;

            for (int i = 0; i < gridVerticals.Length; ++i)
            {
                Line  line = gridVerticals[i];
                float x    = graphRect.xMin + ((i - (GridHorizontalCount / 3)) * graph01Size.x / (GridVerticalCount / 4 - 1));
                line.X1     =
                    line.X2 = x;
                line.Y1     = 0d;
                line.Y2     = ActualHeight;
            }
            for (int i = 0; i < gridHorizontals.Length; ++i)
            {
                Line  line = gridHorizontals[i];
                float y    = graphRect.yMax - ((i - (GridHorizontalCount / 3)) * graph01Size.y / (GridHorizontalCount / 4 - 1));
                line.Y1     =
                    line.Y2 = y;
                line.X1     = 0d;
                line.X2     = ActualWidth;
            }
        }
Ejemplo n.º 10
0
        public UICheckBox(string checkmarkResource = "graphics/checkmark")
        {
            Size          = new Vector2(20);
            Alpha         = defaultAlpha;
            DrawBounds    = true;
            AbsorbPointer = true;
            Color         = Color.Black;

            rect       = new PRect(boundingRect, 3);
            rect.Color = Color.Black;

            checkmark       = new UIImage(checkmarkResource);
            checkmark.Color = Color.Green;
            AddDecoration(checkmark);

            //innerRect = new PRect(boundingRect, 4);
            //innerRect.Color = Color.Black;
            //innerRect.Alpha = 30;

            InputReleased += UICheckBox_InputReleased;
            InputDown     += UICheckBox_InputDown;
            InputEnter    += UICheckBox_InputEnter;
            InputLeave    += UICheckBox_InputLeave;
        }
Ejemplo n.º 11
0
        // Draw all the graphics on top of the image
        // This is generalized so it can be used either by onpaint or by the image save routine
        private void DrawImage(Graphics g)
        {
            // Draw identified words
            if (OCRResult != null && OCRResult.isDone)
            {
                foreach (OCRBox ocr in OCRResult.smallBoxes)
                {
                    g.FillPolygon(new SolidBrush(Color.FromArgb(100, 128, 50, 128)), ocr.points);
                    g.DrawPolygon(new Pen(Color.Purple, 1.0f), ocr.points);
                }
            }

            // Draw user bounding box
            if (Marking)
            {
                Rectangle Rect = MouseStart.RectTo(MouseEnd);
                switch (BoundingBoxState)
                {
                case BoundingState.Normal:
                    g.DrawRectangle(Pens.White, Rect);
                    break;

                case BoundingState.RectsFound:
                    g.DrawRectangle(Pens.Green, Rect);
                    break;

                case BoundingState.TooSmall:
                    g.DrawRectangle(Pens.Red, Rect);
                    break;
                }
                // Draw a black rectangle around the others to help with contrast
                Rect.Inflate(1, 1);
                g.DrawRectangle(Pens.Black, Rect);
            }


            // Draw phrases
            foreach (PhraseRect PRect in PhraseRects)
            {
                //Rectangle DisplayRect = QuantizeRect(PRect.Location, 8, 8); // This was quantizing the display location of the box, but this is a bad idea as it turns out and may not ever be practical

                g.FillRectangle(new SolidBrush(Color.FromArgb(200, 0, 0, 0)), PRect.Location); // Background

                // Pick color for outline
                Pen BoxColor = Pens.Green;
                // The order of these statements is critical, leave them as-is
                if (PRect.Hovered)
                {
                    BoxColor = Pens.LightGreen;
                }
                if (PRect.Selected)
                {
                    BoxColor = Pens.LightBlue;
                }
                if (PRect.Clicked)
                {
                    BoxColor = Pens.DarkBlue;
                }
                BoxColor = (Pen)BoxColor.Clone(); // Clone the pen prototype so we can modify it if need be
                // If the box is an intersect box, draw it dashed
                if (PRect.mode == PhraseRectMode.intersects)
                {
                    BoxColor.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                    //BoxColor.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
                    //BoxColor.DashPattern = new float[] { 5, 2, 15, 4 };
                }
                g.DrawRectangle(BoxColor, PRect.Location); // Draw outline

                string TextToRender  = PRect.atrans.rawText;
                Brush  ColorToRender = Brushes.Gray;
                if (PRect.atrans.isDone)
                {
                    // Draw translated text if available
                    TextToRender  = PRect.atrans.translatedText;
                    ColorToRender = Brushes.White;
                }

                // Draw text

                // Fit font to bounding box
                //Font LargeFont = GetAdjustedFont(g, TextToRender, DefaultFont, PRect.Location, 32, 6, true);
                Font LargeFont = PRect.FitFont(g, DefaultFont, 32, 6);

                // Center-justify text
                // TODO: Currently disabled to enable wordwrap, fix this
                int       JustifySpace     = (int)(PRect.Location.Width - g.MeasureString(TextToRender, LargeFont).Width) / 2;
                Rectangle AdjustedPosition = new Rectangle(
                    PRect.Location.Left + JustifySpace, PRect.Location.Top,
                    PRect.Location.Width, PRect.Location.Height);

                // Draw translated text
                g.DrawString(
                    TextToRender,
                    LargeFont,
                    ColorToRender,
                    PRect.Location);



                if (Properties.Settings.Default.displayTimes)
                {
                    // Draw the translation time
                    Font  BoldFont   = new Font(DefaultFont, FontStyle.Bold);
                    SizeF TimeLength = g.MeasureString(PRect.atrans.timeStamp, BoldFont);

                    g.DrawString(PRect.atrans.timeStamp,
                                 BoldFont,
                                 Brushes.Gray,
                                 new Point(PRect.Location.Right - (int)TimeLength.Width, PRect.Location.Bottom - (int)TimeLength.Height));
                }

                // Write name of translation service
                Font  SvcFont   = new Font(FontFamily.GenericSansSerif, 8.0f);
                SizeF SvcLength = g.MeasureString(PRect.atrans.name, SvcFont);
                g.DrawString(PRect.atrans.name, SvcFont, Brushes.Gray,
                             new Point(PRect.Location.Right - (int)SvcLength.Width, PRect.Location.Top));
            }

            if (OCRResult != null)
            {
                // Write name of OCR service
                Font  OCRFont   = new Font(FontFamily.GenericSansSerif, 8.0f);
                SizeF OCRLength = g.MeasureString(OCRResult.name, OCRFont);
                g.DrawString(OCRResult.name, OCRFont, Brushes.Gray,
                             new Point((int)(g.ClipBounds.Width - OCRLength.Width), 0));
            }
        }