Applied Troeglazov "3dEyes**" Gerasim's patches: adds keys up and mouse wheel events support.

Thanks.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20141 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin 2007-02-16 11:37:36 +00:00
parent 5fbb5241c7
commit abbdc51e90
5 changed files with 209 additions and 3 deletions

View File

@ -37,12 +37,24 @@ glutKeyboardFunc(GLUTkeyboardCB keyboardFunc)
gState.currentWindow->keyboard = keyboardFunc;
}
void APIENTRY
glutKeyboardUpFunc(GLUTkeyboardCB keyboardUpFunc)
{
gState.currentWindow->keyboardUp = keyboardUpFunc;
}
void APIENTRY
glutSpecialFunc(GLUTspecialCB specialFunc)
{
gState.currentWindow->special = specialFunc;
}
void APIENTRY
glutSpecialUpFunc(GLUTspecialCB specialUpFunc)
{
gState.currentWindow->specialUp = specialUpFunc;
}
void APIENTRY
glutMouseFunc(GLUTmouseCB mouseFunc)
{
@ -135,6 +147,11 @@ glutOverlayDisplayFunc(GLUTdisplayCB displayFunc)
{
}
void APIENTRY
glutJoystickFunc(GLUTjoystickCB joystickFunc, int pollInterval)
{
}
void APIENTRY
glutSpaceballMotionFunc(GLUTspaceMotionCB spaceMotionFunc)
{

View File

@ -18,6 +18,10 @@
#include "glutint.h"
#include "glutState.h"
#include "glutBlocker.h"
#include <stdio.h>
#define MOUSE_WHEEL_UP 3
#define MOUSE_WHEEL_DOWN 4
/***********************************************************
* CLASS: GLUTtimer
@ -222,6 +226,31 @@ processEventsAndTimeouts(void)
if (!gState.windowList[i])
continue; // window was destroyed by callback!
if (win->keybUpEvent) {
win->keybUpEvent = false;
__glutSetWindow(win);
if (win->keyboardUp) {
gState.modifierKeys = win->modifierKeys;
win->keyboardUp(win->key, win->keyX, win->keyY);
gState.modifierKeys = ~0;
}
}
if (!gState.windowList[i])
continue; // window was destroyed by callback!
if (win->specialUpEvent) {
win->specialUpEvent = false;
__glutSetWindow(win);
if (win->specialUp) {
gState.modifierKeys = win->modifierKeys;
win->specialUp(win->specialKey, win->specialX, win->specialY);
gState.modifierKeys = ~0;
}
}
if (!gState.windowList[i])
continue; // window was destroyed by callback!
if (win->entryEvent) {
win->entryEvent = false;
__glutSetWindow(win);
@ -458,6 +487,127 @@ setModifiers:
}
}
/***********************************************************
* CLASS: GlutWindow
*
* FUNCTION: KeyUp
*
* DESCRIPTION: handles keyboard and special events
***********************************************************/
void GlutWindow::KeyUp(const char *s, int32 slen)
{
ulong aChar = s[0];
BGLView::KeyUp(s,slen);
BPoint p;
switch (aChar) {
case B_FUNCTION_KEY:
switch(Window()->CurrentMessage()->FindInt32("key")) {
case B_F1_KEY:
aChar = GLUT_KEY_F1;
goto specialLabel;
case B_F2_KEY:
aChar = GLUT_KEY_F2;
goto specialLabel;
case B_F3_KEY:
aChar = GLUT_KEY_F3;
goto specialLabel;
case B_F4_KEY:
aChar = GLUT_KEY_F4;
goto specialLabel;
case B_F5_KEY:
aChar = GLUT_KEY_F5;
goto specialLabel;
case B_F6_KEY:
aChar = GLUT_KEY_F6;
goto specialLabel;
case B_F7_KEY:
aChar = GLUT_KEY_F7;
goto specialLabel;
case B_F8_KEY:
aChar = GLUT_KEY_F8;
goto specialLabel;
case B_F9_KEY:
aChar = GLUT_KEY_F9;
goto specialLabel;
case B_F10_KEY:
aChar = GLUT_KEY_F10;
goto specialLabel;
case B_F11_KEY:
aChar = GLUT_KEY_F11;
goto specialLabel;
case B_F12_KEY:
aChar = GLUT_KEY_F12;
goto specialLabel;
default:
return;
}
case B_LEFT_ARROW:
aChar = GLUT_KEY_LEFT;
goto specialLabel;
case B_UP_ARROW:
aChar = GLUT_KEY_UP;
goto specialLabel;
case B_RIGHT_ARROW:
aChar = GLUT_KEY_RIGHT;
goto specialLabel;
case B_DOWN_ARROW:
aChar = GLUT_KEY_DOWN;
goto specialLabel;
case B_PAGE_UP:
aChar = GLUT_KEY_PAGE_UP;
goto specialLabel;
case B_PAGE_DOWN:
aChar = GLUT_KEY_PAGE_DOWN;
goto specialLabel;
case B_HOME:
aChar = GLUT_KEY_HOME;
goto specialLabel;
case B_END:
aChar = GLUT_KEY_END;
goto specialLabel;
case B_INSERT:
aChar = GLUT_KEY_INSERT;
specialLabel:
if (specialUp!=0) {
anyevents = specialUpEvent = true;
GetMouse(&p,&m_buttons);
specialKey = aChar;
specialX = (int)p.x;
specialY = (int)p.y;
goto setModifiers; // set the modifier variable
}
return;
default:
break;
}
if (keyboardUp!=0) {
anyevents = keybUpEvent = true;
GetMouse(&p,&m_buttons);
key = aChar;
keyX = (int)p.x;
keyY = (int)p.y;
setModifiers:
modifierKeys = 0;
uint32 beMod = Window()->CurrentMessage()->FindInt32("modifiers");
if(beMod & B_SHIFT_KEY)
modifierKeys |= GLUT_ACTIVE_SHIFT;
if(beMod & B_CONTROL_KEY)
modifierKeys |= GLUT_ACTIVE_CTRL;
if(beMod & B_OPTION_KEY) {
// since the window traps B_COMMAND_KEY, we'll have to settle
// for the option key.. but we need to get the raw character,
// not the Unicode-enhanced version
key = Window()->CurrentMessage()->FindInt32("raw_char");
modifierKeys |= GLUT_ACTIVE_ALT;
}
gBlock.NewEvent();
}
}
/***********************************************************
* CLASS: GlutWindow
*
@ -595,6 +745,35 @@ void GlutWindow::MouseMoved(BPoint point,
}
}
/***********************************************************
* CLASS: GlutWindow
*
* FUNCTION: MessageReceived
*
* DESCRIPTION: handles mouse wheel events
***********************************************************/
void GlutWindow::MessageReceived(BMessage *message)
{
switch(message->what){
case B_MOUSE_WHEEL_CHANGED:
{
float shift=0;
if(message->FindFloat("be:wheel_delta_y",&shift)==B_OK) {
if(shift>0)button = MOUSE_WHEEL_UP;
if(shift<0)button = MOUSE_WHEEL_DOWN;
if(shift!=0) {
anyevents = mouseEvent = true;
gBlock.NewEvent();
}
}
break;
}
default:
break;
}
}
/***********************************************************
* CLASS: GlutWindow
*

View File

@ -120,8 +120,10 @@ GlutWindow::GlutWindow(GlutWindow *nparent, char *name,
passive = 0;
entry = 0;
keyboard = 0;
keyboardUp = 0;
visibility = 0;
special = 0;
specialUp = 0;
windowStatus = 0;
// clear event counters
@ -133,9 +135,11 @@ GlutWindow::GlutWindow(GlutWindow *nparent, char *name,
passiveEvent = 0;
entryEvent = 0;
keybEvent = 0;
keybUpEvent = 0;
windowStatusEvent = 0; // DirectConnected() will report change in
visState = -1; // visibility
specialEvent = 0;
specialUpEvent = 0;
statusEvent = 0;
menuEvent = 0;
visible = true;

View File

@ -31,8 +31,10 @@ class GlutWindow : public BGLView {
public:
GlutWindow(GlutWindow *nparent, char *name, int x, int y, int width,
int height, ulong options);
virtual void MessageReceived(BMessage *message);
void KeyDown(const char *bytes, int32 numBytes);
void KeyUp(const char *bytes, int32 numBytes);
void MouseDown(BPoint point);
void MouseMoved(BPoint point, uint32 transit, const BMessage *message);
void FrameResized(float width, float height);
@ -63,8 +65,10 @@ public:
GLUTpassiveCB passive; /* passive motion (x,y) */
GLUTentryCB entry; /* window entry/exit (state) */
GLUTkeyboardCB keyboard; /* keyboard (ASCII,x,y) */
GLUTkeyboardCB keyboardUp; /* keyboard up (ASCII,x,y) */
GLUTvisibilityCB visibility; /* visibility */
GLUTspecialCB special; /* special key */
GLUTspecialCB specialUp; /* special key up */
GLUTwindowStatusCB windowStatus; /* window status */
bool anyevents; // were any events received?
@ -75,8 +79,10 @@ public:
bool passiveEvent; // call passive
bool entryEvent; // call entry
bool keybEvent; // call keyboard
bool keybUpEvent; // call keyboard
bool windowStatusEvent; // call visibility
bool specialEvent; // call special
bool specialUpEvent; // call special
bool statusEvent; // menu status changed
bool menuEvent; // menu selected

View File

@ -123,8 +123,8 @@ static struct name_address_pair glut_functions[] = {
{ "glutMenuStatusFunc", (const GLUTproc) glutMenuStatusFunc },
{ "glutOverlayDisplayFunc", (const GLUTproc) glutOverlayDisplayFunc },
{ "glutWindowStatusFunc", (const GLUTproc) glutWindowStatusFunc },
// { "glutKeyboardUpFunc", (const GLUTproc) glutKeyboardUpFunc },
// { "glutSpecialUpFunc", (const GLUTproc) glutSpecialUpFunc },
{ "glutKeyboardUpFunc", (const GLUTproc) glutKeyboardUpFunc },
{ "glutSpecialUpFunc", (const GLUTproc) glutSpecialUpFunc },
// { "glutJoystickFunc", (const GLUTproc) glutJoystickFunc },
{ "glutSetColor", (const GLUTproc) glutSetColor },
{ "glutGetColor", (const GLUTproc) glutGetColor },