void drawTree <T>(QuadTree <T> qt) where T : IRegion { if (qt != null) { Vector2 p1 = new Vector2(qt.Span.XMax, qt.Span.YMin); Vector2 p2 = new Vector2(qt.Span.XMin, qt.Span.YMin); Vector2 p3 = new Vector2(qt.Span.XMin, qt.Span.YMax); Vector2 p4 = new Vector2(qt.Span.XMax, qt.Span.YMax); float t = 1f; GraphicsUtils.DrawLineTop(p1, p2, Color.GreenYellow, t); GraphicsUtils.DrawLineTop(p2, p3, Color.GreenYellow, t); GraphicsUtils.DrawLineTop(p3, p4, Color.GreenYellow, t); GraphicsUtils.DrawLineTop(p4, p1, Color.GreenYellow, t); if (qt.SubTrees != null) { foreach (var qtsub in qt.SubTrees) { drawTree <T>(qtsub); } } } }
private static LTexture GetRMXPDialog(LImage rmxpImage, int width, int height, int size, int offset) { if (lazyImages == null) { lazyImages = new Dictionary <string, LTexture>(10); } string keyName = "dialog" + width + "|" + height; LTexture lazy = (LTexture)CollectionUtils.Get(lazyImages, keyName); if (lazy == null) { try { int objWidth = 64; int objHeight = 64; int x1 = 128; int x2 = 192; int y1 = 0; int y2 = 64; int center_size = objHeight - size * 2; LImage lazyImage = null; LImage image = null; LImage messageImage = null; image = GraphicsUtils.DrawClipImage(rmxpImage, objWidth, objHeight, x1, y1, x2, y2); LImage centerTop = GraphicsUtils.DrawClipImage(image, center_size, size, size, 0); LImage centerDown = GraphicsUtils.DrawClipImage(image, center_size, size, size, objHeight - size); LImage leftTop = GraphicsUtils.DrawClipImage(image, size, size, 0, 0); LImage leftCenter = GraphicsUtils.DrawClipImage(image, size, center_size, 0, size); LImage leftDown = GraphicsUtils.DrawClipImage(image, size, size, 0, objHeight - size); LImage rightTop = GraphicsUtils.DrawClipImage(image, size, size, objWidth - size, 0); LImage rightCenter = GraphicsUtils.DrawClipImage(image, size, center_size, objWidth - size, size); LImage rightDown = GraphicsUtils.DrawClipImage(image, size, size, objWidth - size, objHeight - size); lazyImage = centerTop; lazyImage = LImage.CreateImage(width, height, true); LGraphics g = lazyImage.GetLGraphics(); g.SetAlpha(0.5f); messageImage = GraphicsUtils.DrawClipImage(rmxpImage, 128, 128, 0, 0, 128, 128); messageImage = GraphicsUtils.GetResize(messageImage, width - offset, height - offset); messageImage.XNAUpdateAlpha(125); g.DrawImage(messageImage, (lazyImage.Width - messageImage.Width) / 2 + 1, (lazyImage.Height - messageImage .Height) / 2 + 1); LImage tmp = GraphicsUtils.GetResize(centerTop, width - (size * 2), size); g.DrawImage(tmp, size, 0); if (tmp != null) { tmp.Dispose(); tmp = null; } tmp = GraphicsUtils.GetResize(centerDown, width - (size * 2), size); g.DrawImage(tmp, size, height - size); if (tmp != null) { tmp.Dispose(); tmp = null; } g.DrawImage(leftTop, 0, 0); tmp = GraphicsUtils.GetResize(leftCenter, leftCenter.GetWidth(), width - (size * 2)); g.DrawImage(tmp, 0, size); if (tmp != null) { tmp.Dispose(); tmp = null; } g.DrawImage(leftDown, 0, height - size); int right = width - size; g.DrawImage(rightTop, right, 0); tmp = GraphicsUtils.GetResize(rightCenter, leftCenter .Width, width - (size * 2)); g.DrawImage(tmp, right, size); if (tmp != null) { tmp.Dispose(); tmp = null; } g.DrawImage(rightDown, right, height - size); g.Dispose(); lazy = lazyImage.GetTexture(); lazyImages.Add(keyName, lazy); image.Dispose(); messageImage.Dispose(); centerTop.Dispose(); centerDown.Dispose(); leftTop.Dispose(); leftCenter.Dispose(); leftDown.Dispose(); rightTop.Dispose(); rightCenter.Dispose(); rightDown.Dispose(); image = null; messageImage = null; centerTop = null; centerDown = null; leftTop = null; leftCenter = null; leftDown = null; rightTop = null; rightCenter = null; rightDown = null; } catch (Exception ex) { Loon.Utils.Debugging.Log.Exception(ex); } } return(lazy); }
public override void paint(Graphics g, bool drawHandles, ViewParameters parameters) { Brush shadow = new SolidBrush(crop.Editing ? Color.FromArgb(0xb0, crop.ShapeColor) : SystemColors.Control); Point p1 = parameters.toAbsolute(crop.Handles["start"]); Point p2 = parameters.toAbsolute(crop.Handles["end"]); if (p1.X > p2.X) { int x = p2.X; p2.X = p1.X; p1.X = x; } if (p1.Y > p2.Y) { int y = p2.Y; p2.Y = p1.Y; p1.Y = y; } Rectangle[] rects = new Rectangle[4]; rects[0] = new Rectangle(0, 0, parameters.CanvasSize.Width, p1.Y); rects[1] = new Rectangle(0, crop.Editing ? p1.Y : 0, p1.X, crop.Editing ? (p2.Y - p1.Y) : parameters.CanvasSize.Height); rects[2] = new Rectangle(0, p2.Y, parameters.CanvasSize.Width, parameters.CanvasSize.Height - p2.Y); rects[3] = new Rectangle(p2.X, crop.Editing ? p1.Y : 0, parameters.CanvasSize.Width - p2.X, crop.Editing ? (p2.Y - p1.Y) : parameters.CanvasSize.Height); g.FillRectangles(shadow, rects); if (crop.Editing) { Pen penActive = new Pen(Color.Red, 1); g.DrawLine(penActive, 0, p1.Y, parameters.CanvasSize.Width, p1.Y); g.DrawLine(penActive, p1.X, 0, p1.X, parameters.CanvasSize.Height); g.DrawLine(penActive, 0, p2.Y, parameters.CanvasSize.Width, p2.Y); g.DrawLine(penActive, p2.X, 0, p2.X, parameters.CanvasSize.Height); #if false if (ConfigDialog.Instance.ShowUsageHints) { Font f = new Font("Arial", 10, FontStyle.Bold); Size s = g.MeasureString(HINT_TXT, f).ToSize(); Brush b1 = new SolidBrush(Color.FromArgb(0x80, crop.ShapeColor)); Brush b2 = new SolidBrush(Color.Red); int x1 = ((parameters.Viewport.Width - s.Width) / 2) - 5; const int y1 = 0; g.FillRectangle(b1, x1, y1, s.Width + 10, s.Height + 10); g.DrawString(HINT_TXT, f, b2, x1 + 5, y1 + 5); b1.Dispose(); b2.Dispose(); f.Dispose(); } #endif Font f = new Font("Arial", 12, GraphicsUnit.Pixel); Brush fgb = new SolidBrush(Color.White); Brush bgb = new SolidBrush(Color.Red); RectangleF rectangle = crop.CropRectangle; int width = (int)(rectangle.Width); int height = (int)(rectangle.Height); string text = string.Format("{0}x{1}", width, height); SizeF s = g.MeasureString(text, f); int x = (int)(p1.X + (p2.X - p1.X - s.Width) / 2); int y = (int)(p1.Y + (p2.Y - p1.Y - s.Height) / 2); GraphicsUtils.drawText(g, f, fgb, bgb, text, x, y); f.Dispose(); fgb.Dispose(); bgb.Dispose(); penActive.Dispose(); } else { Pen outline = new Pen(Color.Black, 1); g.DrawRectangle(outline, p1.X, p1.Y, p2.X - p1.X, p2.Y - p1.Y); outline.Dispose(); } shadow.Dispose(); }
private Bitmap GetImageToReturn(String imageFilename, ImageSize imagesize, Size boundingRectangle) { // Precondition: imageFilename refers to an existing filename. Bitmap originalImage; try { originalImage = new Bitmap(imageFilename); } catch { // If an exception was thrown, that means // the given filename does not contain an image. // Throw an exception to tell the caller. throw new ImageHandlerException(String.Format("ERROR: The file '{0}' does not refer to a valid image file.", imageFilename)); } switch (imagesize) { case ImageSize.OriginalSize: return(originalImage); case ImageSize.Thumbnail: { // This HTTP handler can be used my multiple processes. // This is the only place in the code where two processes could interfere // with each other by trying to write a new thumbnail to the same file // at the same time. lock (_semaphore) { Bitmap thumbnail; // Does the thumbnail image folder exist? String thumbnailFolder = Path.Combine(Path.GetDirectoryName(imageFilename), "Thumbnails"); Directory.CreateDirectory(thumbnailFolder); // Does the thumbnail image exist? String thumbnailFilename = Path.Combine(thumbnailFolder, Path.GetFileName(imageFilename)); if (File.Exists(thumbnailFilename)) { try { thumbnail = new Bitmap(thumbnailFilename); } catch { // If there was any problem in creating the thumbnail from // an existing file, assume the file does not contain a valid image. throw new ImageHandlerException(String.Format("ERROR: The file '{0}' does not appear to contain a valid image.", thumbnailFilename)); } // It's possible the caller requested a thumbnail of a different size // via the width and height querystring parameters. // If they did, create a new thumbnail of the requested size and // return that. if (thumbnail.Size != boundingRectangle) { thumbnail.Dispose(); thumbnail = GraphicsUtils.GetResizedImage(originalImage, boundingRectangle); thumbnail.Save(thumbnailFilename); } } else { thumbnail = GraphicsUtils.GetResizedImage(originalImage, boundingRectangle); thumbnail.Save(thumbnailFilename); } return(new Bitmap(thumbnail)); } } default: throw new ImageHandlerException("Unknown ImageSize enumeration value."); } }
public override void OnDisable() { GraphicsUtils.Destroy(m_GrainLookupRT); m_GrainLookupRT = null; }
public override void Draw(Microsoft.Xna.Framework.GameTime time, Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) { GraphicsUtils.DrawBall(this.Position, 5, Color.HotPink, 255, 0.0f); }
public void OnCreate(bool m_landscape, bool m_fullscreen) { if (!m_landscape) { if (LSystem.MAX_SCREEN_HEIGHT > LSystem.MAX_SCREEN_WIDTH) { int tmp_height = LSystem.MAX_SCREEN_HEIGHT; LSystem.MAX_SCREEN_HEIGHT = LSystem.MAX_SCREEN_WIDTH; LSystem.MAX_SCREEN_WIDTH = tmp_height; } } RectBox d = GetScreenDimension(); LSystem.SCREEN_LANDSCAPE = m_landscape; this.CheckDisplayMode(); //下列代码修正屏幕大小为LSetting设定尺寸 this.maxWidth = (int)d.GetWidth(); this.maxHeight = (int)d.GetHeight(); if (m_landscape && (d.GetWidth() > d.GetHeight())) { maxWidth = (int)d.GetWidth(); maxHeight = (int)d.GetHeight(); } else if (m_landscape && (d.GetWidth() < d.GetHeight())) { maxHeight = (int)d.GetWidth(); maxWidth = (int)d.GetHeight(); } else if (!m_landscape && (d.GetWidth() < d.GetHeight())) { maxWidth = (int)d.GetWidth(); maxHeight = (int)d.GetHeight(); } else if (!m_landscape && (d.GetWidth() > d.GetHeight())) { maxHeight = (int)d.GetWidth(); maxWidth = (int)d.GetHeight(); } if (m_mode != LMode.Max) { if (m_landscape) { this.width = LSystem.MAX_SCREEN_WIDTH; this.height = LSystem.MAX_SCREEN_HEIGHT; } else { this.width = LSystem.MAX_SCREEN_HEIGHT; this.height = LSystem.MAX_SCREEN_WIDTH; } } else { if (m_landscape) { this.width = maxWidth >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH : maxWidth; this.height = maxHeight >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT : maxHeight; } else { this.width = maxWidth >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT : maxWidth; this.height = maxHeight >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH : maxHeight; } } if (m_mode == LMode.Fill) { LSystem.scaleWidth = ((float)maxWidth) / width; LSystem.scaleHeight = ((float)maxHeight) / height; } else if (m_mode == LMode.FitFill) { RectBox res = GraphicsUtils.FitLimitSize(width, height, maxWidth, maxHeight); maxWidth = res.width; maxHeight = res.height; LSystem.scaleWidth = ((float)maxWidth) / width; LSystem.scaleHeight = ((float)maxHeight) / height; } else if (m_mode == LMode.Ratio) { maxWidth = MeasureSpec.GetSize(maxWidth); maxHeight = MeasureSpec.GetSize(maxHeight); float userAspect = (float)width / (float)height; float realAspect = (float)maxWidth / (float)maxHeight; if (realAspect < userAspect) { maxHeight = MathUtils.Round(maxWidth / userAspect); } else { maxWidth = MathUtils.Round(maxHeight * userAspect); } LSystem.scaleWidth = ((float)maxWidth) / width; LSystem.scaleHeight = ((float)maxHeight) / height; } else if (m_mode == LMode.MaxRatio) { maxWidth = MeasureSpec.GetSize(maxWidth); maxHeight = MeasureSpec.GetSize(maxHeight); float userAspect = (float)width / (float)height; float realAspect = (float)maxWidth / (float)maxHeight; if ((realAspect < 1 && userAspect > 1) || (realAspect > 1 && userAspect < 1)) { userAspect = (float)height / (float)width; } if (realAspect < userAspect) { maxHeight = MathUtils.Round(maxWidth / userAspect); } else { maxWidth = MathUtils.Round(maxHeight * userAspect); } LSystem.scaleWidth = ((float)maxWidth) / width; LSystem.scaleHeight = ((float)maxHeight) / height; } else { LSystem.scaleWidth = 1f; LSystem.scaleHeight = 1f; } if (LSystem.screenRect == null) { LSystem.screenRect = new RectBox(0, 0, width, height); } else { LSystem.screenRect.SetBounds(0, 0, width, height); } //PS:width与height为期望的游戏画布大小,而maxWidth和maxHeight为实际的手机屏幕大小 graphics.PreferredBackBufferFormat = m_displayMode.Format; graphics.PreferredBackBufferWidth = maxWidth; graphics.PreferredBackBufferHeight = maxHeight; if (m_landscape) { graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight; } else { graphics.SupportedOrientations = DisplayOrientation.Portrait; } //画面渲染与显示器同步 graphics.SynchronizeWithVerticalRetrace = false; graphics.PreferMultiSampling = true; graphics.PreparingDeviceSettings += new EventHandler <PreparingDeviceSettingsEventArgs>(Inner_deviceSettings); #if WINDOWS graphics.IsFullScreen = false; IsMouseVisible = true; #elif XBOX || WINDOWS_PHONE //全屏 if (m_fullscreen) { graphics.IsFullScreen = true; } else { graphics.IsFullScreen = false; } #endif base.IsFixedTimeStep = false; graphics.ApplyChanges(); }
public void Initialization(bool l, bool f, LMode m) { log.I("GPU surface"); this.landscape = l; this.fullScreen = f; this.mode = m; if (landscape == false) { if (LSystem.MAX_SCREEN_HEIGHT > LSystem.MAX_SCREEN_WIDTH) { int tmp_height = LSystem.MAX_SCREEN_HEIGHT; LSystem.MAX_SCREEN_HEIGHT = LSystem.MAX_SCREEN_WIDTH; LSystem.MAX_SCREEN_WIDTH = tmp_height; } } this.CheckDisplayMode(); RectBox d = GetScreenDimension(); LSystem.SCREEN_LANDSCAPE = landscape; this.maxWidth = (int)d.GetWidth(); this.maxHeight = (int)d.GetHeight(); if (landscape && (d.GetWidth() > d.GetHeight())) { maxWidth = (int)d.GetWidth(); maxHeight = (int)d.GetHeight(); } else if (landscape && (d.GetWidth() < d.GetHeight())) { maxHeight = (int)d.GetWidth(); maxWidth = (int)d.GetHeight(); } else if (!landscape && (d.GetWidth() < d.GetHeight())) { maxWidth = (int)d.GetWidth(); maxHeight = (int)d.GetHeight(); } else if (!landscape && (d.GetWidth() > d.GetHeight())) { maxHeight = (int)d.GetWidth(); maxWidth = (int)d.GetHeight(); } if (mode != LMode.Max) { if (landscape) { this.width = LSystem.MAX_SCREEN_WIDTH; this.height = LSystem.MAX_SCREEN_HEIGHT; } else { this.width = LSystem.MAX_SCREEN_HEIGHT; this.height = LSystem.MAX_SCREEN_WIDTH; } } else { if (landscape) { this.width = maxWidth >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH : maxWidth; this.height = maxHeight >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT : maxHeight; } else { this.width = maxWidth >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT : maxWidth; this.height = maxHeight >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH : maxHeight; } } if (mode == LMode.Fill) { LSystem.scaleWidth = ((float)maxWidth) / width; LSystem.scaleHeight = ((float)maxHeight) / height; } else if (mode == LMode.FitFill) { RectBox res = GraphicsUtils.FitLimitSize(width, height, maxWidth, maxHeight); maxWidth = res.width; maxHeight = res.height; LSystem.scaleWidth = ((float)maxWidth) / width; LSystem.scaleHeight = ((float)maxHeight) / height; } else if (mode == LMode.Ratio) { maxWidth = MeasureSpec.GetSize(maxWidth); maxHeight = MeasureSpec.GetSize(maxHeight); float userAspect = (float)width / (float)height; float realAspect = (float)maxWidth / (float)maxHeight; if (realAspect < userAspect) { maxHeight = MathUtils.Round(maxWidth / userAspect); } else { maxWidth = MathUtils.Round(maxHeight * userAspect); } LSystem.scaleWidth = ((float)maxWidth) / width; LSystem.scaleHeight = ((float)maxHeight) / height; } else if (mode == LMode.MaxRatio) { maxWidth = MeasureSpec.GetSize(maxWidth); maxHeight = MeasureSpec.GetSize(maxHeight); float userAspect = (float)width / (float)height; float realAspect = (float)maxWidth / (float)maxHeight; if ((realAspect < 1 && userAspect > 1) || (realAspect > 1 && userAspect < 1)) { userAspect = (float)height / (float)width; } if (realAspect < userAspect) { maxHeight = MathUtils.Round(maxWidth / userAspect); } else { maxWidth = MathUtils.Round(maxHeight * userAspect); } LSystem.scaleWidth = ((float)maxWidth) / width; LSystem.scaleHeight = ((float)maxHeight) / height; } else { LSystem.scaleWidth = 1; LSystem.scaleHeight = 1; } LSystem.screenRect = new RectBox(0, 0, width, height); graphics.PreferredBackBufferFormat = displayMode.Format; graphics.PreferredBackBufferWidth = maxWidth; graphics.PreferredBackBufferHeight = maxHeight; if (landscape) { graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight; } else { graphics.SupportedOrientations = DisplayOrientation.Portrait; } //画面渲染与显示器同步 graphics.SynchronizeWithVerticalRetrace = true; graphics.PreferMultiSampling = true; #if WINDOWS graphics.IsFullScreen = false; IsMouseVisible = true; #elif XBOX || WINDOWS_PHONE //全屏 graphics.IsFullScreen = true; #endif graphics.ApplyChanges(); base.IsFixedTimeStep = false; isFPS = false; if (maxFrames <= 0) { SetFPS(LSystem.DEFAULT_MAX_FPS); } SetSleepTime(1); LSystem.screenActivity = this; LSystem.screenProcess = (process = new LProcess(this, width, height)); StringBuilder sbr = new StringBuilder(); sbr.Append("Mode:").Append(mode); log.I(sbr.ToString()); sbr.Clear(); sbr.Append("Width:").Append(width).Append(",Height:" + height); log.I(sbr.ToString()); sbr.Clear(); sbr.Append("MaxWidth:").Append(maxWidth) .Append(",MaxHeight:" + maxHeight); log.I(sbr.ToString()); sbr.Clear(); sbr.Append("Scale:").Append(IsScale()); log.I(sbr.ToString()); }
public override void Draw(GameTime time, Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) { //Utilities.GraphicsUtils.DrawBall(Position, Radius, _playerColor, 255); GraphicsUtils.DrawBallTex(ContentRepository.Repository["shipbrick"], Position, Radius, this.Rotation, 255); }
public void TestFontConversion2() { var points = GraphicsUtils.PixelsToPoints(null, 13.33333); Assert.AreEqual(10, points, 0.001); }
public void TestFontConversion1() { var pixels = GraphicsUtils.PointsToPixel(null, 10); Assert.AreEqual(13.333, pixels, 0.001); }
public static LTexture GetRMXPloadBuoyage(LPixmap rmxpImage, int width, int height) { if (lazyImages == null) { lazyImages = new Dictionary <string, LTexture>(10); } string keyName = ("buoyage" + width + "|" + height); LTexture lazy = (LTexture)CollectionUtils.Get(lazyImages, keyName); if (lazy == null) { LPixmap lazyImage; LPixmap image, left, right, center, up, down = null; int objWidth = 32; int objHeight = 32; int x1 = 128; int x2 = 160; int y1 = 64; int y2 = 96; int k = 1; try { image = GraphicsUtils.DrawClipImage(rmxpImage, objWidth, objHeight, x1, y1, x2, y2); lazyImage = new LPixmap(width, height, true); left = GraphicsUtils.DrawClipImage(image, k, height, 0, 0, k, objHeight); right = GraphicsUtils.DrawClipImage(image, k, height, objWidth - k, 0, objWidth, objHeight); center = GraphicsUtils.DrawClipImage(image, width, height, k, k, objWidth - k, objHeight - k); up = GraphicsUtils.DrawClipImage(image, width, k, 0, 0, objWidth, k); down = GraphicsUtils.DrawClipImage(image, width, k, 0, objHeight - k, objWidth, objHeight); lazyImage.DrawPixmap(center, 0, 0); lazyImage.DrawPixmap(left, 0, 0); lazyImage.DrawPixmap(right, width - k, 0); lazyImage.DrawPixmap(up, 0, 0); lazyImage.DrawPixmap(down, 0, height - k); lazy = lazyImage.Texture; if (lazyImage != null) { lazyImage.Dispose(); lazyImage = null; } lazyImages.Add(keyName, lazy); } catch { return(null); } finally { left = null; right = null; center = null; up = null; down = null; image = null; } } return(lazy); }
private static LTexture GetRMXPDialog(LPixmap rmxpImage, int width, int height, int size, int offset) { if (lazyImages == null) { lazyImages = new Dictionary <string, LTexture>(10); } string keyName = "dialog" + width + "|" + height; LTexture lazy = (LTexture)CollectionUtils.Get(lazyImages, keyName); if (lazy == null) { try { int objWidth = 64; int objHeight = 64; int x1 = 128; int x2 = 192; int y1 = 0; int y2 = 64; int center_size = objHeight - size * 2; LPixmap lazyImage = null; LPixmap image = null; LPixmap messageImage = null; image = GraphicsUtils.DrawClipImage(rmxpImage, objWidth, objHeight, x1, y1, x2, y2); LPixmap centerTop = GraphicsUtils.DrawClipImage(image, center_size, size, size, 0); LPixmap centerDown = GraphicsUtils.DrawClipImage(image, center_size, size, size, objHeight - size); LPixmap leftTop = GraphicsUtils.DrawClipImage(image, size, size, 0, 0); LPixmap leftCenter = GraphicsUtils.DrawClipImage(image, size, center_size, 0, size); LPixmap leftDown = GraphicsUtils.DrawClipImage(image, size, size, 0, objHeight - size); LPixmap rightTop = GraphicsUtils.DrawClipImage(image, size, size, objWidth - size, 0); LPixmap rightCenter = GraphicsUtils.DrawClipImage(image, size, center_size, objWidth - size, size); LPixmap rightDown = GraphicsUtils.DrawClipImage(image, size, size, objWidth - size, objHeight - size); lazyImage = centerTop; lazyImage = new LPixmap(width, height, true); messageImage = GraphicsUtils.DrawClipImage(rmxpImage, 128, 128, 0, 0, 128, 128); messageImage = GraphicsUtils.GetResize(messageImage, width - offset + 1, height - offset + 1); messageImage.UpdateAlpha(125); lazyImage.DrawPixmap(messageImage, (lazyImage.Width - messageImage.Width) / 2, (lazyImage.Height - messageImage .Height) / 2); LPixmap tmp = GraphicsUtils.GetResize(centerTop, width - (size * 2), size); lazyImage.DrawPixmap(tmp, size, 0); if (tmp != null) { tmp.Dispose(); tmp = null; } tmp = GraphicsUtils.GetResize(centerDown, width - (size * 2), size); lazyImage.DrawPixmap(tmp, size, height - size); if (tmp != null) { tmp.Dispose(); tmp = null; } lazyImage.DrawPixmap(leftTop, 0, 0); tmp = GraphicsUtils.GetResize(leftCenter, leftCenter.GetWidth(), width - (size * 2)); lazyImage.DrawPixmap(tmp, 0, size); if (tmp != null) { tmp.Dispose(); tmp = null; } lazyImage.DrawPixmap(leftDown, 0, height - size); int right = width - size; lazyImage.DrawPixmap(rightTop, right, 0); tmp = GraphicsUtils.GetResize(rightCenter, leftCenter .Width, width - (size * 2)); lazyImage.DrawPixmap(tmp, right, size); if (tmp != null) { tmp.Dispose(); tmp = null; } lazyImage.DrawPixmap(rightDown, right, height - size); lazy = lazyImage.Texture; lazy.isExt = true; lazyImages.Add(keyName, lazy); image.Dispose(); messageImage.Dispose(); centerTop.Dispose(); centerDown.Dispose(); leftTop.Dispose(); leftCenter.Dispose(); leftDown.Dispose(); rightTop.Dispose(); rightCenter.Dispose(); rightDown.Dispose(); image = null; messageImage = null; centerTop = null; centerDown = null; leftTop = null; leftCenter = null; leftDown = null; rightTop = null; rightCenter = null; rightDown = null; } catch { } } return(lazy); }
private void AddMultimediaFromFile(string filename) { if (IsReadOnly) { return; } if (string.IsNullOrWhiteSpace(filename)) { return; } FileInfo finfo = new FileInfo(filename); if (finfo.Exists) { MultimediaLink model = null; MultimediaLinkViewModel viewModel = null; Multimedia duplicate = null; var action = CheckDuplicate(finfo, out duplicate); switch (action) { case MultimediaDuplicateAction.Cancel: // Do nothing break; case MultimediaDuplicateAction.NoDuplicate: case MultimediaDuplicateAction.InsertDuplicate: // Insert new multimedia and new link model = new MultimediaLink(); model.MultimediaID = NextNewId(); model.MultimediaLinkID = model.MultimediaID; if (finfo.Name.Contains(".")) { model.Name = finfo.Name.Substring(0, finfo.Name.LastIndexOf(".")); model.Extension = finfo.Extension.Substring(1); } else { model.Name = finfo.Name; } model.SizeInBytes = (int)finfo.Length; viewModel = new MultimediaLinkViewModel(model); viewModel.Thumbnail = GraphicsUtils.GenerateThumbnail(filename, THUMB_SIZE); _tempFileManager.CopyToTempFile(viewModel.MultimediaID, filename); _model.Add(viewModel); RegisterPendingChange(new InsertMultimediaCommand(model, _tempFileManager.GetContentFileName(viewModel.MultimediaID, finfo.Extension.Substring(1)))); RegisterPendingChange(new InsertMultimediaLinkCommand(model, CategoryType, Owner)); break; case MultimediaDuplicateAction.UseExisting: // Link to existing multimedia model = new MultimediaLink(); model.MultimediaID = duplicate.MultimediaID; model.MultimediaLinkID = NewLinkID(); model.Name = duplicate.Name; model.Extension = duplicate.FileExtension; viewModel = new MultimediaLinkViewModel(model); GenerateThumbnail(viewModel, THUMB_SIZE); _model.Add(viewModel); RegisterPendingChange(new InsertMultimediaLinkCommand(model, CategoryType, Owner)); break; case MultimediaDuplicateAction.ReplaceExisting: // register an update for the multimedia, // and insert a new link // Link to existing multimedia model = new MultimediaLink(); model.MultimediaID = duplicate.MultimediaID; model.MultimediaLinkID = NewLinkID(); model.Name = duplicate.Name; model.Extension = duplicate.FileExtension; viewModel = new MultimediaLinkViewModel(model); GenerateThumbnail(viewModel, THUMB_SIZE); _model.Add(viewModel); _tempFileManager.CopyToTempFile(viewModel.MultimediaID, filename); RegisterPendingChange(new UpdateMultimediaBytesCommand(model, filename)); RegisterPendingChange(new InsertMultimediaLinkCommand(model, CategoryType, Owner)); break; } if (viewModel != null) { viewModel.IsSelected = true; thumbList.SelectedItem = viewModel; } } }
protected override Texture LoadStaging(Stream stream) { stream.Seek(0, SeekOrigin.Begin); using var context = new FormatContext(stream); AVFrame *frame = ffmpeg.av_frame_alloc(); int streamId = ffmpeg.av_find_best_stream( context.Inner, AVMediaType.AVMEDIA_TYPE_VIDEO, -1, -1, null, 0 ); AVCodecContext *codecCtx = context.OpenStream(streamId); CheckResult(ffmpeg.av_read_frame(context.Inner, context.RecvPacket)); CheckResult(ffmpeg.avcodec_send_packet(codecCtx, context.RecvPacket)); CheckResult(ffmpeg.avcodec_receive_frame(codecCtx, frame)); (uint width, uint height) = ((uint)frame->width, (uint)frame->height); Texture stagingTexture = _rf.CreateTexture(TextureDescription.Texture2D( width, height, mipLevels: 1, arrayLayers: 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Staging )); MappedResource map = _gd.Map(stagingTexture, MapMode.Write); if (frame->format == (int)AVPixelFormat.AV_PIX_FMT_RGBA) { GraphicsUtils.CopyTextureRegion( src: frame->data[0], 0, 0, 0, srcRowPitch: (uint)frame->linesize[0], srcDepthPitch: (uint)frame->linesize[0] * height, dst: map.Data.ToPointer(), 0, 0, 0, dstRowPitch: map.RowPitch, dstDepthPitch: map.DepthPitch, width, height, depth: 1, bytesPerPixel: 4 ); } else { SwsContext *swsContext = ffmpeg.sws_getContext( frame->width, frame->height, (AVPixelFormat)frame->format, frame->width, frame->height, AVPixelFormat.AV_PIX_FMT_RGBA, flags: 0, null, null, null ); Span <IntPtr> srcPlanes = stackalloc IntPtr[8]; frame->data.CopyPointers(srcPlanes); Span <int> srcLinesizes = stackalloc int[8]; frame->linesize.CopyTo(srcLinesizes); Span <IntPtr> dstPlanes = stackalloc IntPtr[4]; dstPlanes[0] = map.Data; Span <int> dstLinesizes = stackalloc int[4]; dstLinesizes[0] = (int)map.RowPitch; fixed(IntPtr *pSrcPlanes = &srcPlanes[0]) fixed(IntPtr * pDstPlanes = &dstPlanes[0]) fixed(int *pSrcLinesizes = &srcLinesizes[0]) fixed(int *pDstLinesizes = &dstLinesizes[0]) { int _ = ffmpeg.sws_scale(swsContext, (byte **)pSrcPlanes, pSrcLinesizes, srcSliceY: 0, frame->height, (byte **)pDstPlanes, pDstLinesizes ); } ffmpeg.sws_freeContext(swsContext); } _gd.Unmap(stagingTexture); ffmpeg.av_frame_free(&frame); ffmpeg.avcodec_free_context(&codecCtx); return(stagingTexture); }
private static ImageSource CreateThumbnailImage(Bitmap image, int thumbnailWidth, int thumbnailHeight) { var bmp = GraphicsUtils.BitmapToBitmapImage(image); return(GraphicsUtils.Downsize(bmp, thumbnailWidth, thumbnailHeight)); }
public void Release() { GraphicsUtils.Destroy(mesh); mesh = null; }
public void LoadFile(string fileName) { if (File.Exists(fileName)) { Point spriteGroupPosition = Point.Empty; var xml = new XmlDocument(); xml.Load(fileName); Filename = Path.GetFileName(fileName); foreach (XmlNode entityNode in xml.ChildNodes[0].ChildNodes) { if (entityNode.Name.ToLower().Equals("object")) { var entity = new Entity() { ID = int.Parse(entityNode.Attributes["id"].Value), Filename = entityNode.Attributes["texture"].Value }; var texture = new Bitmap(Path.Combine(ResourceUtils.GetResourcePath(ResourceUtils.AssetsType.Gfx), entityNode.Attributes["texture"].Value)); foreach (XmlNode spriteNode in entityNode.ChildNodes) { if (spriteNode.Name.ToLower().Equals("sprite")) { if (ValidateSpriteGroup(spriteNode.Attributes["name"].Value)) { if (spriteNode.Attributes["name"].Value.Split('_')[1] == "a") { spriteGroupPosition = new Point(spriteNode.ChildNodes[0].Attributes["x"].ToValue <int>(), spriteNode.ChildNodes[0].Attributes["y"].ToValue <int>()); } } else { spriteGroupPosition = new Point(spriteNode.ChildNodes[0].Attributes["x"].ToValue <int>(), spriteNode.ChildNodes[0].Attributes["y"].ToValue <int>()); } var sprite = new Sprite() { Name = spriteNode.Attributes["name"].Value, X = spriteGroupPosition.X, Y = spriteGroupPosition.Y, }; sprite.Texture = GraphicsUtils.Cut(spriteNode.ChildNodes[0].Attributes["x"].ToValue <int>(), spriteNode.ChildNodes[0].Attributes["y"].ToValue <int>(), spriteNode.Attributes["width"].ToValue <int>(), spriteNode.Attributes["height"].ToValue <int>(), texture); entity.Sprites.Add(sprite); } } var drawNode = entityNode.ChildNodes.FindNode("draw"); foreach (XmlNode variationNode in drawNode.ChildNodes) { var template = new Template() { Name = variationNode.Attributes["name"].Value, }; foreach (XmlNode layerNode in variationNode.ChildNodes) { var layer = new Layer() { Name = layerNode.Attributes["name"].Value, Offset = new Point(layerNode.Attributes["xoffset"].ToValue <int>(), layerNode.Attributes["yoffset"].ToValue <int>()), }; if (layerNode.Name.ToLower().Equals("background")) { layer.Level = Layer.LevelType.Background; } else if (layerNode.Name.ToLower().Equals("foreground")) { layer.Level = Layer.LevelType.Foreground; } template.Layers.Add(layer); } entity.Templates.Add(template); } Entities.Add(entity); } } } }
public override void OnDisable() { GraphicsUtils.Destroy(m_SpectrumLut); m_SpectrumLut = null; }
public void Initialization(bool l, bool f, LMode m) { log.I("GPU surface"); this.landscape = l; this.fullScreen = f; this.mode = m; if (landscape == false) { if (LSystem.MAX_SCREEN_HEIGHT > LSystem.MAX_SCREEN_WIDTH) { int tmp_height = LSystem.MAX_SCREEN_HEIGHT; LSystem.MAX_SCREEN_HEIGHT = LSystem.MAX_SCREEN_WIDTH; LSystem.MAX_SCREEN_WIDTH = tmp_height; } } this.CheckDisplayMode(); RectBox d = GetScreenDimension(); LSystem.SCREEN_LANDSCAPE = landscape; this.maxWidth = (int)d.GetWidth(); this.maxHeight = (int)d.GetHeight(); if (landscape && (d.GetWidth() > d.GetHeight())) { maxWidth = (int)d.GetWidth(); maxHeight = (int)d.GetHeight(); } else if (landscape && (d.GetWidth() < d.GetHeight())) { maxHeight = (int)d.GetWidth(); maxWidth = (int)d.GetHeight(); } else if (!landscape && (d.GetWidth() < d.GetHeight())) { maxWidth = (int)d.GetWidth(); maxHeight = (int)d.GetHeight(); } else if (!landscape && (d.GetWidth() > d.GetHeight())) { maxHeight = (int)d.GetWidth(); maxWidth = (int)d.GetHeight(); } if (mode != LMode.Max) { if (landscape) { this.width = LSystem.MAX_SCREEN_WIDTH; this.height = LSystem.MAX_SCREEN_HEIGHT; } else { this.width = LSystem.MAX_SCREEN_HEIGHT; this.height = LSystem.MAX_SCREEN_WIDTH; } } else { if (landscape) { this.width = maxWidth >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH : maxWidth; this.height = maxHeight >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT : maxHeight; } else { this.width = maxWidth >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT : maxWidth; this.height = maxHeight >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH : maxHeight; } } if (mode == LMode.Fill) { LSystem.scaleWidth = ((float)maxWidth) / width; LSystem.scaleHeight = ((float)maxHeight) / height; } else if (mode == LMode.FitFill) { RectBox res = GraphicsUtils.FitLimitSize(width, height, maxWidth, maxHeight); maxWidth = res.width; maxHeight = res.height; LSystem.scaleWidth = ((float)maxWidth) / width; LSystem.scaleHeight = ((float)maxHeight) / height; } else if (mode == LMode.Ratio) { maxWidth = MeasureSpec.GetSize(maxWidth); maxHeight = MeasureSpec.GetSize(maxHeight); float userAspect = (float)width / (float)height; float realAspect = (float)maxWidth / (float)maxHeight; if (realAspect < userAspect) { maxHeight = MathUtils.Round(maxWidth / userAspect); } else { maxWidth = MathUtils.Round(maxHeight * userAspect); } LSystem.scaleWidth = ((float)maxWidth) / width; LSystem.scaleHeight = ((float)maxHeight) / height; } else if (mode == LMode.MaxRatio) { maxWidth = MeasureSpec.GetSize(maxWidth); maxHeight = MeasureSpec.GetSize(maxHeight); float userAspect = (float)width / (float)height; float realAspect = (float)maxWidth / (float)maxHeight; if ((realAspect < 1 && userAspect > 1) || (realAspect > 1 && userAspect < 1)) { userAspect = (float)height / (float)width; } if (realAspect < userAspect) { maxHeight = MathUtils.Round(maxWidth / userAspect); } else { maxWidth = MathUtils.Round(maxHeight * userAspect); } LSystem.scaleWidth = ((float)maxWidth) / width; LSystem.scaleHeight = ((float)maxHeight) / height; } else { LSystem.scaleWidth = 1; LSystem.scaleHeight = 1; } if (landscape) { GamePage.Orientation = Microsoft.Phone.Controls.PageOrientation.Landscape | Microsoft.Phone.Controls.PageOrientation.LandscapeLeft | Microsoft.Phone.Controls.PageOrientation.LandscapeRight; GamePage.SupportedOrientations = Microsoft.Phone.Controls.SupportedPageOrientation.Landscape; } else { GamePage.Orientation = Microsoft.Phone.Controls.PageOrientation.Portrait | Microsoft.Phone.Controls.PageOrientation.PortraitDown | Microsoft.Phone.Controls.PageOrientation.PortraitUp; GamePage.SupportedOrientations = Microsoft.Phone.Controls.SupportedPageOrientation.Portrait; } LSystem.screenRect = new RectBox(0, 0, width, height); graphics.PreferredBackBufferFormat = displayMode.Format; graphics.PreferredBackBufferWidth = maxWidth; graphics.PreferredBackBufferHeight = maxHeight; if (GamePage != null) { UIElementRenderer = new UIElementRenderer(GamePage, maxWidth, maxHeight); } //画面渲染与显示器同步 graphics.SynchronizeWithVerticalRetrace = true; graphics.ApplyChanges(); isFPS = false; if (maxFrames <= 0) { SetFPS(LSystem.DEFAULT_MAX_FPS); } LSystem.screenActivity = this; LSystem.screenProcess = (process = new LProcess(this, width, height)); StringBuilder sbr = new StringBuilder(); sbr.Append("Mode:").Append(mode); log.I(sbr.ToString()); sbr.Clear(); sbr.Append("Width:").Append(width).Append(",Height:" + height); log.I(sbr.ToString()); sbr.Clear(); sbr.Append("MaxWidth:").Append(maxWidth) .Append(",MaxHeight:" + maxHeight); log.I(sbr.ToString()); sbr.Clear(); sbr.Append("Scale:").Append(IsScale()); log.I(sbr.ToString()); if (GamePage != null) { GamePage.Background = null; GamePage.Foreground = null; GamePage.Style = null; GamePage.AllowDrop = false; GamePage.Visibility = System.Windows.Visibility.Collapsed; /*System.Windows.Interop.Settings settings = new System.Windows.Interop.Settings(); * settings.EnableFrameRateCounter = true; * settings.EnableCacheVisualization = true; * settings.EnableRedrawRegions = true; * settings.MaxFrameRate = maxFrames; * System.Windows.Media.BitmapCache cache = new System.Windows.Media.BitmapCache(); * cache.RenderAtScale = 1; * GamePage.CacheMode = cache;*/ GamePage.Opacity = 1f; } }
internal void Draw(FivePointNine.Windows.Graphics.Graphics2 g, int width, int height, float xog, float yog, float xs, float ys, bool showHighlighted) { //minDispCached = float.PositiveInfinity; //maxDispCached = float.NegativeInfinity; if (!Enabled) { return; } try { minDispValueOvershoot = false; maxDispValueOvershoot = false; List <PointF> ps = new List <PointF>(); if (Values.Count > 2) { minDispYCached = Values[0]; maxDispYCached = Values[0]; float sumOfValues = 0; float sumOfTimes = 0; float summedValues = 0; int lastAddedX = (int)Math.Round(TimeStamps[0] * xs) - 1; for (int i = 0; i < Values.Count; i++) { var xToAdd = (int)Math.Round(TimeStamps[i] * xs); summedValues++; sumOfValues += Values[i]; sumOfTimes += TimeStamps[i]; if (xToAdd > lastAddedX) { float t = sumOfTimes / summedValues; float v = sumOfValues / summedValues; if (double.IsPositiveInfinity(v)) { continue; } float vG = height - (v * ys + yog); float tG = t * xs + xog; if (tG >= 0 && tG <= width) { if (vG < 0) { maxDispValueOvershoot = true; } if (vG > height) { minDispValueOvershoot = true; } if (v < minDispYCached) { minDispYCached = v; } if (v > maxDispYCached) { maxDispYCached = v; } ps.Add(new PointF(tG, vG)); } summedValues = 0; sumOfTimes = 0; sumOfValues = 0; lastAddedX = xToAdd; } } } Color c = Color.FromArgb((int)(LineOpacity * 255), LineColor); Pen PlotP = new Pen(c, LineThickness); if (ps.Count > 1) { if (showHighlighted) { g.DrawLines(new Pen(GraphicsUtils.GetContrast(PlotP.Color), PlotP.Width + 3), ps.ToArray()); g.DrawLines(new Pen(Color.FromArgb(255, PlotP.Color), LineThickness), ps.ToArray()); } else { g.DrawLines(PlotP, ps.ToArray()); } } if (LastPointHighlight && ps.Count > 0) { var p = ps[ps.Count - 1]; g.DrawRectangle(Pen, (int)(p.X - LineThickness * 2), (int)(p.Y - LineThickness * 2), LineThickness * 4, LineThickness * 4); } } catch (Exception ex) { } }
public override void Draw(GameTime time, SpriteBatch spriteBatch) { GraphicsUtils.DrawBall(Position, Radius, DebugMode ? Color:Color.Gray, 255); }
public PShadowEffect(LPixmap img, LPixmap back, int x, int y, int w, int h) { if (deasilTrans == null || widdershinTrans == null) { deasilTrans = new Color[max_pixel]; for (int i = 0; i < max_pixel; i++) { deasilTrans[i] = new Color(i, i, i); } int count = 0; widdershinTrans = new Color[max_pixel]; for (int i = 0; i < max_pixel; i++) { widdershinTrans[count++] = deasilTrans[i]; } } this.SetLocation(x, y); this.width = w; this.height = h; this.visible = true; LPixmap temp = null; if (back == null) { this.scaleWidth = width / 2; this.scaleHeight = height / 2; temp = GraphicsUtils.GetResize(img, scaleWidth, scaleHeight); this.image = new LPixmap(scaleWidth, scaleHeight, true); this.finalDrawPixels = temp.GetData(); this.nowDrawPixels = (Color[])CollectionUtils.CopyOf(finalDrawPixels); if (temp != null) { temp.Dispose(); temp = null; } } else { this.scaleWidth = width / 2; this.scaleHeight = height / 2; temp = GraphicsUtils.GetResize(img, scaleWidth, scaleHeight); this.image = new LPixmap(scaleWidth, scaleHeight, true); if (back.GetWidth() == scaleWidth && back.GetHeight() == scaleHeight) { this.finalBackgroundPixels = back.GetData(); this.backgroundPixels = (Color[])CollectionUtils .CopyOf(finalBackgroundPixels); } else { LPixmap tmp = GraphicsUtils.GetResize(back, scaleWidth, scaleHeight); this.finalBackgroundPixels = tmp.GetData(); if (tmp != null) { tmp.Dispose(); tmp = null; } this.backgroundPixels = (Color[])CollectionUtils .CopyOf(finalBackgroundPixels); } this.finalDrawPixels = temp.GetData(); this.nowDrawPixels = (Color[])CollectionUtils.CopyOf(finalDrawPixels); } this.SetBlackToWhite(flag); if (temp != null) { temp.Dispose(); temp = null; } if (img != null) { img.Dispose(); img = null; } if (back != null) { back.Dispose(); back = null; } }
/// <summary> /// 创建消息窗图像,同时输出内容区,用于外部定位 /// </summary> private static Bitmap CreateTipImage(string text, TipStyle style, out Rectangle contentBounds) { var size = Size.Empty; var iconBounds = Rectangle.Empty; var textBounds = Rectangle.Empty; if (style.Icon != null) { size = style.Icon.Size; iconBounds.Size = size; textBounds.X = size.Width; } if (text.Length != 0) { if (style.Icon != null) { size.Width += style.IconSpacing; textBounds.X += style.IconSpacing; } textBounds.Size = Size.Truncate(GraphicsUtils.MeasureString(text, style.TextFont ?? DefaultFont, 0, DefStringFormat)); size.Width += textBounds.Width; if (size.Height < textBounds.Height) { size.Height = textBounds.Height; } else if (size.Height > textBounds.Height)//若文字没有图标高,令文字与图标垂直居中,否则与图标平齐 { textBounds.Y += (size.Height - textBounds.Height) / 2; } textBounds.Offset(style.TextOffset); } size += style.Padding.Size; iconBounds.Offset(style.Padding.Left, style.Padding.Top); textBounds.Offset(style.Padding.Left, style.Padding.Top); contentBounds = new Rectangle(Point.Empty, size); var fullBounds = GraphicsUtils.GetBounds(contentBounds, style.Border, style.ShadowRadius, style.ShadowOffset.X, style.ShadowOffset.Y); contentBounds.Offset(-fullBounds.X, -fullBounds.Y); iconBounds.Offset(-fullBounds.X, -fullBounds.Y); textBounds.Offset(-fullBounds.X, -fullBounds.Y); var bmp = new Bitmap(fullBounds.Width, fullBounds.Height); Graphics g = null; Brush backBrush = null; Brush textBrush = null; try { g = Graphics.FromImage(bmp); g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; backBrush = (style.BackBrush ?? (r => new SolidBrush(style.BackColor)))(contentBounds); GraphicsUtils.DrawRectangle(g, contentBounds, backBrush, style.Border, style.CornerRadius, style.ShadowColor, style.ShadowRadius, style.ShadowOffset.X, style.ShadowOffset.Y); if (style.Icon != null) { //DEBUG: g.DrawRectangle(new Border(Color.Red) { Width = 1, Direction = Direction.Inner }.Pen, iconBounds); g.DrawImageUnscaled(style.Icon, iconBounds.Location); } if (text.Length != 0) { textBrush = new SolidBrush(style.TextColor); //DEBUG: g.DrawRectangle(new Border(Color.Red){ Width=1, Direction= Direction.Inner}.Pen, textBounds); g.DrawString(text, style.TextFont ?? DefaultFont, textBrush, textBounds.Location, DefStringFormat); } g.Flush(FlushIntention.Sync); return(bmp); } finally { if (g != null) { g.Dispose(); } if (backBrush != null) { backBrush.Dispose(); } if (textBrush != null) { textBrush.Dispose(); } } }
public override void Draw(GameTime time, SpriteBatch spriteBatch) { GraphicsUtils.DrawBall(Position, Radius, Color.Teal, 255); }
private static Bitmap texture1() { int h = 0x40; int bmpW = h << 0x01; int bmpH = h << 0x02; Bitmap bmp = new Bitmap(bmpW, bmpH); Graphics g = Graphics.FromImage(bmp); g.CompositingQuality = CompositingQuality.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; float h_2 = 0.5f * h; float rightEnd = h * 2.0f; float margin = h / 48.0f; float margin2 = margin * 2.0f; float margin3 = margin * 3.0f; float r = h / 36.0f; float r2 = 2.0f * r; float s = 0.25f * h; float s2 = s * 2.0f; float s3 = s * 3.0f; float t = 0.5f * s; float t2 = t * 2.0f; float t3 = t * 3.0f; float temp = (margin + s + t - h_2); float R = temp - 4.0f * temp * (float)Math.Sqrt(0.5f); float xP = (2.0f - (float)Math.Sqrt(2.0f)) * temp + r + h_2; float R2 = 2.0f * R; int royalN = 7; float gamma = 180.0f / royalN; float penW = h / 1024.0f; for (int l = 0x00; l < 0x03; l++) { using (GraphicsPath gpNocturne = new GraphicsPath()) { gpNocturne.AddArc(margin, margin, h - margin2, h - margin2, 90.0f, 180.0f); gpNocturne.AddLine(h_2, margin, rightEnd, margin); gpNocturne.AddLine(rightEnd, margin, rightEnd, h - margin); gpNocturne.AddLine(rightEnd, h - margin, h_2, h - margin); gpNocturne.CloseFigure(); if (l == 0x01) { g.FillPath(EgyptInformation.Brushes.EgyptLure, gpNocturne); } else { g.FillPath(EgyptInformation.Brushes.EgyptNocturne, gpNocturne); } } using (GraphicsPath gpGold = new GraphicsPath()) { for (int i = 0x00; i < royalN;) { using (GraphicsPath gpRoyal = new GraphicsPath()) { gpRoyal.AddArc(margin + r, margin + r, h - margin2 - r2, h - margin2 - r2, 90 + gamma * i++, gamma); gpRoyal.AddArc(margin + s, margin + s, h - margin2 - s2, h - margin2 - s2, 90 + gamma * i, -gamma); gpRoyal.CloseFigure(); g.FillPath((((i & 0x01) == 0x01) ? EgyptInformation.Brushes.EgyptPaintBlue : EgyptInformation.Brushes.EgyptPaintRed), gpRoyal); } } gpGold.AddArc(margin, margin, h - margin2, h - margin2, 90.0f, 180.0f); gpGold.AddLine(h_2, margin, rightEnd, margin); gpGold.AddLine(rightEnd, margin, rightEnd, margin + r); gpGold.AddLine(rightEnd, margin + r, h_2 + r, margin + r); gpGold.AddLine(h_2 + r, margin + r, h_2 + r, s + t + margin); //flower gpGold.AddArc(r + margin + s + t, margin3 + s3 + t3 - h, h - margin2 - s2 - t2, h - margin2 - s2 - t2, 90.0f, -45.0f); gpGold.AddArc(xP - R, h_2 - R, R2, R2, -45.0f, 90.0f); gpGold.AddArc(r + margin + s + t, h - margin - s - t, h - margin2 - s2 - t2, h - margin2 - s2 - t2, -45.0f, -45.0f); gpGold.AddLine(h_2 + r, h - s - t - margin, h_2 + r, h - margin - r); gpGold.AddLine(h_2 + r, h - margin - r, rightEnd, h - margin - r); gpGold.AddLine(rightEnd, h - margin - r, rightEnd, h - margin); gpGold.AddLine(rightEnd, h - margin, h_2, h - margin); gpGold.CloseFigure(); gpGold.AddArc(margin + r, margin + r, h - margin2 - r2, h - margin2 - r2, 90.0f, 180.0f); gpGold.AddLine(h_2, margin + r, h_2, margin + s); gpGold.AddArc(margin + s, margin + s, h - margin2 - s2, h - margin2 - s2, 270.0f, -180.0f); gpGold.AddLine(h_2, h - margin - s, h_2, h - margin - r); gpGold.CloseFigure(); gpGold.AddArc(margin + r + s, margin + r + s, h - margin2 - r2 - s2, h - margin2 - r2 - s2, 90.0f, 180.0f); gpGold.AddLine(h_2, margin + r + s, h_2, margin + s + t); gpGold.AddArc(margin + s + t, margin + s + t, h - margin2 - s2 - t2, h - margin2 - s2 - t2, 270.0f, -180.0f); gpGold.AddLine(h_2, h - margin - s - t, h_2, h - margin - r - s); gpGold.CloseFigure(); g.FillPath(EgyptInformation.Brushes.EgyptGold, gpGold); GraphicsUtils.DrawGlass(g, gpGold); //g.DrawPath(new Pen(Color.Black,penW),gpGold); using (GraphicsPath gpTurquoise = new GraphicsPath()) { gpTurquoise.AddEllipse(margin + r + s + t, margin + r + s + t, h - margin2 - r2 - s2 - t2, h - margin2 - r2 - s2 - t2); gpTurquoise.CloseFigure(); g.FillPath(EgyptInformation.Brushes.EgyptPaintTurquoise, gpTurquoise); Region oldRegion = g.Clip; g.Clip = new Region(gpTurquoise); if (l == 0x01) { using (GraphicsPath gpGlow = new GraphicsPath()) { gpGlow.AddEllipse(margin2 + r2 + s2 + t2 - h_2, margin + r + s + t, 2.0f * (h - margin2 - r2 - s2 - t2), 2.0f * (h - margin2 - r2 - s2 - t2)); gpGlow.CloseFigure(); PathGradientBrush pgbGlow = new PathGradientBrush(gpGlow); pgbGlow.CenterColor = EgyptInformation.Colors.EgyptPaintRed; pgbGlow.SurroundColors = new Color[] { Color.Transparent }; g.FillPath(pgbGlow, gpGlow); } } LinearGradientBrush lgbGlass = new LinearGradientBrush(new PointF(0.0f, margin + r + s + t), new PointF(0.0f, h_2 - margin - r - s - t), Color.FromArgb(0x50, 0xff, 0xff, 0xff), Color.FromArgb(0x80, 0xff, 0xff, 0xff)); g.FillEllipse(lgbGlass, margin + r + s + t, margin2 + r2 + s2 + t2 - h_2, h - margin2 - r2 - s2 - t2, h - margin2 - r2 - s2 - t2); g.Clip = oldRegion; g.DrawPath(new Pen(Color.Black, penW), gpTurquoise); } } g.TranslateTransform(0.0f, h); } GraphicsUtils.DrawSepia(bmp, 0x00, 0x00, bmpW, bmpH >> 0x02, 0x00, 0x03 * bmpH / 0x04); bmp.Save("ti.png"); return(bmp); }
private Bitmap GetErrorImage(String errorMessage) { return(GraphicsUtils.GetTextImage(errorMessage, new Font("Arial", 12), Color.White, Color.Red)); }
private static Bitmap texture0() { int w = 0xc0; int wa = w / 0x03; int h = 0x80; float m = 2.0f; float t = 3.0f; float mt = m + t; float t_2 = 0.5f * t; float R = w / 3 - m; float r = R - t; float s = r - t; float R2 = 2.0f * R; float r2 = 2.0f * r; Bitmap bmp = new Bitmap(0x04 * w / 0x03, 0x02 * h); Graphics g = Graphics.FromImage(bmp); g.CompositingQuality = CompositingQuality.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; using (GraphicsPath gpLure = new GraphicsPath()) { gpLure.AddArc(m, m, R2, R2, 180.0f, 90.0f); gpLure.AddLine(m + R, m, w - m - R, m); gpLure.AddArc(w - m - R2, m, R2, R2, 270.0f, 90.0f); gpLure.AddLine(w - m, m + R, w - m, w - m - R); gpLure.AddArc(w - m - R2, w - m - R2, R2, R2, 0.0f, 90.0f); gpLure.AddLine(w - m - R, w - m, m + R, w - m); gpLure.AddArc(m, w - m - R2, R2, R2, 90.0f, 90.0f); gpLure.AddLine(m, w - m - R, m, m + R); gpLure.CloseFigure(); g.FillPath(EgyptInformation.Brushes.EgyptLure, gpLure); } using (GraphicsPath gpGold = new GraphicsPath()) { gpGold.AddArc(m, m, R2, R2, 180.0f, 90.0f); gpGold.AddLine(m + R, m, w - m - R, m); gpGold.AddArc(w - m - R2, m, R2, R2, 270.0f, 90.0f); gpGold.AddLine(w - m, m + R, w - m, w - m - R); gpGold.AddArc(w - m - R2, w - m - R2, R2, R2, 0.0f, 90.0f); gpGold.AddLine(w - m - R, w - m, m + R, w - m); gpGold.AddArc(m, w - m - R2, R2, R2, 90.0f, 90.0f); gpGold.AddLine(m, w - m - R, m, m + R); gpGold.CloseFigure(); gpGold.AddArc(mt, mt, r2, r2, 180.0f, 90.0f); gpGold.AddLine(m + R, mt, w - m - R, mt); gpGold.AddArc(w - mt - r2, mt, r2, r2, 270.0f, 90.0f); gpGold.AddLine(w - mt, m + R, w - mt, w - m - R); gpGold.AddArc(w - mt - r2, w - mt - r2, r2, r2, 0.0f, 90.0f); gpGold.AddLine(w - m - R, w - mt, m + R, w - mt); gpGold.AddArc(mt, w - mt - r2, r2, r2, 90.0f, 90.0f); gpGold.AddLine(mt, w - m - R, mt, m + R); gpGold.CloseFigure(); g.FillPath(EgyptInformation.Brushes.EgyptGold, gpGold); GraphicsUtils.DrawGlass(g, gpGold); } g.FillEllipse(EgyptInformation.Brushes.EgyptNocturne, m, h + wa + m, R, R); using (GraphicsPath gpTurquoise = new GraphicsPath()) { gpTurquoise.AddEllipse(wa + m + t, h + wa + m + t, s, s); g.FillPath(EgyptInformation.Brushes.EgyptPaintTurquoise, gpTurquoise); GraphicsUtils.DrawGlass(g, gpTurquoise); } g.FillEllipse(EgyptInformation.Brushes.EgyptNocturne, m, h + wa + m, R, R); for (int i = 0x00; i < 0x02; i++) { using (GraphicsPath gpGold = new GraphicsPath()) { gpGold.AddEllipse(wa * i + m, h + m + wa, R, R); gpGold.AddEllipse(wa * i + m + t, h + m + wa + t, s, s); g.FillPath(EgyptInformation.Brushes.EgyptGold, gpGold); GraphicsUtils.DrawGlass(g, gpGold); } } g.FillRectangle(EgyptInformation.Brushes.EgyptPaintBlue, wa * 2.5f - 0.5f * t, h + wa, t, wa); bmp.Save("ti.png"); return(bmp); }
void ComputeHistogram(RenderTexture source) { if (m_Buffer == null) { CreateBuffer(256, 1); } else if (m_Buffer.count != 256) { m_Buffer.Release(); CreateBuffer(256, 1); } if (m_Material == null) { m_Material = new Material(Shader.Find("Hidden/Post FX/Monitors/Histogram Render")) { hideFlags = HideFlags.DontSave }; } var channels = Vector4.zero; switch (m_MonitorSettings.histogramMode) { case HistogramMode.Red: channels.x = 1f; break; case HistogramMode.Green: channels.y = 1f; break; case HistogramMode.Blue: channels.z = 1f; break; case HistogramMode.Luminance: channels.w = 1f; break; default: channels = new Vector4(1f, 1f, 1f, 0f); break; } var cs = m_ComputeShader; int kernel = cs.FindKernel("KHistogramClear"); cs.SetBuffer(kernel, "_Histogram", m_Buffer); cs.Dispatch(kernel, 1, 1, 1); kernel = cs.FindKernel("KHistogramGather"); cs.SetBuffer(kernel, "_Histogram", m_Buffer); cs.SetTexture(kernel, "_Source", source); cs.SetInt("_IsLinear", GraphicsUtils.isLinearColorSpace ? 1 : 0); cs.SetVector("_Res", new Vector4(source.width, source.height, 0f, 0f)); cs.SetVector("_Channels", channels); cs.Dispatch(kernel, Mathf.CeilToInt(source.width / 16f), Mathf.CeilToInt(source.height / 16f), 1); kernel = cs.FindKernel("KHistogramScale"); cs.SetBuffer(kernel, "_Histogram", m_Buffer); cs.Dispatch(kernel, 1, 1, 1); if (m_HistogramTexture == null || m_HistogramTexture.width != source.width || m_HistogramTexture.height != source.height) { GraphicsUtils.Destroy(m_HistogramTexture); m_HistogramTexture = new RenderTexture(source.width, source.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear) { hideFlags = HideFlags.DontSave, wrapMode = TextureWrapMode.Clamp, filterMode = FilterMode.Bilinear }; } m_Material.SetBuffer("_Histogram", m_Buffer); m_Material.SetVector("_Size", new Vector2(m_HistogramTexture.width, m_HistogramTexture.height)); m_Material.SetColor("_ColorR", new Color(1f, 0f, 0f, 1f)); m_Material.SetColor("_ColorG", new Color(0f, 1f, 0f, 1f)); m_Material.SetColor("_ColorB", new Color(0f, 0f, 1f, 1f)); m_Material.SetColor("_ColorL", new Color(1f, 1f, 1f, 1f)); m_Material.SetInt("_Channel", (int)m_MonitorSettings.histogramMode); int pass = 0; if (m_MonitorSettings.histogramMode == HistogramMode.RGBMerged) { pass = 1; } else if (m_MonitorSettings.histogramMode == HistogramMode.RGBSplit) { pass = 2; } Graphics.Blit(null, m_HistogramTexture, m_Material, pass); }
public PointShapeViewModel(MapPointShape shape) { Shape = shape; Icon = GraphicsUtils.SystemDrawingImageToBitmapSource(MapSymbolGenerator.GetSymbol(shape, 10, Colors.Black, true)); }