protected override void DrawItemOn(Gdi g, NativeItemData nativeItem, Rectangle rItem, int nItem) { if (rItem.Height > Settings.ListItemPixSize) rItem = new Rectangle(rItem.Left, rItem.Top + rItem.Height - Settings.ListItemPixSize, rItem.Width, Settings.ListItemPixSize); DrawItemBackgroundOn(g, nativeItem, rItem, nItem, /*nItem == SelectedIndex*/ false); var rSep = new Rectangle(rItem.Left, rItem.Bottom - 1, rItem.Width, 1); g.FillRect(rSep, Settings.ListItemSeparator); // write name if (!string.IsNullOrEmpty(nativeItem.PrimaryText)) { g.Font = Settings.PrimaryTextFontGdi; g.TextAlign = Win32.TextAlign.TA_LEFT; g.TextColor = Settings.ListItemTextColor; g.ExtTextOut(rItem.Left + nativeItem.InfoLeftIndents[0], rItem.Top + nativeItem.InfoTopIndents[0], nativeItem.PrimaryText); } base.DrawItemOn(g, nativeItem, rItem, nItem); }
public override void DrawScreenOn(Gdi mem, Rectangle rect) { var fromDC = _fromGraphics.GetHdc(); var toDC = _ToGraphics.GetHdc(); var toWidth = (int)(ViewTransitionManager.TransitionCanvas.Width * _transitionPct); if (SlideDirection == TransitionType.SlideLeft) toWidth = ViewTransitionManager.TransitionCanvas.Width - toWidth; int fromWidth = ViewTransitionManager.TransitionCanvas.Width - toWidth; if (SlideDirection == TransitionType.SlideLeft) { mem.BitBlt(0, 0, toWidth, _FromBitmap.Height, fromDC, fromWidth, 0, TernaryRasterOperations.SRCCOPY); mem.BitBlt(toWidth, 0, fromWidth, _ToBitmap.Height, toDC, 0, 0, TernaryRasterOperations.SRCCOPY); } else { mem.BitBlt(0, 0, toWidth, _FromBitmap.Height, toDC, fromWidth, 0, TernaryRasterOperations.SRCCOPY); mem.BitBlt(toWidth, 0, fromWidth, _ToBitmap.Height, fromDC, 0, 0, TernaryRasterOperations.SRCCOPY); } _fromGraphics.ReleaseHdc(fromDC); _ToGraphics.ReleaseHdc(toDC); }
public override void DrawScreenOn(Gdi mem, Rectangle rect) { IntPtr fromDC = _FromGraphics.GetHdc(); IntPtr toDC = _ToGraphics.GetHdc(); IntPtr stretchDC = _StretchGraphics.GetHdc(); mem.FillRect(rect, Color.Gainsboro); double percent = 2 * (_transitionPct > 0.5 ? _transitionPct - 0.5 : _transitionPct); if (FlipDirection == TransitionType.FlipLeft) { if (_transitionPct <= 0.5) FlipOut(mem, rect, fromDC, stretchDC, percent); else FlipIn(mem, rect, toDC, stretchDC, percent); } else { if (_transitionPct <= 0.5) FlipIn(mem, rect, fromDC, stretchDC, 1 - percent); else FlipOut(mem, rect, toDC, stretchDC, 1 - percent); } _StretchGraphics.ReleaseHdc(stretchDC); _FromGraphics.ReleaseHdc(fromDC); _ToGraphics.ReleaseHdc(toDC); }
public override void DrawItemOn(Gdi g, Rectangle rItem) { int x = (rItem.Width - _imageSize.Width) / 2; int y = (rItem.Height - _imageSize.Height) / 2; ImageInfo ii; _checkBoxSelected.GetImageInfo(out ii); if ((bool)DataSource.OptionValue) { if (_checkBoxSelected != null) g.DrawImageAlphaChannel(_checkBoxSelected, rItem.Right - (int)ii.Width - UISettings.CalcPix(10), rItem.Top + y); } else { if (_checkBoxEmpty != null) g.DrawImageAlphaChannel(_checkBoxEmpty, rItem.Right - (int)ii.Width - UISettings.CalcPix(10), rItem.Top + y); } }
private void CalcContentRectangle() { int w = Width / 8; int textHeight = 0; if (!string.IsNullOrEmpty(_message)) using (Gdi g = new Gdi(this)) { SetFont(g); Size textSize = g.GetDrawTextSize(_message, w * 6 - _margin * 2, Win32.DT.CENTER | Win32.DT.WORDBREAK); textHeight = textSize.Height; } int h = textHeight + _margin * 3 + button1.Height; if (h > Height / 8 * 6) h = Height / 8 * 6; int contentWidth = w * 6; int contentHeight = h; int vPos = (Height - contentHeight) / 2; int hPos = w; _contentRectangle = new Rectangle(hPos, vPos, contentWidth, contentHeight); _textRectangle = new Rectangle(_contentRectangle.X + _margin, _contentRectangle.Y + _margin, _contentRectangle.Width - _margin * 2, _contentRectangle.Height - _margin * 3 - button1.Height); if (button3.Visible) { } else if (button2.Visible) { int workWidth = _contentRectangle.Width - _margin * 3; int left = (workWidth / 2 - button1.Width) / 2; left = _margin + left; button1.Location = new Point(left + _contentRectangle.Left, _textRectangle.Y + _textRectangle.Height + _margin); left = left + workWidth / 2 + _margin; button2.Location = new Point(left + _contentRectangle.Left, _textRectangle.Y + _textRectangle.Height + _margin); } else { button1.Location = new Point((ClientRectangle.Width - button1.Width) / 2, _textRectangle.Y + _textRectangle.Height + _margin); } _imgLT.Location = new Point(_contentRectangle.X, _contentRectangle.Y); _imgTT.Location = new Point(_imgLT.Right + 1, _contentRectangle.Y); _imgTT.Width = _contentRectangle.Width - _imgLT.Width - _imgRT.Width; _imgRT.Location = new Point(_imgTT.Right + 1, _contentRectangle.Y); _imgLL.Location = new Point(_contentRectangle.X, _imgLT.Bottom + 1); _imgLL.Height = _contentRectangle.Height - _imgLT.Height - _imgLB.Height; _imgRR.Location = new Point(_imgRT.Location.X + _imgRT.Size.Width - _imgRR.Size.Width, _imgRT.Bottom + 1); _imgRR.Height = _contentRectangle.Height - _imgRT.Height - _imgRB.Height; _imgLB.Location = new Point(_contentRectangle.X, _imgLL.Bottom + 1); _imgBB.Location = new Point(_imgLB.Right + 1, _imgLB.Top + 1); _imgBB.Width = _contentRectangle.Width - _imgLB.Width - _imgRB.Width; _imgRB.Location = new Point(_imgBB.Right + 1, _imgLB.Top); _backgroundRectangle = new Rectangle(_imgLL.Right + 1, _imgLL.Top, _imgRR.Left - _imgLL.Right - 1, _imgLL.Height + 1); }
/// <summary> /// /// </summary> /// <param name="graphics">Graphics object.</param> /// <param name="clipRect">Rectangle in which to paint</param> protected virtual void OnRender(Gdi graphics, Rectangle clipRect) { }
protected override void OnRender(Gdi graphics, Rectangle clipRect) { if (_leftBorder != null && _rightBorder != null && _topBorder != null && _bottomBorder != null) { Rectangle rect = new Rectangle(clipRect.Left + _leftBorderSize.Width, clipRect.Top + _topBorderSize.Height, clipRect.Width - _leftBorderSize.Width - _rightBorderSize.Width, _leftBorderSize.Height - _topBorderSize.Height - _bottomBorderSize.Height); if (_leftBorder != null) graphics.DrawImageAlphaChannel(_leftBorder, clipRect.Left, clipRect.Top); if (_rightBorder != null) graphics.DrawImageAlphaChannel(_rightBorder, rect.Right, clipRect.Top); if (_topBorder != null) graphics.DrawImageAlphaChannel(_topBorder, new Rectangle(rect.Left, clipRect.Top, rect.Width, _topBorderSize.Height)); if (_bottomBorder != null) graphics.DrawImageAlphaChannel(_bottomBorder, new Rectangle(rect.Left, rect.Bottom, rect.Width, _topBorderSize.Height)); if (BackColor != Color.Empty) graphics.FillRect(rect, BackColor); } else { //if (BackColor != Color.Empty) // graphics.FillRect(clipRect, BackColor); } if (_textbox.Visible) { // } else { _label.Render(graphics, clipRect); } }
protected override void DrawScreenOn(Gdi mem, Rectangle rect, int position) { if (rect.Bottom > ContentRectangle.Top || rect.Top < ContentRectangle.Bottom) { DrawBackground(mem, rect, position); // Pass the graphics to the canvas to render if (Canvas != null) { Canvas.Render(mem, rect); } } }
protected abstract void DrawScreenOn(Gdi mem, Rectangle rect, int position);
private void SetFont(Gdi g) { g.Font = FontCache.CreateFont("Calibri", 13, FontStyle.Regular, true); g.TextAlign = Win32.TextAlign.TA_LEFT; g.TextColor = Color.Black; }
protected override void OnRender(Gdi graphics, Rectangle clipRect) { IntPtr ptrSrc = OffscreenBuffer.OffScreenGraphics.GetHdc(); using (Gdi gr = Gdi.FromHdc(ptrSrc, Rectangle.Empty)) { DrawBackground(gr, clipRect); // fill background with double gradient var y = (int)(_backgroundRectangle.Height * _gradientCenter); gr.GradientFill(new Rectangle(_backgroundRectangle.Left, _backgroundRectangle.Top, _backgroundRectangle.Width, y), _gradientColor1, _gradientColor2, FillDirection.TopToBottom); gr.GradientFill(new Rectangle(_backgroundRectangle.Left, _backgroundRectangle.Top + y, _backgroundRectangle.Width, _backgroundRectangle.Height - y), _gradientColor2, _gradientColor3, FillDirection.TopToBottom); // Pass the graphics to the canvas to render if (Canvas != null) { Canvas.Render(gr, clipRect); } //Draw Text SetFont(gr); gr.DrawText(_message, new Win32.RECT(_textRectangle.X, _textRectangle.Y, _textRectangle.Width, _textRectangle.Height), Win32.DT.LEFT | Win32.DT.TOP | Win32.DT.WORDBREAK); } graphics.BitBlt(clipRect.Left, clipRect.Top, Width, Height, ptrSrc, clipRect.Left, clipRect.Top, TernaryRasterOperations.SRCCOPY); OffscreenBuffer.OffScreenGraphics.ReleaseHdc(ptrSrc); }
/// <summary> /// Draw an image with full transparency /// </summary> /// <param name="gdi"></param> /// <param name="transp">Transparency index</param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> public int DrawAlpha(Gdi gdi, byte transp, int x, int y, int width, int height) { return DrawAlpha(gdi._hdc, transp, x, y, width, height); }
public static Gdi FromHdc(IntPtr hdc, Rectangle clipRect) { Gdi gdi = new Gdi(); gdi.InitWithHdc(hdc, clipRect, false); return gdi; }
public override void DrawItemOn(Gdi g, Rectangle rItem) { int x = rItem.Width / 2; int y = (rItem.Height - _imageSize.Height) / 2; Color color1; Color color2; g.Font = Font; if ((string)DataSource.OptionValue == DataSource.OptionValues[0]) { if (_itemLeftSelected != null) g.DrawImageAlphaChannel(_itemLeftSelected, rItem.Left + x - _imageSize.Width, rItem.Top + y); if (_itemRight != null) g.DrawImageAlphaChannel(_itemRight, rItem.Left + x, rItem.Top + y); color1 = Color.White; color2 = Color.Gray; } else { if (_itemLeft != null) g.DrawImageAlphaChannel(_itemLeft, rItem.Left + x - _imageSize.Width, rItem.Top + y); if (_itemRightSelected != null) g.DrawImageAlphaChannel(_itemRightSelected, rItem.Left + x, rItem.Top + y); color1 = Color.Gray; color2 = Color.White; } g.TextAlign = Win32.TextAlign.TA_LEFT; g.TextColor = color1; Size textSize = g.GetTextExtent(DataSource.OptionValues[0]); y = (rItem.Height - textSize.Height) / 2; int left = x - _imageSize.Width; g.ExtTextOut(rItem.Left + left, rItem.Top + y, _imageSize.Width, DataSource.OptionValues[0]); g.TextColor = color2; left = x; g.ExtTextOut(rItem.Left + left, rItem.Top + y, _imageSize.Width, DataSource.OptionValues[1]); }
public override void DrawItemOn(Gdi g, Rectangle rItem) { int y = (rItem.Height - _imageSize.Height) / 2; g.Font = Font; if (_selectButton != null) g.DrawImageAlphaChannel(_selectButton, rItem.Right - _imageSize.Width - UISettings.CalcPix(15), rItem.Top + y); g.TextColor = Color.FromArgb(51, 153, 255); var textSize = g.GetTextExtent((string)DataSource.OptionValue); y = (rItem.Height - textSize.Height) / 2; int x = rItem.Width - UISettings.CalcPix(20) - _imageSize.Width; if (textSize.Width < x) x = textSize.Width; g.DrawText((string)DataSource.OptionValue, new Win32.RECT(rItem.Right - UISettings.CalcPix(20) - _imageSize.Width - x, rItem.Top + y, x, textSize.Height), Win32.DT.LEFT | Win32.DT.TOP | Win32.DT.WORDBREAK | Win32.DT.SINGLELINE); }
public abstract void DrawItemOn(Gdi g, Rectangle rItem);
private void FlipOut(Gdi mem, Rectangle canvas, IntPtr dc, IntPtr stretchDC, double transitionPct) { int margin = (int)((double)_CanvasMiddle * transitionPct); using (Gdi stretch = Gdi.FromHdc(stretchDC, Rectangle.Empty)) { stretch.FillRect(canvas, Color.Gainsboro); stretch.StretchBlt(0, 0, canvas.Width - margin*2, canvas.Height, dc, 0, 0, canvas.Width, canvas.Height, TernaryRasterOperations.SRCCOPY); } var currLine = BuildPath(_FlipOutLeftPath[margin].X, _FlipOutLeftPath[margin].Y, _FlipOutTopPath[margin].X, _FlipOutTopPath[margin].Y); for (int i = 0; i < currLine.Count - 1; i++) { mem.StretchBlt(currLine[i].X, currLine[i].Y, 1, canvas.Height - currLine[i].Y*2, stretchDC, i, 0, 1, canvas.Height, TernaryRasterOperations.SRCCOPY); } }
private void CalcContentRectangle() { int buttonHeight = UISettings.CalcPix(24); int buttonWidth = UISettings.CalcPix(75); int w = Width / 10; int textHeight = 0; if (!string.IsNullOrEmpty(_message)) { using (Gdi g = new Gdi(this)) { SetFont(g); Size textSize = g.GetDrawTextSize(_message, w * 9 - _margin * 2, Win32.DT.WORDBREAK); textHeight = textSize.Height; } } int h = _margin + textHeight + _margin + (buttonHeight * 3 + _margin / 2 * 2) + _margin; if (_shortview) { h -= (buttonHeight + _margin / 2); } if (h > Height / 10 * 6) { h = Height / 10 * 6; } int contentWidth = w * 9; int contentHeight = h; int vPos = (Height - contentHeight) / 2; int hPos = w / 2; _contentRectangle = new Rectangle(hPos, vPos, contentWidth, contentHeight); _textRectangle = new Rectangle(_contentRectangle.X + _margin, _contentRectangle.Y + _margin, _contentRectangle.Width - _margin * 2, _contentRectangle.Height - _margin - _margin - (buttonHeight * 3 + _margin / 2 * 2) - _margin); if (_shortview) { _textRectangle.Height += (buttonHeight + _margin / 2); } int buttonXPos = _contentRectangle.Left + (_contentRectangle.Width - buttonWidth) / 2; int buttonYPos = _contentRectangle.Y + _margin + _textRectangle.Height + _margin; _textRectangle.Height -= _margin; buttonUpdate.Location = new Point(buttonXPos, buttonYPos); buttonUpdate.Size = new Size(buttonWidth, buttonHeight); if (!_shortview) { buttonYPos += buttonHeight + _margin / 2; buttonSkip.Location = new Point(buttonXPos, buttonYPos); buttonSkip.Size = new Size(buttonWidth, buttonHeight); buttonSkip.Visible = true; } else { buttonSkip.Location = new Point(buttonXPos, buttonYPos); buttonSkip.Size = new Size(1, 1); buttonSkip.Visible = false; } buttonYPos += buttonHeight + _margin / 2; buttonCancel.Location = new Point(buttonXPos, buttonYPos); buttonCancel.Size = new Size(buttonWidth, buttonHeight); if (_shortview) { buttonCancel.Text = Resources.UpdateInfoDialogControl_Buttons_Exit; } else { buttonCancel.Text = Resources.UpdateInfoDialogControl_Buttons_Cancel; } //Границы и фон _imgLT.Location = new Point(_contentRectangle.X, _contentRectangle.Y); _imgTT.Location = new Point(_imgLT.Right + 1, _contentRectangle.Y); _imgTT.Width = _contentRectangle.Width - _imgLT.Width - _imgRT.Width; _imgRT.Location = new Point(_imgTT.Right + 1, _contentRectangle.Y); _imgLL.Location = new Point(_contentRectangle.X, _imgLT.Bottom + 1); _imgLL.Height = _contentRectangle.Height - _imgLT.Height - _imgLB.Height; _imgRR.Location = new Point(_imgRT.Location.X + _imgRT.Size.Width - _imgRR.Size.Width, _imgRT.Bottom + 1); _imgRR.Height = _contentRectangle.Height - _imgRT.Height - _imgRB.Height; _imgLB.Location = new Point(_contentRectangle.X, _imgLL.Bottom + 1); _imgBB.Location = new Point(_imgLB.Right + 1, _imgLB.Top + 1); _imgBB.Width = _contentRectangle.Width - _imgLB.Width - _imgRB.Width; _imgRB.Location = new Point(_imgBB.Right + 1, _imgLB.Top); _backgroundRectangle = new Rectangle(_imgLL.Right + 1, _imgLL.Top, _imgRR.Left - _imgLL.Right - 1, _imgLL.Height + 1); }
public bool BitBlt(int nxDest, int dyDest, int nWidth, int nHeight, Gdi src, int nxSrc, int nySrc, TernaryRasterOperations rop) { return Win32.BitBlt(_hdc, nxDest, dyDest, nWidth, nHeight, src._hdc, nxSrc, nySrc, rop); }
protected override void OnRender(Gdi graphics, Rectangle clipRect) { //graphics.DrawText(_message, // new Win32.RECT(_textRectangle.X, // _textRectangle.Y, // _textRectangle.Width, // _textRectangle.Height), // Win32.DT.LEFT | Win32.DT.TOP | Win32.DT.WORDBREAK); clipRect.Intersect(this.Rectangle); if (clipRect.IsEmpty) return; //base.OnRender(graphics, clipRect); //SetupDefaultClip(g); float topAdjust = 0; switch (VerticalTextAlignment) { case VerticalAlignment.Top: topAdjust = 0; break; case VerticalAlignment.Bottom: //topAdjust = ClientHeight - _totalHeight; topAdjust = Height - _totalHeight; break; case VerticalAlignment.Center: //topAdjust = (ClientHeight - _totalHeight) / 2; topAdjust = (Height - _totalHeight) / 2; break; } if (BackColor != Color.Transparent) { graphics.FillRect( //new Rectangle(e.Origin.X, e.Origin.Y, ClientWidth, ClientHeigh), clipRect, BackColor); } foreach (LineBreak lineBreak in _lineBreaks) { float leftAdjust = 0; switch (HorizontalTextAlignment) { case HorizontalAlignment.Left: leftAdjust = 0; break; case HorizontalAlignment.Right: //leftAdjust = ClientWidth - lineBreak.Width; leftAdjust = Width - lineBreak.Width; break; case HorizontalAlignment.Center: //leftAdjust = (ClientWidth - lineBreak.Width) / 2.0f; leftAdjust = (Width - lineBreak.Width) / 2.0f; break; } Rectangle drawRect = new Rectangle(this.Left + Margin.Left + (int)leftAdjust, this.Top + Margin.Top + (int)topAdjust, (int)lineBreak.Width, (int)lineBreak.Height); if (clipRect.IntersectsWith(drawRect)) { graphics.Font = Font; graphics.TextColor = ForeColor; //graphics. //TODO: chhange all this code to only one single DrawText graphics.ExtTextOut(drawRect.Left, drawRect.Top, drawRect.Width, lineBreak.Text); // new Galssoft.WM.Components.SystemHelpers.Win32.RECT(drawRect), Galssoft.WM.Components.SystemHelpers.Win32.DT.LEFT); //Font, myForeBrush, e.Origin.X + leftAdjust, e.Origin.Y + topAdjust); } topAdjust += lineBreak.Height; if (topAdjust > Height) break; } }
/// <summary> /// Функция "распила" текста на строчки /// </summary> /// <param name="text">Исходный текст</param> /// <param name="width">Ширина области отображения текста</param> /// <param name="count">Количество выводимых строк (если значение не ограничено указать 0)</param> /// <param name="g">Графический контекст</param> /// <returns></returns> public static List<string> CutTextToLines(string inputText, int textWidth, int linesCount, Gdi g) { List<string> result = new List<string>(); if (linesCount == 0) { linesCount = int.MaxValue; } inputText = inputText.Replace("\r", string.Empty); string[] lines = inputText.Split('\n'); // первый распил по символам переноса строки int currentLine; int maxChars; string text; string outtext; int ipreviouscol; int icol; int[] extents; Size size; bool isSpace; // признак: пробел bool isOver; // признак: нужна новая строка currentLine = 0; try { foreach (string line in lines) { currentLine++; text = line; icol = line.Length; ipreviouscol = 0; do { text = line.Substring(ipreviouscol); size = g.GetTextExtent(text, textWidth, out extents, out maxChars); isSpace = false; isOver = false; if (text.Length > maxChars) { isOver = true; // ищем первый пробел по которому можем обрезать int iSpace = text.LastIndexOf(' ', maxChars, maxChars); if (iSpace > -1) // он есть { isSpace = true; icol = iSpace; } else // его нет { isSpace = false; icol = maxChars; } outtext = text.Substring(0, icol); // обрезаем кусок текста до пробела } else { isOver = false; outtext = text; // берем весь текст } // если в конце строки был пробел, то это необходимо учесть на следующей итерации if (isSpace) { ipreviouscol += (icol + 1); } else { ipreviouscol += icol; } // если набрали требуемое в linesCount количество строк, необходимо прервать фукцию обработки // если к этому моменту остался необработанный текст, необходимо добавить символы "..." if (linesCount > (result.Count + 1)) { result.Add(outtext); } else { if (isOver || (lines.Length != currentLine)) { outtext = outtext.Remove(outtext.Length - 3, 3); // удаляем последние 3 символа чтобы "..." гарантировано влезло outtext = outtext.Trim(); outtext += "..."; } result.Add(outtext); throw new Exception(); } } while (text.Length > maxChars); } } catch // чтобы выйти из всех циклов { // } return result; }
protected override void OnRender(Gdi gMem, Rectangle clipRect) { switch (Style) { case ButtonStyle.AlphaChannel: IImage img1 = null; if (_selected && !_pressed) img1 = TransparentButtonSelected; if (_pressed || (_selected && img1 == null)) img1 = TransparentButtonPressed; if (!_pressed && !_selected) img1 = TransparentButton; if (img1 != null) gMem.DrawImageAlphaChannel(img1, clipRect); break; case ButtonStyle.TransparentBackground: ImageData img2 = null; if (_selected && !_pressed) img2 = ButtonSelected; if (_pressed || (_selected && img2 == null)) img2 = ButtonPressed; if (!_pressed && !_selected) img2 = Button; if (img2 != null) { int imgWidth = img2.ImageSize.Width; int imgHeight = img2.ImageSize.Height; gMem.TransparentImage(clipRect.Left, clipRect.Top, clipRect.Width, clipRect.Height, img2.ImageHandle, img2.ImageOffset.X, img2.ImageOffset.Y, imgWidth, imgHeight, img2.TransparentColor); } break; default: if (_pressed || _selected) gMem.FillRect(clipRect, BackColor); else gMem.FillRect(clipRect, ForeColor); break; } if (!string.IsNullOrEmpty(Text)) { FontGdi font = Font; if (_pressed) font = PressedFont; else if (_selected) font = SelectedFont; Color color = FontColor; if (_pressed) color = PressedFontColor; else if (_selected) color = SelectedFontColor; gMem.Font = font; gMem.TextColor = color; Size textSize = gMem.GetTextExtent(Text); int topAdjust = 0; switch (VerticalTextAlignment) { case VerticalAlignment.Top: topAdjust = 0 + _verticalTextMargin; break; case VerticalAlignment.Bottom: topAdjust = Height - textSize.Height - _verticalTextMargin; break; case VerticalAlignment.Center: topAdjust = (Height - textSize.Height) / 2; break; } gMem.ExtTextOut(clipRect.Left + (clipRect.Width - textSize.Width) / 2, clipRect.Top + topAdjust, textSize.Width, Text); } }
private void CalcContentRectangle() { int w = Width / 8; int textHeight = 0; if (!string.IsNullOrEmpty(_message)) using (Gdi g = new Gdi(this)) { SetFont(g); Size textSize = g.GetDrawTextSize(_message, w * 6 - _margin * 2, Win32.DT.WORDBREAK); textHeight = textSize.Height; } int h = textBoxStatus.Height + /*buttonOk.Height*/30 * 3 + _margin * 10; if (h > Height / 8 * 6) h = Height / 8 * 6; int contentWidth = w * 6; int contentHeight = h; int vPos = (Height - contentHeight) / 2; int hPos = w; _contentRectangle = new Rectangle(hPos, vPos, contentWidth, contentHeight); /* _textRectangle = new Rectangle(_contentRectangle.X + _margin, _contentRectangle.Y + _margin, _contentRectangle.Width - _margin * 2, _contentRectangle.Height - _margin * 3 - buttonOk.Height); */ int workWidth = _contentRectangle.Width - _margin * 3; int left = hPos + _margin; textBoxStatus.Location = new Point(left + _contentRectangle.Left, _contentRectangle.Y + _margin * 3); textBoxStatus.Size = new Size(workWidth - _margin * 4, 30); buttonOk.Location = new Point(left + _contentRectangle.Left, textBoxStatus.Location.Y + textBoxStatus.Height + _margin); buttonOk.Size = new Size(workWidth - _margin * 4, 30); buttonReset.Location = new Point(left + _contentRectangle.Left, buttonOk.Location.Y + buttonOk.Height + _margin); buttonReset.Size = new Size(workWidth - _margin * 4, 30); buttonCancel.Location = new Point(left + _contentRectangle.Left, buttonReset.Location.Y + buttonReset.Height + _margin); buttonCancel.Size = new Size(workWidth - _margin * 4, 30); //Границы и фон _imgLT.Location = new Point(_contentRectangle.X, _contentRectangle.Y); _imgTT.Location = new Point(_imgLT.Right + 1, _contentRectangle.Y); _imgTT.Width = _contentRectangle.Width - _imgLT.Width - _imgRT.Width; _imgRT.Location = new Point(_imgTT.Right + 1, _contentRectangle.Y); _imgLL.Location = new Point(_contentRectangle.X, _imgLT.Bottom + 1); _imgLL.Height = _contentRectangle.Height - _imgLT.Height - _imgLB.Height; _imgRR.Location = new Point(_imgRT.Location.X + _imgRT.Size.Width - _imgRR.Size.Width, _imgRT.Bottom + 1); _imgRR.Height = _contentRectangle.Height - _imgRT.Height - _imgRB.Height; _imgLB.Location = new Point(_contentRectangle.X, _imgLL.Bottom + 1); _imgBB.Location = new Point(_imgLB.Right + 1, _imgLB.Top); _imgBB.Width = _contentRectangle.Width - _imgLB.Width - _imgRB.Width; _imgRB.Location = new Point(_imgBB.Right + 1, _imgLB.Top); _backgroundRectangle = new Rectangle(_imgLL.Right + 1, _imgLL.Top, _imgRR.Left - _imgLL.Right - 1, _imgLL.Height); }
protected override void OnRender(Gdi graphics, Rectangle clipRect) { graphics.Font = Font; graphics.TextAlign = Galssoft.VKontakteWM.Components.Common.SystemHelpers.Win32.TextAlign.TA_LEFT; if (string.IsNullOrEmpty(_text)) { _text = string.Empty; } _textToPrint = _text.Replace("<br>", "\n"); if (!_textOld.Equals(_textToPrint)) { _textOld = _textToPrint; _lines.Clear(); } int totalHeight = 0; int averageHeight = 0; #region распил текста на строчки выполняется только если _lines пустой if (_lines.Count == 0) { //пилим по переносам строки... string[] lines = _textToPrint.Split('\n'); foreach (string line in lines) { int ipreviouscol = 0; string text = line; string outtext = string.Empty; int icol = text.Length; int maxChars; do { text = line.Substring(ipreviouscol); int[] extents; Size size = graphics.GetTextExtent(text, clipRect.Width, out extents, out maxChars); totalHeight += size.Height; if (totalHeight > clipRect.Height) { totalHeight -= size.Height; break; } bool isSpace = false; //признак пробела if (text.Length > maxChars) { //ищем последний с позиции в начало maxChars пробел int iSpace = text.LastIndexOf(' ', maxChars, maxChars); if (iSpace > -1) { isSpace = true; icol = iSpace; } else { isSpace = false; icol = maxChars; } outtext = text.Substring(0, icol); } else { outtext = text; } //учитываем пробел в конце строки if (isSpace) { ipreviouscol += (icol + 1); } else { ipreviouscol += icol; } _lines.Add(outtext); } while (text.Length > maxChars); } _totalHeight = totalHeight; } #endregion totalHeight = _totalHeight; if (_lines.Count != 0) { averageHeight = totalHeight / _lines.Count; } int iter = 0; foreach (string line in _lines) { int leftIndent = 0; int topIndent = 0; Size size = graphics.GetTextExtent(line); switch (HorizontalTextAlignment) { case HorizontalAlignment.Left: leftIndent = clipRect.Left; break; case HorizontalAlignment.Center: case HorizontalAlignment.Stretch: leftIndent = clipRect.Left + (clipRect.Width - size.Width) / 2; break; case HorizontalAlignment.Right: leftIndent = clipRect.Left + (clipRect.Width - size.Width); break; } switch (VerticalTextAlignment) { case VerticalAlignment.Top: topIndent = clipRect.Top; break; case VerticalAlignment.Center: case VerticalAlignment.Stretch: topIndent = clipRect.Top + (clipRect.Height - totalHeight) / 2; break; case VerticalAlignment.Bottom: topIndent = clipRect.Top + (clipRect.Height - totalHeight); break; } //тень if (_dropShadow) { graphics.TextColor = FontColorShadow; graphics.ExtTextOut(leftIndent + UISettings.CalcPix(1), topIndent + averageHeight * iter + UISettings.CalcPix(1), line); } graphics.TextColor = FontColor; graphics.ExtTextOut(leftIndent, topIndent + averageHeight * iter, line); iter++; } }
public void DrawRender(Gdi g) { Rectangle rect = new Rectangle(0, 0, Width, Height); IntPtr hdcMem = OffScreenGraphics.GetHdc(); using (Gdi gMem = Gdi.FromHdc(hdcMem, Rectangle.Empty)) { DrawScreenOn(gMem, rect, _currentScrollPosition); g.BitBlt(Location.X, Location.Y, rect.Width, rect.Height, gMem, 0, 0, TernaryRasterOperations.SRCCOPY); } OffScreenGraphics.ReleaseHdc(hdcMem); }
public virtual void DrawScreenOn(Gdi mem, Rectangle rect) { }
protected override void OnRender(Gdi graphics, Rectangle clipRect) { if (_leftPart != null && _rightPart != null && _centerPart != null) { Rectangle rect = new Rectangle(clipRect.Left + _leftPartSize.Width, clipRect.Top, clipRect.Width - _rightPartSize.Width - _leftPartSize.Width, clipRect.Height); if (!_pressed) { graphics.DrawImageAlphaChannel(_leftPart, clipRect.Left, clipRect.Top); graphics.DrawImageAlphaChannel(_rightPart, rect.Right, clipRect.Top); graphics.DrawImageAlphaChannel(_centerPart, rect); } else { graphics.DrawImageAlphaChannel(_leftPartPressed, clipRect.Left, clipRect.Top); graphics.DrawImageAlphaChannel(_rightPartPressed, rect.Right, clipRect.Top); graphics.DrawImageAlphaChannel(_centerPartPressed, rect); } #region отрисовка текста комментария graphics.Font = Font; graphics.TextAlign = Galssoft.VKontakteWM.Components.Common.SystemHelpers.Win32.TextAlign.TA_LEFT; if (string.IsNullOrEmpty(_text)) { _text = string.Empty; if (string.IsNullOrEmpty(_textSubstitute)) { _textToPrint = string.Empty; } else { _textToPrint = _textSubstitute; } graphics.TextColor = FontColorUnactive; } else { _textToPrint = _text; graphics.TextColor = FontColor; } if (_pressed) { graphics.TextColor = FontColorInvert; } if (!_textOld.Equals(_textToPrint)) { _textOld = _textToPrint; _lines.Clear(); } int topIndent = 0; int totalHeight = 0; int averageHeight = 0; #region распил текста на строчки выполняется только если _lines пустой if (_lines.Count == 0) { //пилим по переносам строки... string[] lines = _textToPrint.Split('\n'); foreach (string line in lines) { int ipreviouscol = 0; string text = line; string outtext = string.Empty; int icol = text.Length; int maxChars; do { text = line.Substring(ipreviouscol); int[] extents; Size size = graphics.GetTextExtent(text, clipRect.Width - _leftPartSize.Width - _rightPartSize.Width, out extents, out maxChars); totalHeight += size.Height * 11 / 10; bool isSpace = false; //признак пробела bool isOver = false; //признак необходимости новой строки if (text.Length > maxChars) { isOver = true; //ищем последний с позиции в начало maxChars пробел int iSpace = text.LastIndexOf(' ', maxChars, maxChars); if (iSpace > -1) { isSpace = true; icol = iSpace; } else { isSpace = false; icol = maxChars; } outtext = text.Substring(0, icol); } else { isOver = false; outtext = text; } //учитываем пробел в конце строки if (isSpace) { ipreviouscol += (icol + 1); } else { ipreviouscol += icol; } //добавляем точечки if ((_lines.Count + 1) < 2) { _lines.Add(outtext); } else { if (isOver) { outtext = outtext.Remove(outtext.Length - 3, 3); if (outtext.EndsWith(" ")) { outtext = outtext.Remove(outtext.Length - 1, 1); } outtext += "..."; } _lines.Add(outtext); break; } } while (text.Length > maxChars); break; } _totalHeight = totalHeight; } #endregion totalHeight = _totalHeight; averageHeight = totalHeight / _lines.Count; foreach (string line in _lines) { //для отображения используется прямоугольник 4/5 от ширины контрола //отступ: 4 зазора от левого края //graphics.ExtTextOut(clipRect.Left + (clipRect.Width - clipRect.Width * 4 / 5) / 4, clipRect.Top + topIndent + (clipRect.Height - totalHeight) / 2, line); graphics.ExtTextOut(clipRect.Left + _leftPartSize.Width, clipRect.Top + topIndent + (clipRect.Height - totalHeight) / 2, line); topIndent += averageHeight; } #endregion } /* switch (Style) { case ButtonStyle.AlphaChannel: IImage img1 = null; if (_selected && !_pressed) img1 = TransparentButtonSelected; if (_pressed || (_selected && img1 == null)) img1 = TransparentButtonPressed; if (!_pressed && !_selected) img1 = TransparentButton; if (img1 != null) gMem.DrawImageAlphaChannel(img1, clipRect); break; case ButtonStyle.TransparentBackground: ImageData img2 = null; if (_selected && !_pressed) img2 = ButtonSelected; if (_pressed || (_selected && img2 == null)) img2 = ButtonPressed; if (!_pressed && !_selected) img2 = Button; if (img2 != null) { int imgWidth = img2.ImageSize.Width; int imgHeight = img2.ImageSize.Height; gMem.TransparentImage(clipRect.Left, clipRect.Top, clipRect.Width, clipRect.Height, img2.ImageHandle, img2.ImageOffset.X, img2.ImageOffset.Y, imgWidth, imgHeight, img2.TransparentColor); } break; default: if (_pressed) gMem.FillRect(clipRect, BackColor); else gMem.FillRect(clipRect, ForeColor); break; } if (!string.IsNullOrEmpty(Text)) { gMem.Font = Font; gMem.TextColor = FontColor; Size textSize = gMem.GetTextExtent(Text); gMem.ExtTextOut(clipRect.Left + (clipRect.Width - textSize.Width) / 2, clipRect.Top + (clipRect.Height - textSize.Height) / 2, textSize.Width, Text); }*/ }
/// <summary> /// Renders the UIElement. /// </summary> /// <param name="graphics">Graphics object.</param> public void Render(Gdi graphics, Rectangle rect) { this.OnRender(graphics, rect); }
protected override void OnRender(Gdi graphics, Rectangle clipRect) { if (_leftPart != null && _rightPart != null && _centerPart != null) { var rect = new Rectangle(clipRect.Left + _leftPartSize.Width, clipRect.Top, clipRect.Width - _rightPartSize.Width - _leftPartSize.Width, clipRect.Height); int iconIndentWidth = 0; int iconIndentHeight = 0; switch(_iconType) { case WideButtonWithIconType.Write: case WideButtonWithIconType.Photo: iconIndentWidth = 7; iconIndentHeight = 6; break; case WideButtonWithIconType.Open: iconIndentWidth = 5; iconIndentHeight = 7; break; } if (!_pressed) { graphics.DrawImageAlphaChannel(_leftPart, clipRect.Left, clipRect.Top); graphics.DrawImageAlphaChannel(_rightPart, rect.Right, clipRect.Top); graphics.DrawImageAlphaChannel(_centerPart, rect); graphics.DrawImageAlphaChannel(_icon, clipRect.Left + UISettings.CalcPix(iconIndentWidth), clipRect.Top + UISettings.CalcPix(iconIndentHeight)); } else { graphics.DrawImageAlphaChannel(_leftPartPressed, clipRect.Left, clipRect.Top); graphics.DrawImageAlphaChannel(_rightPartPressed, rect.Right, clipRect.Top); graphics.DrawImageAlphaChannel(_centerPartPressed, rect); graphics.DrawImageAlphaChannel(_icon, clipRect.Left + UISettings.CalcPix(iconIndentWidth), clipRect.Top + UISettings.CalcPix(iconIndentHeight + 1)); } if (!string.IsNullOrEmpty(Text)) { FontGdi font = Font; if (_pressed) { font = PressedFont; } /*else if (_selected) font = SelectedFont;*/ Color color = FontColor; if (_pressed) { color = PressedFontColor; } /*else if (_selected) color = SelectedFontColor;*/ graphics.Font = font; graphics.TextColor = color; Size textSize = graphics.GetTextExtent(Text); int topAdjust = 0; switch (VerticalTextAlignment) { case VerticalAlignment.Top: topAdjust = 0 + _verticalTextMargin; break; case VerticalAlignment.Bottom: topAdjust = Height - textSize.Height - _verticalTextMargin; break; case VerticalAlignment.Center: topAdjust = (Height - textSize.Height) / 2; break; } int pressIndent = 0; if (_pressed) { pressIndent = UISettings.CalcPix(1); } //if (_dropShadow && !_pressed) if (_dropShadow) { graphics.TextColor = FontColorShadow; //graphics.ExtTextOut(clipRect.Left + (clipRect.Width - textSize.Width) / 2 + UISettings.CalcPix(1), clipRect.Top + topAdjust + UISettings.CalcPix(1), textSize.Width, Text); graphics.ExtTextOut(clipRect.Left + UISettings.CalcPix(22 + 5), clipRect.Top + topAdjust + UISettings.CalcPix(1) + pressIndent, textSize.Width, Text); } graphics.TextColor = color; //graphics.ExtTextOut(clipRect.Left + (clipRect.Width - textSize.Width) / 2, clipRect.Top + topAdjust, textSize.Width, Text); graphics.ExtTextOut(clipRect.Left + UISettings.CalcPix(22 + 5), clipRect.Top + topAdjust + pressIndent, textSize.Width, Text); } } }
protected override void OnRender(Gdi gMem, Rectangle clipRect) { if (_backgroundImage != null) _backgroundImage.Render(gMem, clipRect); else gMem.FillRect(Rectangle, BackColor); if (_buttons.Count > 0) { for (int i = 0; i < _buttons.Count; i++) { _buttons[i].Instance.Render(gMem, new Rectangle(_buttons[i].Instance.Location.X, _buttons[i].Instance.Location.Y, _buttonsSize.Width, _buttonsSize.Height)); } } }