/// <summary> /// ITextureのBltのoverride /// </summary> /// <param name="drawContext"></param> /// <param name="srcRect"></param> /// <param name="dstPoint"></param> public void Blt(DrawContext drawContext,Rect srcRect,Point[] dstPoint) { float w = Width; float h = Height; if (srcRect == null) { srcRect = new Rect(0, 0, Width, Height); } Rect sr = new Rect(srcRect.Left / w, srcRect.Top / h, srcRect.Right / w, srcRect.Bottom / h); { // 転送元は0.0~1.0にclipping if (sr.Left<0.0) sr.Left = 0.0f; if (sr.Right<0.0) sr.Right = 0.0f; if (sr.Top<0.0) sr.Top = 0.0f; if (sr.Bottom<0.0) sr.Bottom = 0.0f; if (sr.Left>1.0) sr.Left = 1.0f; if (sr.Right>1.0) sr.Right = 1.0f; if (sr.Top>1.0) sr.Top = 1.0f; if (sr.Bottom>1.0) sr.Bottom = 1.0f; } bool bW=false,bH=false; // 水平方向の反転フラグ float www = sr.Right - sr.Left; float hhh = sr.Bottom - sr.Top; if (www == 0 || hhh == 0) return ; if (www<0) { www = -www; bW = true; } if (hhh<0) { hhh = -hhh; bH = true; } foreach(TextureInfo info in infos){ Point[] dp = new Point[4]; // 転送先 Rect r = new Rect(); // 転送元矩形 // 転送元矩形をテクスチャ座標で表したもの Rect rr = new Rect(info.Left, info.Top, info.Right, info.Bottom); // sr のなかに含まれる矩形か? if (sr.Left <= info.Left && info.Right <= sr.Right && sr.Top <= info.Top && info.Bottom <= sr.Bottom){ // 含まれるのでそのまま描画 r.SetRect(0,0,info.Width,info.Height); } else { // 完全には含まれていないので、削り取る作業が必要 r.SetRect(0,0,info.Width,info.Height); float ww = info.Width / (info.Right-info.Left); float hh = info.Height / (info.Bottom-info.Top); float t; if (!bW){ t = sr.Left - info.Left; if (t>0) { r.Left += t * ww; rr.Left = sr.Left; } t = info.Right - sr.Right; if (t>0) { r.Right -= t * ww; rr.Right = sr.Right; } if (r.Left > r.Right) continue; // 表示エリアなし } else { t = sr.Right - info.Left; if (t>0) { r.Left += t * ww; rr.Left = sr.Right; } t = info.Right - sr.Left; if (t>0) { r.Right -= t * ww; rr.Right = sr.Left; } if (r.Left > r.Right) continue; // 表示エリアなし } if (!bH){ t = sr.Top - info.Top; if (t>0) { r.Top += t * hh; rr.Top = sr.Top; } t = info.Bottom - sr.Bottom; if (t>0) { r.Bottom -= t * hh; rr.Bottom = sr.Bottom; } else t = 0; if (r.Top > r.Bottom) continue; // 表示エリアなし } else { t = sr.Bottom - info.Top; if (t>0) { r.Top += t * hh; rr.Top = sr.Bottom; } else t = 0; t = info.Bottom - sr.Top; if (t>0) { r.Bottom -= t * hh; rr.Bottom = sr.Top; } if (r.Top > r.Bottom) continue; // 表示エリアなし } } float leftRM; float rightRM; if (!bW){ leftRM = (rr.Left - sr.Left) / www; rightRM = (rr.Right - sr.Left) / www; } else { leftRM = (1 - (rr.Left - sr.Right)) / www; rightRM = (1 - (rr.Right - sr.Right)) / www; } float topRM; float bottomRM; if (!bH){ topRM = (rr.Top - sr.Top) / hhh; bottomRM = (rr.Bottom - sr.Top) / hhh; } else { topRM = (1-(rr.Top - sr.Bottom)) / hhh; bottomRM = (1-(rr.Bottom - sr.Bottom)) / hhh; } calcUV(dstPoint,leftRM,topRM,ref dp[0]); calcUV(dstPoint,rightRM,topRM,ref dp[1]); calcUV(dstPoint,rightRM,bottomRM,ref dp[2]); calcUV(dstPoint,leftRM,bottomRM,ref dp[3]); info.Texture.Blt(drawContext,r,dp); } }
/// <summary> /// これ、めちゃくちゃ面倒くさいですなぁ..(´Д`) /// </summary> /// <param name="src"></param> /// <param name="srcRect"></param> /// <param name="dstPoint"></param> /// <remarks> /// 未実装だ! 実装する予定は当分無い! /// </remarks> public void Blt(DrawContext src, Point[] srcRect, Point[] dstPoint) { }
/// <summary> /// ITextureのBltのoverride /// </summary> /// <remarks> /// rateを考慮してのblt /// </remarks> /// <param name="drawContext"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="srcRect"></param> public void Blt(DrawContext drawContext,float x,float y,Rect srcRect) { Point[] points = new Point[4]; float w,h; if (srcRect == null) { srcRect = new Rect(0, 0, Width, Height); } w = srcRect.Right - srcRect.Left; if (w<0) w = -w; h = srcRect.Bottom - srcRect.Top; if (h<0) h = -h; points[0].SetPoint(x,y); points[1].SetPoint(x+w*rate,y); points[2].SetPoint(x+w*rate,y+h*rate); points[3].SetPoint(x,y+h*rate); Blt(drawContext,srcRect,points); }
/// <summary> /// ITextureのBltのoverride /// </summary> /// <remarks> /// rateを考慮してのblt /// </remarks> /// <param name="drawContext"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="srcRect"></param> /// <param name="dstSize"></param> public void Blt(DrawContext drawContext,float x,float y, Rect srcRect,Size dstSize) { Point[] points = new Point[4]; if (srcRect == null) { srcRect = new Rect(0, 0, Width, Height); } if (dstSize == null) { dstSize = new Size(drawContext.ScreenSizeX, drawContext.ScreenSizeY); } points[0].SetPoint(x,y); points[1].SetPoint(x+dstSize.Cx-1,y); points[2].SetPoint(x+dstSize.Cx-1,y+dstSize.Cy-1); points[3].SetPoint(x,y+dstSize.Cy-1); Blt(drawContext,srcRect,points); }
/// <summary> /// ���̃e�N�X�`����w���screen��blt����B /// </summary> /// <param name="src"></param> /// <param name="srcPoint"></param> /// <param name="dstPoint"></param> /// <remarks> /// visitor�p�^�[���̂��߂Ɏ������Ă���B /// SDLWindow.blt����Visitor�Ƃ��ČĂяo�����B /// ����A Textures �ł͖������B(�ʓ|������) /// </remarks> public void Blt(DrawContext src, Point[] srcPoint, Point[] dstPoint) { if (srcPoint == null) Blt(src, (Rect)null, dstPoint); // ����srcPoint��rect�̂Ȃ��ł̍��W��Ӗ�����̂ō��W�ϊ���{���K�v������B // outRect��Width,Height���}�C�i�X�̒l�ł��邱�Ƃ�l�����āc int sw = global::System.Math.Sign(rect.Right-rect.Left); int sh = global::System.Math.Sign(rect.Bottom-rect.Top); Point[] srcPoint_ = new Point[srcPoint.Length]; for(int i=0;i<srcPoint.Length;++i) { srcPoint_[i].X = rect.Left + sw * srcPoint[i].X; srcPoint_[i].Y = rect.Top + sh * srcPoint[i].Y; } Point[] dstPoint_ = new Point[dstPoint.Length]; for (int i = 0; i < dstPoint_.Length; ++i) { dstPoint_[i].X = dstPoint[i].X + DstOffsetX; dstPoint_[i].Y = dstPoint[i].Y + DstOffsetY; } texture.Blt(src, srcPoint_, dstPoint_); }
/// <summary> /// ITextureのBltのoverride /// </summary> /// <remarks> /// rateを考慮してのblt /// </remarks> /// <param name="drawContext"></param> /// <param name="x"></param> /// <param name="y"></param> public void Blt(DrawContext drawContext,float x,float y) { float w = Width; float h = Height; foreach(TextureInfo info in infos){ info.Texture.Blt(drawContext, x+info.Left*w, y+info.Top*h ,null ,new Size(info.Width*rate,info.Height*rate) ); } }
/* /// <summary> /// ���̃e�N�X�`����w���screen��blt����B /// </summary> /// <param name="drawContext"></param> /// <param name="x"></param> /// <param name="y"></param> /// <remarks> /// visitor�p�^�[���̂��߂Ɏ������Ă���B /// SDLWindow.blt����Visitor�Ƃ��ČĂяo�����B /// </remarks> public void Blt(DrawContext context, float x, float y) { texture.Blt(context, x +DstOffsetX, y + DstOffsetY, rect); } /// <summary> /// ���̃e�N�X�`����w���screen��blt����B /// </summary> /// <param name="drawContext"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="srcRect"></param> /// <remarks> /// visitor�p�^�[���̂��߂Ɏ������Ă���B /// SDLWindow.blt����Visitor�Ƃ��ČĂяo�����B /// </remarks> public void Blt(DrawContext src, float x, float y, Rect srcRect) { // ����srcRect��rect�̂Ȃ��ł̍��W��Ӗ�����̂ō��W�ϊ���{���K�v������B Rect r = Rect.CalcRectInRect(rect, srcRect); texture.Blt(src, x + DstOffsetX, y + DstOffsetY, r); } */ /// <summary> /// ���̃e�N�X�`����w���screen��blt����B /// </summary> /// <param name="drawContext"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="srcRect"></param> /// <param name="dstSize"></param> /// <remarks> /// visitor�p�^�[���̂��߂Ɏ������Ă���B /// SDLWindow.blt����Visitor�Ƃ��ČĂяo�����B /// </remarks> public void Blt(DrawContext src, float x, float y, Rect srcRect, Size dstSize) { // ����srcRect��rect�̂Ȃ��ł̍��W��Ӗ�����̂ō��W�ϊ���{���K�v������B // Rect r = Rect.CalcRectInRect(rect, srcRect); Rect r = srcRect; texture.Blt(src, x + DstOffsetX, y + DstOffsetY, r, dstSize); }
/// <summary> /// ���̃e�N�X�`����w���screen��blt����B /// </summary> /// <param name="src"></param> /// <param name="srcRect"></param> /// <param name="dstPoint"></param> /// <remarks> /// visitor�p�^�[���̂��߂Ɏ������Ă���B /// SDLWindow.blt����Visitor�Ƃ��ČĂяo�����B /// </remarks> public void Blt(DrawContext src, Rect srcRect, Point[] dstPoint) { // ����srcRect��rect�̂Ȃ��ł̍��W��Ӗ�����̂ō��W�ϊ���{���K�v������B // Rect r = Rect.CalcRectInRect(rect, srcRect); Rect r = srcRect; Point[] dstPoint_ = new Point[dstPoint.Length]; for (int i = 0; i < dstPoint_.Length; ++i) { dstPoint_[i].X = dstPoint[i].X + DstOffsetX; dstPoint_[i].Y = dstPoint[i].Y + DstOffsetY; } texture.Blt(src, r, dstPoint_); }
/// <summary> /// このテクスチャを対象(DrawContext)の(x,y)に転送する。 /// 転送元(このテクスチャ)の転送元四角形を指定できる。 /// また、転送先での四角形を指定できる。 /// /// 転送元の4点(srcPoint[4])が、転送先の4点(dstPoint[4])に /// 対応するように転送される。 /// </summary> /// <param name="context"></param> /// <param name="srcPoint"></param> /// <param name="dstPoint"></param> public void Blt(DrawContext context,Point[] srcPoint,Point[] dstPoint) { if (!Loaded) return; // クリップ処理は、openglに任せたので、もはや不要なのだ float w = Width; float h = Height; if (w==0 || h==0) return ; float wr = WidthRate; float hr = HeightRate; if (dstPoint == null) return ; Bind(); Gl.glBegin(Gl.GL_POLYGON); for(int i=0;i<4;++i){ float xx = (wr*srcPoint[i].X) / w; float yy = (hr*srcPoint[i].Y) / h; Gl.glTexCoord2f(xx,yy); float dx = dstPoint[i].X * context.RateX + context.OffsetRX; float dy = dstPoint[i].Y * context.RateY + context.OffsetRY; Gl.glVertex2f(dx,dy); } Gl.glEnd(); Unbind(); }
/// <summary> /// このテクスチャを対象(DrawContext)の(x,y)に転送する。 /// 転送元(このテクスチャ)の転送元矩形を指定できる。 /// また、転送先での四角形を指定できる。 /// </summary> /// <param name="context"></param> /// <param name="srcRect"></param> /// <param name="dstPoint">dstPoint Point[4]は、転送元矩形の左上,右上,右下,左下が、 /// 転送先において対応する4点。</param> public void Blt(DrawContext context,Rect srcRect,Point[] dstPoint) { if (!Loaded) return; float w = Width; float h = Height; if (w==0 || h==0) return ; if (srcRect == null) { srcRect = new Rect(0, 0, w, h); } float wr = WidthRate; float hr = HeightRate; float left,top,right,bottom; left = (wr*srcRect.Left) / w; top = (hr*srcRect.Top) / h; right = (wr*srcRect.Right) / w; bottom = (hr*srcRect.Bottom) / h; if (dstPoint == null) return; Point[] dp = new Point[4]; for(int i=0;i<4;++i){ dp[i].X = dstPoint[i].X*context.RateX + context.OffsetRX; dp[i].Y = dstPoint[i].Y*context.RateY + context.OffsetRY; } Bind(); Gl.glBegin(Gl.GL_POLYGON); Gl.glTexCoord2f(left,top); Gl.glVertex2f(dp[0].X,dp[0].Y); Gl.glTexCoord2f(right,top); Gl.glVertex2f(dp[1].X,dp[1].Y); Gl.glTexCoord2f(right,bottom); Gl.glVertex2f(dp[2].X,dp[2].Y); Gl.glTexCoord2f(left,bottom); Gl.glVertex2f(dp[3].X,dp[3].Y); Gl.glEnd(); Unbind(); }
/// <summary> /// このテクスチャを対象(DrawContext)の(x,y)に転送する。 /// 転送元(このテクスチャ)の転送元矩形を指定できる。 /// また、転送先でのサイズを指定できる。 /// </summary> /// <param name="context"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="srcRect"></param> /// <param name="dstSize"></param> public void Blt(DrawContext context,float x,float y,Rect srcRect,Size dstSize) { if (!Loaded) return; float w = Width; float h = Height; if (w==0 || h==0) return ; if (srcRect == null) { srcRect = new Rect(0, 0, w, h); } float wr = WidthRate; float hr = HeightRate; float left,top,right,bottom; left = (wr * srcRect.Left) / w; top = (hr * srcRect.Top) / h; right = (wr * srcRect.Right) / w; bottom = (hr * srcRect.Bottom) / h; float rateX = context.RateX; float rateY = context.RateY; w = srcRect.Right - srcRect.Left; h = srcRect.Bottom - srcRect.Top; if (w==0 || h==0) return ; // 転送先サイズは指定されているが.. if (dstSize == null) { // dstSize = new Size(context.ScreenSizeX, context.ScreenSizeY); w = context.ScreenSizeX; h = context.ScreenSizeY; } else { w = dstSize.Cx; h = dstSize.Cy; } x = x /* * rateX */ + context.OffsetRX; y = y /* * rateY */ + context.OffsetRY; // w *= rateX; // h *= rateY; Bind(); Gl.glBegin(Gl.GL_POLYGON); // クリップ処理は、openglに任せたので、もはや不要なのだ // クリップ無し Gl.glTexCoord2f(left,top); Gl.glVertex2f(x ,y ); Gl.glTexCoord2f(right,top); Gl.glVertex2f(x+w,y ); Gl.glTexCoord2f(right,bottom); Gl.glVertex2f(x+w,y+h); Gl.glTexCoord2f(left,bottom); Gl.glVertex2f(x ,y+h); Gl.glEnd(); Unbind(); }
/// <summary> /// このテクスチャを対象(DrawContext)の(x,y)に転送する。 /// 転送元(このテクスチャ)の転送元矩形を指定できる。 /// </summary> /// <param name="context"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="srcRect"></param> public void Blt(DrawContext context,float x,float y,Rect srcRect) { // ref Rectにreadonly制約はつけられへんのかいな(´ω`) if (!Loaded) return; float w = Width; float h = Height; if (w==0 || h==0) return ; if (srcRect == null){ srcRect = new Rect(0, 0, w, h); } float wr = WidthRate; float hr = HeightRate; float left,top,right,bottom; left = (wr * srcRect.Left) / w; top = (hr * srcRect.Top) / h; right = (wr * srcRect.Right) / w; bottom = (hr * srcRect.Bottom) / h; float rateX = context.RateX; float rateY = context.RateY; w = srcRect.Right - srcRect.Left; h = srcRect.Bottom - srcRect.Top; if (w==0 || h==0) return ; // 左右、上下反転描画のためにabsをとる。 if (w<0) w=-w; if (h<0) h=-h; x = x * rateX + context.OffsetRX; y = y * rateY + context.OffsetRY; w *= rateX; h *= rateY; Bind(); Gl.glBegin(Gl.GL_POLYGON); // クリップ処理は、openglに任せたので、もはや不要なのだ // クリップ無し Gl.glTexCoord2f(left,top); Gl.glVertex2f(x ,y ); Gl.glTexCoord2f(right,top); Gl.glVertex2f(x+w,y ); Gl.glTexCoord2f(right,bottom); Gl.glVertex2f(x+w,y+h); Gl.glTexCoord2f(left,bottom); Gl.glVertex2f(x ,y+h); Gl.glEnd(); Unbind(); }
/// <summary> /// このテクスチャを対象(DrawContext)の(x,y)に転送する。 /// </summary> /// <param name="context"></param> /// <param name="x"></param> /// <param name="y"></param> public void Blt(DrawContext context,float x,float y) { if (!Loaded) return ; float w = Width; float h = Height; if (w==0 || h==0) return ; float wr = WidthRate; float hr = HeightRate; // 描画は、Drawcontext.RateX,rateYの値を反映しなければならない float rateX = context.RateX; float rateY = context.RateY; x = x * rateX + context.OffsetRX; y = y * rateY + context.OffsetRY; w *= rateX; h *= rateY; // クリップ処理は、openglに任せたので、もはや不要なのだ // クリップ無し Bind(); Gl.glBegin(Gl.GL_POLYGON); Gl.glTexCoord2f(0,0); Gl.glVertex2f(x ,y ); Gl.glTexCoord2f(wr,0); Gl.glVertex2f(x+w,y ); Gl.glTexCoord2f(wr,hr); Gl.glVertex2f(x+w,y+h); Gl.glTexCoord2f(0,hr); Gl.glVertex2f(x ,y+h); Gl.glEnd(); Unbind(); }