• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修订版691196ad7e6aaf1afab0f7a38fadfa237beed25b (tree)
时间2011-01-19 16:59:00
作者azyobuzin <azyobuzin@user...>
Commiterazyobuzin

Log Message

・StatusesListViewでオーナードローするように
・正規表現不具合を直した

更改概述

  • delete: "\202\302\202\242\202\351\202\361\202\351\202\361/Controls/StatusBrowser.cs"
  • delete: "\202\302\202\242\202\351\202\361\202\351\202\361/Controls/StatusesListView.cs"
  • delete: "\202\302\202\242\202\351\202\361\202\351\202\361/Icons.cs"

差异

--- "a/\202\302\202\242\202\351\202\361\202\351\202\361/Controls/StatusBrowser.cs"
+++ "b/\202\302\202\242\202\351\202\361\202\351\202\361/Controls/StatusBrowser.cs"
@@ -54,7 +54,7 @@ namespace Azyobuzi.Twirunrun
5454 .RegexReplace(@"https?://[\w\d/%#$&?()~_.=+\-!]+", (match) =>
5555 string.Format(@"<a href=""{0}"">{1}</a>",
5656 match.ToString().HtmlAttributeEncode(), match.ToString().HtmlEncode()))
57- .RegexReplace(@"[@@]\w+", (match) =>
57+ .RegexReplace(@"[@@][a-zA-Z0-9_]+"/*\wだとうまく認識しない*/, (match) =>
5858 string.Format(@"{0}<a href=""https://twitter.com/{1}"">{1}</a>", match.ToString()[0], match.ToString().Substring(1)))
5959 .RegexReplace(@"(^|\W)([##][a-zA-Z0-9_\-]+)", (match) =>
6060 string.Format(@"{0}<a href=""https://twitter.com/search?q={1}"">{2}</a>", match.Groups[1].ToString(), Uri.EscapeDataString(match.Groups[2].ToString()).HtmlAttributeEncode(), match.Groups[2].ToString()));
--- "a/\202\302\202\242\202\351\202\361\202\351\202\361/Controls/StatusesListView.cs"
+++ "b/\202\302\202\242\202\351\202\361\202\351\202\361/Controls/StatusesListView.cs"
@@ -1,7 +1,5 @@
1-using System;
2-using System.Collections.Generic;
3-using System.Linq;
4-using System.Text;
1+using System.Collections.Generic;
2+using System.Drawing;
53 using System.Windows.Forms;
64
75 namespace Azyobuzi.Twirunrun
@@ -18,10 +16,10 @@ namespace Azyobuzi.Twirunrun
1816 this.Columns.Add("名前", Settings.Instance.NameWidth);
1917 this.Columns.Add("投稿");
2018 this.SizeChanged += (sender, e) => this.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.ColumnContent);
19+ this.OwnerDraw = true;
20+ this.DrawSubItem += this_DrawSubItem;
2121 }
22-
23- public const string NAME_SUBITEM = "NameSubItem";//SubItem識別用
24-
22+
2523 private IList<StatusInfo> statuses;
2624 public IList<StatusInfo> Statuses
2725 {
@@ -59,9 +57,70 @@ namespace Azyobuzi.Twirunrun
5957
6058 lvi.SubItems.Add(item.Text.Replace('\n', ' '));
6159
62- lvi.SubItems[0].Tag = NAME_SUBITEM;
63-
6460 e.Item = lvi;
6561 }
62+
63+ //ラベルは保留
64+ private void this_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
65+ {
66+ if (e.ItemIndex < 0 || e.ColumnIndex < 0) return;
67+
68+ using (var b = new SolidBrush(
69+ (e.ItemState & ListViewItemStates.Selected) == ListViewItemStates.Selected ?
70+ SystemColors.Highlight : e.SubItem.BackColor))
71+ {
72+ e.Graphics.FillRectangle(b, e.Bounds);
73+ }
74+
75+ var foreColor = (e.ItemState & ListViewItemStates.Selected) == ListViewItemStates.Selected ?
76+ SystemColors.HighlightText : e.SubItem.ForeColor;
77+
78+ e.ColumnIndex.SelectCase()
79+ .Case(0, () =>//名前部
80+ {
81+ const int LEFT_SPACE = 2;
82+ var itemPoint = e.Bounds.Location;
83+ var post = Statuses[e.ItemIndex];
84+ //アイコン描画
85+ int iconsize = e.Bounds.Height - 1;
86+ var icon = Icons.GetItem(post.ProfileImageUri);
87+ if (icon == null)
88+ {
89+ Icons.AddAsync(post.ProfileImageUri);
90+ }
91+ else
92+ {
93+ e.Graphics.DrawImage(icon, itemPoint.X + LEFT_SPACE, itemPoint.Y, iconsize, iconsize);
94+ }
95+ //名前描画
96+ TextRenderer.DrawText(e.Graphics,
97+ e.SubItem.Text,
98+ e.SubItem.Font,
99+ new Rectangle(
100+ itemPoint.X + LEFT_SPACE + iconsize + LEFT_SPACE,
101+ itemPoint.Y,
102+ e.Bounds.Width - LEFT_SPACE - iconsize - LEFT_SPACE,
103+ e.Bounds.Height
104+ ),
105+ foreColor,
106+ TextFormatFlags.NoPrefix |
107+ TextFormatFlags.VerticalCenter |
108+ TextFormatFlags.EndEllipsis |
109+ TextFormatFlags.SingleLine
110+ );
111+ })
112+ .Case(1, () =>//投稿内容部
113+ {
114+ TextRenderer.DrawText(e.Graphics,
115+ e.SubItem.Text,
116+ e.SubItem.Font,
117+ e.Bounds,
118+ foreColor,
119+ TextFormatFlags.NoPrefix |
120+ TextFormatFlags.VerticalCenter |
121+ TextFormatFlags.WordEllipsis |
122+ TextFormatFlags.SingleLine);
123+ });
124+ }
66125 }
67126 }
--- "a/\202\302\202\242\202\351\202\361\202\351\202\361/Icons.cs"
+++ "b/\202\302\202\242\202\351\202\361\202\351\202\361/Icons.cs"
@@ -39,10 +39,16 @@ namespace Azyobuzi.Twirunrun
3939 {
4040 try
4141 {
42- var result = CreateIcon(uri);
42+ var _uri = e.Argument.ToString();
43+ Image result;
44+ using (var wc = new WebClient())
45+ {
46+ result = wc.DownloadImage(_uri);
47+ }
48+
4349 lock (LockObj)
4450 {
45- Icons.Add(uri, result);
51+ Icons.Add(_uri, result);
4652 }
4753 }
4854 catch { }
@@ -55,7 +61,7 @@ namespace Azyobuzi.Twirunrun
5561 AddCompleted();
5662 }
5763 };
58- bw.RunWorkerAsync();
64+ bw.RunWorkerAsync(uri);
5965 }
6066
6167 private static int RunnningCount = 0;
@@ -67,45 +73,45 @@ namespace Azyobuzi.Twirunrun
6773
6874
6975
70- /// <summary>
71- /// 指定したURIからアイコンを作成する
72- /// </summary>
73- public static Bitmap CreateIcon(string uri)
74- {
75- const int RESULT_SIZE = 48;
76-
77- Image img;
78-
79- using (var wc = new WebClient())
80- {
81- img = wc.DownloadImage(uri);
82- }
83-
84- if (img.Width == img.Height)
85- return new Bitmap(img, RESULT_SIZE, RESULT_SIZE);
86-
87- int size = Math.Min(img.Width, img.Height);
88- using (Bitmap temp = new Bitmap(size, size))
89- {
90- if (img.Width > img.Height)
91- {
92- int left = img.Width / 2 - ((/*img.Width - */img.Height) / 2);
93- using (var g = Graphics.FromImage(temp))
94- {
95- g.DrawImage(img, 0, 0, new Rectangle(left, 0, size, size), GraphicsUnit.Pixel);
96- }
97- }
98- else if (img.Width < img.Height)
99- {
100- int top = img.Height / 2 - ((/*img.Height - */img.Width) / 2);
101- using (var g = Graphics.FromImage(temp))
102- {
103- g.DrawImage(img, 0, 0, new Rectangle(0, top, size, size), GraphicsUnit.Pixel);
104- }
105- }
106-
107- return new Bitmap(temp, RESULT_SIZE, RESULT_SIZE);
108- }
109- }
76+ ///// <summary>
77+ ///// 指定したURIからアイコンを作成する
78+ ///// </summary>
79+ //public static Bitmap CreateIcon(string uri)
80+ //{
81+ // const int RESULT_SIZE = 48;
82+
83+ // Image img;
84+
85+ // using (var wc = new WebClient())
86+ // {
87+ // img = wc.DownloadImage(uri);
88+ // }
89+
90+ // if (img.Width == img.Height)
91+ // return new Bitmap(img, RESULT_SIZE, RESULT_SIZE);
92+
93+ // int size = Math.Min(img.Width, img.Height);
94+ // using (Bitmap temp = new Bitmap(size, size))
95+ // {
96+ // if (img.Width > img.Height)
97+ // {
98+ // int left = img.Width / 2 - ((/*img.Width - */img.Height) / 2);
99+ // using (var g = Graphics.FromImage(temp))
100+ // {
101+ // g.DrawImage(img, 0, 0, new Rectangle(left, 0, size, size), GraphicsUnit.Pixel);
102+ // }
103+ // }
104+ // else if (img.Width < img.Height)
105+ // {
106+ // int top = img.Height / 2 - ((/*img.Height - */img.Width) / 2);
107+ // using (var g = Graphics.FromImage(temp))
108+ // {
109+ // g.DrawImage(img, 0, 0, new Rectangle(0, top, size, size), GraphicsUnit.Pixel);
110+ // }
111+ // }
112+
113+ // return new Bitmap(temp, RESULT_SIZE, RESULT_SIZE);
114+ // }
115+ //}
110116 }
111117 }