예제 #1
0
        private DockNotebookTab FindTabWithCanvas(PintaCanvas canvas)
        {
            foreach (var tab in DockNotebookManager.AllTabs)
            {
                var window      = (SdiWorkspaceWindow)tab.Content;
                var doc_content = (DocumentViewContent)window.ActiveViewContent;

                if (((CanvasWindow)doc_content.Control).Canvas == canvas)
                {
                    return(tab);
                }
            }

            return(null);
        }
예제 #2
0
파일: CanvasWindow.cs 프로젝트: ywscr/Pinta
        public CanvasWindow(Document document) : base(2, 2, false)
        {
            scrolled_window = new ScrolledWindow();

            var vp = new Viewport()
            {
                ShadowType = ShadowType.None
            };

            Canvas = new PintaCanvas(this, document)
            {
                Name       = "canvas",
                CanDefault = true,
                CanFocus   = true,
                Events     = (Gdk.EventMask) 16134
            };

            // Rulers
            horizontal_ruler        = new HRuler();
            horizontal_ruler.Metric = MetricType.Pixels;
            Attach(horizontal_ruler, 1, 2, 0, 1, AttachOptions.Shrink | AttachOptions.Fill, AttachOptions.Shrink | AttachOptions.Fill, 0, 0);

            vertical_ruler        = new VRuler();
            vertical_ruler.Metric = MetricType.Pixels;
            Attach(vertical_ruler, 0, 1, 1, 2, AttachOptions.Shrink | AttachOptions.Fill, AttachOptions.Shrink | AttachOptions.Fill, 0, 0);

            scrolled_window.Hadjustment.ValueChanged += delegate {
                UpdateRulerRange();
            };

            scrolled_window.Vadjustment.ValueChanged += delegate {
                UpdateRulerRange();
            };

            document.Workspace.CanvasSizeChanged += delegate {
                UpdateRulerRange();
            };

            Canvas.MotionNotifyEvent += delegate(object o, MotionNotifyEventArgs args) {
                if (!PintaCore.Workspace.HasOpenDocuments)
                {
                    return;
                }

                var point = PintaCore.Workspace.WindowPointToCanvas(args.Event.X, args.Event.Y);

                horizontal_ruler.Position = point.X;
                vertical_ruler.Position   = point.Y;
            };

            Attach(scrolled_window, 1, 2, 1, 2, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Expand | AttachOptions.Fill, 0, 0);

            scrolled_window.Add(vp);
            vp.Add(Canvas);

            ShowAll();
            Canvas.Show();
            vp.Show();

            horizontal_ruler.Visible = false;
            vertical_ruler.Visible   = false;

            Canvas.SizeAllocated += delegate { UpdateRulerRange(); };
        }
예제 #3
0
파일: CanvasPad.cs 프로젝트: romanzes/Pinta
        public void Initialize(DockFrame workspace, Menu padMenu)
        {
            // Create canvas
            Table mainTable = new Table(2, 2, false);

            sw = new ScrolledWindow()
            {
                Name       = "sw",
                ShadowType = ShadowType.EtchedOut
            };

            Viewport vp = new Viewport()
            {
                ShadowType = ShadowType.None
            };

            canvas = new PintaCanvas()
            {
                Name       = "canvas",
                CanDefault = true,
                CanFocus   = true,
                Events     = (Gdk.EventMask) 16134
            };

            // Canvas pad
            DockItem documentDockItem = workspace.AddItem("Canvas");

            documentDockItem.Behavior = DockItemBehavior.Locked;
            documentDockItem.Expand   = true;

            documentDockItem.DrawFrame = false;
            documentDockItem.Label     = Catalog.GetString("Canvas");
            documentDockItem.Content   = mainTable;
            documentDockItem.Icon      = PintaCore.Resources.GetIcon("Menu.Effects.Artistic.OilPainting.png");

            //rulers
            hruler        = new HRuler();
            hruler.Metric = MetricType.Pixels;
            mainTable.Attach(hruler, 1, 2, 0, 1, AttachOptions.Shrink | AttachOptions.Fill, AttachOptions.Shrink | AttachOptions.Fill, 0, 0);

            vruler        = new VRuler();
            vruler.Metric = MetricType.Pixels;
            mainTable.Attach(vruler, 0, 1, 1, 2, AttachOptions.Shrink | AttachOptions.Fill, AttachOptions.Shrink | AttachOptions.Fill, 0, 0);

            sw.Hadjustment.ValueChanged += delegate {
                UpdateRulerRange();
            };

            sw.Vadjustment.ValueChanged += delegate {
                UpdateRulerRange();
            };

            PintaCore.Workspace.CanvasSizeChanged += delegate {
                UpdateRulerRange();
            };

            canvas.MotionNotifyEvent += delegate(object o, MotionNotifyEventArgs args) {
                if (!PintaCore.Workspace.HasOpenDocuments)
                {
                    return;
                }

                Cairo.PointD point = PintaCore.Workspace.WindowPointToCanvas(args.Event.X, args.Event.Y);

                hruler.Position = point.X;
                vruler.Position = point.Y;
            };

            mainTable.Attach(sw, 1, 2, 1, 2, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Expand | AttachOptions.Fill, 0, 0);

            sw.Add(vp);
            vp.Add(canvas);

            mainTable.ShowAll();
            canvas.Show();
            vp.Show();

            hruler.Visible = false;
            vruler.Visible = false;


            PintaCore.Chrome.InitializeCanvas(canvas);

            canvas.SizeAllocated += delegate { UpdateRulerRange(); };

            PintaCore.Actions.View.Rulers.Toggled        += HandleRulersToggled;
            PintaCore.Actions.View.Pixels.Activated      += (o, e) => { SetRulersUnit(MetricType.Pixels); };
            PintaCore.Actions.View.Inches.Activated      += (o, e) => { SetRulersUnit(MetricType.Inches); };
            PintaCore.Actions.View.Centimeters.Activated += (o, e) => { SetRulersUnit(MetricType.Centimeters); };
        }