// Position a label at the indicated point.
        public void DrawText(Canvas can, string text, Point location, double angle, double font_size, HorizontalAlignment halign, VerticalAlignment valign)
        {
            // Make the label.
            Label label = new Label();
            label.Content = text;
            label.FontSize = font_size;
            label.FontWeight = FontWeights.Bold;
            can.Children.Add(label);

            // Rotate if desired.
            if (angle != 0)
                label.LayoutTransform = new RotateTransform(angle);

            // Position the label.
            label.Measure(new Size(double.MaxValue, double.MaxValue));

            double x = location.X;
            if (halign == HorizontalAlignment.Center)
                x -= label.DesiredSize.Width / 2;
            else if (halign == HorizontalAlignment.Right)
                x -= label.DesiredSize.Width;
            Canvas.SetLeft(label, x);

            double y = location.Y;
            if (valign == VerticalAlignment.Center)
                y -= label.DesiredSize.Height / 2;
            else if (valign == VerticalAlignment.Bottom)
                y -= label.DesiredSize.Height;
            Canvas.SetTop(label, y);
        }
Exemplo n.º 2
0
        public SparkleEventLog()
        {
            Title                 = "Recent Changes";
            Height                = 640;
            Width                 = 480;
            ResizeMode            = ResizeMode.NoResize;
            Background            = new SolidColorBrush (Color.FromRgb (240, 240, 240));
            AllowsTransparency    = false;
            WindowStartupLocation = WindowStartupLocation.CenterScreen;

            WriteOutImages ();

            Label size_label = new Label () {
                Content    = "Size:",
                FontWeight = FontWeights.Bold
            };

            this.size_label_value = new Label () {
                Content = Controller.Size
            };

            size_label.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
            Rect size_label_rect = new Rect (size_label.DesiredSize);

            Label history_label = new Label () {
                Content    = "History:",
                FontWeight = FontWeights.Bold
            };

            this.history_label_value = new Label () {
                Content = Controller.HistorySize,
            };

            history_label.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
            Rect history_label_rect = new Rect (history_label.DesiredSize);

            Shapes.Rectangle line = new Shapes.Rectangle () {
                Width  = Width,
                Height = 1,
                Fill   = new SolidColorBrush (Color.FromRgb (223, 223, 223))
            };

            Shapes.Rectangle background = new Shapes.Rectangle () {
                Width  = Width,
                Height = Height,
                Fill   = new SolidColorBrush (Color.FromRgb (250, 250, 250))
            };

            this.web_browser = new WebBrowser () {
                Width  = Width - 6,
                Height = Height - 36 - 11
            };

            this.web_browser.ObjectForScripting = new SparkleScriptingObject ();

            spinner = new SparkleSpinner (22);

            // Disable annoying IE clicking sound
            CoInternetSetFeatureEnabled (21, 0x00000002, true);

            this.canvas = new Canvas ();
            Content     = this.canvas;

            this.canvas.Children.Add (size_label);
            Canvas.SetLeft (size_label, 24);
            Canvas.SetTop (size_label, 4);

            this.canvas.Children.Add (this.size_label_value);
            Canvas.SetLeft (this.size_label_value, 22 + size_label_rect.Width);
            Canvas.SetTop (this.size_label_value, 4);

            this.canvas.Children.Add (history_label);
            Canvas.SetLeft (history_label, 130);
            Canvas.SetTop (history_label, 4);

            this.canvas.Children.Add (this.history_label_value);
            Canvas.SetLeft (this.history_label_value, 130 + history_label_rect.Width);
            Canvas.SetTop (this.history_label_value, 4);

            this.canvas.Children.Add (background);
            Canvas.SetLeft (background, 0);
            Canvas.SetTop (background, 36);

            this.canvas.Children.Add (spinner);
            Canvas.SetLeft (spinner, (Width / 2) - 15);
            Canvas.SetTop (spinner, (Height / 2) - 22);

            this.canvas.Children.Add (line);
            Canvas.SetLeft (line, 0);
            Canvas.SetTop (line, 35);

            Closing += Close;

            Controller.ShowWindowEvent += delegate {
               Dispatcher.Invoke ((Action) delegate {
                    Show ();
                    Activate ();
                    BringIntoView ();

                    UpdateContent (null);
                    UpdateChooser (null);
                });
            };

            Controller.HideWindowEvent += delegate {
                Dispatcher.Invoke ((Action) delegate {
                    Hide ();

                    if (this.canvas.Children.Contains (this.web_browser))
                        this.canvas.Children.Remove (this.web_browser);
                });
            };

            Controller.UpdateSizeInfoEvent += delegate (string size, string history_size) {
                Dispatcher.Invoke ((Action) delegate {
                    this.size_label_value.Content = size;
                    this.size_label_value.UpdateLayout ();

                    this.history_label_value.Content = history_size;
                    this.history_label_value.UpdateLayout ();
                });
            };

            Controller.UpdateChooserEvent += delegate (string [] folders) {
                Dispatcher.Invoke ((Action) delegate {
                    UpdateChooser (folders);
                });
            };

            Controller.UpdateContentEvent += delegate (string html) {
                Dispatcher.Invoke ((Action) delegate {
                    UpdateContent (html);
                });
            };

            Controller.ContentLoadingEvent += delegate {
                this.spinner.Start ();

                if (this.canvas.Children.Contains (this.web_browser))
                    this.canvas.Children.Remove (this.web_browser);
            };
        }
Exemplo n.º 3
0
        /// <summary>
        /// Redraws the whole barcode
        /// </summary>
        public override void RedrawAll()
        {
            Children.Clear();

            double actualWidth = ActualWidth;
            double actualHeight = ActualHeight;
            if ((double.IsNaN(actualWidth)) || (actualWidth <= 0)) actualWidth = Width;
            if ((double.IsNaN(actualHeight)) || (actualHeight <= 0)) actualHeight = Height;
            if ((double.IsNaN(actualWidth)) || (actualWidth <= 0)) return;
            if ((double.IsNaN(actualHeight)) || (actualHeight <= 0)) return;

            Rect rectClient = new Rect(0, 0, actualWidth, actualHeight);

            if (Value == null) return;

            string text = InlineHasValue.FormatValue(Value, Format);
            if (String.IsNullOrEmpty(text)) return;

            List<BarcodeCharInfo> charInfo;
            List<int> codeSequence = GenerateCodeSequence(text, out charInfo);
            if (codeSequence.Count <= 0) return;

            // override shown text
            if ((Text != null) && (!String.IsNullOrEmpty(Text))) text = Text;

            int checkSum = 0;
            double left = 0;

            // measure barcode first
            double startCharWidth = 0;
            for (int i = 0; i < codeSequence.Count; i++)
            {
                double charWidth = DrawCharByIndex(null, left, 0, 1, codeSequence[i]);
                if (i == 0) startCharWidth = charWidth;
                left += charWidth;

                if (i == 0) checkSum = codeSequence[0]; else checkSum += codeSequence[i] * i;
            }
            double barcodeDataWidth = left - startCharWidth;

            // draw check sum
            left += DrawCharByIndex(null, left, 0, 1, (checkSum % 103)); // Check Sum

            // draw stop char
            left += DrawCharByIndex(null, left, 0, 1, 106); // Stop

            double barcodeWidth = left;

            Canvas canvas = new Canvas();

            // show barcode text
            Label labelText = null;
            double textHeight = 0;
            decimal labelScale = 1;
            TransformGroup tgl = null;
            if (ShowText)
            {
                labelText = new Label();
                labelText.Content = text;
                labelText.Padding = new Thickness(0.25); // HACK: something is not right here
                labelText.FontFamily = FontFamily;
                labelText.FontStretch = FontStretch;
                labelText.FontStyle = FontStyle;
                labelText.FontWeight = FontWeight;
                labelText.FontSize = 1;
                labelText.Measure(new Size(actualWidth, actualHeight));

                labelScale = (decimal)rectClient.Width / (decimal)barcodeWidth * (decimal)barcodeDataWidth / (decimal)labelText.DesiredSize.Width;
                textHeight = labelText.DesiredSize.Height * (double)labelScale;

                // set new size of barcode text
                tgl = new TransformGroup();
                tgl.Children.Add(new ScaleTransform((double)labelScale, (double)labelScale));
                labelText.RenderTransform = tgl;
            }

            // draw barcode now
            left = 0;
            for (int i = 0; i < codeSequence.Count; i++)
            {
                double lineHeight = 1;
                double th = 0;
                if (labelText != null) th = labelText.DesiredSize.Height;
                if ((ShowText) && (i > 0)) lineHeight = (rectClient.Height - (double)labelScale * th / 2) / rectClient.Height;

                double charWidth = DrawCharByIndex(canvas, left, 0, lineHeight, codeSequence[i]);
                left += charWidth;
            }

            // draw check sum
            left += DrawCharByIndex(canvas, left, 0, 1, (checkSum % 103)); // Check Sum

            // draw stop char
            left += DrawCharByIndex(canvas, left, 0, 1, 106); // Stop

            // move text to right place
            if ((ShowText) && (labelText != null))
            {
                tgl.Children.Add(new TranslateTransform(startCharWidth * rectClient.Width / left, rectClient.Height - textHeight));
                Children.Add(labelText);
            }

            TransformGroup tg = new TransformGroup();
            tg.Children.Add(new ScaleTransform(rectClient.Width / left, rectClient.Height - textHeight / 2));
            tg.Children.Add(new TranslateTransform(rectClient.Left, rectClient.Top));
            canvas.RenderTransform = tg;
            Children.Add(canvas);
        }
Exemplo n.º 4
0
        public PryanetEventLog()
        {
            Title              = "Recent Changes";
            Height             = 640;
            Width              = 480;
            ResizeMode         = ResizeMode.NoResize; // TODO
            Background         = new SolidColorBrush (Color.FromRgb (240, 240, 240));
            AllowsTransparency = false;
            Icon               = PryanetUIHelpers.GetImageSource ("pryanetshare-app", "ico");

            int x = (int) (SystemParameters.PrimaryScreenWidth * 0.61);
            int y = (int) (SystemParameters.PrimaryScreenHeight * 0.5 - (Height * 0.5));

            WindowStartupLocation = WindowStartupLocation.Manual;
            Left = x;
            Top = y;

            WriteOutImages ();

            Label size_label = new Label () {
                Content    = "Size:",
                FontWeight = FontWeights.Bold
            };

            this.size_label_value = new Label () {
                Content = Controller.Size
            };

            size_label.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
            Rect size_label_rect = new Rect (size_label.DesiredSize);

            Label history_label = new Label () {
                Content    = "History:",
                FontWeight = FontWeights.Bold
            };

            this.history_label_value = new Label () {
                Content = Controller.HistorySize,
            };

            history_label.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
            Rect history_label_rect = new Rect (history_label.DesiredSize);

            Shapes.Rectangle line = new Shapes.Rectangle () {
                Width  = Width,
                Height = 1,
                Fill   = new SolidColorBrush (Color.FromRgb (223, 223, 223))
            };

            Shapes.Rectangle background = new Shapes.Rectangle () {
                Width  = Width,
                Height = Height,
                Fill   = new SolidColorBrush (Color.FromRgb (250, 250, 250))
            };

            this.web_browser = new WebBrowser () {
                Width  = Width - 6,
                Height = Height - 64
            };

            this.web_browser.ObjectForScripting = new PryanetScriptingObject ();

            spinner = new PryanetSpinner (22);

            // Disable annoying IE clicking sound
            CoInternetSetFeatureEnabled (21, 0x00000002, true);

            this.canvas = new Canvas ();
            Content     = this.canvas;

            this.canvas.Children.Add (size_label);
            Canvas.SetLeft (size_label, 24);
            Canvas.SetTop (size_label, 4);

            this.canvas.Children.Add (this.size_label_value);
            Canvas.SetLeft (this.size_label_value, 22 + size_label_rect.Width);
            Canvas.SetTop (this.size_label_value, 4);

            this.canvas.Children.Add (history_label);
            Canvas.SetLeft (history_label, 130);
            Canvas.SetTop (history_label, 4);

            this.canvas.Children.Add (this.history_label_value);
            Canvas.SetLeft (this.history_label_value, 130 + history_label_rect.Width);
            Canvas.SetTop (this.history_label_value, 4);

            this.canvas.Children.Add (background);
            Canvas.SetLeft (background, 0);
            Canvas.SetTop (background, 36);

            this.canvas.Children.Add (spinner);
            Canvas.SetLeft (spinner, (Width / 2) - 15);
            Canvas.SetTop (spinner, (Height / 2) - 22);

            this.canvas.Children.Add (line);
            Canvas.SetLeft (line, 0);
            Canvas.SetTop (line, 35);

            Closing += Close;

            Controller.ShowWindowEvent += delegate {
               Dispatcher.BeginInvoke ((Action) delegate {
                    Show ();
                    Activate ();
                    BringIntoView ();
                });
            };

            Controller.HideWindowEvent += delegate {
                Dispatcher.BeginInvoke ((Action) delegate {
                    Hide ();

                    if (this.canvas.Children.Contains (this.web_browser))
                        this.canvas.Children.Remove (this.web_browser);
                });
            };

            Controller.UpdateSizeInfoEvent += delegate (string size, string history_size) {
                Dispatcher.BeginInvoke ((Action) delegate {
                    this.size_label_value.Content = size;
                    this.size_label_value.UpdateLayout ();

                    this.history_label_value.Content = history_size;
                    this.history_label_value.UpdateLayout ();
                });
            };

            Controller.UpdateChooserEvent += delegate (string [] folders) {
                Dispatcher.BeginInvoke ((Action) delegate {
                    UpdateChooser (folders);
                });
            };

            Controller.UpdateChooserEnablementEvent += delegate (bool enabled) {
                Dispatcher.BeginInvoke ((Action) delegate {
                    this.combo_box.IsEnabled = enabled;
                });
            };

            Controller.UpdateContentEvent += delegate (string html) {
                Dispatcher.BeginInvoke ((Action) delegate {
                    UpdateContent (html);
                });
            };

            Controller.ContentLoadingEvent += delegate {
                Dispatcher.BeginInvoke ((Action) delegate {
                    this.spinner.Start ();

                    if (this.canvas.Children.Contains (this.web_browser))
                        this.canvas.Children.Remove (this.web_browser);
                });
            };

            Controller.ShowSaveDialogEvent += delegate (string file_name, string target_folder_path) {
                Dispatcher.BeginInvoke ((Action) delegate {
                    SaveFileDialog dialog = new SaveFileDialog () {
                        FileName         = file_name,
                        InitialDirectory = target_folder_path,
                        Title            = "Restore from History",
                        DefaultExt       = "." + Path.GetExtension (file_name),
                        Filter           = "All Files|*.*"
                    };

                    Nullable<bool> result = dialog.ShowDialog (this);

                    if (result == true)
                        Controller.SaveDialogCompleted (dialog.FileName);
                    else
                        Controller.SaveDialogCancelled ();
                });
            };
        }
    CreateHeaderOrFooterLabel
    (
        String sLabelText,
        Double dLabelWidth,
        System.Drawing.Font oLabelFont,
        out Label oLabel,
        out Double dLabelHeight
    )
    {
        Debug.Assert(dLabelWidth > 0);
        Debug.Assert(oLabelFont != null);
        AssertValid();

        if (sLabelText == null)
        {
            oLabel = null;
            dLabelHeight = 0;
            return;
        }

        // Use a TextBlock to provide wrapping.

        TextBlock oTextBlock = new TextBlock();
        oTextBlock.Text = sLabelText;
        oTextBlock.TextWrapping = TextWrapping.Wrap;
        WpfGraphicsUtil.SetTextBlockFont(oTextBlock, oLabelFont);

        oLabel = new Label();
        oLabel.Background = HeaderFooterBackgroundBrush;
        oLabel.MaxWidth = dLabelWidth;
        oLabel.Content = oTextBlock;

        // Determine the height of the control.  This will likely be a floating
        // point number.

        oLabel.Measure( new Size(dLabelWidth, Double.PositiveInfinity) );

        // The label height must be an integer.  If it's not an integer, any
        // Image controls contained in the parent StackPanel will be distorted
        // because they don't fall on a pixel boundary.

        oLabel.Height = Math.Ceiling(oLabel.DesiredSize.Height);
        oLabel.Measure( new Size(dLabelWidth, Double.PositiveInfinity) );

        dLabelHeight = oLabel.DesiredSize.Height;
    }
Exemplo n.º 6
0
        public void createNewConcept(double x, double y, String type, String name, String attributs, String methods)
        {
            if (classes == null)
                classes = new List<Classe>();

            Label nam, var, fun;
            var = new Label
            {
                Content = attributs == "" ? "attributs" : attributs,
                FontSize = 16,
                Margin = new Thickness(x, y, 0, 0),
            };

            fun = new Label
            {
                Content = methods == "" ? "methodes" : methods,
                FontSize = 16,
                Margin = new Thickness(x, y, 0, 0)
            };

            nam = new Label
            {
                Content = name == "" ? "classe : " + classes.Count : name,
                FontSize = 16,
                Margin = new Thickness(x, y, 0, 0)
            };

            nam.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
            nam.Arrange(new Rect(nam.DesiredSize));

            double myWidth = nam.ActualWidth;
            double myHeight = nam.ActualHeight + LABEL_SPACE;

            Classe clas = new Classe();
            double i = 0;

            if (type.Contains("classe"))
                i = 0.5;
            else
                i = 4;

            clas.Cadres = new List<Rectangle>();
            clas.Cadres.Add(generateMyRect(myWidth + LABEL_SPACE*2, myHeight, x - LABEL_SPACE, y, i));
            clas.Cadres.Add(generateMyRect(myWidth + LABEL_SPACE * 2, myHeight, x - LABEL_SPACE, y + myHeight + 4, i));
            clas.Cadres.Add(generateMyRect(myWidth + LABEL_SPACE * 2, myHeight, x - LABEL_SPACE, y + myHeight * 2 + 8, i));
            clas.Cadres.Add(generateMyRect(LABEL_SPACE * 4, LABEL_SPACE * 4, x - LABEL_SPACE, y - LABEL_SPACE * 4, 0.5));
            clas.Cadres.Add(generateMyRect(LABEL_SPACE * 4, LABEL_SPACE * 4, x + LABEL_SPACE*3, y - LABEL_SPACE * 4, 0.5));
            //clas.Cadres.Add(generateMyRect(myWidth + LABEL_SPACE * 2, myHeight, x - LABEL_SPACE, y, i));

            clas.Cadres[3].Fill = new SolidColorBrush(Colors.Red);
            clas.Cadres[4].Fill = new SolidColorBrush(Colors.Blue);

            clas.Nom = nam;
            var.Margin = clas.Cadres[1].Margin;
            clas.Variables = var;
            fun.Margin = clas.Cadres[2].Margin;
            clas.Fonctions = fun;

            clas.Type = type;

            clas.Nom_tb = generateTextBox(myWidth + LABEL_SPACE * 2
                                        , myHeight
                                        , clas.Cadres[0].Margin
                                        , clas.Nom.Content.ToString());

            clas.Variables_tb = generateRichTextBox(myWidth + LABEL_SPACE * 2
                                                    , myHeight
                                                    , clas.Cadres[1].Margin);

            clas.Fonctions_tb = generateRichTextBox(myWidth + LABEL_SPACE * 2
                                                    , myHeight
                                                    , clas.Cadres[2].Margin);

            classes.Add(clas);

            back.Children.Add(clas.Cadres[0]);
            back.Children.Add(clas.Cadres[1]);
            back.Children.Add(clas.Cadres[2]);
            back.Children.Add(clas.Cadres[3]);
            back.Children.Add(clas.Cadres[4]);
            back.Children.Add(clas.Nom);
            back.Children.Add(clas.Nom_tb);
            back.Children.Add(clas.Variables);
            back.Children.Add(clas.Variables_tb);
            back.Children.Add(clas.Fonctions);
            back.Children.Add(clas.Fonctions_tb);
        }
Exemplo n.º 7
0
        protected void DrawText(string text, Point sp, Point ep, double font_size)
        {
            Label label = new Label();
            label.Content = text;
            label.FontSize = font_size;
            mCanvas.Children.Add(label);

            Point location = new Point((sp.X + ep.X) / 2, (sp.Y + ep.Y) / 2);

            double angle = (Math.Atan2(sp.Y - ep.Y, sp.X - ep.X) + Math.PI) * 180 / Math.PI;

            if (angle != 0)
                label.LayoutTransform = new RotateTransform(angle);
            label.Measure(new Size(double.MaxValue, double.MaxValue));

            double x = location.X;
            x -= label.DesiredSize.Width / 2;
            Canvas.SetLeft(label, x);

            double y = location.Y;
            y -= label.DesiredSize.Height / 2;
            Canvas.SetTop(label, y);
        }