gltut / framework / MousePole.h

#ifndef FRAMEWORK_MOUSE_POLE_H
#define FRAMEWORK_MOUSE_POLE_H

#include <glm/glm.hpp>
#include <GL/freeglut.h>
#include <glutil/MousePoles.h>

namespace Framework
{
	inline int calc_glut_modifiers()
	{
		int ret = 0;

		int modifiers = glutGetModifiers();
		if(modifiers & GLUT_ACTIVE_SHIFT)
			ret |= glutil::MM_KEY_SHIFT;
		if(modifiers & GLUT_ACTIVE_CTRL)
			ret |= glutil::MM_KEY_CTRL;
		if(modifiers & GLUT_ACTIVE_ALT)
			ret |= glutil::MM_KEY_ALT;

		return ret;
	}

	template<typename Pole>
	inline void ForwardMouseMotion(Pole &forward, int x, int y)
	{
		forward.MouseMove(glm::ivec2(x, y));
	}

	template<typename Pole>
	inline void ForwardMouseButton(Pole &forward, int button, int state, int x, int y)
	{
		int modifiers = calc_glut_modifiers();

		glm::ivec2 mouseLoc = glm::ivec2(x, y);

		glutil::MouseButtons eButton;

		switch(button)
		{
		case GLUT_LEFT_BUTTON:
			eButton = glutil::MB_LEFT_BTN;
			break;
		case GLUT_MIDDLE_BUTTON:
			eButton = glutil::MB_MIDDLE_BTN;
			break;
		case GLUT_RIGHT_BUTTON:
			eButton = glutil::MB_RIGHT_BTN;
			break;
#ifdef LOAD_X11
			//Linux Mouse wheel support
		case 3:
			{
				forward.MouseWheel(1, modifiers, mouseLoc);
				return;
			}
		case 4:
			{
				forward.MouseWheel(-1, modifiers, mouseLoc);
				return;
			}
#endif
		default:
			return;
		}

		forward.MouseClick(eButton, state == GLUT_DOWN, modifiers, glm::ivec2(x, y));
	}

	template<typename Pole>
	inline void ForwardMouseWheel(Pole &forward, int wheel, int direction, int x, int y)
	{
		forward.MouseWheel(direction, calc_glut_modifiers(), glm::ivec2(x, y));
	}

}

#endif //FRAMEWORK_MOUSE_POLE_H
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.