コード例 #1
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();
        }
コード例 #2
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();
        }
コード例 #3
0
ファイル: KeyFrame.cs プロジェクト: weimingtom/OtterUI
        /// <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();
        }
コード例 #4
0
ファイル: GUISlider.cs プロジェクト: weimingtom/OtterUI
        /// <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();
        }
コード例 #5
0
 public virtual void ExportControls(PlatformBinaryWriter bw)
 {
     bw.Write(Controls.Count);
     foreach (GUIControl control in Controls)
     {
         control.Export(bw);
     }
 }
コード例 #6
0
ファイル: GUIGroup.cs プロジェクト: weimingtom/OtterUI
        /// <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();
        }
コード例 #7
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();
        }
コード例 #8
0
        /// <summary>
        /// Exports the layout to binary format
        /// </summary>
        /// <param name="bw"></param>
        public virtual void Export(PlatformBinaryWriter bw)
        {
            FourCCStack fourCCStack = new FourCCStack(bw);

            fourCCStack.Push("CLLT");
            {
                ExportBase(bw);
            }
            fourCCStack.Pop();
        }
コード例 #9
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();
        }
コード例 #10
0
ファイル: GUIGroup.cs プロジェクト: weimingtom/OtterUI
        /// <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();
        }
コード例 #11
0
        /// <summary>
        /// Exports the base data
        /// </summary>
        /// <param name="bw"></param>
        protected void ExportBase(PlatformBinaryWriter bw)
        {
            bw.Write(this.Center.X);
            bw.Write(this.Center.Y);

            bw.Write(this.Location.X);
            bw.Write(this.Location.Y);

            bw.Write(this.Size.Width);
            bw.Write(this.Size.Height);

            bw.Write(this.Rotation);
        }
コード例 #12
0
        /// <summary>
        /// Exports the GUI Mask to disk
        /// </summary>
        /// <param name="bw"></param>
        public override void Export(PlatformBinaryWriter bw)
        {
            FourCCStack fourCCStack = new FourCCStack(bw);

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

                bw.Write(Scene.GetUniqueTextureID(mTextureID));
                bw.Write(0.0f); // Skew
                bw.Write((UInt32)mFlipType);
            }

            fourCCStack.Pop();
        }
コード例 #13
0
ファイル: Circle.cs プロジェクト: weimingtom/OtterUI
        /// <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();
        }
コード例 #14
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();
        }
コード例 #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bw"></param>
        public virtual void Export(PlatformBinaryWriter bw)
        {
            bw.Write(ID);
            byte[] bytes = Utils.StringToBytes(mName, 64);
            bytes[63] = 0;
            bw.Write(bytes, 0, 64);

            bw.Write((float)this.Layout.Location.X);
            bw.Write((float)this.Layout.Location.Y);
            bw.Write((float)this.Layout.Center.X);
            bw.Write((float)this.Layout.Center.Y);
            bw.Write((float)this.Layout.Size.Width);
            bw.Write((float)this.Layout.Size.Height);
            bw.Write((float)this.Layout.Rotation);

            bw.Write((uint)this.AnchorFlags);

            bw.Write(this.InheritedMask);
        }
コード例 #16
0
        /// <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();
        }
コード例 #17
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();
        }
コード例 #18
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();
                }
            }
        }
コード例 #19
0
        /// <summary>
        /// Exports the GUI Scene to a file
        /// </summary>
        /// <param name="bw"></param>
        public void Export(PlatformBinaryWriter bw)
        {
            FourCCStack fourCCStack = new FourCCStack(bw);

            fourCCStack.Push("GGSC");
            {
                bw.Write(Otter.Properties.Settings.Default.DataVersion);
                bw.Write((uint)this.ID);

                bw.Write(GUIProject.CurrentProject.Fonts.Count);
                bw.Write(Textures.Count + TextureAtlasses.Count);
                bw.Write(Sounds.Count);
                bw.Write(Views.Count);
                bw.Write(Messages.Count);

                int fontOffsetPos = (int)bw.BaseStream.Position;
                bw.Write(0); // Placeholder - font data start

                int textureOffsetPos = (int)bw.BaseStream.Position;
                bw.Write(0); // Placeholder - texture data start

                int soundOffsetPos = (int)bw.BaseStream.Position;
                bw.Write(0); // Placeholder - sound data start

                int viewDataOffsetPos = (int)bw.BaseStream.Position;
                bw.Write(0); // Placeholder - sceneView data start

                int msgDataOffsetPos = (int)bw.BaseStream.Position;
                bw.Write(0); // Placeholder - message data start;

                int dataStartPos = (int)bw.BaseStream.Position;
                int pos          = 0;

                // Fonts
                pos = (int)bw.BaseStream.Position;
                bw.Seek(fontOffsetPos, SeekOrigin.Begin);
                bw.Write(pos - dataStartPos);
                bw.Seek(0, SeekOrigin.End);
                foreach (GUIFont font in GUIProject.CurrentProject.Fonts)
                {
                    font.Export(bw);
                }

                // Textures
                pos = (int)bw.BaseStream.Position;
                bw.Seek(textureOffsetPos, SeekOrigin.Begin);
                bw.Write(pos - dataStartPos);
                bw.Seek(0, SeekOrigin.End);

                // Write out the texture atlasses first
                foreach (TextureAtlas textureAtlas in TextureAtlasses)
                {
                    char[] textureFile = new char[256];
                    textureAtlas.mFilename.CopyTo(0, textureFile, 0, Math.Min(255, textureAtlas.mFilename.Length));

                    bw.Write(textureAtlas.mID);
                    bw.Write(textureFile);
                    bw.Write(0);  // Placeholder : Reference Count

                    bw.Write((uint)0);
                    bw.Write(0.0f);
                    bw.Write(0.0f);
                    bw.Write(1.0f);
                    bw.Write(1.0f);
                }

                foreach (TextureInfo textureInfo in Textures)
                {
                    char[] textureFile = new char[256];
                    textureInfo.Filename.CopyTo(0, textureFile, 0, Math.Min(255, textureInfo.Filename.Length));

                    bw.Write(GetUniqueTextureID(textureInfo.ID));
                    bw.Write(textureFile);
                    bw.Write(0);  // Placeholder : Reference Count

                    FinalTexture finalTexture = GetFinalTexture(textureInfo.ID);

                    bw.Write(finalTexture.mFinalTextureID);
                    bw.Write(finalTexture.mRectangle.X);
                    bw.Write(finalTexture.mRectangle.Y);
                    bw.Write(finalTexture.mRectangle.X + finalTexture.mRectangle.Width);
                    bw.Write(finalTexture.mRectangle.Y + finalTexture.mRectangle.Height);
                }

                // Sounds
                pos = (int)bw.BaseStream.Position;
                bw.Seek(soundOffsetPos, SeekOrigin.Begin);
                bw.Write(pos - dataStartPos);
                bw.Seek(0, SeekOrigin.End);
                foreach (SoundInfo soundInfo in Sounds)
                {
                    char[] soundIdentifier = new char[256];

                    if (soundInfo.Filename != "")
                    {
                        soundInfo.Filename.CopyTo(0, soundIdentifier, 0, Math.Min(255, soundInfo.Filename.Length));
                    }
                    else
                    {
                        soundInfo.Name.CopyTo(0, soundIdentifier, 0, Math.Min(255, soundInfo.Name.Length));
                    }

                    bw.Write(GetUniqueSoundID(soundInfo.ID));
                    bw.Write(soundIdentifier);
                    bw.Write(0);  // Placeholder : Reference Count
                }

                // Views
                pos = (int)bw.BaseStream.Position;
                bw.Seek(viewDataOffsetPos, SeekOrigin.Begin);
                bw.Write(pos - dataStartPos);
                bw.Seek(0, SeekOrigin.End);
                foreach (GUIView view in Views)
                {
                    view.Export(bw);
                }

                // Messages
                pos = (int)bw.BaseStream.Position;
                bw.Seek(msgDataOffsetPos, SeekOrigin.Begin);
                bw.Write(pos - dataStartPos);
                bw.Seek(0, SeekOrigin.End);
                foreach (UI.Message msg in Messages)
                {
                    bw.Write(this.GetUniqueMessageID(msg.ID));

                    byte[] bytes = Utils.StringToBytes(msg.Text, 64);
                    bytes[63] = 0;
                    bw.Write(bytes, 0, 64);
                }

                // Write an end-marker for the scene file, to verify all data was loaded properly
                bw.Write((UInt32)0x12344321);
            }
            fourCCStack.Pop();
        }
コード例 #20
0
 /// <summary>
 /// Exports to a binary stream
 /// </summary>
 /// <param name="bw"></param>
 public virtual void Export(PlatformBinaryWriter bw)
 {
 }
コード例 #21
0
        /// <summary>
        /// Exports the GUI ActiveView
        /// </summary>
        /// <param name="bw"></param>
        public override void Export(PlatformBinaryWriter bw)
        {
            FourCCStack fourCCStack = new FourCCStack(bw);

            // [G]ame[G]UI [V]ie[W]
            fourCCStack.Push("GGVW");

            base.Export(bw);

            {
                List <int> textureList = TextureIDs;
                List <int> soundList   = SoundIDs;

                bw.Write(textureList.Count);
                bw.Write(soundList.Count);
                bw.Write(Controls.Count);

                int textureOffsetPos = (int)bw.BaseStream.Position;
                bw.Write(0); // Placeholder - texture data start

                int soundsOffsetPos = (int)bw.BaseStream.Position;
                bw.Write(0); // Placeholder - sound data start

                int controlsOffsetPos = (int)bw.BaseStream.Position;
                bw.Write(0); // Placeholder - control data start

                int animationListOffsetPos = (int)bw.BaseStream.Position;
                bw.Write(0); // Placeholder - channel list data start

                int dataStartPos = (int)bw.BaseStream.Position;
                int pos          = 0;

                // Textures
                pos = (int)bw.BaseStream.Position;
                bw.Seek(textureOffsetPos, SeekOrigin.Begin);
                bw.Write(pos - dataStartPos);
                bw.Seek(0, SeekOrigin.End);
                foreach (int texID in textureList)
                {
                    bw.Write(Scene.GetUniqueTextureID(texID));
                }

                // Sounds
                pos = (int)bw.BaseStream.Position;
                bw.Seek(soundsOffsetPos, SeekOrigin.Begin);
                bw.Write(pos - dataStartPos);
                bw.Seek(0, SeekOrigin.End);
                foreach (int soundID in soundList)
                {
                    bw.Write(Scene.GetUniqueSoundID(soundID));
                }

                // Controls
                pos = (int)bw.BaseStream.Position;
                bw.Seek(controlsOffsetPos, SeekOrigin.Begin);
                bw.Write(pos - dataStartPos);
                bw.Seek(0, SeekOrigin.End);
                foreach (GUIControl control in Controls)
                {
                    control.Export(bw);
                }

                // Animation List
                pos = (int)bw.BaseStream.Position;
                bw.Seek(animationListOffsetPos, SeekOrigin.Begin);
                bw.Write(pos - dataStartPos);
                bw.Seek(0, SeekOrigin.End);

                // [G]ame[G]UI [A]nimation [L]ist
                fourCCStack.Push("GGAL");
                {
                    bw.Write(Animations.Count);

                    foreach (GUIAnimation animation in Animations)
                    {
                        List <GUIAnimationChannel> channels = null;

                        try
                        {
                            channels = animation.GetSortedChannels(this.Controls);
                        }
                        catch (Exception e)
                        {
                            System.Console.WriteLine("Exception : " + e);
                            channels = animation.AnimationChannels;
                        }

                        // [G]ame[G]UI [A][N]imation
                        fourCCStack.Push("GGAN");
                        {
                            byte[] bytes = Utils.StringToBytes(animation.Name, 64);
                            bytes[63] = 0;
                            bw.Write(bytes, 0, 64);
                            bw.Write(animation.NumFrames);
                            bw.Write(animation.RepeatStart);
                            bw.Write(animation.RepeatEnd);

                            bw.Write(channels.Count);
                            bw.Write(animation.MainChannelFrames.Count);

                            int actionlistDataOffsetPos = (int)bw.BaseStream.Position;
                            bw.Write(0); // Placeholder - action list data start;

                            int anmDataStartPos = (int)bw.BaseStream.Position;
                            int anmPos          = 0;

                            foreach (GUIAnimationChannel channel in channels)
                            {
                                // [G]ame[G]UI [A]nimation [C]hannel
                                fourCCStack.Push("GGAC");
                                {
                                    bw.Write(channel.ControlID);
                                    bw.Write(channel.KeyFrames.Count);

                                    // Make sure we sort the keyframes prior to export
                                    channel.KeyFrames.Sort((a, b) => ((int)a.Frame - (int)b.Frame));

                                    foreach (KeyFrame keyFrame in channel.KeyFrames)
                                    {
                                        keyFrame.Export(bw);
                                    }
                                }
                                fourCCStack.Pop();
                            }

                            anmPos = (int)bw.BaseStream.Position;
                            bw.Seek(actionlistDataOffsetPos, SeekOrigin.Begin);
                            bw.Write(anmPos - anmDataStartPos);
                            bw.Seek(0, SeekOrigin.End);

                            foreach (MainChannelFrame mainChannelFrame in animation.MainChannelFrames)
                            {
                                mainChannelFrame.Export(bw);
                            }
                        }
                        fourCCStack.Pop();
                    }
                }
                fourCCStack.Pop();
            }
            fourCCStack.Pop();
        }