Exemple #1
0
 /// <summary>
 /// Exports the layout to binary format
 /// </summary>
 /// <param name="bw"></param>
 public override void Export(PlatformBinaryWriter bw)
 {
     FourCCStack fourCCStack = new FourCCStack(bw);
     fourCCStack.Push("GPLT");
     {
         ExportBase(bw);
     }
     fourCCStack.Pop();
 }
Exemple #2
0
 /// <summary>
 /// Exports the action
 /// </summary>
 /// <param name="bw"></param>
 public override void Export(PlatformBinaryWriter bw)
 {
     FourCCStack fourCCStack = new FourCCStack(bw);
     fourCCStack.Push("MSGA");
     {
         bw.Write(this.Scene.GetUniqueMessageID(this.Message));
     }
     fourCCStack.Pop();
 }
Exemple #3
0
 /// <summary>
 /// Exports the action
 /// </summary>
 /// <param name="bw"></param>
 public override void Export(PlatformBinaryWriter bw)
 {
     FourCCStack fourCCStack = new FourCCStack(bw);
     fourCCStack.Push("SNDA");
     {
         bw.Write(this.Scene.GetUniqueSoundID(this.Sound));
         bw.Write((float)mVolume);
     }
     fourCCStack.Pop();
 }
Exemple #4
0
        /// <summary>
        /// Exports the table
        /// </summary>
        /// <param name="bw"></param>
        public override void Export(Otter.Export.PlatformBinaryWriter bw)
        {
            FourCCStack fourCCStack = new FourCCStack(bw);

            fourCCStack.Push("GTBL");
            {
                base.Export(bw);

                bw.Write(DefaultRowHeight);
                bw.Write(RowSpacing);
            }
            fourCCStack.Pop();
        }
Exemple #5
0
        /// <summary>
        /// Exports the Toggle
        /// </summary>
        /// <param name="bw"></param>
        public override void Export(Otter.Export.PlatformBinaryWriter bw)
        {
            FourCCStack fourCCStack = new FourCCStack(bw);

            fourCCStack.Push("GTGL");
            {
                base.Export(bw);

                bw.Write(Scene.GetUniqueTextureID(OnTexture));
                bw.Write(Scene.GetUniqueTextureID(OffTexture));

                bw.Write(Color.White.ToArgb());
            }
            fourCCStack.Pop();
        }
Exemple #6
0
        /// <summary>
        /// Exports the Circle
        /// </summary>
        /// <param name="bw"></param>
        public override void Export(Otter.Export.PlatformBinaryWriter bw)
        {
            FourCCStack fourCCStack = new FourCCStack(bw);

            fourCCStack.Push("CIRC");
            {
                base.Export(bw);

                bw.Write((UInt32)Segments);
                bw.Write((UInt32)Radius);
                bw.Write((UInt32)Width);
                bw.Write((UInt32)this.Color.ToArgb());
            }
            fourCCStack.Pop();
        }
        /// <summary>
        /// Exports an exportable object to file
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="fileName"></param>
        public bool Export <T>(T obj, string filename, Platform platform) where T : IExportable
        {
            FileStream           fs = null;
            PlatformBinaryWriter bw = null;
            bool bSuccess           = false;

            try
            {
                fs = new FileStream(filename, FileMode.Create);
                bw = new PlatformBinaryWriter(fs, platform);

                obj.Export(bw);

                bw.Close();
                fs.Close();

                bSuccess = true;
            }
            catch (Exception ex)
            {
                System.Console.Write("Error exporting object: " + ex.Message);
            }
            finally
            {
                if (bw != null)
                {
                    bw.Close();
                }

                if (fs != null)
                {
                    fs.Close();
                }
            }

            return(bSuccess);
        }
Exemple #8
0
        /// <summary>
        /// Exports the circle layout
        /// </summary>
        /// <param name="bw"></param>
        public override void Export(PlatformBinaryWriter bw)
        {
            FourCCStack fourCCStack = new FourCCStack(bw);
            fourCCStack.Push("CRLT");
            {
                // Export the base layout properties
                ExportBase(bw);

                // Export our specific properties
                bw.Write((UInt32)Radius);
                bw.Write((UInt32)Width);
                bw.Write((UInt32)Color.ToArgb());
            }
            fourCCStack.Pop();
        }
Exemple #9
0
        /// <summary>
        /// Exports the GUI Sprite to disk
        /// </summary>
        /// <param name="bw"></param>
        public override void Export(PlatformBinaryWriter bw)
        {
            FourCCStack fourCCStack = new FourCCStack(bw);
            fourCCStack.Push("GSPR");
            {
                base.Export(bw);

                bw.Write(Scene.GetUniqueTextureID(mTextureID));
                bw.Write(Color.White.ToArgb());
                bw.Write(0.0f); // Skew
                bw.Write((UInt32)mFlipType);

                base.ExportControls(bw);
            }

            fourCCStack.Pop();
        }
Exemple #10
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="bw"></param>
 public FourCCStack(PlatformBinaryWriter bw)
 {
     mBinaryWriter = bw;
 }
Exemple #11
0
        /// <summary>
        /// Exports this frame to a binary stream
        /// </summary>
        /// <param name="bw"></param>
        public virtual void Export(PlatformBinaryWriter bw)
        {
            FourCCStack fourCCStack = new FourCCStack(bw);
            fourCCStack.Push("KFRM");
            {
                bw.Write(this.Frame);

                bw.Write((int)this.EaseFunction);
                bw.Write(this.EaseAmount);

                bw.Write(this.LeftAnchor.AbsoluteValue);
                bw.Write(this.LeftAnchor.RatioValue);

                bw.Write(this.RightAnchor.AbsoluteValue);
                bw.Write(this.RightAnchor.RatioValue);

                bw.Write(this.TopAnchor.AbsoluteValue);
                bw.Write(this.TopAnchor.RatioValue);

                bw.Write(this.BottomAnchor.AbsoluteValue);
                bw.Write(this.BottomAnchor.RatioValue);

                this.Layout.Export(bw);
            }

            fourCCStack.Pop();
        }
Exemple #12
0
        /// <summary>
        /// Exports the GUI Label to disk
        /// </summary>
        /// <param name="bw"></param>
        public override void Export(PlatformBinaryWriter bw)
        {
            FourCCStack fourCCStack = new FourCCStack(bw);
            fourCCStack.Push("GLBL");

            base.Export(bw);

            bw.Write(mFontID);
            bw.Write(Color.White.ToArgb());
            bw.Write(1.0f); // Scale X
            bw.Write(1.0f); // Scale Y
            bw.Write(0.0f); // Skew
            bw.Write(0); // Drop shadow
            bw.Write((UInt32)mHorizontalAlignment);
            bw.Write((UInt32)mVerticalAlignment);
            bw.Write(mLeading);
            bw.Write(mTracking);
            bw.Write((UInt32)mTextFit);

            byte[] bytes = Utils.StringToBytes(mText, 4);
            bw.Write(bytes.Length);
            bw.Write(bytes);

            fourCCStack.Pop();
        }
Exemple #13
0
 /// <summary>
 /// Exports the group
 /// </summary>
 /// <param name="bw"></param>
 public override void Export(PlatformBinaryWriter bw)
 {
     FourCCStack fourCCStack = new FourCCStack(bw);
     fourCCStack.Push("GGRP");
     {
         base.Export(bw);
         base.ExportControls(bw);
     }
     fourCCStack.Pop();
 }
Exemple #14
0
        /// <summary>
        /// Reloads the font
        /// </summary>
        public void ReloadFont()
        {
            if (mProject == null)
                return;

            int borderWidth = 2;

            string fullPath = mProject.ProjectDirectory + "/" + mFontFile;
            if (System.IO.File.Exists(fullPath))
            {
                // Ensure that the character list ALWAYS contains at least the ? character.
                if (!Characters.Contains('?'))
                    Characters.Add('?');

                // Load the image glyph textures
                foreach (FontBuilder.ImageGlyph imageGlyph in Images)
                    imageGlyph.Load(mProject.ProjectDirectory);

                if (mFontData != null)
                    mFontData.Dispose();

                mFontData = new FontBuilder.FontData(Characters, Images);
                FontBuilder.Glyph[] glyphs = mFontData.GetGlyphs(fullPath, mFontSize);

                // Clear out our existing textures and texture atlasses
                foreach (TextureAtlas atlas in mTextureAtlasses)
                {
                    DisposeAtlasNode(atlas.mRoot);
                }
                mTextureAtlasses.Clear();

                mTextures.Clear();
                mCharInfoList.Clear();
                mMaxTop = -99999;

                Image texture = null;
                Bitmap textureBitmap = null;
                if (File.Exists(mProject.ProjectDirectory + "/" + mTextureFile))
                {
                    texture = Image.FromFile(mProject.ProjectDirectory + "/" + mTextureFile);
                    textureBitmap = new Bitmap(texture);
                }

                TextureAtlas curAtlas = null;
                foreach (FontBuilder.Glyph glyph in glyphs)
                {
                    if (glyph == null)
                        continue;

                    if (mMaxTop < glyph.mTop)
                        mMaxTop = glyph.mTop;

                    Bitmap finalBitmap = null;
                    if (glyph.mBitmap != null)
                    {
                        finalBitmap = (borderWidth == 0) ? new Bitmap(glyph.mBitmap) : Utils.ExpandImageBorder(glyph.mBitmap, borderWidth, true);
                        if (finalBitmap == null)
                            continue;

                        Bitmap outlinedBitmap = null;
                        Bitmap texturedBitmap = null;

                        if (OutlineAmount > 0.0f && OutlineColor.A != 0)
                        {
                            float s = Math.Min(1.0f, Math.Max(OutlineSharpness, 0.0f));
                            outlinedBitmap = BlurBitmap(finalBitmap, OutlineAmount, OutlineSharpness, OutlineColor);
                            finalBitmap.Dispose();
                            finalBitmap = outlinedBitmap;
                        }

                        BitmapData texturedBitmapData = null;
                        if (textureBitmap != null && glyph.mImageGlyph == 0)
                        {
                            texturedBitmap = ApplyTexture(textureBitmap, glyph.mBitmap, mTextureBaseline, glyph.mTop);
                            texturedBitmapData = texturedBitmap.LockBits(new Rectangle(0, 0,
                                                                        texturedBitmap.Width,
                                                                        texturedBitmap.Height),
                                                                        ImageLockMode.ReadOnly,
                                                                        texturedBitmap.PixelFormat);
                        }

                        // Now we need to use the original bitmap (from the glyph) and reapply it to the new
                        // bitmap (that may or may not have been blurred) with the fill color
                        BitmapData sourceBitmapData = glyph.mBitmap.LockBits( new Rectangle(0, 0, glyph.mBitmap.Width, glyph.mBitmap.Height),
                                                                              ImageLockMode.ReadOnly,
                                                                              glyph.mBitmap.PixelFormat);

                        BitmapData targetBitmapData = finalBitmap.LockBits(new Rectangle((finalBitmap.Width - glyph.mBitmap.Width) / 2,
                                                                      (finalBitmap.Height - glyph.mBitmap.Height) / 2,
                                                                      glyph.mBitmap.Width,
                                                                      glyph.mBitmap.Height),
                                                                      ImageLockMode.WriteOnly,
                                                                      finalBitmap.PixelFormat);

                        try
                        {
                            for (int x = 0; x < sourceBitmapData.Width; x++)
                            {
                                for (int y = 0; y < sourceBitmapData.Height; y++)
                                {
                                    IntPtr sourcePixel = (IntPtr)((int)sourceBitmapData.Scan0 + sourceBitmapData.Stride * y + x * 4);
                                    IntPtr targetPixel = (IntPtr)((int)targetBitmapData.Scan0 + targetBitmapData.Stride * y + x * 4);
                                    IntPtr texturePixel = IntPtr.Zero;

                                    if(texturedBitmapData != null)
                                        texturePixel = (IntPtr)((int)texturedBitmapData.Scan0 + texturedBitmapData.Stride * y + x * 4);

                                    Color srcColor = Color.FromArgb(Marshal.ReadInt32(sourcePixel));
                                    Color tgtColor = Color.FromArgb(Marshal.ReadInt32(targetPixel));
                                    Color texColor = (texturePixel != IntPtr.Zero) ? Color.FromArgb(Marshal.ReadInt32(texturePixel)) : Color.White;

                                    float alpha = srcColor.A / 255.0f;
                                    if (alpha == 0.0f)
                                        continue;

                                    byte r = (byte)(tgtColor.R * (1.0f - alpha) + FillColor.R * (srcColor.R / 255.0f) * (texColor.R / 255.0f) * alpha);
                                    byte g = (byte)(tgtColor.G * (1.0f - alpha) + FillColor.G * (srcColor.G / 255.0f) * (texColor.G / 255.0f) * alpha);
                                    byte b = (byte)(tgtColor.B * (1.0f - alpha) + FillColor.B * (srcColor.B / 255.0f) * (texColor.B / 255.0f) * alpha);
                                    byte a = (byte)(tgtColor.A * (1.0f - alpha) + FillColor.A * (srcColor.A / 255.0f) * (texColor.A / 255.0f) * alpha);

                                    Color finalColor = Color.FromArgb(a, r, g, b);

                                    Marshal.WriteInt32(targetPixel, finalColor.ToArgb());
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            System.Console.WriteLine("Exception : " + ex);
                        }

                        glyph.mBitmap.UnlockBits(sourceBitmapData);
                        finalBitmap.UnlockBits(targetBitmapData);

                        if (texturedBitmapData != null)
                            texturedBitmap.UnlockBits(texturedBitmapData);
                    }
                    else
                    {
                        finalBitmap = new Bitmap(4, 4);
                    }

                    if (curAtlas == null || !curAtlas.AddTexture(finalBitmap, glyph))
                    {
                        curAtlas = new TextureAtlas(0, AtlasSize.Width, AtlasSize.Height, "tmp");
                        mTextureAtlasses.Add(curAtlas);

                        curAtlas.AddTexture(finalBitmap, glyph);
                    }
                }

                if (textureBitmap != null)
                    textureBitmap.Dispose();

                if (texture != null)
                    texture.Dispose();

                // Unload the image glyph textures
                foreach (FontBuilder.ImageGlyph imageGlyph in Images)
                    imageGlyph.Unload();

                // Then iterate and add to the texture atlas(ses).
                if (Otter.Interface.Graphics.Instance != null)
                {
                    foreach(int textureID in mTextures)
                        Otter.Interface.Graphics.Instance.UnloadTexture(textureID);

                    foreach (TextureAtlas atlas in mTextureAtlasses)
                    {
                        Bitmap bitmap = atlas.GetBitmap();

                        // BitmapData
                        BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);

                        // Get the address of the first line.
                        IntPtr ptr = bitmapData.Scan0;

                        // Declare an array to hold the bytes of the bitmap.
                        int size = Math.Abs(bitmapData.Stride) * bitmap.Height;
                        byte[] bytes = new byte[size];

                        System.Runtime.InteropServices.Marshal.Copy(ptr, bytes, 0, size);

                        int textureID = Otter.Interface.Graphics.Instance.LoadTexture(bytes, bitmap.Width, bitmap.Height, 32);

                        bitmap.UnlockBits(bitmapData);

                        mTextures.Add(textureID);

                        bitmap.Dispose();

                        // SLOW
                        foreach (FontBuilder.Glyph glyph in glyphs)
                        {
                            if (glyph == null)
                                continue;

                            AtlasNode node = atlas.FindNode(glyph);

                            if(node != null)
                            {
                                NewCharInfo info = new NewCharInfo();

                                int diffW = node.mRectangle.Width - borderWidth * 2 - glyph.mW;
                                int diffH = node.mRectangle.Height - borderWidth * 2 - glyph.mH;

                                info.mCharCode = glyph.mCharCode;
                                info.mImageGlyph = glyph.mImageGlyph;
                                info.mX = node.mRectangle.X + borderWidth;
                                info.mY = node.mRectangle.Y + borderWidth;
                                info.mW = glyph.mW + diffW;
                                info.mH = glyph.mH + diffH;

                                info.mTop = glyph.mTop + diffH / 2;
                                info.mAdvance = glyph.mAdvance;
                                info.mLeftBearing = glyph.mLeftBearing - diffW / 2;

                                info.mAtlasIndex = mTextureAtlasses.IndexOf(atlas);

                                mCharInfoList.Add(info);
                            }
                        }
                    }

                    MemoryStream stream = new MemoryStream();

                    Platform platform = new Platform();
                    platform.Endianness = Endian.Little;
                    platform.ColorFormat = ColorFormat.ARGB;

                    PlatformBinaryWriter bw = new PlatformBinaryWriter(stream, platform);
                    this.Export(bw);

                    mFontID = Otter.Interface.Graphics.Instance.LoadFont(this.Name, stream.GetBuffer(), mTextures);

                    bw.Close();
                    stream.Close();
                }
            }
        }
Exemple #15
0
        /// <summary>
        /// Exports the GUI Font
        /// </summary>
        /// <param name="bw"></param>
        public void Export(PlatformBinaryWriter bw)
        {
            byte[] bytes = Utils.StringToBytes(mName, 64);
            bytes[63] = 0;

            FourCCStack fourCCStack = new FourCCStack(bw);
            fourCCStack.Push("GFNT");

            // Font information
            bw.Write(this.ID);
            bw.Write(bytes, 0, 64);
            bw.Write(this.FontSize);
            bw.Write(AtlasSize.Width);
            bw.Write(AtlasSize.Height);
            bw.Write(this.mMaxTop);
            bw.Write(this.mTextures.Count);

            // Now write the glyph data
            bw.Write(this.mCharInfoList.Count);

            foreach (NewCharInfo charInfo in this.mCharInfoList)
            {
                bw.Write(charInfo.mCharCode);
                bw.Write(charInfo.mImageGlyph);

                bw.Write(charInfo.mX);
                bw.Write(charInfo.mY);
                bw.Write(charInfo.mW);
                bw.Write(charInfo.mH);

                bw.Write(charInfo.mTop);
                bw.Write(charInfo.mAdvance);
                bw.Write(charInfo.mLeftBearing);

                bw.Write(charInfo.mAtlasIndex);
            }

            fourCCStack.Pop();
        }
Exemple #16
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="bw"></param>
 public FourCCStack(PlatformBinaryWriter bw)
 {
     mBinaryWriter = bw;
 }
Exemple #17
0
 /// <summary>
 /// Exports to a binary stream
 /// </summary>
 /// <param name="bw"></param>
 public virtual void Export(PlatformBinaryWriter bw)
 {
 }
        /// <summary>
        /// Exports the action list
        /// </summary>
        /// <param name="bw"></param>
        public void Export(PlatformBinaryWriter bw)
        {
            FourCCStack fourCCStack = new FourCCStack(bw);
            fourCCStack.Push("MCFR");
            {
                byte[] bytes = Utils.StringToBytes(mName, 64);
                bytes[63] = 0;
                bw.Write(bytes, 0, 64);

                bw.Write(this.Frame);
                bw.Write(this.Actions.Count);

                foreach (UI.Actions.Action action in this.Actions)
                {
                    action.Export(bw);
                }
            }
            fourCCStack.Pop();
        }
Exemple #19
0
        /// <summary>
        /// Exports the GUI Slider to disk
        /// </summary>
        /// <param name="bw"></param>
        public override void Export(PlatformBinaryWriter bw)
        {
            FourCCStack fourCCStack = new FourCCStack(bw);
            fourCCStack.Push("GSLD");
            {
                base.Export(bw);

                bw.Write(ThumbWidth);
                bw.Write(ThumbHeight);

                bw.Write(Scene.GetUniqueTextureID(StartTexture));
                bw.Write(Scene.GetUniqueTextureID(MiddleTexture));
                bw.Write(Scene.GetUniqueTextureID(EndTexture));
                bw.Write(Scene.GetUniqueTextureID(ThumbTexture));

                bw.Write(Min);
                bw.Write(Max);
                bw.Write(Step);
                bw.Write((UInt32)0);

                bw.Write(Color.White.ToArgb());
            }
            fourCCStack.Pop();
        }
Exemple #20
0
        /// <summary>
        /// Exports the label layout
        /// </summary>
        /// <param name="bw"></param>
        public override void Export(PlatformBinaryWriter bw)
        {
            FourCCStack fourCCStack = new FourCCStack(bw);
            fourCCStack.Push("LBLT");
            {
                ExportBase(bw);

                bw.Write(Color);
                bw.Write(Scale.Width);
                bw.Write(Scale.Height);
                bw.Write(Skew);
                bw.Write(DropShadow);
            }
            fourCCStack.Pop();
        }
Exemple #21
0
        /// <summary>
        /// Exports the GUI Sprite to disk
        /// </summary>
        /// <param name="bw"></param>
        public override void Export(PlatformBinaryWriter bw)
        {
            FourCCStack fourCCStack = new FourCCStack(bw);
            fourCCStack.Push("GBTT");

            base.Export(bw);

            bw.Write(Scene.GetUniqueTextureID(mDefaultTextureID));
            bw.Write(Scene.GetUniqueTextureID(mDownTextureID));

            bw.Write(mLabel.FontID);
            bw.Write(DefaultColor.ToArgb());
            bw.Write(DownColor.ToArgb());
            bw.Write(1.0f);
            bw.Write(1.0f);
            bw.Write((UInt32)HorizontalAlignment);
            bw.Write((UInt32)VerticalAlignment);

            bw.Write(OnClickActionList.Count);

            byte[] bytes = Utils.StringToBytes(mLabel.Text, 4);
            bw.Write(bytes.Length);
            bw.Write(bytes);

            foreach (UI.Actions.Action action in this.OnClickActionList)
            {
                action.Export(bw);
            }

            fourCCStack.Pop();
        }