public Shell() : base("Mono Heap Profiler") { entries = new ActionEntry[] { new ActionEntry ("FileMenu", null, "_File", null, null, null), new ActionEntry ("OpenAction", Stock.Open, null, "<control>O", "Open a profile...", new EventHandler (OnOpen)), new ActionEntry ("QuitAction", Stock.Quit, null, "<control>Q", "Quit the application", delegate { Application.Quit (); }), }; DefaultSize = new Gdk.Size (700, 700); DeleteEvent += delegate { Application.Quit (); }; main_box = new VBox (false, 0); Add (main_box); shell_commands = new ActionGroup ("TestActions"); shell_commands.Add (entries); uim = new UIManager (); uim.AddWidget += delegate (object obj, AddWidgetArgs args) { args.Widget.Show (); main_box.PackStart (args.Widget, false, true, 0); }; uim.ConnectProxy += OnProxyConnect; uim.InsertActionGroup (shell_commands, 0); uim.AddUiFromResource ("shell-ui.xml"); AddAccelGroup (uim.AccelGroup); sb = new Statusbar (); main_box.PackEnd (sb, false, true, 0); pager = new ShellPager (this); main_box.PackEnd (pager, true, true, 0); }
public override void Undo () { // maintain the current scaling setting after the operation double scale = PintaCore.Workspace.Scale; Size swap = PintaCore.Workspace.ImageSize; PintaCore.Workspace.ImageSize = old_size; PintaCore.Workspace.CanvasSize = old_size; old_size = swap; base.Undo (); if (RestoreSelection != null) { DocumentSelection old = PintaCore.Workspace.ActiveDocument.Selection; PintaCore.Workspace.ActiveDocument.Selection = RestoreSelection.Clone(); if (old != null) { old.Dispose (); } PintaCore.Layers.ShowSelection = true; } else { PintaCore.Layers.ResetSelectionPath (); } PintaCore.Workspace.Invalidate (); PintaCore.Workspace.Scale = scale; }
public ResizeHistoryItem (Size oldSize) : base () { old_size = oldSize; Icon = "Menu.Image.Resize.png"; Text = Catalog.GetString ("Resize Image"); }
public void Import(string fileName) { Pixbuf bg; // Handle any EXIF orientation flags using (var fs = new FileStream (fileName, FileMode.Open, FileAccess.Read)) bg = new Pixbuf (fs); bg = bg.ApplyEmbeddedOrientation (); Size imagesize = new Size (bg.Width, bg.Height); Document doc = PintaCore.Workspace.CreateAndActivateDocument (fileName, imagesize); doc.HasFile = true; doc.ImageSize = imagesize; doc.Workspace.CanvasSize = imagesize; Layer layer = doc.AddNewLayer (Path.GetFileName (fileName)); using (Cairo.Context g = new Cairo.Context (layer.Surface)) { CairoHelper.SetSourcePixbuf (g, bg, 0, 0); g.Paint (); } bg.Dispose (); }
/// <summary> /// Enmarca una imagen. /// </summary> /// <param name="image"> /// La imagen a enmarcar. /// </param> /// <param name="pos"> /// La esquina de la zona a recortar. /// </param> /// <param name="size"> /// El tamaño de la zona a recortar. /// </param> protected void GetEdges(FloatBitmap image, out Point pos, out Size size) { pos = new Point(0,0); size = new Size(image.Width, image.Height); bool found =false; for(int i = 0; i < image.Width && !found; i++) { for(int j = 0; j < image.Height && !found; j++) { if (image[i, j] != FloatBitmap.White) { pos.X = i-1; found = true; } } } found =false; for(int i = image.Width-1; i >=0 && !found; i--) { for(int j = 0; j < image.Height && !found; j++) { if (image[i, j] != FloatBitmap.White) { size.Width = i - pos.X +2 ; found = true; } } } found =false; for(int j = 0; j < image.Height && !found; j++) { for(int i = 0; i < image.Width&& !found; i++) { if (image[i, j] != FloatBitmap.White) { pos.Y = j-1; found = true; } } } found =false; for(int j = image.Height-1; j >=0 && !found; j--) { for(int i = 0; i < image.Width && !found; i++) { if (image[i, j] != FloatBitmap.White) { size.Height = j - pos.Y +2; found = true; } } } }
public override void ApplyTransform (Matrix xform, Size new_size) { base.ApplyTransform (xform, new_size); foreach (ReEditableLayer rel in ReEditableLayers) { if (rel.IsLayerSetup) rel.Layer.ApplyTransform (xform, new_size); } }
public ImageWidget(Pixbuf pixbuf) { resizingX = resizingY = false; this.CanFocus = true; this.Events = EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.PointerMotionMask; this.child = new Gtk.Image (); this.child.Pixbuf = pixbuf; originalPixbuf = pixbuf; Add (child); imageSize = child.Allocation.Size; }
public void Initialize(Size sourceSize, Size destinationSize) { if (sourceSize == source_size && destinationSize == destination_size) return; source_size = sourceSize; destination_size = destinationSize; scale_factor = new ScaleFactor (source_size.Width, destination_size.Width); generated = false; }
private void Init() { Events = EventMask.PointerMotionMask | EventMask.ButtonPressMask | EventMask.ButtonReleaseMask; _imContext = new Gtk.IMMulticontext(); _imContext.Commit += ImContext_Commit; DoubleBuffered = false; Realize(); _lastClientSize = ClientSize; }
public void Rotate (double angle, Size new_size) { double radians = (angle / 180d) * Math.PI; var old_size = PintaCore.Workspace.ImageSize; var xform = new Matrix (); xform.Translate (new_size.Width / 2.0, new_size.Height / 2.0); xform.Rotate (radians); xform.Translate (-old_size.Width / 2.0, -old_size.Height / 2.0); ApplyTransform (xform, new_size); }
private void OnMeasure() { if (!measure_pending) { return; } measure_pending = false; header_height = 0; child_size = OnMeasureChild(); UpdateAdjustments(); }
void HandleBarFrameSizeAllocated(object o, SizeAllocatedArgs args) { if (!lastFrameSize.Equals(args.Allocation.Size)) { lastFrameSize = args.Allocation.Size; if (autoShowFrame != null) { bar.Frame.UpdateSize(bar, autoShowFrame); } UnscheduleAutoHide(); AutoHide(false); } }
public NewFileDialog(Gtk.Window parentWindow, string parentDir, Gdk.Size size) { this.DefaultSize = size; this.parentDir = parentDir; this.Build(); this.btnNew.Name = "MainButton"; this.btnNew.GrabDefault(); this.entry_FileName.ActivatesDefault = true; this.SetToDialogStyle(parentWindow, true, true, true); this.InitiaFileType(); this.InitiaEvent(); this.InitShow(); this.InitPlatform(); this.InitLanguages(); }
public Document(Gdk.Size size) { Selection = new DocumentSelection(); Guid = Guid.NewGuid(); Layers = new DocumentLayers(this); Workspace = new DocumentWorkspace(this); IsDirty = false; HasFile = false; HasBeenSavedInSession = false; ImageSize = size; ResetSelectionPaths(); }
/// <summary> /// Provides a default implementation for performing dst = F(lhs, rhs) over some rectangle of interest. /// </summary> /// <param name="dst">The Surface to write pixels to.</param> /// <param name="dstOffset">The pixel offset that defines the upper-left of the rectangle-of-interest for the dst Surface.</param> /// <param name="lhs">The Surface to read pixels from for the lhs parameter given to the method <b>ColorBgra Apply(ColorBgra, ColorBgra)</b>.</param> /// <param name="lhsOffset">The pixel offset that defines the upper-left of the rectangle-of-interest for the lhs Surface.</param> /// <param name="rhs">The Surface to read pixels from for the rhs parameter given to the method <b>ColorBgra Apply(ColorBgra, ColorBgra)</b></param> /// <param name="rhsOffset">The pixel offset that defines the upper-left of the rectangle-of-interest for the rhs Surface.</param> /// <param name="roiSize">The size of the rectangles-of-interest for all Surfaces.</param> public void Apply (Cairo.ImageSurface dst, Point dstOffset, Cairo.ImageSurface lhs, Point lhsOffset, Cairo.ImageSurface rhs, Point rhsOffset, Size roiSize) { // Bounds checking only enabled in Debug builds. #if DEBUG // Create bounding rectangles for each Surface Rectangle dstRect = new Rectangle (dstOffset, roiSize); Rectangle lhsRect = new Rectangle (lhsOffset, roiSize); Rectangle rhsRect = new Rectangle (rhsOffset, roiSize); // Clip those rectangles to those Surface's bounding rectangles Rectangle dstClip = Rectangle.Intersect (dstRect, dst.GetBounds ()); Rectangle lhsClip = Rectangle.Intersect (lhsRect, lhs.GetBounds ()); Rectangle rhsClip = Rectangle.Intersect (rhsRect, rhs.GetBounds ()); // If any of those Rectangles actually got clipped, then throw an exception if (dstRect != dstClip) { throw new ArgumentOutOfRangeException ("roiSize", "Destination roi out of bounds"); } if (lhsRect != lhsClip) { throw new ArgumentOutOfRangeException ("roiSize", "lhs roi out of bounds"); } if (rhsRect != rhsClip) { throw new ArgumentOutOfRangeException ("roiSize", "rhs roi out of bounds"); } #endif // Cache the width and height properties int width = roiSize.Width; int height = roiSize.Height; // Do the work. unsafe { for (int row = 0; row < height; ++row) { ColorBgra* dstPtr = dst.GetPointAddress (dstOffset.X, dstOffset.Y + row); ColorBgra* lhsPtr = lhs.GetPointAddress (lhsOffset.X, lhsOffset.Y + row); ColorBgra* rhsPtr = rhs.GetPointAddress (rhsOffset.X, rhsOffset.Y + row); Apply (dstPtr, lhsPtr, rhsPtr, width); } } }
public Browser(string catalog_dir) : base("Documentation Browser Sample") { DefaultSize = new Size (600, 400); Gtk.Paned paned = new Gtk.HPaned (); Gtk.ScrolledWindow sw = new ScrolledWindow (); DocTree tree = new DocTree (catalog_dir); sw.Add (tree); paned.Add1 (sw); sw = new ScrolledWindow (); DocView view = new DocView (tree); sw.AddWithViewport (view); paned.Add2 (sw); paned.Position = 250; paned.ShowAll (); Add (paned); }
private void CanvasSizeChangeEventHandle(CanvasSizeChangeEventArgs args) { this.sceneSize = args.NewSize; Project currentSelectedProject = Services.ProjectOperations.CurrentSelectedProject; if (currentSelectedProject == null || !(currentSelectedProject.GetProjectType() != NodeType.Node.ToString())) { return; } Gdk.Size newSize = args.NewSize; double width = (double)newSize.Width; newSize = args.NewSize; double height = (double)newSize.Height; this.Size = new PointF((float)width, (float)height); }
internal AutoHideBox AutoShow(DockItem item, DockBar bar, int size) { AutoHideBox aframe = new AutoHideBox(this, item, bar.Position, size); Gdk.Size sTop = GetBarFrameSize(dockBarTop); Gdk.Size sBot = GetBarFrameSize(dockBarBottom); Gdk.Size sLeft = GetBarFrameSize(dockBarLeft); Gdk.Size sRgt = GetBarFrameSize(dockBarRight); int x, y, w, h; if (bar == dockBarLeft || bar == dockBarRight) { h = Allocation.Height - sTop.Height - sBot.Height; w = size; y = sTop.Height; if (bar == dockBarLeft) { x = sLeft.Width; } else { x = Allocation.Width - size - sRgt.Width; } } else { w = Allocation.Width - sLeft.Width - sRgt.Width; h = size; x = sLeft.Width; if (bar == dockBarTop) { y = sTop.Height; } else { y = Allocation.Height - size - sBot.Height; } } AddTopLevel(aframe, x, y, w, h); aframe.AnimateShow(); return(aframe); }
private bool OnMeasure() { if (!measure_pending) { return(false); } measure_pending = false; header_height = 0; var old_child_size = child_size; child_size = OnMeasureChild(); UpdateAdjustments(); return(old_child_size != child_size); }
public override void Redo() { // maintain the current scaling setting after the operation double scale = PintaCore.Workspace.Scale; Size swap = PintaCore.Workspace.ImageSize; PintaCore.Workspace.ImageSize = old_size; PintaCore.Workspace.CanvasSize = old_size; old_size = swap; base.Redo (); PintaCore.Layers.ResetSelectionPath (); PintaCore.Workspace.Invalidate (); PintaCore.Workspace.Scale = scale; }
public Document(Gdk.Size size) { Guid = Guid.NewGuid(); Workspace = new DocumentWorkspace(this); IsDirty = false; HasFile = false; ImageSize = size; Layers = new List <Layer> (); tool_layer = CreateLayer("Tool Layer"); tool_layer.Hidden = true; selection_layer = CreateLayer("Selection Layer"); selection_layer.Hidden = true; ResetSelectionPath(); }
public void Import(LayerManager layers, string fileName) { Pixbuf bg = new Pixbuf (fileName); Size imagesize = new Size (bg.Width, bg.Height); PintaCore.Workspace.CreateAndActivateDocument (fileName, imagesize); PintaCore.Workspace.ActiveDocument.HasFile = true; PintaCore.Workspace.ActiveDocument.ImageSize = imagesize; PintaCore.Workspace.ActiveWorkspace.CanvasSize = imagesize; Layer layer = layers.AddNewLayer (Path.GetFileName (fileName)); using (Cairo.Context g = new Cairo.Context (layer.Surface)) { CairoHelper.SetSourcePixbuf (g, bg, 0, 0); g.Paint (); } bg.Dispose (); }
/// <summary> /// Initializes a new instance of the <see cref="ConfiguratorDialog"/> class. /// </summary> /// <param name="treeStore">The tree store.</param> /// <param name="dialogTitle">The dialog title.</param> /// <param name="parentWindow">The parent window.</param> /// <param name="flags">The flags.</param> /// <param name="buttonData">The button data.</param> public ConfiguratorDialog( TreeStore treeStore, string dialogTitle = "Configuration", Window parentWindow = null, DialogFlags flags = DialogFlags.DestroyWithParent, params object[] buttonData) : base(dialogTitle, parentWindow, flags, buttonData) { // Save the various parameters as member variables. if (treeStore == null) { throw new ArgumentNullException("treeStore"); } // Set up the widget. InitializeWidget(treeStore); // Set up the default DefaultSize = new Size(400, 250); }
void OnConfigureEvent(object o, Gtk.ConfigureEventArgs args) { var evnt = args.Event; args.RetVal = true; var newSize = new Size(evnt.Width, evnt.Height); if (newSize != _lastClientSize) { Resized(newSize); _lastClientSize = newSize; } var newPosition = new Point(evnt.X, evnt.Y); if (newPosition != _lastPosition) { PositionChanged(newPosition); _lastPosition = newPosition; } }
/// <summary> /// Resizes the canvas. /// </summary> /// <param name='compoundAction'> /// Optionally, the history item for resizing the canvas can be added to /// a CompoundHistoryItem if it is part of a larger action (e.g. pasting an image). /// </param> public void ResizeCanvas(int width, int height, Anchor anchor, CompoundHistoryItem compoundAction) { double scale; if (ImageSize.Width == width && ImageSize.Height == height) { return; } PintaCore.Tools.Commit(); ResizeHistoryItem hist = new ResizeHistoryItem(ImageSize); hist.Icon = "Menu.Image.CanvasSize.png"; hist.Text = Catalog.GetString("Resize Canvas"); hist.StartSnapshotOfImage(); scale = Workspace.Scale; ImageSize = new Gdk.Size(width, height); foreach (var layer in UserLayers) { layer.ResizeCanvas(width, height, anchor); } hist.FinishSnapshotOfImage(); if (compoundAction != null) { compoundAction.Push(hist); } else { Workspace.History.PushNewItem(hist); } ResetSelectionPath(); Workspace.Scale = scale; }
public DockBarItem(DockBar bar, DockItem it, int size) { var actionHandler = new ActionDelegate(this); actionHandler.PerformPress += OnPerformPress; Events = Events | Gdk.EventMask.EnterNotifyMask | Gdk.EventMask.LeaveNotifyMask; this.size = size; this.bar = bar; this.it = it; CanFocus = true; VisibleWindow = false; UpdateTab(); lastFrameSize = bar.Frame.Allocation.Size; bar.Frame.SizeAllocated += HandleBarFrameSizeAllocated; tracker = new MouseTracker(this); tracker.TrackMotion = false; tracker.HoveredChanged += (sender, e) => { if (crossfade == null) { return; } AnimateHover(tracker.Hovered); if (tracker.Hovered) { crossfade.ShowSecondary(); } else { crossfade.ShowPrimary(); } }; Styles.Changed += UpdateStyle; Accessible.Name = "DockbarItem"; Accessible.Role = Atk.Role.PushButton; }
public Window (ComparisonInfo info) : base ("ilContrast Assembly Comparison Tool") { DefaultSize = new Size (450, 450); main_vbox = new VBox (false, 0); AddActionUI (); #if USE_GECKO browser = new Gecko.WebControl (); main_vbox.PackStart (browser, true, true, 0); #else web_view = new WebKit.WebView (); ScrolledWindow sw = new ScrolledWindow (); sw.Add (web_view); main_vbox.PackStart (sw, true, true, 0); #endif statusbar = new Statusbar (); main_vbox.PackStart (statusbar, false, false, 0); Add (main_vbox); main_vbox.ShowAll (); first_show = true; this.info = info; }
public Document(Gdk.Size size) { Selection = new DocumentSelection(); Guid = Guid.NewGuid(); Workspace = new DocumentWorkspace(this); IsDirty = false; HasFile = false; HasBeenSavedInSession = false; ImageSize = size; UserLayers = new List <UserLayer>(); tool_layer = CreateLayer("Tool Layer"); tool_layer.Hidden = true; selection_layer = CreateLayer("Selection Layer"); selection_layer.Hidden = true; ResetSelectionPaths(); }
public void AnimatedResize() { if (!GtkUtil.ScreenSupportsARGB()) { QueueResize(); return; } disableSizeCheck = true; Gtk.Requisition sizeReq = Gtk.Requisition.Zero; // use OnSizeRequested instead of SizeRequest to bypass internal GTK caching OnSizeRequested(ref sizeReq); disableSizeCheck = false; Gdk.Size size = new Gdk.Size(sizeReq.Width, sizeReq.Height); // ensure that our apint area is big enough for our padding if (paintSize.Width <= 15 || paintSize.Height <= 15) { paintSize = size; } targetSize = size; Gdk.Size start = paintSize; Func <double, Gdk.Size> transform = x => new Gdk.Size((int)(start.Width + (size.Width - start.Width) * x), (int)(start.Height + (size.Height - start.Height) * x)); this.Animate("Resize", transform, s => paintSize = s, length: 150, easing: Easing.SinInOut, finished: (x, aborted) => { if (!aborted) { MaybeReanimate(); } }); QueueResize(); }
internal void UpdateSize(DockBar bar, AutoHideBox aframe) { Gdk.Size sTop = GetBarFrameSize(dockBarTop); Gdk.Size sBot = GetBarFrameSize(dockBarBottom); Gdk.Size sLeft = GetBarFrameSize(dockBarLeft); Gdk.Size sRgt = GetBarFrameSize(dockBarRight); if (bar == dockBarLeft || bar == dockBarRight) { aframe.HeightRequest = Allocation.Height - sTop.Height - sBot.Height; if (bar == dockBarRight) { aframe.X = Allocation.Width - aframe.Allocation.Width - sRgt.Width; } } else { aframe.WidthRequest = Allocation.Width - sLeft.Width - sRgt.Width; if (bar == dockBarBottom) { aframe.Y = Allocation.Height - aframe.Allocation.Height - sBot.Height; } } }
internal void UpdatePlaceholder(DockItem item, Gdk.Size size, bool allowDocking) { container.UpdatePlaceholder(item, size, allowDocking); }
public WindowImpl() : base(Gtk.WindowType.Toplevel) { DefaultSize = new Gdk.Size(900, 480); Init(); }
public virtual void ApplyTransform(Matrix xform, Size new_size) { var old_size = PintaCore.Workspace.ImageSize; var dest = new ImageSurface (Format.ARGB32, new_size.Width, new_size.Height); using (var g = new Context (dest)) { g.Transform (xform); g.SetSource (Surface); g.Paint (); } Surface old = Surface; Surface = dest; old.Dispose (); }
private unsafe void RenderZoomOut(Cairo.ImageSurface src, Cairo.ImageSurface dst, Gdk.Point offset, Gdk.Size destinationSize, bool checker) { const int fpShift = 12; const int fpFactor = (1 << fpShift); Gdk.Size sourceSize = src.GetBounds().Size; long fDstLeftLong = ((long)offset.X * fpFactor * (long)sourceSize.Width) / (long)destinationSize.Width; long fDstTopLong = ((long)offset.Y * fpFactor * (long)sourceSize.Height) / (long)destinationSize.Height; long fDstRightLong = ((long)(offset.X + dst.Width) * fpFactor * (long)sourceSize.Width) / (long)destinationSize.Width; long fDstBottomLong = ((long)(offset.Y + dst.Height) * fpFactor * (long)sourceSize.Height) / (long)destinationSize.Height; int fDstLeft = (int)fDstLeftLong; int fDstTop = (int)fDstTopLong; int fDstRight = (int)fDstRightLong; int fDstBottom = (int)fDstBottomLong; int dx = (fDstRight - fDstLeft) / dst.Width; int dy = (fDstBottom - fDstTop) / dst.Height; ColorBgra *src_ptr = (ColorBgra *)src.DataPtr; ColorBgra *dst_ptr = (ColorBgra *)dst.DataPtr; int src_width = src.Width; int dst_width = dst.Width; for (int dstRow = 0, fDstY = fDstTop; dstRow < dst.Height && fDstY < fDstBottom; ++dstRow, fDstY += dy) { int srcY1 = fDstY >> fpShift; // y int srcY2 = (fDstY + (dy >> 2)) >> fpShift; // y + 0.25 int srcY3 = (fDstY + (dy >> 1)) >> fpShift; // y + 0.50 int srcY4 = (fDstY + (dy >> 1) + (dy >> 2)) >> fpShift; // y + 0.75 ColorBgra *src1 = src.GetRowAddressUnchecked(src_ptr, src_width, srcY1); ColorBgra *src2 = src.GetRowAddressUnchecked(src_ptr, src_width, srcY2); ColorBgra *src3 = src.GetRowAddressUnchecked(src_ptr, src_width, srcY3); ColorBgra *src4 = src.GetRowAddressUnchecked(src_ptr, src_width, srcY4); ColorBgra *dstPtr = dst.GetRowAddressUnchecked(dst_ptr, dst_width, dstRow); int checkerY = dstRow + offset.Y; int checkerX = offset.X; int maxCheckerX = checkerX + dst.Width; for (int fDstX = fDstLeft; checkerX < maxCheckerX && fDstX < fDstRight; ++checkerX, fDstX += dx) { int srcX1 = (fDstX + (dx >> 2)) >> fpShift; // x + 0.25 int srcX2 = (fDstX + (dx >> 1) + (dx >> 2)) >> fpShift; // x + 0.75 int srcX3 = fDstX >> fpShift; // x int srcX4 = (fDstX + (dx >> 1)) >> fpShift; // x + 0.50 ColorBgra *p1 = src1 + srcX1; ColorBgra *p2 = src2 + srcX2; ColorBgra *p3 = src3 + srcX3; ColorBgra *p4 = src4 + srcX4; int r = (2 + p1->R + p2->R + p3->R + p4->R) >> 2; int g = (2 + p1->G + p2->G + p3->G + p4->G) >> 2; int b = (2 + p1->B + p2->B + p3->B + p4->B) >> 2; int a = (2 + p1->A + p2->A + p3->A + p4->A) >> 2; if (checker) { // Blend it over the checkerboard background int v = ((checkerX ^ checkerY) & 8) * 8 + 191; a = a + (a >> 7); int vmia = v * (256 - a); r = ((r * a) + vmia) >> 8; g = ((g * a) + vmia) >> 8; b = ((b * a) + vmia) >> 8; dstPtr->Bgra = (uint)b + ((uint)g << 8) + ((uint)r << 16) + 0xff000000; } else { dstPtr->Bgra = (uint)b + ((uint)g << 8) + ((uint)r << 16) + ((uint)a << 24); } ++dstPtr; } } }
public static void CachedDraw(this Cairo.Context self, ref SurfaceWrapper surface, Gdk.Point position, Gdk.Size size, object parameters = null, float opacity = 1.0f, Action <Cairo.Context, float> draw = null, double?forceScale = null) { self.CachedDraw(ref surface, new Gdk.Rectangle(position, size), parameters, opacity, draw, forceScale); }
public void DrawDrawable( Gdk.GC gc, Drawable src, Point src_location, Point dest_location, Size sz ) { this.DrawDrawable( gc, src, src_location.X, src_location.Y, dest_location.X, dest_location.Y, sz.Width, sz.Height ); }
public void AnimatedResize () { if (!GtkUtil.ScreenSupportsARGB ()) { QueueResize(); return; } disableSizeCheck = true; Gtk.Requisition sizeReq = Gtk.Requisition.Zero; // use OnSizeRequested instead of SizeRequest to bypass internal GTK caching OnSizeRequested (ref sizeReq); disableSizeCheck = false; Gdk.Size size = new Gdk.Size (sizeReq.Width, sizeReq.Height); // ensure that our apint area is big enough for our padding if (paintSize.Width <= 15 || paintSize.Height <= 15) paintSize = size; targetSize = size; Gdk.Size start = paintSize; Func<double, Gdk.Size> transform = x => new Gdk.Size ((int)(start.Width + (size.Width - start.Width) * x), (int)(start.Height + (size.Height - start.Height) * x)); this.Animate ("Resize", transform, s => paintSize = s, length: 150, easing: Easing.SinInOut, finished: (x, aborted) => { if (!aborted) MaybeReanimate(); }); QueueResize (); }
public void ClearCategories() { categories.Clear(); iconSize = new Gdk.Size(24, 24); }
public Rectangle(Point loc, Size sz) : this(loc.X, loc.Y, sz.Width, sz.Height) { }
public override void Undo() { Size swap = PintaCore.Workspace.ImageSize; PintaCore.Workspace.ImageSize = old_size; PintaCore.Workspace.CanvasSize = old_size; old_size = swap; base.Undo (); if (RestorePath != null) { Cairo.Path old = PintaCore.Layers.SelectionPath; PintaCore.Layers.SelectionPath = RestorePath.Clone (); if (old != null) (old as IDisposable).Dispose (); PintaCore.Layers.ShowSelection = true; } else { PintaCore.Layers.ResetSelectionPath (); } PintaCore.Workspace.Invalidate (); }
public override void Redo() { Size swap = PintaCore.Workspace.ImageSize; PintaCore.Workspace.ImageSize = old_size; PintaCore.Workspace.CanvasSize = old_size; old_size = swap; base.Redo (); PintaCore.Layers.ResetSelectionPath (); PintaCore.Workspace.Invalidate (); }
protected override void OnSizeAllocated (Rectangle allocation) { if (!this.AnimationIsRunning ("Resize")) paintSize = new Gdk.Size (allocation.Width, allocation.Height); base.OnSizeAllocated (allocation); }
public void DrawArc( Gdk.GC gc, bool filled, Point p, Size s, int angle1, int angle2 ) { Rectangle rect = new Rectangle( p, s ); this.DrawArc( gc, filled, rect.X, rect.Y, rect.Width, rect.Height, angle1, angle2 ); }
public void Import(string fileName) { ZipFile file = new ZipFile (fileName); XmlDocument stackXml = new XmlDocument (); stackXml.Load (file.GetInputStream (file.GetEntry ("stack.xml"))); XmlElement imageElement = stackXml.DocumentElement; int width = int.Parse (imageElement.GetAttribute ("w")); int height = int.Parse (imageElement.GetAttribute ("h")); Size imagesize = new Size (width, height); Document doc = PintaCore.Workspace.CreateAndActivateDocument (fileName, imagesize); doc.HasFile = true; XmlElement stackElement = (XmlElement) stackXml.GetElementsByTagName ("stack")[0]; XmlNodeList layerElements = stackElement.GetElementsByTagName ("layer"); if (layerElements.Count == 0) throw new XmlException ("No layers found in OpenRaster file"); doc.ImageSize = imagesize; doc.Workspace.CanvasSize = imagesize; for (int i = 0; i < layerElements.Count; i++) { XmlElement layerElement = (XmlElement) layerElements[i]; int x = int.Parse (GetAttribute (layerElement, "x", "0")); int y = int.Parse (GetAttribute (layerElement, "y", "0")); string name = GetAttribute (layerElement, "name", string.Format ("Layer {0}", i)); try { // Write the file to a temporary file first // Fixes a bug when running on .Net ZipEntry zf = file.GetEntry (layerElement.GetAttribute ("src")); Stream s = file.GetInputStream (zf); string tmp_file = System.IO.Path.GetTempFileName (); using (Stream stream_out = File.Open (tmp_file, FileMode.OpenOrCreate)) { byte[] buffer = new byte[2048]; while (true) { int len = s.Read (buffer, 0, buffer.Length); if (len > 0) stream_out.Write (buffer, 0, len); else break; } } UserLayer layer = doc.CreateLayer(name); doc.Insert (layer, 0); layer.Opacity = double.Parse (GetAttribute (layerElement, "opacity", "1"), GetFormat ()); layer.BlendMode = StandardToBlendMode (GetAttribute (layerElement, "composite-op", "svg:src-over")); using (var fs = new FileStream (tmp_file, FileMode.Open)) using (Pixbuf pb = new Pixbuf (fs)) { using (Context g = new Context (layer.Surface)) { CairoHelper.SetSourcePixbuf (g, pb, x, y); g.Paint (); } } try { File.Delete (tmp_file); } catch { } } catch { MessageDialog md = new MessageDialog (PintaCore.Chrome.MainWindow, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Could not import layer \"{0}\" from {0}", name, file); md.Title = "Error"; md.Run (); md.Destroy (); } } file.Close (); }
private void SetRequisition(Size size) { Requisition req = new Requisition (); req.Width = size.Width; req.Height = size.Height; Requisition = req; QueueResize (); }
private unsafe void RenderZoomOut(List <Layer> layers, Cairo.ImageSurface dst, Gdk.Point offset, Gdk.Size destinationSize) { // The first layer should be blended with the transparent checkerboard var checker = true; CheckerBoardOperation checker_op = null; for (int i = 0; i < layers.Count; i++) { var layer = layers[i]; // If we're in LivePreview, substitute current layer with the preview layer if (layer == PintaCore.Layers.CurrentLayer && PintaCore.LivePreview.IsEnabled) { layer = CreateLivePreviewLayer(layer); } // If the layer is offset, handle it here if (!layer.Offset.IsEmpty()) { layer = CreateOffsetLayer(layer); } var src = layer.Surface; // Get the blend mode for this layer and opacity var blend_op = UserBlendOps.GetBlendOp(layer.BlendMode, layer.Opacity); if (checker) { checker_op = new CheckerBoardOperation(layer.Opacity); } const int fpShift = 12; const int fpFactor = (1 << fpShift); Gdk.Size sourceSize = src.GetBounds().Size; long fDstLeftLong = ((long)offset.X * fpFactor * (long)sourceSize.Width) / (long)destinationSize.Width; long fDstTopLong = ((long)offset.Y * fpFactor * (long)sourceSize.Height) / (long)destinationSize.Height; long fDstRightLong = ((long)(offset.X + dst.Width) * fpFactor * (long)sourceSize.Width) / (long)destinationSize.Width; long fDstBottomLong = ((long)(offset.Y + dst.Height) * fpFactor * (long)sourceSize.Height) / (long)destinationSize.Height; int fDstLeft = (int)fDstLeftLong; int fDstTop = (int)fDstTopLong; int fDstRight = (int)fDstRightLong; int fDstBottom = (int)fDstBottomLong; int dx = (fDstRight - fDstLeft) / dst.Width; int dy = (fDstBottom - fDstTop) / dst.Height; ColorBgra *src_ptr = (ColorBgra *)src.DataPtr; ColorBgra *dst_ptr = (ColorBgra *)dst.DataPtr; int src_width = src.Width; int dst_width = dst.Width; for (int dstRow = 0, fDstY = fDstTop; dstRow < dst.Height && fDstY < fDstBottom; ++dstRow, fDstY += dy) { int srcY1 = fDstY >> fpShift; // y int srcY2 = (fDstY + (dy >> 2)) >> fpShift; // y + 0.25 int srcY3 = (fDstY + (dy >> 1)) >> fpShift; // y + 0.50 int srcY4 = (fDstY + (dy >> 1) + (dy >> 2)) >> fpShift; // y + 0.75 ColorBgra *src1 = src.GetRowAddressUnchecked(src_ptr, src_width, srcY1); ColorBgra *src2 = src.GetRowAddressUnchecked(src_ptr, src_width, srcY2); ColorBgra *src3 = src.GetRowAddressUnchecked(src_ptr, src_width, srcY3); ColorBgra *src4 = src.GetRowAddressUnchecked(src_ptr, src_width, srcY4); ColorBgra *dstPtr = dst.GetRowAddressUnchecked(dst_ptr, dst_width, dstRow); int checkerY = dstRow + offset.Y; int checkerX = offset.X; int maxCheckerX = checkerX + dst.Width; for (int fDstX = fDstLeft; checkerX < maxCheckerX && fDstX < fDstRight; ++checkerX, fDstX += dx) { int srcX1 = (fDstX + (dx >> 2)) >> fpShift; // x + 0.25 int srcX2 = (fDstX + (dx >> 1) + (dx >> 2)) >> fpShift; // x + 0.75 int srcX3 = fDstX >> fpShift; // x int srcX4 = (fDstX + (dx >> 1)) >> fpShift; // x + 0.50 ColorBgra *p1 = src1 + srcX1; ColorBgra *p2 = src2 + srcX2; ColorBgra *p3 = src3 + srcX3; ColorBgra *p4 = src4 + srcX4; int r = (2 + p1->R + p2->R + p3->R + p4->R) >> 2; int g = (2 + p1->G + p2->G + p3->G + p4->G) >> 2; int b = (2 + p1->B + p2->B + p3->B + p4->B) >> 2; int a = (2 + p1->A + p2->A + p3->A + p4->A) >> 2; // Blend it over the checkerboard background if (checker) { *dstPtr = checker_op.Apply(ColorBgra.FromUInt32((uint)b + ((uint)g << 8) + ((uint)r << 16) + ((uint)a << 24)), checkerX, checkerY); } else { *dstPtr = blend_op.Apply(*dstPtr, ColorBgra.FromUInt32((uint)b + ((uint)g << 8) + ((uint)r << 16) + ((uint)a << 24))); } ++dstPtr; } } // Only checker the first layer checker = false; } }
internal bool UpdatePlaceholder(DockItem item, Gdk.Size size, bool allowDocking) { if (!Runtime.IsMainThread) { var msg = "UpdatePlaceholder called from background thread."; LoggingService.LogInternalError($"{msg}\n{Environment.StackTrace}", new InvalidOperationException(msg)); } var placeholderWindow = this.placeholderWindow; var padTitleWindow = this.padTitleWindow; if (placeholderWindow == null || padTitleWindow == null) { return(false); } int px, py; GetPointer(out px, out py); placeholderWindow.AllowDocking = allowDocking; int ox, oy; GdkWindow.GetOrigin(out ox, out oy); int tw, th; padTitleWindow.GetSize(out tw, out th); padTitleWindow.Move(ox + px - tw / 2, oy + py - th / 2); padTitleWindow.GdkWindow.KeepAbove = true; DockDelegate dockDelegate; Gdk.Rectangle rect; if (allowDocking && layout.GetDockTarget(item, px, py, out dockDelegate, out rect)) { placeholderWindow.Relocate(ox + rect.X, oy + rect.Y, rect.Width, rect.Height, true); placeholderWindow.Show(); placeholderWindow.SetDockInfo(dockDelegate, rect); return(true); } else { int w, h; var gi = layout.FindDockGroupItem(item.Id); if (gi != null) { w = gi.Allocation.Width; h = gi.Allocation.Height; } else { w = item.DefaultWidth; h = item.DefaultHeight; } placeholderWindow.Relocate(ox + px - w / 2, oy + py - h / 2, w, h, false); placeholderWindow.Show(); placeholderWindow.AllowDocking = false; } return(false); }
private void ComputeVirtualSize() { if (TotalPages == 0) { VirtualSize = ControlSize; } else { Gdk.Size visibleSize = ControlSize; // Invalid values may cause invalid values for zoom and lead to flickering and useless computations if (document.FormArea.Width <= 0 || document.FormArea.Height <= 0 || visibleSize.Width <= 1 || visibleSize.Height <= 1) { return; } SizeI pageSize = new SizeI(document.PaperWidth, document.PaperHeight); if (autoZoom) { // Adjust the zoom ratio in respect to the number of columns and rows double widthRatio = (visibleSize.Width - (HORIZONTAL_GAP * (columns + 1))) / ((double)(columns * pageSize.Width)); double heightRatio = (visibleSize.Height - (VERTICAL_GAP * (rows + 1))) / ((double)(rows * pageSize.Height)); double newZoom = Math.Min(widthRatio, heightRatio); if (newZoom != zoom) { zoom = newZoom; ClearPagesCache(); OnZoomChanged(EventArgs.Empty); } } else { // Adjust the number of columns and rows in respect to the zoom ratio columns = 1; int i; for (i = 1; i < 5; i++) { double calcWidth = i * pageSize.Width * zoom + 10 * (i + 1); if (calcWidth > visibleSize.Width) { break; } columns = Math.Min(i, document.PageColumns); } rows = 1; for (i = 1; i < 5; i++) { double calcHeight = i * pageSize.Height * zoom + 10 * (i + 1); if (calcHeight > visibleSize.Height) { break; } rows = Math.Min(i, document.PageRows); } OnPagesPerSheetChanged(EventArgs.Empty); } imageSize = new SizeI((int)(zoom * pageSize.Width), (int)(zoom * pageSize.Height)); int virtualWidth = (imageSize.Width * columns) + HORIZONTAL_GAP * (columns + 1); int virtualHeight = (imageSize.Height * rows) + VERTICAL_GAP * (rows + 1); if (visibleSize.Width > virtualWidth) { drawOffset.X = (visibleSize.Width - virtualWidth) / 2; virtualWidth = visibleSize.Width; } else { drawOffset.X = 0; } if (visibleSize.Height > virtualHeight) { drawOffset.Y = (visibleSize.Height - virtualHeight) / 2; virtualHeight = visibleSize.Height; } else { drawOffset.Y = 0; } VirtualSize = new Size(virtualWidth, virtualHeight); } virtualSizeIsInvalid = false; }
protected override bool OnConfigureEvent(EventConfigure evnt) { var newSize = new Size(evnt.Width, evnt.Height); if (newSize != _clientSize) { Resized(newSize); } return true; }
/// <summary> /// Pastes an image from the clipboard. /// </summary> /// <param name="toNewLayer">Set to TRUE to paste into a /// new layer. Otherwise, will paste to the current layer.</param> /// <param name="x">Optional. Location within image to paste to. /// Position will be adjusted if pasted image would hang /// over right or bottom edges of canvas.</param> /// <param name="y">Optional. Location within image to paste to. /// Position will be adjusted if pasted image would hang /// over right or bottom edges of canvas.</param> public void Paste(bool toNewLayer, int x = 0, int y = 0) { // Create a compound history item for recording several // operations so that they can all be undone/redone together. CompoundHistoryItem paste_action; if (toNewLayer) { paste_action = new CompoundHistoryItem(Stock.Paste, Catalog.GetString("Paste Into New Layer")); } else { paste_action = new CompoundHistoryItem(Stock.Paste, Catalog.GetString("Paste")); } Gtk.Clipboard cb = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false)); // See if the current tool wants to handle the paste // operation (e.g., the text tool could paste text) if (!toNewLayer) { if (PintaCore.Tools.CurrentTool.TryHandlePaste(cb)) { return; } } PintaCore.Tools.Commit(); Path p; // Don't dispose this, as we're going to give it to the history Gdk.Pixbuf cbImage = cb.WaitForImage(); if (cbImage == null) { ShowClipboardEmptyDialog(); return; } Gdk.Size canvas_size = PintaCore.Workspace.ImageSize; // If the image being pasted is larger than the canvas size, allow the user to optionally resize the canvas if (cbImage.Width > canvas_size.Width || cbImage.Height > canvas_size.Height) { ResponseType response = ShowExpandCanvasDialog(); if (response == ResponseType.Accept) { PintaCore.Workspace.ResizeCanvas(cbImage.Width, cbImage.Height, Pinta.Core.Anchor.Center, paste_action); PintaCore.Actions.View.UpdateCanvasScale(); } else if (response == ResponseType.Cancel || response == ResponseType.DeleteEvent) { return; } } // If the pasted image would fall off bottom- or right- // side of image, adjust paste position x = Math.Max(0, Math.Min(x, canvas_size.Width - cbImage.Width)); y = Math.Max(0, Math.Min(y, canvas_size.Height - cbImage.Height)); // If requested, create a new layer, make it the current // layer and record it's creation in the history if (toNewLayer) { UserLayer l = AddNewLayer(string.Empty); SetCurrentUserLayer(l); paste_action.Push(new AddLayerHistoryItem("Menu.Layers.AddNewLayer.png", Catalog.GetString("Add New Layer"), UserLayers.IndexOf(l))); } // Copy the paste to the temp layer, which should be at least the size of this document. CreateSelectionLayer(Math.Max(ImageSize.Width, cbImage.Width), Math.Max(ImageSize.Height, cbImage.Height)); ShowSelectionLayer = true; using (Cairo.Context g = new Cairo.Context(SelectionLayer.Surface)) { g.DrawPixbuf(cbImage, new Cairo.Point(0, 0)); p = g.CreateRectanglePath(new Cairo.Rectangle(x, y, cbImage.Width, cbImage.Height)); } SelectionLayer.Transform.InitIdentity(); SelectionLayer.Transform.Translate(x, y); PintaCore.Tools.SetCurrentTool(Catalog.GetString("Move Selected Pixels")); DocumentSelection old_selection = Selection.Clone(); bool old_show_selection = ShowSelection; Selection.SelectionPath = p; Selection.SelectionPolygons.Clear(); ShowSelection = true; Workspace.Invalidate(); paste_action.Push(new PasteHistoryItem(cbImage, old_selection, old_show_selection)); History.PushNewItem(paste_action); }
public void NewFile(Size imageSize) { PintaCore.Workspace.ActiveDocument.HasFile = false; PintaCore.Workspace.ImageSize = imageSize; PintaCore.Workspace.CanvasSize = imageSize; PintaCore.Layers.Clear (); PintaCore.History.Clear (); PintaCore.Layers.DestroySelectionLayer (); PintaCore.Layers.ResetSelectionPath (); // Start with an empty white layer Layer background = PintaCore.Layers.AddNewLayer (Catalog.GetString ("Background")); using (Cairo.Context g = new Cairo.Context (background.Surface)) { g.SetSourceRGB (255, 255, 255); g.Paint (); } PintaCore.Workspace.Filename = "Untitled1"; PintaCore.History.PushNewItem (new BaseHistoryItem (Stock.New, Catalog.GetString ("New Image"))); PintaCore.Workspace.IsDirty = false; PintaCore.Actions.View.ZoomToWindow.Activate (); }