示例#1
0
            void _WmMousemove(POINT pc)
            {
                if (!_paintedOnce)
                {
                    return;
                }

                //format text to draw below magnifier
                string text;

                using (new StringBuilder_(out var s)) {
                    var ic = _flags & (ICFlags.Image | ICFlags.Color | ICFlags.Rectangle);
                    if (ic == 0)
                    {
                        ic = ICFlags.Image | ICFlags.Color;
                    }
                    bool canColor = ic.Has(ICFlags.Color);
                    if (canColor)
                    {
                        var color = _img.GetPixel(pc.x, pc.y).ToArgb() & 0xffffff;
                        s.Append("Color  #").Append(color.ToString("X6")).Append('\n');
                    }
                    if (ic == ICFlags.Color)
                    {
                        s.Append("Click to capture color.\n");
                    }
                    else if (ic == ICFlags.Rectangle)
                    {
                        s.Append("Mouse-drag to capture rectangle.\n");
                    }
                    else if (!canColor)
                    {
                        s.Append("Mouse-drag to capture image.\n");
                    }
                    else
                    {
                        s.Append("Mouse-drag to capture image,\nor Ctrl+click to capture color.\n");
                    }
                    s.Append("More:  right-click");                     //"  cancel:  key Esc\n  retry:  key F3 ... F3"
                    text = s.ToString();
                }

                var font   = NativeFont_.RegularCached(_dpi);
                int magnWH = Dpi.Scale(200, _dpi) / 10 * 10;                 //width and height of the magnified image without borders etc

                if (_textSize == default)
                {
                    using (var tr = new FontDC_(font)) _textSize = tr.MeasureDT(text, TFFlags.NOPREFIX);
                }
                int width = Math.Max(magnWH, _textSize.width) + 2, height = magnWH + 4 + _textSize.height;

                using var mb = new MemoryBitmap(width, height);
                var dc = mb.Hdc;

                using var wdc = new WindowDC_(_w);

                //draw frames and color background. Also erase magnifier, need when near screen edges.
                Api.FillRect(dc, (0, 0, width, height), Api.GetStockObject(4));                 //BLACK_BRUSH

                //copy from captured screen image to magnifier image. Magnify 5 times.
                int k = magnWH / 10;

                Api.StretchBlt(dc, 1, 1, magnWH, magnWH, wdc, pc.x - k, pc.y - k, k * 2, k * 2, Api.SRCCOPY);

                //draw red crosshair
                k = magnWH / 2;
                using (var pen = new Pen_(0xff)) {
                    pen.DrawLine(dc, (k, 1), (k, magnWH + 1));
                    pen.DrawLine(dc, (1, k), (magnWH + 1, k));
                }

                //draw text below magnifier
                var rc = new RECT(1, magnWH + 2, _textSize.width, _textSize.height);

                Api.SetTextColor(dc, 0x32CD9A);                 //Color.YellowGreen
                Api.SetBkMode(dc, 1);
                var oldFont = Api.SelectObject(dc, font);

                Api.DrawText(dc, text, ref rc, TFFlags.NOPREFIX);
                Api.SelectObject(dc, oldFont);

                //set magninifier position far from cursor
                var pm    = new POINT(4, 4); _w.MapScreenToClient(ref pm);
                int xMove = magnWH * 3;

                if (_magnMoved)
                {
                    pm.Offset(xMove, 0);
                }
                var rm = new RECT(pm.x, pm.y, width, height); rm.Inflate(magnWH / 2, magnWH / 2);

                if (rm.Contains(pc))
                {
                    Api.InvalidateRect(_w, (pm.x, pm.y, width, height));
                    _magnMoved ^= true;
                    pm.Offset(_magnMoved ? xMove : -xMove, 0);
                }

                Api.BitBlt(wdc, pm.x, pm.y, width, height, dc, 0, 0, Api.SRCCOPY);
            }
示例#2
0
文件: pm render.cs 项目: qmgindi/Au
        SIZE _Measure(int maxWidth)
        {
            SIZE R = default;

            _z?.Dispose();
            _z = new _Metrics(this);

            int buttonPlusX  = (_z.bBorder + _z.textPaddingX) * 2 + _z.check + _z.image + _z.submenu + _z.submenuMargin;
            int buttonPlusY  = (_z.bBorder + _z.textPaddingY) * 2 + 1;
            int maxTextWidth = maxWidth - buttonPlusX;

            var font = NativeFont_.RegularCached(_dpi);

            using var dc = new FontDC_(font);
            int lineHeight = dc.MeasureEP(" ").height + buttonPlusY;

            int maxHotkey = 0;

            if (_z.hasHotkeys)
            {
                foreach (var b in _a)
                {
                    if (b.Hotkey == null)
                    {
                        continue;
                    }
                    int wid = dc.MeasureDT(b.Hotkey, c_tffHotkey).width;
                    maxHotkey = Math.Max(maxHotkey, Math.Min(wid, maxTextWidth / 2));
                }
            }
            int hotkeyPlus = lineHeight * 3 / 2;             //space between text and hotkey

            if (maxHotkey > 0)
            {
                maxTextWidth -= maxHotkey += hotkeyPlus;
            }

            int y = 0;

            for (int i = 0; i < _a.Count; i++)
            {
                //note: to support multiline, wrap, underlines and tabs we have to use DrawText, not TextOut.
                //	DrawText(DT_CALCRECT) is slow. Very slow compared with GetTextExtentPoint32. Eg 100-300 ms for 1000 items. Depends on text length.
                var  b = _a[i];
                SIZE z;
                if (b.IsSeparator)
                {
                    z = new(0, _z.separator);
                }
                else
                {
                    var s = b.Text;
                    if (!s.NE())
                    {
                        if (b.FontBold)
                        {
                            Api.SelectObject(dc, NativeFont_.BoldCached(_dpi));
                        }
                        z       = dc.MeasureDT(s, _TfFlags(b), maxTextWidth);
                        z.width = Math.Min(z.width, maxTextWidth);
                        if (b.FontBold)
                        {
                            Api.SelectObject(dc, font);
                        }
                        _z.xTextEnd = Math.Max(_z.xTextEnd, z.width);
                        z.width    += buttonPlusX; z.height += buttonPlusY;
                    }
                    else
                    {
                        z = new(0, lineHeight);
                    }
                }
                b.rect   = new(0, y, z.width, z.height);
                y       += z.height;
                R.width  = Math.Max(R.width, z.width);
                R.height = Math.Max(R.height, y);
            }

            if (maxHotkey > 0)
            {
                R.width        += maxHotkey;
                _z.xHotkeyStart = _z.xTextEnd + hotkeyPlus;
            }
            foreach (var b in _a)
            {
                b.rect.right = R.width;
            }

            return(R);
        }