瀏覽代碼

ThePimp: middle mouse drag now scrolls the image.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2889 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam 16 年之前
父節點
當前提交
244d20073d
共有 1 個檔案被更改,包括 58 行新增0 行删除
  1. +58
    -0
      ThePimp/PictureView.cs

+ 58
- 0
ThePimp/PictureView.cs 查看文件

@@ -22,6 +22,8 @@ namespace ThePimp
{
private Pipi.Picture _p;
private Adjustment _hadj = null, _vadj = null;
private bool _drag = false;
private double _xdrag, _ydrag;

void HAdjust(object sender, EventArgs args)
{
@@ -37,6 +39,9 @@ namespace ThePimp
{
bool ret = base.OnExposeEvent(e);

if(_hadj == null || _vadj == null)
return ret;

using (Gdk.GC gc = new Gdk.GC(GdkWindow))
{
int w = e.Area.Width;
@@ -61,6 +66,55 @@ namespace ThePimp
base.OnRealized();
}

protected override bool OnButtonPressEvent(Gdk.EventButton e)
{
if(e.Button == 2)
{
GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Hand1);
_drag = true;
_xdrag = e.X;
_ydrag = e.Y;
}

return base.OnButtonPressEvent(e);
}

protected override bool OnButtonReleaseEvent(Gdk.EventButton e)
{
if(e.Button == 2)
{
GdkWindow.Cursor = null;
_drag = false;
}

return base.OnButtonReleaseEvent(e);
}

protected override bool OnMotionNotifyEvent(Gdk.EventMotion e)
{
if(_drag)
{
if(_hadj != null && e.X != _xdrag)
{
_hadj.Value += _xdrag - e.X;
_xdrag = e.X;
if(_hadj.Value + Allocation.Width > _p.Width)
_hadj.Value = _p.Width - Allocation.Width;
_hadj.ChangeValue();
}
if(_vadj != null && e.Y != _ydrag)
{
_vadj.Value += _ydrag - e.Y;
_ydrag = e.Y;
if(_vadj.Value + Allocation.Height > _p.Height)
_vadj.Value = _p.Height - Allocation.Height;
_vadj.ChangeValue();
}
}

return base.OnMotionNotifyEvent(e);
}

protected override void OnSetScrollAdjustments(Adjustment hadj,
Adjustment vadj)
{
@@ -115,6 +169,10 @@ namespace ThePimp
public PictureArea(Picture p)
{
_p = p;

AddEvents((int)Gdk.EventMask.ButtonPressMask);
AddEvents((int)Gdk.EventMask.ButtonReleaseMask);
AddEvents((int)Gdk.EventMask.PointerMotionMask);
}
}



Loading…
取消
儲存