本文整理汇总了C#中SdlDotNet.Graphics.Surface.Lock方法的典型用法代码示例。如果您正苦于以下问题:C# Surface.Lock方法的具体用法?C# Surface.Lock怎么用?C# Surface.Lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SdlDotNet.Graphics.Surface
的用法示例。
在下文中一共展示了Surface.Lock方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetAlert
public virtual void SetAlert(bool on, string message)
{
_onAlert = on;
if (_onAlert && string.IsNullOrEmpty(message)) _onAlert = false;
if (_alertSurface != null) _alertSurface.Dispose();
if (!_onAlert) _alertSurface = null;
if (_onAlert)
{
message += "\n\n" + Properties.Resources.Str_AlertTail;
string[] lines = message.Split('\n');
Size[] sizes = Array.ConvertAll<string, Size>(lines, (l) => { return ResourceManager.SmallPFont.SizeText(l); });
int maxWidth = 0; int height = 0;
foreach (Size s in sizes)
{
if (maxWidth < s.Width) maxWidth = s.Width;
height += (int)(s.Height * Constants.LineHeight);
}
_alertSurface = new Surface(maxWidth + Constants.WindowPadding * 2, height + Constants.WindowPadding * 2);
SdlDotNet.Graphics.Primitives.Box box = new SdlDotNet.Graphics.Primitives.Box(
Point.Empty, new Size(maxWidth + Constants.WindowPadding * 2 - 1, height + Constants.WindowPadding * 2 - 1));
_alertSurface.Lock();
_alertSurface.Draw(box, Constants.Color_AlertBackground, false, true);
_alertSurface.Draw(box, Constants.Color_AlertForeground, false, false);
_alertSurface.Unlock();
int y = Constants.WindowPadding; int idx = 0;
foreach (string l in lines)
{
using (Surface ts = ResourceManager.SmallPFont.Render(l, Constants.Color_AlertForeground))
{
if (idx == lines.Length - 1)
{
_alertSurface.Blit(ts, new Point((int)(_alertSurface.Width / 2.0 - ts.Width / 2.0), y));
}
else
{
_alertSurface.Blit(ts, new Point(Constants.WindowPadding, y));
}
y += (int)(ts.Height * Constants.LineHeight);
}
idx++;
}
_alertSurface.Update();
}
}
示例2: SetAlpha
public static void SetAlpha(Surface s, float a)
{
if (s == null) return;
Color[,] colors = s.GetColors(new Rectangle(0, 0, s.Width, s.Height));
s.Lock();
for (int i = 0; i < colors.GetLength(0); i++)
{
for (int j = 0; j < colors.GetLength(1); j++)
{
Color c = colors[i, j];
int na = (int)(c.A * a);
colors[i, j] = Color.FromArgb(na < 0 ? 0 : (na > 255 ? 255 : na), c.R, c.G, c.B);
}
}
s.SetPixels(Point.Empty, colors);
s.Unlock();
s.Update();
}
示例3: LoadSurfacesFromFile
public static SurfaceCollection LoadSurfacesFromFile(string filePath, Size tileSize)
{
SurfaceCollection ret = new SurfaceCollection();
ret.AlphaBlending = true;
if (!File.Exists(filePath)) return ret;
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(filePath))
{
using (Surface s = new Surface(bmp))
{
s.Lock();
for (int i = 0; i < s.Width; i += tileSize.Width)
{
for (int j = 0; j < s.Height; j += tileSize.Height)
{
Surface ss = new Surface(tileSize.Width, tileSize.Height, 32, s.RedMask, s.GreenMask, s.BlueMask, s.AlphaMask);
ss.Transparent = true;
ss.AlphaBlending = true;
Color[,] tmp = s.GetColors(new Rectangle(i, j, tileSize.Width, tileSize.Height));
ss.Lock();
ss.SetPixels(Point.Empty, tmp);
tmp = ss.GetColors(new Rectangle(0, 0, ss.Width, ss.Height));
ss.Unlock();
ss.Update();
ret.Add(ss);
}
}
s.Unlock();
}
}
return ret;
}
示例4: SetColor
public static void SetColor(Surface s, Color c)
{
if (s == null) return;
Color[,] colors = s.GetColors(new Rectangle(0, 0, s.Width, s.Height));
s.Lock();
for (int i = 0; i < colors.GetLength(0); i++)
{
for (int j = 0; j < colors.GetLength(1); j++)
{
colors[i, j] = Color.FromArgb(colors[i, j].A, c.R, c.G, c.B);
}
}
s.SetPixels(Point.Empty, colors);
s.Unlock();
s.Update();
}
示例5: CreateColored
public static Surface CreateColored(Surface s, Color c0, Color c1)
{
if (s == null) return null;
Color[,] colors = s.GetColors(new Rectangle(0, 0, s.Width, s.Height));
for (int i = 0; i < colors.GetLength(0); i++)
{
for (int j = 0; j < colors.GetLength(1); j++)
{
Color c = colors[i, j];
float br = (c.R / 255.0f + c.G / 255.0f + c.B / 255.0f) / 3.0f;
if (br > 0.8f)
{
br = 1.0f;
}
else if (br < 0.2f)
{
br = 0.0f;
}
int r = (int)((1 - br) * c0.R + br * c1.R);
int g = (int)((1 - br) * c0.G + br * c1.G);
int b = (int)((1 - br) * c0.B + br * c1.B);
r = r < 0 ? 0 : (r > 255 ? 255 : r);
g = g < 0 ? 0 : (g > 255 ? 255 : g);
b = b < 0 ? 0 : (b > 255 ? 255 : b);
colors[i, j] = Color.FromArgb(c.A, r, g, b);
Color nc = Color.FromArgb(c.A, r, g, b);
}
}
Surface ns = new Surface(s.Width, s.Height, s.BitsPerPixel, s.RedMask, s.GreenMask, s.BlueMask, s.AlphaMask);
ns.AlphaBlending = s.AlphaBlending;
ns.Alpha = s.Alpha;
ns.Transparent = s.Transparent;
ns.TransparentColor = s.TransparentColor;
ns.Lock();
ns.SetPixels(Point.Empty, colors);
ns.Unlock();
ns.Update();
return ns;
}
示例6: GetAvgColor
public static Color GetAvgColor(Surface s)
{
s.Lock();
Color[,] tmp = s.GetColors(new Rectangle(0, 0, s.Width, s.Height));
s.Unlock();
int num = 0;
double a = 0; double r = 0; double g = 0; double b = 0;
for (int i = 0; i < tmp.GetLength(0); i++)
{
for (int j = 0; j < tmp.GetLength(1); j++)
{
Color pc = tmp[i, j];
if (pc.A != 0)
{
a += pc.A; r += pc.R; g += pc.G; b += pc.B;
num++;
}
}
}
if (num == 0) return Color.Transparent;
a /= (double)num; r /= (double)num; g /= (double)num; b /= (double)num;
int ia = (int)a; int ir = (int)r; int ig = (int)g; int ib = (int)b;
ia = ia < 0 ? 0 : (ia > 255 ? 255 : ia);
ir = ir < 0 ? 0 : (ir > 255 ? 255 : ir);
ig = ig < 0 ? 0 : (ig > 255 ? 255 : ig);
ib = ib < 0 ? 0 : (ib > 255 ? 255 : ib);
return Color.FromArgb(ia, ir, ig, ib);
}
示例7: Render
public virtual void Render(Surface s, Rectangle r)
{
if (_startLineSurface == null)
{
#warning パフォーマンスチェック
using (Surface ts = ResourceManager.LargePFont.Render("START", _foreColor, true))
{
_startLineSurface = new Surface(ts.Width + 20, view.Height, 32, ts.RedMask, ts.GreenMask, ts.BlueMask, ts.AlphaMask);
Color[,] tmp = ts.GetColors(new Rectangle(0, 0, ts.Width, ts.Height));
for (int i = 0; i < tmp.GetLength(0); i++)
{
for (int j = 0; j < tmp.GetLength(1); j++)
{
Color c = tmp[i, j];
tmp[i, j] = Color.FromArgb((int)(c.A / 2.0), c.R, c.G, c.B);
}
}
_startLineSurface.Lock();
_startLineSurface.SetPixels(new Point(20, (int)(_startLineSurface.Height / 2.0 - ts.Height / 2.0)), tmp);
_startLineSurface.Unlock();
}
_startLineSurface.Fill(new Rectangle(0, 0, 3, _startLineSurface.Height), Color.FromArgb(128, _foreColor.R, _foreColor.G, _foreColor.B));
_startLineSurface.Update();
_startLineSurface.AlphaBlending = true;
}
if (_goalLineSurface == null)
{
using (Surface ts = ResourceManager.LargePFont.Render("GOAL", _foreColor, true))
{
_goalLineSurface = new Surface(ts.Width + 20, view.Height, 32, ts.RedMask, ts.GreenMask, ts.BlueMask, ts.AlphaMask);
Color[,] tmp = ts.GetColors(new Rectangle(0, 0, ts.Width, ts.Height));
for (int i = 0; i < tmp.GetLength(0); i++)
{
for (int j = 0; j < tmp.GetLength(1); j++)
{
Color c = tmp[i, j];
tmp[i, j] = Color.FromArgb((int)(c.A / 2.0), c.R, c.G, c.B);
}
}
_goalLineSurface.Lock();
_goalLineSurface.SetPixels(new Point(0, (int)(_goalLineSurface.Height / 2.0 - ts.Height / 2.0)), tmp);
_goalLineSurface.Unlock();
}
_goalLineSurface.Fill(new Rectangle(_goalLineSurface.Width - 3, 0, 3, _goalLineSurface.Height), Color.FromArgb(128, _foreColor.R, _foreColor.G, _foreColor.B));
_goalLineSurface.Update();
_goalLineSurface.AlphaBlending = true;
}
renderBackground(s, r);
if (_startLineSurface.Width >= view.X && view.X + view.Width >= 0)
{
s.Blit(_startLineSurface, new Point(
(int)(r.X - view.X),
(int)(r.Y + view.Height / 2.0 - _startLineSurface.Height / 2.0)));
}
if (this.HasEnd)
{
if (this.Width >= view.X && view.X + view.Width >= this.Width - _goalLineSurface.Width)
{
s.Blit(_goalLineSurface, new Point(
(int)(r.X + this.Width - _goalLineSurface.Width - view.X),
(int)(r.Y + view.Height / 2.0 - _goalLineSurface.Height / 2.0)));
}
}
renderForeground(s, r);
}
示例8: RenderInformation
public virtual void RenderInformation(Surface s, Rectangle rect)
{
// 結果値
using (Surface sc = new Surface(rect.Size))
{
sc.Lock();
sc.Alpha = 100;
sc.AlphaBlending = true;
sc.Fill(Color.DarkGreen);
sc.Unlock();
s.Blit(sc, rect.Location);
}
using (Surface sc = new Surface(rect.Size))
{
sc.Transparent = true;
sc.Draw(new SdlDotNet.Graphics.Primitives.Box(Point.Empty, new Size(rect.Width - 1, rect.Height - 1)),
Color.White, true, false);
sc.Blit(ResourceManager.SmallTTFont.Render(
string.Format("({0},{1}), {2}x{3}", X, Y, Width, Height),
Color.White, true), new Point(10, 10));
sc.Blit(ResourceManager.SmallTTFont.Render(
string.Format("HP: {0}", _hp),
Color.White, true), new Point(10, 13 + ResourceManager.SmallTTFont.Height));
s.Blit(sc, rect.Location);
}
}