Example #1
0
        public static odl.Rect CreateRect(IntPtr Self)
        {
            int x = 0,
                y = 0,
                w = 0,
                h = 0;

            if (Ruby.IVarIs(Self, "@x", "Float"))
            {
                x = (byte)Ruby.Float.RoundFromPtr(Ruby.GetIVar(Self, "@x"));
            }
            else
            {
                x = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Self, "@x"));
            }
            if (Ruby.IVarIs(Self, "@y", "Float"))
            {
                y = (byte)Ruby.Float.RoundFromPtr(Ruby.GetIVar(Self, "@y"));
            }
            else
            {
                y = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Self, "@y"));
            }
            if (Ruby.IVarIs(Self, "@width", "Float"))
            {
                w = (byte)Ruby.Float.RoundFromPtr(Ruby.GetIVar(Self, "@width"));
            }
            else
            {
                w = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Self, "@width"));
            }
            if (Ruby.IVarIs(Self, "@height", "Float"))
            {
                h = (byte)Ruby.Float.RoundFromPtr(Ruby.GetIVar(Self, "@height"));
            }
            else
            {
                h = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Self, "@height"));
            }
            return(new odl.Rect(x, y, w, h));
        }
Example #2
0
        public static odl.Tone CreateTone(IntPtr Self)
        {
            short R   = 0,
                  G   = 0,
                  B   = 0;
            byte Grey = 0;

            if (Ruby.IVarIs(Self, "@red", "Float"))
            {
                R = (short)Ruby.Float.RoundFromPtr(Ruby.GetIVar(Self, "@red"));
            }
            else
            {
                R = (short)Ruby.Integer.FromPtr(Ruby.GetIVar(Self, "@red"));
            }
            if (Ruby.IVarIs(Self, "@green", "Float"))
            {
                G = (short)Ruby.Float.RoundFromPtr(Ruby.GetIVar(Self, "@green"));
            }
            else
            {
                G = (short)Ruby.Integer.FromPtr(Ruby.GetIVar(Self, "@green"));
            }
            if (Ruby.IVarIs(Self, "@blue", "Float"))
            {
                B = (short)Ruby.Float.RoundFromPtr(Ruby.GetIVar(Self, "@blue"));
            }
            else
            {
                B = (short)Ruby.Integer.FromPtr(Ruby.GetIVar(Self, "@blue"));
            }
            if (Ruby.IVarIs(Self, "@grey", "Float"))
            {
                Grey = (byte)Ruby.Float.RoundFromPtr(Ruby.GetIVar(Self, "@grey"));
            }
            else
            {
                Grey = (byte)Ruby.Integer.FromPtr(Ruby.GetIVar(Self, "@grey"));
            }
            return(new odl.Tone(R, G, B, Grey));
        }
Example #3
0
        public static odl.Color CreateColor(IntPtr Self)
        {
            byte R = 0,
                 G = 0,
                 B = 0,
                 A = 0;

            if (Ruby.IVarIs(Self, "@red", "Float"))
            {
                R = (byte)Ruby.Float.RoundFromPtr(Ruby.GetIVar(Self, "@red"));
            }
            else
            {
                R = (byte)Ruby.Integer.FromPtr(Ruby.GetIVar(Self, "@red"));
            }
            if (Ruby.IVarIs(Self, "@green", "Float"))
            {
                G = (byte)Ruby.Float.RoundFromPtr(Ruby.GetIVar(Self, "@green"));
            }
            else
            {
                G = (byte)Ruby.Integer.FromPtr(Ruby.GetIVar(Self, "@green"));
            }
            if (Ruby.IVarIs(Self, "@blue", "Float"))
            {
                B = (byte)Ruby.Float.RoundFromPtr(Ruby.GetIVar(Self, "@blue"));
            }
            else
            {
                B = (byte)Ruby.Integer.FromPtr(Ruby.GetIVar(Self, "@blue"));
            }
            if (Ruby.IVarIs(Self, "@alpha", "Float"))
            {
                A = (byte)Ruby.Float.RoundFromPtr(Ruby.GetIVar(Self, "@alpha"));
            }
            else
            {
                A = (byte)Ruby.Integer.FromPtr(Ruby.GetIVar(Self, "@alpha"));
            }
            return(new odl.Color(R, G, B, A));
        }
Example #4
0
        static IntPtr blt(IntPtr Self, IntPtr Args)
        {
            GuardDisposed(Self);
            Ruby.Array.Expect(Args, 1, 3, 4, 6, 9);
            int dx = 0,
                dy = 0,
                dw = 0,
                dh = 0;

            odl.Bitmap srcbmp = null;
            int        sx     = 0,
                       sy     = 0,
                       sw     = 0,
                       sh     = 0;
            long len          = Ruby.Array.Length(Args);

            if (len == 1) // bmp
            {
                Ruby.Array.Expect(Args, 0, "Bitmap");
                srcbmp = BitmapDictionary[Ruby.Array.Get(Args, 0)];
                dw     = srcbmp.Width;
                dh     = srcbmp.Height;
                sw     = srcbmp.Width;
                sh     = srcbmp.Height;
            }
            else if (len == 3) // destrect, bmp, srcrect
            {
                Ruby.Array.Expect(Args, 0, "Rect");
                Ruby.Array.Expect(Args, 1, "Bitmap");
                Ruby.Array.Expect(Args, 2, "Rect");

                if (Ruby.IVarIs(Ruby.Array.Get(Args, 0), "@x", "Float"))
                {
                    dx = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@x"));
                }
                else
                {
                    dx = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@x"));
                }
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 0), "@y", "Float"))
                {
                    dy = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@y"));
                }
                else
                {
                    dy = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@y"));
                }
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 0), "@width", "Float"))
                {
                    dw = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@width"));
                }
                else
                {
                    dw = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@width"));
                }
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 0), "@height", "Float"))
                {
                    dh = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@height"));
                }
                else
                {
                    dh = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@height"));
                }
                srcbmp = BitmapDictionary[Ruby.Array.Get(Args, 1)];
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 2), "@x", "Float"))
                {
                    sx = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 2), "@x"));
                }
                else
                {
                    sx = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 2), "@x"));
                }
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 2), "@y", "Float"))
                {
                    sy = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 2), "@y"));
                }
                else
                {
                    sy = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 2), "@y"));
                }
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 2), "@width", "Float"))
                {
                    sw = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 2), "@width"));
                }
                else
                {
                    sw = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 2), "@width"));
                }
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 2), "@height", "Float"))
                {
                    sh = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 2), "@height"));
                }
                else
                {
                    sh = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 2), "@height"));
                }
            }
            else if (len == 4) // dx, dy, bmp, srcrect
            {
                Ruby.Array.Expect(Args, 0, "Integer");
                Ruby.Array.Expect(Args, 1, "Integer");
                Ruby.Array.Expect(Args, 2, "Bitmap");
                Ruby.Array.Expect(Args, 3, "Rect");
                dx     = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 0));
                dy     = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 1));
                srcbmp = BitmapDictionary[Ruby.Array.Get(Args, 2)];
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 3), "@x", "Float"))
                {
                    sx = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 3), "@x"));
                }
                else
                {
                    sx = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 3), "@x"));
                }
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 3), "@y", "Float"))
                {
                    sy = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 3), "@y"));
                }
                else
                {
                    sy = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 3), "@y"));
                }
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 3), "@width", "Float"))
                {
                    sw = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 3), "@width"));
                }
                else
                {
                    sw = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 3), "@width"));
                }
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 3), "@height", "Float"))
                {
                    sh = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 3), "@height"));
                }
                else
                {
                    sh = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 3), "@height"));
                }
                dw = sw;
                dh = sh;
            }
            else if (len == 6) // dx, dy, dw, dh, bmp, srcrect
            {
                Ruby.Array.Expect(Args, 0, "Integer");
                Ruby.Array.Expect(Args, 1, "Integer");
                Ruby.Array.Expect(Args, 2, "Integer");
                Ruby.Array.Expect(Args, 3, "Integer");
                Ruby.Array.Expect(Args, 4, "Bitmap");
                Ruby.Array.Expect(Args, 5, "Rect");
                dx     = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 0));
                dy     = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 1));
                dw     = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 2));
                dh     = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 3));
                srcbmp = BitmapDictionary[Ruby.Array.Get(Args, 4)];
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 5), "@x", "Float"))
                {
                    sx = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 5), "@x"));
                }
                else
                {
                    sx = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 5), "@x"));
                }
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 5), "@y", "Float"))
                {
                    sy = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 5), "@y"));
                }
                else
                {
                    sy = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 5), "@y"));
                }
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 5), "@width", "Float"))
                {
                    sw = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 5), "@width"));
                }
                else
                {
                    sw = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 5), "@width"));
                }
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 5), "@height", "Float"))
                {
                    sh = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 5), "@height"));
                }
                else
                {
                    sh = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 5), "@height"));
                }
            }
            else if (len == 9) // dx, dy, dw, dh, bmp, sx, sy, sw, sh
            {
                Ruby.Array.Expect(Args, 0, "Integer");
                Ruby.Array.Expect(Args, 1, "Integer");
                Ruby.Array.Expect(Args, 2, "Integer");
                Ruby.Array.Expect(Args, 3, "Integer");
                Ruby.Array.Expect(Args, 4, "Bitmap");
                Ruby.Array.Expect(Args, 5, "Integer");
                Ruby.Array.Expect(Args, 6, "Integer");
                Ruby.Array.Expect(Args, 7, "Integer");
                Ruby.Array.Expect(Args, 8, "Integer");
                dx     = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 0));
                dy     = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 1));
                dw     = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 2));
                dh     = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 3));
                srcbmp = BitmapDictionary[Ruby.Array.Get(Args, 4)];
                sx     = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 5));
                sy     = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 6));
                sw     = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 7));
                sh     = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 8));
            }
            AutoUnlock(Self);
            BitmapDictionary[Self].Build(dx, dy, dw, dh, srcbmp, sx, sy, sw, sh);
            AutoLock(Self);
            return(Ruby.True);
        }
Example #5
0
        static IntPtr fill_rect(IntPtr Self, IntPtr Args)
        {
            GuardDisposed(Self);
            Ruby.Array.Expect(Args, 2, 5);
            int x = 0,
                y = 0,
                w = 0,
                h = 0;

            odl.Color c   = null;
            long      len = Ruby.Array.Length(Args);

            if (len == 2)
            {
                Ruby.Array.Expect(Args, 0, "Rect");
                Ruby.Array.Expect(Args, 1, "Color");
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 0), "@x", "Float"))
                {
                    x = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@x"));
                }
                else
                {
                    x = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@x"));
                }
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 0), "@y", "Float"))
                {
                    y = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@y"));
                }
                else
                {
                    y = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@y"));
                }
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 0), "@width", "Float"))
                {
                    w = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@width"));
                }
                else
                {
                    w = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@width"));
                }
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 0), "@height", "Float"))
                {
                    h = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@height"));
                }
                else
                {
                    h = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@height"));
                }
                c = Color.CreateColor(Ruby.Array.Get(Args, 1));
            }
            else if (len == 5)
            {
                Ruby.Array.Expect(Args, 0, "Integer");
                Ruby.Array.Expect(Args, 1, "Integer");
                Ruby.Array.Expect(Args, 2, "Integer");
                Ruby.Array.Expect(Args, 3, "Integer");
                Ruby.Array.Expect(Args, 4, "Color");
                x = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 0));
                y = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 1));
                w = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 2));
                h = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 3));
                c = Color.CreateColor(Ruby.Array.Get(Args, 4));
            }
            AutoUnlock(Self);
            BitmapDictionary[Self].FillRect(x, y, w, h, c);
            AutoLock(Self);
            return(Ruby.True);
        }
Example #6
0
        static IntPtr initialize(IntPtr Self, IntPtr Args)
        {
            Ruby.Array.Expect(Args, 0, 1, 4);
            int x    = 0,
                y    = 0,
                w    = 0,
                h    = 0;
            long len = Ruby.Array.Length(Args);

            if (len == 0)
            {
                w = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(System.Module, "@width"));
                h = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(System.Module, "@height"));
            }
            else if (len == 1)
            {
                Ruby.Array.Expect(Args, 0, "Rect");
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 0), "@x", "Float"))
                {
                    x = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@x"));
                }
                else
                {
                    x = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@x"));
                }
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 0), "@y", "Float"))
                {
                    y = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@y"));
                }
                else
                {
                    y = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@y"));
                }
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 0), "@width", "Float"))
                {
                    w = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@width"));
                }
                else
                {
                    w = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@width"));
                }
                if (Ruby.IVarIs(Ruby.Array.Get(Args, 0), "@height", "Float"))
                {
                    h = Ruby.Float.RoundFromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@height"));
                }
                else
                {
                    h = (int)Ruby.Integer.FromPtr(Ruby.GetIVar(Ruby.Array.Get(Args, 0), "@height"));
                }
            }
            else if (len == 4)
            {
                if (Ruby.Array.Is(Args, 0, "Float"))
                {
                    x = Ruby.Float.RoundFromPtr(Ruby.Array.Get(Args, 0));
                }
                else
                {
                    Ruby.Array.Expect(Args, 0, "Integer");
                    x = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 0));
                }
                if (Ruby.Array.Is(Args, 1, "Float"))
                {
                    y = Ruby.Float.RoundFromPtr(Ruby.Array.Get(Args, 1));
                }
                else
                {
                    Ruby.Array.Expect(Args, 1, "Integer");
                    y = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 1));
                }
                if (Ruby.Array.Is(Args, 2, "Float"))
                {
                    w = Ruby.Float.RoundFromPtr(Ruby.Array.Get(Args, 2));
                }
                else
                {
                    Ruby.Array.Expect(Args, 2, "Integer");
                    w = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 2));
                }
                if (Ruby.Array.Is(Args, 3, "Float"))
                {
                    h = Ruby.Float.RoundFromPtr(Ruby.Array.Get(Args, 3));
                }
                else
                {
                    Ruby.Array.Expect(Args, 3, "Integer");
                    h = (int)Ruby.Integer.FromPtr(Ruby.Array.Get(Args, 3));
                }
            }
            Ruby.SetIVar(Self, "@x", Ruby.Integer.ToPtr(x));
            Ruby.SetIVar(Self, "@y", Ruby.Integer.ToPtr(y));
            Ruby.SetIVar(Self, "@width", Ruby.Integer.ToPtr(w));
            Ruby.SetIVar(Self, "@height", Ruby.Integer.ToPtr(h));
            Ruby.SetIVar(Self, "@ox", Ruby.Integer.ToPtr(0));
            Ruby.SetIVar(Self, "@oy", Ruby.Integer.ToPtr(0));
            Ruby.SetIVar(Self, "@z", Ruby.Integer.ToPtr(0));
            IntPtr color = Color.CreateColor(odl.Color.ALPHA);

            Ruby.SetIVar(color, "@__viewport__", Self);
            Ruby.SetIVar(Self, "@color", color);
            Ruby.SetIVar(Self, "@disposed", Ruby.False);

            odl.Viewport vp = new odl.Viewport(x, y, w, h);

            if (ViewportDictionary.ContainsKey(Self))
            {
                ViewportDictionary[Self].Dispose();
                ViewportDictionary.Remove(Self);
            }
            ViewportDictionary.Add(Self, vp);
            return(Self);
        }