public Software.Meshes.IndexedPlane GetPlane(Vector2 textureSize)
        {
            Software.Meshes.IndexedPlane plane = new Graphics.Software.Meshes.IndexedPlane();
            if (SizeMode == SizeMode.Fixed)
            {
                plane.Size = Size;
            }
            else
            {
                plane.Size = textureSize;
            }

            var sourceTextureAreaSize = new Vector2(
                textureSize.X * (TextureUVMax.X - TextureUVMin.X),
                textureSize.Y * (TextureUVMax.Y - TextureUVMin.Y));

            var sourceAreaPosMin = OrientationUtil.Position(TextureAnchor, sourceTextureAreaSize,
                                                            Vector2.Zero, plane.Size);
            var sourceAreaPosMax = sourceAreaPosMin + plane.Size;

            var texturePosMin = sourceAreaPosMin + new Vector2(
                TextureUVMin.X * textureSize.X,
                TextureUVMin.Y * textureSize.Y
                );

            var texturePosMax = sourceAreaPosMax + new Vector2(
                TextureUVMin.X * textureSize.X,
                TextureUVMin.Y * textureSize.Y
                );

            plane.UVMin = new Vector2(texturePosMin.X / textureSize.X, texturePosMin.Y / textureSize.Y);
            plane.UVMax = new Vector2(texturePosMax.X / textureSize.X, texturePosMax.Y / textureSize.Y);
            return(plane);
        }
Beispiel #2
0
        static PlistArray SaveOrientationsCombo(ComboBox combo)
        {
            var      store = (ListStore)combo.Model;
            int      i     = combo.Active;
            TreeIter iter;

            if (store.GetIterFirst(out iter))
            {
                do
                {
                    if (i-- == 0)
                    {
                        return(OrientationUtil.ToPlist((Orientation)store.GetValue(iter, 1)));
                    }
                } while (store.IterNext(ref iter));
            }
            return(null);
        }
Beispiel #3
0
        static void LoadOrientationsCombo(ComboBox combo, PlistArray values)
        {
            var store = (ListStore)combo.Model;

            store.Clear();
            store.AppendValues(GettextCatalog.GetString("Both"), Orientation.Both);
            store.AppendValues(GettextCatalog.GetString("Portrait"), Orientation.Portrait);
            store.AppendValues(GettextCatalog.GetString("Landscape"), Orientation.Landscape);
            store.AppendValues(GettextCatalog.GetString("Not specified"), Orientation.None);

            var o = OrientationUtil.Parse(values);

            switch (o)
            {
            case Orientation.Both:
                combo.Active = 0;
                break;

            case Orientation.Portrait:
                combo.Active = 1;
                break;

            case Orientation.Landscape:
                combo.Active = 2;
                break;

            case Orientation.None:
                combo.Active = 3;
                break;

            default:
                store.AppendValues(GettextCatalog.GetString("Custom"), o);
                combo.Active = 4;
                break;
            }
        }
        public static List <Glyph> BuildGlyphs(FontImplementation fi, Orientation anchor, Vector2 size, string text, out int textHeight)
        {
            textHeight = 0;
            if (text == null)
            {
                return(null);
            }
            var glyhps = new List <Glyph>();

            String[] lines   = text.Split('\n');
            int      nglyphs = 0;

            foreach (String line in lines)
            {
                foreach (String word in line.Split(' '))
                {
                    nglyphs += word.Length;
                }
            }
            if (nglyphs == 0)
            {
                return(null);
            }
            float textWidth = 0, textHeightTmp = 0;

            float x = 0, y = 0;

            for (int i = 0; i < lines.Length; i++)
            {
                String[] words = lines[i].Split(' ');

                for (int j = 0; j < words.Length; j++)
                {
                    String word = words[j];
                    if (x + fi.TextWidth(word) > size.X && j > 0)
                    {
                        y += fi.CharacterHeight;
                        x  = 0;
                    }
                    foreach (char c in word)
                    {
                        var uv    = fi.CharacterUV(c);
                        var width = fi.CharacterWidth(c);
                        glyhps.Add(new Glyph
                        {
                            Position = new Vector3(x, y, 0),
                            Size     = new Vector2(width, fi.CharacterHeight),
                            UVMin    = new Vector2(uv.X, uv.Y),
                            UVMax    = new Vector2(uv.X + width / ((float)fi.TextureSize),
                                                   uv.Y + fi.CharacterHeight / ((float)fi.TextureSize)),
                        });
                        x        += (float)Math.Ceiling(width);
                        textWidth = Math.Max(textWidth, x);
                    }
                    x += (float)Math.Ceiling(fi.CharacterWidth(' '));
                }
                y            += fi.CharacterHeight;
                textHeightTmp = Math.Max(0, y);
                textHeight    = (int)Math.Ceiling(textHeightTmp);
                x             = 0;
            }

            Vector3 offset = Vector3.Zero;

            /*if (Anchor == Orientation.TopLeft || Anchor == Orientation.Left || Anchor == Orientation.BottomLeft)
             *  offset.X = 0;
             * else if (Anchor == Orientation.Top || Anchor == Orientation.Center || Anchor == Orientation.Bottom)
             *  offset.X = (Size.X - textWidth) / 2f;
             * else
             *  offset.X = Size.X - textWidth - 1;
             *
             * if (Anchor == Orientation.TopLeft || Anchor == Orientation.Top || Anchor == Orientation.TopRight)
             *  offset.Y = 0;
             * else if (Anchor == Orientation.Left || Anchor == Orientation.Center || Anchor == Orientation.Right)
             *  offset.Y = (Size.Y - textHeight) / 2f;
             * else
             *  offset.Y = Size.Y - textHeight - 1;*/

            offset = Common.Math.ToVector3(OrientationUtil.Position(anchor, size, Vector2.Zero,
                                                                    new Vector2(textWidth, textHeight)));

            foreach (Glyph g in new List <Glyph>(glyhps))
            {
                g.Position += offset;
            }

            return(glyhps);
        }