public void RenderGL() { if ((img == null) && (imgname != null)) { img = UVDLPApp.Instance().m_2d_graphics.GetImage(imgname); } if (img != null) { GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, img.tex); //GL.Begin(BeginMode.Quads); GL.Begin(PrimitiveType.Quads); GL.Color3(Color.White); GL.TexCoord2(img.x2, img.y1); GL.Vertex3(points[0].x, points[0].y, points[0].z); GL.TexCoord2(img.x1, img.y1); GL.Vertex3(points[1].x, points[1].y, points[1].z); GL.TexCoord2(img.x1, img.y2); GL.Vertex3(points[2].x, points[2].y, points[2].z); GL.TexCoord2(img.x2, img.y2); GL.Vertex3(points[3].x, points[3].y, points[3].z); GL.End(); GL.Disable(EnableCap.Texture2D); } else { GL.Begin(PrimitiveType.Quads); GL.Color3(col); for (int i = 0; i < 4; i++) GL.Vertex3(points[i].x, points[i].y, points[i].z); GL.End(); } }
public void Image(String name, float x, float y) { if (ImgDbase.ContainsKey(name)) { C2DImage img = ImgDbase[name]; Image(img.tex, img.x1, img.x2, img.y1, img.y2, x, y, img.w, img.h); } }
public Quad3d() { points = new Point3d[4]; for (int i = 0; i < 4; i++) points[i] = new Point3d(0, 0, 0); img = null; imgname = null; }
public void Image(C2DImage img, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) { sx /= img.scalex; sy /= img.scaley; sw /= img.scalex; sh /= img.scaley; Image(img.tex, img.x1 + sx, img.x1 + sx + sw, img.y1 + sy, img.y1 + sy + sh, dx, dy, dw, dh); }
public void Image(String name, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) { if (ImgDbase.ContainsKey(name)) { C2DImage img = ImgDbase[name]; Image(img, sx, sy, sw, sh, dx, dy, dw, dh); } }
public void Panel9(String name, float x, float y, float w, float h) { if (name == null) { return; } if (!ImgDbase.ContainsKey(name)) { return; } C2DImage img = ImgDbase[name]; float x3 = img.w / 3; float x4 = img.w - x3; if ((x4 + x3) > w) { x3 = x4 = w / 2; } float y3 = img.h / 3; float y4 = img.h - x3; if ((y4 + y3) > h) { y3 = y4 = h / 2; } float sx3 = img.x1 + x3 / img.scalex; float sx4 = img.x1 + x4 / img.scalex; float sy3 = img.y1 + y3 / img.scaley; float sy4 = img.y1 + y4 / img.scaley; // draw corners Image(img.tex, img.x1, sx3, img.y1, sy3, x, y, x3, y3); Image(img.tex, sx4, img.x2, img.y1, sy3, x + w - x3, y, x3, y3); Image(img.tex, img.x1, sx3, sy4, img.y2, x, y + h - y3, x3, y3); Image(img.tex, sx4, img.x2, sy4, img.y2, x + w - x3, y + h - y3, x3, y3); // draw top and bottom bar if (x3 < x4) { Image(img.tex, sx3, sx4, img.y1, sy3, x + x3, y, w - 2 * x3, y3); Image(img.tex, sx3, sx4, sy4, img.y2, x + x3, y + h - y3, w - 2 * x3, y3); } // draw left and right bar if (y3 < y4) { Image(img.tex, img.x1, sx3, sy3, sy4, x, y + y3, x3, h - 2 * y3); Image(img.tex, sx4, img.x2, sy3, sy4, x + w - x3, y + y3, x3, h - 2 * y3); } // draw center bar if ((y3 < y4) && (x3 < x4)) { Image(img.tex, sx3, sx4, sy3, sy4, x + x3, y + y3, w - 2 * x3, h - 2 * y3); } }
public C2DFont LoadFont(string name, string metrics) { if ((name == null) || (metrics == null)) { return(null); } C2DImage img = GetImage(name); if (img == null) { return(null); } // string metrics = global::UV_DLP_3D_Printer.Properties.Resources.ResourceManager.GetString(name + "_metrics"); try { MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(metrics)); XmlDocument xdoc = new XmlDocument(); xdoc.Load(ms); XmlNode rootnode = xdoc.ChildNodes[1]; if (rootnode.Name != "fontMetrics") { return(null); } C2DFont font = new C2DFont(); font.image = img; font.chars = new C2DChar[256]; for (int i = 0; i < 256; i++) { font.chars[0] = null; } C2DChar chr = null; int chrnum; foreach (XmlNode xnode in rootnode.ChildNodes) { chrnum = int.Parse(xnode.Attributes["key"].Value); chr = new C2DChar(); chr.x = int.Parse(xnode["x"].InnerText); chr.y = int.Parse(xnode["y"].InnerText); chr.w = int.Parse(xnode["width"].InnerText); chr.h = int.Parse(xnode["height"].InnerText); font.chars[chrnum] = chr; } if (chr != null) { font.height = chr.h; } FontDbase[name] = font; return(font); } catch (Exception) { return(null); } }
public void AddImage(string name, Bitmap image) { C2DImage img = new C2DImage(); img.name = name; img.w = image.Width; img.h = image.Height; img.bmp = image; mNewImages.Add(img); needPacking = true; }
public void Image(String name, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) { if (needPacking) { GenereteUserTexture(); } if (ImgDbase.ContainsKey(name)) { C2DImage img = ImgDbase[name]; Image(img, sx, sy, sw, sh, dx, dy, dw, dh); } }
public override void OnGLPaint(C2DGraphics gr) { base.OnGLPaint(gr); if (mGLImageCach == null) { mGLImageCach = gr.GetImage(mGLImage); if (mGLImageCach == null) return; gr.SetColor(Style.ForeColor); gr.Image(mGLImageCach, 0, 0, mGLImageCach.w, mGLImageCach.h, 0, 0, Width, Height); } }
public Bitmap GetBitmap(String name) { C2DImage img = GetImage(name); if (img == null) { return(null); } Bitmap bmp = img.bmp.Clone(new RectangleF(img.x, img.y, img.w, img.h), img.bmp.PixelFormat); return(bmp); }
public void Image(String name, float x, float y) { if (needPacking) { GenereteUserTexture(); } if (ImgDbase.ContainsKey(name)) { C2DImage img = ImgDbase[name]; Image(img.tex, img.x1, img.x2, img.y1, img.y2, x, y, img.w, img.h); } }
public void GetImageDim(String name, ref int w, ref int h) { if (name == null) { return; } if (ImgDbase.ContainsKey(name)) { C2DImage img = ImgDbase[name]; w = img.w; h = img.h; } else { w = 0; h = 0; } }
public void Image(C2DImage img, float x, float y) { Image(img.tex, img.x1, img.x2, img.y1, img.y2, x, y, img.w, img.h); }
public void GenereteUserTexture() { if (mUserTexture >= 0) { DeleteTexture(mUserTexture); } // step 1, arrange all textures in a one big bitmap; Bitmap bmp = new Bitmap(2048, 2048, System.Drawing.Imaging.PixelFormat.Format32bppArgb); float tw = bmp.Width; float th = bmp.Height; BinPacker bp = new BinPacker(); List <BinPacker.BinRect> rects = new List <BinPacker.BinRect>(); foreach (C2DImage img in mNewImages) { BinPacker.BinRect rc = new BinPacker.BinRect(img.w, img.h, img); rects.Add(rc); } bp.Pack(rects, bmp.Width, bmp.Height, false); List <C2DImage> packedImages = new List <C2DImage>(); foreach (BinPacker.BinRect rc in rects) { C2DImage img = (C2DImage)rc.obj; if (rc.packed) { img.x = rc.x; img.y = rc.y; img.x1 = (img.x + 0.5f) / tw; img.y1 = (img.y + 0.5f) / th; img.x2 = img.x1 + (float)(img.w - 1) / tw; img.y2 = img.y1 + (float)(img.h - 1) / th; img.scalex = tw; img.scaley = th; for (int i = 0; i < img.bmp.Height; i++) { System.Drawing.Imaging.BitmapData ddata = bmp.LockBits(new Rectangle((int)img.x, (int)img.y + i, img.bmp.Width, 1), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb); System.Drawing.Imaging.BitmapData sdata = img.bmp.LockBits(new Rectangle(0, i, img.bmp.Width, 1), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); int numBytes = 4 * img.bmp.Width; byte[] rgbValues = new byte[numBytes]; Marshal.Copy(sdata.Scan0, rgbValues, 0, numBytes); Marshal.Copy(rgbValues, 0, ddata.Scan0, numBytes); bmp.UnlockBits(ddata); img.bmp.UnlockBits(sdata); } packedImages.Add(img); mNewImages.Remove(img); } } if (mNewImages.Count != 0) { DebugLogger.Instance().LogError("Not all user images could be loaded"); } //bmp.Save("packedbmp.png", System.Drawing.Imaging.ImageFormat.Png); mUserTexture = LoadTextureImage(bmp); foreach (C2DImage img in packedImages) { img.tex = mUserTexture; ImgDbase[img.name] = img; } needPacking = false; }
public void LoadTexture(Bitmap image, string index) { float tw = image.Width; float th = image.Height; int tex = LoadTextureImage(image); //StreamReader sr = new StreamReader(index); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(index)); StreamReader sr = new StreamReader(ms); bool datasection = false; C2DImage img = null; while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line.StartsWith("repeat:")) { datasection = true; continue; } if (!datasection) continue; if (line[0] != ' ') { // a new image img = new C2DImage(); img.name = line.Trim(); img.tex = tex; img.scalex = tw; img.scaley = th; ImgDbase[img.name] = img; continue; } // a parameter string[] tokens = line.Trim().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries); switch (tokens[0]) { case "xy:": img.x1 = float.Parse(tokens[1]) / tw; img.y1 = float.Parse(tokens[2]) / th; break; case "size:": img.w = int.Parse(tokens[1]); img.h = int.Parse(tokens[2]); img.x2 = img.x1 + (float)img.w / tw; img.y2 = img.y1 + (float)img.h / th; break; } } }
public void LoadTexture(string index, IPlugin plugin) { float tw = 1; float th = 1; Bitmap image = null; int tex = -1; //StreamReader sr = new StreamReader(index); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(index)); StreamReader sr = new StreamReader(ms); bool datasection = false; C2DImage img = null; while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line.StartsWith("repeat:") && tex >= 0) { datasection = true; continue; } if (!datasection) { if (line.EndsWith(".png")) { string imgname = line.Substring(0, line.Length - 4); try { if (plugin != null) { image = (Bitmap)plugin.GetImage(imgname); } else { image = (Bitmap)global::UV_DLP_3D_Printer.Properties.Resources.ResourceManager.GetObject(imgname); } tw = image.Width; th = image.Height; tex = LoadTextureImage(image); } catch (Exception) { tex = -1; } } continue; } if (line[0] != ' ') { // a new image img = new C2DImage(); img.name = line.Trim(); img.tex = tex; img.scalex = tw; img.scaley = th; img.bmp = image; ImgDbase[img.name] = img; continue; } // a parameter string[] tokens = line.Trim().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries); switch (tokens[0]) { case "xy:": img.x = float.Parse(tokens[1]); img.y = float.Parse(tokens[2]); img.x1 = (img.x + 0.5f) / tw; img.y1 = (img.y + 0.5f) / th; break; case "size:": img.w = int.Parse(tokens[1]); img.h = int.Parse(tokens[2]); img.x2 = img.x1 + (float)(img.w - 1) / tw; img.y2 = img.y1 + (float)(img.h - 1) / th; break; } } }
public void LoadTexture(string index, IPlugin plugin) { float tw = 1; float th = 1; Bitmap image = null; int tex = -1; //StreamReader sr = new StreamReader(index); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(index)); StreamReader sr = new StreamReader(ms); bool datasection = false; C2DImage img = null; while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line.StartsWith("repeat:") && tex >= 0) { datasection = true; continue; } if (!datasection) { if (line.EndsWith(".png")) { string imgname = line.Substring(0, line.Length - 4); try { if (plugin != null) image = (Bitmap)plugin.GetImage(imgname); else image = (Bitmap)global::UV_DLP_3D_Printer.Properties.Resources.ResourceManager.GetObject(imgname); tw = image.Width; th = image.Height; tex = LoadTextureImage(image); } catch (Exception) { tex = -1; } } continue; } if (line[0] != ' ') { // a new image img = new C2DImage(); img.name = line.Trim(); img.tex = tex; img.scalex = tw; img.scaley = th; img.bmp = image; ImgDbase[img.name] = img; continue; } // a parameter string[] tokens = line.Trim().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries); switch (tokens[0]) { case "xy:": img.x = float.Parse(tokens[1]); img.y = float.Parse(tokens[2]); img.x1 = (img.x + 0.5f) / tw; img.y1 = (img.y + 0.5f) / th; break; case "size:": img.w = int.Parse(tokens[1]); img.h = int.Parse(tokens[2]); img.x2 = img.x1 + (float)(img.w -1) / tw; img.y2 = img.y1 + (float)(img.h -1) / th; break; } } }
public override void OnGLPaint(C2DGraphics gr) { base.OnGLPaint(gr); if (mGLImageCach == null) { mGLImageCach = gr.GetImage(mGLImage); if (mGLImageCach == null) return; mSubImgWidth = mGLImageCach.w / Style.SubImgCount; } GuiControlStyle stl = Style; if (stl.SubImgCount == 4) GLPaint4(gr); if (stl.SubImgCount == 1) GLPaint1(gr, stl); C2DImage cimg = stl.CheckedImageCach; if (Enabled && (cimg != null)) { int chimgw = cimg.w / 2; int posx = Checked ? chimgw : 0; gr.SetColor(stl.CheckedColor); gr.Image(cimg, posx, 0, chimgw, cimg.h, 0, 0, Width, Height); } }