public static void LoadFigmaFromUrlFile(this NSView contentView, string urlFile, out List <FigmaImageView> figmaImageViews, string viewName = null, string nodeName = null) { figmaImageViews = new List <FigmaImageView>(); var figmaDialog = FigmaHelper.GetFigmaDialogFromUrlFile(urlFile, viewName, nodeName); LoadFigmaFromFrameEntity(contentView, figmaDialog, figmaImageViews, viewName, nodeName); }
public static void Load(this IEnumerable <FigmaImageView> figmaImageViews, string fileId) { var ids = figmaImageViews.Select(s => s.Data.ID).ToArray(); var images = FigmaHelper.GetFigmaImages(fileId, ids); if (images != null) { List <Task> downloadImageTaks = new List <Task>(); foreach (var imageView in figmaImageViews) { Task.Run(() => { var url = images.images[imageView.Data.ID]; Console.WriteLine($"Processing image - ID:[{imageView.Data.ID}] ImageRef:[{imageView.Data.imageRef}] Url:[{url}]"); try { var image = new NSImage(new Foundation.NSUrl(url)); NSApplication.SharedApplication.InvokeOnMainThread(() => { imageView.Image = image; }); Console.WriteLine($"[SUCCESS] Processing image - ID:[{imageView.Data.ID}] ImageRef:[{imageView.Data.imageRef}] Url:[{url}]"); } catch (Exception ex) { Console.WriteLine($"[ERROR] Processing image - ID:[{imageView.Data.ID}] ImageRef:[{imageView.Data.imageRef}] Url:[{url}]"); Console.WriteLine(ex); } }); } } }
public static void LoadFigmaFromResource(this NSView contentView, string resource, out List <FigmaImageView> figmaImageViews, Assembly assembly = null, string viewName = null, string nodeName = null) { figmaImageViews = new List <FigmaImageView>(); var template = FigmaHelper.GetManifestResource(assembly, resource); var figmaDialog = FigmaHelper.GetFigmaDialogFromContent(template, viewName, nodeName); LoadFigmaFromFrameEntity(contentView, figmaDialog, figmaImageViews, viewName, nodeName); }
public static void LoadFigmaFromUrlFile(this NSWindow window, string urlFile, out List <FigmaImageView> figmaImageViews, string viewName = null, string nodeName = null) { figmaImageViews = new List <FigmaImageView>(); var figmaDialog = FigmaHelper.GetFigmaDialogFromUrlFile(urlFile, viewName, nodeName); var boundingBox = figmaDialog.absoluteBoundingBox; window.SetFrame(new CGRect(window.Frame.X, window.Frame.Y, boundingBox.width, boundingBox.height), true); LoadFigma(window.ContentView, new FigmaFrameEntityResponse(urlFile, figmaDialog), figmaImageViews); }
//TODO: Change to async multithread public static async Task SaveFigmaImageFiles(this FigmaPaint[] paints, string fileId, string directoryPath, string format = ".png") { var ids = paints.Select(s => s.ID).ToArray(); var query = new FigmaImageQuery(FigmaEnvirontment.Token, fileId, ids); var images = FigmaHelper.GetFigmaImage(query); if (images != null) { var urls = paints.Select(s => images.images[s.ID]).ToArray(); await FigmaHelper.SaveFilesAsync(directoryPath, format, urls); } }
public void Initialize() { try { Console.WriteLine($"Reading {file} from resources"); var template = FigmaHelper.GetManifestResource(GetType().Assembly, file); Document = FigmaHelper.GetFigmaDialogFromContent(template); Console.WriteLine($"Reading successfull"); FigmaImages = new List <FigmaImageView> (); ContentView = new NSView(); //Reload (); } catch (Exception ex) { Console.WriteLine($"Error reading resource"); Console.WriteLine(ex); } }
public static FigmaImageResponse GetFigmaImages(string fileId, string[] ids) { var query = new FigmaImageQuery(FigmaEnvirontment.Token, fileId, ids); return(FigmaHelper.GetFigmaImage(query)); }