前回のGLUT コールバック関数のテンプレート版をc_functionで書き直してみました。
ひとつの関数をラップするのに1行で済みました。
ついでに、NULL指定によるコールバックの削除にも対応しました。
以下ソース(glut.hpp)
#ifndef CPP_GLUT_INCLUDE #define CPP_GLUT_INCLUDE #include <GL/glut.h> #include "c_function.hpp" namespace glut { using redshift::base::make_c_function; template <class F> inline void DisplayFunc(F f) { ::glutDisplayFunc(make_c_function<struct display_functor, void(*)()>(f)); } template <class F> inline void OverlayDisplayFunc(F f) { ::glutDisplayFunc(make_c_function<struct overlay_display_functor, void(*)()>(f)); } template <class F> inline void ReshapeFunc(F f) { ::glutReshapeFunc(make_c_function<struct reshape_functor, void(*)(int width, int height)>(f)); } template <class F> inline void MotionFunc(F f) { ::glutMotionFunc(make_c_function<struct motion_functor, void(*)(int x, int y)>(f)); } template <class F> inline void PassiveMotionFunc(F f) { ::glutPassiveMotionFunc(make_c_function<struct passive_motion_functor, void(*)(int x, int y)>(f)); } template <class F> inline void KeyboardFunc(F f) { ::glutKeyboardFunc(make_c_function<struct keyboard_functor, void(*)(unsigned char key, int x, int y)>(f)); } template <class F> inline void MouseFunc(F f) { ::glutMouseFunc(make_c_function<struct mouse_functor, void(*)(int button, int state, int x, int y)>(f)); } template <class F> inline void VisibilityFunc(F f) { ::glutVisibilityFunc(make_c_function<struct visibility_functor, void(*)(int state)>(f)); } template <class F> inline void EntryFunc(F f) { ::glutEntryFunc(make_c_function<struct entry_functor, void(*)(int state)>(f)); } template <class F> inline void SpecialFunc(F f) { ::glutSpecialFunc(make_c_function<struct special_functor, void(*)(int key, int x, int y)>(f)); } template <class F> inline void SpaceballMotionFunc(F f) { ::glutSpaceballMotionFunc(make_c_function<struct spaceball_motion_functor, void(*)(int x, int y, int z)>(f)); } template <class F> inline void SpaceballRotateFunc(F f) { ::glutSpaceballRotateFunc(make_c_function<struct spaceball_rotate_functor, void(*)(int x, int y, int z)>(f)); } template <class F> inline void SpaceballButtonFunc(F f) { ::glutSpaceballButtonFunc(make_c_function<struct spaceball_button_functor, void(*)(int button, int state)>(f)); } template <class F> inline void ButtonBoxFunc(F f) { ::glutButtonBoxFunc(make_c_function<struct button_box_functor, void(*)(int button, int state)>(f)); } template <class F> inline void DialsFunc(F f) { ::glutDialsFunc(make_c_function<struct dials_functor, void(*)(int dials, int value)>(f)); } template <class F> inline void TabletMotionFunc(F f) { ::glutTabletMotionFunc(make_c_function<struct tablet_motion_functor, void(*)(int x, int y)>(f)); } template <class F> inline void TabletButtonFunc(F f) { ::glutTabletButtonFunc(make_c_function<struct tablet_button_functor, void(*)(int button, int state, int x, int y)>(f)); } template <class F> inline void MenuStatusFunc(F f) { ::glutMenuStatusFunc(make_c_function<struct menu_status_functor, void(*)(int status, int x, int y)>(f)); } template <class F> inline void MenuStateFunc(F f) { ::glutMenuStateFunc(make_c_function<struct menu_state_functor, void(*)(int status)>(f)); } template <class F> inline void IdleFunc(F f) { ::glutIdleFunc(make_c_function<struct idle_functor, void(*)()>(f)); } template <class F> inline void TimerFunc(unsigned int msecs, F f, int value) { ::glutTimerFunc(msecs, make_c_function<struct timer_functor, void(*)(int value)>, value); } template <class F> inline void WindowStatusFunc(F f) { ::glutWindowStatusFunc(make_c_function<struct window_status_func, void(*)(int state)>(f)); } template <class F> inline void KeyboardUpFunc(F f) { ::glutKeyboardUpFunc(make_c_function<struct keyboard_functor, void(*)(unsigned char key, int x, int y)>(f)); } template <class F> inline void SpecialUpFunc(F f) { ::glutSpecialUpFunc(make_c_function<struct special_up_functor, void(*)(int key, int x, int y)>(f)); } template <class F> inline void JoystickFunc(F f, int pollInterval) { ::glutJoystickFunc(make_c_function<struct joystick_functor, void(*)(unsigned int buttonMask, int x, int y, int z)>(f), pollInterval); } // Delete Callback inline void DisplayFunc<>(int) { ::glutDisplayFunc(NULL); } inline void OverlayDisplayFunc<>(int) { ::glutOverlayDisplayFunc(NULL); } inline void ReshapeFunc<>(int) { ::glutReshapeFunc(NULL); } inline void MotionFunc<>(int) { ::glutMotionFunc(NULL); } inline void PassiveMotionFunc<>(int) { ::glutPassiveMotionFunc(NULL); } inline void KeyboardFunc<>(int) { ::glutKeyboardFunc(NULL); } inline void MouseFunc<>(int) { ::glutMouseFunc(NULL); } inline void VisibilityFunc<>(int) { ::glutVisibilityFunc(NULL); } inline void EntryFunc<>(int) { ::glutEntryFunc(NULL); } inline void SpecialFunc<>(int) { ::glutSpecialFunc(NULL); } inline void SpaceballMotionFunc<>(int) { ::glutSpaceballMotionFunc(NULL); } inline void SpaceballRotateFunc<>(int) { ::glutSpaceballRotateFunc(NULL); } inline void SpaceballButtonFunc<>(int) { ::glutSpaceballButtonFunc(NULL); } inline void ButtonBoxFunc<>(int) { ::glutButtonBoxFunc(NULL); } inline void DialsFunc<>(int) { ::glutDialsFunc(NULL); } inline void TabletMotionFunc<>(int) { ::glutTabletMotionFunc(NULL); } inline void TabletButtonFunc<>(int) { ::glutTabletButtonFunc(NULL); } inline void MenuStatusFunc<>(int) { ::glutMenuStatusFunc(NULL); } inline void MenuStateFunc<>(int) { ::glutMenuStateFunc(NULL); } inline void IdleFunc<>(int) { ::glutIdleFunc(NULL); } inline void TimerFunc<>(unsigned int msecs, int, int value) { ::glutTimerFunc(msecs, NULL, value); } inline void WindowStatusFunc<>(int) { ::glutWindowStatusFunc(NULL); } inline void KeyboardUpFunc<>(int) { ::glutKeyboardUpFunc(NULL); } inline void SpecialUpFunc<>(int) { ::glutSpecialUpFunc(NULL); } inline void JoystickFunc<>(int, int pollInterval) { ::glutJoystickFunc(NULL, pollInterval); } } // namespace glut #endif // CPP_GLUT_INCLUDE