public void Initialize(IBaubleButton button) { var properties = new string[] { "Width", "Height" }; Animator.SetButtonDoubleAnimation(button as FrameworkElement, EasingMode.EaseIn, FrameworkElement.MouseEnterEvent, button.MaxWidth, properties); Animator.SetButtonDoubleAnimation(button as FrameworkElement, EasingMode.EaseOut, FrameworkElement.MouseLeaveEvent, button.MinWidth, properties); }
private void UpdateIconText(IBaubleButton button) { if (button != null) { if (IconTextBlock.Text != button.Text) { IconTextBlock.Inlines.Clear(); IconTextBlock.Inlines.Add(new Bold(new Run(button.Text))); } Size available = new Size(double.PositiveInfinity, double.PositiveInfinity); IconTextBlock.Measure(available); double textWidth = IconTextBlock.DesiredSize.Width; double textMidpoint = textWidth / 2; GeneralTransform transform = (button as FrameworkElement).TransformToAncestor(DisplayGrid); Point rootPoint = transform.Transform(new Point(0, 0)); double imageLeft = rootPoint.X; double imageMidpoint = imageLeft + (button.Width / 2); double textLeft = (imageMidpoint - textMidpoint); if (textLeft < 0) { textLeft = 0; } Canvas.SetLeft(IconTextBlock, textLeft); } }
private void Window_MouseMove(object sender, MouseEventArgs e) { FrameworkElement element = e.Source as FrameworkElement; IBaubleButton activeButton = _settings.Buttons.FirstOrDefault(b => b == element); if (activeButton == null) { if (_lastActiveButton != null) { activeButton = _lastActiveButton; } } if (activeButton != null) { bool updated = _iconFlow.MouseMove(e, activeButton, _settings.Buttons); if (activeButton != null) { UpdateIconText(activeButton); } if (updated) { DisplayGrid_SizeChanged(null, null); } _lastActiveButton = activeButton; } }
private void UpdateDisplayGridColumn(IBaubleButton button, ColumnDefinition column) { column.MinWidth = _settings.Theme.MinimumIconSize > button.MinWidth ? button.MinWidth : _settings.Theme.MinimumIconSize; column.MaxWidth = _settings.Theme.MaximumIconSize > button.MaxWidth ? button.MaxWidth : _settings.Theme.MaximumIconSize; Grid.SetColumnSpan(IconTextCanvas, DisplayGrid.ColumnDefinitions.Count); }
private void DisplayButton(int buttonNumber, IBaubleButton button) { UserControl fe = button as UserControl; if (fe is Bauble.Buttons.Shortcut) { fe.DataContext = (button as Bauble.Buttons.Shortcut).ExecutablePath; } else if (fe is Bauble.Buttons.Separator) { fe.MaxWidth = fe.MinWidth = fe.Width = fe.Width * separatorScale; fe.MaxHeight = fe.MinHeight = fe.Height = fe.Height * separatorScale; } DropShadowEffect dse = new DropShadowEffect(); dse.Color = Colors.Black; dse.BlurRadius = 10; dse.Opacity = 0.25; dse.Direction = 270; fe.Effect = dse; if (buttonNumber > DisplayGrid.ColumnDefinitions.Count) { ColumnDefinition column = new ColumnDefinition(); DisplayGrid.ColumnDefinitions.Add(column); UpdateDisplayGridColumn(button, column); } fe.VerticalAlignment = _settings.Theme.VerticalAlignment; // add an almost transparent shape to our dock // to capture mouse events even when the icon has mostly transparent area Canvas alphaCanvas = new Canvas(); var rect = new System.Windows.Shapes.Rectangle(); rect.Fill = new SolidColorBrush(Color.FromArgb(1, 1, 1, 1)); rect.Stroke = rect.Fill; rect.StrokeThickness = 1; alphaCanvas.Width = rect.Width = fe.Width; alphaCanvas.Height = rect.Height = fe.Height; alphaCanvas.Children.Add(rect); //alphaCanvas.Margin = _settings.Theme.Margin; Grid.SetColumn(alphaCanvas, DisplayGrid.ColumnDefinitions.Count - 1); Grid.SetRow(alphaCanvas, 0); DisplayGrid.Children.Add(alphaCanvas); //fe.SnapsToDevicePixels = true; Grid.SetColumn(fe, DisplayGrid.ColumnDefinitions.Count - 1); Grid.SetRow(fe, 0); DisplayGrid.Children.Add(fe); //ButtonImages.Add(button, button); }
private IBaubleButton LoadButton(JsonElement element) { string typeName = element.GetProperty("type").GetString(); IBaubleButton button = null; var buttonType = ButtonAddIns.FirstOrDefault( bt => bt.FullName == typeName ); if (buttonType != null) { try { button = CreateButton(buttonType); button.LoadFromJson(element); button.Initialize(Theme); Animator.SetButtonDoubleAnimation( button as FrameworkElement, System.Windows.Media.Animation.EasingMode.EaseInOut, SharedEvents.ActivatedEvent, 100, new string[] { "Width", "Height" }); Buttons.Add(button); } catch (Exception ex) { string message = ex.Message; } } return(button); }
public bool MouseMove(MouseEventArgs mouse, IBaubleButton activeButton, List <IBaubleButton> buttons) { bool updated = false; foreach (var b in buttons) { var bUpdated = false; var spread = b.MinWidth * AreaOfEffect; var m = mouse.GetPosition(b as FrameworkElement); var x = m.X - (b.Width / 2); if (Math.Abs(x) >= spread) { if ((b.Width > b.MinWidth) || (b.Height > b.MinHeight)) { b.Width = b.MinHeight; b.Height = b.MinHeight; bUpdated = true; } } else { var percentageOfSpread = (spread - Math.Abs(x)) / spread; b.Width = b.MinWidth + ((b.MaxWidth - b.MinWidth) * percentageOfSpread); b.Height = b.MinHeight + ((b.MaxHeight - b.MinHeight) * percentageOfSpread); bUpdated = true; } if (bUpdated) { b.Width = b.Width; b.Height = b.Height; updated = true; } } return(updated); }
public IBaubleButton AddShortcut(IBaubleButton button) { var element = button.ToXml(); return(LoadButton(element)); }
private List <IBaubleButton> GetAffectedButtons(IBaubleButton activeButton, List <IBaubleButton> buttons, double positionRelativeToButtonCenter) { // get the list of icons this affects int iconsBefore = (int)Math.Ceiling((float)AreaOfEffect / 2F); int iconsAfter = (int)Math.Ceiling((float)AreaOfEffect / 2F); if ((iconsBefore + iconsAfter) > AreaOfEffect) { if (positionRelativeToButtonCenter < 0) { // if mouse is before center of icon iconsAfter--; } else { // else mouse is after center of icon iconsBefore--; } } else { if (positionRelativeToButtonCenter < 0) { // if mouse is before center of icon iconsAfter--; iconsBefore++; } else { // else mouse is after center of icon iconsBefore++; iconsAfter--; } } List <IBaubleButton> affectedButtons = new List <IBaubleButton>(); int activeButtonIndex = buttons.IndexOf(activeButton); int buttonFrom = activeButtonIndex - iconsBefore; if (buttonFrom < 0) { buttonFrom = 0; } int buttonTo = activeButtonIndex + iconsAfter; if (buttonTo >= buttons.Count) { buttonTo = buttons.Count - 1; } for (int currentButton = buttonFrom; currentButton < activeButtonIndex; currentButton++) { affectedButtons.Add(buttons[currentButton]); } affectedButtons.Add(activeButton); for (int currentButton = activeButtonIndex + 1; currentButton <= buttonTo; currentButton++) { affectedButtons.Add(buttons[currentButton]); } return(affectedButtons); }
public void Initialize(IBaubleButton button) { }
public Boolean MouseMove(MouseEventArgs mouse, IBaubleButton activeButton, List <IBaubleButton> buttons) { return(false); }