Example #1
0
        public void CreateDefault()
        {
            Reset();

            ImageTile it = new ImageTile();

            it.imagePath = @"Resources/doge.png";
            it.imageSize = new System.Drawing.Size(120, 100);
            this.tileList.Add(it);

            TextTile tt = new TextTile();

            tt.text             = "woo";
            tt.foreground       = Colors.White;
            tt.randomBackground = true;
            tt.background       = Colors.DarkGreen;
            tt.randomForeground = true;
            this.tileList.Add(tt);
        }
Example #2
0
        /// <summary>
        /// Generate qualified labels
        /// </summary>
        /// <param name="interval"></param>
        public TileGenerator(Configuration config,
                             int screenWidth, int screenHeight)
        {
            //clone the original list
            List <TileBase> tileList = config.tileList.ToList();

            if (config.useUniversalAnimation)
            {
                tileList.ForEach(tile => tile.animation = config.universalAnimation);
            }

            timer.Interval = new TimeSpan(config.interval * 1000 * 10);
            timer.Tick    += delegate
            {
                //random
                TileBase nextTile  = tileList[random.Next(tileList.Count)];
                int      positionX = random.Next(screenWidth);
                int      positionY = random.Next(screenHeight);

                Label tileLabel = new Label();
                tileLabel.Uid = "a_" + Guid.NewGuid().ToString().Replace("-", "");
                tileLabel.VerticalAlignment   = VerticalAlignment.Top;
                tileLabel.HorizontalAlignment = HorizontalAlignment.Left;
                tileLabel.Margin = new Thickness(positionX, positionY, 0, 0);

                //image or text
                switch (nextTile.tileType)
                {
                case TileType.Image:
                    ImageTile imageTile = (ImageTile)nextTile;
                    tileLabel.Background = new ImageBrush(new BitmapImage(new Uri
                                                                              (new Uri(AppDomain.CurrentDomain.BaseDirectory), imageTile.imagePath)
                                                                          ));
                    tileLabel.Width   = imageTile.imageSize.Width;
                    tileLabel.Height  = imageTile.imageSize.Height;
                    tileLabel.Opacity = imageTile.opacity;
                    break;

                case TileType.Text:
                    TextTile textTile = (TextTile)nextTile;
                    tileLabel.Content  = textTile.text;
                    tileLabel.FontSize = textTile.fontSize;

                    tileLabel.Background = new SolidColorBrush(textTile.background);
                    if (textTile.randomBackground)
                    {
                        tileLabel.Background = new SolidColorBrush(
                            Color.FromScRgb(1, (float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble())
                            );
                    }

                    tileLabel.Foreground = new SolidColorBrush(textTile.foreground);
                    if (textTile.randomForeground)
                    {
                        tileLabel.Foreground = new SolidColorBrush(
                            Color.FromScRgb(1, (float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble())
                            );
                    }

                    break;

                default:    //undefined TileType
                    return;
                }

                WorkerEvent(this, new WorkerEventArgs()
                {
                    element = tileLabel
                });
            };
        }