public MsgBox(string text, string caption, int style) { InitializeComponent(); this.Text = caption; lblMsg.Text = text; switch (style) { case 0: pctImg.Image = AlphaImage.CreateFromFile(path + @"\Resources\error.png"); break; case 1: pctImg.Image = AlphaImage.CreateFromFile(path + @"\Resources\information.png"); break; case 2: pctImg.Image = AlphaImage.CreateFromFile(path + @"\Resources\question.png"); break; case 3: pctImg.Image = AlphaImage.CreateFromFile(path + @"\Resources\warning.png"); break; } pctImg.Alpha = 200; hkMsgBox.KeyHandlerDelegate += new Hook.KeyHandler(hkMsgBox_KeyHandlerDelegate); hkMsgBox.Start(); }
public AlertBox(string text, string caption, int style) { InitializeComponent(); this.Text = caption; lblMsg.Text = text; switch (style) { case 0: pctImg.Image = AlphaImage.CreateFromFile(path + @"\Resources\error.png"); break; case 1: pctImg.Image = AlphaImage.CreateFromFile(path + @"\Resources\information.png"); break; case 2: pctImg.Image = AlphaImage.CreateFromFile(path + @"\Resources\question.png"); break; case 3: pctImg.Image = AlphaImage.CreateFromFile(path + @"\Resources\warning.png"); break; } pctImg.Alpha = 175; }
private void listBox_DrawItem(object sender, Tenor.Mobile.UI.DrawItemEventArgs e) { Badge badge = (Badge)e.Item.Value; Size factor = Tenor.Mobile.UI.Skin.Current.ScaleFactor; if (!string.IsNullOrEmpty(badge.Name)) { int padding = 5 * factor.Width; int imageSize = listBox.DefaultItemHeight - padding; RectangleF rect = new RectangleF (e.Bounds.X + imageSize + (padding * 2), e.Bounds.Y, e.Bounds.Width - (imageSize) - (padding * 2), e.Bounds.Height); if (imageList != null && imageList.ContainsKey(badge.ImageUrl.ToString())) { if (!imageListA.ContainsKey(badge.ImageUrl.ToString())) { imageListA.Add(badge.ImageUrl.ToString(), new AlphaImage(new Bitmap(new MemoryStream(imageList[badge.ImageUrl.ToString()])))); imageList[badge.ImageUrl.ToString()] = null; } AlphaImage image = imageListA[badge.ImageUrl.ToString()]; Rectangle imgRect = new Rectangle(0 + Convert.ToInt32(padding), Convert.ToInt32(rect.Y + (rect.Height / 2) - (imageSize / 2)), imageSize, imageSize); try { image.Draw(e.Graphics, imgRect); } catch (Exception ex) { Log.RegisterLog(ex); } } rect.Y += 2 * factor.Height; SizeF size = e.Graphics.MeasureString(badge.Name, fontBold); e.Graphics.DrawString( badge.Name, fontBold, brush, rect); string text = badge.Description ?? badge.Hint; rect.Y += size.Height + (3 * factor.Height); e.Graphics.DrawString( text, font, brush, rect, format); Rectangle rect2 = new Rectangle( e.Bounds.X, e.Bounds.Bottom - 2, e.Bounds.Width / 3, 1); Tenor.Mobile.Drawing.GradientFill.Fill(e.Graphics, rect2, this.BackColor, Color.Gray, Tenor.Mobile.Drawing.GradientFill.FillDirection.LeftToRight); rect2.X += rect2.Width; Tenor.Mobile.Drawing.GradientFill.Fill(e.Graphics, rect2, Color.Gray, Color.Gray, Tenor.Mobile.Drawing.GradientFill.FillDirection.LeftToRight); rect2.X += rect2.Width; Tenor.Mobile.Drawing.GradientFill.Fill(e.Graphics, rect2, Color.Gray, this.BackColor, Tenor.Mobile.Drawing.GradientFill.FillDirection.LeftToRight); } }
public UserLogin() { InitializeComponent(); pbxUname.Image = AlphaImage.CreateFromFile(path + @"\Resources\login_people.png"); pbxUname.Alpha = 200; pbxPwd.Image = AlphaImage.CreateFromFile(path + @"\Resources\login_lock.png"); pbxPwd.Alpha = 200; hkUserLogin.KeyHandlerDelegate += new Hook.KeyHandler(hkUserLogin_KeyHandlerDelegate); hkUserLogin.Start(); LoadLoginInfo(); //testLogin(); }
private void picMap_Paint(object sender, PaintEventArgs e) { if (picMap.Tag != null && picMap.Tag is byte[]) { try { picMap.Tag = new AlphaImage(Main.CreateRoundedAvatar((byte[])picMap.Tag, picMap.Size, factor)); } catch { GC.Collect(); } } Rectangle picMapRect = new Rectangle(0, 0, picMap.Width, picMap.Height); if (picMap.Tag != null && picMap.Tag is AlphaImage) { string text = string.Format("{0}\r\n{1}", fixType, helpText); try { ((AlphaImage)picMap.Tag).Draw(e.Graphics, picMapRect); e.Graphics.DrawString( text, font, brush1, 4 * factor.Width, 4 * factor.Height); e.Graphics.DrawString( text, font, brush2, 3 * factor.Width, 3 * factor.Height); if (!selectedPoint.IsEmpty) { Pen p = new Pen(Color.Black); int size = Convert.ToInt32(10 * factor.Width); if (pin == null) { pin = new AlphaImage(Resources.Pin); } Rectangle rect = new Rectangle(selectedPoint.X - Convert.ToInt32(2 * factor.Width), selectedPoint.Y - size, size, size); pin.Draw(e.Graphics, rect); } } catch (Exception ex) { MySquare.Service.Log.RegisterLog("gdi", ex); } } else if (!ellipse.IsEmpty) { TextureBrush brush = new TextureBrush(Resources.MapBg); Tenor.Mobile.Drawing.RoundedRectangle.Fill(e.Graphics, new Pen(Color.Gray), brush, picMapRect, ellipse); } }
public Main() { InitializeComponent(); pbxLogo.Image = AlphaImage.CreateFromFile(path + @"\Resources\logo.png"); pbxLogo.Alpha = 200; lblDeviceID.Text = TerminalInfo.GetDeviceID(); clsMessage = new Cls_Message(this.Handle); clsMessage.MessageHandlerDelegate += new Cls_Message.MessageHandler(clsMessage_MessageHandlerDelegate); hkMain.KeyHandlerDelegate += new Hook.KeyHandler(hkMain_KeyHandlerDelegate); hkMain.Start(); RecordAppLocation(); CheckNewVersion(); }
private void picAvatar_Paint(object sender, PaintEventArgs e) { try { if (img == null) { img = new AlphaImage(Resources.Shout); } img.Draw(e.Graphics, new Rectangle(0, 0, picAvatar.Width, picAvatar.Height)); } catch (Exception ex) { Log.RegisterLog("gdi", ex); } }
private void picAvatar_Paint(object sender, PaintEventArgs e) { try { if (avatar != null) { AlphaImage alpha = new AlphaImage(avatar); alpha.Draw(e.Graphics, new Rectangle( 0, 0, picAvatar.Width, picAvatar.Height), Tenor.Mobile.UI.Skin.Current.SelectedBackColor); } } catch (Exception ex) { Log.RegisterLog("gdi", ex); } }
private void SaveAlphaImage(BinaryWriter writer, AlphaImage ii) { BitmapInfoHeader bih = ii.iconHeader; writer.Write(bih.biSize); writer.Write(bih.biWidth); writer.Write(bih.biHeight); writer.Write(bih.biPlanes); writer.Write(bih.biBitCount); writer.Write(bih.biCompression); writer.Write(bih.biSizeImage); writer.Write(bih.biXPelsPerMeter); writer.Write(bih.biYPelsPerMeter); writer.Write(bih.biClrUsed); writer.Write(bih.biClrImportant); //now write bits writer.Write(ii.iconARGB); }
private void UserInfo_Paint(object sender, PaintEventArgs e) { if (imgEmail == null) { imgEmail = new AlphaImage(Resources.Email); } if (imgFacebook == null) { imgFacebook = new AlphaImage(Resources.Facebook); } if (imgTwitter == null) { imgTwitter = new AlphaImage(Resources.Twitter); } if (imgFoursquare == null) { imgFoursquare = new AlphaImage(Resources.Foursquare); } int padd = (3 * Tenor.Mobile.UI.Skin.Current.ScaleFactor.Width); imgFoursquare.Draw(e.Graphics, new Rectangle( lnkFoursquare.Left - lnkFoursquare.Height, lnkFoursquare.Top, lnkFoursquare.Height - padd, lnkFoursquare.Height - padd)); imgEmail.Draw(e.Graphics, new Rectangle( lblEmail.Left - lblEmail.Height, lblEmail.Top, lblEmail.Height - padd, lblEmail.Height - padd)); imgFacebook.Draw(e.Graphics, new Rectangle( lblFacebook.Left - lblFacebook.Height, lblFacebook.Top, lblFacebook.Height - padd, lblFacebook.Height - padd)); imgTwitter.Draw(e.Graphics, new Rectangle( lblTwitter.Left - lblTwitter.Height, lblTwitter.Top, lblTwitter.Height - padd, lblTwitter.Height - padd)); }
private void Img_Paint(object sender, PaintEventArgs e) { Control control = ((Control)sender); if (control.Tag != null) { try { if (control.Tag is byte[]) { control.Tag = new AlphaImage (Main.CreateRoundedAvatar((byte[])control.Tag, control.Width, factor)); } AlphaImage image = (AlphaImage)control.Tag; Rectangle rect = new Rectangle(0, 0, control.Width, control.Height); image.Draw(e.Graphics, rect); } catch { control.Tag = null; } } }
private void picMap_Paint(object sender, PaintEventArgs e) { if (picMap.Tag != null && picMap.Tag is byte[]) { try { picMap.Tag = new AlphaImage(Main.CreateRoundedAvatar((byte[])picMap.Tag, picMap.Size, factor)); } catch (Exception ex) { Log.RegisterLog("gdi", ex); GC.Collect(); } } if (picMap.Tag != null && picMap.Tag is AlphaImage) { AlphaImage image = (AlphaImage)picMap.Tag; Rectangle picMapRect = new Rectangle(0, 0, image.Width, image.Height); try { image.Draw(e.Graphics, picMapRect); } catch (Exception ex) { Log.RegisterLog("gdi", ex); picMap.Tag = null; } } else if (!ellipse.IsEmpty) { try { Rectangle picMapRect = new Rectangle(0, 0, picMap.Width, picMap.Height); TextureBrush brush = new TextureBrush(Resources.MapBg); Tenor.Mobile.Drawing.RoundedRectangle.Fill(e.Graphics, new Pen(Color.Gray), brush, picMapRect, ellipse); } catch { } } }
private void InitFromStreamWithSize(Stream stream, int width, int height) { //read the icon header if (stream == null || stream.Length == 0) { throw new System.ArgumentException("The argument 'stream' must be a picture that can be used as a Icon", "stream"); } BinaryReader reader = new BinaryReader(stream); //iconDir = new IconDir (); iconDir.idReserved = reader.ReadUInt16(); if (iconDir.idReserved != 0) //must be 0 { throw new System.ArgumentException("Invalid Argument", "stream"); } iconDir.idType = reader.ReadUInt16(); if (iconDir.idType != 1) //must be 1 { throw new System.ArgumentException("Invalid Argument", "stream"); } ushort dirEntryCount = reader.ReadUInt16(); if (dirEntryCount == 0) { throw new Win32Exception(0, "Zero directory entry count."); } imageData = new ImageData [dirEntryCount]; iconDir.idCount = dirEntryCount; iconDir.idEntries = new IconDirEntry [dirEntryCount]; bool sizeObtained = false; // now read in the IconDirEntry structures for (int i = 0; i < dirEntryCount; i++) { IconDirEntry ide; ide.width = reader.ReadByte(); ide.height = reader.ReadByte(); ide.colorCount = reader.ReadByte(); ide.reserved = reader.ReadByte(); ide.planes = reader.ReadUInt16(); ide.bitCount = reader.ReadUInt16(); ide.bytesInRes = reader.ReadUInt32(); ide.imageOffset = reader.ReadUInt32(); #if false Console.WriteLine("Entry: {0}", i); Console.WriteLine("\tide.width: {0}", ide.width); Console.WriteLine("\tide.height: {0}", ide.height); Console.WriteLine("\tide.colorCount: {0}", ide.colorCount); Console.WriteLine("\tide.reserved: {0}", ide.reserved); Console.WriteLine("\tide.planes: {0}", ide.planes); Console.WriteLine("\tide.bitCount: {0}", ide.bitCount); Console.WriteLine("\tide.bytesInRes: {0}", ide.bytesInRes); Console.WriteLine("\tide.imageOffset: {0}", ide.imageOffset); #endif // Vista 256x256 icons points directly to a PNG bitmap // 256x256 icons are decoded as 0x0 (width and height are encoded as BYTE) // and we ignore them just like MS does (at least up to fx 2.0) // Added: storing data so it can be saved back if ((ide.width == 0) && (ide.height == 0)) { ide.ignore = true; } else { ide.ignore = false; } iconDir.idEntries [i] = ide; //is this is the best fit?? if (!sizeObtained) { if (((ide.height == height) || (ide.width == width)) && !ide.ignore) { this.id = (ushort)i; sizeObtained = true; this.iconSize.Height = ide.height; this.iconSize.Width = ide.width; } } } // throw error if no valid entries found int valid = 0; for (int i = 0; i < dirEntryCount; i++) { if (!(iconDir.idEntries [i].ignore)) { valid++; } } if (valid == 0) { iconDir.idEntries [0].ignore = false; } // if we havent found the best match, return the one with the // largest size. Is this approach correct?? if (!sizeObtained) { uint largestSize = 0; for (int j = 0; j < dirEntryCount; j++) { if (iconDir.idEntries [j].bytesInRes >= largestSize && !iconDir.idEntries [j].ignore) { largestSize = iconDir.idEntries [j].bytesInRes; this.id = (ushort)j; if (iconDir.idEntries[j].height == 0 && iconDir.idEntries[j].width == 0) { this.iconSize.Height = 256; this.iconSize.Width = 256; } else { this.iconSize.Height = iconDir.idEntries [j].height; this.iconSize.Width = iconDir.idEntries [j].width; } } } } //now read in the icon data for (int j = 0; j < dirEntryCount; j++) { // process ignored into IconDump if (iconDir.idEntries [j].ignore) { IconDump id = new IconDump(); stream.Seek(iconDir.idEntries [j].imageOffset, SeekOrigin.Begin); id.data = new byte [iconDir.idEntries [j].bytesInRes]; stream.Read(id.data, 0, id.data.Length); imageData [j] = id; continue; } // standard image IconImage iidata = new IconImage(); BitmapInfoHeader bih = new BitmapInfoHeader(); stream.Seek(iconDir.idEntries [j].imageOffset, SeekOrigin.Begin); byte [] png_header = new byte[] { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a }; byte [] buffer = new byte [iconDir.idEntries [j].bytesInRes]; stream.Read(buffer, 0, buffer.Length); if (iconDir.idEntries[j].height == 0 && iconDir.idEntries[j].width == 0) { int i; for (i = 0; i < 8; ++i) { if (png_header[i] != buffer[i]) { break; } } if (i == 8) { /* PNG image, convert it. */ Bitmap bmp = new Bitmap(new MemoryStream(buffer)); AlphaImage aidata = new AlphaImage(); aidata.iconHeader.biSize = 40; aidata.iconHeader.biWidth = bmp.Width; aidata.iconHeader.biHeight = bmp.Height; aidata.iconHeader.biPlanes = 1; aidata.iconHeader.biBitCount = 32; aidata.iconHeader.biCompression = 0; aidata.iconHeader.biSizeImage = 0; aidata.iconHeader.biXPelsPerMeter = 0; aidata.iconHeader.biYPelsPerMeter = 0; aidata.iconHeader.biClrUsed = 0; aidata.iconHeader.biClrImportant = 0; BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); int bytes = Math.Abs(bmpData.Stride) * bmp.Height; IntPtr ptr = bmpData.Scan0; aidata.iconARGB = new byte[bytes]; System.Runtime.InteropServices.Marshal.Copy(ptr, aidata.iconARGB, 0, bytes); bmp.UnlockBits(bmpData); imageData [j] = aidata; continue; } } BinaryReader bihReader = new BinaryReader(new MemoryStream(buffer)); bih.biSize = bihReader.ReadUInt32(); bih.biWidth = bihReader.ReadInt32(); bih.biHeight = bihReader.ReadInt32(); bih.biPlanes = bihReader.ReadUInt16(); bih.biBitCount = bihReader.ReadUInt16(); bih.biCompression = bihReader.ReadUInt32(); bih.biSizeImage = bihReader.ReadUInt32(); bih.biXPelsPerMeter = bihReader.ReadInt32(); bih.biYPelsPerMeter = bihReader.ReadInt32(); bih.biClrUsed = bihReader.ReadUInt32(); bih.biClrImportant = bihReader.ReadUInt32(); #if false Console.WriteLine("Entry: {0}", j); Console.WriteLine("\tbih.biSize: {0}", bih.biSize); Console.WriteLine("\tbih.biWidth: {0}", bih.biWidth); Console.WriteLine("\tbih.biHeight: {0}", bih.biHeight); Console.WriteLine("\tbih.biPlanes: {0}", bih.biPlanes); Console.WriteLine("\tbih.biBitCount: {0}", bih.biBitCount); Console.WriteLine("\tbih.biCompression: {0}", bih.biCompression); Console.WriteLine("\tbih.biSizeImage: {0}", bih.biSizeImage); Console.WriteLine("\tbih.biXPelsPerMeter: {0}", bih.biXPelsPerMeter); Console.WriteLine("\tbih.biYPelsPerMeter: {0}", bih.biYPelsPerMeter); Console.WriteLine("\tbih.biClrUsed: {0}", bih.biClrUsed); Console.WriteLine("\tbih.biClrImportant: {0}", bih.biClrImportant); #endif iidata.iconHeader = bih; //Read the number of colors used and corresponding memory occupied by //color table. Fill this memory chunk into rgbquad[] int numColors; switch (bih.biBitCount) { case 1: numColors = 2; break; case 4: numColors = 16; break; case 8: numColors = 256; break; default: numColors = 0; break; } iidata.iconColors = new uint [numColors]; for (int i = 0; i < numColors; i++) { iidata.iconColors [i] = bihReader.ReadUInt32(); } //XOR mask is immediately after ColorTable and its size is //icon height* no. of bytes per line //icon height is half of BITMAPINFOHEADER.biHeight, since it contains //both XOR as well as AND mask bytes int iconHeight = bih.biHeight / 2; //bytes per line should should be uint aligned int numBytesPerLine = ((((bih.biWidth * bih.biPlanes * bih.biBitCount) + 31) >> 5) << 2); //Determine the XOR array Size int xorSize = numBytesPerLine * iconHeight; iidata.iconXOR = new byte [xorSize]; int nread = bihReader.Read(iidata.iconXOR, 0, xorSize); if (nread != xorSize) { string msg = Locale.GetText("{0} data length expected {1}, read {2}", "XOR", xorSize, nread); throw new ArgumentException(msg, "stream"); } if (bih.biBitCount == 32) { // This may be an ARGB icon bool has_alpha = false; for (int k = 3; k < xorSize; k += 4) { if (iidata.iconXOR [k] != 0) { has_alpha = true; break; } } if (has_alpha) { AlphaImage aidata = new AlphaImage(); aidata.iconHeader = iidata.iconHeader; aidata.iconARGB = iidata.iconXOR; imageData [j] = aidata; bihReader.Dispose(); continue; } } //Determine the AND array size numBytesPerLine = (int)((((bih.biWidth) + 31) & ~31) >> 3); int andSize = numBytesPerLine * iconHeight; iidata.iconAND = new byte [andSize]; nread = bihReader.Read(iidata.iconAND, 0, andSize); if (nread != andSize) { string msg = Locale.GetText("{0} data length expected {1}, read {2}", "AND", andSize, nread); throw new ArgumentException(msg, "stream"); } imageData [j] = iidata; bihReader.Dispose(); } reader.Dispose(); }
internal Bitmap BuildBitmapOnWin32() { Bitmap bmp; if (imageData == null) { return(new Bitmap(32, 32)); } if (imageData [id] is AlphaImage) { AlphaImage ai = (AlphaImage)imageData [id]; BitmapData bd = new BitmapData(); bd.Width = ai.iconHeader.biWidth; bd.Height = ai.iconHeader.biHeight / 2; bd.PixelFormat = PixelFormat.Format32bppArgb; bd.Stride = -ai.iconHeader.biWidth * 4; bmp = new Bitmap(bd.Width, bd.Height, PixelFormat.Format32bppArgb); unsafe { fixed(byte *p = ai.iconARGB) { bd.Scan0 = (IntPtr)(p + (bd.Width * 4 * (bd.Height - 1))); BitmapData bd2 = bmp.LockBits( new Rectangle(0, 0, bd.Width, bd.Height), ImageLockMode.WriteOnly | ImageLockMode.UserInputBuffer, PixelFormat.Format32bppArgb, bd); bmp.UnlockBits(bd2); } } return(bmp); } IconImage ii = (IconImage)imageData [id]; BitmapInfoHeader bih = ii.iconHeader; int biHeight = bih.biHeight / 2; int ncolors = (int)bih.biClrUsed; if ((ncolors == 0) && (bih.biBitCount < 24)) { ncolors = (int)(1 << bih.biBitCount); } switch (bih.biBitCount) { case 1: bmp = new Bitmap(bih.biWidth, biHeight, PixelFormat.Format1bppIndexed); break; case 4: bmp = new Bitmap(bih.biWidth, biHeight, PixelFormat.Format4bppIndexed); break; case 8: bmp = new Bitmap(bih.biWidth, biHeight, PixelFormat.Format8bppIndexed); break; case 24: bmp = new Bitmap(bih.biWidth, biHeight, PixelFormat.Format24bppRgb); break; case 32: bmp = new Bitmap(bih.biWidth, biHeight, PixelFormat.Format32bppArgb); break; default: string msg = Locale.GetText("Unexpected number of bits: {0}", bih.biBitCount); throw new Exception(msg); } if (bih.biBitCount < 24) { ColorPalette pal = bmp.Palette; // Managed palette for (int i = 0; i < ii.iconColors.Length; i++) { pal.Entries[i] = Color.FromArgb((int)ii.iconColors[i] | unchecked ((int)0xff000000)); } bmp.Palette = pal; } int bytesPerLine = (int)((((bih.biWidth * bih.biBitCount) + 31) & ~31) >> 3); BitmapData bits = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat); for (int y = 0; y < biHeight; y++) { Marshal.Copy(ii.iconXOR, bytesPerLine * y, (IntPtr)(bits.Scan0.ToInt64() + bits.Stride * (biHeight - 1 - y)), bytesPerLine); } bmp.UnlockBits(bits); bmp = new Bitmap(bmp); // This makes a 32bpp image out of an indexed one // Apply the mask to make properly transparent bytesPerLine = (int)((((bih.biWidth) + 31) & ~31) >> 3); for (int y = 0; y < biHeight; y++) { for (int x = 0; x < bih.biWidth / 8; x++) { for (int bit = 7; bit >= 0; bit--) { if (((ii.iconAND[y * bytesPerLine + x] >> bit) & 1) != 0) { bmp.SetPixel(x * 8 + 7 - bit, biHeight - y - 1, Color.Transparent); } } } } return(bmp); }
void lstAll_DrawItem(object sender, Tenor.Mobile.UI.DrawItemEventArgs e) { var listBox = (Tenor.Mobile.UI.KListControl)sender; LeaderboardUser lboard = (LeaderboardUser)e.Item.Value; User user = lboard.User; string rankText = "#" + lboard.Rank.ToString(); SizeF rankSize = e.Graphics.MeasureString(rankText, medFont); RectangleF rankRect = new RectangleF( 3 * factorF.Width, e.Bounds.Y + (e.Bounds.Height / 2 - rankSize.Height / 2), rankSize.Width, rankSize.Height ); Size factor = Tenor.Mobile.UI.Skin.Current.ScaleFactor; if (!string.IsNullOrEmpty(user.ToString())) { int padding = 5 * factor.Width; int imageSize = listBox.DefaultItemHeight - padding; RectangleF rect = new RectangleF (imageSize + (padding * 2) + rankRect.Right, e.Bounds.Y, e.Bounds.Width - (imageSize) - (padding * 2), e.Bounds.Height); if (user.FriendStatus != null && user.FriendStatus.Value == FriendStatus.self) { Tenor.Mobile.Drawing.RoundedRectangle.Fill(e.Graphics, borderPen, selectedBrush, e.Bounds, new Size(8 * factor.Width, 8 * factor.Height)); } e.Graphics.DrawString(rankText, medFont, brush, rankRect); if (imageList != null && imageList.ContainsKey(user.ImageUrl)) { if (!imageListBuffer.ContainsKey(user.ImageUrl)) { imageListBuffer.Add(user.ImageUrl, new AlphaImage(Main.CreateRoundedAvatar(imageList[user.ImageUrl], imageSize, factorF))); } AlphaImage image = imageListBuffer[user.ImageUrl]; Rectangle imgRect = new Rectangle(Convert.ToInt32(rankRect.Right + padding), Convert.ToInt32(rect.Y + (rect.Height / 2) - (imageSize / 2)), imageSize, imageSize); try { //e.Graphics.DrawImage(image, imgRect, new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel); image.Draw(e.Graphics, imgRect); } catch (Exception ex) { Log.RegisterLog("gdi", ex); } } rect.Y += 2 * factor.Height; SizeF size = e.Graphics.MeasureString(user.ToString(), fontBold); e.Graphics.DrawString( user.ToString(), fontBold, brush, rect); if (lboard.Scores != null) { string text = "7-day high score: "; text += lboard.Scores.Max.ToString(); rect.Y += size.Height + (3 * factor.Height); e.Graphics.DrawString( text, font, brush, rect, format); var scoreText = lboard.Scores.Recent.ToString(); SizeF sizeScore = e.Graphics.MeasureString(scoreText, bigFont); rect = new RectangleF( e.Bounds.Width - sizeScore.Width - (10 * factorF.Width), e.Bounds.Y + (e.Bounds.Height / 2 - sizeScore.Height / 2), sizeScore.Width, sizeScore.Height ); e.Graphics.DrawString( scoreText, bigFont, brush, rect, format); } if (user.FriendStatus != null && user.FriendStatus.Value != FriendStatus.self) { Rectangle rect2 = new Rectangle( e.Bounds.X, e.Bounds.Bottom - 2, e.Bounds.Width / 3, 1); Tenor.Mobile.Drawing.GradientFill.Fill(e.Graphics, rect2, this.BackColor, Color.Gray, Tenor.Mobile.Drawing.GradientFill.FillDirection.LeftToRight); rect2.X += rect2.Width; Tenor.Mobile.Drawing.GradientFill.Fill(e.Graphics, rect2, Color.Gray, Color.Gray, Tenor.Mobile.Drawing.GradientFill.FillDirection.LeftToRight); rect2.X += rect2.Width; Tenor.Mobile.Drawing.GradientFill.Fill(e.Graphics, rect2, Color.Gray, this.BackColor, Tenor.Mobile.Drawing.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(); } }
private void listBox_DrawItem(object sender, Tenor.Mobile.UI.DrawItemEventArgs e) { User user = (User)e.Item.Value; Size factor = Tenor.Mobile.UI.Skin.Current.ScaleFactor; if (!string.IsNullOrEmpty(user.ToString())) { int padding = 5 * factor.Width; int imageSize = listBox.DefaultItemHeight - padding; RectangleF rect = new RectangleF (e.Bounds.X + imageSize + (padding * 2), e.Bounds.Y, e.Bounds.Width - (imageSize) - (padding * 2), e.Bounds.Height); if (e.Item.Selected) { Tenor.Mobile.Drawing.RoundedRectangle.Fill(e.Graphics, borderPen, selectedBrush, e.Bounds, new Size(8 * factor.Width, 8 * factor.Height)); } if (imageList != null && imageList.ContainsKey(user.ImageUrl)) { if (!imageListBuffer.ContainsKey(user.ImageUrl)) { imageListBuffer.Add(user.ImageUrl, new AlphaImage(Main.CreateRoundedAvatar(imageList[user.ImageUrl], imageSize, factorF))); } AlphaImage image = imageListBuffer[user.ImageUrl]; Rectangle imgRect = new Rectangle(0 + Convert.ToInt32(padding), Convert.ToInt32(rect.Y + (rect.Height / 2) - (imageSize / 2)), imageSize, imageSize); try { //e.Graphics.DrawImage(image, imgRect, new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel); image.Draw(e.Graphics, imgRect); } catch (Exception ex) { Log.RegisterLog("gdi", ex); } } rect.Y += 2 * factor.Height; SizeF size = e.Graphics.MeasureString(user.ToString(), fontBold); e.Graphics.DrawString( user.ToString(), fontBold, brush, rect); if (user.CheckIn != null) { string text = string.Empty; if (user.CheckIn.Venue != null) { text = "@ " + user.CheckIn.Venue.Name; } else if (!string.IsNullOrEmpty(user.CheckIn.Shout)) { text = user.CheckIn.Shout; } else if (user.CheckIn.Created > DateTime.MinValue) { text = user.CheckIn.Created.ToHumanTime(); } rect.Y += size.Height + (3 * factor.Height); e.Graphics.DrawString( text, font, brush, rect, format); } if (!e.Item.Selected) { Rectangle rect2 = new Rectangle( e.Bounds.X, e.Bounds.Bottom - 2, e.Bounds.Width / 3, 1); Tenor.Mobile.Drawing.GradientFill.Fill(e.Graphics, rect2, this.BackColor, Color.Gray, Tenor.Mobile.Drawing.GradientFill.FillDirection.LeftToRight); rect2.X += rect2.Width; Tenor.Mobile.Drawing.GradientFill.Fill(e.Graphics, rect2, Color.Gray, Color.Gray, Tenor.Mobile.Drawing.GradientFill.FillDirection.LeftToRight); rect2.X += rect2.Width; Tenor.Mobile.Drawing.GradientFill.Fill(e.Graphics, rect2, Color.Gray, this.BackColor, Tenor.Mobile.Drawing.GradientFill.FillDirection.LeftToRight); } } }
private void listBox_DrawItem(object sender, Tenor.Mobile.UI.DrawItemEventArgs e) { if (smallFont == null) { smallFont = new Font(this.Font.Name, this.Font.Size - 1, this.Font.Style); } if (format == null) { format = new StringFormat(); } if (textBrush == null) { textBrush = new SolidBrush(Color.White); } if (secondBrush == null) { secondBrush = new SolidBrush(Color.LightGray); } Font thisFont = listBox.Font; float thisLeft = e.Bounds.Height; string text = e.Item.Text; string secondText = null; if (text.IndexOf("\r\n") > -1) { string[] textS = text.Split('\r', '\n'); text = textS[0]; secondText = textS[2]; } SizeF measuring = e.Graphics.MeasureString(text, thisFont); RectangleF rect = new RectangleF(thisLeft, e.Bounds.Y + itemPadding, measuring.Width, measuring.Height); Color color = Tenor.Mobile.UI.Skin.Current.ControlBackColor; if (e.Item.YIndex % 2 == 0) { color = Tenor.Mobile.UI.Skin.Current.AlternateBackColor; } //if (!e.Item.Selected) // e.Graphics.FillRectangle(new SolidBrush(color), e.Bounds); if (e.Item.YIndex > 0) { e.Graphics.DrawSeparator(e.Bounds, color); } e.Graphics.DrawString(text, thisFont, textBrush, rect, format); if (secondText != null) { measuring = e.Graphics.MeasureString(secondText, smallFont); rect = new RectangleF(rect.X, rect.Bottom + itemPadding, measuring.Width, measuring.Height); e.Graphics.DrawString(secondText, smallFont, secondBrush, rect, format); } AlphaImage alpha = e.Item.Value as AlphaImage; if (alpha != null) { try { int imageSize = e.Bounds.Height - Convert.ToInt32(itemPadding * 2); alpha.Draw(e.Graphics, new Rectangle( e.Bounds.X + Convert.ToInt32(itemPadding), e.Bounds.Y + Convert.ToInt32(itemPadding), imageSize, imageSize)); } catch (Exception ex) { Log.RegisterLog("gdi", ex); } } }
private void listBox_DrawItem(object sender, Tenor.Mobile.UI.DrawItemEventArgs e) { object obj = e.Item.Value; Venue venue = e.Item.Value as Venue; Tip tip = e.Item.Value as Tip; if (tip != null) { venue = tip.Venue; } Brush textBrush = (e.Item.Selected ? brushS : brush); if (obj == null) { if (smallFont == null) { smallFont = new Font(this.Font.Name, this.Font.Size - 1, this.Font.Style); } Font thisFont; float thisLeft; if (e.Item.YIndex < listBox.Count - 1) { thisLeft = itemPadding; thisFont = smallFont; } else { thisLeft = e.Bounds.Height; thisFont = Font; } string text = e.Item.Text; if (text.EndsWith("Nearby") && Address != null) { StringBuilder geo = new StringBuilder(); if (!string.IsNullOrEmpty(Address.Neighborhood)) { geo.Append(", "); geo.Append(Address.Neighborhood); } if (!string.IsNullOrEmpty(Address.City)) { geo.Append(", "); geo.Append(Address.City); } if (string.IsNullOrEmpty(Address.Neighborhood) && string.IsNullOrEmpty(Address.City)) { if (!string.IsNullOrEmpty(Address.Province)) { geo.Append(", "); geo.Append(Address.Province); } if (!string.IsNullOrEmpty(Address.Country)) { geo.Append(", "); geo.Append(Address.Country); } } if (geo.Length > 0) { geo = geo.Remove(0, 2); text += " " + geo.ToString(); } } string secondText = null; if (text.IndexOf("\r\n") > -1) { string[] textS = text.Split('\r', '\n'); text = textS[0]; secondText = textS[2]; } SizeF measuring = e.Graphics.MeasureString(text, thisFont); RectangleF rect = new RectangleF(thisLeft, e.Bounds.Y + itemPadding, measuring.Width, measuring.Height); Color color = Tenor.Mobile.UI.Skin.Current.ControlBackColor; if (e.Item.YIndex % 2 == 0) { color = Tenor.Mobile.UI.Skin.Current.AlternateBackColor; } if (e.Item.YIndex < listBox.Count - 1) { e.Graphics.FillRectangle(new SolidBrush(color), e.Bounds); } if (e.Item.YIndex > 0) { e.Graphics.DrawSeparator(e.Bounds, color); } e.Graphics.DrawString(text, thisFont, textBrush, rect, format); if (secondText != null) { if (secondFont == null) { secondFont = new Font(Font.Name, Font.Size - 1, Font.Style); } measuring = e.Graphics.MeasureString(secondText, secondFont); rect = new RectangleF(rect.X, rect.Bottom + itemPadding, measuring.Width, measuring.Height); e.Graphics.DrawString(secondText, secondFont, secondBrush, rect, format); } } else { string title = null; if (tip != null) { title = tip.User.ToString() + " @ " + venue.Name; } else { title = venue.Name; } SizeF measuring = e.Graphics.MeasureString(title, Font); RectangleF rect = new RectangleF(listBox.DefaultItemHeight, e.Bounds.Y + itemPadding, measuring.Width, measuring.Height); if (tip != null) { rect.X = e.Bounds.X + itemPadding; } e.Graphics.DrawString(title, this.Font, textBrush, rect, format); string secondText = null; if (tip != null && !string.IsNullOrEmpty(tip.Text)) { secondText = tip.Text; } else if (venue.Location != null) { if (!string.IsNullOrEmpty(venue.Location.Address)) { secondText = venue.Location.Address; } else if (!string.IsNullOrEmpty(venue.Location.City)) { secondText = venue.Location.City; } else if (!string.IsNullOrEmpty(venue.Location.State)) { secondText = venue.Location.State; } } if (secondText != null) { if (secondFont == null) { secondFont = new Font(Font.Name, Font.Size - 1, Font.Style); } measuring = e.Graphics.MeasureString(secondText, secondFont); rect = new RectangleF(rect.X, rect.Bottom + itemPadding, e.Bounds.Width - rect.X, e.Bounds.Height); e.Graphics.DrawString(secondText, secondFont, secondBrush, rect, formatWrap); } if ( ( (venue.PrimaryCategory == null && imageList.ContainsKey(string.Empty)) || (venue.PrimaryCategory != null && imageList.ContainsKey(venue.PrimaryCategory.IconUrl.ToString())) ) && tip == null ) { string iconUrl = string.Empty; if (venue.PrimaryCategory != null) { iconUrl = venue.PrimaryCategory.IconUrl.ToString(); } int imageSize = listBox.DefaultItemHeight - Convert.ToInt32(itemPadding * 2); if (!imageListBuffer.ContainsKey(iconUrl)) { imageListBuffer.Add(iconUrl, new AlphaImage(Main.CreateRoundedAvatar(imageList[iconUrl], imageSize, factor))); } AlphaImage alpha = imageListBuffer[iconUrl]; try { alpha.Draw(e.Graphics, new Rectangle( e.Bounds.X + Convert.ToInt32(itemPadding), e.Bounds.Y + Convert.ToInt32(itemPadding), imageSize, imageSize), Tenor.Mobile.UI.Skin.Current.SelectedBackColor); } catch (Exception ex) { imageListBuffer.Remove(iconUrl); Log.RegisterLog("gdi", ex); } } if (venue.Specials != null) { foreach (Special special in venue.Specials) { if (special.Kind != SpecialKind.here) { continue; } try { int padd = 10 * Tenor.Mobile.UI.Skin.Current.ScaleFactor.Height; AlphaImage alpha = new AlphaImage(Resources.SpecialHere); Rectangle rectS = new Rectangle(e.Bounds.Right - listBox.DefaultItemHeight - padd, e.Bounds.Y, listBox.DefaultItemHeight + padd, listBox.DefaultItemHeight + padd); rectS.Y = rectS.Y - (padd / 2); alpha.Draw(e.Graphics, rectS); } catch (Exception ex) { Log.RegisterLog("gdi", ex); } } } } }
private void listBox_DrawItem(object sender, Tenor.Mobile.UI.DrawItemEventArgs e) { string text = null; string secondText = null; string userUrl = null; Font font = this.Font; float thisLeft = e.Bounds.Height; if (e.Item.Value == null) { if (smallFont == null) { smallFont = new Font(this.Font.Name, this.Font.Size - 1, this.Font.Style); } font = smallFont; text = e.Item.Text; Color color = Tenor.Mobile.UI.Skin.Current.ControlBackColor; if (e.Item.YIndex % 2 == 0) { color = Tenor.Mobile.UI.Skin.Current.AlternateBackColor; } e.Graphics.FillRectangle(new SolidBrush(color), e.Bounds); thisLeft = itemPadding; if (e.Item.YIndex > 0) { e.Graphics.DrawSeparator(e.Bounds, color); } } else if (e.Item.Value != null && e.Item.Value is CheckIn) { CheckIn checkIn = (CheckIn)e.Item.Value; text = checkIn.ToString(); if (checkIn.User != null) { userUrl = checkIn.User.ImageUrl; } secondText = checkIn.Created.ToHumanTime(); } else if (e.Item.Value != null && e.Item.Value is User) { User user = (User)e.Item.Value; text = string.Format("{0} {1}", user.FirstName, user.LastName); if (user.Contact != null) { secondText = user.Contact.Email; } userUrl = user.ImageUrl; } Brush textBrush = (e.Item.Selected ? brushS : brush); SizeF measuring = e.Graphics.MeasureString(text, Font); RectangleF rect = new RectangleF(thisLeft, e.Bounds.Y + itemPadding, measuring.Width, measuring.Height); e.Graphics.DrawString(text, font, textBrush, rect, format); if (!string.IsNullOrEmpty(secondText)) { measuring = e.Graphics.MeasureString(secondText, Font); rect = new RectangleF(rect.X, rect.Bottom + itemPadding, measuring.Width, measuring.Height); if (secondFont == null) { secondFont = new Font(Font.Name, Font.Size - 1, Font.Style); } e.Graphics.DrawString(secondText, secondFont, secondBrush, rect, format); } if (userUrl != null && imageList.ContainsKey(userUrl) && imageList[userUrl] != null) { int imageSize = e.Bounds.Height - Convert.ToInt32(itemPadding * 2); if (!imageListBuffer.ContainsKey(userUrl)) { imageListBuffer.Add(userUrl, new AlphaImage(Main.CreateRoundedAvatar(imageList[userUrl], imageSize, factor))); } AlphaImage alpha = imageListBuffer[userUrl]; try { alpha.Draw(e.Graphics, new Rectangle( e.Bounds.X + Convert.ToInt32(itemPadding), e.Bounds.Y + Convert.ToInt32(itemPadding), imageSize, imageSize), Tenor.Mobile.UI.Skin.Current.SelectedBackColor); } catch (Exception ex) { imageListBuffer.Remove(userUrl); Log.RegisterLog("gdi", ex); } } }
private void picGps_Paint(object sender, PaintEventArgs e) { try { if (backBufferG == null) { return; } e.Graphics.DrawImage(backBuffer, 0, 0); backBufferG.Clear(Color.Black); Rectangle size; size = new Rectangle(0, 0, picGps.Height, picGps.Height); if (showGps) { if (gps == null) { gps = new AlphaImage(Resources.Gps); } gps.Draw(backBufferG, size); } size = new Rectangle( size.Width, 0, 14 * Tenor.Mobile.UI.Skin.Current.ScaleFactor.Width, 11 * Tenor.Mobile.UI.Skin.Current.ScaleFactor.Height); if (Program.Location.IsGpsOpen) { Debug.Write(Program.Location.Sattelites.ToString()); int strength = 0; if (Program.Location.Sattelites.Total > 0) { float active = Program.Location.Sattelites.Active; float total = Program.Location.Sattelites.Total; if (active > 0 && active <= 2) { active = 1; } else { active -= 2; } if (total > 4) { total = 4; } float strengthPercent = (active / total) * 100F; strength = Convert.ToInt32(Math.Floor(4F * strengthPercent / 100F)); if (strength > 4) { strength = 4; } Debug.WriteLine(": " + strengthPercent.ToString() + ": " + strength.ToString()); } Image image = null; switch (strength) { case 1: image = Resources.Gps_1; break; case 2: image = Resources.Gps_2; break; case 3: image = Resources.Gps_3; break; case 4: image = Resources.Gps_4; break; default: image = Resources.Gps_0; break; } backBufferG.DrawImage(image, size, new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel); } e.Graphics.DrawImage(backBuffer, 0, 0); } catch (Exception ex) { Log.RegisterLog("gdi", ex); } }