protected override CGRect GetRect(nfloat winWidth, nfloat winHeight) { nfloat min = winWidth < winHeight ? winWidth : winHeight; // a value from 0 to 1 nfloat spread = UserSettings.GetSettings().BounceWidthPad * 2; nfloat width, height, xPos, yPos; var ratio = winHeight / winWidth; var spreadRatio = 1 / (spread + 1); if (spreadRatio > ratio) { height = winHeight; width = height * (spread + 1); yPos = 0; xPos = winWidth / 2 - width / 2; } else { width = winWidth; height = width / (1 + spread); xPos = 0; yPos = winHeight / 2 - height / 2; } BounceHelper.SetDimensions(width, height); // create the elements. We need to initialize them here when all the dimensions are set. //CreateAssets(); return(new CGRect(xPos, yPos, width, height)); }
void Instance_BeatChanged(object sender, EventArgs e) { // need to create all new elements; recreate everything BounceHelper.SetDimensions(Layer.Frame.Width, Layer.Frame.Height); // redraw lanes AnimationLayer.SetNeedsDisplay(); CreateAssets(); ReturnToInitialState(); BounceHelper.ElapsedBpm = Metronome.Instance.ElapsedBpm; DrawElements(); }
//protected AnimationTimer Timer = new AnimationTimer(); #endregion public BounceView(IntPtr handle) : base(handle) { AnimationLayer.Delegate = new BounceLayerDelegate(); TickLayer = new CALayer(); TickLayer.ContentsScale = NSScreen.MainScreen.BackingScaleFactor; Layer.AddSublayer(TickLayer); Metronome.Instance.Started += Instance_Started; Metronome.Instance.Stopped += Instance_Stopped; Metronome.Instance.BeatChanged += Instance_BeatChanged; UserSettings.BounceSettingsChanged += UserSettings_BounceSettingsChanged; BounceHelper.ResetElaspedBpm(); }
public override void DrawFrame() { if (Metronome.Instance.PlayState == Metronome.PlayStates.Stopped) { // sometimes the drawFrame will run after playback is started, so we handle that case ReturnToInitialState(); BounceHelper.ResetElaspedBpm(); } else { //BounceHelper.ElapsedBpm = Metronome.Instance.ElapsedBpm - BounceHelper.ElapsedBpm; //BounceHelper.ElapsedBpm = Timer.GetElapsedBpm(); BounceHelper.UpdateElapsedBpm(); } DrawElements(); }
void Instance_Stopped(object sender, EventArgs e) { ReturnToInitialState(); BounceHelper.ResetElaspedBpm(); DrawElements(); }