Exemplo n.º 1
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            double fontSize;
            Typeface typeFace;
            TextAlignment alignment;
            FlowDirection flowDirection;
            double padding;
            if (AdornedPasswordBox != null) {
                alignment = ConvertAlignment (AdornedPasswordBox.HorizontalContentAlignment);
                flowDirection = AdornedPasswordBox.FlowDirection;
                fontSize = AdornedPasswordBox.FontSize;
                typeFace = AdornedPasswordBox.FontFamily.GetTypefaces ().FirstOrDefault ();
                padding = 6;
            }
            else {
                alignment = AdornedTextBox.ReadLocalValue (TextBox.TextAlignmentProperty) !=DependencyProperty.UnsetValue ? AdornedTextBox.TextAlignment : ConvertAlignment (AdornedTextBox.HorizontalContentAlignment);
                flowDirection = AdornedTextBox.FlowDirection;
                fontSize = AdornedTextBox.FontSize;
                typeFace = AdornedTextBox.FontFamily.GetTypefaces ().FirstOrDefault ();
                padding = 6;
            }
            var text = new System.Windows.Media.FormattedText (PlaceholderText ?? "", CultureInfo.CurrentCulture, flowDirection, typeFace, fontSize, System.Windows.Media.Brushes.LightGray) {
                TextAlignment = alignment
            };

            drawingContext.DrawText (text, new System.Windows.Point (padding, (RenderSize.Height - text.Height) / 2));
        }
Exemplo n.º 2
0
 protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
 {
     drawingContext.DrawRectangle(background, new Pen(Brushes.White, 1), new Rect(new Point(0, 0), DesiredSize));
     drawingContext.DrawText(new FormattedText(this.Message, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight,
         new Typeface("SegoeUI"),
         20.0,
         foreground),
         new Point(10, 10));
     base.OnRender(drawingContext);
 }
Exemplo n.º 3
0
        protected override void OnRender(System.Windows.Media.DrawingContext dc)
        {
            base.OnRender(dc);

            if (this.playground == null)
            {
                return;
            }

            var xlength = this.playground.GetLength(1);
            var ylength = this.playground.GetLength(0);

            if (ylength == 0 || xlength == 0)
            {
                return;
            }

            double cellHeight = ActualHeight / xlength;
            double cellWidth = ActualWidth / ylength;

            cellHeight = Math.Floor(cellHeight);
            cellWidth = Math.Floor(cellWidth);

            if (cellHeight == 0 || cellWidth == 0)
            {
                FormattedText text = new FormattedText("Auflösung falsch gewählt", CultureInfo.InvariantCulture,FlowDirection.LeftToRight, new Typeface("Arial"),12,Brushes.Black);
                dc.DrawText(text,new Point(25, 25));
                return;
            }

            for (int x = 0; x < ylength; x++)
            {
                for (int y = 0; y < xlength; y++)
                {
                    var rect = new Rect(x*cellWidth, y*cellHeight, cellWidth, cellHeight);
                    if (this.playground[x, y] == true)
                    {
                        dc.DrawRectangle(Brushes.Blue, new Pen(), rect);
                    }
                }
            }

            for (int x = 0; x <= ylength; x++)
            {
                var drawingWidth = ylength*cellWidth;
                dc.DrawLine(new Pen(Brushes.LightGray, 1), new Point(0, x * cellHeight), new Point(drawingWidth, x * cellHeight));
            }

            for (int y = 0; y <= xlength; y++)
            {
                var drawingLength = xlength * cellHeight;
                dc.DrawLine(new Pen(Brushes.LightGray, 1), new Point(y * cellWidth, 0), new Point(y * cellWidth, drawingLength));
            }
        }
Exemplo n.º 4
0
        public override void Draw(System.Windows.Media.DrawingContext dc)
        {
            var formattedText = GetFormattedText(Text, Thickness);

            if (Orientation == Orientation.Hor)
            {
                dc.DrawText(formattedText, new System.Windows.Point(StartPoint.X - formattedText.Width/2, StartPoint.Y));
            }
            else
            {
                var rotate = new RotateTransform();
                rotate.Angle = 90;
                dc.PushTransform(rotate);
                dc.DrawText(formattedText, new System.Windows.Point(StartPoint.Y, -StartPoint.X));
                dc.Pop();
            }
        }
Exemplo n.º 5
0
 protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
 {
     RotarySwitch rotarySwitch = Visual as RotarySwitch;
     if (rotarySwitch != null)
     {
         if (rotarySwitch.DrawLines)
         {
             drawingContext.DrawDrawing(_lines);
         }
         foreach (SwitchPositionLabel label in _labels)
         {
             drawingContext.DrawText(label.Text, label.Location);
         }
         _imageBrush.RelativeTransform = new RotateTransform(rotarySwitch.KnobRotation, 0.5d, 0.5d);
         drawingContext.DrawRectangle(_imageBrush, null, _imageRect);
     }
 }
Exemplo n.º 6
0
 protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
 {
     TextView textView = this.TextView;
     Size renderSize = this.RenderSize;
     if (textView != null && textView.VisualLinesValid)
     {
         foreach (VisualLine line in textView.VisualLines)
         {
             int lineNumber = line.FirstDocumentLine.LineNumber;
             if (lineNumbers != null && lineNumbers.Length > line.FirstDocumentLine.LineNumber - 1)
                 lineNumber = lineNumbers[line.FirstDocumentLine.LineNumber - 1];
             FormattedText text = createFormattedText(
                 this,
                 lineNumber.ToString(CultureInfo.CurrentCulture),
                 typeface, emSize, gray
             );
             double y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop);
             drawingContext.DrawText(text, new Point(renderSize.Width - text.Width, y - textView.VerticalOffset));                    
         }
     }
 }
Exemplo n.º 7
0
        protected override void OnRender(System.Windows.Media.DrawingContext dc)
        {
            if (this.TickFrequency <= 1)
            {
                return;
            }

            dc.DrawLine(Timelineborder, new Point(0, 0), new Point(this.ActualWidth, 0));
            double totalCount = this.Maximum - this.Minimum;
            double y = this.ReservedSpace * 0.5;
            FormattedText formattedText = null;
            double x = 0;
            double pixelDelta = this.ActualWidth / (totalCount / this.TickFrequency);
            double innerDelta = pixelDelta / 10;
            TimelineResolution resolution = this.GetMinResolution(totalCount);
            for (double i = 0; i <= totalCount; i += this.TickFrequency, x += pixelDelta)
            {
                string time = i == 0 ? this.GetDateTimeString(this.Minimum) : "+" + this.GetTimeString(resolution, i);
                formattedText = new FormattedText(time,
                            CultureInfo.CurrentUICulture,
                            System.Windows.FlowDirection.LeftToRight,
                            Verdana,
                            8,
                            Brushes.Black);

                dc.DrawText(formattedText, new Point(x, 10));
                //base.OnRender(dc);
                dc.DrawLine(Timelineborder, new Point(x, 0), new Point(x, 10));

                //Draw innter intervals;
                if (i < this.Maximum)
                {
                    for (double k = innerDelta; k < pixelDelta; k += innerDelta)
                    {
                        dc.DrawLine(Timelineborder, new Point(x + k, 0), new Point(x + k, 5));
                    }
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Draws the content of a <see cref="T:System.Windows.Media.DrawingContext" /> object during the render pass of a <see cref="T:System.Windows.Controls.Panel" /> element.
        /// </summary>
        /// <param name="dc">The <see cref="T:System.Windows.Media.DrawingContext" /> object to draw.</param>
        protected override void OnRender(System.Windows.Media.DrawingContext dc)
        {

            //For each face
            foreach (KeyValuePair<int, Affdex.Face> pair in Faces)
            {
                
                Affdex.Face face = pair.Value;

                var featurePoints = face.FeaturePoints;

                //Calculate bounding box corners coordinates.
                System.Windows.Point tl = new System.Windows.Point(featurePoints.Min(r => r.X) * XScale,
                                                   featurePoints.Min(r => r.Y) * YScale);
                System.Windows.Point br = new System.Windows.Point(featurePoints.Max(r => r.X) * XScale,
                                                                   featurePoints.Max(r => r.Y) * YScale);

                System.Windows.Point bl = new System.Windows.Point(tl.X, br.Y);

                //Draw Points
                if (DrawPoints)
                {
                    foreach (var point in featurePoints)
                    {
                        dc.DrawEllipse(pointBrush, null, new System.Windows.Point(point.X * XScale, point.Y * YScale), fpRadius, fpRadius);
                    }

                    //Draw BoundingBox
                    dc.DrawRectangle(null, boundingPen, new System.Windows.Rect(tl, br));
                }

                //Draw Metrics  
                if (DrawMetrics)
                {
                    double padding = (bl.Y - tl.Y) / MetricNames.Count;
                    double startY = tl.Y - padding;
                    foreach (string metric in MetricNames)
                    {
                        double width = maxTxtWidth;
                        double height = maxTxtHeight;
                        float value = -1;
                        PropertyInfo info;
                        if ((info = face.Expressions.GetType().GetProperty(NameMappings(metric))) != null)
                        {
                            value = (float)info.GetValue(face.Expressions, null);
                        }
                        else if ((info = face.Emotions.GetType().GetProperty(NameMappings(metric))) != null)
                        {
                            value = (float)info.GetValue(face.Emotions, null);
                        }
                        else if ((info = face.Emotions.GetType().GetProperty(NameMappings(metric))) != null)
                        {
                            value = (float)info.GetValue(face.Emojis, null);
                        }

                        SolidColorBrush metricBrush = value > 0 ? pozMetricBrush : negMetricBrush;
                        value = Math.Abs(value);
                        SolidColorBrush txtBrush = value > 1 ? emojiBrush : boundingBrush;

                        double x = tl.X - width - margin;
                        double y = startY += padding;
                        double valBarWidth = width * (value / 100);

                        if (value > 1) dc.DrawRectangle(null, boundingPen, new System.Windows.Rect(x, y, width, height));
                        dc.DrawRectangle(metricBrush, null, new System.Windows.Rect(x, y, valBarWidth, height));

                        FormattedText metricFTScaled = new FormattedText((String)upperConverter.Convert(metric, null, null, null),
                                                                System.Globalization.CultureInfo.CurrentCulture,
                                                                System.Windows.FlowDirection.LeftToRight,
                                                                metricTypeFace, metricFontSize * width / maxTxtWidth, txtBrush);

                        dc.DrawText(metricFTScaled, new System.Windows.Point(x, y));
                    }
                }


                //Draw Emoji
                if (DrawEmojis)
                {
                    if (face.Emojis.dominantEmoji != Affdex.Emoji.Unknown)
                    {
                        BitmapImage img = emojiImages[face.Emojis.dominantEmoji];
                        double imgRatio = ((br.Y - tl.Y) * 0.3) / img.Width;
                        System.Windows.Point tr = new System.Windows.Point(br.X + margin, tl.Y);
                        dc.DrawImage(img, new System.Windows.Rect(tr.X, tr.Y, img.Width * imgRatio, img.Height * imgRatio));
                    }
                }

                //Draw Appearance metrics
                if (DrawAppearance)
                {
                    BitmapImage img = appImgs[ConcatInt((int)face.Appearance.Gender, (int)face.Appearance.Glasses)];
                    double imgRatio = ((br.Y - tl.Y) * 0.3) / img.Width;
                    double imgH = img.Height * imgRatio;
                    dc.DrawImage(img, new System.Windows.Rect(br.X + margin, br.Y - imgH, img.Width * imgRatio, imgH));
                }
            }

            
            
            
            //base.OnRender(dc);
        }
Exemplo n.º 9
0
        protected override void OnRender(System.Windows.Media.DrawingContext ctx)
        {
            double x = 0;
            double y = 0;

            ctx.PushClip(new RectangleGeometry(new Rect(0, 0, this.ActualWidth, this.ActualHeight)));//restrict drawing to textbox
            ctx.DrawRectangle(Brushes.White, null, new Rect(0, 0, this.ActualWidth, this.ActualHeight));//Draw Background

            int startLine = this.firstLine;
            int count = (int)(this.ActualHeight / CodeBox.GetLineHeight());

            int lastLine = Math.Min(startLine + count, this.LineInfos.Length);
            string[] lines = this.LineInfos.Skip(startLine).Take(count).Select(f => f.TextLine).ToArray();
            FormattedText text = CodeBox.GetFormatText(string.Join(Environment.NewLine, lines), Brushes.White);

            int lineIndex = 0;
            for (int i = startLine; i < lastLine; ++i)
            {
                var lineInfo = this.LineInfos[i];
                int index = 0;

                double h = text.Height;// +text.LineHeight;
                // Draw for each segment.
                foreach (var seg in lineInfo.Segments)
                {
                    if (seg.StartIndex != index)
                    {
                        text.SetForegroundBrush(Brushes.Black, index + lineIndex, seg.StartIndex - index);
                    }
                    text.SetForegroundBrush(seg.Foreground, seg.StartIndex + lineIndex, seg.Length);

                    index = seg.StartIndex + seg.Length;
                }

                if (lineInfo.TextLine.Length != index)
                {
                    text.SetForegroundBrush(Brushes.Black, index + lineIndex, lineInfo.TextLine.Length - index);
                }

                lineIndex += lineInfo.TextLine.Length + Environment.NewLine.Length;
            }

            FormattedText hide = CodeBox.GetFormatText(text.Text.Substring(0, firstCharCol), Brushes.White);

            ctx.DrawText(text, new Point(x - hide.WidthIncludingTrailingWhitespace, y));
        }
Exemplo n.º 10
0
        internal void DrawGroundAtomWPF(structTransportCommonProperty refGroundAtom, System.Windows.Media.DrawingContext dc)
        {
            int PixelX = 0;
            int PixelY = 0;
            char ch = new char();
            string ParentName = string.Empty;
            System.Windows.Media.SolidColorBrush BackgroundBrush = new SolidColorBrush();
            System.Windows.Media.SolidColorBrush curBrush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Black);


            try
            {
                BackgroundBrush = Brushes.Red;
                curBrush.Color = System.Windows.Media.Colors.Red;
                if (refGroundAtom.isCollision)
                {
                    curBrush.Color = System.Windows.Media.Colors.Blue;
                }



                MyMainMap.ConvertCoordGroundToPixel(refGroundAtom.X, refGroundAtom.Y, ref PixelX, ref PixelY);

                ch = (char)150; //  1000;         //(char)refGroundAtom.FontKey;
				// Yinon Douchan: Added code for showing dead/injured
				int fontSize = 42;
                if (refGroundAtom.isDead)
                {
                    //curBrush.Color = System.Windows.Media.Colors.Black;
                    ch = (char)207;
                    fontSize = 16;
                }
                else if (refGroundAtom.isIncapacitated || refGroundAtom.isInjured)
                {
                    ch = (char)204;
                    fontSize = 16;
                }
				// ---------------------------------------------------
                //42

                //System.Windows.Media.FormattedText frm2 = new System.Windows.Media.FormattedText(new string(ch, 1),
                //                                    System.Globalization.CultureInfo.GetCultureInfo("en-us"),
                //                                    System.Windows.FlowDirection.LeftToRight,
                //                                    new System.Windows.Media.Typeface("Simulation Font Environmental"),
                //                                    24, curBrush);


				// Yinon Douchan: Added code for showing dead/injured
                System.Windows.Media.FormattedText frm2 = new System.Windows.Media.FormattedText(new string(ch, 1),
                                                  System.Globalization.CultureInfo.GetCultureInfo("en-us"),
                                                  System.Windows.FlowDirection.LeftToRight,
                                                  new System.Windows.Media.Typeface("Wingdings 2"),
                                                  fontSize, curBrush);
				// ---------------------------------------------------

                frm2.TextAlignment = System.Windows.TextAlignment.Center;

             // double w=  (frm2.Width / 8);
              double w = (frm2.Width / 2);
              w = 0;
              double h = frm2.Height / 2;
             //   dc.DrawText(frm2, new System.Windows.Point(PixelX, PixelY - frm2.Height / 2));
                dc.DrawText(frm2, new System.Windows.Point(PixelX + w, PixelY -h));




            }
            catch (Exception ex)
            {
            }


        }
Exemplo n.º 11
0
        protected override void DrawVisualThumbnail(System.Windows.Media.DrawingContext drawingContext, out string title, ref BitmapSource icon)
        {
            var aeroColor = (Color)Application.Current.Resources["AeroColor"];
            var aeroBrush = new SolidColorBrush(aeroColor);
            var aeroPen = new Pen(aeroBrush, 7);

            var grayBrush = new SolidColorBrush(Color.FromArgb(0x70, 255, 255, 255));
            var transparencyOverlayBrush = new SolidColorBrush(Color.FromArgb(0x22, 0, 0, 0));

            var fontFamily = (FontFamily)Application.Current.Resources["CuprumFont"];
            var typeface = new Typeface(fontFamily, FontStyles.Normal, FontWeights.Light, FontStretches.Normal);

            const int sourceTextOffset = VisualThumbnailMargin + 16 + VisualThumbnailMargin / 2;

            var sourceText = new FormattedText(Source.ApplicationName ?? "Unknown application", CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                                         typeface, 14, grayBrush);
            sourceText.MaxTextWidth = VisualThumbnailWidth - sourceTextOffset - VisualThumbnailMargin;
            sourceText.MaxTextHeight = 32;

            var imageRectangle = new Rect(-1, -1, VisualThumbnailWidth + 1 * 2, VisualThumbnailHeight + 1 * 2);

            drawingContext.DrawImage(Image, imageRectangle);
            drawingContext.DrawRectangle(transparencyOverlayBrush, aeroPen, imageRectangle);

            drawingContext.DrawImage(Source.Icon, new Rect(VisualThumbnailMargin, VisualThumbnailHeight - VisualThumbnailMargin - 16, 16, 16));
            drawingContext.DrawText(sourceText, new Point(sourceTextOffset, VisualThumbnailHeight - VisualThumbnailMargin - 16));

            title = "Image from " + Source.ApplicationName;
        }
Exemplo n.º 12
0
		protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
		{
			double fontSize;
			Typeface typeFace;
			TextAlignment alignment;
			FlowDirection flowDirection;
			bool multiline = false;
			double ypos = 3, xpos = 6;

			if (AdornedPasswordBox != null) {
				alignment = ConvertAlignment (AdornedPasswordBox.HorizontalContentAlignment);
				flowDirection = AdornedPasswordBox.FlowDirection;
				fontSize = AdornedPasswordBox.FontSize;
				typeFace = AdornedPasswordBox.FontFamily.GetTypefaces ().FirstOrDefault ();
			}
			else if (AdornedTextBox != null) {
				multiline = AdornedTextBox.AcceptsReturn;
				alignment = AdornedTextBox.ReadLocalValue (TextBox.TextAlignmentProperty) !=DependencyProperty.UnsetValue ? AdornedTextBox.TextAlignment : ConvertAlignment (AdornedTextBox.HorizontalContentAlignment);
				flowDirection = AdornedTextBox.FlowDirection;
				fontSize = AdornedTextBox.FontSize;
				typeFace = AdornedTextBox.FontFamily.GetTypefaces ().FirstOrDefault ();
			} else {
				alignment = ConvertAlignment (AdornedComboBox.HorizontalContentAlignment);
				flowDirection = AdornedComboBox.FlowDirection;
				fontSize = AdornedComboBox.FontSize;
				typeFace = AdornedComboBox.FontFamily.GetTypefaces ().FirstOrDefault ();
			}
			var text = new System.Windows.Media.FormattedText (PlaceholderText ?? "", CultureInfo.CurrentCulture, flowDirection, typeFace, fontSize, System.Windows.Media.Brushes.LightGray);


			if (!multiline)
				ypos = (RenderSize.Height - text.Height) / 2;

			switch (alignment) {
			case TextAlignment.Center:
				xpos = (RenderSize.Width - text.Width) * 0.5;
				break;
			case TextAlignment.Right:
				xpos = (RenderSize.Width - text.Width) - 6;
				break;
			}

			drawingContext.DrawText (text, new System.Windows.Point (xpos, ypos));
		}
Exemplo n.º 13
0
        protected override void DrawVisualThumbnail(System.Windows.Media.DrawingContext drawingContext, out string title, ref BitmapSource icon)
        {
            var aeroColor = (Color)Application.Current.Resources["AeroColor"];
            var aeroBrush = new SolidColorBrush(aeroColor);
            var aeroPen = new Pen(aeroBrush, 7);

            var grayBrush = new SolidColorBrush(Color.FromArgb(255, 0xaf, 0xaf, 0xaf));

            var fontFamily = (FontFamily)Application.Current.Resources["CuprumFont"];
            var typeface = new Typeface(fontFamily, FontStyles.Normal, FontWeights.Light, FontStretches.Normal);

            const int sourceTextOffset = VisualThumbnailMargin;

            var sourceText = new FormattedText(Name, CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                                         typeface, 14, grayBrush);
            sourceText.MaxTextWidth = VisualThumbnailWidth - sourceTextOffset - VisualThumbnailMargin;
            sourceText.MaxTextHeight = 32;

            var imageRectangle = new Rect(VisualThumbnailWidth / 2 - 64 / 2, VisualThumbnailHeight / 2 - 64 / 2, 64, 64);

            drawingContext.DrawRectangle(Brushes.White, aeroPen, new Rect(-1, -1, VisualThumbnailWidth + 2, VisualThumbnailHeight + 2));
            drawingContext.DrawImage(Icon, imageRectangle);

            drawingContext.DrawText(sourceText, new Point(sourceTextOffset, VisualThumbnailHeight - VisualThumbnailMargin - 16));

            title = Name + " from " + Source.ApplicationName;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Renders the current line numbers to the margin.
        /// </summary>
        /// <param name="drawingContext">The current drawing context used to write line numbers</param>
        /// <history>
        /// [Curtis_Beard]		04/08/2015	ADD: update RichTextBox to AvalonEdit
        /// </history>
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            TextView textView = this.TextView;
             Size renderSize = this.RenderSize;
             if (textView != null && textView.VisualLinesValid)
             {
            var foreground = (Brush)GetValue(Control.ForegroundProperty);  // non-match line
            var matchForeground = (Brush)GetValue(Control.BackgroundProperty); // match line

            foreach (VisualLine line in textView.VisualLines)
            {
               int lineNumber = line.FirstDocumentLine.LineNumber;
               bool isMatch = false;
               if (LineNumbers != null)
               {
                  // all line numbers are specified
                  if (LineNumbers.Count == this.Document.LineCount)
                  {
                     lineNumber = -1;

                     if (line.FirstDocumentLine.LineNumber - 1 < LineNumbers.Count)
                     {
                        lineNumber = LineNumbers[line.FirstDocumentLine.LineNumber - 1].Number;
                        isMatch = LineNumbers[line.FirstDocumentLine.LineNumber - 1].HasMatch;
                     }
                  }
                  else
                  {
                     // look for only a given line number since not all are specified
                     LineNumber lineNum = (from n in LineNumbers where n.Number == line.FirstDocumentLine.LineNumber select n).FirstOrDefault();
                     if (lineNum != null)
                     {
                        lineNumber = lineNum.Number;
                        isMatch = lineNum.HasMatch;
                     }
                  }
               }

               FormattedText text = CreateFormattedText(
                  this,
                  lineNumber > -1
                     ? lineNumber.ToString(CultureInfo.CurrentCulture)
                     : string.Empty,
                     typeface, emSize, isMatch ? matchForeground : foreground
               );
               drawingContext.DrawText(text, new Point(renderSize.Width - text.Width,
                                                       line.VisualTop - textView.VerticalOffset));
            }
             }
        }
Exemplo n.º 15
0
        // Handles drawing the ToolTip.
        private void toolTip_Draw(System.Object sender,
            System.Windows.Forms.DrawToolTipEventArgs e)
        {
            // Draw the ToolTip differently depending on which
            // control this ToolTip is for.
            // Draw a custom 3D border if the ToolTip is for button1.
            //if (e.AssociatedControl == fpPictureBox1)
            {
                // Draw the standard background.
                e.DrawBackground();

                // Draw the custom border to appear 3-dimensional.
                e.Graphics.DrawLines(SystemPens.ControlLightLight, new Point[] {
                    new Point (0, e.Bounds.Height - 1),
                    new Point (0, 0),
                    new Point (e.Bounds.Width - 1, 0)
                });
                e.Graphics.DrawLines(SystemPens.ControlDarkDark, new Point[] {
                    new Point (0, e.Bounds.Height - 1),
                    new Point (e.Bounds.Width - 1, e.Bounds.Height - 1),
                    new Point (e.Bounds.Width - 1, 0)
                });

                // Specify custom text formatting flags.
                TextFormatFlags sf = TextFormatFlags.VerticalCenter |
                                     TextFormatFlags.HorizontalCenter |
                                     TextFormatFlags.NoFullWidthCharacterBreak;

                // Draw the standard text with customized formatting options.
                e.DrawText(sf);
            }
            /*
            // Draw a custom background and text if the ToolTip is for button2.
            else if (e.AssociatedControl == fpPictureBox2)
            {
                // Draw the custom background.
                e.Graphics.FillRectangle(SystemBrushes.ActiveCaption, e.Bounds);

                // Draw the standard border.
                e.DrawBorder();

                // Draw the custom text.
                // The using block will dispose the StringFormat automatically.
                using (StringFormat sf = new StringFormat())
                {
                    sf.Alignment = StringAlignment.Center;
                    sf.LineAlignment = StringAlignment.Center;
                    sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None;
                    sf.FormatFlags = StringFormatFlags.NoWrap;
                    using (Font f = new Font("Tahoma", 9))
                    {
                        e.Graphics.DrawString(e.ToolTipText, f,
                            SystemBrushes.ActiveCaptionText, e.Bounds, sf);
                    }
                }
            }
            // Draw the ToolTip using default values if the ToolTip is for button3.
            else if (e.AssociatedControl == fpPictureBox3)

            {
                e.DrawBackground();
                e.DrawBorder();
                e.DrawText();
            }
            */
        }
Exemplo n.º 16
0
 protected override void OnRender(System.Windows.Media.DrawingContext dc)
 {
    dc.DrawRectangle(Brushes.White, null, new Rect(this.RenderSize));
    dc.DrawText(new FormattedText("text", CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, new Typeface("Segoe"), 12, Brushes.Black), new Point(0, 0));
    base.OnRender(dc);
 }
Exemplo n.º 17
0
 //1、重写OnRender方法
 //2、利用DrawingContext实例进行绘制操作
 //3、值得注意的是以下几点:
 //      1,在我们的代码中,我们不能直接调用OnRender方法,它将被系统异步调用进行布局和绘制(这与Win32不同)。
 //      2,我们不能直接创建DrawingContext实例,但我们可以利用 DrawingGroup.Open 和DrawingVisual.RenderOpen来得到。
 //      3,我们的绘制不是实时的,事实上我们的绘制将被保存到一个绘制指令集中被图形 系统在某个时候调用。
 protected override void OnRender(System.Windows.Media.DrawingContext dc)
 {
     base.OnRender(dc);
     dc.DrawRectangle(Brushes.Bisque, new Pen(Brushes.Brown, 2), new Rect(new Point(50, 50), new Size(100, 50)));
     dc.DrawText(new FormattedText("My UIElement", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Tahoma"), 20, Brushes.Black), new Point(20, 50));
 }
Exemplo n.º 18
0
 void ToolTip_Draw(object sender, System.Windows.Forms.DrawToolTipEventArgs e)
 {
     e.DrawBackground();
     e.DrawText();
 }
Exemplo n.º 19
0
        protected override void OnRender(System.Windows.Media.DrawingContext dc)
        {
            base.OnRender(dc);
            //ImageSource trumpie = new BitmapImage( new Uri( Directory.GetCurrentDirectory()+"\\Resources\\trumpman.jpg") );
            //dc.DrawImage( trumpie, new Rect(0, 0, _tileSize, _tileSize ) );

            // draw blocks:
            foreach ( GamePoint p in BoardBlocks.Keys ){
                BlockType bt = BoardBlocks[p];
                dc.DrawImage(BlockBitmaps[bt], new Rect(p.X*_tileSize, p.Y*_tileSize, _tileSize, _tileSize));

                drawOutline(Color.FromRgb(0x00, 0x00, 0x00),p,dc);
            }

            // draw lines:
            foreach ( Color c in BoardLines.Keys ){
                Color transparent = Color.FromArgb(0x40, c.R, c.G, c.B);
                Brush brush = new SolidColorBrush( transparent );
                Pen   pen   = new Pen( brush, _tileSize/2 );

                foreach (List<GamePoint> line in BoardLines[c]){
                    for (int i = 1; i < line.Count; i++){
                        Point a = new Point(_tileSize * line[i - 1].X + _tileSize / 2, _tileSize * line[i - 1].Y + _tileSize / 2);
                        Point b = new Point(_tileSize * line[i].X + _tileSize / 2, _tileSize * line[i].Y + _tileSize / 2);
                        dc.DrawLine(pen, a, b);
                    }
                }
            }

            // draw stations:
            foreach (Color c in BoardStations.Keys){
                Color transparent = Color.FromArgb(0x80, c.R, c.G, c.B);
                Brush brush = new SolidColorBrush(transparent);
                Pen pen = new Pen(brush, 1.0);

                foreach ( GamePoint p in BoardStations[c] ){
                    Point center = new Point(p.X * _tileSize + _tileSize / 2, p.Y * _tileSize + _tileSize / 2);
                    dc.DrawEllipse( brush, pen, center, ((double)_tileSize)/4.0, ((double)_tileSize)/4.0 );
                }
            }

            // draw pieces:
            foreach (GamePoint p in BoardPieces.Keys){
                PieceType pt = BoardPieces[p];
                if ( p != GamePoint.Error )
                    dc.DrawImage(PieceBitmaps[pt], new Rect(p.X * _tileSize, p.Y * _tileSize, _tileSize, _tileSize));
            }

            // draw marked squares:
            foreach (KeyValuePair<GamePoint, Color> kvp in MarkedSquares)
            {
                drawOutline(kvp.Value, kvp.Key, dc);
            }

            // draw selection:
            if (BoardSelection != GamePoint.Error)
            {
                drawOutline(Color.FromRgb(0xff, 0xff, 0x00), BoardSelection, dc);
            }

            // draw text:
            foreach (GamePoint p in BoardText.Keys){
                Brush back = new SolidColorBrush(Color.FromRgb(0x00, 0x00, 0x00));
                Brush b = new SolidColorBrush(Color.FromRgb(0xff, 0xff, 0x00));

                System.Globalization.CultureInfo cinf = new System.Globalization.CultureInfo(0x0409);
                Typeface tf = new Typeface("Verdana");
                double size = 12.0;
                FormattedText btext = new FormattedText(BoardText[p], cinf, FlowDirection.LeftToRight, tf, size, back);
                FormattedText ftext = new FormattedText(BoardText[p], cinf, FlowDirection.LeftToRight, tf, size, b);
                Point text_centerpos = new Point( TileSize*(p.X+0.5), TileSize*(p.Y+0.5) );
                Point draw_origin = new Point( text_centerpos.X-ftext.Width/2, text_centerpos.Y-ftext.Height/2 );

                int text_border = 1;
                dc.DrawText(btext, new Point(draw_origin.X + text_border, draw_origin.Y + text_border));
                dc.DrawText(btext, new Point(draw_origin.X + text_border, draw_origin.Y - text_border));
                dc.DrawText(btext, new Point(draw_origin.X - text_border, draw_origin.Y + text_border));
                dc.DrawText(btext, new Point(draw_origin.X - text_border, draw_origin.Y - text_border));

                dc.DrawText( ftext, draw_origin );
            }
        }
Exemplo n.º 20
0
 /// <summary>
 /// Called to draw on screen
 /// </summary>
 /// <param name="drawingContext">The drawind context in which we can draw</param>
 protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
 {
     FormattedText text = new FormattedText(OverlayedText, Thread.CurrentThread.CurrentUICulture,
         FlowDirection.LeftToRight, Typeface, FontSize, ForeGround);
     drawingContext.DrawText(text, startPoint);
     drawingContext.DrawRectangle(Color, Border, new Rect(startPoint, DesiredSize));
     base.OnRender(drawingContext);
 }
Exemplo n.º 21
0
        // Handles drawing the ToolTip.
        private void toolTip_Draw(System.Object sender,
            System.Windows.Forms.DrawToolTipEventArgs e)
        {
            // Draw the ToolTip differently depending on which
            // control this ToolTip is for.
            // Draw a custom 3D border if the ToolTip is for button1.
            //if (e.AssociatedControl == fpPictureBox1)
            {
                // Draw the standard background.
                e.DrawBackground();

                // Draw the custom border to appear 3-dimensional.
                e.Graphics.DrawLines(SystemPens.ControlLightLight, new Point[] {
                    new Point (0, e.Bounds.Height - 1),
                    new Point (0, 0),
                    new Point (e.Bounds.Width - 1, 0)
                });
                e.Graphics.DrawLines(SystemPens.ControlDarkDark, new Point[] {
                    new Point (0, e.Bounds.Height - 1),
                    new Point (e.Bounds.Width - 1, e.Bounds.Height - 1),
                    new Point (e.Bounds.Width - 1, 0)
                });

                // Specify custom text formatting flags.
                TextFormatFlags sf = TextFormatFlags.VerticalCenter |
                                     TextFormatFlags.HorizontalCenter |
                                     TextFormatFlags.NoFullWidthCharacterBreak;

                // Draw the standard text with customized formatting options.
                e.DrawText(sf);
            }
        }
Exemplo n.º 22
0
 protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
 {
     for (int i = 0; i < Steps + 1; ++i)
     {
         var value = (Maximum - Minimum) / Steps * i + Minimum;
         var location = (MaximumAngle - MinimumAngle) / Steps * i + MinimumAngle;
         var rad = (90 - location) * Math.PI / 180;
         while (rad > Math.PI * 2) rad -= Math.PI * 2;
         while (rad < 0) rad += Math.PI * 2;
         var point = new Point(
             ActualWidth / 2 + ActualWidth / 2 * Math.Cos(rad),
             ActualHeight / 2 - ActualHeight / 2 * Math.Sin(rad));
         drawingContext.DrawRectangle(Brushes.Red, null, new Rect(point.X - 2, point.Y - 2, 4, 4));
         var ft = new FormattedText(value.ToString(ScaleFormat),
                 CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight,
                 new Typeface("Arial"), 15, Brushes.Red);
         if (Math.Abs(point.X - ActualWidth / 2) < 1)
         {
             point = new Point(point.X - ft.Width / 2, point.Y);
         }
         else if (point.X > ActualWidth / 2)
         {
             point = new Point(point.X - ft.Width, point.Y);
         }
         drawingContext.DrawText(ft, point);
     }
 }
Exemplo n.º 23
0
        protected override void OnRender(System.Windows.Media.DrawingContext dc)
        {
            if (game == null) return;
            if (ImageCache == null) return;
            bool needsCheckerBoard = true;
            if (ImageCache.Contains("bg"))
            {
                dc.DrawImage(ImageCache["bg"], new Rect(0, 0, Width, Height));
                needsCheckerBoard = false;
            }

            Coords size = ict.GameToBoard(game.Size);

            for (int i = 0; i < size[0]; i++)
            {
                for (int j = 0; j < size[1]; j++)
                {
                    int myj = size[1] - j - 1;
                    Coords c = new Coords(i+1, j+1);
                    if (highlightCoord.Contains(c))
                    {
                        dc.DrawRectangle(Brushes.LightBlue, null, new Rect(i * 30, myj * 30, 30, 30));
                    }
                    else if (needsCheckerBoard)
                    {
                        Brush b = ((i + j) % 2) == 0 ? Brushes.Brown : Brushes.BurlyWood;
                        dc.DrawRectangle(b, null, new Rect(i * 30, myj * 30, 30, 30));
                    }
                }
            }

            foreach (var kvp in game.GetPieces(GetGameState()))
            {
                Coords c = ict.GameToBoard(kvp.Key);
                Piece p = kvp.Value;
                string player = p.Owner.ID.ToString();
                string type = p.Type;
                int x = (c[0]-1) * 30;
                int y = (size[1]-c[1]) * 30;

                if (highlightPiece.Contains(p))
                {
                    dc.DrawRectangle(Brushes.LightBlue, null, new Rect(x, y, 30, 30));
                }

                dc.DrawImage(ImageCache[type + player], new System.Windows.Rect(x, y, 30, 30));
            }

            for (int i = 0; i < size[0]; i++)
            {
                for (int j = 0; j < size[1]; j++)
                {
                    int myj = size[1] - j - 1;
                    Coords c = new Coords(i + 1, j + 1);
                    if (PrintGameCoords && ict.IsValidBoardCoord(c))
                    {
                        string str = c.ToString() + "\n" + ict.BoardToGame(c);
                        dc.DrawText(new FormattedText(
                            str,
                            CultureInfo.CurrentCulture,
                            FlowDirection.LeftToRight,
                            new Typeface("Consolas"),
                            8,
                            Brushes.Black),
                            new Point(i * 30, myj * 30));

                    }
                }
            }
        }