public void DrawFlat(Render.RenderContext context, Gem.Render.Cameras.OrthographicCamera Camera) { var uiContext = module.GetRenderContext(); uiContext.Camera = Camera; uiContext.BeginScene(null, false); uiRoot.Render(uiContext); }
public void DrawEx(Render.RenderContext context, Matrix worldTransform) { context.Color = Vector3.One; context.Texture = renderTarget; context.World = worldTransform; context.ApplyChanges(); context.Draw(quadModel); }
private void Page_Load(object sender, System.EventArgs e) { if (!AdminAuthorized()) { return; } ResourceManager resourceManager = new ResourceManager(Server, Cache); MapOptions options = MapOptions.SectorGrid | MapOptions.FilledBorders; Stylesheet.Style style = Stylesheet.Style.Poster; ParseOptions(ref options, ref style); double x = -0.5; double y = -0.5; double scale = 2; Size tileSize = new Size(1000, 1000); RectangleF tileRect = new RectangleF(); tileRect.X = (float)(x * tileSize.Width / (scale * Astrometrics.ParsecScaleX)); tileRect.Y = (float)(y * tileSize.Height / (scale * Astrometrics.ParsecScaleY)); tileRect.Width = (float)(tileSize.Width / (scale * Astrometrics.ParsecScaleX)); tileRect.Height = (float)(tileSize.Height / (scale * Astrometrics.ParsecScaleY)); DateTime dt = DateTime.Now; Render.RenderContext ctx = new Render.RenderContext(); ctx.resourceManager = resourceManager; ctx.selector = new RectSelector( SectorMap.FromName(SectorMap.DefaultSetting, resourceManager), resourceManager, tileRect); ctx.tileRect = tileRect; ctx.scale = scale; ctx.options = options; ctx.styles = new Stylesheet(scale, options, style); ctx.tileSize = tileSize; ctx.silly = false; ctx.tiling = true; ctx.styles.microRoutes.visible = true; ctx.styles.macroRoutes.visible = false; ctx.styles.macroBorders.visible = false; ctx.styles.microBorders.visible = true; ctx.styles.capitals.visible = false; ctx.styles.worlds.visible = true; ctx.styles.worldDetails = WorldDetails.Dotmap; ctx.styles.showAllSectorNames = false; ctx.styles.showSomeSectorNames = false; ctx.styles.macroNames.visible = false; ctx.styles.pseudoRandomStars.visible = false; ctx.styles.fillMicroBorders = true; ProduceResponse("Overview", ctx, tileSize); }
private static void RenderToGraphics(Render.RenderContext ctx, int rot, float translateX, float translateY, XGraphics graphics) { graphics.TranslateTransform(translateX, translateY); graphics.RotateTransform(rot * 90); using (Maps.Rendering.RenderUtil.SaveState(graphics)) { if (ctx.clipPath != null) { XMatrix m = ctx.ImageSpaceToWorldSpace; graphics.MultiplyTransform(m); graphics.IntersectClip(ctx.clipPath); m.Invert(); graphics.MultiplyTransform(m); } ctx.graphics = graphics; Maps.Rendering.Render.RenderTile(ctx); } if (ctx.border && ctx.clipPath != null) { using (Maps.Rendering.RenderUtil.SaveState(graphics)) { // Render border in world space XMatrix m = ctx.ImageSpaceToWorldSpace; graphics.MultiplyTransform(m); XPen pen = new XPen(ctx.styles.imageBorderColor, 0.2f); // PdfSharp can't ExcludeClip so we take advantage of the fact that we know // the path starts on the left edge and proceeds clockwise. We extend the // path with a counterclockwise border around it, then use that to exclude // the original path's region for rendering the border. ctx.clipPath.Flatten(); RectangleF bounds = PathUtil.Bounds(ctx.clipPath); bounds.Inflate(2 * (float)pen.Width, 2 * (float)pen.Width); List <byte> types = new List <byte>(ctx.clipPath.Internals.GdiPath.PathTypes); List <PointF> points = new List <PointF>(ctx.clipPath.Internals.GdiPath.PathPoints); PointF key = points[0]; points.Add(new PointF(bounds.Left, key.Y)); types.Add(1); points.Add(new PointF(bounds.Left, bounds.Bottom)); types.Add(1); points.Add(new PointF(bounds.Right, bounds.Bottom)); types.Add(1); points.Add(new PointF(bounds.Right, bounds.Top)); types.Add(1); points.Add(new PointF(bounds.Left, bounds.Top)); types.Add(1); points.Add(new PointF(bounds.Left, key.Y)); types.Add(1); points.Add(new PointF(key.X, key.Y)); types.Add(1); XGraphicsPath path = new XGraphicsPath(points.ToArray(), types.ToArray(), XFillMode.Winding); graphics.IntersectClip(path); graphics.DrawPath(pen, ctx.clipPath); } } }
private void Page_Load(object sender, System.EventArgs e) { ResourceManager resourceManager = new ResourceManager(Server, Cache); MapOptions options = MapOptions.SectorGrid | MapOptions.BordersMajor | MapOptions.NamesMajor | MapOptions.NamesMinor; Stylesheet.Style style = Stylesheet.Style.Poster; ParseOptions(ref options, ref style); double x = GetDoubleOption("x", 0); double y = GetDoubleOption("y", 0); double scale = Util.Clamp(GetDoubleOption("scale", 0), MinScale, MaxScale); int width = Util.Clamp(GetIntOption("w", NormalTileWidth), MinDimension, MaxDimension); int height = Util.Clamp(GetIntOption("h", NormalTileHeight), MinDimension, MaxDimension); Size tileSize = new Size(width, height); RectangleF tileRect = new RectangleF(); tileRect.X = (float)(x * tileSize.Width / (scale * Astrometrics.ParsecScaleX)); tileRect.Y = (float)(y * tileSize.Height / (scale * Astrometrics.ParsecScaleY)); tileRect.Width = (float)(tileSize.Width / (scale * Astrometrics.ParsecScaleX)); tileRect.Height = (float)(tileSize.Height / (scale * Astrometrics.ParsecScaleY)); DateTime dt = DateTime.Now; bool silly = (Math.Abs((int)x % 2) == Math.Abs((int)y % 2)) && (dt.Month == 4 && dt.Day == 1); silly = GetBoolOption("silly", silly); Render.RenderContext ctx = new Render.RenderContext(); ctx.resourceManager = resourceManager; ctx.selector = new RectSelector( SectorMap.FromName(SectorMap.DefaultSetting, resourceManager), resourceManager, tileRect); ctx.tileRect = tileRect; ctx.scale = scale; ctx.options = options; ctx.styles = new Stylesheet(scale, options, style); ctx.tileSize = tileSize; ctx.silly = silly; ctx.tiling = true; ProduceResponse("Tile", ctx, tileSize); }
void ISceneNode.Draw(Render.RenderContext context) { Renderable.DrawEx(context, worldTransformation); }
private void Page_Load(object sender, System.EventArgs e) { if (!ServiceConfiguration.CheckEnabled("jumpmap", Response)) { return; } // NOTE: This (re)initializes a static data structure used for // resolving names into sector locations, so needs to be run // before any other objects (e.g. Worlds) are loaded. ResourceManager resourceManager = new ResourceManager(Server, Cache); // // Jump // int jump = Util.Clamp(GetIntOption("jump", 6), 0, 12); // // Content & Coordinates // Selector selector; Location loc; if (Request.HttpMethod == "POST") { Sector sector; try { sector = GetPostedSector(); } catch (Exception ex) { SendError(400, "Invalid request", ex.Message); return; } if (sector == null) { SendError(400, "Invalid request", "Either file or data must be supplied in the POST data."); return; } int hex = GetIntOption("hex", Astrometrics.SectorCentralHex); loc = new Location(new Point(0, 0), hex); selector = new HexSectorSelector(resourceManager, sector, loc.HexLocation, jump); } else { SectorMap map = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager); if (HasOption("sector") && HasOption("hex")) { string sectorName = GetStringOption("sector"); int hex = GetIntOption("hex", 0); loc = new Location(map.FromName(sectorName).Location, hex); } else if (HasOption("sx") && HasOption("sy") && HasOption("hx") && HasOption("hy")) { int sx = GetIntOption("sx", 0); int sy = GetIntOption("sy", 0); int hx = GetIntOption("hx", 0); int hy = GetIntOption("hy", 0); loc = new Location(map.FromLocation(sx, sy).Location, hx * 100 + hy); } else if (HasOption("x") && HasOption("y")) { loc = Astrometrics.CoordinatesToLocation(GetIntOption("x", 0), GetIntOption("y", 0)); } else { loc = new Location(map.FromName("Spinward Marches").Location, 1910); } selector = new HexSelector(map, resourceManager, loc, jump); } // // Scale // double scale = Util.Clamp(GetDoubleOption("scale", 64), MinScale, MaxScale); // // Options & Style // MapOptions options = MapOptions.BordersMajor | MapOptions.BordersMinor | MapOptions.ForceHexes; Stylesheet.Style style = Stylesheet.Style.Poster; ParseOptions(ref options, ref style); // // Border // bool border = GetBoolOption("border", defaultValue: true); // // Clip // bool clip = GetBoolOption("clip", defaultValue: true); // // What to render // RectangleF tileRect = new RectangleF(); Point coords = Astrometrics.LocationToCoordinates(loc); tileRect.X = coords.X - jump - 1; tileRect.Width = jump + 1 + jump; tileRect.Y = coords.Y - jump - 1; tileRect.Height = jump + 1 + jump; // Account for jagged hexes tileRect.Y += (coords.X % 2 == 0) ? 0 : 0.5f; tileRect.Inflate(0.35f, 0.15f); Size tileSize = new Size((int)Math.Floor(tileRect.Width * scale * Astrometrics.ParsecScaleX), (int)Math.Floor(tileRect.Height * scale * Astrometrics.ParsecScaleY)); // Construct clipping path List <Point> clipPath = new List <Point>(jump * 6 + 1); Point cur = coords; for (int i = 0; i < jump; ++i) { // Move J parsecs to the upper-left (start of border path logic) cur = Astrometrics.HexNeighbor(cur, 1); } clipPath.Add(cur); for (int dir = 0; dir < 6; ++dir) { for (int i = 0; i < jump; ++i) { cur = Astrometrics.HexNeighbor(cur, (dir + 3) % 6); // Clockwise from upper left clipPath.Add(cur); } } Stylesheet styles = new Stylesheet(scale, options, style); // If any names are showing, show them all if (styles.worldDetails.HasFlag(WorldDetails.KeyNames)) { styles.worldDetails |= WorldDetails.AllNames; } // Compute path float[] edgeX, edgeY; RenderUtil.HexEdges(styles.microBorderStyle == MicroBorderStyle.Square ? PathUtil.PathType.Square : PathUtil.PathType.Hex, out edgeX, out edgeY); PointF[] boundingPathCoords; byte[] boundingPathTypes; PathUtil.ComputeBorderPath(clipPath, edgeX, edgeY, out boundingPathCoords, out boundingPathTypes); Render.RenderContext ctx = new Render.RenderContext(); ctx.resourceManager = resourceManager; ctx.selector = selector; ctx.tileRect = tileRect; ctx.scale = scale; ctx.options = options; ctx.styles = styles; ctx.tileSize = tileSize; ctx.border = border; ctx.clipPath = clip ? new XGraphicsPath(boundingPathCoords, boundingPathTypes, XFillMode.Alternate) : null; ProduceResponse("Jump Map", ctx, tileSize, transparent: clip); }
public void DrawEx(Render.RenderContext context) { DrawEx(context, Orientation.Transform); }
public void PreDraw(float elapsedTime, GraphicsDevice device, Render.RenderContext context) { module.DrawRoot(uiRoot, uiCamera, renderTarget); }
protected void ProduceResponse(string title, Render.RenderContext ctx, Size tileSize, int rot = 0, float translateX = 0, float translateY = 0, bool transparent = false) { // New-style Options // TODO: move to ParseOptions (maybe - requires options to be parsed after stylesheet creation?) if (GetBoolOption("sscoords", defaultValue: false)) { ctx.styles.hexCoordinateStyle = Stylesheet.HexCoordinateStyle.Subsector; } if (!GetBoolOption("routes", defaultValue: true)) { ctx.styles.macroRoutes.visible = false; ctx.styles.microRoutes.visible = false; } double devicePixelRatio = GetDoubleOption("dpr", 1); if (Accepts(MediaTypeNames.Application.Pdf)) { using (var document = new PdfDocument()) { document.Version = 14; // 1.4 for opacity document.Info.Title = title; document.Info.Author = "Joshua Bell"; document.Info.Creator = "TravellerMap.com"; document.Info.Subject = DateTime.Now.ToString("F", CultureInfo.InvariantCulture); document.Info.Keywords = "The Traveller game in all forms is owned by Far Future Enterprises. Copyright (C) 1977 - 2013 Far Future Enterprises. Traveller is a registered trademark of Far Future Enterprises."; // TODO: Credits/Copyright // This is close, but doesn't define the namespace correctly: // document.Info.Elements.Add( new KeyValuePair<string, PdfItem>( "/photoshop/Copyright", new PdfString( "HelloWorld" ) ) ); PdfPage page = document.AddPage(); // NOTE: only PageUnit currently supported in XGraphics is Points page.Width = XUnit.FromPoint(tileSize.Width); page.Height = XUnit.FromPoint(tileSize.Height); PdfSharp.Drawing.XGraphics gfx = PdfSharp.Drawing.XGraphics.FromPdfPage(page); RenderToGraphics(ctx, rot, translateX, translateY, gfx); using (var stream = new MemoryStream()) { document.Save(stream, closeStream: false); SetCommonResponseHeaders(); Response.ContentType = MediaTypeNames.Application.Pdf; Response.AddHeader("content-length", stream.Length.ToString()); Response.AddHeader("content-disposition", "inline;filename=\"map.pdf\""); Response.BinaryWrite(stream.ToArray()); Response.Flush(); stream.Close(); } return; } } using (var bitmap = new Bitmap((int)Math.Floor(tileSize.Width * devicePixelRatio), (int)Math.Floor(tileSize.Height * devicePixelRatio), PixelFormat.Format32bppArgb)) { if (transparent) { bitmap.MakeTransparent(); } using (var g = Graphics.FromImage(bitmap)) { g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; using (var graphics = XGraphics.FromGraphics(g, new XSize(tileSize.Width * devicePixelRatio, tileSize.Height * devicePixelRatio))) { if (devicePixelRatio != 0) { graphics.ScaleTransform(devicePixelRatio); } RenderToGraphics(ctx, rot, translateX, translateY, graphics); } } SetCommonResponseHeaders(); BitmapResponse(ctx.styles, bitmap, transparent ? Util.MediaTypeName_Image_Png : null); } }
private void Page_Load(object sender, System.EventArgs e) { if (!ServiceConfiguration.CheckEnabled("poster", Response)) { return; } // NOTE: This (re)initializes a static data structure used for // resolving names into sector locations, so needs to be run // before any other objects (e.g. Worlds) are loaded. ResourceManager resourceManager = new ResourceManager(Server, Cache); Selector selector; RectangleF tileRect = new RectangleF(); MapOptions options = MapOptions.SectorGrid | MapOptions.SubsectorGrid | MapOptions.BordersMajor | MapOptions.BordersMinor | MapOptions.NamesMajor | MapOptions.NamesMinor | MapOptions.WorldsCapitals | MapOptions.WorldsHomeworlds; Stylesheet.Style style = Stylesheet.Style.Poster; ParseOptions(ref options, ref style); string title; if (HasOption("x1") && HasOption("x2") && HasOption("y1") && HasOption("y2")) { // Arbitrary rectangle int x1 = GetIntOption("x1", 0); int x2 = GetIntOption("x1", 0); int y1 = GetIntOption("x1", 0); int y2 = GetIntOption("x1", 0); tileRect.X = Math.Min(x1, x2); tileRect.Y = Math.Min(y1, y2); tileRect.Width = Math.Max(x1, x2) - tileRect.X; tileRect.Height = Math.Max(y1, y2) - tileRect.Y; SectorMap map = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager); selector = new RectSelector(map, resourceManager, tileRect); selector.Slop = false; tileRect.Offset(-1, -1); tileRect.Width += 1; tileRect.Height += 1; title = String.Format("Poster ({0},{1}) - ({2},{3})", x1, y1, x2, y2); } else { // Sector - either POSTed or specified by name Sector sector = null; options = options & ~MapOptions.SectorGrid; if (Request.HttpMethod == "POST") { try { sector = GetPostedSector(); } catch (Exception ex) { SendError(400, "Invalid request", ex.Message); return; } if (sector == null) { SendError(400, "Invalid request", "Either file or data must be supplied in the POST data."); return; } title = "User Data"; } else { string sectorName = GetStringOption("sector"); if (sectorName == null) { SendError(404, "Not Found", "No sector specified."); return; } SectorMap map = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager); sector = map.FromName(sectorName); if (sector == null) { SendError(404, "Not Found", String.Format("The specified sector '{0}' was not found.", sectorName)); return; } title = sector.Names[0].Text; } if (HasOption("subsector") && GetStringOption("subsector").Length > 0) { options = options & ~MapOptions.SubsectorGrid; char ss = GetStringOption("subsector").ToUpperInvariant()[0]; if (ss < 'A' || ss > 'P') { SendError(400, "Invalid subsector", String.Format("The subsector index '{0}' is not valid (must be A...P).", ss)); return; } int index = (int)(ss) - (int)('A'); selector = new SubsectorSelector(resourceManager, sector, index); tileRect = sector.SubsectorBounds(index); options &= ~(MapOptions.SectorGrid | MapOptions.SubsectorGrid); title = String.Format("{0} - Subsector {1}", title, ss); } else { selector = new SectorSelector(resourceManager, sector); tileRect = sector.Bounds; options &= ~(MapOptions.SectorGrid); } // Account for jagged hexes tileRect.X -= 0.25f; tileRect.Width += 0.5f; tileRect.Height += 0.5f; if (style == Stylesheet.Style.Candy) { tileRect.Width += 0.75f; } } const double NormalScale = 64; // pixels/parsec - standard subsector-rendering scale double scale = Util.Clamp(GetDoubleOption("scale", NormalScale), MinScale, MaxScale); int rot = GetIntOption("rotation", 0) % 4; Size tileSize = new Size((int)Math.Floor(tileRect.Width * scale * Astrometrics.ParsecScaleX), (int)Math.Floor(tileRect.Height * scale * Astrometrics.ParsecScaleY)); int bitmapWidth = tileSize.Width, bitmapHeight = tileSize.Height; float translateX = 0, translateY = 0, angle = rot * 90; switch (rot) { case 1: // 90 degrees clockwise bitmapWidth = tileSize.Height; bitmapHeight = tileSize.Width; translateX = bitmapWidth; break; case 2: // 180 degrees translateX = tileSize.Width; translateY = tileSize.Height; break; case 3: // 270 degrees clockwise bitmapWidth = tileSize.Height; bitmapHeight = tileSize.Width; translateY = bitmapHeight; break; } Render.RenderContext ctx = new Render.RenderContext(); ctx.resourceManager = resourceManager; ctx.selector = selector; ctx.tileRect = tileRect; ctx.scale = scale; ctx.options = options; ctx.styles = new Stylesheet(scale, options, style); ctx.tileSize = tileSize; ProduceResponse(title, ctx, new Size(bitmapWidth, bitmapHeight), rot, translateX, translateY); }