Skip to content

Commit

Permalink
Mac: Main window: Changed completely how Time Shifting/Pitch Shifting…
Browse files Browse the repository at this point in the history
…/Information/Actions panels are managed. They are now part of a mini tab panel which is similar to the mobile UX. Much, much better than trying to present tons of controls in a crawled space.

Related to issue #382.
  • Loading branch information
ycastonguay committed Aug 23, 2013
1 parent 483f58e commit 887bec5
Show file tree
Hide file tree
Showing 6 changed files with 1,864 additions and 1,244 deletions.
168 changes: 168 additions & 0 deletions MPfm/MPfm.Mac/Classes/Controls/MPfmTabButton.cs
@@ -0,0 +1,168 @@
// Copyright © 2011-2013 Yanick Castonguay
//
// This file is part of MPfm.
//
// MPfm is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// MPfm is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Reflection;
using MonoMac.AppKit;
using MonoMac.CoreGraphics;
using MonoMac.Foundation;
using MPfm.Mac.Classes.Helpers;
using MPfm.Mac.Classes.Objects;

namespace MPfm.Mac.Classes.Controls
{
[Register("MPfmTabButton")]
public class MPfmTabButton : NSButton
{
bool _isMouseDown = false;
bool _isMouseOver = false;

public CGColor TextColor { get; set; }
public CGColor BackgroundColor { get; set; }
public CGColor BackgroundMouseDownColor { get; set; }
public CGColor BackgroundMouseOverColor { get; set; }
public CGColor BorderColor { get; set; }

private bool _isSelected = false;
public bool IsSelected
{
get
{
return _isSelected;
}
set
{
_isSelected = value;
SetNeedsDisplay();
}
}

public delegate void TabButtonSelected(MPfmTabButton button);
public event TabButtonSelected OnTabButtonSelected;

[Export("init")]
public MPfmTabButton() : base(NSObjectFlag.Empty)
{
Initialize();
}

// Called when created from unmanaged code
public MPfmTabButton(IntPtr handle) : base (handle)
{
Initialize();
}

private void Initialize()
{
TextColor = GlobalTheme.ButtonTextColor;
//BackgroundColor = GlobalTheme.ButtonToolbarBackgroundColor;
BackgroundColor = GlobalTheme.PanelHeaderColor1;
BackgroundMouseDownColor = GlobalTheme.ButtonToolbarBackgroundMouseOverColor;
BackgroundMouseOverColor = GlobalTheme.ButtonToolbarBackgroundMouseDownColor;
BorderColor = GlobalTheme.ButtonToolbarBorderColor;

// This allows MouseEntered and MouseExit to work
AddTrackingRect(Bounds, this, IntPtr.Zero, false);
}

[Export("mouseDown:")]
public override void MouseDown(NSEvent theEvent)
{
_isMouseDown = true;
base.MouseDown(theEvent);
this.MouseUp(theEvent);
}

[Export("mouseUp:")]
public override void MouseUp(NSEvent theEvent)
{
base.MouseUp(theEvent);
_isMouseDown = false;
IsSelected = true;

if(OnTabButtonSelected != null)
OnTabButtonSelected(this);
SetNeedsDisplay();
}

[Export("mouseEntered:")]
public override void MouseEntered(NSEvent theEvent)
{
base.MouseEntered(theEvent);
_isMouseOver = true;
SetNeedsDisplay();
}

[Export("mouseExited:")]
public override void MouseExited(NSEvent theEvent)
{
base.MouseExited(theEvent);
_isMouseOver = false;
SetNeedsDisplay();
}

public override void DrawRect(RectangleF dirtyRect)
{
float padding = 4;
CGContext context = NSGraphicsContext.CurrentContext.GraphicsPort;
context.SaveState();
context.TranslateCTM(0, Bounds.Height);
context.ScaleCTM(1, -1);

if (_isMouseDown)
CocoaHelper.FillRect(context, Bounds, BackgroundMouseDownColor);
else if (_isMouseOver)
CocoaHelper.FillRect(context, Bounds, BackgroundMouseOverColor);
else
CocoaHelper.FillRect(context, Bounds, BackgroundColor);

if(IsSelected)
CocoaHelper.DrawLine(context, new PointF[2] { new PointF(0, 1), new PointF(Bounds.Width, 1) }, 0.5f, new CGColor(0.4f, 1, 1, 1));

//CocoaHelper.DrawRect(context, Bounds, BorderColor);
//RectangleF rectTextSize = CocoaHelper.MeasureString(Bounds.Size, Title, "Junction", 11);
RectangleF rectTextSize = CocoaHelper.MeasureString(Bounds.Size, Title, "TitilliumText25L-800wt", 12);
RectangleF rectText;
if (Image != null)
{
float xImage = ((Bounds.Width - rectTextSize.Width - (padding * 2) - Image.Size.Width) / 2);
RectangleF rectImage = new RectangleF(xImage, (Bounds.Height - Image.Size.Height) / 2, Image.Size.Width, Image.Size.Height);
Image.DrawInRect(rectImage, new RectangleF(0, 0, Image.Size.Width, Image.Size.Height), NSCompositingOperation.SourceOver, 1.0f);

float xText = xImage + padding + Image.Size.Width + padding;
rectText = new RectangleF(xText, (Bounds.Height - rectTextSize.Height) / 2, rectTextSize.Width, rectTextSize.Height);
}
else
{
rectText = new RectangleF((Bounds.Width - rectTextSize.Width) / 2, (Bounds.Height - rectTextSize.Height) / 2, rectTextSize.Width, rectTextSize.Height);
}

context.RestoreState();
//CocoaHelper.DrawText(rectText, 0, 0, Title, "Junction", 11, NSColor.White);
CocoaHelper.DrawText(rectText, 0, 0, Title, "TitilliumText25L-800wt", 12, NSColor.White);
}

RectangleF Get1pxRect(RectangleF rect)
{
RectangleF newRect = new RectangleF(rect.X + 0.5f, rect.Y + 0.5f, rect.Width - 1, rect.Height - 1);
return newRect;
}
}
}
1 change: 1 addition & 0 deletions MPfm/MPfm.Mac/Classes/Controls/MPfmView.cs
Expand Up @@ -103,6 +103,7 @@ public override void DrawRect(RectangleF dirtyRect)
{
RectangleF rectHeader = new RectangleF(0, Bounds.Height - 24, Bounds.Width, 24);
CocoaHelper.FillRect(context, rectHeader, HeaderColor1);
//CocoaHelper.DrawLine(context, new PointF[2] { new PointF(0, Bounds.Height - 24), new PointF(Bounds.Width, Bounds.Height - 24) }, 0.5f, new CGColor(0.4f, 1, 1, 1));
}

// context.SaveState();
Expand Down
1 change: 1 addition & 0 deletions MPfm/MPfm.Mac/MPfm.Mac.csproj
Expand Up @@ -214,6 +214,7 @@
<DependentUpon>SyncDownloadWindow.cs</DependentUpon>
</Compile>
<Compile Include="Classes\Objects\SyncMenuItem.cs" />
<Compile Include="Classes\Controls\MPfmTabButton.cs" />
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="Views\LibraryBrowser.xib" />
Expand Down
48 changes: 42 additions & 6 deletions MPfm/MPfm.Mac/Windows/Controllers/MainWindowController.cs
Expand Up @@ -39,6 +39,7 @@
using MPfm.Mac.Classes.Delegates;
using MPfm.Player.Objects;
using MPfm.MVP.Presenters;
using MPfm.Mac.Classes.Controls;

namespace MPfm.Mac
{
Expand Down Expand Up @@ -120,11 +121,46 @@ public override void WindowDidLoad()
scrollViewAlbumCovers.SetSynchronizedScrollView(scrollViewSongBrowser);
scrollViewSongBrowser.SetSynchronizedScrollView(scrollViewAlbumCovers);

btnTabTimeShifting.IsSelected = true;
btnTabTimeShifting.OnTabButtonSelected += HandleOnTabButtonSelected;
btnTabPitchShifting.OnTabButtonSelected += HandleOnTabButtonSelected;
btnTabInfo.OnTabButtonSelected += HandleOnTabButtonSelected;
btnTabActions.OnTabButtonSelected += HandleOnTabButtonSelected;

NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSOutlineViewItemDidExpandNotification"), ItemDidExpand, outlineLibraryBrowser);

OnViewReady.Invoke(this);
}

private void HandleOnTabButtonSelected(MPfmTabButton button)
{
Console.WriteLine("Test: {0}", button.Title);

btnTabTimeShifting.IsSelected = button == btnTabTimeShifting;
btnTabPitchShifting.IsSelected = button == btnTabPitchShifting;
btnTabInfo.IsSelected = button == btnTabInfo;
btnTabActions.IsSelected = button == btnTabActions;

viewTimeShifting.Hidden = button != btnTabTimeShifting;
viewPitchShifting.Hidden = button != btnTabPitchShifting;
viewInformation.Hidden = button != btnTabInfo;
viewActions.Hidden = button != btnTabActions;

// if (button == btnTabTimeShifting)
// {
//
// }
// else if (button == btnTabPitchShifting)
// {
// }
// else if (button == btnTabInfo)
// {
// }
// else if (button == btnTabActions)
// {
// }
}

private void SetTheme()
{
viewLeftHeader.BackgroundColor1 = GlobalTheme.PanelHeaderColor1;
Expand Down Expand Up @@ -179,11 +215,11 @@ private void SetTheme()
lblSongTitle.TextColor = NSColor.FromDeviceRgba(171f/255f, 186f/255f, 196f/255f, 1);
lblSongPath.TextColor = NSColor.FromDeviceRgba(97f/255f, 122f/255f, 140f/255f, 1);

viewInformation.IsHeaderVisible = true;
//viewInformation.IsHeaderVisible = true;
viewSongPosition.IsHeaderVisible = true;
viewVolume.IsHeaderVisible = true;
viewTimeShifting.IsHeaderVisible = true;
viewPitchShifting.IsHeaderVisible = true;
//viewTimeShifting.IsHeaderVisible = true;
//viewPitchShifting.IsHeaderVisible = true;

lblArtistName.Font = NSFont.FromFontName("TitilliumText25L-800wt", 24);
lblAlbumTitle.Font = NSFont.FromFontName("TitilliumText25L-600wt", 20);
Expand All @@ -203,10 +239,10 @@ private void SetTheme()
lblTitleSongBrowser.Font = NSFont.FromFontName("TitilliumText25L-800wt", 14);

lblSubtitleSongPosition.Font = NSFont.FromFontName("TitilliumText25L-800wt", 12);
lblSubtitleTimeShifting.Font = NSFont.FromFontName("TitilliumText25L-800wt", 12);
//lblSubtitleTimeShifting.Font = NSFont.FromFontName("TitilliumText25L-800wt", 12);
lblSubtitleVolume.Font = NSFont.FromFontName("TitilliumText25L-800wt", 12);
lblSubtitleInformation.Font = NSFont.FromFontName("TitilliumText25L-800wt", 12);
lblSubtitlePitchShifting.Font = NSFont.FromFontName("TitilliumText25L-800wt", 12);
//lblSubtitleInformation.Font = NSFont.FromFontName("TitilliumText25L-800wt", 12);
//lblSubtitlePitchShifting.Font = NSFont.FromFontName("TitilliumText25L-800wt", 12);

lblPosition.Font = NSFont.FromFontName("DroidSansMono", 15f);
lblLength.Font = NSFont.FromFontName("DroidSansMono", 15f);
Expand Down
60 changes: 52 additions & 8 deletions MPfm/MPfm.Mac/Windows/MainWindow.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 887bec5

Please sign in to comment.