Inheritance: ILibrary
Esempio n. 1
0
 public static void LoadTextureInternal(Flood.GUI.Texture t, System.Drawing.Bitmap bmp)
 {
     System.Drawing.Imaging.BitmapData data = bmp.LockBits(System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
     int bytes = std.abs(data.Stride) * bmp.Height;
     LoadTextureInternal(t,(uint8*)data.Scan0.ToPointer(), bytes);
     bmp.UnlockBits(data);
 }
Esempio n. 2
0
 static Flood.GUI.Texture GetTexture(Flood.GUI.Font font, System.String text)
 {
     System.Tuple<System.String, Flood.GUI.Font> key = new System.Tuple<System.String, Flood.GUI.Font>(text, font);
     if (m_StringCache.ContainsKey(key))
         return m_StringCache[key];
     return null;
 }
Esempio n. 3
0
        static bool LoadFont(Flood.GUI.Font font)
        {
            //Debug.Print(String.Format("LoadFont {0}", font.FaceName));
            font.RealSize = font.Size;// * Scale;
            System.Drawing.Font sysFont = (System.Drawing.Font)font.RendererData;

            if (sysFont != null)
                delete(sysFont);

            // apaprently this can't fail @[email protected]
            // "If you attempt to use a font that is not supported, or the font is not installed on the machine that is running the application, the Microsoft Sans Serif font will be substituted."
            sysFont = new System.Drawing.Font(font.FaceName, font.Size);
            font.RendererData = sysFont;
            return true;
        }
Esempio n. 4
0
        public override void DrawTexturedRect(Flood.GUI.Texture t, System.Drawing.Rectangle rect, float u1, float v1, float u2, float v2)
        {
            if(t.RendererData == null){
                DrawFilledRect(rect);
            }

            var hId = (uint)t.RendererData;

            rect = Translate(rect);

            if (m_ClipEnabled)
            {
                // cpu scissors test
                if (rect.Y < ClipRegion.Y)
                {
                    int oldHeight = rect.Height;
                    int delta = ClipRegion.Y - rect.Y;
                    rect.Y = ClipRegion.Y;
                    rect.Height -= delta;

                    if (rect.Height <= 0)
                    {
                        return;
                    }

                    float dv = (float)delta / (float)oldHeight;

                    v1 += dv * (v2 - v1);
                }

                if ((rect.Y + rect.Height) > (ClipRegion.Y + ClipRegion.Height))
                {
                    int oldHeight = rect.Height;
                    int delta = (rect.Y + rect.Height) - (ClipRegion.Y + ClipRegion.Height);

                    rect.Height -= delta;

                    if (rect.Height <= 0)
                    {
                        return;
                    }

                    float dv = (float)delta / (float)oldHeight;

                    v2 -= dv * (v2 - v1);
                }

                if (rect.X < ClipRegion.X)
                {
                    int oldWidth = rect.Width;
                    int delta = ClipRegion.X - rect.X;
                    rect.X = ClipRegion.X;
                    rect.Width -= delta;

                    if (rect.Width <= 0)
                    {
                        return;
                    }

                    float du = (float)delta / (float)oldWidth;

                    u1 += du * (u2 - u1);
                }

                if ((rect.X + rect.Width) > (ClipRegion.X + ClipRegion.Width))
                {
                    int oldWidth = rect.Width;
                    int delta = (rect.X + rect.Width) - (ClipRegion.X + ClipRegion.Width);

                    rect.Width -= delta;

                    if (rect.Width <= 0)
                    {
                        return;
                    }

                    float du = (float)delta / (float)oldWidth;

                    u2 -= du * (u2 - u1);
                }
            }

            buffer.AddRectangle(rect,new Vector2(u1,v1),new Vector2(u2,v2), hId, m_Color);
        }
Esempio n. 5
0
        static void FreeFont(Flood.GUI.Font font)
        {
            //Debug.Print(String.Format("FreeFont {0}", font.FaceName));
            if (font.RendererData == null)
                return;

            //Debug.Print(String.Format("FreeFont {0} - actual free", font.FaceName));
            System.Drawing.Font sysFont = (System.Drawing.Font)font.RendererData;
            if (sysFont == null)
            //    throw new System.InvalidOperationException("Freeing empty font");
                return;

            //sysFont.Dispose();
            font.RendererData = null;
        }
Esempio n. 6
0
 protected override void Render(Flood.GUI.Skins.Skin skin)
 {
     skin.Renderer.DrawColor = TextRunProperties.Foreground;
     skin.Renderer.RenderText(skin.DefaultFont, new Vector2i(0,0), Text);
 }
Esempio n. 7
0
        protected override void Render(Flood.GUI.Skins.Skin skin)
        {
            if (DateTime.Now.Millisecond < 500)
                return;

            var location = new TextLocation(textAnchor.Line,textAnchor.Column);
            var charPos = TextView.TextLayer.GetTextLocationPosition(location);

            var lineHeight = Skin.DefaultFont.Size;

            skin.Renderer.DrawColor = new Color(0,0,0,255);
            skin.Renderer.DrawFilledRect(new Rectangle((int)charPos.X,(int)charPos.Y,1,lineHeight));
        }
Esempio n. 8
0
 public override void RenderText(Flood.GUI.Font font, System.Drawing.Point position, System.String text)
 {
     Flood.GUI.Texture texture = TextRenderer.StringToTexture(text, font, this); // renders string on the texture
        var rect = new System.Drawing.Rectangle(position.X, position.Y, texture.Width, texture.Height);
        DrawTexturedRect(texture, rect,0,0,1,1);
 }
Esempio n. 9
0
 public static System.Drawing.Point MeasureText(System.String text, Flood.GUI.Font font)
 {
     System.Drawing.Font sysFont = ConvertFont(font);
     System.Drawing.SizeF size = m_Graphics.MeasureString(text, sysFont, System.Drawing.Point.Empty, m_StringFormat);
     return System.Drawing.Point((int)floor(size.Width+0.5), (int)floor(size.Height+0.5));
 }
Esempio n. 10
0
 public override System.Drawing.Point MeasureText(Flood.GUI.Font font, System.String text)
 {
     return TextRenderer.MeasureText(text,font);
 }
Esempio n. 11
0
        public override System.Drawing.Color PixelColor(Flood.GUI.Texture texture, System.UInt32 x, System.UInt32 y, System.Drawing.Color defaultColor)
        {
            if(texture.RendererData == null){
                return defaultColor;
            }

            ImageHandle iHandle;
            var hId = (uint)texture.RendererData;
            iHandle.setId(hId);

            Image img = iHandle.Resolve();

            System.Drawing.Color pixel;
            long offset = 4 * (x + y * texture.Width);
            std.vector<uint8>& data = img.getBuffer();

            pixel = System.Drawing.Color.FromArgb(data[offset + 3], data[offset + 0], data[offset + 1], data[offset + 2]);

            // Retrieving the entire texture for a single pixel read
            // is kind of a waste - maybe cache this pointer in the texture
            // data and then release later on? It's never called during runtime
            // - only during initialization.
            return pixel;
        }
Esempio n. 12
0
 public override void LoadTextureBitmap(Flood.GUI.Texture t, System.Drawing.Bitmap bitmap)
 {
     TextureUtil.LoadTextureInternal(t,bitmap);
 }
Esempio n. 13
0
        public override void LoadTexture(Flood.GUI.Texture t)
        {
            var options = new ResourceLoadOptions();
            options.Name = t.Name;
            options.AsynchronousLoad = false;
            uint iHandle = FloodEngine.GetEngine().GetResourceManager().LoadResource(options);

            if(iHandle == HandleInvalid){
                t.RendererData = null;
                return;
            }

            Image img = iHandle.Resolve();
            t.Width =	(int)img.GetWidth();
            t.Height = (int)img.GetHeight();
            t.RendererData = iHandle;
        }
Esempio n. 14
0
        public override void FreeTexture(Flood.GUI.Texture t)
        {
            if (t.RendererData == null)
                return;

            ImageHandle iHandle;
            HandleId hId = (HandleId)t.RendererData;
            iHandle.setId(hId);

            Image* img = iHandle.Resolve();

               FloodEngine.GetEngine().GetResourceManager().RemoveResource(img);
        }
Esempio n. 15
0
        public static void LoadTextureInternal(Flood.GUI.Texture t, uint8* data, int size)
        {
            ImageHandle iHandle = ImageCreate(AllocatorGetHeap(),t.Width,t.Height, PixelFormat.B8G8R8A8);

            //array to vector
            std.vector<byte> buffer(size);
            std.copy(data, data+size, buffer.begin());

            iHandle.Resolve().setBuffer(buffer);
            t.RendererData = iHandle.getId();
            iHandle.addReference(); //hackzito
        }
Esempio n. 16
0
        //TODO use scale, remove renderer
        public static Flood.GUI.Texture StringToTexture(System.String text, Flood.GUI.Font font, Flood.GUI.Renderers.Renderer renderer)
        {
            System.Drawing.Brush brush = System.Drawing.Brushes.White;
            Flood.GUI.Texture texture = GetTexture(font,text);
            if(texture != null){ //TODO Check stringFormat
                return texture;
            }

            System.Drawing.Font sysFont = ConvertFont(font);

            System.Drawing.Point size = TextRenderer.MeasureText(sysFont, text, m_StringFormat);
            texture = new Flood.GUI.Texture(renderer);
            texture.Width = size.X;
            texture.Height = size.Y;

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(size.X, size.Y, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            System.Drawing.Graphics gfx = System.Drawing.Graphics.FromImage(bmp);

            // NOTE:    TextRenderingHint.AntiAliasGridFit looks sharper and in most cases better
            //          but it comes with a some problems.
            //
            //          1.  Graphic.MeasureString and format.MeasureCharacterRanges
            //              seem to return wrong values because of this.
            //
            //          2.  While typing the kerning changes in random places in the sentence.
            //
            //          Until 1st problem is fixed we should use TextRenderingHint.AntiAlias...  :-(

            gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            gfx.Clear(System.Drawing.Color.Transparent);

            gfx.DrawString(text, sysFont, brush, System.Drawing.Point.Empty, m_StringFormat); // render text on the bitmap
            TextureUtil.LoadTextureInternal(texture,bmp);
            AddTexture(font,text,texture);
            return texture;
        }
Esempio n. 17
0
 public void Initialize(Flood.GUI.Controls.Canvas c)
 {
     m_Canvas = c;
 }
Esempio n. 18
0
 static void AddTexture(Flood.GUI.Font font, System.String text, Flood.GUI.Texture texture)
 {
     System.Tuple<System.String, Flood.GUI.Font> key = new System.Tuple<System.String, Flood.GUI.Font>(text, font);
     m_StringCache.Add(key,texture);
 }
Esempio n. 19
0
 public void Resize(Flood.Settings settings)
 {
     EditorWindow.SetSize(settings.Width, settings.Height);
 }
Esempio n. 20
0
 static System.Drawing.Font ConvertFont(Flood.GUI.Font font)
 {
     System.Drawing.Font sysFont = (System.Drawing.Font)font.RendererData;
     if (sysFont == null || Math.Abs(font.RealSize - font.Size /** Scale*/) > 2)
     {
         FreeFont(font);
         LoadFont(font);
         sysFont = (System.Drawing.Font)font.RendererData;
     }
     return sysFont;
 }
Esempio n. 21
0
        protected override void Layout(Flood.GUI.Skins.Skin skin)
        {
            double y = 0;
            foreach (var control in Children)
            {
                if (!control.IsVisible)
                    continue;

                control.SetPosition(0,(int)y);
                y += heightTree.DefaultLineHeight;
            }
        }
Esempio n. 22
0
 protected override void Layout(Flood.GUI.Skins.Skin skin)
 {
     base.Layout(skin);
     var currentX = 0;
     foreach (var child in Children)
     {
         child.X = currentX;
         currentX += child.Width;
     }
     SizeToChildren();
 }