コード例 #1
0
        public MainWindow()
        {
            InitializeComponent();

            CrossThreading.Init();
            ListViewHelper.EnableDoubleBuffer(lvPalette);
            ListViewHelper.EnableDoubleBuffer(recordView);

            InitWorker();
            InitToolTip();
            InitHotKey();
            InitPaletteMenu();

            this.Text                += $"  {ProductVersion}";
            cList                     = new ImageList();
            cList.ImageSize           = new Size(16, 16);
            recordView.SmallImageList = cList;

            InitSetting();

            if (lvPalette.Items.Count == 0)
            {
                AddPalette("Palette1");
            }

            SelectPalette(0);

            this.Height       = this.MinimumSize.Height;
            this.Shown       += MainWindow_Shown;
            this.FormClosing += MainWindow_FormClosing;

            zoomSlider.Scroll             += ZoomSlider_Scroll;
            ldcPlate.SelectedColorChanged += LdcPlate_SelectedColorChanged;
            extender.Click += Extender_Click;
        }
コード例 #2
0
        private void AddColor(IColor c)
        {
            CrossThreading.UIInvoke(() =>
            {
                foreach (ListViewItem item in recordView.Items)
                {
                    if (item.SubItems[1].Text == c.ToString())
                    {
                        return;
                    }
                }

                Copy(c);

                ListViewItem itm = PaletteManager.Add(selectedPaletteName, c, GetItemIconIndex(c));
                recordView.Items.Add(itm);
                recordView.EnsureVisible(recordView.Items.Count - 1);
            });
        }
コード例 #3
0
        private void Processing()
        {
            // Prevent Zoom Tolerance
            float Zoom = setting.Zoom;

            // ViewSize
            Size vSize = new Size(100, 100);

            // View Half Size
            Size vhSize = new Size(vSize.Width / 2, vSize.Height / 2);

            // Capture Size
            Size scSize = new Size(SelectOdd(vSize.Width / Zoom), SelectOdd(vSize.Height / Zoom));

            // ZoomBuffer Size
            Size zbSize = new Size((int)(scSize.Width * Zoom), (int)(scSize.Height * Zoom));

            // Remain Size
            Size rmSize = zbSize - vSize;

            // Capture Area
            Point mPt = Mouse.Position;

            if (IsActivated && IntersectWith(this.Bounds, mPt))
            {
                if (mInWorkArea)
                {
                    return;
                }
                else
                {
                    mInWorkArea = true;
                }

                mPt = this.Location;
            }
            else
            {
                mInWorkArea = false;
            }

            Rectangle area = new Rectangle(mPt.X - scSize.Width / 2, mPt.Y - scSize.Height / 2, scSize.Width, scSize.Height);

            // Capture
            Bitmap buffer = ScreenCapture.Capture(area);

            // Picked Color
            Color pColor = buffer.GetPixel(area.Width / 2, area.Height / 2);

            // ViewBox Processing
            Bitmap view = new Bitmap(vSize.Width, vSize.Height);

            using (Graphics g = Graphics.FromImage(view))
            {
                Point dPos = new Point(-rmSize.Width / 2, -rmSize.Height / 2);

                g.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                g.InterpolationMode = InterpolationMode.NearestNeighbor;

                g.DrawImage(buffer, new Rectangle(dPos, zbSize));

                // Grid Processing
                if (setting.ShowGrid && Zoom >= 2f)
                {
                    using (SolidBrush sb = new SolidBrush(Color.FromArgb(100, Color.White)))
                    {
                        using (Pen p = new Pen(sb))
                        {
                            int z = (int)Zoom;

                            for (int x = dPos.X; x <= vSize.Width; x += z)
                            {
                                if (x >= 0)
                                {
                                    g.DrawLine(p, new PointF(x, 0), new PointF(x, vSize.Height));
                                }
                            }

                            for (int y = dPos.Y; y <= vSize.Height; y += z)
                            {
                                if (y >= 0)
                                {
                                    g.DrawLine(p, new PointF(0, y), new PointF(vSize.Width, y));
                                }
                            }
                        }
                    }
                }

                // CrossLine Processing
                for (int x = 0; x < vSize.Width; x++)
                {
                    Color px = view.GetPixel(x, vhSize.Height);

                    view.SetPixel(x, vhSize.Height, ColorUtils.Invert(px));
                }

                for (int y = 0; y < vSize.Height; y++)
                {
                    Color px = view.GetPixel(vhSize.Width, y);

                    view.SetPixel(vhSize.Width, y, ColorUtils.Invert(px));
                }
            }

            buffer.Dispose();

            SetPickedColor(pColor);

            CrossThreading.UIInvoke(() =>
            {
                ldcPlate.BaseColor = pColor;

                viewBox.Image?.Dispose();
                viewBox.Image = view;
            });
        }