Jump to content

xod

Members
  • Posts

    632
  • Joined

  • Last visited

  • Days Won

    20

Posts posted by xod

  1. Spaced / Outlined text it only supports 32 characters.

     

    Spoiler
    
    // Name: SpacedOutlinedText
    // Submenu: Text Formations
    // Author: xod
    // Title: Spaced / Outlined Text
    // Version: 1.0
    // Desc:
    // Keywords:
    // URL:
    
    #region UICode
    MultiLineTextboxControl Amount1 = "TEST"; // [1,255]
    FontFamily Amount2 = new FontFamily("Arial"); // Font
    CheckboxControl Amount3 = false; // [0,1] Bold
    CheckboxControl Amount4 = false; // [0,1] Italic
    IntSliderControl Amount5 = 150; // [10,400] Size
    ColorWheelControl Amount6 = ColorBgra.FromBgr(100,255,255); // [SecondaryColor] Fill color
    PanSliderControl Amount7 = Pair.Create(0.000,0.000); // Offset space X, Y
    ColorWheelControl Amount8 = ColorBgra.FromBgr(0,100,0); // [PrimaryColor] Outline color
    IntSliderControl Amount9 = 3; // [0,100] Outline depth
    CheckboxControl Amount10 = false; // [0,1] Outline over text
    PanSliderControl Amount11 = Pair.Create(0.000,0.000); // Location
    #endregion
    
    void Render(Surface dst, Surface src, Rectangle rect)
    {
        Rectangle sel = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
        dst.CopySurface(src,rect.Location,rect);
    
        int offsetX = (int)Math.Round((Amount7.First * (sel.Right - sel.Left) / 2));
        int offsetY = (int)Math.Round((Amount7.Second * (sel.Bottom - sel.Top) / 2));
        byte opacity = 255;
        string measureString = Amount1;
        int numChars = measureString.Length;
        Color outlineColor = Amount8;
        float outlineSize = (float)Amount9;
        
        FontStyle myStyle = FontStyle.Regular;
        if (Amount3) myStyle |= FontStyle.Bold;
        if (Amount4) myStyle |= FontStyle.Italic;
    
        CharacterRange[] characterRanges = new CharacterRange[numChars];
        for (int i = 0; i < numChars; i++) characterRanges[i] = new CharacterRange(i, 1);
    
        Region[] stringRegions = new Region[numChars];
        StringFormat stringFormat = new StringFormat();
        stringFormat.FormatFlags = StringFormatFlags.NoClip;
        stringFormat.SetMeasurableCharacterRanges(characterRanges);
        stringFormat.Alignment = StringAlignment.Center;
    
        using(SolidBrush solidBrush = new SolidBrush(Color.FromArgb(opacity, Amount6)))
        using (GraphicsPath path = new GraphicsPath())
        using (Pen outlinePen = new Pen(Color.FromArgb(opacity, outlineColor), outlineSize))
        {
            Graphics g = new RenderArgs(dst).Graphics;
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.TextRenderingHint = TextRenderingHint.AntiAlias;
            g.Clip = new Region(rect);
    
            Font stringFont;
            try
            {
                stringFont = new Font(Amount2.Name, Amount5, myStyle);
            }
            catch
            {
                stringFont = new Font("Arial", Amount5);
            }
    
            SizeF size = g.MeasureString(measureString, stringFont);
            RectangleF layoutRect = new RectangleF(0.0f, 0.0f, size.Width, size.Height);
    
            int col = (int)Math.Round(((Amount11.First + 1) / 2) * (sel.Right - sel.Left) + sel.Left - size.Width / 2);
            int row = (int)Math.Round(((Amount11.Second + 1) / 2) * (sel.Bottom - sel.Top) + sel.Top - size.Height / 2);
    
            stringRegions = g.MeasureCharacterRanges(measureString, stringFont, layoutRect, stringFormat);
            FontFamily myFont = new FontFamily(Amount2.Name);
            for (int index = 0; index < numChars; index++)
            {
                Region region = stringRegions[index] as Region;
                RectangleF rectChr = region.GetBounds(g);
                rectChr.Offset(col + offsetX * index, row + offsetY * index);
                g.DrawString(measureString.Substring(index, 1), stringFont, solidBrush, rectChr, stringFormat);
    
                outlinePen.LineJoin = LineJoin.Round;
                path.AddString(measureString.Substring(index, 1), myFont, (int)myStyle, g.DpiY * Amount5 / 72, rectChr, stringFormat);
            }
            if (Amount9 > 0)
            {
                g.DrawPath(outlinePen, path);
            }
            if (!Amount10)
            {
                g.FillPath(solidBrush, path);
            }
            g.Dispose();
        }
    }

     

     

  2. Added new gradient facilities.

     

    Spoiler
    
    // Name: Outlined / Gradient text
    // Submenu: Text Formations
    // Author: xod & BoltBait
    // Title: Outlined / Gradient text
    // Version: 1.0
    // Desc: Draws outlined, gradient filled text
    // Keywords: text|gradient|outline
    // URL:
    #region UICode
    MultiLineTextboxControl Amount1 = "TEST"; // [1,32767] Text
    FontFamily Amount2 = new FontFamily("Impact"); // Font
    IntSliderControl Amount3 = 140; // [2,400] Font size
    IntSliderControl Amount4 = 8; // [0,100] Outline size
    ColorWheelControl Amount5 = ColorBgra.FromBgr(0,0,255); // [Red] Outline color
    ColorWheelControl Amount6 = ColorBgra.FromBgr(139,0,0); // [DarkBlue] Fill color
    ListBoxControl Amount7 = 5; // Fill Type|Solid Fill|Vertical Gradient|Horizontal Gradient|Diagonal Gradient|Reverse Diagonal Gradient|Vertical Gradient Reflected|Horizontal Gradient Reflected
    ColorWheelControl Amount8 = ColorBgra.FromBgr(255,255,0); // [Cyan] {!Amount7} Secondary Fill Color
    DoubleSliderControl Amount9 = 0.5; // [0,1] {!Amount7} Start position
    DoubleSliderControl Amount10 = 1; // [0,1] {!Amount7} Intensity
    PanSliderControl Amount11 = Pair.Create(0.000,0.000); // Location
    #endregion
    
    void Render(Surface dst, Surface src, Rectangle rect)
    {
        Rectangle sel = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
        dst.CopySurface(src,rect.Location,rect);
    
        int adrX = (int)Math.Round(((Amount11.First + 1) / 2) * (sel.Right - sel.Left));
        int adrY = (int)Math.Round(((Amount11.Second + 1) / 2) * (sel.Bottom - sel.Top));
    
        String text = Amount1;
        FontFamily font = Amount2;
        int txtSize = Amount3;
        Color fontColor = Amount6;
        int outlineSize = Amount4;
        Color outlineColor = Amount5;
        byte opacity = 255;
        if (Amount4 == 0) opacity = 0; //no outline
        float startGradient = (float) Amount9;
        float intensity = (float) Amount10;
    
        Graphics g = new RenderArgs(dst).Graphics;
        g.SmoothingMode = SmoothingMode.AntiAlias;
        g.TextRenderingHint = TextRenderingHint.AntiAlias;
    
        StringFormat format = new StringFormat();
        format.Alignment = StringAlignment.Center;
        format.LineAlignment = StringAlignment.Center;
    
        ColorBgra FillColor1 = Amount6;
        ColorBgra FillColor2 = Amount8;
        if (Amount7 == 0) FillColor2 = FillColor1;
    
        SizeF stringSize = new SizeF();
        stringSize = g.MeasureString(text, new Font(Amount2, Amount3));
    
        int GStartX = 0;
        int GStartY = 0;
        int GEndX = 1;
        int GEndY = 1;
    
        switch (Amount7)
        {
            case 1:
                GStartX = adrX;
                GEndX = adrX;
                GStartY = (int)(adrY - stringSize.Height / 2);
                GEndY = (int)(adrY + stringSize.Height / 2);
                break;
            case 2:
                GStartX = (int)(adrX - stringSize.Width / 2);
                GEndX = (int)(adrX + stringSize.Width / 2);
                GStartY = adrY;
                GEndY = adrY;
                break;
            case 3:
                GStartX = (int)(adrX - stringSize.Width / 2);
                GStartY = (int)(adrY - stringSize.Height / 2);
                GEndX = (int)(adrX + stringSize.Width / 2);
                GEndY = (int)(adrY + stringSize.Height / 2);
                break;
            case 4:
                GStartX = (int)(adrX + stringSize.Width / 2);
                GStartY = (int)(adrY - stringSize.Height / 2);
                GEndX = (int)(adrX - stringSize.Width / 2);
                GEndY = (int)(adrY + stringSize.Height / 2);
                break;
            case 5:
                GStartX = adrX;
                GEndX = adrX;
                GStartY = (int)(adrY - stringSize.Height / 2);
                GEndY = (int)(adrY + stringSize.Height / 2);
                break;
            case 6:
                GStartX = (int)(adrX - stringSize.Width / 2);
                GEndX = (int)(adrX + stringSize.Width / 2);
                GStartY = adrY;
                GEndY = adrY;
                break;
            default:
                break;
        }
        using (GraphicsPath path = new GraphicsPath())
        using (Pen outlinePen = new Pen(Color.FromArgb(opacity, outlineColor), outlineSize))
        using (LinearGradientBrush myGradientBrush = new LinearGradientBrush(new Point(GStartX,GStartY),new Point(GEndX,GEndY), FillColor1, FillColor2))
        {
            if(Amount7 == 5|| Amount7 == 6) myGradientBrush.SetBlendTriangularShape(startGradient, intensity);
            g.Clip = new Region(rect);
            FontFamily myFont;
            try
            {
                myFont = new FontFamily(font.Name);
            }
            catch
            {
                myFont = new FontFamily("Arial");
            }
            outlinePen.LineJoin = LineJoin.Round;
            path.AddString(text, myFont, (int)FontStyle.Regular, g.DpiY * txtSize / 72, new PointF(adrX, adrY), format);
            if (Amount4 > 0)
            {
                g.DrawPath(outlinePen, path);
            }
            g.FillPath(myGradientBrush, path);
        }
        g.Dispose();
    }

     

     

    • Upvote 1
  3. Thank you very much both of you: BoltBait and MadJik who have shown interest in completing this plugin. Thanks to you it looks very professional now.
    Thank you toehead_2001 and special thanks for Ego Eram Reputo who gave me some very clear and detailed explanation about VS template.

  4. This is my Outlined text plugin. Is not working very well because of the approach.

     

    Spoiler
    
    // Name: Outlined text
    // Submenu: Text Formations
    // Author: xod
    // Title: Outlined text
    // Version: 1.0
    // Desc:
    // Keywords:
    // URL:
    // Help:
    
    #region UICode
    MultiLineTextboxControl Amount1 = "Test"; // [1,32767] Text
    FontFamily Amount2 = new FontFamily("Arial"); // Font
    IntSliderControl Amount3 = 72; // [2,400] Font size
    ColorWheelControl Amount4 = ColorBgra.FromBgr(255,255,255); // [White] Font color
    IntSliderControl Amount5 = 5; // [1,10] Outline size
    ColorWheelControl Amount6 = ColorBgra.FromBgr(0,0,0); // [Black] Outline color
    PanSliderControl Amount7 = Pair.Create(0.000,0.000); // Location
    #endregion
    
    void Render(Surface dst, Surface src, Rectangle rect)
    {
        Rectangle sel = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
        dst.CopySurface(src,rect.Location,rect);
    
        int adrX = (int)Math.Round(((Amount7.First + 1) / 2) * (sel.Right - sel.Left));
        int adrY = (int)Math.Round(((Amount7.Second + 1) / 2) * (sel.Bottom - sel.Top));
    
        String text = Amount1;
        FontFamily font = Amount2;
        int txtSize = Amount3;
        Color fontColor = Amount4;
        int outlineSize = Amount5;
        Color outlineColor = Amount6;
        byte opacity = 255;
    
        Graphics g = new RenderArgs(dst).Graphics;
        g.SmoothingMode = SmoothingMode.AntiAlias;
        g.TextRenderingHint = TextRenderingHint.AntiAlias;
    
        StringFormat format = new StringFormat();
        format.Alignment = StringAlignment.Center;
        format.LineAlignment = StringAlignment.Center;
        
        using (GraphicsPath path = new GraphicsPath())
        using (Pen outlinePen = new Pen(Color.FromArgb(opacity, outlineColor), outlineSize))
        using (SolidBrush myBrush = new SolidBrush(fontColor))
        {
            g.Clip = new Region(rect);
            FontFamily myFont;
            try
            {
                myFont = new FontFamily(font.Name);
            }
            catch
            {
                myFont = new FontFamily("Arial");
            }
            path.AddString(text, myFont, (int)FontStyle.Regular, g.DpiY * txtSize / 72, new PointF(adrX, adrY), format);
            g.DrawPath(outlinePen, path);
            g.FillPath(myBrush, path);
        }
    }
    

     

     

    Outlined text.zip

    • Like 1
  5. You need an update.
    The newest version is 4.0.21
    Please update and see if the problem persists.
    Click on gear (Settings) > Updates > Check now.

     

    Eli, I could not reproduce the problem even if I disable antialiasing. Only 1 pixel from border became dark blue.

×
×
  • Create New...