Browse Source

Handle mouse event in Gtk subsystem

(Also Key events, badly - every key is an X)
pull/10/head
Steven Kirk 12 years ago
parent
commit
717f87b05c
  1. 39
      Gtk/Perspex.Gtk/Input/GtkKeyboardDevice.cs
  2. 34
      Gtk/Perspex.Gtk/Input/GtkMouseDevice.cs
  3. 5
      Gtk/Perspex.Gtk/Perspex.Gtk.csproj
  4. 50
      Gtk/Perspex.Gtk/WindowImpl.cs

39
Gtk/Perspex.Gtk/Input/GtkKeyboardDevice.cs

@ -0,0 +1,39 @@
// -----------------------------------------------------------------------
// <copyright file="GtkKeyboardDevice.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Gtk
{
using Perspex.Input;
public class GtkKeyboardDevice : KeyboardDevice
{
private static GtkKeyboardDevice instance;
static GtkKeyboardDevice()
{
instance = new GtkKeyboardDevice();
}
private GtkKeyboardDevice()
{
}
public static GtkKeyboardDevice Instance
{
get { return instance; }
}
public override ModifierKeys Modifiers
{
get { throw new System.NotImplementedException(); }
}
public static Perspex.Input.Key ConvertKey(Gdk.Key key)
{
return Key.X;
}
}
}

34
Gtk/Perspex.Gtk/Input/GtkMouseDevice.cs

@ -0,0 +1,34 @@
// -----------------------------------------------------------------------
// <copyright file="GtkMouseDevice.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Gtk
{
using Perspex.Input;
public class GtkMouseDevice : MouseDevice
{
private static GtkMouseDevice instance;
static GtkMouseDevice()
{
instance = new GtkMouseDevice();
}
private GtkMouseDevice()
{
}
public static GtkMouseDevice Instance
{
get { return instance; }
}
protected override Point GetClientPosition()
{
throw new System.NotImplementedException();
}
}
}

5
Gtk/Perspex.Gtk/Perspex.Gtk.csproj

@ -59,6 +59,8 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="GtkPlatform.cs" />
<Compile Include="WindowImpl.cs" />
<Compile Include="Input\GtkKeyboardDevice.cs" />
<Compile Include="Input\GtkMouseDevice.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
@ -94,4 +96,7 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="Input\" />
</ItemGroup>
</Project>

50
Gtk/Perspex.Gtk/WindowImpl.cs

@ -14,6 +14,8 @@ namespace Perspex.Gtk
public class WindowImpl : Gtk.Window, IWindowImpl
{
private Window owner;
private IPlatformHandle windowHandle;
private Size clientSize;
@ -22,6 +24,9 @@ namespace Perspex.Gtk
: base(Gtk.WindowType.Toplevel)
{
this.DefaultSize = new Gdk.Size(640, 480);
this.Events = Gdk.EventMask.PointerMotionMask |
Gdk.EventMask.ButtonPressMask |
Gdk.EventMask.ButtonReleaseMask;
this.windowHandle = new PlatformHandle(this.Handle, "GtkWindow");
}
@ -52,6 +57,7 @@ namespace Perspex.Gtk
public void SetOwner(Window window)
{
this.owner = window;
}
public void SetTitle(string title)
@ -59,6 +65,28 @@ namespace Perspex.Gtk
this.Title = title;
}
protected override bool OnButtonPressEvent(Gdk.EventButton evnt)
{
var e = new RawMouseEventArgs(
GtkMouseDevice.Instance,
this.owner,
RawMouseEventType.LeftButtonDown,
new Point(evnt.X, evnt.Y));
this.Input(e);
return true;
}
protected override bool OnButtonReleaseEvent(Gdk.EventButton evnt)
{
var e = new RawMouseEventArgs(
GtkMouseDevice.Instance,
this.owner,
RawMouseEventType.LeftButtonUp,
new Point(evnt.X, evnt.Y));
this.Input(e);
return true;
}
protected override bool OnConfigureEvent(Gdk.EventConfigure evnt)
{
var newSize = new Size(evnt.Width, evnt.Height);
@ -77,6 +105,17 @@ namespace Perspex.Gtk
this.Closed();
}
protected override bool OnKeyPressEvent(Gdk.EventKey evnt)
{
var e = new RawKeyEventArgs(
GtkKeyboardDevice.Instance,
RawKeyEventType.KeyDown,
GtkKeyboardDevice.ConvertKey(evnt.Key),
"X");
this.Input(e);
return true;
}
protected override bool OnExposeEvent(Gdk.EventExpose evnt)
{
this.Paint(evnt.Area.ToPerspex(), GetHandle(evnt.Window));
@ -88,6 +127,17 @@ namespace Perspex.Gtk
this.Activated();
}
protected override bool OnMotionNotifyEvent(Gdk.EventMotion evnt)
{
var e = new RawMouseEventArgs(
GtkMouseDevice.Instance,
this.owner,
RawMouseEventType.Move,
new Point(evnt.X, evnt.Y));
this.Input(e);
return true;
}
private IPlatformHandle GetHandle(Gdk.Window window)
{
return new PlatformHandle(window.Handle, "GdkWindow");

Loading…
Cancel
Save