Example #1
0
 public void DrawDefaultGrid(Bounds2 clipping_bounds, float step)
 {
     this.GL.Context.Enable(EnableMode.Blend);             //(EnableMode)4);
     //this.GL.Context.SetBlendFunc(new BlendFunc((BlendFuncMode)0, (BlendFuncFactor)4, (BlendFuncFactor)1));
     this.GL.Context.SetBlendFunc(new BlendFunc(BlendFuncMode.Add, BlendFuncFactor.SrcAlpha, BlendFuncFactor.One));
     this.DrawDefaultGrid(clipping_bounds, new Vector2(step), Colors.Grey30 * 0.5f, Colors.Black);
 }
Example #2
0
        public Bounds2 OutrageousYVCoordFlip()
        {
            Bounds2 result = this;

            result.Min.Y = 1f - result.Min.Y;
            result.Max.Y = 1f - result.Max.Y;
            return(result);
        }
Example #3
0
        public void SetViewFromViewport()
        {
            Bounds2 viewportf = this.GL.GetViewportf();

            Common.Assert(viewportf.Size.Y != 0f);
            this.SetViewFromHeightAndCenter(viewportf.Size.Y, viewportf.Center);
            this.m_data.m_aspect = viewportf.Aspect;
        }
Example #4
0
 public void MakeBox(Bounds2 bounds)
 {
     this.Planes    = new Plane2[4];
     this.Planes[0] = new Plane2(bounds.Point00, -Math._10);
     this.Planes[1] = new Plane2(bounds.Point10, -Math._01);
     this.Planes[2] = new Plane2(bounds.Point11, Math._10);
     this.Planes[3] = new Plane2(bounds.Point01, Math._01);
     this.m_sphere  = new Sphere2(bounds.Center, bounds.Size.Length() * 0.5f);
 }
Example #5
0
        public Bounds2 OutrageousYTopBottomSwap()
        {
            Bounds2 result = this;
            float   y      = this.Min.Y;

            result.Min.Y = result.Max.Y;
            result.Max.Y = y;
            return(result);
        }
Example #6
0
        public Bounds2 Bounds2()
        {
            Bounds2 result = new Bounds2(this.Point00, this.Point00);

            result.Add(this.Point10);
            result.Add(this.Point01);
            result.Add(this.Point11);
            return(result);
        }
Example #7
0
 public void DrawDefaultGrid(Bounds2 clipping_bounds, Vector2 step, Vector4 rulers_color, Vector4 axis_color)
 {
     this.ShaderPush();
     this.SetColor(rulers_color);
     this.DrawRulers(clipping_bounds, step.X, step.Y);
     this.GL.Context.Disable(EnableMode.Blend);            //(EnableMode)4);
     this.SetColor(axis_color);
     this.DrawAxis(clipping_bounds, 2f);
     this.ShaderPop();
 }
Example #8
0
        public void SetFromCamera2D(Camera2D cam2d)
        {
            Vector2 vector = cam2d.Y();
            float   num    = vector.Length() / FMath.Tan(0.5f * this.Frustum.FovY);

            this.Eye              = cam2d.Center.Xy0 + num * Math._001;
            this.Center           = cam2d.Center.Xy0;
            this.Up               = vector.Xy0.Normalize();
            this.m_last_2d_bounds = cam2d.CalcBounds();
        }
Example #9
0
 public void DrawBounds2Fill(Bounds2 bounds)
 {
     this.ShaderPush();
     this.ImmBegin((DrawMode)4, 4u);
     this.ImmVertex(new DrawHelpers.Vertex(bounds.Point01.Xy01, this.m_current_color));
     this.ImmVertex(new DrawHelpers.Vertex(bounds.Point00.Xy01, this.m_current_color));
     this.ImmVertex(new DrawHelpers.Vertex(bounds.Point11.Xy01, this.m_current_color));
     this.ImmVertex(new DrawHelpers.Vertex(bounds.Point10.Xy01, this.m_current_color));
     this.ImmEnd();
     this.ShaderPop();
 }
Example #10
0
        public void AddSprite(Vector2 bottom_left_start_pos, Vector2 x, Bounds2 uv_bounds)
        {
            Vector2 vector  = uv_bounds.Size.Abs() * this.m_current_texture_info.TextureSizef;
            Vector2 vector2 = Math.Perp(x) * vector.Y / vector.X;

            this.m_v0 = new Vector4(bottom_left_start_pos, uv_bounds.Point00);
            this.m_v1 = new Vector4(bottom_left_start_pos + x, uv_bounds.Point10);
            this.m_v2 = new Vector4(bottom_left_start_pos + vector2, uv_bounds.Point01);
            this.m_v3 = new Vector4(bottom_left_start_pos + x + vector2, uv_bounds.Point11);
            this.add_quad();
        }
Example #11
0
 public void DrawBounds2(Bounds2 bounds)
 {
     this.ShaderPush();
     this.ImmBegin(DrawMode.LineStrip /*(DrawMode)2*/, 5u);
     this.ImmVertex(new DrawHelpers.Vertex(bounds.Point00.Xy01, this.m_current_color));
     this.ImmVertex(new DrawHelpers.Vertex(bounds.Point10.Xy01, this.m_current_color));
     this.ImmVertex(new DrawHelpers.Vertex(bounds.Point11.Xy01, this.m_current_color));
     this.ImmVertex(new DrawHelpers.Vertex(bounds.Point01.Xy01, this.m_current_color));
     this.ImmVertex(new DrawHelpers.Vertex(bounds.Point00.Xy01, this.m_current_color));
     this.ImmEnd();
     this.ShaderPop();
 }
Example #12
0
        public Bounds2 CalcBounds()
        {
            Vector2 vector  = this.X();
            Vector2 vector2 = this.Y();
            Vector2 center  = this.Center;
            Bounds2 result  = new Bounds2(center, center);

            result.Add(center - vector - vector2);
            result.Add(center + vector - vector2);
            result.Add(center + vector + vector2);
            result.Add(center - vector + vector2);
            return(result);
        }
Example #13
0
        public Bounds2 DrawTextDebug(string str, Vector2 bottom_left_start_pos, float char_height, bool draw = true, SpriteRenderer.ISpriteShader shader = null)
        {
            if (null == shader)
            {
                shader = this.m_default_font_shader;
            }
            float   num     = char_height / (float)EmbeddedDebugFontData.CharSizei.Y;
            Vector2 vector  = new Vector2(-1f, 1f);
            Vector2 vector2 = vector * num;
            TRS     tRS     = default(TRS);

            tRS.R = Math._10;
            tRS.S = EmbeddedDebugFontData.CharSizef * num;
            tRS.T = bottom_left_start_pos;
            Vector2 max = bottom_left_start_pos;
            float   x   = tRS.T.X;

            if (draw)
            {
                this.DefaultFontShader.SetUVTransform(ref Math.UV_TransformFlipV);
                this.BeginSprites(this.m_embedded_font_texture_info, this.DefaultFontShader, str.Length);
            }
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == '\n')
                {
                    tRS.T  -= new Vector2(0f, tRS.S.Y + vector2.Y);
                    tRS.T.X = x;
                }
                else
                {
                    if (draw)
                    {
                        int num2 = (int)(str[i] - ' ');
                        if (num2 < 0 || num2 >= EmbeddedDebugFontData.NumChars)
                        {
                            num2 = 31;
                        }
                        this.AddSprite(ref tRS, new Vector2i(num2, 0));
                    }
                    tRS.T += new Vector2(tRS.S.X + vector2.X, 0f);
                    max.X  = FMath.Max(tRS.T.X, max.X);
                    max.Y  = FMath.Min(tRS.T.Y, max.Y);
                }
            }
            if (draw)
            {
                this.EndSprites();
            }
            return(Bounds2.SafeBounds(bottom_left_start_pos + new Vector2(0f, tRS.S.Y), max));
        }
Example #14
0
        public void DrawAxis(Bounds2 clipping_bounds, float thickness)
        {
            this.GL.Context.SetLineWidth(thickness);
            float num  = 0f;
            float num2 = 0f;

            this.ShaderPush();
            this.ImmBegin((DrawMode)1, 4u);
            this.ImmVertex(new Vector2(clipping_bounds.Min.X, num2));
            this.ImmVertex(new Vector2(clipping_bounds.Max.X, num2));
            this.ImmVertex(new Vector2(num, clipping_bounds.Min.Y));
            this.ImmVertex(new Vector2(num, clipping_bounds.Max.Y));
            this.ImmEnd();
            this.ShaderPop();
            this.GL.Context.SetLineWidth(1f);
        }
Example #15
0
        public Bounds2 Intersection(Bounds2 bounds)
        {
            Vector2 vector  = this.Min.Max(bounds.Min);
            Vector2 vector2 = this.Max.Min(bounds.Max);
            Vector2 vector3 = vector2 - vector;
            Bounds2 result;

            if (vector3.X < 0f || vector3.Y < 0f)
            {
                result = Bounds2.Zero;
            }
            else
            {
                result = new Bounds2(vector, vector2);
            }
            return(result);
        }
Example #16
0
        public Bounds2 CalcBounds()
        {
            Bounds2 result;

            if (this.Size() == 0u)
            {
                result = Bounds2.Zero;
            }
            else
            {
                Bounds2 bounds = new Bounds2(this.GetPoint(0), this.GetPoint(0));
                for (int num = 1; num != (int)this.Size(); num++)
                {
                    bounds.Add(this.GetPoint(num));
                }
                result = bounds;
            }
            return(result);
        }
Example #17
0
 public void DrawRulers(Bounds2 bounds, float step_x, float step_y)
 {
     step_x = FMath.Max(step_x, 0f);
     step_y = FMath.Max(step_y, 0f);
     if (step_x >= 1.401298E-45f)
     {
         if (step_y >= 1.401298E-45f)
         {
             float x    = bounds.Min.X;
             float x2   = bounds.Max.X;
             float y    = bounds.Min.Y;
             float y2   = bounds.Max.Y;
             int   num  = (int)(x / step_x);
             int   num2 = (int)(x2 / step_x);
             int   num3 = (int)(y / step_y);
             int   num4 = (int)(y2 / step_y);
             this.ShaderPush();
             bool flag  = num2 - num + 1 < 1000;
             bool flag2 = num4 - num3 + 1 < 1000;
             this.ImmBegin((DrawMode)1, (uint)((flag ? ((num2 - num + 1) * 2) : 0) + (flag2 ? ((num4 - num3 + 1) * 2) : 0)));
             if (flag)
             {
                 for (int i = num; i <= num2; i++)
                 {
                     this.ImmVertex(new Vector2((float)i * step_x, y));
                     this.ImmVertex(new Vector2((float)i * step_x, y2));
                 }
             }
             if (flag2)
             {
                 for (int i = num3; i <= num4; i++)
                 {
                     this.ImmVertex(new Vector2(x, (float)i * step_y));
                     this.ImmVertex(new Vector2(x2, (float)i * step_y));
                 }
             }
             this.ImmEnd();
             this.ShaderPop();
         }
     }
 }
Example #18
0
        public Bounds2 DrawTextWithFontMap(string str, Vector2 bottom_left_start_pos, float char_height, bool draw, FontMap fontmap, SpriteRenderer.ISpriteShader shader)
        {
            float   num     = char_height / fontmap.CharPixelHeight;
            Vector2 vector  = new Vector2(1f, 1f);
            Vector2 vector2 = vector * num;
            Vector2 vector3 = bottom_left_start_pos;
            Vector2 max     = bottom_left_start_pos;
            float   x       = bottom_left_start_pos.X;

            if (draw)
            {
                shader.SetUVTransform(ref Math.UV_TransformFlipV);
                this.BeginSprites(new TextureInfo(fontmap.Texture), shader, str.Length);
            }
            for (int i = 0; i < str.Length; i++)
            {
                FontMap.CharData charData;
                if (str[i] == '\n')
                {
                    vector3  -= new Vector2(0f, char_height + vector2.Y);
                    vector3.X = x;
                }
                else if (fontmap.TryGetCharData(str[i], out charData))
                {
                    Vector2 vector4 = charData.PixelSize * num;
                    if (draw)
                    {
                        this.AddSprite(vector3, new Vector2(vector4.X, 0f), charData.UV);
                    }
                    vector3 += new Vector2(vector4.X + vector2.X, 0f);
                    max.X    = FMath.Max(vector3.X, max.X);
                    max.Y    = FMath.Min(vector3.Y, max.Y);
                }
            }
            if (draw)
            {
                this.EndSprites();
            }
            return(Bounds2.SafeBounds(bottom_left_start_pos + new Vector2(0f, char_height), max));
        }
Example #19
0
        public float GetPixelSize()
        {
            Bounds2 viewportf = this.GL.GetViewportf();

            return(this.m_last_2d_bounds.Size.X * 0.5f / (viewportf.Size.X * 0.5f));
        }
Example #20
0
        public float GetPixelSize()
        {
            Bounds2 viewportf = this.GL.GetViewportf();

            return(this.X().Length() / (viewportf.Size.X * 0.5f));
        }
Example #21
0
 public void Add(Bounds2 bounds)
 {
     this.Add(bounds.Min);
     this.Add(bounds.Max);
 }
Example #22
0
 public TRS(Bounds2 a_bounds)
 {
     this.T  = a_bounds.Min;
     this.R  = Math._10;
     this._S = a_bounds.Size;
 }
Example #23
0
 public bool Overlaps(Bounds2 bounds)
 {
     return(this.Min.X <= bounds.Max.X && bounds.Min.X <= this.Max.X && this.Min.Y <= bounds.Max.Y && bounds.Min.Y <= this.Max.Y);
 }
Example #24
0
        public void Initialize(Font font, string charset, int fontmap_width = 512)
        {
            this.CharSet         = new Dictionary <char, FontMap.CharData>();
            this.CharPixelHeight = (float)font.Metrics.Height;
            Image    image    = null;
            Vector2i vector2i = new Vector2i(0, 0);

            for (int i = 0; i < 2; i++)
            {
                Vector2i a   = new Vector2i(0, 0);
                int      num = 0;
                for (int j = 0; j < charset.Length; j++)
                {
                    if (!this.CharSet.ContainsKey(charset[j]))
                    {
                        Vector2i value = new Vector2i(font.GetTextWidth(charset[j].ToString(), 0, 1), font.Metrics.Height);
                        num = Common.Max(num, value.Y);
                        if (a.X + value.X > fontmap_width)
                        {
                            a.X  = 0;
                            a.Y += num;
                            num  = 0;
                            Common.Assert(value.Y <= fontmap_width);
                        }
                        if (i > 0)
                        {
                            image.DrawText(charset[j].ToString(), new ImageColor(255, 255, 255, 255), font, new ImagePosition(a.X, a.Y));
                            Bounds2 uV = new Bounds2(a.Vector2() / vector2i.Vector2(), (a + value).Vector2() / vector2i.Vector2());
                            uV = uV.OutrageousYVCoordFlip().OutrageousYTopBottomSwap();
                            this.CharSet.Add(charset[j], new FontMap.CharData
                            {
                                UV        = uV,
                                PixelSize = value.Vector2()
                            });
                        }
                        a.X += value.X;
                        if (i == 0)
                        {
                            vector2i.X = Common.Max(vector2i.X, a.X);
                            vector2i.Y = Common.Max(vector2i.Y, a.Y + num);
                        }
                    }
                }
                if (i == 0)
                {
                    //image = new Image((ImageMode)1, new ImageSize(vector2i.X, vector2i.Y), new ImageColor(0, 0, 0, 0));
                    image = new Image(ImageMode.A, new ImageSize(vector2i.X, vector2i.Y), new ImageColor(0, 0, 0, 0));
                    this.CharSet.Clear();
                }
            }
            this.Texture = new Texture2D(image.Size.Width, image.Size.Height, false, (PixelFormat)8);
            this.Texture.SetPixels(0, image.ToBuffer());
            image.Dispose();
            this.m_ascii_char_data       = new FontMap.CharData[FontMap.AsciiCharSet.Length];
            this.m_ascii_char_data_valid = new bool[FontMap.AsciiCharSet.Length];
            for (int j = 0; j < FontMap.AsciiCharSet.Length; j++)
            {
                FontMap.CharData charData;
                this.m_ascii_char_data_valid[j] = this.CharSet.TryGetValue(FontMap.AsciiCharSet[j], out charData);
                this.m_ascii_char_data[j]       = charData;
            }
            font.Dispose();
        }