Beispiel #1
0
 public static BitmapData_ CreateFromBitmap(GamePlatform p, BitmapCi atlas2d_)
 {
     BitmapData_ b = new BitmapData_();
     b.width = p.FloatToInt(p.BitmapGetWidth(atlas2d_));
     b.height = p.FloatToInt(p.BitmapGetHeight(atlas2d_));
     b.argb = new int[b.width * b.height];
     p.BitmapGetPixelsArgb(atlas2d_, b.argb);
     return b;
 }
Beispiel #2
0
    public static BitmapData_ CreateFromBitmap(GamePlatform p, BitmapCi atlas2d_)
    {
        BitmapData_ b = new BitmapData_();

        b.width  = p.FloatToInt(p.BitmapGetWidth(atlas2d_));
        b.height = p.FloatToInt(p.BitmapGetHeight(atlas2d_));
        b.argb   = new int[b.width * b.height];
        p.BitmapGetPixelsArgb(atlas2d_, b.argb);
        return(b);
    }
Beispiel #3
0
    TextTexture GetTextTexture(string text, FontCi font)
    {
        for (int i = 0; i < textTexturesCount; i++)
        {
            TextTexture t = textTextures[i];
            if (t == null)
            {
                continue;
            }
            if (t.text == text &&
                t.font.size == font.size &&
                t.font.family == font.family &&
                t.font.style == font.style)
            {
                return(t);
            }
        }
        TextTexture textTexture = new TextTexture();

        Text_ text_ = new Text_();

        text_.text  = text;
        text_.font  = font;
        text_.color = Game.ColorFromArgb(255, 255, 255, 255);
        BitmapCi textBitmap = textColorRenderer.CreateTextTexture(text_);

        int texture = p.LoadTextureFromBitmap(textBitmap);

        IntRef textWidth  = new IntRef();
        IntRef textHeight = new IntRef();

        p.TextSize(text, font, textWidth, textHeight);

        textTexture.texture       = texture;
        textTexture.texturewidth  = p.FloatToInt(p.BitmapGetWidth(textBitmap));
        textTexture.textureheight = p.FloatToInt(p.BitmapGetHeight(textBitmap));
        textTexture.text          = text;
        textTexture.font          = font;
        textTexture.textwidth     = textWidth.value;
        textTexture.textheight    = textHeight.value;

        p.BitmapDelete(textBitmap);

        textTextures[textTexturesCount++] = textTexture;
        return(textTexture);
    }
Beispiel #4
0
    /// <summary>
    /// Creates a bitmap from a given string
    /// </summary>
    /// <param name="t">The <see cref="Text_"/> object to create an image from</param>
    /// <returns>A <see cref="BitmapCi"/> containing the rendered text</returns>
    internal BitmapCi CreateTextTexture(Text_ t)
    {
        IntRef partsCount = new IntRef();

        TextPart[] parts = DecodeColors(t.text, t.color, partsCount);

        float totalwidth  = 0;
        float totalheight = 0;

        int[] sizesX = new int[partsCount.value];
        int[] sizesY = new int[partsCount.value];

        for (int i = 0; i < partsCount.value; i++)
        {
            IntRef outWidth  = new IntRef();
            IntRef outHeight = new IntRef();
            platform.TextSize(parts[i].text, t.font, outWidth, outHeight);

            sizesX[i] = outWidth.value;
            sizesY[i] = outHeight.value;

            totalwidth += outWidth.value;
            totalheight = MathCi.MaxFloat(totalheight, outHeight.value);
        }

        int      size2X = NextPowerOfTwo(platform.FloatToInt(totalwidth) + 1);
        int      size2Y = NextPowerOfTwo(platform.FloatToInt(totalheight) + 1);
        BitmapCi bmp2   = platform.BitmapCreate(size2X, size2Y);

        int[] bmp2Pixels = new int[size2X * size2Y];

        float currentwidth = 0;

        for (int i = 0; i < partsCount.value; i++)
        {
            int sizeiX = sizesX[i];
            int sizeiY = sizesY[i];
            if (sizeiX == 0 || sizeiY == 0)
            {
                continue;
            }

            Text_ partText = new Text_();
            partText.text  = parts[i].text;
            partText.color = parts[i].color;
            partText.font  = t.font;

            BitmapCi partBmp       = platform.CreateTextTexture(partText);
            int      partWidth     = platform.FloatToInt(platform.BitmapGetWidth(partBmp));
            int      partHeight    = platform.FloatToInt(platform.BitmapGetHeight(partBmp));
            int[]    partBmpPixels = new int[partWidth * partHeight];
            platform.BitmapGetPixelsArgb(partBmp, partBmpPixels);
            for (int x = 0; x < partWidth; x++)
            {
                for (int y = 0; y < partHeight; y++)
                {
                    if (x + currentwidth >= size2X)
                    {
                        continue;
                    }
                    if (y >= size2Y)
                    {
                        continue;
                    }
                    int c = partBmpPixels[MapUtilCi.Index2d(x, y, partWidth)];
                    if (Game.ColorA(c) > 0)
                    {
                        bmp2Pixels[MapUtilCi.Index2d(platform.FloatToInt(currentwidth) + x, y, size2X)] = c;
                    }
                }
            }
            currentwidth += sizeiX;
        }
        platform.BitmapSetPixelsArgb(bmp2, bmp2Pixels);
        return(bmp2);
    }