Exemple #1
0
    public virtual int DrawPoly2(float[] verts, gxtkSurface surf, int srcx, int srcy)
    {
        int n = verts.Length / 4;

        if (n < 1 || n > MAX_VERTS)
        {
            return(0);
        }

        Flush();

        for (int i = 0; i < n; ++i)
        {
            float px = verts[i * 4];
            float py = verts[i * 4 + 1];

            if (_tformed)
            {
                float ppx = px;
                px = ppx * _ix + py * _jx + _tx;
                py = ppx * _iy + py * _jy + _ty;
            }

            _verts[i * 2] = px; _verts[i * 2 + 1] = py; _colors[i] = _color;
        }

        _primType  = 5;
        _primSurf  = null;
        _vertCount = n;

        Flush();

        return(0);
    }
Exemple #2
0
    public virtual int DrawRect(float x, float y, float w, float h)
    {
        if (_primType != 4 || _vertCount == MAX_VERTS || _primSurf != null)
        {
            Flush();
            _primType = 4;
            _primSurf = null;
        }

        float x0 = x, x1 = x + w, x2 = x + w, x3 = x;
        float y0 = y, y1 = y, y2 = y + h, y3 = y + h;

        if (_tformed)
        {
            float tx0 = x0, tx1 = x1, tx2 = x2, tx3 = x3;
            x0 = tx0 * _ix + y0 * _jx + _tx; y0 = tx0 * _iy + y0 * _jy + _ty;
            x1 = tx1 * _ix + y1 * _jx + _tx; y1 = tx1 * _iy + y1 * _jy + _ty;
            x2 = tx2 * _ix + y2 * _jx + _tx; y2 = tx2 * _iy + y2 * _jy + _ty;
            x3 = tx3 * _ix + y3 * _jx + _tx; y3 = tx3 * _iy + y3 * _jy + _ty;
        }

        int i = _vertCount * 2, j = _vertCount;

        _verts[i]     = x0; _verts[i + 1] = y0; _colors[j] = _color;
        _verts[i + 2] = x1; _verts[i + 3] = y1; _colors[j + 1] = _color;
        _verts[i + 4] = x2; _verts[i + 5] = y2; _colors[j + 2] = _color;
        _verts[i + 6] = x3; _verts[i + 7] = y3; _colors[j + 3] = _color;

        _vertCount += 4;

        return(0);
    }
Exemple #3
0
    public virtual int DrawPoly2(float[] verts, gxtkSurface surf, int srcx, int srcy)
    {
        int n = verts.Length / 2;

        if (n < 1 || n > MAX_VERTS)
        {
            return(0);
        }

        Flush();
        primType = 5;
        primTex  = null;

        for (int i = 0; i < n; ++i)
        {
            float px = verts[i * 4];
            float py = verts[i * 4 + 1];

            if (tformed)
            {
                float ppx = px;
                px = ppx * ix + py * jx + tx;
                py = ppx * iy + py * jy + ty;
            }

            vertices[i].Position.X = px; vertices[i].Position.Y = py;
            vertices[i].Color      = color;
        }

        primCount = n;

        Flush();

        return(0);
    }
Exemple #4
0
    public virtual int DrawSurface(gxtkSurface surf, float x, float y)
    {
        if (_primType != 4 || _vertCount == MAX_VERTS || _primSurf != surf)
        {
            Flush();
            _primType = 4;
            _primSurf = surf;
        }

        float w = surf.Width();
        float h = surf.Height();
        float u0 = 0, u1 = 1, v0 = 0, v1 = 1;
        float x0 = x, x1 = x + w, x2 = x + w, x3 = x;
        float y0 = y, y1 = y, y2 = y + h, y3 = y + h;

        if (_tformed)
        {
            float tx0 = x0, tx1 = x1, tx2 = x2, tx3 = x3;
            x0 = tx0 * _ix + y0 * _jx + _tx; y0 = tx0 * _iy + y0 * _jy + _ty;
            x1 = tx1 * _ix + y1 * _jx + _tx; y1 = tx1 * _iy + y1 * _jy + _ty;
            x2 = tx2 * _ix + y2 * _jx + _tx; y2 = tx2 * _iy + y2 * _jy + _ty;
            x3 = tx3 * _ix + y3 * _jx + _tx; y3 = tx3 * _iy + y3 * _jy + _ty;
        }

        int i = _vertCount * 2, j = _vertCount;

        _verts[i + 0] = x0; _verts[i + 1] = y0; _texcs[i + 0] = u0; _texcs[i + 1] = v0; _colors[j + 0] = _color;
        _verts[i + 2] = x1; _verts[i + 3] = y1; _texcs[i + 2] = u1; _texcs[i + 3] = v0; _colors[j + 1] = _color;
        _verts[i + 4] = x2; _verts[i + 5] = y2; _texcs[i + 4] = u1; _texcs[i + 5] = v1; _colors[j + 2] = _color;
        _verts[i + 6] = x3; _verts[i + 7] = y3; _texcs[i + 6] = u0; _texcs[i + 7] = v1; _colors[j + 3] = _color;

        _vertCount += 4;

        return(0);
    }
Exemple #5
0
    public virtual int DrawLine(float x0, float y0, float x1, float y1)
    {
        if (_primType != 2 || _vertCount == MAX_VERTS || _primSurf != null)
        {
            Flush();
            _primType = 2;
            _primSurf = null;
        }

        if (_tformed)
        {
            float tx0 = x0, tx1 = x1;
            x0 = tx0 * _ix + y0 * _jx + _tx; y0 = tx0 * _iy + y0 * _jy + _ty;
            x1 = tx1 * _ix + y1 * _jx + _tx; y1 = tx1 * _iy + y1 * _jy + _ty;
        }

        int i = _vertCount * 2, j = _vertCount;

        _verts[i + 0] = x0; _verts[i + 1] = y0; _colors[j + 0] = _color;
        _verts[i + 2] = x1; _verts[i + 3] = y1; _colors[j + 1] = _color;

        _vertCount += 2;

        return(0);
    }
Exemple #6
0
    public virtual gxtkSurface LoadSurface(String path)
    {
        gxtkSurface surf = new gxtkSurface();

        if (!LoadSurface__UNSAFE__(surf, path))
        {
            return(null);
        }
        return(surf);
    }
Exemple #7
0
    public virtual bool LoadSurface__UNSAFE__(gxtkSurface surface, String path)
    {
        Texture2D texture = BBXnaGame.XnaGame().LoadTexture2D(path);

        if (texture == null)
        {
            return(false);
        }
        surface.SetTexture(texture);
        return(true);
    }
Exemple #8
0
    public virtual int DrawOval(float x, float y, float w, float h)
    {
        Flush();

        float xr = w / 2.0f;
        float yr = h / 2.0f;

        int segs;

        if (_tformed)
        {
            float dx_x = xr * _ix;
            float dx_y = xr * _iy;
            float dx   = (float)Math.Sqrt(dx_x * dx_x + dx_y * dx_y);
            float dy_x = yr * _jx;
            float dy_y = yr * _jy;
            float dy   = (float)Math.Sqrt(dy_x * dy_x + dy_y * dy_y);
            segs = (int)(dx + dy);
        }
        else
        {
            segs = (int)(Math.Abs(xr) + Math.Abs(yr));
        }
        segs = Math.Max(segs, 12) & ~3;
        segs = Math.Min(segs, MAX_VERTS);

        float x0 = x + xr, y0 = y + yr;

        for (int i = 0; i < segs; ++i)
        {
            float th = -(float)i * (float)(Math.PI * 2.0) / (float)segs;

            float px = x0 + (float)Math.Cos(th) * xr;
            float py = y0 - (float)Math.Sin(th) * yr;

            if (_tformed)
            {
                float ppx = px;
                px = ppx * _ix + py * _jx + _tx;
                py = ppx * _iy + py * _jy + _ty;
            }

            _verts[i * 2] = px; _verts[i * 2 + 1] = py; _colors[i] = _color;
        }

        _primType  = 5;
        _primSurf  = null;
        _vertCount = segs;

        Flush();

        return(0);
    }
Exemple #9
0
    public virtual int DrawSurface2(gxtkSurface surf, float x, float y, int srcx, int srcy, int srcw, int srch)
    {
        if (primType != 4 || primCount == MAX_QUADS || surf.texture != primTex)
        {
            Flush();
            primType = 4;
            primTex  = surf.texture;
        }

        float w = surf.Width();
        float h = surf.Height();
        float u0 = srcx / w, u1 = (srcx + srcw) / w;
        float v0 = srcy / h, v1 = (srcy + srch) / h;
        float x0 = x, x1 = x + srcw, x2 = x + srcw, x3 = x;
        float y0 = y, y1 = y, y2 = y + srch, y3 = y + srch;

        if (tformed)
        {
            float tx0 = x0, tx1 = x1, tx2 = x2, tx3 = x3;
            x0 = tx0 * ix + y0 * jx + tx;
            y0 = tx0 * iy + y0 * jy + ty;
            x1 = tx1 * ix + y1 * jx + tx;
            y1 = tx1 * iy + y1 * jy + ty;
            x2 = tx2 * ix + y2 * jx + tx;
            y2 = tx2 * iy + y2 * jy + ty;
            x3 = tx3 * ix + y3 * jx + tx;
            y3 = tx3 * iy + y3 * jy + ty;
        }

        int vp = primCount++ *4;

        vertices[vp].Position.X          = x0; vertices[vp].Position.Y = y0;
        vertices[vp].TextureCoordinate.X = u0; vertices[vp].TextureCoordinate.Y = v0;
        vertices[vp].Color                   = color;
        vertices[vp + 1].Position.X          = x1; vertices[vp + 1].Position.Y = y1;
        vertices[vp + 1].TextureCoordinate.X = u1; vertices[vp + 1].TextureCoordinate.Y = v0;
        vertices[vp + 1].Color               = color;
        vertices[vp + 2].Position.X          = x2; vertices[vp + 2].Position.Y = y2;
        vertices[vp + 2].TextureCoordinate.X = u1; vertices[vp + 2].TextureCoordinate.Y = v1;
        vertices[vp + 2].Color               = color;
        vertices[vp + 3].Position.X          = x3; vertices[vp + 3].Position.Y = y3;
        vertices[vp + 3].TextureCoordinate.X = u0; vertices[vp + 3].TextureCoordinate.Y = v1;
        vertices[vp + 3].Color               = color;

        return(0);
    }
Exemple #10
0
    public virtual int WritePixels2(gxtkSurface surface, int[] pixels, int x, int y, int width, int height, int offset, int pitch)
    {
        Color[] data = new Color[width * height];

        int i = 0;

        for (int py = 0; py < height; ++py)
        {
            int j = offset + py * pitch;
            for (int px = 0; px < width; ++px)
            {
                int argb = pixels[j++];
                data[i++] = new Color((argb >> 16) & 0xff, (argb >> 8) & 0xff, argb & 0xff, (argb >> 24) & 0xff);
            }
        }

        surface.texture.SetData(0, new Rectangle(x, y, width, height), data, 0, data.Length);

        return(0);
    }
Exemple #11
0
    public virtual int WritePixels2(gxtkSurface surface, int[] pixels, int x, int y, int width, int height, int offset, int pitch)
    {
        byte[] data = new byte[width * height * 4];

        int i = 0;

        for (int py = 0; py < height; ++py)
        {
            int j = offset + py * pitch;
            for (int px = 0; px < width; ++px)
            {
                int argb = pixels[j++];
                data[i]     = (byte)(argb >> 16);
                data[i + 1] = (byte)(argb >> 8);
                data[i + 2] = (byte)(argb);
                data[i + 3] = (byte)(argb >> 24);
                i          += 4;
            }
        }

        surface._texture.SetPixels(0, data, PixelFormat.Rgba, 0, width * 4, x, y, width, height);

        return(0);
    }
Exemple #12
0
    public virtual int DrawPoint(float x, float y)
    {
        if (_primType != 1 || _vertCount == MAX_VERTS || _primSurf != null)
        {
            Flush();
            _primType = 1;
            _primSurf = null;
        }

        if (_tformed)
        {
            float tx = x;
            x = tx * _ix + y * _jx + _tx;
            y = tx * _iy + y * _jy + _ty;
        }

        int i = _vertCount * 2, j = _vertCount;

        _verts[i] = x; _verts[i + 1] = y; _colors[j] = _color;

        _vertCount += 1;

        return(0);
    }
Exemple #13
0
    public virtual int DrawPoly2( float[] verts,gxtkSurface surf,int srcx,int srcy )
    {
        int n=verts.Length/2;
        if( n<1 || n>MAX_VERTS ) return 0;

        Flush();
        primType=5;
        primTex=null;

        for( int i=0;i<n;++i ){

            float px=verts[i*4];
            float py=verts[i*4+1];

            if( tformed ){
                float ppx=px;
                px=ppx * ix + py * jx + tx;
                py=ppx * iy + py * jy + ty;
            }

            vertices[i].Position.X=px;vertices[i].Position.Y=py;
            vertices[i].Color=color;
        }

        primCount=n;

        Flush();

        return 0;
    }
Exemple #14
0
 public virtual gxtkSurface LoadSurface( String path )
 {
     gxtkSurface surf=new gxtkSurface();
     if( !LoadSurface__UNSAFE__( surf,path ) ) return null;
     return surf;
 }
Exemple #15
0
 public virtual bool LoadSurface__UNSAFE__( gxtkSurface surface,String path )
 {
     Texture2D texture=BBXnaGame.XnaGame().LoadTexture2D( path );
     if( texture==null ) return false;
     surface.SetTexture( texture );
     return true;
 }
Exemple #16
0
    public virtual int WritePixels2( gxtkSurface surface,int[] pixels,int x,int y,int width,int height,int offset,int pitch )
    {
        Color[] data=new Color[width*height];

        int i=0;
        for( int py=0;py<height;++py ){
            int j=offset+py*pitch;
            for( int px=0;px<width;++px ){
                int argb=pixels[j++];
                data[i++]=new Color( (argb>>16) & 0xff,(argb>>8) & 0xff,argb & 0xff,(argb>>24) & 0xff );
            }
        }

        surface.texture.SetData( 0,new Rectangle( x,y,width,height ),data,0,data.Length );

        return 0;
    }
Exemple #17
0
 public c_Image p_Init(gxtkSurface t_surf,int t_nframes,int t_iflags)
 {
     bb_std_lang.pushErr();
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<143>";
     if((m_surface)!=null){
         bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<143>";
         bb_std_lang.Error("Image already initialized");
     }
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<144>";
     m_surface=t_surf;
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<146>";
     m_width=m_surface.Width()/t_nframes;
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<147>";
     m_height=m_surface.Height();
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<149>";
     m_frames=new c_Frame[t_nframes];
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<150>";
     for(int t_i=0;t_i<t_nframes;t_i=t_i+1){
         bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<151>";
         m_frames[t_i]=(new c_Frame()).m_Frame_new(t_i*m_width,0);
     }
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<154>";
     p_ApplyFlags(t_iflags);
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<155>";
     bb_std_lang.popErr();
     return this;
 }
Exemple #18
0
 public c_Image p_Init2(gxtkSurface t_surf,int t_x,int t_y,int t_iwidth,int t_iheight,int t_nframes,int t_iflags,c_Image t_src,int t_srcx,int t_srcy,int t_srcw,int t_srch)
 {
     bb_std_lang.pushErr();
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<159>";
     if((m_surface)!=null){
         bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<159>";
         bb_std_lang.Error("Image already initialized");
     }
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<160>";
     m_surface=t_surf;
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<161>";
     m_source=t_src;
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<163>";
     m_width=t_iwidth;
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<164>";
     m_height=t_iheight;
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<166>";
     m_frames=new c_Frame[t_nframes];
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<168>";
     int t_ix=t_x;
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<168>";
     int t_iy=t_y;
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<170>";
     for(int t_i=0;t_i<t_nframes;t_i=t_i+1){
         bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<171>";
         if(t_ix+m_width>t_srcw){
             bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<172>";
             t_ix=0;
             bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<173>";
             t_iy+=m_height;
         }
         bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<175>";
         if(t_ix+m_width>t_srcw || t_iy+m_height>t_srch){
             bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<176>";
             bb_std_lang.Error("Image frame outside surface");
         }
         bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<178>";
         m_frames[t_i]=(new c_Frame()).m_Frame_new(t_ix+t_srcx,t_iy+t_srcy);
         bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<179>";
         t_ix+=m_width;
     }
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<182>";
     p_ApplyFlags(t_iflags);
     bb_std_lang.errInfo="C:/MonkeyXPro82b/modules/mojo/graphics.monkey<183>";
     bb_std_lang.popErr();
     return this;
 }
Exemple #19
0
    public virtual int DrawSurface2( gxtkSurface surf,float x,float y,int srcx,int srcy,int srcw,int srch )
    {
        if( primType!=4 || primCount==MAX_QUADS || surf.texture!=primTex ){
            Flush();
            primType=4;
            primTex=surf.texture;
        }

        float w=surf.Width();
        float h=surf.Height();
        float u0=srcx/w,u1=(srcx+srcw)/w;
        float v0=srcy/h,v1=(srcy+srch)/h;
        float x0=x,x1=x+srcw,x2=x+srcw,x3=x;
        float y0=y,y1=y,y2=y+srch,y3=y+srch;

        if( tformed ){
            float tx0=x0,tx1=x1,tx2=x2,tx3=x3;
            x0=tx0 * ix + y0 * jx + tx;
            y0=tx0 * iy + y0 * jy + ty;
            x1=tx1 * ix + y1 * jx + tx;
            y1=tx1 * iy + y1 * jy + ty;
            x2=tx2 * ix + y2 * jx + tx;
            y2=tx2 * iy + y2 * jy + ty;
            x3=tx3 * ix + y3 * jx + tx;
            y3=tx3 * iy + y3 * jy + ty;
        }

        int vp=primCount++*4;

        vertices[vp  ].Position.X=x0;vertices[vp  ].Position.Y=y0;
        vertices[vp  ].TextureCoordinate.X=u0;vertices[vp  ].TextureCoordinate.Y=v0;
        vertices[vp  ].Color=color;
        vertices[vp+1].Position.X=x1;vertices[vp+1].Position.Y=y1;
        vertices[vp+1].TextureCoordinate.X=u1;vertices[vp+1].TextureCoordinate.Y=v0;
        vertices[vp+1 ].Color=color;
        vertices[vp+2].Position.X=x2;vertices[vp+2].Position.Y=y2;
        vertices[vp+2].TextureCoordinate.X=u1;vertices[vp+2].TextureCoordinate.Y=v1;
        vertices[vp+2].Color=color;
        vertices[vp+3].Position.X=x3;vertices[vp+3].Position.Y=y3;
        vertices[vp+3].TextureCoordinate.X=u0;vertices[vp+3].TextureCoordinate.Y=v1;
        vertices[vp+3].Color=color;

        return 0;
    }