Exemplo n.º 1
0
        private void PictureBox_Paint(object sender, PaintEventArgs e)
        {
            Quote q;

            if (string.IsNullOrWhiteSpace(_configSettings.SourcePath))
            {
                q = QuoteManager.Default;
            }
            else
            {
                QuoteManager manager = QuoteManager.Create(_configSettings.SourcePath);
                q = manager?.ReadRandom() ?? QuoteManager.Default;
            }

            QuoteRenderer renderer = new QuoteRenderer(new RenderSettings()
            {
                TextFont            = _configSettings.TextFont,
                TextColor           = _configSettings.TextColor,
                TextAlignment       = (TextAlignment)_configSettings.TextAlignment,
                BackgroundColor     = _configSettings.BackgroundColor,
                BackgroundImagePath = _configSettings.BackgroundImagePath,
                BackgroundAlignment = (BackgroundAlignment)_configSettings.BackgroundAlignment,
                BackgroundOpacity   = _configSettings.BackgroundOpacity
            });

            renderer.RenderText(q, e.Graphics, (sender as PictureBox).ClientRectangle);
        }
        public void Initialize(bool isPreview)
        {
            if (_isInitialized)
            {
                return;
            }

            _isInitialized = true;

            _renderer = new QuoteRenderer(new RenderSettings()
            {
                BackgroundAlignment = (BackgroundAlignment)Settings.Default.BackgroundAlignment,
                BackgroundColor     = Settings.Default.BackgroundColor,
                BackgroundImagePath = Settings.Default.BackgroundImagePath,
                BackgroundOpacity   = Settings.Default.BackgroundOpacity,
                TextAlignment       = (TextAlignment)Settings.Default.TextAlignment,
                TextColor           = Settings.Default.TextColor,
                TextFont            = Settings.Default.TextFont
            });

            QuoteManager manager = QuoteManager.Create(Settings.Default.SourcePath);

            if (manager != null)
            {
                _quote = manager.ReadRandom();
            }
            else
            {
                _quote = QuoteManager.Default;
            }
        }
Exemplo n.º 3
0
        private void EditButton_Click(object sender, EventArgs e)
        {
            EditForm form = new EditForm()
            {
                Manager = QuoteManager.Create(_configSettings.SourcePath)
            };

            form.ShowDialog(this);
        }
Exemplo n.º 4
0
        public ConfigForm()
        {
            InitializeComponent();
            this.Text = $"{Application.ProductName} [{Application.ProductVersion}]";

            _configSettings = Settings.Default;

            // Source
            pathTextBox.Text = _configSettings.SourcePath;
            if (!string.IsNullOrWhiteSpace(_configSettings.SourcePath))
            {
                try
                {
                    QuoteManager manager = QuoteManager.Create(_configSettings.SourcePath);
                    editButton.Enabled = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            // Font
            fontTextBox.Text      = $"{_configSettings.TextFont.FontFamily.Name}; {_configSettings.TextFont.Style}";
            textColorTextBox.Text = $"#{_configSettings.TextColor.R:X2}{_configSettings.TextColor.G:X2}{_configSettings.TextColor.B:X2}";

            alignmentComboBox.DataSource = new ArrayList()
            {
                Tuple.Create <TextAlignment, string>(TextAlignment.Auto, "Auto"),
                Tuple.Create <TextAlignment, string>(TextAlignment.Left, "Left"),
                Tuple.Create <TextAlignment, string>(TextAlignment.Center, "Center"),
                Tuple.Create <TextAlignment, string>(TextAlignment.Right, "Right")
            };
            alignmentComboBox.DisplayMember = "Item2";
            alignmentComboBox.ValueMember   = "Item1";
            alignmentComboBox.SelectedValue = (TextAlignment)_configSettings.TextAlignment;

            // Background
            backgroundColorTextBox.Text = $"#{_configSettings.BackgroundColor.R:X2}{_configSettings.BackgroundColor.G:X2}{_configSettings.BackgroundColor.B:X2}";
            backgroundImageTextBox.Text = _configSettings.BackgroundImagePath;

            backgroundAlignmentComboBox.DataSource = new ArrayList()
            {
                Tuple.Create <BackgroundAlignment, string>(BackgroundAlignment.Fit, "Fit"),
                Tuple.Create <BackgroundAlignment, string>(BackgroundAlignment.Stretch, "Stretch"),
                Tuple.Create <BackgroundAlignment, string>(BackgroundAlignment.Center, "Center"),
                Tuple.Create <BackgroundAlignment, string>(BackgroundAlignment.Tile, "Tile"),
            };
            backgroundAlignmentComboBox.DisplayMember = "Item2";
            backgroundAlignmentComboBox.ValueMember   = "Item1";
            backgroundAlignmentComboBox.SelectedValue = (BackgroundAlignment)_configSettings.BackgroundAlignment;

            backgroundOpacityNumericUpDown.Value = _configSettings.BackgroundOpacity;
        }
Exemplo n.º 5
0
        private void PathButton_Click(object sender, EventArgs e)
        {
            editButton.Enabled = false;

            openFileDialog.Filter = "Quotes XML|*.xml|Quotes JSON|*.json|All files|*.*";
            openFileDialog.Title  = "Select quoute source";

            if (!string.IsNullOrWhiteSpace(_configSettings.SourcePath))
            {
                openFileDialog.FileName         = Path.GetFileName(_configSettings.SourcePath);
                openFileDialog.InitialDirectory = Path.GetDirectoryName(_configSettings.SourcePath);
                openFileDialog.DefaultExt       = Path.GetExtension(_configSettings.SourcePath);
                if (string.Equals(Path.GetExtension(_configSettings.SourcePath), ".xml", StringComparison.OrdinalIgnoreCase))
                {
                    openFileDialog.FilterIndex = 1;
                }
                else
                {
                    openFileDialog.FilterIndex = 2;
                }
            }
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                if (!string.IsNullOrWhiteSpace(openFileDialog.FileName))
                {
                    try
                    {
                        QuoteManager manager = QuoteManager.Create(openFileDialog.FileName);

                        _configSettings.SourcePath = openFileDialog.FileName;
                        pathTextBox.Text           = _configSettings.SourcePath;

                        applyButton.Enabled = true;
                        editButton.Enabled  = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }