protected override HCShapeLineObj GetObjAt(int x, int y) { HCShapeLineObj vResult = HCShapeLineObj.sloNone; if (HC.PtInRect(new RECT(StartPt.X - PointSize, StartPt.Y - PointSize, StartPt.X + PointSize, StartPt.Y + PointSize), new POINT(x, y))) { vResult = HCShapeLineObj.sloStart; } else if (HC.PtInRect(new RECT(EndPt.X - PointSize, EndPt.Y - PointSize, EndPt.X + PointSize, EndPt.Y + PointSize), new POINT(x, y))) { vResult = HCShapeLineObj.sloEnd; } else { RECT vRect = ClientRect(); vRect.Inflate(PointSize, PointSize); if (HC.PtInRect(vRect, x, y)) // 在边框点宽度外 { vRect.Inflate(-PointSize - PointSize, -PointSize - PointSize); if (!HC.PtInRect(vRect, x, y)) { vResult = HCShapeLineObj.sloLine; } } } return(vResult); }
protected override void DoPaint(HCStyle aStyle, RECT aDrawRect, int aDataDrawTop, int aDataDrawBottom, int aDataScreenTop, int aDataScreenBottom, HCCanvas aCanvas, PaintInfo aPaintInfo) { if (this.Active && (!aPaintInfo.Print)) { aCanvas.Brush.Color = HC.clBtnFace; aCanvas.FillRect(aDrawRect); } if (!aPaintInfo.Print) { RECT vFocusRect = new RECT(); if (FActiveArea != ExpressArea.ceaNone) { if (FActiveArea == ExpressArea.ceaTop) { vFocusRect = FSupRect; } else if (FActiveArea == ExpressArea.ceaBottom) { vFocusRect = FSubRect; } vFocusRect.Offset(aDrawRect.Left, aDrawRect.Top); vFocusRect.Inflate(2, 2); aCanvas.Pen.Color = Color.Blue; aCanvas.Rectangle(vFocusRect); } if ((FMouseMoveArea != ExpressArea.ceaNone) && (FMouseMoveArea != FActiveArea)) { if (FMouseMoveArea == ExpressArea.ceaTop) { vFocusRect = FSupRect; } else if (FMouseMoveArea == ExpressArea.ceaBottom) { vFocusRect = FSubRect; } vFocusRect.Offset(aDrawRect.Left, aDrawRect.Top); vFocusRect.Inflate(2, 2); aCanvas.Pen.Color = HC.clMedGray; aCanvas.Rectangle(vFocusRect); } } ApplySupSubStyle(aStyle.TextStyles[TextStyleNo], aCanvas, aPaintInfo.ScaleY / aPaintInfo.Zoom); aCanvas.TextOut(aDrawRect.Left + FSupRect.Left, aDrawRect.Top + FSupRect.Top, FSupText); aCanvas.TextOut(aDrawRect.Left + FSubRect.Left, aDrawRect.Top + FSubRect.Top, FSubText); }
}; //Color.BlueViolet /// <summary> /// Briefly shows standard blinking on-screen rectangle. /// </summary> public static void ShowOsdRect(RECT r, bool limitToScreen = false) { var osr = CreateOsdRect(); r.Inflate(2, 2); //2 pixels inside, 2 outside if (limitToScreen) { var k = AScreen.Of(r).Bounds; r.Intersect(k); } osr.Rect = r; osr.Show(); int i = 0; ATimer.Every(250, t => { if (i++ < 5) { osr.Color = (i & 1) != 0 ? 0xFFFFFF00 : 0xFF8A2BE2; } else { t.Stop(); osr.Dispose(); } }); }
protected override HCShapeLineObj GetObjAt(int x, int y) { HCShapeLineObj vResult = HCShapeLineObj.sloNone; if (HC.PtInRect(new RECT(StartPt.X - PointSize, StartPt.Y - PointSize, StartPt.X + PointSize, StartPt.Y + PointSize), new POINT(x, y))) { vResult = HCShapeLineObj.sloStart; } else if (HC.PtInRect(new RECT(EndPt.X - PointSize, EndPt.Y - PointSize, EndPt.X + PointSize, EndPt.Y + PointSize), new POINT(x, y))) { vResult = HCShapeLineObj.sloEnd; } else { RECT vRect = ClientRect(); vRect.Inflate(PointSize, PointSize); IntPtr vRgn1 = GDI.CreateEllipticRgnIndirect(ref vRect); try { if (GDI.PtInRegion(vRgn1, x, y)) // 在外围 { vRect.Inflate(-PointSize - PointSize, -PointSize - PointSize); IntPtr vRgn2 = GDI.CreateEllipticRgnIndirect(ref vRect); try { if (!GDI.PtInRegion(vRgn2, x, y)) // 不在内围 { vResult = HCShapeLineObj.sloLine; } } finally { GDI.DeleteObject(vRgn2); } } } finally { GDI.DeleteObject(vRgn1); } } return(vResult); }
internal override void UpdateLayout(Rectangle r) { Debug.Assert(!this.IsHidden); this.Bounds = r; RECT rCont = r, rCap = rCont; var gt = this as _Tab; var gp = this as _Panel; bool isTB = gp != null && gp.HasToolbar; int capThick = isTB ? _splitterWidth * 2 : _manager._CaptionHeight; bool noCaption = gp != null && gp.HasDocument; if (noCaption) { this.CaptionBounds = new Rectangle(r.Left, r.Top, 0, 0); } else { switch (this.CaptionAt) { case CaptionEdge.Left: rCap.right = (rCont.left += capThick); break; case CaptionEdge.Top: rCap.bottom = (rCont.top += capThick); break; case CaptionEdge.Right: rCap.left = (rCont.right -= capThick); break; case CaptionEdge.Bottom: rCap.top = (rCont.bottom -= capThick); break; } this.CaptionBounds = rCap; } if (!isTB) { //add border around content rCont.Inflate(-1, -1); if (rCont.right < rCont.left) { rCont.right = rCont.left; } if (rCont.bottom < rCont.top) { rCont.bottom = rCont.top; } } if (gt != null) { gt.UpdateItemsLayout(rCont); } else { gp.Content.Bounds = rCont; gp.OnSizeChanged(rCont.Width, rCont.Height); } this.InvalidateCaption(); }
internal void SetBorder(TBBorder value) { int _Pad(TBBorder b) => b >= TBBorder.Width2 && b <= TBBorder.Width4 ? (int)b - 1 : 0; #if true int pOld = _Pad(_tb._border), pNew = _Pad(value), pDif = pNew - pOld; if (pDif != 0) { this.Padding = new Padding(pNew); } var w = this.Hwnd(); if (!w.Is0) { RECT r = w.ClientRectInScreen; r.Inflate(pDif, pDif); r.Normalize(false); const WS mask = WS.CAPTION | WS.THICKFRAME | WS.SYSMENU; WS s1 = w.Style, s2 = _BorderStyle(value); if (s2 != (s1 & mask)) { w.SetStyle((s1 & ~mask) | s2); } //preserve client size and position Api.AdjustWindowRectEx(ref r, _BorderStyle(value), false, WS2.TOOLWINDOW); w.MoveLL(r.left, r.top, r.Width, r.Height, Native.SWP.FRAMECHANGED); } #else //this simpler code does not preserve client size and position int pOld = _Pad(_tb._border), pNew = _Pad(value); if (pNew != pOld) { this.Padding = new Padding(pNew); } var w = this.Hwnd(); if (!w.Is0) { const WS mask = WS.CAPTION | WS.THICKFRAME | WS.SYSMENU; WS s1 = w.Style, s2 = _BorderStyle(value); if (s2 != (s1 & mask)) { w.SetStyle((s1 & ~mask) | s2, updateNC: true, updateClient: true); } } #endif }
/// <summary> /// Takes screenshot of specified rectangle in screen, quantizes colors to make smaller, compresses, Base64 encodes and returns comment string like <c>" /*image:...*/"</c>. /// If fails, prints warning and returns null. /// </summary> public static string MakeScreenshotComment(RECT r, DpiOf dpi = default) { if (dpi != default) { int i = dpi.Dpi; if (i != 96) { r.Inflate((Dpi.Scale(r.Width, i) - r.Width) / 2, (Dpi.Scale(r.Height, i) - r.Height) / 2); } } try { var b = uiimage.capture(r); var a = Quantize(b, 16); var z = Convert2.BrotliCompress(a); return("/*image:" //+ "\r\n" //rejected + "WkJN" + Convert.ToBase64String(z) + "*/"); } catch (Exception e1) { print.warning("MakeScreenshotComment() failed. " + e1.ToStringWithoutStack()); return(null); } }
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); }
public static void InflateRect(ref RECT ARect, int x, int y) { ARect.Inflate(x, y); }
protected override void DoPaint(HCStyle aStyle, RECT aDrawRect, int aDataDrawTop, int aDataDrawBottom, int aDataScreenTop, int aDataScreenBottom, HCCanvas aCanvas, PaintInfo aPaintInfo) { if (this.Active && (!aPaintInfo.Print)) { aCanvas.Brush.Color = HC.View.HC.clBtnFace; aCanvas.FillRect(aDrawRect); } aStyle.TextStyles[TextStyleNo].ApplyStyle(aCanvas, aPaintInfo.ScaleY / aPaintInfo.Zoom); if (FLeftTopText != "") { aCanvas.TextOut(aDrawRect.Left + FLeftTopRect.Left, aDrawRect.Top + FLeftTopRect.Top, FLeftTopText); } if (FLeftBottomText != "") { aCanvas.TextOut(aDrawRect.Left + FLeftBottomRect.Left, aDrawRect.Top + FLeftBottomRect.Top, FLeftBottomText); } if (FRightTopText != "") { aCanvas.TextOut(aDrawRect.Left + FRightTopRect.Left, aDrawRect.Top + FRightTopRect.Top, FRightTopText); } if (FRightBottomText != "") { aCanvas.TextOut(aDrawRect.Left + FRightBottomRect.Left, aDrawRect.Top + FRightBottomRect.Top, FRightBottomText); } // 十字线 aCanvas.Pen.Color = Color.Black; aCanvas.MoveTo(aDrawRect.Left, aDrawRect.Top + FLeftTopRect.Bottom + FPadding); aCanvas.LineTo(aDrawRect.Right, aDrawRect.Top + FLeftTopRect.Bottom + FPadding); aCanvas.MoveTo(aDrawRect.Left + FLeftTopRect.Right + FPadding, aDrawRect.Top); aCanvas.LineTo(aDrawRect.Left + FLeftTopRect.Right + FPadding, aDrawRect.Bottom); if (!aPaintInfo.Print) { RECT vFocusRect = new RECT(); if (FActiveArea != ToothArea.ctaNone) { switch (FActiveArea) { case ToothArea.ctaLeftTop: vFocusRect = FLeftTopRect; break; case ToothArea.ctaLeftBottom: vFocusRect = FLeftBottomRect; break; case ToothArea.ctaRightTop: vFocusRect = FRightTopRect; break; case ToothArea.ctaRightBottom: vFocusRect = FRightBottomRect; break; } vFocusRect.Offset(aDrawRect.Left, aDrawRect.Top); vFocusRect.Inflate(2, 2); aCanvas.Pen.Color = Color.Gray; aCanvas.Rectangle(vFocusRect); } if ((FMouseMoveArea != ToothArea.ctaNone) && (FMouseMoveArea != FActiveArea)) { switch (FMouseMoveArea) { case ToothArea.ctaLeftTop: vFocusRect = FLeftTopRect; break; case ToothArea.ctaLeftBottom: vFocusRect = FLeftBottomRect; break; case ToothArea.ctaRightTop: vFocusRect = FRightTopRect; break; case ToothArea.ctaRightBottom: vFocusRect = FRightBottomRect; break; } vFocusRect.Offset(aDrawRect.Left, aDrawRect.Top); vFocusRect.Inflate(2, 2); aCanvas.Pen.Color = Color.LightGray; aCanvas.Rectangle(vFocusRect); } } }
protected override void DoPaint(HCStyle aStyle, RECT aDrawRect, int aDataDrawTop, int aDataDrawBottom, int aDataScreenTop, int aDataScreenBottom, HCCanvas aCanvas, PaintInfo aPaintInfo) { if (this.Active && (!aPaintInfo.Print)) { aCanvas.Brush.Color = HC.clBtnFace; aCanvas.FillRect(aDrawRect); } if (!FLineHide) // 分数线 { aCanvas.Pen.Color = Color.Black; aCanvas.MoveTo(aDrawRect.Left + FPadding, aDrawRect.Top + FTopRect.Bottom + FPadding); aCanvas.LineTo(aDrawRect.Left + Width - FPadding, aDrawRect.Top + FTopRect.Bottom + FPadding); } if (!aPaintInfo.Print) { RECT vFocusRect = new RECT(); if (FActiveArea != ExpressArea.ceaNone) { if (FActiveArea == ExpressArea.ceaTop) { vFocusRect = FTopRect; } else if (FActiveArea == ExpressArea.ceaBottom) { vFocusRect = FBottomRect; } vFocusRect.Offset(aDrawRect.Left, aDrawRect.Top); vFocusRect.Inflate(2, 2); aCanvas.Pen.Color = Color.Blue; aCanvas.Rectangle(vFocusRect); } if ((FMouseMoveArea != ExpressArea.ceaNone) && (FMouseMoveArea != FActiveArea)) { if (FMouseMoveArea == ExpressArea.ceaTop) { vFocusRect = FTopRect; } else if (FMouseMoveArea == ExpressArea.ceaBottom) { vFocusRect = FBottomRect; } vFocusRect.Offset(aDrawRect.Left, aDrawRect.Top); vFocusRect.Inflate(2, 2); aCanvas.Pen.Color = HC.clMedGray; aCanvas.Rectangle(vFocusRect); } } aStyle.TextStyles[TextStyleNo].ApplyStyle(aCanvas, aPaintInfo.ScaleY / aPaintInfo.Zoom); aCanvas.TextOut(aDrawRect.Left + FTopRect.Left, aDrawRect.Top + FTopRect.Top, FTopText); aCanvas.TextOut(aDrawRect.Left + FBottomRect.Left, aDrawRect.Top + FBottomRect.Top, FBottomText); }
protected override void DoPaint(HCStyle AStyle, RECT ADrawRect, int ADataDrawTop, int ADataDrawBottom, int ADataScreenTop, int ADataScreenBottom, HCCanvas ACanvas, PaintInfo APaintInfo) { if (this.Active && (!APaintInfo.Print)) { ACanvas.Brush.Color = HC.clBtnFace; ACanvas.FillRect(ADrawRect); } AStyle.TextStyles[TextStyleNo].ApplyStyle(ACanvas, APaintInfo.ScaleY / APaintInfo.Zoom); ACanvas.TextOut(ADrawRect.Left + FLeftRect.Left, ADrawRect.Top + FLeftRect.Top, FLeftText); ACanvas.TextOut(ADrawRect.Left + TopRect.Left, ADrawRect.Top + TopRect.Top, TopText); ACanvas.TextOut(ADrawRect.Left + FRightRect.Left, ADrawRect.Top + FRightRect.Top, FRightText); ACanvas.TextOut(ADrawRect.Left + BottomRect.Left, ADrawRect.Top + BottomRect.Top, BottomText); ACanvas.Pen.Color = Color.Black; ACanvas.MoveTo(ADrawRect.Left + FLeftRect.Right + Padding, ADrawRect.Top + TopRect.Bottom + Padding); ACanvas.LineTo(ADrawRect.Left + FRightRect.Left - Padding, ADrawRect.Top + TopRect.Bottom + Padding); if (!APaintInfo.Print) { RECT vFocusRect = new RECT(); if (FActiveArea != ExpressArea.ceaNone) { switch (FActiveArea) { case ExpressArea.ceaLeft: vFocusRect = FLeftRect; break; case ExpressArea.ceaTop: vFocusRect = TopRect; break; case ExpressArea.ceaRight: vFocusRect = FRightRect; break; case ExpressArea.ceaBottom: vFocusRect = BottomRect; break; } vFocusRect.Offset(ADrawRect.Left, ADrawRect.Top); vFocusRect.Inflate(2, 2); ACanvas.Pen.Color = Color.Blue; ACanvas.Rectangle(vFocusRect); } if ((FMouseMoveArea != ExpressArea.ceaNone) && (FMouseMoveArea != FActiveArea)) { switch (FMouseMoveArea) { case ExpressArea.ceaLeft: vFocusRect = FLeftRect; break; case ExpressArea.ceaTop: vFocusRect = TopRect; break; case ExpressArea.ceaRight: vFocusRect = FRightRect; break; case ExpressArea.ceaBottom: vFocusRect = BottomRect; break; } vFocusRect.Offset(ADrawRect.Left, ADrawRect.Top); vFocusRect.Inflate(2, 2); ACanvas.Pen.Color = HC.clMedGray; ACanvas.Rectangle(vFocusRect); } } }
protected override void DoPaint(HCStyle aStyle, RECT aDrawRect, int aDataDrawTop, int aDataDrawBottom, int aDataScreenTop, int aDataScreenBottom, HCCanvas aCanvas, PaintInfo aPaintInfo) { if (this.Active && (!aPaintInfo.Print)) { aCanvas.Brush.Color = HC.View.HC.clBtnFace; aCanvas.FillRect(aDrawRect); } aStyle.TextStyles[TextStyleNo].ApplyStyle(aCanvas, aPaintInfo.ScaleY / aPaintInfo.Zoom); aCanvas.TextOut(aDrawRect.Left + LeftRect.Left, aDrawRect.Top + LeftRect.Top, LeftText); aCanvas.TextOut(aDrawRect.Left + TopRect.Left, aDrawRect.Top + TopRect.Top, TopText); aCanvas.TextOut(aDrawRect.Left + RightRect.Left, aDrawRect.Top + RightRect.Top, RightText); aCanvas.TextOut(aDrawRect.Left + BottomRect.Left, aDrawRect.Top + BottomRect.Top, BottomText); aCanvas.Pen.Color = Color.Black; aCanvas.DrawLine(aDrawRect.Left, aDrawRect.Top, aDrawRect.Right, aDrawRect.Bottom); aCanvas.DrawLine(aDrawRect.Right, aDrawRect.Top, aDrawRect.Left, aDrawRect.Bottom); if (!aPaintInfo.Print) { RECT vFocusRect = new RECT(); if (FMouseIn) { aCanvas.Pen.Color = Color.Gray; vFocusRect = LeftRect; vFocusRect.Offset(aDrawRect.Left, aDrawRect.Top); vFocusRect.Inflate(2, 2); aCanvas.Rectangle(vFocusRect); vFocusRect = TopRect; vFocusRect.Offset(aDrawRect.Left, aDrawRect.Top); vFocusRect.Inflate(2, 2); aCanvas.Rectangle(vFocusRect); vFocusRect = RightRect; vFocusRect.Offset(aDrawRect.Left, aDrawRect.Top); vFocusRect.Inflate(2, 2); aCanvas.Rectangle(vFocusRect); vFocusRect = BottomRect; vFocusRect.Offset(aDrawRect.Left, aDrawRect.Top); vFocusRect.Inflate(2, 2); aCanvas.Rectangle(vFocusRect); } if (FActiveArea != ExpressArea.ceaNone) { switch (FActiveArea) { case ExpressArea.ceaLeft: vFocusRect = LeftRect; break; case ExpressArea.ceaTop: vFocusRect = TopRect; break; case ExpressArea.ceaRight: vFocusRect = RightRect; break; default: vFocusRect = BottomRect; break; } vFocusRect.Offset(aDrawRect.Left, aDrawRect.Top); vFocusRect.Inflate(2, 2); aCanvas.Pen.Color = Color.Blue; aCanvas.Rectangle(vFocusRect); } } }