Skip to content

Commit d61120f

Browse files
committed
シングルクリックでサムネイルを開く
1 parent 9053572 commit d61120f

4 files changed

Lines changed: 180 additions & 0 deletions

File tree

OpenTween/OpenTween.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@
198198
<DependentUpon>TweetDetailsView.cs</DependentUpon>
199199
</Compile>
200200
<Compile Include="TweetExtractor.cs" />
201+
<Compile Include="TweetThumbnailWindow.cs">
202+
<SubType>Form</SubType>
203+
</Compile>
204+
<Compile Include="TweetThumbnailWindow.Designer.cs">
205+
<DependentUpon>TweetThumbnailWindow.cs</DependentUpon>
206+
</Compile>
201207
<Compile Include="WaitingDialog.cs">
202208
<SubType>Form</SubType>
203209
</Compile>

OpenTween/TweetThumbnail.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public partial class TweetThumbnail : UserControl
5050
public event EventHandler<ThumbnailDoubleClickEventArgs>? ThumbnailDoubleClick;
5151
public event EventHandler<ThumbnailImageSearchEventArgs>? ThumbnailImageSearchClick;
5252

53+
private TweetThumbnailWindow? _thumbWindow;
54+
private TweetThumbnailWindow ThumbnailWindow
55+
=> _thumbWindow ??= CreateTweetThumbnailWindow();
56+
57+
5358
public ThumbnailInfo Thumbnail
5459
=> (ThumbnailInfo)this.pictureBox[this.scrollBar.Value].Tag;
5560

@@ -142,6 +147,7 @@ protected void SetThumbnailCount(int count)
142147

143148
picbox.MouseWheel -= this.pictureBox_MouseWheel;
144149
picbox.DoubleClick -= this.pictureBox_DoubleClick;
150+
picbox.MouseClick -= this.pictureBox_MouseClick;
145151
picbox.Dispose();
146152

147153
memoryImage?.Dispose();
@@ -160,6 +166,7 @@ protected void SetThumbnailCount(int count)
160166
picbox.Visible = (i == 0);
161167
picbox.MouseWheel += this.pictureBox_MouseWheel;
162168
picbox.DoubleClick += this.pictureBox_DoubleClick;
169+
picbox.MouseClick += this.pictureBox_MouseClick;
163170

164171
filter.Register(picbox);
165172

@@ -231,6 +238,36 @@ private void pictureBox_MouseWheel(object sender, MouseEventArgs e)
231238
this.ScrollDown();
232239
}
233240

241+
private void pictureBox_MouseClick(object sender, MouseEventArgs e)
242+
{
243+
var picBox = sender as PictureBox;
244+
if (picBox == null) return;
245+
246+
var thumb = picBox.Tag as ThumbnailInfo;
247+
if (thumb == null || thumb.IsPlayable) return;
248+
249+
this.ShowThubWindow(picBox.Image, thumb);
250+
}
251+
252+
private void ShowThubWindow(Image image, ThumbnailInfo thumbnailInfo)
253+
{
254+
var thumbWindow = this.ThumbnailWindow;
255+
if (thumbWindow.Image == image)
256+
{
257+
ThumbnailWindow.HideAndClear();
258+
return;
259+
}
260+
261+
thumbWindow.Image = image;
262+
thumbWindow.Show();
263+
}
264+
private TweetThumbnailWindow CreateTweetThumbnailWindow()
265+
{
266+
var window = new TweetThumbnailWindow(this.ParentForm);
267+
this.components.Add(window);
268+
return window;
269+
}
270+
234271
private void pictureBox_DoubleClick(object sender, EventArgs e)
235272
{
236273
if (((PictureBox)sender).Tag is ThumbnailInfo thumb)

OpenTween/TweetThumbnailWindow.Designer.cs

Lines changed: 73 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OpenTween/TweetThumbnailWindow.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
using System.Drawing;
3+
using System.Windows.Forms;
4+
#nullable enable
5+
namespace OpenTween
6+
{
7+
public partial class TweetThumbnailWindow : Form
8+
{
9+
private Point mouseDownPoint;
10+
private bool _moved;
11+
12+
public Image? Image
13+
{
14+
set => pictureBox1.Image = value;
15+
get => pictureBox1.Image;
16+
}
17+
18+
public TweetThumbnailWindow(Form tweenMain)
19+
{
20+
InitializeComponent();
21+
tweenMain.Activated += TweenMain_Activated;
22+
}
23+
24+
public void HideAndClear()
25+
{
26+
this.Hide();
27+
Image = null;
28+
}
29+
30+
private void TweetThumbnailWindow_KeyPress(object sender, KeyPressEventArgs e)
31+
{
32+
this.HideAndClear();
33+
}
34+
35+
private void TweenMain_Activated(object sender, EventArgs e)
36+
{
37+
/// <see cref="TweetThumbnail.ShowThubWindow(Image, ThumbnailInfo)"/> で確認できるように Image を残しておく
38+
this.Hide();
39+
}
40+
41+
private void pictureBox1_Click(object sender, EventArgs e)
42+
{
43+
if (!_moved) this.HideAndClear();
44+
}
45+
46+
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
47+
{
48+
if (e.Button.HasFlag(MouseButtons.Left))
49+
{
50+
_moved = false;
51+
mouseDownPoint = e.Location;
52+
}
53+
}
54+
55+
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
56+
{
57+
if (e.Button.HasFlag(MouseButtons.Left))
58+
{
59+
_moved = true;
60+
this.Location = new Point(this.Location.X + e.X - mouseDownPoint.X, this.Location.Y + e.Y - mouseDownPoint.Y);
61+
}
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)