11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

スクロールイベントの取得方法

11
Posted at

※ OpenFrameworksのバージョンはv0.8.3です。

OpenFrameworksは標準ではマウスホイールによるスクロールイベントをハンドルしませんが、ライブラリを編集すれば簡単にスクロールイベントをハンドルするようにできます。

まず、openFrameworksのソースフォルダを開き、app/ofAppGLFWWindow.cppのscroll_cbメソッドを編集します。

ofAppGLFWWindow.cpp

void ofAppGLFWWindow::scroll_cb(GLFWwindow* windowP_, double x, double y) {
	//TODO: implement scroll events
	ofAppPtr->mouseScrolled(x, y);
}

次に、ofBaseApp.hを開いて、mouseReleasedメソッドの下にmouseScrolledメソッドを追加します。

ofBaseApp.h

		virtual void mouseMoved( int x, int y ){}
		virtual void mouseDragged( int x, int y, int button ){}
		virtual void mousePressed( int x, int y, int button ){}
		virtual void mouseReleased(int x, int y, int button ){}
        virtual void mouseScrolled(double x, double y){}

最後に、ofApp.hにmouseScrolledメソッドを追加し、ofApp.cppにmouseScrolledメソッドの実装を記述すれば、マウスホイールをスクロールさせる度にofAppのmouseScrolledが呼び出されます。

ofApp.h

void mouseScrolled(double x, double y);

ofApp.cpp

void ofApp::mouseScrolled(double x, double y) {
    // ここに、スクロール時の処理を実装します。
    ofLogNotice() << "mouse scrolled: (" << x << "," << y << ")";
}
11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?