private void ColorTile_OnClick(object sender, EventArgs e) { Button colorTile = (Button)sender; FlatColor flatColor = (FlatColor)colorTile.Tag; NameTextBox.Text = flatColor.Name; HexTextBox.Text = flatColor.Hex; }
private void BuildColorTiles() { ColorsTLP.SuspendLayout(); _flatUIColorPicker = new FlatUIColorPicker(); _flatUIColorPicker.SetFlatColors(); ColorsTLP.RowCount = GetNumberOfRows(_flatUIColorPicker.FlatColors.Count); ColorsTLP.ColumnCount = Convert.ToInt32(Math.Ceiling((decimal)_flatUIColorPicker.FlatColors.Count / ColorsTLP.RowCount)); float rowRercent = 100F / ColorsTLP.RowCount; float columnRercent = 100F / ColorsTLP.ColumnCount; for (int i = 0; i < ColorsTLP.RowCount; i++) { ColorsTLP.RowStyles.Add(new RowStyle(SizeType.Percent, rowRercent)); } for (int i = 0; i < ColorsTLP.ColumnCount; i++) { ColorsTLP.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, columnRercent)); } int flatColorIndex = 0; for (int row = 0; row < ColorsTLP.RowCount; row++) { for (int column = 0; column < ColorsTLP.ColumnCount; column++) { if (flatColorIndex < _flatUIColorPicker.FlatColors.Count) { FlatColor flatColor = _flatUIColorPicker.FlatColors[flatColorIndex++]; MetroTile colorTile = new MetroTile() { UseCustomBackColor = true, BackColor = ColorTranslator.FromHtml(flatColor.Hex), Tag = flatColor, Margin = new Padding(1), Anchor = (AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom) }; colorTile.Click += new EventHandler(ColorTile_OnClick); ColorsTLP.Controls.Add(colorTile); ColorsTLP.SetRow(colorTile, row); ColorsTLP.SetColumn(colorTile, column); } } } ColorsTLP.ResumeLayout(true); }
private async void Main() { var executionQueue = new Queue <IQueueElement>(); TestInit(executionQueue); ISource <Frame> currentSource = new FlatColor(_width, _height, new BehaviorSubject <FlatColorConfig>(new FlatColorConfig { Color = "000000" })); DateTime elementStartTime = DateTime.UtcNow; IQueueElement currentQueueElement = new StaticQueueElement(currentSource, TimeSpan.Zero); while (!_cancellationTokenSource.Token.IsCancellationRequested) { DateTime currentTime = DateTime.UtcNow; SwitchQueueElement(ref currentQueueElement, executionQueue, ref elementStartTime, currentTime); if (currentQueueElement is StaticQueueElement staticQueueElement) { } else if (currentQueueElement is TransitionQueueElement transitionQueueElement) { var durationElapsed = (currentTime - elementStartTime); var x = durationElapsed.TotalMilliseconds / transitionQueueElement.Duration.TotalMilliseconds; if (x > 1) { x = 1; } transitionQueueElement.Mixer.SetMixerLevel(x); } else { throw new InvalidOperationException("Invalid TransitionQueueElement"); } var frame = await currentQueueElement.Source.Pop(); await Task.WhenAll(Sinks.Select(x => x.Push(frame))); await Task.Delay(1000 / 30); } }
private void TestInit(Queue <IQueueElement> queue) { var red = new FlatColor(_width, _height, new BehaviorSubject <FlatColorConfig>(new FlatColorConfig { Color = "FF0000" })); var green = new FlatColor(_width, _height, new BehaviorSubject <FlatColorConfig>(new FlatColorConfig { Color = "00FF00" })); var blue = new FlatColor(_width, _height, new BehaviorSubject <FlatColorConfig>(new FlatColorConfig { Color = "0000FF" })); var rainbow = new Rainbow(_width, _height); var mixer = new LinearMixer(_width, _height); queue.Enqueue(new TransitionQueueElement(red, green, mixer, TimeSpan.FromMilliseconds(1000))); queue.Enqueue(new TransitionQueueElement(green, blue, mixer, TimeSpan.FromMilliseconds(1000))); queue.Enqueue(new TransitionQueueElement(blue, red, mixer, TimeSpan.FromMilliseconds(1000))); queue.Enqueue(new TransitionQueueElement(red, rainbow, mixer, TimeSpan.FromMilliseconds(1000))); queue.Enqueue(new StaticQueueElement(rainbow, TimeSpan.FromMilliseconds(2000))); queue.Enqueue(new TransitionQueueElement(rainbow, red, mixer, TimeSpan.FromMilliseconds(1000))); }