public static UIGraphic Begin(double width, double height) { UIGraphic g = new UIGraphic(); g.imageBuffer = new ImageBuffer((int)width, (int)height, 32, new BlenderRGBA()); g.graphics2D = g.imageBuffer.NewGraphics2D(); return g; }
//路径 public static CCSprite CreatePath( double width, double height, string[] paths, double contentX, double contentY, double contentWidth, double contentHeight, CCColor4B fill, CCColor4B stroke, double strokeThickness = 1, UIGraphic.Stretch stretch = UIGraphic.Stretch.StretchNone ) { if (width == 0) width = contentWidth; if (height == 0) height = contentHeight; ImageBuffer buffer = new ImageBuffer((int)width, (int)height, 32, new BlenderRGBA()); Graphics2D g = buffer.NewGraphics2D(); double scalex = 0; double scaley = 0; //if (stretch == Stretch.StretchNone) { } else if (stretch == UIGraphic.Stretch.StretchFill) { if (width != contentWidth || height != contentHeight) { scalex = width / contentWidth; scaley = height / contentHeight; } } else if (stretch == UIGraphic.Stretch.StretchUniformToFill) { scalex = scaley = Math.Min(width / contentWidth, height / contentHeight); } foreach (string path in paths) { IVertexSource vertexs = MiniLanguage.CreatePathStorage(path); if (contentX != 0 || contentY != 0) vertexs = new VertexSourceApplyTransform(vertexs, Affine.NewTranslation(-contentX, -contentY)); if (scalex != 0 || scaley != 0) vertexs = new VertexSourceApplyTransform(vertexs, Affine.NewScaling(scalex, scaley)); if (fill.A > 0) g.Render(vertexs, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A)); if (stroke.A > 0) g.Render(new Stroke(vertexs, strokeThickness), new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A)); } Texture2D xnaTexture = XnaTexture((int)width, (int)height); xnaTexture.SetData<byte>(buffer.GetBuffer()); CCTexture2D ccTexture = new CCTexture2D(); ccTexture.InitWithTexture(xnaTexture); return new CCSprite(ccTexture); }