⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gapisurface.cs.svn-base

📁 这是一个windows mobile程序能够实现窗体运货效果非常不错
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Drawing;
using System.Runtime.InteropServices;

namespace Aspecto.GapiDrawNet
{
	/// <summary>
	/// Summary description for GapiSurface.
	/// </summary>
	public class GapiSurface : IDisposable
	{
		protected IntPtr unmanagedGapiObject;
        protected IntPtr gapiDraw;
		protected bool OwnsGapiObject = true;
		public IntPtr GapiObject
		{
			get { return unmanagedGapiObject; }
			set { unmanagedGapiObject = value; }
		}

        
        public IntPtr GapiDraw
        {
            get
            {
                return gapiDraw;
            }
        }

        public GapiSurface(IntPtr gapiDraw) {
            unmanagedGapiObject = GdNet.CGapiSurface_Create(gapiDraw);
            this.gapiDraw = gapiDraw;
        }

        //public GapiSurface(IntPtr gapiObject)
        //{	
        //    unmanagedGapiObject = gapiObject;
			
        //}

		virtual public void Dispose()
		{
			OwnsGapiObject = false;
			GdNet.CGapiSurface_Destroy(unmanagedGapiObject);
		}

		public UInt32 CreateSurface(string fileName)
		{
			// public UInt32 CreateSurfaceFromFile (IntPtr pSurface, ref char pImageFile);
			UInt32 hResult = GdNet.CGapiSurface_CreateSurfaceFromFile(unmanagedGapiObject, 0, fileName);

			GapiUtility.RaiseExceptionOnError(hResult);

			return hResult;
		}

		public UInt32 CreateSurface(CreateSurfaceOptions dwFlags, string fileName)
		{
			// public UInt32 CreateSurfaceFromFile (IntPtr pSurface, ref char pImageFile);
			UInt32 hResult = GdNet.CGapiSurface_CreateSurfaceFromFile(unmanagedGapiObject, (int)dwFlags, fileName);

			GapiUtility.RaiseExceptionOnError(hResult);

			return hResult;
		}
		
		public UInt32 CreateSurface(GapiSurface srcSurface)
		{
			// public UInt32 CreateSurfaceFromFile (IntPtr pSurface, ref char pImageFile);
			UInt32 hResult = GdNet.CGapiSurface_CreateSurfaceFromSurface(unmanagedGapiObject, srcSurface.unmanagedGapiObject);

			GapiUtility.RaiseExceptionOnError(hResult);

			return hResult;
		}

		public UInt32 CreateSurface(byte[] pImageFileMem, CreateSurfaceOptions dwFlags, int dwImageFileSize)
		{
			UInt32 hResult = GdNet.CGapiSurface_CreateSurfaceFromMem (unmanagedGapiObject, (int)dwFlags, pImageFileMem, dwImageFileSize);

			GapiUtility.RaiseExceptionOnError(hResult);

			return hResult;
		}
		//		public UInt32 CreateSurfaceFromMem (IntPtr pSurface, ref byte pImageFileMem, int dwImageFileSize);
		//		public UInt32 CreateSurfaceFromRes (IntPtr pSurface, IntPtr hInstance, int dwResourceID, string pResourceType);

		public UInt32 CreateSurface(IntPtr hInstance, CreateSurfaceOptions dwFlags, int dwResourceID, string pResourceType)
		{
			UInt32 hResult = GdNet.CGapiSurface_CreateSurfaceFromRes(unmanagedGapiObject, (int)dwFlags, hInstance, dwResourceID, pResourceType);

			GapiUtility.RaiseExceptionOnError(hResult);

			return hResult;
		}

		//		public UInt32 CreateSurfaceOfSize (IntPtr pSurface, int dwFlags, int dwWidth, int dwHeight);
		public void CreateSurface(CreateSurfaceOptions dwFlags, int dwWidth, int dwHeight)
		{
			// public UInt32 CreateSurfaceFromFile (IntPtr pSurface, ref char pImageFile);
			UInt32 hResult = GdNet.CGapiSurface_CreateSurface(unmanagedGapiObject, (int)dwFlags, dwWidth, dwHeight);

			GapiUtility.RaiseExceptionOnError(hResult);
		}

		public void CreateSurface(int dwWidth, int dwHeight)
		{
			// public UInt32 CreateSurfaceFromFile (IntPtr pSurface, ref char pImageFile);
			UInt32 hResult = GdNet.CGapiSurface_CreateSurface(unmanagedGapiObject, 0, dwWidth, dwHeight);

			GapiUtility.RaiseExceptionOnError(hResult);
		}
		public int GetWidth()
		{
			return GdNet.CGapiSurface_GetWidth(unmanagedGapiObject);
		}

		public int Width
		{
			get { return GdNet.CGapiSurface_GetWidth(unmanagedGapiObject); }
		}

		public int GetHeight()
		{
			return GdNet.CGapiSurface_GetHeight(unmanagedGapiObject);
		}

		public int Height
		{
			get { return GdNet.CGapiSurface_GetHeight(unmanagedGapiObject); }
		}		

		
		//		public UInt32 GetColorKey (IntPtr pSurface, ref int pColorKey);
		public int GetColorKey()
		{
			int result;
			GapiUtility.RaiseExceptionOnError(GdNet.CGapiSurface_GetColorKey(unmanagedGapiObject, out result));
			return result;
		}
		
		//		public UInt32 SetColorKey (IntPtr pSurface, int dwColorKey);
		public void SetColorKey(int dwColorKey)
		{
			GapiUtility.RaiseExceptionOnError(GdNet.CGapiSurface_SetColorKey(unmanagedGapiObject, dwColorKey));
		}

		public int ColorKey
		{
			get { return GetColorKey(); }
			set { SetColorKey(value); }
		}

		public void SetColorKeyFromBottomLeftCorner()
		{
			// get from bottom left corner
			int height = Height;
			int color  = GetPixel(0, height - 1);
			SetColorKey(color);
		}

		public void SetColorKeyFromTopLeftCorner()
		{
			SetColorKey(GetPixel(0, 0));
		}
		
//		public UInt32 CGapiSurface_Lock(IntPtr pSurface, ref GDRect pRect, ref GDSURFACEDESC pGDSurfaceDesc);

		
//		public UInt32 CGapiSurface_Unlock(IntPtr pSurface, ref GDRect pRect);

		
//		public UInt32 CGapiSurface_GetDC(IntPtr pSurface, IntPtr pDC);
		public IntPtr GetDC()
		{
			IntPtr result;
			GapiUtility.RaiseExceptionOnError(GdNet.CGapiSurface_GetDC(unmanagedGapiObject, out result));
			return result;
		}

		
//		public UInt32 CGapiSurface_ReleaseDC(IntPtr pSurface, IntPtr hDC);
		public void ReleaseDC(IntPtr hDC)
		{
			GapiUtility.RaiseExceptionOnError(GdNet.CGapiSurface_ReleaseDC(unmanagedGapiObject, hDC));
		}
		
//		public UInt32 CGapiSurface_GetBuffer (IntPtr pSurface, ref GDBUFFERDESC pGDBufferDesc);
		public GDBUFFERDESC GetBuffer()
		{
			GDBUFFERDESC pGDBufferDesc;
			GapiUtility.RaiseExceptionOnError(GdNet.CGapiSurface_GetBuffer(unmanagedGapiObject, out pGDBufferDesc));
			return pGDBufferDesc;
		}

		
//		public UInt32 CGapiSurface_ReleaseBuffer (IntPtr pSurface);
		public void ReleaseBuffer()
		{
			GapiUtility.RaiseExceptionOnError(GdNet.CGapiSurface_ReleaseBuffer(unmanagedGapiObject));
		}
	
		// TODO : TEST THESE
		public UInt32 LockVideoSurface()
		{
			return GdNet.CGapiSurface_LockVideoSurface(unmanagedGapiObject);
		}

		// TODO : TEST THESE
		public UInt32 UnlockVideoSurface()
		{
			return GdNet.CGapiSurface_UnlockVideoSurface(unmanagedGapiObject);
		}

//		public UInt32 CGapiSurface_SaveSurface (IntPtr pSurface, ref char pBitmapFile);
		public void SaveSurface(string bitmapFilename, SaveSurfaceOptions options)
		{
			GapiUtility.RaiseExceptionOnError(GdNet.CGapiSurface_SaveSurface(unmanagedGapiObject, bitmapFilename, (int)options));
		}

		public void SaveSurface(string bitmapFilename)
		{
			GapiUtility.RaiseExceptionOnError(GdNet.CGapiSurface_SaveSurface(unmanagedGapiObject, bitmapFilename, (int)SaveSurfaceOptions.GDSAVESURFACE_BMP));
		}
		
//		public UInt32 CGapiSurface_GetSurfaceOptions (IntPtr pSurface, ref int pOptions);
		public CreateSurfaceOptions GetSurfaceFlags()
		{
			int result;
			GapiUtility.RaiseExceptionOnError(GdNet.CGapiSurface_GetSurfaceFlags(unmanagedGapiObject, out result));
			return (CreateSurfaceOptions)result;
		}
		
//		public UInt32 CGapiSurface_SetSurfaceOptions (IntPtr pSurface, int dwOptions);
//		public void SetSurfaceOptions(GapiSurfaceOptions options)
//		{
//			GapiUtility.RaiseExceptionOnError(GdNet.CGapiSurface_SetSurfaceOptions(unmanagedGapiObject, (int)options));
//		}
		
//		public GapiSurfaceOptions SurfaceOptions
//		{
//			get { return GetSurfaceOptions(); }
//			set { SetSurfaceOptions(value); }
//		}

		
#if (TEST)
		public GDRect LastRect;
#endif

//		public UInt32 CGapiSurface_BltFast (IntPtr pSurface, int dwX, int dwY, IntPtr pSrcSurface, ref GDRect pSrcRect, int dwFlags, ref GDBLTFASTFX pGDBltFastFx);
		/// <summary>
        /// CGapiSurface::BltFast is always much faster than CGapiSurface::Blt. If you need to stretch or mirror the source surface during the blit, use CGapiSurface::Blt. Otherwise you should always use CGapiSurface::BltFast.
		/// </summary>
		/// <param name="dwX"></param>
		/// <param name="dwY"></param>
		/// <param name="srcSurface"></param>
		/// <param name="srcRect"></param>
		/// <param name="dwFlags"></param>
		/// <param name="fastFx"></param>
        public void BltFast(int dwX, int dwY, GapiSurface srcSurface, ref GDRect srcRect, BltFastOptions dwFlags, ref GDBLTFASTFX fastFx)
		{
			GdNet.CGapiSurface_BltFast(unmanagedGapiObject, dwX, dwY, srcSurface.GapiObject, ref srcRect, (int)dwFlags, ref fastFx);
			
#if (TEST)
			LastRect.Left = dwX;
			LastRect.Top = dwY;
			LastRect.Right = dwX + srcRect.Right - srcRect.Left;
			LastRect.Top = dwY + srcRect.Bottom - srcRect.Top;			
#endif
		}
		
		public void BltFast(int dwX, int dwY, GapiSurface srcSurface, ref GDRect srcRect, BltFastOptions dwFlags)
		{
			unsafe
			{
				fixed (GDRect* pSrcRect = &srcRect)
					GdNet.CGapiSurface_BltFastNoRect(unmanagedGapiObject, dwX, dwY, srcSurface.GapiObject, pSrcRect, (int)dwFlags, null);
			}
#if (TEST)
			LastRect.Left = dwX;
			LastRect.Top = dwY;
			LastRect.Right = dwX + srcRect.Right - srcRect.Left;
			LastRect.Top = dwY + srcRect.Bottom - srcRect.Top;			
#endif
		}

		public void BltFast(int dwX, int dwY, GapiSurface srcSurface, BltFastOptions dwFlags, ref GDBLTFASTFX gDBltFastFx)
		{
			unsafe
			{
				fixed (GDBLTFASTFX* pGDBltFastFx = &gDBltFastFx)
					GdNet.CGapiSurface_BltFastNoRect(unmanagedGapiObject, dwX, dwY, srcSurface.GapiObject, null, (int)dwFlags, pGDBltFastFx);
				//GapiUtility.RaiseExceptionOnError(GdNet.CGapiSurface_BltFastNoRect(unmanagedGapiObject, dwX, dwY, srcSurface.GapiObject, null, (int)dwFlags, ref pGDBltFastFx));
			}
			
#if (TEST)
			LastRect.Left = dwX;
			LastRect.Top = dwY;
			LastRect.Right = dwX;
			LastRect.Top = dwY;			
#endif
		}

		public void BltFast(int dwX, int dwY, GapiSurface srcSurface, BltFastOptions dwFlags)
		{
			unsafe
			{
				GdNet.CGapiSurface_BltFastNoRect(unmanagedGapiObject, dwX, dwY, srcSurface.GapiObject, null, (int)dwFlags, null);
				//GapiUtility.RaiseExceptionOnError(GdNet.CGapiSurface_BltFastNoRect(unmanagedGapiObject, dwX, dwY, srcSurface.GapiObject, null, (int)dwFlags, ref pGDBltFastFx));
			}
#if (TEST)
			LastRect.Left = dwX;
			LastRect.Top = dwY;
			LastRect.Right = dwX;
			LastRect.Top = dwY;			
#endif
		}

		//		public UInt32 CGapiSurface_Blt(IntPtr pSurface, ref GDRect pDestRect, IntPtr pSrcSurface, ref GDRect pSrcRect, int dwFlags, ref GDBLTFX pGDBltFx);
		public UInt32 Blt(ref GDRect pDestRect, GapiSurface srcSurface, ref GDRect pSrcRect, BltOptions dwFlags, ref GDBLTFX pGDBltFx)
		{
			UInt32 result = GdNet.CGapiSurface_Blt(unmanagedGapiObject, ref pDestRect, srcSurface.GapiObject, ref pSrcRect, (int)dwFlags, ref pGDBltFx);
#if (TEST)
			LastRect = pDestRect;			
#endif
			return result;
		}

//		public UInt32 CGapiSurface_Blt(IntPtr pSurface, ref GDRect pDestRect, IntPtr pSrcSurface, ref GDRect pSrcRect, int dwFlags, ref GDBLTFX pGDBltFx);
		public UInt32 Blt(ref GDRect destRect, GapiSurface srcSurface, BltOptions dwFlags, ref GDBLTFX pGDBltFx)
		{
			UInt32 result;
			unsafe
			{
				fixed (GDRect* pDestRect = &destRect)
				{
					result = GdNet.CGapiSurface_BltNoRect(unmanagedGapiObject, pDestRect, srcSurface.GapiObject, null, (int)dwFlags, ref pGDBltFx);
				}
			}


#if (TEST)
			LastRect = destRect;			
#endif
			return result;
		}

        public void Blt(GapiSurface srcSurface, int x, int y)
        {
             GDRect gr = new GDRect(x,y,x+srcSurface.Width,srcSurface.Height);
             GDBLTFX fx = new GDBLTFX();
             Blt(ref gr, srcSurface, 0, ref fx);
               
        }
		public UInt32 Blt(GapiSurface srcSurface, BltOptions dwFlags, ref GDBLTFX pGDBltFx)
		{
			unsafe
			{
				return GdNet.CGapiSurface_BltNoRect(unmanagedGapiObject, null, srcSurface.GapiObject, null, (int)dwFlags, ref pGDBltFx);
			}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -