public static Image CreateRoundedAvatar(Image original, Size imageSize, SizeF scaleFactor) { if (original == null) { return(null); } using (Bitmap bmp1 = new Bitmap(imageSize.Width, imageSize.Height)) { using (Graphics g = Graphics.FromImage(bmp1)) g.DrawImage(original, new Rectangle(0, 0, bmp1.Width, bmp1.Height), new Rectangle(0, 0, original.Width, original.Height), GraphicsUnit.Pixel); Bitmap bmp2 = new Bitmap(imageSize.Width, imageSize.Height); using (TextureBrush textureBrush = new TextureBrush(bmp1)) using (Graphics g = Graphics.FromImage(bmp2)) { g.Clear(Tenor.Mobile.UI.Skin.Current.SelectedBackColor); RoundedRectangle.Fill( g, new Pen(Color.DarkGray), textureBrush, new Rectangle( 0, 0, bmp2.Width, bmp2.Height) , new SizeF(8 * scaleFactor.Width, 8 * scaleFactor.Height).ToSize() ); } return(bmp2); } }
internal override void DrawTextControlBackground(TextControl control, Graphics graphics, Rectangle bounds) { Size ellipse = new SizeF(9 * ScaleFactor.Width, 9 * ScaleFactor.Height).ToSize(); using (Bitmap buffer = new Bitmap(bounds.Width, bounds.Height)) { using (Graphics g = Graphics.FromImage(buffer)) { g.Clear(TextBackGround); int lineSize = Convert.ToInt32(ScaleFactor.Height); Color color = Tenor.Mobile.Drawing.Strings.ToColor("#313131"); using (SolidBrush brush = new SolidBrush(color)) using (Pen pen = new Pen(color)) { int radius = Convert.ToInt32(ellipse.Height / 2); int x = 1; int y = 1; Point[] arc = Tenor.Mobile.Drawing.Arc.CreateArc(0, -90, 200, radius, 0, 0, lineSize - 1); g.DrawLines(pen, arc); arc = Tenor.Mobile.Drawing.Arc.CreateArc(0, -90, 200, radius, x, y, lineSize - 1); g.DrawLines(pen, arc); g.FillRectangle(brush, new Rectangle(arc[0].X, y, bounds.Width - arc[0].X, lineSize)); int middlePoint = Convert.ToInt32((arc.Length - 1) / 2); g.FillRectangle(brush, new Rectangle(x, arc[middlePoint].Y, lineSize, bounds.Height - arc[middlePoint].Y)); } } using (Pen p = new Pen(control.BackColor)) using (TextureBrush brush = new TextureBrush(buffer)) { graphics.Clear(control.BackColor); RoundedRectangle.Fill(graphics, p, brush, bounds, ellipse ); } } }
void kListControl1_DrawItem(object sender, Tenor.Mobile.UI.DrawItemEventArgs e) { Graphics g = e.Graphics; StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Near; SolidBrush textBrush; if (e.Item.Selected) { SolidBrush backBrush; backBrush = new SolidBrush(SystemColors.Highlight); textBrush = new SolidBrush(SystemColors.HighlightText); g.FillRectangle(backBrush, e.Bounds); } else { //backBrush = new SolidBrush(SystemColors.Window); textBrush = new SolidBrush(SystemColors.ControlText); } FF ff = (FF)e.Item.Value; Rectangle iconRect = new Rectangle(e.Bounds.X + 1, e.Bounds.Y + 1, ff.icon.Width, ff.icon.Height); RoundedRectangle.Fill(g, new Pen(SystemColors.ControlDark), new SolidBrush(SystemColors.ControlDark), iconRect, new Size(8, 8)); g.DrawIcon(ff.icon, iconRect.X, iconRect.Y); Rectangle r = e.Bounds; r.X += 32; g.DrawString(" " + ff.file.Name, kListControl1.Font, textBrush, r, format); r.Y += 14; g.DrawString(" " + ff.file.CreationTime.ToString(), kListControl1.Font, textBrush, r, format); Rectangle rect = new Rectangle(e.Bounds.X, e.Bounds.Bottom - 2, Convert.ToInt32(e.Bounds.Width / 2), 2); GradientFill.Fill(g, rect, SystemColors.Window, SystemColors.Control, GradientFill.FillDirection.LeftToRight); rect.Offset(rect.Width, 0); GradientFill.Fill(g, rect, SystemColors.Control, SystemColors.Window, GradientFill.FillDirection.LeftToRight); }
private void pnlCheckInResult_Paint(object sender, PaintEventArgs e) { if (backBuffer == null) { ResetBackBuffer(); } e.Graphics.DrawImage(backBuffer, 0, 0); Graphics graphics = backBufferG; graphics.Clear(pnlCheckInResult.BackColor); int padding = 4 * Tenor.Mobile.UI.Skin.Current.ScaleFactor.Width; RectangleF rectF = new RectangleF( padding, padding, pnlCheckInResult.Width - (padding * 2), pnlCheckInResult.Height - (padding * 2) ); Rectangle rect = Rectangle.Round(rectF); int leftWithPadding = rect.X + padding; int widthWithPadding = Convert.ToInt32(rect.Width - (padding * 2.5)); RoundedRectangle.Fill(graphics, new Pen(Color.Gray), new SolidBrush(Color.White), rect, new Size(8 * Tenor.Mobile.UI.Skin.Current.ScaleFactor.Width, 8 * Tenor.Mobile.UI.Skin.Current.ScaleFactor.Height)); Rectangle lastRectangle; // -- message lastRectangle = new Rectangle( leftWithPadding, rect.Y + padding, widthWithPadding, this.Height); Size measure = Tenor.Mobile.Drawing.Strings.Measure(graphics, message ?? "", Font, lastRectangle); graphics.DrawString(message ?? "", Font, textBrush, new RectangleF(lastRectangle.X, lastRectangle.Y, lastRectangle.Width, lastRectangle.Height), format); lastRectangle.Height = measure.Height + padding; // -- if (specials != null) { foreach (var special in specials) { if (special.Kind == SpecialKind.nearby) { continue; //TODO: Show specials nearby on check ins. } int stampSize = 31 * Tenor.Mobile.UI.Skin.Current.ScaleFactor.Width; DrawSeparator(graphics, padding, ref rectF, ref lastRectangle); AlphaImage image; if (special.Kind == SpecialKind.here) { image = new AlphaImage(Resources.SpecialHere); } else if (special.Kind == SpecialKind.nearby) { image = new AlphaImage(Resources.SpecialNearby); } else { image = new AlphaImage(Resources.SpecialUnlocked); } Rectangle textRectangle = new Rectangle( lastRectangle.Left, lastRectangle.Top, lastRectangle.Width - stampSize - (padding * 2), this.Height); measure = Tenor.Mobile.Drawing.Strings.Measure(graphics, special.Message ?? "", Font, textRectangle); graphics.DrawString(special.Message ?? "", Font, textBrush, new RectangleF(textRectangle.X, textRectangle.Y, textRectangle.Width, textRectangle.Height), format); if (measure.Height < stampSize) { measure.Height = stampSize; } try { image.Draw(graphics, new Rectangle( lastRectangle.Right - stampSize - padding, lastRectangle.Top + ((measure.Height / 2) - (stampSize / 2)), stampSize, stampSize)); } catch (Exception ex) { Log.RegisterLog("gdi", ex); } lastRectangle.Height = measure.Height + padding; } } if (!string.IsNullOrEmpty(mayorship)) { int crownSize = 0; if (showCrown) { crownSize = 31 * Tenor.Mobile.UI.Skin.Current.ScaleFactor.Width; } DrawSeparator(graphics, padding, ref rectF, ref lastRectangle); Rectangle textRectangle = new Rectangle( lastRectangle.Left, lastRectangle.Top, lastRectangle.Width - crownSize - (padding * 2), this.Height); measure = Tenor.Mobile.Drawing.Strings.Measure(graphics, mayorship ?? "", Font, textRectangle); graphics.DrawString(mayorship ?? "", Font, textBrush, new RectangleF(textRectangle.X, textRectangle.Y, textRectangle.Width, textRectangle.Height), format); if (measure.Height < crownSize) { measure.Height = crownSize; } if (showCrown) { try { AlphaImage image = new AlphaImage(Resources.Crown); image.Draw(graphics, new Rectangle( lastRectangle.Right - crownSize - padding, lastRectangle.Top + ((measure.Height / 2) - (crownSize / 2)), crownSize, crownSize)); } catch (Exception ex) { Log.RegisterLog("gdi", ex); } } lastRectangle.Height = measure.Height + padding; } if (badges != null) { foreach (var badge in badges) { int stampSize = 31 * Tenor.Mobile.UI.Skin.Current.ScaleFactor.Width; DrawSeparator(graphics, padding, ref rectF, ref lastRectangle); Rectangle textRectangle = new Rectangle( lastRectangle.Left, lastRectangle.Top, lastRectangle.Width - stampSize - (padding * 2), this.Height); measure = Tenor.Mobile.Drawing.Strings.Measure(graphics, badge.ToString(), Font, textRectangle); graphics.DrawString(badge.ToString(), Font, textBrush, new RectangleF(textRectangle.X, textRectangle.Y, textRectangle.Width, textRectangle.Height), format); if (measure.Height < stampSize) { measure.Height = stampSize; } if (badgeImageList != null && badgeImageList.ContainsKey(badge.ImageUrl.ToString())) { try { AlphaImage image = new AlphaImage(badgeImageList[badge.ImageUrl.ToString()]); image.Draw(graphics, new Rectangle( lastRectangle.Right - stampSize - padding, lastRectangle.Top + ((measure.Height / 2) - (stampSize / 2)), stampSize, stampSize)); } catch (Exception ex) { Log.RegisterLog("gdi", ex); } } lastRectangle.Height = measure.Height + padding; } } if (scoring != null) { foreach (var score in scoring) { int stampSize = 16 * Tenor.Mobile.UI.Skin.Current.ScaleFactor.Width; DrawSeparator(graphics, padding, ref rectF, ref lastRectangle); Rectangle textRectangle = new Rectangle( lastRectangle.Left, lastRectangle.Top, lastRectangle.Width - stampSize - (padding * 2), this.Height); measure = Tenor.Mobile.Drawing.Strings.Measure(graphics, score.ToString(), Font, textRectangle); graphics.DrawString(score.ToString(), Font, textBrush, new RectangleF(textRectangle.X, textRectangle.Y, textRectangle.Width, textRectangle.Height), format); if (measure.Height < stampSize) { measure.Height = stampSize; } if (scoreImageList != null && scoreImageList.ContainsKey(score.ImageUrl)) { try { AlphaImage image = new AlphaImage(scoreImageList[score.ImageUrl]); image.Draw(graphics, new Rectangle( lastRectangle.Right - stampSize - padding, lastRectangle.Top + ((measure.Height / 2) - (stampSize / 2)), stampSize, stampSize)); } catch (Exception ex) { Log.RegisterLog("gdi", ex); } } lastRectangle.Height = measure.Height + padding; } } e.Graphics.DrawImage(backBuffer, 0, 0); if (pnlCheckInResult.Height != lastRectangle.Bottom + padding) { pnlCheckInResult.Height = lastRectangle.Bottom + padding; pnlCheckInResult.Invalidate(); } }
internal override void DrawTabs(HeaderStrip control, PaintEventArgs e) { if (control.Tabs.Count == 0) { return; } Size size = control.Size; size.Height -= HeaderSelectedTabStrip * ScaleFactor.Height; IList <HeaderTab> tabs = control.Tabs; int bottomHeight = 15 * ScaleFactor.Height; Point offset = new Point(2 * ScaleFactor.Width, 2 * ScaleFactor.Width); int defaultWidth = 42 * ScaleFactor.Width; Size corner = new Size(8 * ScaleFactor.Width, 8 * ScaleFactor.Height); Pen penBorder = new Pen(Strings.ToColor(BorderLineColor)); try { HeaderTab selected = null; foreach (HeaderTab tab in tabs) { tab.area = new Rectangle(offset.X + tab.TabIndex * defaultWidth, offset.Y, defaultWidth, size.Height - offset.Y + corner.Height); if (tab.Selected) { selected = tab; using (SolidBrush backColor = new SolidBrush(Color.Black)) RoundedRectangle.Fill(e.Graphics, penBorder, backColor, tab.area, corner); } if (tab.Image != null) { //draw icon Rectangle destImg = new Rectangle(0, 0, tab.Image.Width, tab.Image.Height); if (tab.Image.Size.Height > tab.area.Height || tab.Image.Size.Width > tab.area.Width) { int oX = 8 * ScaleFactor.Width; int oY = 8 * ScaleFactor.Height; int imageSize = tab.area.Height - ((tab.area.Y + oY) * 2); destImg = new Rectangle(tab.area.X + oX, tab.area.Y + oY, imageSize, imageSize); } destImg = new Rectangle(tab.area.X + (tab.area.Width / 2) - (destImg.Width / 2), (tab.area.Height / 2) - (destImg.Height / 2), destImg.Width, destImg.Height); using (AlphaImage image = new AlphaImage(tab.Image)) { image.Draw(e.Graphics, destImg); } } if (!tab.Selected && (tab.TabIndex == tabs.Count - 1 || !tabs[tab.TabIndex + 1].Selected)) { Point sep = new Point(tab.area.Right, offset.Y); DrawSeparator(e, sep, size.Height - (sep.Y * 2), Orientation.Vertical); } } Font font = new Font(FontFamily.GenericSansSerif, HeaderSelectedTabStripFontSize, FontStyle.Regular); SolidBrush brush = new SolidBrush(ControlBackColor); SolidBrush fBrush = new SolidBrush(Strings.ToColor(HeaderSelectedTabStripFontColor)); Rectangle rect = new Rectangle(0, size.Height, control.Width, control.Height - size.Height); e.Graphics.FillRectangle(brush, rect); SizeF textSize = e.Graphics.MeasureString(selected.Text, font); Rectangle stringRect = rect; stringRect.X = Convert.ToInt32(selected.area.X + ((selected.area.Width / 2) - (textSize.Width / 2))); if (stringRect.X < 0) { stringRect.X = 2 * ScaleFactor.Width; } e.Graphics.DrawString(selected.Text, font, fBrush, stringRect); e.Graphics.DrawLine(new Pen(Strings.ToColor(HeaderSelectedTabStripBorderColor)), rect.Left, rect.Bottom - 1, rect.Right, rect.Bottom - 1); brush.Dispose(); fBrush.Dispose(); font.Dispose(); } finally { penBorder.Dispose(); } }