static void Main(string[] args) { FigmaApplication.Init(Environment.GetEnvironmentVariable("TOKEN")); NSApplication.Init(); NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Regular; var stackView = new StackView() { Orientation = LayoutOrientation.Vertical }; scrollView = new ScrollView(); var mainWindow = new Window(new Rectangle(0, 0, 540, 800)) { Content = scrollView }; mainWindow.Closing += delegate { NSRunningApplication.CurrentApplication.Terminate(); }; //TIP: the render consist in 2 steps: //1) generate all the views, decorating and calculate sizes //2) with this views we generate the hierarchy and position all the views based in the //native toolkit positioning system //in this case we want use a remote file provider (figma url from our document) var fileProvider = new RemoteNodeProvider(); //we initialize our renderer service, this uses all the converters passed //and generate a collection of NodesProcessed which is basically contains <FigmaModel, IView, FigmaParentModel> var rendererService = new ViewRenderService(fileProvider); rendererService.Start(fileName, scrollView.ContentView); //now we have all the views processed and the relationship we can distribute all the views into the desired base view var layoutManager = new StoryboardLayoutManager(); layoutManager.Run(scrollView.ContentView, rendererService); //NOTE: some toolkits requires set the real size of the content of the scrollview before position layers scrollView.AdjustToContent(); mainWindow.Show(); //mainWindow.Title = manager.WindowTitle; NSApplication.SharedApplication.ActivateIgnoringOtherApps(true); NSApplication.SharedApplication.Run(); }
public GameWindow(Rectangle rect) : base(rect) { Resizable = false; //in this case we want use a remote file provider (figma url from our document) var fileProvider = new RemoteNodeProvider(); fileProvider.Load("Jv8kwhoRsrmtJDsSHcTgWGYu"); //we initialize our renderer service, this uses all the converters passed //and generate a collection of NodesProcessed which is basically contains <FigmaModel, IView, FigmaParentModel> var rendererService = new ViewRenderService(fileProvider); //play background music backgroundMusic = new MusicPlayer("Background", "mp3"); backgroundMusic.Play(-1); coinSound = new MusicPlayer("Coin", "mp3"); gameOverSound = new MusicPlayer("GameOver", "mp3"); //we want load the entire level 1 rendererService.RenderInWindow(this, "Level1"); playerTile = rendererService.FindViewStartsWith <IImageView>("Player"); startingPoint = playerTile.Allocation.Origin; pointsLabel = rendererService.FindViewByName <ILabel>("Points"); gemsTiles = rendererService.FindViewsStartsWith <IImageView>("Gem") .ToList(); wallTiles = rendererService.FindViewsStartsWith <IImageView>("Tile") .ToArray(); spikesTiles = rendererService.FindViewsStartsWith <IImageView>("Spikes") .ToArray(); heartTiles = rendererService.FindViewsStartsWith <IImageView>("Heart") .OrderBy(s => s.Allocation.X) .ToList(); WorldUpdate(); }
void RefreshTree(string docId) { var converters = FigmaControlsContext.Current.GetConverters(); fileProvider = new ControlRemoteNodeProvider(); fileProvider.Load(docId); if (fileProvider.Response == null) { return; } var codePropertyConverter = FigmaControlsContext.Current.GetCodePropertyConverter(); codeRenderer = new NativeViewCodeService(fileProvider, converters, codePropertyConverter, translationService); data = new FigmaNodeView(fileProvider.Response.document); figmaDelegate.ConvertToNodes(fileProvider.Response.document, data); outlinePanel.GenerateTree(data); ((NSTextView)logTextField.DocumentView).Value = string.Empty; }
static void Main(string[] args) { const string noimages = "--noimages"; const string outputFile = "downloaded.figma"; Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine("Figma Remote File Exporter"); Console.WriteLine("--------------------------"); Console.WriteLine(); Console.ForegroundColor = default(ConsoleColor); #region Parameters if (args.Length == 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error. No parameters defined"); Console.ForegroundColor = default(ConsoleColor); Console.WriteLine(""); Console.WriteLine($"dotnet FigmaFileExporter.dll [document_id] [figma_token] {{output_directory}} {{{noimages}}}"); Console.WriteLine(""); return; } string token = null; if (args.Length > 1) { token = args[1]; } if (string.IsNullOrEmpty(token)) { Console.WriteLine("Error. Figma Token is not defined."); return; } Console.WriteLine($"Token: {token}"); string outputDirectory = null; if (args.Length > 2 && Directory.Exists(outputDirectory)) { outputDirectory = args[2]; } if (outputDirectory == null) { Console.WriteLine("Output directory is not defined. Using current directory like default."); outputDirectory = Directory.GetCurrentDirectory(); } Console.WriteLine($"Default Directory: {outputDirectory}"); var processImages = !args.Any(s => s.ToLower() == noimages); #endregion FigmaSharp.AppContext.Current.SetAccessToken(token); var fileId = args[0]; var outputFilePath = Path.Combine(outputDirectory, outputFile); if (File.Exists(outputFilePath)) { File.Delete(outputFilePath); } Console.WriteLine(); Console.WriteLine("[Import] Starting from remote document '{0}' ({1} images) in local file: {2}", fileId, processImages ? "with" : "without", outputFilePath); var query = new FigmaFileQuery(fileId); var fileProvider = new RemoteNodeProvider(); fileProvider.Load(fileId); fileProvider.Save(outputFilePath); Console.WriteLine("[Import] Success."); if (processImages) { var mainNode = fileProvider.Response.document.children.FirstOrDefault(); var figmaImageNodes = fileProvider.SearchImageNodes(fileProvider.Response.document) .ToArray(); Console.WriteLine("[Import] Downloading {0} image/s...", figmaImageNodes.Length); var figmaImageIds = figmaImageNodes.Select(s => fileProvider.CreateEmptyImageNodeRequest(s)).ToArray(); if (figmaImageIds.Length > 0) { FigmaSharp.AppContext.Api.ProcessDownloadImages(fileId, figmaImageIds, scale: 2); FigmaSharp.AppContext.Api.ProcessDownloadImages(fileId, figmaImageIds, scale: 1); fileProvider.SaveResourceFiles(outputDirectory, ".png", figmaImageIds); } Console.WriteLine("[Import] Success."); } }
public override void InitializeFigmaComponent() { InternalInitializeComponent(); FileProvider = new RemoteNodeProvider(); RendererService = new ViewRenderService(FileProvider, GetFigmaViewConverters()); }
async void Load(FigmaFileVersion version = null, int pageIndex = 0) { if (string.IsNullOrEmpty(DocumentID)) { return; } windowController.EnableButtons(false); if (response == null) { windowController.Title = string.Format("Opening “{0}”…", DocumentID); } if (response == null || version != null) { fileProvider = new ControlRemoteNodeProvider() { File = DocumentID, Version = version }; fileProvider.ImageLinksProcessed += (sender, e) => { InvokeOnMainThread(() => { windowController.ToggleToolbarSpinner(toggle_on: false); }); }; var embeddedSheetConverter = new EmbededSheetDialogConverter(fileProvider); var embeddedWindowConverter = new EmbededWindowConverter(fileProvider); rendererService = new ControlViewRenderingService(fileProvider); rendererService.CustomConverters.Add(embeddedSheetConverter); rendererService.CustomConverters.Add(embeddedWindowConverter); embeddedWindowConverter.LivePreviewLoading += (s, e) => windowController.ToggleToolbarSpinner(true); embeddedWindowConverter.LivePreviewLoaded += (s, e) => windowController.ToggleToolbarSpinner(false); } var scrollView = CreateScrollView(); await rendererService.StartAsync(DocumentID, scrollView.ContentView, new ViewRenderServiceOptions() { StartPage = pageIndex }); windowController.ToggleToolbarSpinner(toggle_on: true); new StoryboardLayoutManager().Run(scrollView.ContentView, rendererService); response = fileProvider.Response; NativeScrollView.RemoveFromSuperview(); MainScrollView = scrollView; NativeScrollView = (NSScrollView)scrollView.NativeObject; View.AddSubview(NativeScrollView); if (response != null) { windowController.Window.Title = windowController.Title = response.name; // NOTE: Figma does not (yet) support color styles for the document background, // so for now use UnderPageBackgroundColor to get a good contrast in all themes // // windowController.Window.BackgroundColor = NativeScrollView.BackgroundColor; windowController.Window.BackgroundColor = NSColor.UnderPageBackgroundColor; NativeScrollView.BackgroundColor = NSColor.UnderPageBackgroundColor; windowController.UpdatePagesPopupButton(response.document, pageIndex); await windowController.UpdateVersionMenu(DocumentID); windowController.EnableButtons(true); RecentStore.SharedRecentStore.AddRecent(DocumentID, windowController.Window.Title); } else { if (View.Window?.WindowController is DocumentWindowController controller) { controller.ShowError(DocumentID); } var windowController = this.Storyboard.InstantiateControllerWithIdentifier("OpenLocationWindow") as NSWindowController; windowController.ShowWindow(null); this.View.Window.Close(); } ToggleSpinner(toggle_on: false); }