• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得windowscocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

OpenTweenのfork


Commit MetaInfo

修訂2b57f4dbe97f224cb9d9291185b1ea646b60c26d (tree)
時間2012-02-22 19:46:14
作者Kimura Youichi <kim.upsilon@bucy...>
CommiterKimura Youichi

Log Message

Port ToolStripAPIGauge.vb to C#

Change Summary

差異

--- a/Tween/ToolStripAPIGauge.vb
+++ /dev/null
@@ -1,154 +0,0 @@
1-' Tween - Client of Twitter
2-' Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3-' (c) 2008-2011 Moz (@syo68k)
4-' (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5-' (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6-' (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7-' All rights reserved.
8-'
9-' This file is part of Tween.
10-'
11-' This program is free software; you can redistribute it and/or modify it
12-' under the terms of the GNU General Public License as published by the Free
13-' Software Foundation; either version 3 of the License, or (at your option)
14-' any later version.
15-'
16-' This program is distributed in the hope that it will be useful, but
17-' WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18-' or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19-' for more details.
20-'
21-' You should have received a copy of the GNU General Public License along
22-' with this program. If not, see <http://www.gnu.org/licenses/>, or write to
23-' the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
24-' Boston, MA 02110-1301, USA.
25-
26-Imports System
27-Imports System.Drawing
28-Imports System.Windows.Forms
29-
30-Public Class ToolStripAPIGauge
31- Inherits ToolStripControlHost
32-
33- Private originalSize As Size
34-
35- Public Sub New()
36- MyBase.New(New Control())
37- Me.AutoToolTip = True
38- AddHandler Me.Control.Paint, AddressOf Draw
39- AddHandler Me.Control.TextChanged, AddressOf Control_TextChanged
40- AddHandler Me.Control.SizeChanged, AddressOf Control_SizeChanged
41- End Sub
42-
43- Private _gaugeHeight As Integer
44- Public Property GaugeHeight As Integer
45- Set(ByVal value As Integer)
46- Me._gaugeHeight = value
47- If Me.Control IsNot Nothing AndAlso Not Me.Control.IsDisposed Then Me.Control.Refresh()
48- End Set
49- Get
50- Return _gaugeHeight
51- End Get
52- End Property
53-
54- Private _maxCount As Integer = 350
55- Public Property MaxCount As Integer
56- Set(ByVal value As Integer)
57- Me._maxCount = value
58- If Me.Control IsNot Nothing AndAlso Not Me.Control.IsDisposed Then
59- Me.SetText(Me._remainCount, Me._maxCount)
60- Me.Control.Refresh()
61- End If
62- End Set
63- Get
64- Return Me._maxCount
65- End Get
66- End Property
67-
68- Private _remainCount As Integer
69- Public Property RemainCount As Integer
70- Set(ByVal value As Integer)
71- Me._remainCount = value
72- If Me.Control IsNot Nothing AndAlso Not Me.Control.IsDisposed Then
73- Me.SetText(Me._remainCount, Me._maxCount)
74- Me.Control.Refresh()
75- End If
76- End Set
77- Get
78- Return Me._remainCount
79- End Get
80- End Property
81-
82- Private _resetTime As DateTime
83- Public Property ResetTime As DateTime
84- Set(ByVal value As DateTime)
85- Me._resetTime = value
86- If Me.Control IsNot Nothing AndAlso Not Me.Control.IsDisposed Then
87- Me.SetText(Me._remainCount, Me._maxCount)
88- Me.Control.Refresh()
89- End If
90- End Set
91- Get
92- Return Me._resetTime
93- End Get
94- End Property
95-
96- Private Sub Draw(ByVal sender As Object, ByVal e As PaintEventArgs)
97- Dim minute As Double = (Me.ResetTime - DateTime.Now).TotalMinutes
98- Dim apiGaugeBounds As New Rectangle(0, _
99- CType((Me.Control.Height - (Me._gaugeHeight * 2)) / 2, Integer), _
100- CType(Me.Control.Width * (Me.RemainCount / Me._maxCount), Integer), _
101- Me._gaugeHeight)
102- Dim timeGaugeBounds As New Rectangle(0, _
103- apiGaugeBounds.Top + Me._gaugeHeight, _
104- CType(Me.Control.Width * (minute / 60), Integer), _
105- Me._gaugeHeight)
106- e.Graphics.FillRectangle(Brushes.LightBlue, apiGaugeBounds)
107- e.Graphics.FillRectangle(Brushes.LightPink, timeGaugeBounds)
108- e.Graphics.DrawString(Me.Control.Text, Me.Control.Font, SystemBrushes.ControlText, 0, CType(timeGaugeBounds.Top - (Me.Control.Font.Height / 2), Single))
109- End Sub
110-
111- Private Sub Control_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
112- RemoveHandler Me.Control.SizeChanged, AddressOf Me.Control_SizeChanged
113- Using g As Graphics = Me.Control.CreateGraphics()
114- Me.Control.Size = New Size(CType(Math.Max(g.MeasureString(Me.Control.Text, Me.Control.Font).Width, Me.originalSize.Width), Integer), _
115- Me.Control.Size.Height)
116- End Using
117- AddHandler Me.Control.SizeChanged, AddressOf Me.Control_SizeChanged
118- End Sub
119-
120- Private Sub Control_SizeChanged(ByVal sender As Object, ByVal e As EventArgs)
121- Me.originalSize = Me.Control.Size
122- End Sub
123-
124- Private Sub SetText(ByVal remain As Integer, ByVal max As Integer)
125- Dim textFormat As String = "API {0}/{1}"
126- Dim toolTipTextFormat As String = _
127- "API rest {0}/{1}" + Environment.NewLine + _
128- "(reset after {2} minutes)"
129-
130- If Me._remainCount > -1 AndAlso Me._maxCount > -1 Then
131- ' 正常
132- Me.Control.Text = String.Format(textFormat, Me._remainCount, Me._maxCount)
133- ElseIf Me.RemainCount > -1 Then
134- ' uppercount不正
135- Me.Control.Text = String.Format(textFormat, Me._remainCount, "???")
136- ElseIf Me._maxCount < -1 Then
137- ' remaincount不正
138- Me.Control.Text = String.Format(textFormat, "???", Me._maxCount)
139- Else
140- ' 両方とも不正
141- Me.Control.Text = String.Format(textFormat, "???", "???")
142- End If
143-
144- Dim minute As Double = Math.Ceiling((Me.ResetTime - DateTime.Now).TotalMinutes)
145- Dim minuteText As String
146- If minute >= 0 Then
147- minuteText = minute.ToString()
148- Else
149- minuteText = "???"
150- End If
151-
152- Me.ToolTipText = String.Format(toolTipTextFormat, Me._remainCount, Me._maxCount, minuteText)
153- End Sub
154-End Class
\ No newline at end of file
--- a/Tween/Tween.vbproj
+++ b/Tween/Tween.vbproj
@@ -266,9 +266,6 @@
266266 <SubType>Form</SubType>
267267 </Compile>
268268 <Compile Include="Thumbnail.vb" />
269- <Compile Include="ToolStripAPIGauge.vb">
270- <SubType>Component</SubType>
271- </Compile>
272269 <Compile Include="ToolStripLabelHistory.vb">
273270 <SubType>Component</SubType>
274271 </Compile>
--- /dev/null
+++ b/TweenCS/ToolStripAPIGauge.cs
@@ -0,0 +1,182 @@
1+// Tween - Client of Twitter
2+// Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3+// (c) 2008-2011 Moz (@syo68k)
4+// (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5+// (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6+// (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7+// (c) 2011 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
8+// All rights reserved.
9+//
10+// This file is part of Tween.
11+//
12+// This program is free software; you can redistribute it and/or modify it
13+// under the terms of the GNU General Public License as published by the Free
14+// Software Foundation; either version 3 of the License, or (at your option)
15+// any later version.
16+//
17+// This program is distributed in the hope that it will be useful, but
18+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20+// for more details.
21+//
22+// You should have received a copy of the GNU General Public License along
23+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25+// Boston, MA 02110-1301, USA.
26+
27+using System;
28+using System.Collections.Generic;
29+using System.Linq;
30+using System.Text;
31+using System.Windows.Forms;
32+using System.Drawing;
33+
34+namespace Tween
35+{
36+ public class ToolStripAPIGauge : ToolStripControlHost
37+ {
38+ private Size originalSize;
39+
40+ public ToolStripAPIGauge() : base(new Control())
41+ {
42+ this.AutoToolTip = true;
43+ this.Control.Paint += Draw;
44+ this.Control.TextChanged += Control_TextChanged;
45+ this.Control.SizeChanged += Control_SizeChanged;
46+ }
47+
48+ private int _gaugeHeight;
49+
50+ public int GaugeHeight
51+ {
52+ set
53+ {
54+ this._gaugeHeight = value;
55+ if (this.Control != null && !this.Control.IsDisposed) this.Control.Refresh();
56+ }
57+ get { return _gaugeHeight; }
58+ }
59+
60+ private int _maxCount = 350;
61+
62+ public int MaxCount
63+ {
64+ set
65+ {
66+ this._maxCount = value;
67+ if (this.Control != null && !this.Control.IsDisposed)
68+ {
69+ this.SetText(this._remainCount, this._maxCount);
70+ this.Control.Refresh();
71+ }
72+ }
73+ get { return _maxCount; }
74+ }
75+
76+ private int _remainCount;
77+
78+ public int RemainCount
79+ {
80+ set
81+ {
82+ this._remainCount = value;
83+ if (this.Control != null && !this.Control.IsDisposed)
84+ {
85+ this.SetText(this._remainCount, this._maxCount);
86+ this.Control.Refresh();
87+ }
88+ }
89+ get { return _remainCount; }
90+ }
91+
92+ private DateTime _resetTime;
93+
94+ public DateTime ResetTime
95+ {
96+ set
97+ {
98+ this._resetTime = value;
99+ if (this.Control != null && !this.Control.IsDisposed)
100+ {
101+ this.SetText(this._remainCount, this._maxCount);
102+ this.Control.Refresh();
103+ }
104+ }
105+ get { return _resetTime; }
106+ }
107+
108+ private void Draw(object sender, PaintEventArgs e)
109+ {
110+ double minute = (this.ResetTime - DateTime.Now).TotalMinutes;
111+ Rectangle apiGaugeBounds = new Rectangle(0,
112+ (this.Control.Height - (this._gaugeHeight * 2)) / 2,
113+ this.Control.Width * this.RemainCount / this._maxCount,
114+ this._gaugeHeight);
115+ Rectangle timeGaugeBounds = new Rectangle(0,
116+ apiGaugeBounds.Top + this._gaugeHeight,
117+ (int)(this.Control.Width * minute / 60),
118+ this._gaugeHeight);
119+ e.Graphics.FillRectangle(Brushes.LightBlue, apiGaugeBounds);
120+ e.Graphics.FillRectangle(Brushes.LightPink, timeGaugeBounds);
121+ e.Graphics.DrawString(this.Control.Text, this.Control.Font, SystemBrushes.ControlText, 0, (float)(timeGaugeBounds.Top - (this.Control.Font.Height / 2)));
122+ }
123+
124+ private void Control_TextChanged(object sender, EventArgs e)
125+ {
126+ this.Control.SizeChanged -= this.Control_SizeChanged;
127+ using (Graphics g = this.Control.CreateGraphics())
128+ {
129+ this.Control.Size = new Size((int)(Math.Max(g.MeasureString(this.Control.Text, this.Control.Font).Width, this.originalSize.Width)),
130+ this.Control.Size.Height);
131+ }
132+ this.Control.SizeChanged += this.Control_SizeChanged;
133+ }
134+
135+ private void Control_SizeChanged(object sender, EventArgs e)
136+ {
137+ this.originalSize = this.Control.Size;
138+ }
139+
140+ private void SetText(int remain, int max)
141+ {
142+ string textFormat = "API {0}/{1}";
143+ string toolTipTextFormat =
144+ "API rest {0}/{1}" + Environment.NewLine +
145+ "(reset after {2} minutes)";
146+
147+ if (this._remainCount > -1 && this._maxCount > -1)
148+ {
149+ // 正常
150+ this.Control.Text = String.Format(textFormat, this._remainCount, this._maxCount);
151+ }
152+ else if (this.RemainCount > -1)
153+ {
154+ // uppercount不正
155+ this.Control.Text = String.Format(textFormat, this._remainCount, "???");
156+ }
157+ else if (this._maxCount < -1)
158+ {
159+ // remaincount不正
160+ this.Control.Text = String.Format(textFormat, "???", this._maxCount);
161+ }
162+ else
163+ {
164+ // 両方とも不正
165+ this.Control.Text = String.Format(textFormat, "???", "???");
166+ }
167+
168+ double minute = Math.Ceiling((this.ResetTime - DateTime.Now).TotalMinutes);
169+ string minuteText;
170+ if (minute >= 0)
171+ {
172+ minuteText = minute.ToString();
173+ }
174+ else
175+ {
176+ minuteText = "???";
177+ }
178+
179+ this.ToolTipText = String.Format(toolTipTextFormat, this._remainCount, this._maxCount, minuteText);
180+ }
181+ }
182+}
--- a/TweenCS/TweenCS.csproj
+++ b/TweenCS/TweenCS.csproj
@@ -67,6 +67,9 @@
6767 <Compile Include="SearchWord.Designer.cs">
6868 <DependentUpon>SearchWord.cs</DependentUpon>
6969 </Compile>
70+ <Compile Include="ToolStripAPIGauge.cs">
71+ <SubType>Component</SubType>
72+ </Compile>
7073 <Compile Include="TweenAboutBox.cs">
7174 <SubType>Form</SubType>
7275 </Compile>