差分
== 概要 ==
[[マウス]]のボタンが押されるとNSViewクラスのMouseDownメソッドやMouseUpメソッドが呼ばれる。
これらの[[メソッド]]に[[引数]]として渡されるtheEvent変数に含まれる座標はウインドウ領域の座標(ウインドウの角を原点とした座標)である。
常識的に考えてウインドウ領域の座標が欲しい場面などほとんどないわけで、これでは非常に扱いづらい。
== 実装 ==
ウインドウ領域の座標をビュー領域の座標に変換してやるにはNSViewクラスのConvertPointFromViewメソッドを使用する。なんとも面倒くさい。
<source lang="csharp">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using MonoMac.Foundation;
using MonoMac.AppKit;
namespace ContentEditor
{
public partial class EditorView : MonoMac.AppKit.NSView
{
// 〜〜〜省略〜〜〜
public override void MouseDown(NSEvent theEvent)
{
// ウインドウ領域の座標をビュー領域の座標に変換する。
// aViewはnull指定で自身になる
var locationInView = this.ConvertPointFromView( aPoint:theEvent.LocationInWindow, aView:null );
Console.WriteLine(locationInView);
base.MouseUp(theEvent);
}
}
}
</source>
== 関連項目 ==
* [[MonoMac/NSViewを継承したカスタムコントロールを作る]]
* [[MonoMac/Interface Builderでカスタムコントロールを使用する]]
== 参考文献 ==
{{reflist}}
{{stub}}
[[category:MonoMac]]
[[category:Xamarin.Mac]]
[[マウス]]のボタンが押されるとNSViewクラスのMouseDownメソッドやMouseUpメソッドが呼ばれる。
これらの[[メソッド]]に[[引数]]として渡されるtheEvent変数に含まれる座標はウインドウ領域の座標(ウインドウの角を原点とした座標)である。
常識的に考えてウインドウ領域の座標が欲しい場面などほとんどないわけで、これでは非常に扱いづらい。
== 実装 ==
ウインドウ領域の座標をビュー領域の座標に変換してやるにはNSViewクラスのConvertPointFromViewメソッドを使用する。なんとも面倒くさい。
<source lang="csharp">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using MonoMac.Foundation;
using MonoMac.AppKit;
namespace ContentEditor
{
public partial class EditorView : MonoMac.AppKit.NSView
{
// 〜〜〜省略〜〜〜
public override void MouseDown(NSEvent theEvent)
{
// ウインドウ領域の座標をビュー領域の座標に変換する。
// aViewはnull指定で自身になる
var locationInView = this.ConvertPointFromView( aPoint:theEvent.LocationInWindow, aView:null );
Console.WriteLine(locationInView);
base.MouseUp(theEvent);
}
}
}
</source>
== 関連項目 ==
* [[MonoMac/NSViewを継承したカスタムコントロールを作る]]
* [[MonoMac/Interface Builderでカスタムコントロールを使用する]]
== 参考文献 ==
{{reflist}}
{{stub}}
[[category:MonoMac]]
[[category:Xamarin.Mac]]