public void addImage(Bitmap img, Point pos) { if (img != null) { //TODO: ADDIMAGE /* * var box = new uc_CutoutHolder(); * box.Parent = this; * * box.Width = img.Width; * box.Height = img.Height; * * box.Left = pos.X; * box.Top = pos.Y; * * box.BMP = img; */ var box = new c_ImageHolder(); box.parent = this; box.Size = new Size(img.Width, img.Height); box.Position = new Point(pos.X, pos.Y); box.Image = img; box.LayerIndex = Limages.Count; box.selfContainingList = Limages; Limages.Add(box); } }
//TODO: MOUSE MOVE!! private void f_Screen_MouseMove(object sender, MouseEventArgs e) { if (mdown && selectedImage != null) { selectedImage.Position = new Point(e.X - imageDragPoint.X, e.Y - imageDragPoint.Y); Invalidate(); } else { c_ImageHolder img = null; if (pointOverAny(e.Location, out img)) { mouseOverImage = img; mouseOverImage.mouseOver = true; if (pointInPosition(e.Location, new Rectangle(mouseOverImage.Position, new Size(mouseOverImage.Width, 20)))) { mouseOverImage.showPanel(); } } else { mouseOverImage = null; } foreach (c_ImageHolder cc in Limages) { if (cc != mouseOverImage) { cc.mouseOver = false; } } Invalidate(); } }
public bool pointOverAny(Point p, out c_ImageHolder overImg) { overImg = null; foreach (c_ImageHolder c in Limages) { if (pointInPosition(p, c.bounds())) { overImg = c; return(true); } } return(false); }
private void f_Screen_MouseDown(object sender, MouseEventArgs e) { Limages.Sort(new intComparerDesc()); foreach (c_ImageHolder c in Limages) { if (pointInPosition(e.Location, new Rectangle(c.Position, c.Size))) { c.select(); selectedImage = c; imageDragPoint = new Point(e.X - c.Left, e.Y - c.Top); mdown = true; break; } } Invalidate(); }
private void f_Screen_MouseUp(object sender, MouseEventArgs e) { selectedImage = null; mdown = false; }
public void f_Screen_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Right || e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Escape) { var c = c_ImgGen.returnCutouts(this); c_ImageHolder u = null; foreach (var cc in Limages) { if (cc.selected) { u = cc; break; } } int add = 1; if (e.Control) { add = 5; } if (u != null) { c_ImageHolder.directions dir = c_ImageHolder.directions.none; switch (e.KeyCode) { case Keys.Left: dir = c_ImageHolder.directions.left; break; case Keys.Right: dir = c_ImageHolder.directions.right; break; case Keys.Up: dir = c_ImageHolder.directions.up; break; case Keys.Down: dir = c_ImageHolder.directions.down; break; case Keys.Escape: u.selected = false; Invalidate(); break; } if (dir != c_ImageHolder.directions.none) { u.move(dir, add); Invalidate(); } } else if (e.KeyCode == Keys.Escape) { } } else { parent.Form1_KeyDown(sender, e); } }
/* * public static Bitmap createImage(System.Drawing.Rectangle rec, Dictionary<int, uc_CutoutHolder> cutouts) * { * return createImage(rec, cutouts, false); * } */ /* * public static Bitmap createImage(System.Drawing.Rectangle rec, Dictionary<int, uc_CutoutHolder> cutouts, bool drawTBG) * { * int border = 0; * * if (Properties.Settings.Default.s_hasBorder) * { * border = Properties.Settings.Default.s_borderWidth; * } * * Bitmap bm = null; * * try * { * bm = new Bitmap(rec.Width + (border * 2), rec.Height + (border * 2)); * * using (Graphics g = Graphics.FromImage(bm)) * { * c_returnGraphicSettings cg = new c_returnGraphicSettings(); * * g.SmoothingMode = cg.getSM(); * g.InterpolationMode = cg.getIM(); * g.PixelOffsetMode = cg.getPOM(); * * g.Clear(Color.Transparent); * * if (Properties.Settings.Default.s_hasBgColor) * { g.Clear(Properties.Settings.Default.s_bgColor); } * else { g.Clear(Color.Transparent); } * * if (drawTBG) * { * int x = 0; * int y = 0; * while (y < bm.Height) * { * while (x < bm.Width) * { * g.DrawImageUnscaled(Properties.Resources.transparentBG, new Point(x, y)); * x += Properties.Resources.transparentBG.Width; * } * * y += Properties.Resources.transparentBG.Height; * x = 0; * } * } * * foreach (KeyValuePair<int, uc_CutoutHolder> kvp in cutouts) * { * uc_CutoutHolder k = kvp.Value; * g.DrawImage(k.BMP, new System.Drawing.Rectangle(k.Left - rec.Left + border, k.Top - rec.Top + border, k.Width, k.Height), new System.Drawing.Rectangle(0, 0, k.BMP.Width, k.BMP.Height), GraphicsUnit.Pixel); * } * * if (Properties.Settings.Default.s_hasBorder) * { * Brush b = new SolidBrush(Properties.Settings.Default.s_borderColor); * * g.FillRectangle(b, new RectangleF(0, 0, bm.Width, border)); * g.FillRectangle(b, new RectangleF(0, bm.Height - border, bm.Width, border)); * g.FillRectangle(b, new RectangleF(0, 0, border, bm.Height)); * g.FillRectangle(b, new RectangleF(bm.Width - border, 0, border, bm.Height)); * } * } * } * catch * { * * } * * return bm; * } */ /* * public static Bitmap createPng(f_Screen fs, Dictionary<int, uc_CutoutHolder> cutouts, Object[] drawings) { return createPng(fs, cutouts, drawings, false); } */ /* * public static Bitmap createPng(f_Screen fs, Dictionary<int, uc_CutoutHolder> cutouts, Object[] drawings, bool drawTBG) * { * if (fs != null) * { * fillDict(fs,out cutouts); * * int left = int.MaxValue; * int top = int.MaxValue; * * int right = 0; * int bottom = 0; * * foreach (var v in cutouts) * { * var k = v.Value; * if (k.Left < left) { left = k.Left; } * if (k.Top < top) { top = k.Top; } * if (k.Right > right) { right = k.Right; } * if (k.Bottom > bottom) { bottom = k.Bottom; } * } * * int height = bottom - top; * int width = right - left; * * var picrec = new System.Drawing.Rectangle(left, top, width, height); * * Bitmap _b = createImage(picrec, cutouts, drawTBG); * * //TODO: Redo this. drawnpoints instead of lines * //TODO: New object type instead of Bitmaps * if (drawings != null && drawings.Length == 2) * { * List<c_DrawnPoints> lines = drawings[0] as List<c_DrawnPoints>; * //List<Bitmap> shapes = drawings[1] as List<Bitmap>; * * if(lines.Count > 0) * * try * { * using (Graphics g = Graphics.FromImage(_b)) * { * * for (int i = 0; i < lines.Count - 2; i++) * { * c_DrawnPoints l = lines[i]; * c_DrawnPoints l2 = lines[i + 1]; * * Point p1 = new Point(l.X, l.Y); * Point p2 = new Point(l2.X, l2.Y); * * g.DrawLine(Pens.Black, p1, p2); * } * * } * } * catch * { * * } * * } * * return _b; * } * else { return null; } * } * /* -- */ public static Bitmap createImage(System.Drawing.Rectangle rec, List <c_ImageHolder> cutouts, bool drawTBG) { int border = 0; if (Properties.Settings.Default.s_hasBorder) { border = Properties.Settings.Default.s_borderWidth; } Bitmap bm = null; try { bm = new Bitmap(rec.Width + (border * 2), rec.Height + (border * 2)); using (Graphics g = Graphics.FromImage(bm)) { c_returnGraphicSettings cg = new c_returnGraphicSettings(); g.SmoothingMode = cg.getSM(); g.InterpolationMode = cg.getIM(); g.PixelOffsetMode = cg.getPOM(); g.Clear(Color.Transparent); if (Properties.Settings.Default.s_hasBgColor) { g.Clear(Properties.Settings.Default.s_bgColor); } else { g.Clear(Color.Transparent); } if (drawTBG) { int x = 0; int y = 0; while (y < bm.Height) { while (x < bm.Width) { g.DrawImageUnscaled(Properties.Resources.transparentBG, new Point(x, y)); x += Properties.Resources.transparentBG.Width; } y += Properties.Resources.transparentBG.Height; x = 0; } } foreach (c_ImageHolder c in cutouts) { c_ImageHolder k = c; g.DrawImage(k.Image, new System.Drawing.Rectangle(k.Left - rec.Left + border, k.Top - rec.Top + border, k.Width, k.Height), new System.Drawing.Rectangle(0, 0, k.Image.Width, k.Image.Height), GraphicsUnit.Pixel); } if (Properties.Settings.Default.s_hasBorder) { Brush b = new SolidBrush(Properties.Settings.Default.s_borderColor); g.FillRectangle(b, new RectangleF(0, 0, bm.Width, border)); g.FillRectangle(b, new RectangleF(0, bm.Height - border, bm.Width, border)); g.FillRectangle(b, new RectangleF(0, 0, border, bm.Height)); g.FillRectangle(b, new RectangleF(bm.Width - border, 0, border, bm.Height)); } } } catch { } return(bm); }