Skip to content

Commit

Permalink
Move access to the Canvas to the DocumentWorkspace in preparation for…
Browse files Browse the repository at this point in the history
… a future where there are multiple canvases.
  • Loading branch information
jpobst committed Mar 10, 2015
1 parent 25cee68 commit a7bddac
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Pinta.Core/Actions/ImageActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ static void CropImageToRectangle (Document doc, Gdk.Rectangle rect)
hist.StartSnapshotOfImage();
hist.RestoreSelection = doc.Selection.Clone();

PintaCore.Chrome.Canvas.GdkWindow.FreezeUpdates();
doc.Workspace.Canvas.GdkWindow.FreezeUpdates();

double original_scale = doc.Workspace.Scale;
doc.ImageSize = rect.Size;
Expand All @@ -289,7 +289,7 @@ static void CropImageToRectangle (Document doc, Gdk.Rectangle rect)

PintaCore.Actions.View.UpdateCanvasScale();

PintaCore.Chrome.Canvas.GdkWindow.ThawUpdates();
doc.Workspace.Canvas.GdkWindow.ThawUpdates();

foreach (var layer in doc.UserLayers)
layer.Crop(rect);
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Core/Classes/BaseTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ protected virtual ToggleToolButton CreateToolButton ()

public void SetCursor (Gdk.Cursor cursor)
{
if (PintaCore.Chrome.Canvas != null && PintaCore.Chrome.Canvas.GdkWindow != null)
PintaCore.Chrome.Canvas.GdkWindow.Cursor = cursor;
if (PintaCore.Workspace.HasOpenDocuments)
PintaCore.Workspace.ActiveWorkspace.Canvas.GdkWindow.Cursor = cursor;
}

/// <summary>
Expand Down
20 changes: 12 additions & 8 deletions Pinta.Core/Classes/DocumentWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ internal DocumentWorkspace (Document document)
}

#region Public Properties
public Gtk.DrawingArea Canvas {
get { return PintaCore.Chrome.Canvas; }
}

public bool CanvasFitsInWindow {
get {
Gtk.Viewport view = (Gtk.Viewport)PintaCore.Chrome.Canvas.Parent;
Gtk.Viewport view = (Gtk.Viewport)Canvas.Parent;

int window_x = view.Allocation.Width;
int window_y = view.Children[0].Allocation.Height;
Expand All @@ -76,7 +80,7 @@ public Size CanvasSize {

public bool ImageFitsInWindow {
get {
Gtk.Viewport view = (Gtk.Viewport)PintaCore.Chrome.Canvas.Parent;
Gtk.Viewport view = (Gtk.Viewport)Canvas.Parent;

int window_x = view.Allocation.Width;
int window_y = view.Children[0].Allocation.Height;
Expand All @@ -89,7 +93,7 @@ public bool ImageFitsInWindow {
}

public Cairo.PointD Offset {
get { return new Cairo.PointD ((PintaCore.Chrome.Canvas.Allocation.Width - canvas_size.Width) / 2, (PintaCore.Chrome.Canvas.Allocation.Height - canvas_size.Height) / 2); }
get { return new Cairo.PointD ((Canvas.Allocation.Width - canvas_size.Width) / 2, (Canvas.Allocation.Height - canvas_size.Height) / 2); }
}

public double Scale {
Expand Down Expand Up @@ -169,15 +173,15 @@ public bool PointInCanvas (Cairo.PointD point)

public void RecenterView (double x, double y)
{
Gtk.Viewport view = (Gtk.Viewport)PintaCore.Chrome.Canvas.Parent;
Gtk.Viewport view = (Gtk.Viewport)Canvas.Parent;

view.Hadjustment.Value = Utility.Clamp (x * Scale - view.Hadjustment.PageSize / 2, view.Hadjustment.Lower, view.Hadjustment.Upper);
view.Vadjustment.Value = Utility.Clamp (y * Scale - view.Vadjustment.PageSize / 2, view.Vadjustment.Lower, view.Vadjustment.Upper);
}

public void ScrollCanvas (int dx, int dy)
{
Gtk.Viewport view = (Gtk.Viewport)PintaCore.Chrome.Canvas.Parent;
Gtk.Viewport view = (Gtk.Viewport)Canvas.Parent;

view.Hadjustment.Value = Utility.Clamp (dx + view.Hadjustment.Value, view.Hadjustment.Lower, view.Hadjustment.Upper - view.Hadjustment.PageSize);
view.Vadjustment.Value = Utility.Clamp (dy + view.Vadjustment.Value, view.Vadjustment.Lower, view.Vadjustment.Upper - view.Vadjustment.PageSize);
Expand Down Expand Up @@ -270,10 +274,10 @@ private void ZoomAndRecenterView (ZoomType zoomType, Cairo.PointD point)

zoom = Math.Min (zoom, 3600);

PintaCore.Chrome.Canvas.GdkWindow.FreezeUpdates ();
Canvas.GdkWindow.FreezeUpdates ();
PintaCore.Actions.View.SuspendZoomUpdate ();

Gtk.Viewport view = (Gtk.Viewport)PintaCore.Chrome.Canvas.Parent;
Gtk.Viewport view = (Gtk.Viewport)Canvas.Parent;

bool adjustOnMousePosition = point.X >= 0.0 && point.Y >= 0.0;

Expand Down Expand Up @@ -336,7 +340,7 @@ private void ZoomAndRecenterView (ZoomType zoomType, Cairo.PointD point)
RecenterView (center_x, center_y);

PintaCore.Actions.View.ResumeZoomUpdate ();
PintaCore.Chrome.Canvas.GdkWindow.ThawUpdates ();
Canvas.GdkWindow.ThawUpdates ();
}
#endregion
}
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Core/Managers/ChromeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class ChromeManager

public Toolbar ToolToolBar { get { return tool_toolbar; } }
public Toolbar MainToolBar { get { return main_toolbar; } }
public DrawingArea Canvas { get { return drawing_area; } }
internal DrawingArea Canvas { get { return drawing_area; } }
public Window MainWindow { get { return main_window; } }
public IProgressDialog ProgressDialog { get { return progress_dialog; } }
public MenuBar MainMenu { get { return main_menu; } }
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Core/Managers/LivePreviewManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ private void LivePreview_RenderUpdated (object o, LivePreviewRenderUpdatedEventA
int height = (int)Math.Ceiling (y2) - y;

// Tell GTK to expose the drawing area.
PintaCore.Chrome.Canvas.QueueDrawArea (x, y, width, height);
PintaCore.Workspace.ActiveWorkspace.Canvas.QueueDrawArea (x, y, width, height);
}
}
}
5 changes: 3 additions & 2 deletions Pinta.Tools/Tools/TextTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ protected override void OnBuildToolBar (Gtk.Toolbar tb)

private void HandleFontChanged (object sender, EventArgs e)
{
PintaCore.Chrome.Canvas.GrabFocus ();
if (PintaCore.Workspace.HasOpenDocuments)
PintaCore.Workspace.ActiveDocument.Workspace.Canvas.GrabFocus ();

UpdateFontSizes ();
UpdateFont ();
Expand Down Expand Up @@ -508,7 +509,7 @@ protected override void OnMouseDown(DrawingArea canvas, ButtonPressEventArgs arg
Point pt = point.ToGdkPoint();

// Grab focus so we can get keystrokes
PintaCore.Chrome.Canvas.GrabFocus();
canvas.GrabFocus ();

if (selection != null)
selection.Dispose ();
Expand Down
11 changes: 5 additions & 6 deletions Pinta/Actions/Edit/PasteAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,18 @@ private void Activated (object sender, EventArgs e)
return;
}

var doc = PintaCore.Workspace.ActiveDocument;

// Get the scroll position in canvas co-ordinates
Gtk.Viewport view = (Gtk.Viewport)PintaCore.Chrome.Canvas.Parent;
Cairo.PointD canvasPos = PintaCore.Workspace.ActiveWorkspace.WindowPointToCanvas (
Gtk.Viewport view = (Gtk.Viewport)doc.Workspace.Canvas.Parent;
Cairo.PointD canvasPos = doc.Workspace.WindowPointToCanvas (
view.Hadjustment.Value,
view.Vadjustment.Value);

// Paste into the active document.
// The 'false' argument indicates that paste should be
// performed into the current (not a new) layer.
PintaCore.Workspace.ActiveDocument.Paste (
false,
(int) canvasPos.X,
(int) canvasPos.Y);
doc.Paste (false, (int) canvasPos.X, (int) canvasPos.Y);
}
}
}
11 changes: 5 additions & 6 deletions Pinta/Actions/Edit/PasteIntoNewLayerAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,18 @@ private void Activated (object sender, EventArgs e)
return;
}

var doc = PintaCore.Workspace.ActiveDocument;

// Get the scroll position in canvas co-ordinates
Gtk.Viewport view = (Gtk.Viewport)PintaCore.Chrome.Canvas.Parent;
Cairo.PointD canvasPos = PintaCore.Workspace.ActiveWorkspace.WindowPointToCanvas (
Gtk.Viewport view = (Gtk.Viewport)doc.Workspace.Canvas.Parent;
Cairo.PointD canvasPos = doc.Workspace.WindowPointToCanvas (
view.Hadjustment.Value,
view.Vadjustment.Value);

// Paste into the active document.
// The 'true' argument indicates that paste should be
// performed into a new layer.
PintaCore.Workspace.ActiveDocument.Paste (
true,
(int) canvasPos.X,
(int) canvasPos.Y);
doc.Paste (true, (int) canvasPos.X, (int) canvasPos.Y);
}
}
}

0 comments on commit a7bddac

Please sign in to comment.