public override void DrawEditor(IBitmapView view) { if (view.Image == null || view.Image.Width == 0 || view.Image.Height == 0) { return; } Gdk.Drawable target = ((FloatPixmapViewWidget)view).GdkWindow; Gdk.Rectangle image_position = ((FloatPixmapViewWidget)view).CurrentImagePosition; CrotateStageOperationParameters pm = ((CrotateStageOperationParameters)Parameters); Gdk.GC gc = new Gdk.GC(target); // Draw center square dot Point C = new Point(pm.Center.X, pm.Center.Y); int scr_c_x = image_position.X + (int)(image_position.Width * C.X); int scr_c_y = image_position.Y + (int)(image_position.Height * C.Y); // Calculating new picture's real dimensions int trueWidth = image_position.Width, trueHeight = image_position.Height; double w1, h1; w1 = pm.CropWidth * image_position.Width; h1 = pm.CropHeight * image_position.Height; double asp_rat; if (pm.AspectRatioCustom) { asp_rat = pm.AspectRatio; } else { asp_rat = pm.PresetAspectRatioValues[pm.AspectRatioPreset]; } switch (pm.Mode) { case CatEye.Core.CrotateStageOperation.Mode.Disproportional: trueWidth = (int)w1; trueHeight = (int)h1; break; case CatEye.Core.CrotateStageOperation.Mode.ProportionalWidthFixed: trueWidth = (int)w1; trueHeight = (int)(w1 / asp_rat); break; case CatEye.Core.CrotateStageOperation.Mode.ProportionalHeightFixed: trueWidth = (int)(h1 * asp_rat); trueHeight = (int)h1; break; } // Calculating new corners positions and "round" dot position double ang = pm.Angle / 180 * Math.PI; CatEye.Core.Point lt_corner = new CatEye.Core.Point( -trueWidth / 2, -trueHeight / 2); lt_corner_rot = CatEye.Core.Point.Rotate(lt_corner, ang, new Point(0, 0)); Gdk.Point scr_lt = new Gdk.Point( (int)(scr_c_x + lt_corner_rot.X), (int)(scr_c_y + lt_corner_rot.Y)); CatEye.Core.Point rt_corner = new CatEye.Core.Point( +trueWidth / 2, -trueHeight / 2); rt_corner_rot = CatEye.Core.Point.Rotate(rt_corner, ang, new Point(0, 0)); Gdk.Point scr_rt = new Gdk.Point( (int)(scr_c_x + rt_corner_rot.X), (int)(scr_c_y + rt_corner_rot.Y)); CatEye.Core.Point rb_corner = new CatEye.Core.Point( +trueWidth / 2, +trueHeight / 2); rb_corner_rot = CatEye.Core.Point.Rotate(rb_corner, ang, new Point(0, 0)); Gdk.Point scr_rb = new Gdk.Point( (int)(scr_c_x + rb_corner_rot.X), (int)(scr_c_y + rb_corner_rot.Y)); CatEye.Core.Point lb_corner = new CatEye.Core.Point( -trueWidth / 2, +trueHeight / 2); lb_corner_rot = CatEye.Core.Point.Rotate(lb_corner, ang, new Point(0, 0)); Gdk.Point scr_lb = new Gdk.Point( (int)(scr_c_x + lb_corner_rot.X), (int)(scr_c_y + lb_corner_rot.Y)); Gdk.Point scr_rnd = new Gdk.Point( (int)(scr_c_x + (rt_corner_rot.X + rb_corner_rot.X) / 2), (int)(scr_c_y + (rt_corner_rot.Y + rb_corner_rot.Y) / 2)); // Drawing frame using (Cairo.Context cc = Gdk.CairoHelper.Create(target)) { cc.LineCap = Cairo.LineCap.Round; cc.LineJoin = Cairo.LineJoin.Round; cc.Color = new Cairo.Color(0, 0, 0, 0.5); cc.LineWidth = 3; cc.MoveTo(scr_lt.X, scr_lt.Y); cc.LineTo(scr_lb.X, scr_lb.Y); cc.LineTo(scr_rb.X, scr_rb.Y); cc.LineTo(scr_rt.X, scr_rt.Y); cc.LineTo(scr_lt.X, scr_lt.Y); cc.ClosePath(); cc.Stroke(); cc.Color = new Cairo.Color(1, 1, 1, 1); cc.LineWidth = 1; cc.SetDash(new double[] { 3, 3 }, 0); cc.MoveTo(scr_lt.X, scr_lt.Y); cc.LineTo(scr_lb.X, scr_lb.Y); cc.LineTo(scr_rb.X, scr_rb.Y); cc.LineTo(scr_rt.X, scr_rt.Y); cc.LineTo(scr_lt.X, scr_lt.Y); cc.ClosePath(); cc.Stroke(); } // Drawing center "triangle" dot. using (Gdk.Pixbuf buf = Gdk.Pixbuf.LoadFromResource("CatEye.UI.Gtk.Widgets.res.triangle_dot.png")) { target.DrawPixbuf(gc, buf, 0, 0, (int)(scr_c_x - buf.Width / 2), (int)(scr_c_y - buf.Height / 2), buf.Width, buf.Height, Gdk.RgbDither.None, 0, 0); } // Drawing side "round" dot. using (Gdk.Pixbuf buf = Gdk.Pixbuf.LoadFromResource("CatEye.UI.Gtk.Widgets.res.round_dot.png")) { target.DrawPixbuf(gc, buf, 0, 0, (int)(scr_rnd.X - buf.Width / 2), (int)(scr_rnd.Y - buf.Height / 2), buf.Width, buf.Height, Gdk.RgbDither.None, 0, 0); } // Drawing corner "square" dot. using (Gdk.Pixbuf buf = Gdk.Pixbuf.LoadFromResource("CatEye.UI.Gtk.Widgets.res.square_dot.png")) { target.DrawPixbuf(gc, buf, 0, 0, (int)(scr_rb.X - buf.Width / 2), (int)(scr_rb.Y - buf.Height / 2), buf.Width, buf.Height, Gdk.RgbDither.None, 0, 0); } }
public override void DrawEditor(IBitmapView view) { if (view.Image == null || view.Image.Width == 0 || view.Image.Height == 0) return; Gdk.Drawable target = ((FloatPixmapViewWidget)view).GdkWindow; Gdk.Rectangle image_position = ((FloatPixmapViewWidget)view).CurrentImagePosition; CrotateStageOperationParameters pm = ((CrotateStageOperationParameters)Parameters); Gdk.GC gc = new Gdk.GC(target); // Draw center square dot Point C = new Point(pm.Center.X, pm.Center.Y); int scr_c_x = image_position.X + (int)(image_position.Width * C.X); int scr_c_y = image_position.Y + (int)(image_position.Height * C.Y); // Calculating new picture's real dimensions int trueWidth = image_position.Width, trueHeight = image_position.Height; double w1, h1; w1 = pm.CropWidth * image_position.Width; h1 = pm.CropHeight * image_position.Height; double asp_rat; if (pm.AspectRatioCustom) asp_rat = pm.AspectRatio; else asp_rat = pm.PresetAspectRatioValues[pm.AspectRatioPreset]; switch (pm.Mode) { case CatEye.Core.CrotateStageOperation.Mode.Disproportional: trueWidth = (int)w1; trueHeight = (int)h1; break; case CatEye.Core.CrotateStageOperation.Mode.ProportionalWidthFixed: trueWidth = (int)w1; trueHeight = (int)(w1 / asp_rat); break; case CatEye.Core.CrotateStageOperation.Mode.ProportionalHeightFixed: trueWidth = (int)(h1 * asp_rat); trueHeight = (int)h1; break; } // Calculating new corners positions and "round" dot position double ang = pm.Angle / 180 * Math.PI; CatEye.Core.Point lt_corner = new CatEye.Core.Point( - trueWidth / 2, - trueHeight / 2); lt_corner_rot = CatEye.Core.Point.Rotate(lt_corner, ang, new Point(0, 0)); Gdk.Point scr_lt = new Gdk.Point( (int)(scr_c_x + lt_corner_rot.X), (int)(scr_c_y + lt_corner_rot.Y)); CatEye.Core.Point rt_corner = new CatEye.Core.Point( + trueWidth / 2, - trueHeight / 2); rt_corner_rot = CatEye.Core.Point.Rotate(rt_corner, ang, new Point(0, 0)); Gdk.Point scr_rt = new Gdk.Point( (int)(scr_c_x + rt_corner_rot.X), (int)(scr_c_y + rt_corner_rot.Y)); CatEye.Core.Point rb_corner = new CatEye.Core.Point( + trueWidth / 2, + trueHeight / 2); rb_corner_rot = CatEye.Core.Point.Rotate(rb_corner, ang, new Point(0, 0)); Gdk.Point scr_rb = new Gdk.Point( (int)(scr_c_x + rb_corner_rot.X), (int)(scr_c_y + rb_corner_rot.Y)); CatEye.Core.Point lb_corner = new CatEye.Core.Point( - trueWidth / 2, + trueHeight / 2); lb_corner_rot = CatEye.Core.Point.Rotate(lb_corner, ang, new Point(0, 0)); Gdk.Point scr_lb = new Gdk.Point( (int)(scr_c_x + lb_corner_rot.X), (int)(scr_c_y + lb_corner_rot.Y)); Gdk.Point scr_rnd = new Gdk.Point( (int)(scr_c_x + (rt_corner_rot.X + rb_corner_rot.X) / 2), (int)(scr_c_y + (rt_corner_rot.Y + rb_corner_rot.Y) / 2)); // Drawing frame using (Cairo.Context cc = Gdk.CairoHelper.Create(target)) { cc.LineCap = Cairo.LineCap.Round; cc.LineJoin = Cairo.LineJoin.Round; cc.Color = new Cairo.Color(0, 0, 0, 0.5); cc.LineWidth = 3; cc.MoveTo(scr_lt.X, scr_lt.Y); cc.LineTo(scr_lb.X, scr_lb.Y); cc.LineTo(scr_rb.X, scr_rb.Y); cc.LineTo(scr_rt.X, scr_rt.Y); cc.LineTo(scr_lt.X, scr_lt.Y); cc.ClosePath(); cc.Stroke(); cc.Color = new Cairo.Color(1, 1, 1, 1); cc.LineWidth = 1; cc.SetDash(new double[] {3, 3}, 0); cc.MoveTo(scr_lt.X, scr_lt.Y); cc.LineTo(scr_lb.X, scr_lb.Y); cc.LineTo(scr_rb.X, scr_rb.Y); cc.LineTo(scr_rt.X, scr_rt.Y); cc.LineTo(scr_lt.X, scr_lt.Y); cc.ClosePath(); cc.Stroke(); } // Drawing center "triangle" dot. using (Gdk.Pixbuf buf = Gdk.Pixbuf.LoadFromResource("CatEye.UI.Gtk.Widgets.res.triangle_dot.png")) { target.DrawPixbuf(gc, buf, 0, 0, (int)(scr_c_x - buf.Width / 2), (int)(scr_c_y - buf.Height / 2), buf.Width, buf.Height, Gdk.RgbDither.None, 0, 0); } // Drawing side "round" dot. using (Gdk.Pixbuf buf = Gdk.Pixbuf.LoadFromResource("CatEye.UI.Gtk.Widgets.res.round_dot.png")) { target.DrawPixbuf(gc, buf, 0, 0, (int)(scr_rnd.X - buf.Width / 2), (int)(scr_rnd.Y - buf.Height / 2), buf.Width, buf.Height, Gdk.RgbDither.None, 0, 0); } // Drawing corner "square" dot. using (Gdk.Pixbuf buf = Gdk.Pixbuf.LoadFromResource("CatEye.UI.Gtk.Widgets.res.square_dot.png")) { target.DrawPixbuf(gc, buf, 0, 0, (int)(scr_rb.X - buf.Width / 2), (int)(scr_rb.Y - buf.Height / 2), buf.Width, buf.Height, Gdk.RgbDither.None, 0, 0); } }