using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using JD.Application.View.WindowLess; using JD.Sequencers.Windowlesses; using JD.Timeline.Model.Clips; using JD.Timeline.View.Helpers; using JD.Serialization; using TeaBox.Core.Source.Gui; namespace JD.Timeline.View.ClipView.Widgets { public class PictogramClipWidget : DanceEditorClipWidget { #region Variables private static readonly Color _backgroundColor = Color.FromArgb(150, 170, 190); private static readonly Color _borderColor = _backgroundColor.Add(-30); private static readonly Color _fontColor = Color.FromArgb(90, 0, 0, 0); private static readonly Bitmap _icon16X16ClipSettings = Properties.Resources.Icon_16x16_clip_settings; private static readonly Bitmap _icon16X16GoldMedal = Properties.Resources.Icon_16x16_goldmedal; private static readonly Font _pictoClipFont = new Font(FontFamily.GenericSansSerif, 8); private static readonly StringFormat _stringFormat = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Near, }; #endregion #region Constructor public PictogramClipWidget(PictogramClip model) : base(model) { Model.Model.BitmapHandler().PropertyChanged += OnBitmapHandlerPropertyChanged; ToolbarItems.Add( new ToolbarItem { Bitmap = () => _icon16X16ClipSettings, Priority = 0, IsVisible = () => true, OnClick = delegate { var wpfwindow = new PictogramClipEditionHelper(Model); wpfwindow.Show(); wpfwindow.Left = Cursor.Position.X; wpfwindow.Top = Cursor.Position.Y - wpfwindow.ActualHeight; wpfwindow.Closing += (s, e) => { var control = (WindowlessRootControl)RootControl; var position = control.PointToClient(Cursor.Position); control.SimulateOnMouseDown(control, new MouseEventArgs(MouseButtons.Left, 1, position.X, position.Y, 0)); }; } } ); ToolbarItems.Add( new ToolbarItem { Bitmap = () => _icon16X16GoldMedal, Priority = 0, IsVisible = () => Model != null && (Model.Model.Flags & PictogramFlag.Gold) == PictogramFlag.Gold } ); } protected override void Dispose(bool disposing) { if (disposing) { Model.Model.BitmapHandler().PropertyChanged -= OnBitmapHandlerPropertyChanged; } base.Dispose(disposing); } private void OnBitmapHandlerPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "BitmapThumbnail") { SetupBounds(); Invalidate(); } } #endregion #region Properties private Bitmap Pictogram { get { return Model.Model.BitmapHandler().BitmapThumbnail; } } public new PictogramClip Model { get { return (PictogramClip)base.Model; } } public override bool SupportAutoLoop { get { return false; } } #endregion #region Methods protected override void OnPaint(PaintEventArgs e) { SetupBounds(); var graphics = e.Graphics; if (!Model.CollisionsWithOther) { FillBackground(graphics, Bounds, _backgroundColor); } else { FillBackground(graphics, Bounds, WarningFillColor); } if (Pictogram != null) { var units = GraphicsUnit.Pixel; var destBounds = Bounds; destBounds.Height -= 10; destBounds.Y += 5; var srcBounds = Pictogram.GetBounds(ref units); float newImageWidth = destBounds.Width * (float)Pictogram.Height / destBounds.Height; srcBounds.X = srcBounds.X + srcBounds.Width / 2 - newImageWidth / 2; srcBounds.Width = newImageWidth; if (srcBounds.Width > 0 && srcBounds.Height > 0 && destBounds.Width > 0 && destBounds.Height > 0) { graphics.DrawImage(Pictogram, destBounds, srcBounds, units); } } if (Bounds.Width > 60) { var textBounds = Bounds; textBounds.Width = Bounds.Width - 16; graphics.DrawString(Model.Model.Name, _pictoClipFont, StyleSheet.Brushes[_fontColor], textBounds, _stringFormat); } if (Selected) { FillBackground(graphics, Bounds, SelectionFillColor); DrawRectangle(graphics, Bounds, SelectionBorderPen); } else { DrawRectangle(graphics, Bounds, StyleSheet.Pens[_borderColor]); } if (Model.CollisionsWithOther) { DrawClipWithWarning(graphics); } DrawNotificationIcons(graphics); OnPaintChildControls(e); } public override void OnDoubleClick() { TeaBox.ObjectModel.Application.Main.Dispatcher.DispatchAsync( () => Track.TrackView.SelectAll(x => x.Model.Model == Model.Model), forceAsync: true); } public override bool IsResizeAllowed { get { return false; } } public override void Resize(Edge resizeEdge, float delta) { //We don't allow any resize for pictograms } #endregion } }