Build 130105

This commit is contained in:
2013-11-18 20:06:17 +02:00
parent 8816ce4615
commit 43c240001c
81 changed files with 2620 additions and 586 deletions

178
DrumKit/UI/DrumUI.cs Normal file
View File

@ -0,0 +1,178 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml.Media.Imaging;
namespace DrumKit
{
class DrumUI
{
#region Private attributes
private Thumb thumb;
private Image image, imagePressed;
private Grid grid;
private Storyboard hitAnimation;
#endregion
#region Public properties
/// <summary>
/// Gets the ui element which will be put in a canvas.
/// </summary>
public FrameworkElement Element { get { return grid; } }
/// <summary>
/// Gets the drum id.
/// </summary>
public string DrumID { get; private set; }
public event Windows.UI.Xaml.Input.PointerEventHandler PointerPressed
{
add {
grid.PointerPressed += value;
}
remove {
grid.PointerPressed -= value;
}
}
public event DragDeltaEventHandler DragDelta
{
add {
thumb.DragDelta += value;
}
remove {
thumb.DragDelta -= value;
}
}
#endregion
#region Initialization
private void GridAddChild(FrameworkElement element)
{
grid.Children.Add(element);
element.HorizontalAlignment = HorizontalAlignment.Stretch;
element.VerticalAlignment = VerticalAlignment.Stretch;
}
private void InitializeCreateObjects()
{
// Create thumb
this.thumb = new Thumb()
{
Background = new SolidColorBrush(Colors.Green),
Opacity = .3,
Visibility = Visibility.Collapsed
};
// Create image
this.image = new Image();
// Create pressed image
this.imagePressed = new Image()
{
Opacity = 0
};
// Create grid
this.grid = new Grid();
// Create animation
DoubleAnimation fade = new DoubleAnimation();
fade.Duration = TimeSpan.FromSeconds(.6);
fade.From = 1;
fade.To = 0;
Storyboard.SetTarget(fade, this.imagePressed);
Storyboard.SetTargetProperty(fade, "Opacity");
this.hitAnimation = new Storyboard();
this.hitAnimation.Children.Add(fade);
// grid.Resources.Add("hitanimation", this.hitAnimation);
}
private void InitializeParenting()
{
this.GridAddChild(this.image);
this.GridAddChild(this.imagePressed);
this.GridAddChild(this.thumb);
}
public async Task InitializeDrum(Drum drum, StorageFolder root)
{
// Set path
Uri rootpath = new Uri(root.Path);
// Set drum id
this.DrumID = drum.Id;
// Set images
this.image.Source = await IOHelper.GetImageAsync(root, drum.ImageSource);
this.imagePressed.Source = await IOHelper.GetImageAsync(root, drum.ImagePressedSource);
// Set tags
this.thumb.Tag = drum.Id;
this.grid.Tag = drum.Id;
}
#endregion
public DrumUI()
{
// Create objects
this.InitializeCreateObjects();
this.InitializeParenting();
}
public void UpdateLayout(DrumLayout layout, double canvasWidth, double canvasHeight)
{
// Set up size
this.grid.Width = layout.Size * canvasWidth;
this.grid.Height = layout.Size * canvasWidth;
// Set up position
Canvas.SetLeft(this.grid, layout.X * canvasWidth);
Canvas.SetTop(this.grid, layout.Y * canvasHeight);
Canvas.SetZIndex(this.grid, layout.ZIndex);
// Rotation
RotateTransform transform = new RotateTransform();
transform.Angle = layout.Angle;
transform.CenterX = this.grid.Width / 2;
transform.CenterY = this.grid.Height / 2;
this.image.RenderTransform = transform;
this.imagePressed.RenderTransform = transform;
}
public void Hit()
{
// Perform a drum hit
this.hitAnimation.Begin();
}
public void EnableEdit()
{
// Thumb becomes visible
this.thumb.Visibility = Visibility.Visible;
}
public void DisableEdit()
{
// Thumb becomes invisible
this.thumb.Visibility = Visibility.Collapsed;
}
}
}

View File

@ -0,0 +1,30 @@
<Page
x:Class="DrumKit.LoadingPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:DrumKit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="#164646">
<Grid HorizontalAlignment="Center"
VerticalAlignment="Center">
<Image Source="ms-appx:///Assets/Logos/SplashScreen.png"
Stretch="None"/>
</Grid>
<StackPanel
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
Orientation="Horizontal"
Margin="20">
<ProgressRing Width="40" Height="40" IsActive="True" Foreground="White" />
<TextBlock
Name="TextLoading"
Style="{StaticResource SubheaderTextStyle}" Margin="10,0,0,0">
Loading resources...</TextBlock>
</StackPanel>
</Grid>
</Page>

View File

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace DrumKit
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class LoadingPage : Page
{
public LoadingPage()
{
this.InitializeComponent();
this.Loaded += LoadingPage_Loaded;
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private async void LoadingPage_Loaded(object sender, RoutedEventArgs e)
{
// Perform initializations
try
{
TextLoading.Text = "Loading data...";
await DataManager.Initialize();
await Log.Initialize();
await DrumsManager.Initialize(DataManager.Settings);
TextLoading.Text = "Loading sounds...";
SoundManager.Initialize();
await SoundManager.LoadDrumkit(DrumsManager.CurrentDrumkit, DrumsManager.CurrentDrumkitLocation);
TextLoading.Text = "Loading interface...";
UIManager.Initialize();
await UIManager.ReloadDrumkit();
await UIManager.ReloadConfig();
Frame.Navigate(typeof(MainPage));
}
// Error handling
catch (Exception ex)
{
TextLoading.Text = "Failure: " + ex.Message;
Log.Error("Failure during loading!");
Log.Except(ex);
}
}
}
}

84
DrumKit/UI/MainPage.xaml Normal file
View File

@ -0,0 +1,84 @@
<Page
x:Class="DrumKit.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:DrumKit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Transitions>
<TransitionCollection>
<EntranceThemeTransition />
</TransitionCollection>
</Page.Transitions>
<Grid
Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Image Source="ms-appx:///Assets/bg.png"
Stretch="UniformToFill"/>
<Grid Name="canvasContainer" />
<Grid Visibility="Collapsed">
<Border Margin="7"
CornerRadius="10"
BorderBrush="Red"
BorderThickness="5" />
<Canvas Name="recCanvas">
<Ellipse Width="18" Height="18" Fill="Red"
Canvas.Left="20"
Canvas.Top="20"/>
<TextBlock
FontFamily="Consolas"
FontSize="16"
Foreground="Red"
Canvas.Left="42"
Canvas.Top="19">REC
</TextBlock>
<Canvas.Triggers>
<EventTrigger RoutedEvent="Canvas.Loaded">
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever" >
<DoubleAnimation
Storyboard.TargetName="recCanvas"
Storyboard.TargetProperty="Opacity"
Duration="0:0:1" BeginTime="0:0:1" From="1" To="0.1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Canvas.Triggers>
</Canvas>
<!--<StackPanel Orientation="Horizontal"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<Button>Record</Button>
<Button>Stop</Button>
</StackPanel>-->
</Grid>
</Grid>
<Page.BottomAppBar>
<AppBar>
<StackPanel Orientation="Horizontal">
<ToggleButton
Name="buttonAnimations"
Click="buttonAnimations_Click"
AutomationProperties.Name="Animations"
IsChecked="True"
Style="{StaticResource VideoAppBarButtonStyle}" />
<ToggleButton
Name="buttonEditMode"
Click="buttonEditMode_Click"
Style="{StaticResource EditAppBarButtonStyle}" />
</StackPanel>
</AppBar>
</Page.BottomAppBar>
</Page>

View File

@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.ApplicationSettings;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace DrumKit
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.SizeChanged += MainPage_SizeChanged;
this.Loaded += MainPage_Loaded;
this.canvasContainer.Children.Add(UIManager.TheCanvas);
}
void MainPage_SizeChanged(object sender, SizeChangedEventArgs e)
{
// TODO: Find best layout, and change it
DrumsManager.SetLayout();
UIManager.ReloadLayout();
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
// Set layout
DrumsManager.SetLayout();
UIManager.ReloadLayout();
// Set toggles
buttonAnimations.IsChecked = DataManager.Settings.Animations;
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Window.Current.CoreWindow.KeyDown += UIManager.HandlerKeyDown;
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
Window.Current.CoreWindow.KeyDown -= UIManager.HandlerKeyDown;
}
private void buttonEditMode_Click(object sender, RoutedEventArgs e)
{
var button = sender as ToggleButton;
if (button == null) return;
bool isChecked = (button.IsChecked.HasValue && button.IsChecked.Value);
// Fix togglebuton style bug
VisualStateManager.GoToState(button, isChecked ? "Checked" : "Unchecked", false);
// Change visibility of thumbs
if (isChecked) UIManager.EnterEdit();
else UIManager.ExitEdit();
}
private void buttonAnimations_Click(object sender, RoutedEventArgs e)
{
var button = sender as ToggleButton;
if (button == null) return;
bool isChecked = (button.IsChecked.HasValue && button.IsChecked.Value);
// Fix togglebuton style bug
VisualStateManager.GoToState(button, isChecked ? "Checked" : "Unchecked", false);
// Change animation setting
DataManager.Settings.Animations = isChecked;
}
}
}