本文整理汇总了C#中Surface类的典型用法代码示例。如果您正苦于以下问题:C# Surface类的具体用法?C# Surface怎么用?C# Surface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Surface类属于命名空间,在下文中一共展示了Surface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public void Draw(Surface surface, int color, int step, Point location)
{
foreach (Letter letter in letters) {
letter.Draw(surface, color, location);
location.X += step;
}
}
示例2: RenderGlyph
private static unsafe bool RenderGlyph(FontFace typeface, char c, float pixelSize, out Surface surface)
{
bool result = false;
Glyph glyph = typeface.GetGlyph(c, pixelSize);
if (glyph != null && glyph.RenderWidth > 0 && glyph.RenderHeight > 0)
{
surface = new Surface
{
Bits = Marshal.AllocHGlobal(glyph.RenderWidth * glyph.RenderHeight),
Width = glyph.RenderWidth,
Height = glyph.RenderHeight,
Pitch = glyph.RenderWidth
};
var stuff = (byte*)surface.Bits;
for (int i = 0; i < surface.Width * surface.Height; i++)
*stuff++ = 0;
glyph.RenderTo(surface);
result = true;
}
else
{
surface = new Surface();
}
return result;
}
示例3: ProcessRequest
/// <summary>
/// Handle a request.
/// </summary>
/// <param name="pDisplay">The display which called this function.</param>
/// <param name="pSurface">The surface which this display is hosted on.</param>
/// <param name="dArguments">A dictionary of arguments which are passed to the function as parameters.</param>
/// <returns>True if the request was processed sucessfully. False if there was an error.</returns>
public bool ProcessRequest(Display pDisplay, Surface pSurface, JSObject dArguments)
{
// Check we have a sound file.
var sSound = dArguments.GetValueOrDefault("file", "");
if (sSound == null || sSound == "")
{
Log.Write("Cannot play sound. Are you missing a 'file' parameter.", pDisplay.ToString(), Log.Type.DisplayWarning);
return false;
}
// Attempt to play it.
try
{
SoundPlayer pSound = new SoundPlayer(sSound);
pSound.Play();
return true;
}
// Log warnings.
catch (Exception e)
{
Log.Write("Cannot play sound. " + e.Message, pDisplay.ToString(), Log.Type.DisplayWarning);
return false;
}
}
示例4: MafiaVideo
public MafiaVideo(Form form, bool fullscreen)
{
this.form = form;
this.fullscreen = fullscreen;
if (fullscreen)
{
form.FormBorderStyle = FormBorderStyle.None;
}
else
{
form.FormBorderStyle = FormBorderStyle.Sizable;
}
try
{
device = new Device(0, DeviceType.Hardware, form, CreateFlags.HardwareVertexProcessing, GetDefaultPresentParameters(fullscreen));
}
catch (InvalidCallException)
{
try
{
device = new Device(0, DeviceType.Hardware, form, CreateFlags.SoftwareVertexProcessing, GetDefaultPresentParameters(fullscreen));
}
catch (InvalidCallException)
{
try
{
device = new Device(0, DeviceType.Software, form, CreateFlags.SoftwareVertexProcessing, GetDefaultPresentParameters(fullscreen));
}
catch (InvalidCallException)
{
throw new Exception("Direct3Dデバイスの生成に失敗しました。");
}
}
}
deviceLost = new EventHandler(OnDeviceLost);
deviceReset = new EventHandler(OnDeviceReset);
deviceResizing = new CancelEventHandler(OnDeviceResizing);
device.DeviceLost += deviceLost;
device.DeviceReset += deviceReset;
device.DeviceResizing += deviceResizing;
device.Clear(ClearFlags.Target, Color.FromArgb(212, 208, 200), 0.0f, 0);
sprite = new Sprite(device);
backBuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono);
offScreenImage = new Texture(device, Mafia.SCREEN_WIDTH, Mafia.SCREEN_HEIGHT, 1, Usage.RenderTarget, Manager.Adapters[0].CurrentDisplayMode.Format, Pool.Default);
offScreenSurface = offScreenImage.GetSurfaceLevel(0);
texture = MafiaLoader.DefaultLoader.GetTexture(device, "mafia.bmp");
if (fullscreen)
{
Cursor.Hide();
}
// form.ClientSize = new Size(Mafia.SCREEN_WIDTH, Mafia.SCREEN_HEIGHT);
form.ClientSize = new Size(Mafia.SCREEN_WIDTH * 2, Mafia.SCREEN_HEIGHT * 2);
}
示例5: ProcessRequest
/// <summary>
/// Handle a request.
/// </summary>
/// <param name="pDisplay">The display which called this function.</param>
/// <param name="pSurface">The surface which this display is hosted on.</param>
/// <param name="dArguments">A dictionary of arguments which are passed to the function as parameters.</param>
/// <returns>True if the request was processed sucessfully. False if there was an error.</returns>
public bool ProcessRequest(Display pDisplay, Surface pSurface, JSObject dArguments)
{
// Find the new surface.
var pTargetSurface = Authority.FindSurface(dArguments.GetValueOrDefault("target", ""));
if (pTargetSurface == null)
{
Log.Write("Cannot swap display to target surface. Missing valid 'target' parameter.", pDisplay.ToString(), Log.Type.DisplayWarning);
return false;
}
// Check the surface this view is on is not our target.
if (pTargetSurface == pDisplay.ActiveSurface)
{
Log.Write("Cannot swap display to target surface because it is already there.", pDisplay.ToString(), Log.Type.DisplayWarning);
return false;
}
// If the target surface has a display, get a reference and remove it.
Display pOtherView = pTargetSurface.ActiveDisplay;
if (pOtherView != null)
Authority.RemoveDisplay(pOtherView);
// Remove this display from this surface and put it on the target surface.
Authority.RemoveDisplay(pDisplay);
Authority.ShowDisplay(pDisplay, pTargetSurface);
// Now put the other display on the original surface.
if (pOtherView != null)
Authority.ShowDisplay(pOtherView, pSurface);
// Boom.
return true;
}
示例6: DrawFast
public override void DrawFast(Surface target,int x, int y,int width,int height)
{
if(!dying)
images.DrawFast(target,x,y,width,height,(Direction)direction);
else if(!moving)
images.Death[dieFrame].DrawFast(target,x,y,width,height);
}
示例7: SaveSurface
static unsafe void SaveSurface(Surface surface, string fileName)
{
if (surface.Width > 0 && surface.Height > 0)
{
var bitmap = new Bitmap(surface.Width, surface.Height, PixelFormat.Format24bppRgb);
var bitmapData = bitmap.LockBits(new Rectangle(0, 0, surface.Width, surface.Height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
for (int y = 0; y < surface.Height; y++)
{
var dest = (byte*)bitmapData.Scan0 + y * bitmapData.Stride;
var src = (byte*)surface.Bits + y * surface.Pitch;
for (int x = 0; x < surface.Width; x++)
{
var b = *src++;
*dest++ = b;
*dest++ = b;
*dest++ = b;
}
}
bitmap.UnlockBits(bitmapData);
bitmap.Save(fileName);
bitmap.Dispose();
Marshal.FreeHGlobal(surface.Bits);
}
}
示例8: Direct2DRenderTarget
public Direct2DRenderTarget(DeviceContext10_1 deviceContext10, Surface surface, Format format = Format.B8G8R8A8_UNorm)
{
m_deviceContext10 = deviceContext10;
m_surface = surface;
m_format = format;
InitializeResources(surface);
}
示例9: Doom3Map
public Doom3Map(Doom3MapData map)
{
Surfaces=new List<Surface>();
int verts = 0;
int indices = 0;
foreach(Doom3MapData.Model m in map.Models)
{
foreach(Doom3MapData.Surface s in m.Surfaces)
{
VertexBuffer vb = Root.Instance.UserInterface.Renderer.CreateStaticVertexBuffer(
s.Vertices,
s.Vertices.Length*4*(3+2+3)
);
vb.Format = VertexFormat.VF_P3T2N3;
IndexBuffer ib = new IndexBuffer();
ib.buffer = new int[s.Indices.Length];
for (int i = 0; i < ib.buffer.Length; ++i)
ib.buffer[i] = s.Indices[i];
Surface s2 = new Surface();
s2.Ibuffer = ib;
s2.Vbuffer = vb;
verts += s.Vertices.Length;
indices += s.Indices.Length;
Texture t=null;
try
{
t = Root.Instance.ResourceManager.LoadTexture(s.Name + ".tga");
}
catch (Exception)
{
try
{
t = Root.Instance.ResourceManager.LoadTexture(s.Name + "_add.tga");
}
catch (Exception)
{
try
{
t = Root.Instance.ResourceManager.LoadTexture(s.Name + "_d.tga");
}
catch (Exception )
{
System.Console.WriteLine("warning: cant load "+s.Name);
}
}
}
s2.Material=Material.CreateSimpleMaterial(t);
//s2.Material.Additive = true;
Surfaces.Add(s2);
}
}
System.Console.WriteLine("surfaces: "+Surfaces.Count.ToString());
System.Console.WriteLine("verts: " + verts.ToString());
System.Console.WriteLine("indices: " + indices.ToString());
GC.Collect();
BBox = new BoundingBox(map.BBoxMin, map.BBoxMax);
}
示例10: AttemptRecovery
public static void AttemptRecovery()
{
try
{
Sprite.End();
}
catch
{
}
try
{
Device.EndScene();
}
catch
{
}
try
{
MainSurface = Device.GetBackBuffer(0, 0, BackBufferType.Mono);
CurrentSurface = MainSurface;
Device.SetRenderTarget(0, MainSurface);
}
catch
{
}
}
示例11: PixelDataProvider
public PixelDataProvider(int width, int height, int numChannels, Device device, Usage usage)
: base()
{
Format pf = Format.X8R8G8B8;
switch (numChannels)
{
case 1:
pf = Format.A8;
break;
case 3:
pf = Format.R8G8B8;
break;
case 4:
pf = Format.X8R8G8B8;
break;
case 8:
pf = Format.A16B16G16R16;
break;
}
//TODO: how to find out which Formats are supported??
//device.DeviceCaps.TextureCaps
if (pf == Format.R8G8B8)
pf = Format.X8R8G8B8;
//RenderToSurface sf = new RenderToSurface(device, width, height, pf, false, null);
//this._tx = new Texture(device, width, height, 1, Usage.RenderTarget, pf, Pool.Default); // Pool.Managed doesn't work with Usage.RenderTarget
Pool pool = Pool.Managed;
if (usage == Usage.RenderTarget)
pool = Pool.Default;
this._tx = new Texture(device, width, height, 1, usage, pf, pool);
//this._sd = this._tx.GetLevelDescription(0);
this._surf = this._tx.GetSurfaceLevel(0); //AOAO
this._sd = this._surf.Description;
}
示例12: ProcessRequest
/// <summary>
/// Handle a request.
/// </summary>
/// <param name="pDisplay">The display which called this function.</param>
/// <param name="pSurface">The surface which this display is hosted on.</param>
/// <param name="dArguments">A dictionary of arguments which are passed to the function as parameters.</param>
/// <returns>True if the request was processed sucessfully. False if there was an error.</returns>
public bool ProcessRequest(Display pDisplay, Surface pSurface, JSObject dArguments)
{
// Check we have a function to return the results too.
if (!dArguments.HasProperty("callback")) throw new Exception("Missing 'callback' argument.");
// Return a list of surface names.
JSValue[] lSurfaces = (from pSurf in Authority.Surfaces select new JSValue(pSurf.Identifier)).ToArray();
// If that function is a string.
var jsValue = dArguments["callback"];
if (jsValue.IsString)
{
pDisplay.AsyncCallGlobalFunction(jsValue.ToString(), lSurfaces);
return true;
}
/*
// If it is a function.
else if (jsValue.IsObject)
{
((JSObject)jsValue).Invoke("call", lSurfaces);
return true;
}
*/
// Throw the error.
throw new Exception("Unknown type specified in 'callback' argument. Expected string.");
}
示例13: CreateSurface
protected override Surface CreateSurface()
{
if (calc_width) {
Surface textSurf = GuiUtil.ComposeText (Text, Font, Palette, -1, -1,
Sensitive ? 4 : 24);
Width = (ushort)textSurf.Width;
Height = (ushort)textSurf.Height;
return textSurf;
}
else {
/* this is wrong */
Surface surf = new Surface (Width, Height);
Surface textSurf = GuiUtil.ComposeText (Text, Font, Palette, Width, Height,
Sensitive ? 4 : 24);
int x = 0;
if (Type == ElementType.LabelRightAlign)
x += Width - textSurf.Width;
else if (Type == ElementType.LabelCenterAlign)
x += (Width - textSurf.Width) / 2;
surf.Blit (textSurf, new Point (x, 0));
surf.TransparentColor = Color.Black /* XXX */;
return surf;
}
}
示例14: Setup
private void Setup()
{
try
{
EdgeMap = new Texture(SlimMMDXCore.Instance.Device, width, height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
}
catch (Direct3D9Exception)
{
//あれ?ABGRで無いとダメなん?
EdgeMap = new Texture(SlimMMDXCore.Instance.Device, width, height, 1, Usage.RenderTarget, Format.A8B8G8R8, Pool.Default);
}
renderSurface = EdgeMap.GetSurfaceLevel(0);
depthBuffer = Surface.CreateDepthStencil(SlimMMDXCore.Instance.Device, width, height, Format.D16, MultisampleType.None, 0, true);
//エッジ用エフェクト読み込み
if (effect != null)
{
effect.OnResetDevice();
}
else
{
effect = Effect.FromMemory(SlimMMDXCore.Instance.Device, MMDXResource.MMDEdgeEffect,
#if DEBUG
ShaderFlags.OptimizationLevel0 | ShaderFlags.Debug
#else
ShaderFlags.OptimizationLevel3
#endif
);
}
effect.SetValue("EdgeWidth", EdgeWidth);
effect.Technique = "MMDEdgeEffect";
effect.SetValue("ScreenResolution", new Vector2(width, height));
CreateScreenVertex();
}
示例15: CreateSurface
protected override Surface CreateSurface()
{
if (ParentScreen.Background == null && ParentScreen.UseTiles) {
Surface surf = new Surface (Width, Height);
surf.Fill (new Rectangle (new Point (0,0), new Size (Width, Height)),
Color.FromArgb (0,0,0,0));
surf.TransparentColor = Color.Black; /* XXX */
Pcx pal = new Pcx ();
pal.ReadFromStream ((Stream)Mpq.GetResource ("unit\\cmdbtns\\ticon.pcx"),
-1, -1);
/* tile the top border */
TileRow (surf, tileGrp, pal.Palette, TILE_TL, TILE_T, TILE_TR, 0);
/* tile everything down to the bottom border */
for (int y = tileGrp.Height - 2; y < surf.Height - tileGrp.Height; y += tileGrp.Height - 2)
TileRow (surf, tileGrp, pal.Palette, TILE_L, TILE_C, TILE_R, y);
/* tile the bottom row */
TileRow (surf, tileGrp, pal.Palette, TILE_BL, TILE_B, TILE_BR, surf.Height - tileGrp.Height);
return surf;
}
else
return null;
}