protected virtual Task CreateBitmap() { return(Windows.Invoke(() => { var width = this.Width; var height = this.Height; if (width == 0 || double.IsNaN(width) || height == 0 || double.IsNaN(height)) { //We need proper dimentions. return; } var size = Windows.ActiveWindow.GetElementPixelSize( width * this.ScalingFactor.Value, height * this.ScalingFactor.Value ); this.Bitmap = new WriteableBitmap( Convert.ToInt32(size.Width), Convert.ToInt32(size.Height), 96, 96, PixelFormats.Pbgra32, null ); this.CreateViewBox(); })); }
protected virtual BrowseResult BrowseFolder(BrowseOptions options) { var result = default(BrowseResult); Windows.Invoke(() => { //TODO: Use only WPF frameworks. using (var dialog = new global::System.Windows.Forms.FolderBrowserDialog()) { dialog.Description = options.Title; if (Directory.Exists(options.Path)) { dialog.SelectedPath = options.Path; } var window = Windows.ActiveWindow; var success = default(bool); switch (dialog.ShowDialog(new Win32Window(window.GetHandle()))) { case global::System.Windows.Forms.DialogResult.OK: success = true; break; } result = new BrowseResult(new[] { dialog.SelectedPath }, success); } //TODO: Bad .Wait(). }).Wait(); return(result); }
protected virtual void OnMouseRightButtonUp(object sender, EventArgs e) { var task = Windows.Invoke(() => { var x = default(int); var y = default(int); MouseHelper.GetPosition(out x, out y); DpiHelper.TransformPosition(ref x, ref y); if (!object.ReferenceEquals(Menu.DataContext, this.Core)) { Menu.DataContext = this.Core; } Menu.HorizontalOffset = x; Menu.VerticalOffset = y; Menu.IsOpen = true; var source = PresentationSource.FromVisual(Menu) as HwndSource; if (source != null && source.Handle != IntPtr.Zero) { SetForegroundWindow(source.Handle); } }); }
protected virtual Task Refresh() { return(Windows.Invoke(() => { var viewModel = this.FindResource <global::FoxTunes.ViewModel.Rating>("ViewModel"); if (viewModel == null) { return; } var outputStream = PlaybackManager.CurrentStream; if (outputStream != null) { if (outputStream.PlaylistItem.LibraryItem_Id.HasValue) { viewModel.FileData = LibraryBrowser.Get(outputStream.PlaylistItem.LibraryItem_Id.Value); } else { viewModel.FileData = outputStream.PlaylistItem; } } else { viewModel.FileData = null; } })); }
protected virtual BrowseResult BrowseFile(BrowseOptions options) { var result = default(BrowseResult); Windows.Invoke(() => { var dialog = new OpenFileDialog() { Title = options.Title, Filter = GetFilter(options.Filters), Multiselect = options.Flags.HasFlag(BrowseFlags.Multiselect), }; if (File.Exists(options.Path)) { dialog.InitialDirectory = Path.GetDirectoryName(options.Path); dialog.FileName = options.Path; } else if (Directory.Exists(options.Path)) { dialog.InitialDirectory = options.Path; } var window = Windows.ActiveWindow; var success = dialog.ShowDialog(window); result = new BrowseResult(dialog.FileNames, success.GetValueOrDefault()); //TODO: Bad .Wait(). }).Wait(); return(result); }
public async Task Clear() { var bitmap = default(WriteableBitmap); var success = default(bool); var info = default(BitmapHelper.RenderInfo); await Windows.Invoke(() => { bitmap = this.Bitmap; success = bitmap.TryLock(LockTimeout); if (!success) { return; } info = BitmapHelper.CreateRenderInfo(bitmap, Colors.Transparent); }).ConfigureAwait(false); BitmapHelper.Clear(info); await Windows.Invoke(() => { bitmap.AddDirtyRect(new Int32Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight)); bitmap.Unlock(); }).ConfigureAwait(false); }
protected virtual async Task Update(IOutputStream stream) { if (this.GeneratorData != null) { this.GeneratorData.Updated -= this.OnUpdated; if (this.GeneratorData.CancellationToken != null) { this.GeneratorData.CancellationToken.Cancel(); } } this.GeneratorData = WaveFormGenerator.WaveFormGeneratorData.Empty; this.RendererData = WaveFormRendererData.Empty; if (stream == null) { await this.Clear().ConfigureAwait(false); return; } this.GeneratorData = this.Generator.Generate(stream); this.GeneratorData.Updated += this.OnUpdated; await Windows.Invoke(() => { this.RendererData = Create(this.GeneratorData, this.Bitmap.PixelWidth, this.Bitmap.PixelHeight); this.Viewbox = new Rect(0, 0, this.GetPixelWidth(), this.Bitmap.PixelHeight); }).ConfigureAwait(false); this.Update(); }
public Task EnsureTheme() { return(Windows.Invoke(() => { var theme = this.Theme; })); }
protected virtual async Task Update(IOutputStream stream) { if (this.GeneratorData != null) { this.GeneratorData.Updated -= this.OnUpdated; if (this.GeneratorData.CancellationToken != null) { this.GeneratorData.CancellationToken.Cancel(); } } this.GeneratorData = WaveFormGenerator.WaveFormGeneratorData.Empty; this.RendererData = WaveFormRendererData.Empty; if (stream == null) { await this.Clear().ConfigureAwait(false); return; } this.GeneratorData = this.Generator.Generate(stream); this.GeneratorData.Updated += this.OnUpdated; await Windows.Invoke(this.CreateViewBox).ConfigureAwait(false); this.Update(); }
protected virtual async Task Render() { var bitmap = default(WriteableBitmap); var success = default(bool); var info = default(BitmapHelper.RenderInfo); await Windows.Invoke(() => { bitmap = this.Bitmap; success = bitmap.TryLock(LockTimeout); if (!success) { return; } info = BitmapHelper.CreateRenderInfo(bitmap, this.Color); }).ConfigureAwait(false); if (!success) { //Failed to establish lock. this.Start(); return; } Render(info, this.RendererData); await Windows.Invoke(() => { bitmap.AddDirtyRect(new Int32Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight)); bitmap.Unlock(); }).ConfigureAwait(false); this.Start(); }
private void OnValueChanged(object sender, EventArgs e) { var task = Windows.Invoke(() => { //Fix the width so all 2d math is integer. this.MinWidth = SpectrumBehaviourConfiguration.GetWidthForBars(BarCount.Value); }); }
public Task Add() { return(Windows.Invoke(() => { this.Component.Children.Add(new UIComponentConfiguration()); this.UpdateChildren(); })); }
protected virtual void OnThemeChanged(object sender, EventArgs e) { var task = Windows.Invoke(() => { //Ensure resources are loaded. ThemeLoader.EnsureTheme(); this.Apply(); }); }
private static void OnCurrentStreamChanged(object sender, EventArgs e) { //Critical: Don't block in this event handler, it causes a deadlock. #if NET40 var task = TaskEx.Run(() => Windows.Invoke(() => OnNotify())); #else var task = Task.Run(() => Windows.Invoke(() => OnNotify())); #endif }
protected virtual void Configure(int count, int width) { Windows.Invoke(() => this.Width = width); this.ElementCount = count; this.Elements = new int[count, 4]; this.SamplesPerElement = SampleCount / count; this.Weight = (float)16 / this.ElementCount; this.Step = width / ElementCount; }
protected virtual async void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { await Windows.Invoke(() => { if (this.ListView.SelectedItem != null) { this.ListView.ScrollIntoView(this.ListView.SelectedItem); } }).ConfigureAwait(false); }
public Task ManagePlaylists() { return(Windows.Invoke(() => { if (!Windows.IsPlaylistManagerWindowCreated) { Windows.PlaylistManagerWindow.Show(); } })); }
public async Task Render() { const byte SHADE = 30; var bitmap = default(WriteableBitmap); var success = default(bool); var waveRenderInfo = default(BitmapHelper.RenderInfo); var powerRenderInfo = default(BitmapHelper.RenderInfo); if (this.RendererData == null) { return; } await Windows.Invoke(() => { bitmap = this.Bitmap; success = bitmap.TryLock(LockTimeout); if (!success) { return; } if (this.Rms.Value) { var colors = this.Color.ToPair(SHADE); waveRenderInfo = BitmapHelper.CreateRenderInfo(bitmap, colors[0]); powerRenderInfo = BitmapHelper.CreateRenderInfo(bitmap, colors[1]); } else { waveRenderInfo = BitmapHelper.CreateRenderInfo(bitmap, this.Color); } }).ConfigureAwait(false); if (!success) { //No bitmap or failed to establish lock. return; } Render( this.RendererData, waveRenderInfo, powerRenderInfo, this.Rms.Value, WaveBarBehaviourConfiguration.GetMode(this.Mode.Value) ); await Windows.Invoke(() => { bitmap.AddDirtyRect(new Int32Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight)); bitmap.Unlock(); }).ConfigureAwait(false); }
public Task ManagePlaylists() { return(Windows.Invoke(() => { if (!Windows.IsPlaylistManagerWindowCreated) { Windows.PlaylistManagerWindow.DataContext = this.Core; Windows.PlaylistManagerWindow.Show(); } })); }
protected virtual void OnMouseRightButtonDown(object sender, EventArgs e) { var task = Windows.Invoke(() => { this.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Right) { RoutedEvent = Mouse.MouseDownEvent, Source = this }); }); }
protected virtual void UpdateSelection() { var task = Windows.Invoke(() => { if (this.TabItem == null) { return; } Logger.Write(typeof(DragOverSelectionBehaviour), LogLevel.Trace, "Selecting tab \"{0}\".", this.TabItem.Header); this.TabItem.IsSelected = true; }); }
protected virtual void OnMouseLeftButtonUp(object sender, EventArgs e) { var task = Windows.Invoke(() => { Windows.ActiveWindow.Show(); if (Windows.ActiveWindow.WindowState == WindowState.Minimized) { Windows.ActiveWindow.WindowState = WindowState.Normal; } Windows.ActiveWindow.BringToFront(); }); }
protected virtual Task RefreshBitmap() { return(Windows.Invoke(() => { this.RendererData = Create( this, this.Bitmap.PixelWidth, this.Bitmap.PixelHeight, this.Orientation ); })); }
public Task SetAlignment(UIComponentContainer container, string alignment) { return(Windows.Invoke(() => { if (container.Component == null) { container.Component = new UIComponentConfiguration(); } container.Component.MetaData.AddOrUpdate(Alignment, alignment); this.UpdateChildren(); })); }
public Task Edit(IFileData[] fileDatas) { return(Windows.Invoke(() => { var window = new MetaDataEditorWindow() { ShowActivated = true, Owner = Windows.ActiveWindow, }; window.Show(fileDatas); })); }
public Task SetFill(UIComponentContainer container) { return(Windows.Invoke(() => { if (container.Component == null) { container.Component = new UIComponentConfiguration(); } container.Component.MetaData.AddOrUpdate(HorizontalAlignment, Fill); container.Component.MetaData.AddOrUpdate(VerticalAlignment, Fill); this.UpdateChildren(); })); }
protected virtual Task Clear() { return(Windows.Invoke(() => { if (!this.Bitmap.TryLock(LockTimeout)) { return; } BitmapHelper.Clear(BitmapHelper.CreateRenderInfo(this.Bitmap, this.Color)); this.Bitmap.AddDirtyRect(new Int32Rect(0, 0, this.Bitmap.PixelWidth, this.Bitmap.PixelHeight)); this.Bitmap.Unlock(); })); }
protected virtual void CheckColumns() { this.Debouncer.Exec(() => { var task = Windows.Invoke(() => { foreach (var pair in this.Columns) { this.CheckColumns(pair.Key, pair.Value); } }); }); }
protected virtual Task RefreshBitmap() { return(Windows.Invoke(() => { this.RendererData = Create( this, this.Bitmap.PixelWidth, this.Bitmap.PixelHeight, OscilloscopeBehaviourConfiguration.GetDuration(this.Duration.Value), OscilloscopeBehaviourConfiguration.GetMode(this.Mode.Value) ); })); }
public Task InvokeAsync(IInvocationComponent component) { switch (component.Id) { case DESIGN: return(Windows.Invoke(() => this.IsDesigning = !this.IsDesigning)); } #if NET40 return(TaskEx.FromResult(false)); #else return(Task.CompletedTask); #endif }