本文整理匯總了C#中SdlDotNet.Graphics.Surface.Update方法的典型用法代碼示例。如果您正苦於以下問題:C# Surface.Update方法的具體用法?C# Surface.Update怎麽用?C# Surface.Update使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SdlDotNet.Graphics.Surface
的用法示例。
在下文中一共展示了Surface.Update方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
public static void Main(string[] args)
{
Events.Quit += new EventHandler<QuitEventArgs>(ApplicationQuitEventHandler);
Surface plate = Video.SetVideoMode(220, 220, 32, false, false, false, true);
Surface pic = new Surface("nyanbig.png");
pic.Update();
Population fellows = new Population(15, 100);
List<float> fitnesses;
while (fellows.members[0].fitness < 700f)
{
fitnesses = new List<float>();
foreach (Genome g in fellows.members)
{
g.Draw(plate);
Console.Read();
float f = g.GetFitness(plate, pic);
fitnesses.Add(f);
g.fitness = f;
}
fellows.members.Sort();
fellows.members[0].Draw(plate);
Console.WriteLine(fellows.members[0].fitness);
int x = 0;
}
}
示例2: 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();
}
}
示例3: drawOctaveSelecting
private void drawOctaveSelecting(SdlDotNet.Graphics.Surface s)
{
if (_octaveSelectingSurface == null)
{
using (Surface ts = ImageUtil.CreateMultilineStringSurface(new string[] {
Properties.Resources.Str_OctaveSelecting,
null, null, null,
Properties.Resources.Str_OctaveSelecting_Operation },
ResourceManager.SmallPFont, Constants.Color_Background, TextAlign.Center))
{
_octaveSelectingSurface = new Surface(
ts.Width + Constants.WindowPadding * 2,
ts.Height + Constants.WindowPadding * 2);
_octaveSelectingSurface.Fill(Constants.Color_Foreground);
_octaveSelectingSurface.Blit(ts, new Point(Constants.WindowPadding, Constants.WindowPadding));
_octaveSelectingSurface.Update();
}
_octaveUpSurface = ResourceManager.SmallPFont.Render(Properties.Resources.Str_UpArrow, Constants.Color_Background);
_octaveDownSurface = ResourceManager.SmallPFont.Render(Properties.Resources.Str_DownArrow, Constants.Color_Background);
}
s.Blit(_octaveSelectingSurface, new Point(
(int)(Constants.ScreenWidth / 2.0 - _octaveSelectingSurface.Width / 2.0),
(int)(Constants.ScreenHeight / 2.0 - _octaveSelectingSurface.Height / 2.0)));
int fh = (int)(ResourceManager.SmallPFont.Height * Constants.LineHeight);
int y = Constants.WindowPadding +
(int)(Constants.ScreenHeight / 2.0 - _octaveSelectingSurface.Height / 2.0) + fh;
if (_octave < Constants.MaxOctave)
{
s.Blit(_octaveUpSurface, new Point((int)(Constants.ScreenWidth / 2.0 - _octaveUpSurface.Width / 2.0), y));
}
y += fh;
using (Surface ts = ResourceManager.SmallPFont.Render(_octave.ToString(), Constants.Color_Background))
{
s.Blit(ts, new Point((int)(Constants.ScreenWidth / 2.0 - ts.Width / 2.0), y));
}
y += fh;
if (_octave > Constants.MinOctave)
{
s.Blit(_octaveDownSurface, new Point((int)(Constants.ScreenWidth / 2.0 - _octaveDownSurface.Width / 2.0), y));
}
}
示例4: Go
//Main program loop
private void Go()
{
//Set up screen
if (File.Exists(Path.Combine(dataDirectory, "background.png")))
{
filePath = "";
}
background = new Surface(Path.Combine(filePath, Path.Combine(dataDirectory, "background.png")));
Video.WindowIcon();
Video.WindowCaption = "SDL.NET - Bounce Sprites";
screen = Video.SetVideoMode(width, height);
screen.Blit(background);
screen.Update();
//This loads the various images (provided by Moonfire)
// into a SurfaceCollection for animation
SurfaceCollection marbleSurfaces = new SurfaceCollection();
marbleSurfaces.Add(new Surface(Path.Combine(filePath, Path.Combine(dataDirectory, "marble1.png"))), new Size(50, 50));
for (int i = 0; i < this.maxBalls; i++)
{
//Create a new Sprite at a random location on the screen
master.Add(new BounceSprite(marbleSurfaces,
new Point(rand.Next(screen.Rectangle.Left, screen.Rectangle.Right),
rand.Next(screen.Rectangle.Top, screen.Rectangle.Bottom))));
}
//The collection will respond to mouse button clicks, mouse movement and the ticker.
master.EnableMouseButtonEvent();
master.EnableMouseMotionEvent();
master.EnableTickEvent();
//These bind the events to the above methods.
Events.KeyboardDown +=
new EventHandler<KeyboardEventArgs>(this.KeyboardDown);
Events.Tick += new EventHandler<TickEventArgs>(this.Tick);
Events.Quit += new EventHandler<QuitEventArgs>(this.Quit);
//Start the event ticker
Events.Run();
}
示例5: 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;
}
示例6: DrawInfoPanel
public void DrawInfoPanel(Surface surface, LeadActor player, Skin[] skinGroup)
{
/* Draws the information panel on the surface.
surface: The area of the surface to draw into from the pygame window: surface class
player: The lead actor being used for the player: lead_actor class
skin_group: The group of skins to be used in the engines isometric view: skin class
*/
if (surface == null)
{
throw new ArgumentNullException("surface");
}
if (player == null)
{
throw new ArgumentNullException("player");
}
//draw titlebar
Rectangle rect = surface.Blit(this.titleSprite.Surface, this.titleSprite.Rectangle);
int[] draw_order;
//draw inventory
Object3d[] inventory_array = new Object3d[player.Inventory.Count];
for (int i = 0; i < player.Inventory.Count; i++)
{
inventory_array[i] = (Object3d)player.Inventory[i];
}
if (player.Inventory.Count > 0)
{
Sprite[] sprite_group = Sprites.UpdateImages(skinGroup, inventory_array);
int p = 155;
draw_order = new int[player.Inventory.Count];
int q = 0;
for (int i = player.UsingObject; i < player.Inventory.Count; i++)
{
draw_order[q] = i;
q++;
}
for (int i = 0; i < player.UsingObject; i++)
{
draw_order[q] = i;
q++;
}
foreach (int i in draw_order)
{
sprite_group[i].X = p;
sprite_group[i].Y = 38 - sprite_group[i].Height;
surface.Blit(sprite_group[i].Surface, sprite_group[i].Rectangle);
Surface text = this.font.Render(skinGroup[inventory_array[i].ObjectType].Name, Color.FromArgb(255, 255, 255));
Point textpos = new Point(0, 0);
textpos.X = p - skinGroup[inventory_array[i].ObjectType].Name.Length * 3 + sprite_group[i].Width / 2;
textpos.Y = 35;
surface.Blit(text, textpos);
p = p + sprite_group[i].Width + 20;
}
}
//Update the display with the panel changes
surface.Update(rect);
}
示例7: LoadSurfaces
public static SurfaceCollection LoadSurfaces(string[] resourceNames)
{
SurfaceCollection ret = new SurfaceCollection();
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
foreach (string resourceName in resourceNames)
{
using (Bitmap bmp = new Bitmap(asm.GetManifestResourceStream(getImgResourceFullName(resourceName))))
{
Surface s = new Surface(bmp);
s.AlphaBlending = true;
s.Update();
ret.Add(s);
}
}
ret.AlphaBlending = true;
return ret;
}
示例8: 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();
}
示例9: LoadSurface
public static Surface LoadSurface(string resourceName)
{
Surface ret = null;
using (Bitmap bmp = getImgResource(resourceName))
{
ret = new Surface(bmp);
ret.AlphaBlending = true;
}
ret.Update();
return ret;
}
示例10: 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();
}
示例11: 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;
}
示例12: 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);
}
示例13: ViewUpdate
/// <summary>
///
/// </summary>
/// <param name="surface"></param>
/// <param name="objectGroup"></param>
/// <param name="skin_group"></param>
/// <param name="offset"></param>
/// <param name="old_rect"></param>
/// <returns></returns>
public static Rectangle[] ViewUpdate(Surface surface, Object3d[] objectGroup, Skin[] skinGroup, int[] offset, Rectangle[] oldRect)
{
/* Update the isometric view based only on the changes in the screen
surface: The pygame display area to be drawn into: surface
object_group: a list of objects to be displayed: list of objects_3d or subclass
skin_group: a list of skins which will be used to find the correct image for the objects sprite: list of skins
offset: 2d vector to add to the isometric coordinates: list of 2 integers [x,y]
old_rect: A list of pygame rectangles where the old sprites were drawn for updating: list of rect
Returns old_rect: see above
*/
if (skinGroup == null)
{
throw new ArgumentNullException("skinGroup");
}
if (objectGroup == null)
{
throw new ArgumentNullException("objectGroup");
}
if (surface == null)
{
throw new ArgumentNullException("surface");
}
// Find out what objects are visable
int visable_limit = skinGroup.Length;
//Object3d[] visable_object_group;
ArrayList visable_object_list = new ArrayList();
foreach (Object3d obj in objectGroup)
{
if (obj.ObjectType < visable_limit)
{
visable_object_list.Add(obj);
}
}
Object3d[] visable_object_group = new Object3d[visable_object_list.Count];
visable_object_list.CopyTo(visable_object_group);
// Draw the isometric view in the display surface
Rectangle[] sprite_rect = ViewDraw(surface, (Object3d[])visable_object_group, skinGroup, offset);
// Combines the rectangles that need updating: the new sprites and the old background rectangles
Rectangle[] update_rect = Sprites.CombineRectangles(sprite_rect, oldRect);
// Update the display
surface.Update(update_rect);
// Remember the sprite rectangles
oldRect = new Rectangle[sprite_rect.Length];
for (int rect = 0; rect < sprite_rect.Length; rect++)
{
oldRect[rect] = sprite_rect[rect];
}
return (oldRect);
}
示例14: Render
//public Surface UpdateImage(ImageBox imageBox)
//{
// //_surface.Update(
//}
/// <summary>
/// Render surface
/// </summary>
/// <returns></returns>
public Surface Render(Rectangle rect, bool forceRender)
{
//Create temporary surface
Surface tempSurface = new Surface(rect.Width, _size.Height);
tempSurface.Fill(Color.White);
//Render surface
if (Rearrange() || _surface == null || forceRender) //Check is redraw necessary
{
lock (_spriteCln)
{
Surface oldSurface = _surface;
_surface = new Surface(_size);
if (oldSurface != null)
oldSurface.Dispose(); //Clean up old surface memory
_surface.Fill(Color.White);
Collection<Rectangle> rects = _surface.Blit(_spriteCln);
_surface.Update(rects);
}
}
//Blit surface to temporary surface
tempSurface.Blit(_surface);
tempSurface.Fill(new Rectangle(_size.Width, 0, rect.Width - _size.Width, _size.Height)
, Color.White); //Fill the gap with white
Debug.WriteLine("Render size: " + tempSurface.Width + "," + tempSurface.Height);
return tempSurface;
}