📄 buddylist_drawer!1.cs
字号:
namespace Imps.Client.Pc.BizControls
{
using Imps.Client.Core;
using Imps.Client.Resource;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
public class buddylist_drawer<t_item_context> : listbox_drawer_base
{
private SolidBrush m_background_brush;
private Color m_clr_name;
private Color m_clr_personal_message;
private Color m_clr_selected_name;
private Color m_clr_selected_personal_message;
private int m_itemheight;
private int m_padding;
private SolidBrush m_selected_brush;
private int m_separatorheight;
public buddylist_drawer()
{
this.m_background_brush = new SolidBrush(Color.White);
this.m_selected_brush = new SolidBrush(Color.FromArgb(0xff, 0x31, 0x6a, 0xc5));
this.m_clr_name = Color.Black;
this.m_clr_selected_name = Color.White;
this.m_clr_personal_message = Color.Gray;
this.m_clr_selected_personal_message = Color.Gray;
this.m_itemheight = 40;
this.m_separatorheight = 0x1a;
this.m_padding = 2;
}
public override void draw_background(listbox_widget host, Graphics g)
{
if ((0 < host.ClientRectangle.Width) && (0 < host.ClientRectangle.Height))
{
if (0 < host.Items.Count)
{
Rectangle itemRectangle = host.GetItemRectangle(host.Items.Count - 1);
if (itemRectangle.Bottom >= host.ClientRectangle.Bottom)
{
return;
}
Rectangle rect = Rectangle.FromLTRB(host.ClientRectangle.Left, itemRectangle.Bottom, host.ClientRectangle.Right, host.ClientRectangle.Bottom);
g.SetClip(rect);
}
using (Bitmap image = new Bitmap(host.ClientRectangle.Width, host.ClientRectangle.Height))
{
using (Graphics graphics = Graphics.FromImage(image))
{
graphics.FillRectangle(this.m_background_brush, 0, 0, image.Width, image.Height);
}
g.DrawImage(image, host.ClientRectangle.Location);
}
}
}
public override void draw_host_item(listbox_widget host, DrawItemEventArgs e)
{
Rectangle rect = host.GetItemRectangle(e.Index);
using (Bitmap image = new Bitmap(rect.Width, rect.Height))
{
using (Graphics g = Graphics.FromImage(image))
{
object obj2 = host.Items[e.Index];
Rectangle rectangle2 = Rectangle.FromLTRB(0, 0, rect.Width, rect.Height);
if (obj2 is listbox_widget.separator)
{
this.draw_separator(g, rectangle2, (listbox_widget.separator) obj2);
}
else if (obj2 is buddylistbox_item<t_item_context>)
{
this.draw_item_rectangle(g, rectangle2, e.State);
this.draw_item_image(g, rectangle2, (buddylistbox_item<t_item_context>) obj2, DrawItemState.Selected == (e.State & DrawItemState.Selected));
this.draw_item_content(g, rectangle2, (buddylistbox_item<t_item_context>) obj2, e.State);
}
}
e.Graphics.DrawImage(image, rect);
}
}
protected void draw_item_content(Graphics g, Rectangle rect, buddylistbox_item<t_item_context> item, DrawItemState state)
{
if (item == null)
{
return;
}
Rectangle layoutRectangle = Rectangle.FromLTRB(rect.Left + rect.Height, rect.Top + this.m_padding, rect.Right - this.m_padding, rect.Top + (rect.Height / 2));
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Near;
format.LineAlignment = StringAlignment.Center;
format.HotkeyPrefix = HotkeyPrefix.None;
format.Trimming = StringTrimming.EllipsisWord;
format.FormatFlags = StringFormatFlags.NoWrap;
g.DrawString((item.name == null) ? "" : item.name, base.font, new SolidBrush(((state & DrawItemState.Selected) == DrawItemState.Selected) ? this.m_clr_selected_name : this.m_clr_name), layoutRectangle, format);
layoutRectangle.Offset(0, layoutRectangle.Height);
StringBuilder str = new StringBuilder(item.personal_message);
List<object> list = EmoticonParser.ParseString(null, this.EllipsisDisplay(str));
int width = 0x10;
Rectangle rectangle2 = Rectangle.FromLTRB(layoutRectangle.Left, layoutRectangle.Top, layoutRectangle.Left, layoutRectangle.Bottom);
List<object>.Enumerator enumerator = list.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
object obj2 = enumerator.get_Current();
if (obj2 is Emoticon)
{
Image image = ((Emoticon) obj2).Image;
if ((rectangle2.Right + width) <= layoutRectangle.Right)
{
rectangle2 = new Rectangle(rectangle2.Left, rectangle2.Top, width, rectangle2.Height);
g.DrawImage(image, rectangle2);
rectangle2 = Rectangle.FromLTRB(rectangle2.Right, rectangle2.Top, rectangle2.Right, rectangle2.Bottom);
}
}
else if (obj2 is string)
{
string text = (string) obj2;
SizeF ef = g.MeasureString(text, base.font);
if ((rectangle2.Right + ef.Width) <= layoutRectangle.Right)
{
rectangle2 = new Rectangle(rectangle2.Left, rectangle2.Top, (int) Math.Ceiling((double) ef.Width), rectangle2.Height);
g.DrawString(text, base.font, new SolidBrush(((state & DrawItemState.Selected) == DrawItemState.Selected) ? this.m_clr_selected_personal_message : this.m_clr_personal_message), rectangle2, format);
rectangle2 = Rectangle.FromLTRB(rectangle2.Right, rectangle2.Top, rectangle2.Right, rectangle2.Bottom);
continue;
}
rectangle2 = new Rectangle(rectangle2.Right, rectangle2.Top, layoutRectangle.Right - rectangle2.Right, rectangle2.Height);
g.DrawString(text, base.font, new SolidBrush(((state & DrawItemState.Selected) == DrawItemState.Selected) ? this.m_clr_selected_personal_message : this.m_clr_personal_message), rectangle2, format);
goto Label_02CF;
}
}
}
finally
{
enumerator.Dispose();
}
Label_02CF:
if ((state & DrawItemState.Focus) == DrawItemState.Focus)
{
Rectangle rectangle = Rectangle.FromLTRB(rect.Left + rect.Height, rect.Top, rect.Right, rect.Bottom);
ControlPaint.DrawFocusRectangle(g, rectangle, Color.White, Color.Blue);
}
}
protected void draw_item_image(Graphics g, Rectangle rect, buddylistbox_item<t_item_context> item, bool fSelected)
{
if ((item != null) && (item.image != null))
{
Rectangle rectangle = Rectangle.FromLTRB(rect.Left + this.m_padding, rect.Top + this.m_padding, (rect.Left + rect.Height) - (this.m_padding * 2), rect.Bottom - this.m_padding);
if (item.image is Image)
{
g.DrawImage((Image) item.image, rectangle);
}
else if (item.image is Icon)
{
g.DrawIcon((Icon) item.image, rectangle);
}
}
}
protected void draw_item_rectangle(Graphics g, Rectangle rect, DrawItemState state)
{
g.FillRectangle(this.m_background_brush, Rectangle.FromLTRB(rect.Left, rect.Top, rect.Left + rect.Height, rect.Bottom));
if ((state & DrawItemState.Selected) == DrawItemState.Selected)
{
g.FillRectangle(this.m_selected_brush, Rectangle.FromLTRB(rect.Left + rect.Height, rect.Top, rect.Right, rect.Bottom));
}
else
{
g.FillRectangle(this.m_background_brush, Rectangle.FromLTRB(rect.Left + rect.Height, rect.Top, rect.Right, rect.Bottom));
}
}
protected void draw_separator(Graphics g, Rectangle rect, listbox_widget.separator sept)
{
if (sept != null)
{
g.FillRectangle(this.m_background_brush, rect);
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
format.HotkeyPrefix = HotkeyPrefix.Show;
format.Trimming = StringTrimming.EllipsisWord;
format.FormatFlags = StringFormatFlags.NoWrap;
using (Font font = new Font(base.font, FontStyle.Bold))
{
g.DrawString(sept.name, font, Brushes.Black, rect, format);
}
Rectangle rectangle = Rectangle.FromLTRB(rect.Left + 5, rect.Bottom - 2, rect.Right - 5, rect.Bottom - 1);
using (LinearGradientBrush brush = new LinearGradientBrush(rectangle, Color.Black, Color.White, LinearGradientMode.Horizontal))
{
g.FillRectangle(brush, rectangle);
}
}
}
private string EllipsisDisplay(StringBuilder str)
{
str.Replace('\r', ' ');
str.Replace('\n', ' ');
return str.ToString();
}
public override bool get_item_text(listbox_widget host, int index, out string text)
{
text = null;
return false;
}
public override bool get_item_tooltip(listbox_widget host, int index, out string tooltip)
{
object obj2 = host.Items[index];
if (!(obj2 is buddylistbox_item<t_item_context>))
{
tooltip = null;
return false;
}
int itemHeight = host.GetItemHeight(index);
buddylistbox_item<t_item_context> _item = (buddylistbox_item<t_item_context>) obj2;
if ((_item.prompt != null) && (0 < _item.prompt.Length))
{
tooltip = _item.prompt;
return true;
}
bool flag = true;
if (_item.personal_message != null)
{
if (TextRenderer.MeasureText(_item.personal_message, base.font).Width > (host.ClientRectangle.Width - itemHeight))
{
tooltip = _item.personal_message;
return flag;
}
tooltip = null;
return false;
}
tooltip = null;
return flag;
}
public override void measure_host_item(listbox_widget host, MeasureItemEventArgs e)
{
object obj2 = host.Items[e.Index];
if (obj2 is listbox_widget.separator)
{
e.ItemHeight = this.m_separatorheight;
}
else
{
e.ItemHeight = this.m_itemheight;
}
}
public Color background_color
{
get
{
return this.m_background_brush.Color;
}
set
{
this.m_background_brush.Color = value;
base.invalidate_hosts();
}
}
public int itemheight
{
get
{
return this.m_itemheight;
}
set
{
this.m_itemheight = value;
base.invalidate_hosts();
}
}
public Color name_color
{
get
{
return this.m_clr_name;
}
set
{
this.m_clr_name = value;
base.invalidate_hosts();
}
}
public int padding
{
get
{
return this.m_padding;
}
set
{
this.m_padding = value;
base.invalidate_hosts();
}
}
public Color personal_message_color
{
get
{
return this.m_clr_personal_message;
}
set
{
this.m_clr_personal_message = value;
base.invalidate_hosts();
}
}
public Color selected_color
{
get
{
return this.m_selected_brush.Color;
}
set
{
this.m_selected_brush.Color = value;
base.invalidate_hosts();
}
}
public Color selected_name_color
{
get
{
return this.m_clr_selected_name;
}
set
{
this.m_clr_selected_name = value;
base.invalidate_hosts();
}
}
public Color selected_personal_message_color
{
get
{
return this.m_clr_selected_personal_message;
}
set
{
this.m_clr_selected_personal_message = value;
base.invalidate_hosts();
}
}
public int separatorheight
{
get
{
return this.separatorheight;
}
set
{
this.m_separatorheight = value;
base.invalidate_hosts();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -