Esempio n. 1
0
        /// <summary>
        /// Render RadioGroup control.
        /// Return true if failed.
        /// </summary>
        /// <param name="r.Canvas">Parent r.Canvas</param>
        /// <param name="uiCmd">UICommand</param>
        /// <returns>Success = false, Failure = true</returns>
        public static void RenderRadioGroup(RenderInfo r, UICommand uiCmd)
        {
            Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_RadioGroup));
            UIInfo_RadioGroup info = uiCmd.Info as UIInfo_RadioGroup;

            double fontSize = CalcFontPointScale();

            GroupBox box = new GroupBox()
            {
                Header      = uiCmd.Text,
                FontSize    = fontSize,
                BorderBrush = Brushes.LightGray,
            };

            SetToolTip(box, info.ToolTip);

            Grid grid = new Grid();

            box.Content = grid;

            for (int i = 0; i < info.Items.Count; i++)
            {
                RadioButton radio = new RadioButton()
                {
                    GroupName = r.Plugin.FullPath + uiCmd.Key,
                    Content   = info.Items[i],
                    Tag       = i,
                    FontSize  = fontSize,
                    VerticalContentAlignment = VerticalAlignment.Center,
                };

                radio.IsChecked = (i == info.Selected);
                radio.Checked  += (object sender, RoutedEventArgs e) =>
                {
                    RadioButton btn = sender as RadioButton;
                    info.Selected = (int)btn.Tag;
                    uiCmd.Update();
                };

                if (info.SectionName != null)
                {
                    radio.Click += (object sender, RoutedEventArgs e) =>
                    {
                        if (r.Plugin.Sections.ContainsKey(info.SectionName)) // Only if section exists
                        {
                            SectionAddress addr = new SectionAddress(r.Plugin, r.Plugin.Sections[info.SectionName]);
                            UIRenderer.RunOneSection(addr, $"{r.Plugin.Title} - RadioGroup [{uiCmd.Key}]", info.HideProgress);
                        }
                        else
                        {
                            Application.Current.Dispatcher.Invoke(() =>
                            {
                                MainWindow w = Application.Current.MainWindow as MainWindow;
                                w.Logger.System_Write(new LogInfo(LogState.Error, $"Section [{info.SectionName}] does not exists"));
                            });
                        }
                    };
                }

                SetToolTip(radio, info.ToolTip);

                Grid.SetRow(radio, i);
                grid.RowDefinitions.Add(new RowDefinition());
                grid.Children.Add(radio);
            }

            Rect rect = new Rect(uiCmd.Rect.Left, uiCmd.Rect.Top, uiCmd.Rect.Width, uiCmd.Rect.Height);

            DrawToCanvas(r, box, rect);
        }
Esempio n. 2
0
        private static async void RunOneSection(SectionAddress addr, string logMsg, bool hideProgress)
        {
            if (Engine.WorkingLock == 0)
            {
                Interlocked.Increment(ref Engine.WorkingLock);

                Logger           logger    = null;
                SettingViewModel setting   = null;
                MainViewModel    mainModel = null;

                Application.Current.Dispatcher.Invoke(() =>
                {
                    MainWindow w = Application.Current.MainWindow as MainWindow;

                    logger    = w.Logger;
                    mainModel = w.Model;
                    setting   = w.Setting;

                    // Populate BuildTree
                    if (!hideProgress)
                    {
                        w.Model.BuildTree.Children.Clear();
                        w.PopulateOneTreeView(addr.Plugin, w.Model.BuildTree, w.Model.BuildTree);
                        w.CurBuildTree = null;
                    }
                });

                mainModel.WorkInProgress = true;

                EngineState s = new EngineState(addr.Plugin.Project, logger, mainModel, addr.Plugin, addr.Section.SectionName);
                s.SetOption(setting);
                s.DisableLogger = setting.Log_DisableInInterface;

                Engine.WorkingEngine = new Engine(s);

                // Build Start, Switch to Build View
                if (!hideProgress)
                {
                    mainModel.SwitchNormalBuildInterface = false;
                }

                // Run
                long buildId = await Engine.WorkingEngine.Run(logMsg);

                // Build Ended, Switch to Normal View
                if (!hideProgress)
                {
                    mainModel.SwitchNormalBuildInterface = true;
                }

                // Turn off ProgressRing
                mainModel.WorkInProgress = false;

                Engine.WorkingEngine = null;
                Interlocked.Decrement(ref Engine.WorkingLock);

                if (!hideProgress)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        MainWindow w = Application.Current.MainWindow as MainWindow;
                        w.DrawPlugin(w.CurMainTree.Plugin);
                    });
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Render Button control.
        /// Return true if failed.
        /// </summary>
        /// <param name="r.Canvas">Parent r.Canvas</param>
        /// <param name="uiCmd">UICommand</param>
        /// <returns>Success = false, Failure = true</returns>
        public static void RenderButton(RenderInfo r, UICommand uiCmd, Logger logger)
        {
            Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_Button));
            UIInfo_Button info = uiCmd.Info as UIInfo_Button;

            Button button = new Button()
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
            };

            button.Click += (object sender, RoutedEventArgs e) =>
            {
                if (r.Plugin.Sections.ContainsKey(info.SectionName)) // Only if section exists
                {
                    SectionAddress addr = new SectionAddress(r.Plugin, r.Plugin.Sections[info.SectionName]);
                    UIRenderer.RunOneSection(addr, $"{r.Plugin.Title} - Button [{uiCmd.Key}]", info.ShowProgress);
                }
                else
                {
                    Application.Current.Dispatcher.Invoke((Action)(() =>
                    {
                        MainWindow w = Application.Current.MainWindow as MainWindow;
                        w.Logger.System_Write(new LogInfo(LogState.Error, $"Section [{info.SectionName}] does not exists"));
                    }));
                }
            };

            if (info.Picture != null && uiCmd.Addr.Plugin.Sections.ContainsKey($"EncodedFile-InterfaceEncoded-{info.Picture}"))
            { // Has Picture
                if (ImageHelper.GetImageType(info.Picture, out ImageHelper.ImageType type))
                {
                    return;
                }

                Image image = new Image()
                {
                    StretchDirection  = StretchDirection.DownOnly,
                    Stretch           = Stretch.Uniform,
                    UseLayoutRounding = true,
                };
                RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.HighQuality);

                using (MemoryStream ms = EncodedFile.ExtractInterfaceEncoded(uiCmd.Addr.Plugin, info.Picture))
                {
                    if (type == ImageHelper.ImageType.Svg)
                    {
                        // var (Width, Height) = ImageHelper.GetSvgSize(ms);
                        // image.Source = ImageHelper.SvgToBitmapImage(ms, Width, Height);

                        image.Source = ImageHelper.SvgToBitmapImage(ms);
                    }
                    else
                    {
                        image.Source = ImageHelper.ImageToBitmapImage(ms);
                    }
                }

                if (uiCmd.Text.Equals(string.Empty, StringComparison.Ordinal))
                { // No text, just image
                    button.Content = image;
                }
                else
                { // Button has text
                    StackPanel panel = new StackPanel()
                    {
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center,
                        Orientation         = Orientation.Horizontal,
                    };

                    TextBlock text = new TextBlock()
                    {
                        Text              = uiCmd.Text,
                        FontSize          = CalcFontPointScale(),
                        Height            = double.NaN,
                        VerticalAlignment = VerticalAlignment.Center,
                        Margin            = new Thickness(CalcFontPointScale() / 2, 0, 0, 0),
                    };

                    panel.Children.Add(image);
                    panel.Children.Add(text);
                    button.Content = panel;
                }
            }
            else
            { // No picture
                button.Content  = uiCmd.Text;
                button.FontSize = CalcFontPointScale();
            }

            SetToolTip(button, info.ToolTip);
            DrawToCanvas(r, button, uiCmd.Rect);
        }