📄 surface.cs.svn-base
字号:
using System;
using System.Runtime.InteropServices;
namespace Aspecto.PocketFrog
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class Surface : IDisposable
{
public static Surface LoadImageFromFile(string filename)
{
IntPtr s = PF.image_loadimagefromfile(filename);
if (s.ToInt32() == 0)
return null;
else
return new Surface(s);
}
public static Surface LoadImageFromResource(uint resourceID, string resclass, IntPtr hModule)
{
IntPtr s = PF.image_loadimagefromresource(resourceID, resclass, hModule);
if (s.ToInt32() == 0)
return null;
else
return new Surface(s);
}
public static Surface LoadImageFromMem(byte[] data)
{
IntPtr p = Marshal.AllocCoTaskMem(data.Length);
Marshal.Copy(data, 0, p, data.Length);
IntPtr s = PF.image_loadimagefrommem(p, new IntPtr(p.ToInt32() + data.Length));
if (s.ToInt32() == 0)
return null;
else
return new Surface(s);
}
public static bool SaveImage(Surface surface, string filename)
{
return PF.image_saveimage(surface.uObject(), filename);
}
private IntPtr uobj;
public IntPtr uObject()
{
return uobj;
}
public Surface(int width, int height)
{
uobj = PF.surface_create(width, height);
}
public void Dispose()
{
PF.surface_destroy(uobj);
}
public Surface(IntPtr iuobj)
{
uobj = iuobj;
}
public Surface Clone()
{
IntPtr s = PF.surface_clone(uobj);
if (s.ToInt32() == 0)
return null;
else
return new Surface(s);
}
#region Height / Width
public int Height
{
get { return (int)PF.surface_getheight(uobj); }
}
public int Width
{
get { return (int)PF.surface_getwidth(uobj); }
}
#endregion
public uint GetHeight()
{
return PF.surface_getheight(uobj);
}
public uint GetWidth()
{
return PF.surface_getwidth(uobj);
}
public void SetColorMask(int mask)
{
PF.surface_setcolormask(uobj,mask);
}
public int GetColorMask()
{
return PF.surface_getcolormask(uobj);
}
public bool Unlock(bool discard)
{
return PF.surface_unlock(uobj,discard);
}
public Rect rect
{
get
{
return new Rect( 0, 0, (int)GetWidth(), (int)GetHeight() );
}
}
public IntPtr GetDC(bool discard)
{
return PF.surface_getdc(uobj,discard);
}
public bool ReleaseDC(IntPtr hdc)
{
return PF.surface_releasedc(uobj,hdc);
}
/* public System.Drawing.Bitmap gdiEquivalent
{
get
{
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap( Width, Height );
pfNet.Display d = Display.Create( (IntPtr)1, (uint)bmp.Width, (uint)bmp.Height );
d.Blit( 0, 0, this, new Rect( 0, 0, bmp.Width, bmp.Height ) );
for ( int x = 0; x < bmp.Width; x ++ )
for ( int y = 0; y < bmp.Height; y ++ )
{
ushort color = d.GetPixel( x, y );
bmp.SetPixel( x, y, System.Drawing.Color.FromArgb( color ) );
}
d.Dispose();
return bmp;
}
}*/
}
}
/*
POCKETFROGCWRAPPER_API Surface* __stdcall surface_create(unsigned width, unsigned height);
POCKETFROGCWRAPPER_API void __stdcall surface_destroy(Surface* surface);
POCKETFROGCWRAPPER_API Surface* __stdcall surface_clone(Surface* surface);
POCKETFROGCWRAPPER_API unsigned __stdcall surface_getwidth(Surface* surface);
POCKETFROGCWRAPPER_API unsigned __stdcall surface_getheight(Surface* surface);
POCKETFROGCWRAPPER_API void __stdcall surface_setcolormask(Surface* surface, int mask);
POCKETFROGCWRAPPER_API int __stdcall surface_getcolormask(Surface* surface);
POCKETFROGCWRAPPER_API bool __stdcall surface_lock(Surface* surface, Surface::LockInfo& lockinfo, bool bDiscard = false, const Rect* rect = 0);
POCKETFROGCWRAPPER_API bool __stdcall surface_unlock(Surface* surface, bool bDiscard = false);
POCKETFROGCWRAPPER_API HDC __stdcall surface_getdc(Surface* surface, bool bDiscard = false);
POCKETFROGCWRAPPER_API bool __stdcall surface_releasedc(Surface* surface, HDC hdc);
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -