Пример #1
0
        private void SetFingerNum(SolidColorBrush Color)
        {
            if (FingerNum > 0)
            {
                // create new canvas
                Canvas canvas = new Canvas();
                canvas.Background = Color;
                canvas.Height     = 600;
                canvas.Width      = 300;

                // create new label
                Label fingerNumLabel = new Label();
                fingerNumLabel.FontWeight = FontWeights.Bold;

                fingerNumLabel.FontSize   = 120;
                fingerNumLabel.Height     = 200;
                fingerNumLabel.Width      = 200;
                fingerNumLabel.Content    = FingerNum.ToString();
                fingerNumLabel.Background = Color;
                fingerNumLabel.Margin     = new Thickness(91, 400, 0, 0);

                // add label to canvas
                canvas.Children.Add(fingerNumLabel);

                // add canvas to bipmapcachebrush
                BitmapCacheBrush bcb = new BitmapCacheBrush(canvas);
                KeyRect.Fill = bcb;
            }
        }
Пример #2
0
        public AggregateComponent(Color _color, int _id)
        {
            p  = null;
            id = _id;
            component_model = new GeometryModel3D {
                Geometry = new MeshGeometry3D()
            };
            Ellipse ellipse = new Ellipse {
                Width  = 32.0,
                Height = 32.0
            };
            RadialGradientBrush rb = new RadialGradientBrush();

            rb.GradientStops.Add(new GradientStop(_color, 0.0));
            rb.GradientStops.Add(new GradientStop(Colors.Black, 1.0));
            rb.Freeze();
            ellipse.Fill = rb;
            ellipse.Measure(new Size(32.0, 32.0));
            ellipse.Arrange(new Rect(0.0, 0.0, 32.0, 32.0));
            //RenderTargetBitmap bm = new RenderTargetBitmap(32, 32, 96.0, 96.0, PixelFormats.Pbgra32);
            //bm.Render(ellipse);
            //bm.Freeze();
            //ImageBrush ib = new ImageBrush(bm);
            ellipse.CacheMode = new BitmapCache();
            BitmapCacheBrush ib = new BitmapCacheBrush(ellipse);
            DiffuseMaterial  dm = new DiffuseMaterial(ib);

            component_model.Material = dm;
            particle_positions       = new Point3DCollection();
            triangle_indices         = new Int32Collection();
            tex_coords = new PointCollection();
            ((MeshGeometry3D)component_model.Geometry).Positions          = particle_positions;
            ((MeshGeometry3D)component_model.Geometry).TriangleIndices    = triangle_indices;
            ((MeshGeometry3D)component_model.Geometry).TextureCoordinates = tex_coords;
        }
Пример #3
0
        // ChangeText - через создание нового эллипса (эллипсы являются неизменяемыми)
        public static Ellipse GetEllipse(Point center, Point bottom, Brush brush, string txt = "")
        {
            TextBlock text = new TextBlock
            {
                Text                = txt,
                Background          = brush,
                Width               = 40,
                Height              = 40,
                TextAlignment       = System.Windows.TextAlignment.Center,
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
                VerticalAlignment   = System.Windows.VerticalAlignment.Stretch
            };

            BitmapCacheBrush br = new BitmapCacheBrush(text);

            Ellipse elps = new Ellipse
            {
                Width   = 50,
                Height  = 50,
                Opacity = 1,    // непрозрачность
                Stroke  = Brushes.Black,
                Margin  = new System.Windows.Thickness(center.X - 25, center.Y - 25, bottom.X, bottom.Y),
                Tag     = txt   // надпись получим через tag
            };

            elps.Fill = br;

            return(elps);
        }
Пример #4
0
        /// <summary>
        /// Vykresluje 1 cestu na mapě.
        /// </summary>
        /// <param name="lesniStezka">nese <c>DataHran<c> potřebné k vytvoření hrany</param>
        private void KresliSilnici(DataHran lesniStezka)
        {
            //default je hyr
            Brush barvaStezky = Brushes.Beige;

            if (lesniStezka.OznaceniHrany)
            {
                barvaStezky = Brushes.Black;
            }
            else if (!lesniStezka.JeFunkcniCesta)
            {
                barvaStezky = Brushes.DarkGray;
            }

            DataVrcholu pocatekHrany = mapa.NajdiVrcholSemA(lesniStezka.PocatekHrany);
            DataVrcholu konecHrany   = mapa.NajdiVrcholSemA(lesniStezka.KonecHrany);

            Line myline = new Line
            {
                // Name = String.Format("{0}__{1}", lesniStezka.PocatekHrany, lesniStezka.KonecHrany),
                Stroke          = barvaStezky,
                StrokeThickness = 10,
                X1 = pocatekHrany.XSouradniceVrcholu + 4,
                Y1 = pocatekHrany.YSouradniceVrcholu + 4,
                X2 = konecHrany.XSouradniceVrcholu + 4,
                Y2 = konecHrany.YSouradniceVrcholu + 4
            };

            myline.Opacity              = 0.9;
            myline.MouseLeftButtonDown += OnLineMouseLeftButtonDown;
            canvasElem.Children.Add(myline);

            float     xLabel = pocatekHrany.XSouradniceVrcholu + (konecHrany.XSouradniceVrcholu - pocatekHrany.XSouradniceVrcholu) * 1 / 2;
            float     yLabel = pocatekHrany.YSouradniceVrcholu + (konecHrany.YSouradniceVrcholu - pocatekHrany.YSouradniceVrcholu) * 1 / 2;
            TextBlock TB     = new TextBlock();

            TB.Text = $"{lesniStezka.DelkaHrany} min";
            BitmapCacheBrush bcb = new BitmapCacheBrush(TB);

            TB.Margin   = new Thickness(xLabel - 10, yLabel + 5, 0, 0);
            TB.FontSize = 10;
            Canvas.SetZIndex(TB, 20);
            canvasElem.Children.Add(TB);

            //if (lesniStezka.JeFunkcniCesta == false)
            //{
            //    Ellipse currentDot = new Ellipse();
            //    currentDot.Stroke = new SolidColorBrush(Colors.Red);
            //    currentDot.StrokeThickness = 1;
            //    Canvas.SetZIndex(currentDot, 10);
            //    currentDot.Height = 10;
            //    currentDot.Width = 10;
            //    currentDot.Fill = new SolidColorBrush(Colors.Red);
            //    currentDot.Margin = new Thickness(xLabel, yLabel, 0, 0);
            //    canvasElem.Children.Add(currentDot);
            //}
        }
Пример #5
0
 private void UpdateButtonFill(Rectangle clickedButton, string playerSymbol, Brush color)
 {
     if (clickedButton != null)
     {
         TextBlock tb = new TextBlock();
         tb.FontSize   = 72;
         tb.Background = color;
         tb.Text       = playerSymbol;
         BitmapCacheBrush bcb = new BitmapCacheBrush(tb);
         clickedButton.Fill = bcb;
     }
 }
Пример #6
0
        /// <summary>
        /// Creates the BitmapCacheBrush that will be used to hold the interactive
        /// 2D content.
        /// </summary>
        /// <returns>The BitmapCacheBrush to hold the interactive 2D content</returns>
        private BitmapCacheBrush CreateBitmapCacheBrush()
        {
            BitmapCacheBrush bcb = new BitmapCacheBrush();

            // We don't want the cache brush being the InheritanceContext for the Visual it contains.  Rather we want
            // that to be the Viewport2DVisual3D itself.
            bcb.CanBeInheritanceContext = false;

            // Ensure that the brush supports rendering all properties on the Visual to match VisualBrush behavior.
            bcb.AutoWrapTarget = true;

            bcb.BitmapCache = CacheMode as BitmapCache;
            return(bcb);
        }
Пример #7
0
        private Rectangle CreateNewRectangle(string txt, FontFamily myFontFamily)
        {
            Rectangle r = new Rectangle();

            r.Width  = txt.Length * 24;
            r.Height = 24;
            //r.RenderTransform = new TranslateTransform(100, 100);
            TextBlock TB = new TextBlock();

            TB.FontFamily = myFontFamily;
            TB.Text       = txt;
            //The next two magical lines create a special brush that contains a bitmap rendering of the UI element that can then be used like any other brush and its in hardware and is almost the text book example for utilizing all hardware rending performances in WPF unleashed 4.5
            BitmapCacheBrush bcb = new BitmapCacheBrush(TB);

            r.Fill = bcb;
            return(r);
        }
Пример #8
0
        /// <summary>
        /// Vykresluje vrcholy/body/mista na mapě.
        /// </summary>
        /// <param name="vrchol"></param>
        private void VykresliObec(DataVrcholu vrchol)
        {
            Ellipse teckaNaVrcholu = new Ellipse();

            teckaNaVrcholu.Name = vrchol.NazevVrcholu.Replace(" ", "_");
            if (vrchol.TypVrcholu == TypyVrcholu.odpocivadlo)
            {
                teckaNaVrcholu.Stroke          = new SolidColorBrush(Colors.DarkBlue);
                teckaNaVrcholu.StrokeThickness = 10;
                teckaNaVrcholu.Height          = 15;
                teckaNaVrcholu.Width           = 20;
            }
            else if (vrchol.TypVrcholu == TypyVrcholu.zastavka)
            {
                teckaNaVrcholu.Stroke          = new SolidColorBrush(Colors.Cyan);
                teckaNaVrcholu.StrokeThickness = 10;
                teckaNaVrcholu.Height          = 12;
                teckaNaVrcholu.Width           = 12;
            }
            else if (vrchol.TypVrcholu == TypyVrcholu.None)
            {
                teckaNaVrcholu.Stroke          = new SolidColorBrush(Colors.Brown);
                teckaNaVrcholu.StrokeThickness = 8;
                teckaNaVrcholu.Height          = 10;
                teckaNaVrcholu.Width           = 10;
            }
            Canvas.SetZIndex(teckaNaVrcholu, 3);

            teckaNaVrcholu.Margin = new Thickness(vrchol.XSouradniceVrcholu, vrchol.YSouradniceVrcholu, 0, 0);

            //DELEGAT tu se zaregistruje funkce OnElipse.. na jako event handler na akci MouseLeft.. - DELEGAT
            teckaNaVrcholu.MouseLeftButtonDown += OnEllipseMouseLeftButtonDown;

            TextBlock TB = new TextBlock();

            TB.Text = vrchol.NazevVrcholu;
            BitmapCacheBrush bcb = new BitmapCacheBrush(TB);

            TB.Margin   = new Thickness(vrchol.XSouradniceVrcholu - 15, vrchol.YSouradniceVrcholu + 10, 0, 0);
            TB.FontSize = 10;
            Canvas.SetZIndex(TB, 20);

            canvasElem.Children.Add(TB);
            canvasElem.Children.Add(teckaNaVrcholu);
        }
Пример #9
0
        public static void ChangeEllipse(Ellipse ellipse, Brush brush, string txt = "")
        {
            TextBlock text = new TextBlock
            {
                Text                = txt,
                Background          = brush,
                Width               = ellipse.Width - 10,
                Height              = ellipse.Height - 10,
                TextAlignment       = System.Windows.TextAlignment.Center,
                HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
                VerticalAlignment   = System.Windows.VerticalAlignment.Center
            };

            BitmapCacheBrush br = new BitmapCacheBrush(text);

            ellipse.Opacity = 1;
            ellipse.Tag     = txt;
            ellipse.Fill    = br;
        }
        /// <summary>
        /// Gets the brush.
        /// </summary>
        /// <param name="color">The color.</param>
        /// <param name="dead">if set to <c>true</c> [dead].</param>
        /// <returns></returns>
        public static Brush GetBrush(Color color, bool dead)
        {
            var key = new Tuple <Color, bool>(color, dead);

            if (ClopBrushes.ContainsKey(key))
            {
                return(ClopBrushes[key]);
            }

            FrameworkElement image = new KlopImage {
                KlopColor = color
            };

            if (ClopBrushes.Count % 2 == 0)
            {
                //Nice hack to orientate enemy image
                image.RenderTransform = new RotateTransform(180);
            }

            Brush brush;

            if (PreferencesManager.Instance.RenderPreferences.UseCachedBrush)
            {
                image.CacheMode = new BitmapCache(0.15);
                brush           = new BitmapCacheBrush(image);
            }
            else
            {
                brush = new VisualBrush {
                    Visual = image
                };
            }
            //var brush = dead ? new SolidColorBrush(color){Opacity = 1} : new SolidColorBrush(color) {Opacity = 0.5};
            ClopBrushes[key] = brush;

            return(brush);
        }
Пример #11
0
        private RibbonModelGalleryCategory CreateFruitGalleryCategory()
        {
            void AddFruidDrawing(string assetDrawing1, RibbonModelGalleryCategory modelGalleryCategory1)
            {
                var          ii = TryFindResource(assetDrawing1) as DrawingGroup;
                DrawingBrush db = new DrawingBrush(ii);

                // Matrix transformToDevice;
                // using (var source = new HwndSource(new HwndSourceParameters()))
                // transformToDevice = source.CompositionTarget.TransformToDevice;

                // var pixelSize = (Size)transformToDevice.Transform((Vector)ii.Bounds.Size);
                double width, height;

                if (ii.Bounds.Width > ii.Bounds.Height)
                {
                    width  = 32.0;
                    height = ii.Bounds.Height / ii.Bounds.Width * 32.0;
                }
                else
                {
                    height = 32.0;
                    width  = ii.Bounds.Width / ii.Bounds.Height * 32.0;
                }
                Rectangle r = new Rectangle()
                {
                    Fill = db, Width = width, Height = height
                };

                modelGalleryCategory1.Items.Add(r);
            }

            var modelGalleryCategory = new RibbonModelGalleryCategory {
                Header = "Fruits"
            };

            void AddFruit(string s, RibbonModelGalleryCategory galleryCategory)
            {
                void AddFruitImage(object content, string s1)
                {
                    var fruit1 = new RibbonModelGalleryItem()
                    {
                        Content = content
                    };

                    galleryCategory.Items.Add(fruit1);
                }

                var grapes1 = new Rectangle();

                grapes1.Width  = 32;
                grapes1.Height = 32;
                var        tryFindResource = (BitmapSource)TryFindResource(s);
                ImageBrush i = new ImageBrush(tryFindResource);

                i.Freeze();
                CachedBitmap     x   = new CachedBitmap((BitmapSource)TryFindResource(s), BitmapCreateOptions.None, BitmapCacheOption.Default);
                BitmapCacheBrush xx  = new BitmapCacheBrush();
                BitmapCache      xxx = new BitmapCache();

                grapes1.CacheMode = xxx;
                grapes1.Fill      = new ImageBrush(x);
                grapes1.Tag       = s;
                AddFruitImage(new Border {
                    Background = i, Width = tryFindResource.PixelWidth, Height = tryFindResource.PixelHeight
                }, s);
            }

            var grapes = "Grapes";

            var assetDrawing = "Asset_3Drawing";

            AddFruidDrawing(assetDrawing, modelGalleryCategory);
            AddFruidDrawing("Asset_4Drawing", modelGalleryCategory);
            AddFruidDrawing("Asset_2Drawing", modelGalleryCategory);
            // AddFruidDrawing("Asset_4Drawing", modelGalleryCategory);
            // AddFruidDrawing("Asset_4Drawing", modelGalleryCategory);
            // AddFruit(grapes, modelGalleryCategory);
            // AddFruit("Watermelon", modelGalleryCategory);
            // AddFruit("Strawberry", modelGalleryCategory);
            // modelGalleryCategory.Items.Add(new Rectangle { Stroke = Brushes.Green, StrokeThickness =  3.0, Width = 32, Height = 32});
            return(modelGalleryCategory);
        }