mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-10-06 00:30:10 -06:00
rainbow: LinuxFb supports mouse
git-svn-id: svn://ultimatepp.org/upp/trunk@3651 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
4d7308e99e
commit
0cc7a47259
7 changed files with 434 additions and 218 deletions
|
|
@ -2,7 +2,19 @@
|
|||
|
||||
NAMESPACE_UPP
|
||||
|
||||
#define LLOG(x) LOG(x)
|
||||
#define LLOG(x) //LOG(x)
|
||||
|
||||
SDL_Surface *CreateScreen(int w, int h, int bpp, int flags)
|
||||
{
|
||||
SDL_Surface * screen = SDL_SetVideoMode(w, h, bpp, flags);
|
||||
if(!screen)
|
||||
{
|
||||
Cout() << Format("Couldn't set display mode: %s\n", SDL_GetError());
|
||||
return NULL;
|
||||
}
|
||||
Cout() << Format("Screen is in %s mode\n", (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed");
|
||||
return screen;
|
||||
}
|
||||
|
||||
//GetModState ??
|
||||
bool GetShift() { uint8* ka = SDL_GetKeyState(NULL); return ka[SDLK_LSHIFT] || ka[SDLK_RSHIFT]; }
|
||||
|
|
@ -32,7 +44,109 @@ dword fbKEYtoK(dword chr) {
|
|||
return chr;
|
||||
}
|
||||
|
||||
void HandleUserEvents(SDL_Event* event)
|
||||
void HandleSDLEvent(SDL_Event* event)
|
||||
{
|
||||
switch(event->type) {
|
||||
case SDL_ACTIVEEVENT: //SDL_ActiveEvent
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP: //SDL_KeyboardEvent
|
||||
{
|
||||
String msgdump;
|
||||
switch(event->type)
|
||||
{
|
||||
case SDL_KEYDOWN: msgdump << "SDL_KEYDOWN"; break;
|
||||
case SDL_KEYUP: msgdump << "SDL_KEYUP"; break;
|
||||
}
|
||||
msgdump << (int)event->key.keysym.sym;
|
||||
LLOG(msgdump);
|
||||
|
||||
bool b = false;
|
||||
dword keycode = 0;
|
||||
if(event->type == SDL_KEYDOWN) {
|
||||
keycode = fbKEYtoK((dword)event->key.keysym.sym);
|
||||
if(keycode != K_SPACE) //dont send space on keydown
|
||||
b = Ctrl::DoKeyFB(keycode, 1);
|
||||
|
||||
//send respective keyup things as char events as well
|
||||
keycode = (dword)event->key.keysym.unicode;
|
||||
if((keycode != 127 && keycode > 32 && keycode < 255)
|
||||
|| (keycode == 32 && fbKEYtoK(SDLK_SPACE) == K_SPACE))
|
||||
b = Ctrl::DoKeyFB(keycode, 1);
|
||||
}
|
||||
else
|
||||
if(event->type == SDL_KEYUP)
|
||||
{
|
||||
keycode = fbKEYtoK((dword)event->key.keysym.sym) | K_KEYUP;
|
||||
b = Ctrl::DoKeyFB(keycode, 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEMOTION: //SDL_MouseMotionEvent
|
||||
Ctrl::DoMouseFB(Ctrl::MOUSEMOVE, Point(event->motion.x, event->motion.y));
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN: //SDL_MouseButtonEvent, FIXME DoubleClick
|
||||
{
|
||||
Point p(event->button.x, event->button.y);
|
||||
switch(event->button.button)
|
||||
{
|
||||
case SDL_BUTTON_LEFT: Ctrl::DoMouseFB(Ctrl::LEFTDOWN, p); break;
|
||||
case SDL_BUTTON_RIGHT: Ctrl::DoMouseFB(Ctrl::RIGHTDOWN, p); break;
|
||||
case SDL_BUTTON_MIDDLE: Ctrl::DoMouseFB(Ctrl::MIDDLEDOWN, p); break;
|
||||
case SDL_BUTTON_WHEELUP: Ctrl::DoMouseFB(Ctrl::MOUSEWHEEL, p, +120); break;
|
||||
case SDL_BUTTON_WHEELDOWN: Ctrl::DoMouseFB(Ctrl::MOUSEWHEEL, p, -120); break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
{
|
||||
Point p(event->button.x, event->button.y);
|
||||
switch(event->button.button)
|
||||
{
|
||||
case SDL_BUTTON_LEFT: Ctrl::DoMouseFB(Ctrl::LEFTUP, p); break;
|
||||
case SDL_BUTTON_RIGHT: Ctrl::DoMouseFB(Ctrl::RIGHTUP, p); break;
|
||||
case SDL_BUTTON_MIDDLE: Ctrl::DoMouseFB(Ctrl::MIDDLEUP, p); break;
|
||||
case SDL_BUTTON_WHEELUP: Ctrl::DoMouseFB(Ctrl::MOUSEWHEEL, p, +120); break;
|
||||
case SDL_BUTTON_WHEELDOWN: Ctrl::DoMouseFB(Ctrl::MOUSEWHEEL, p, -120); break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_JOYAXISMOTION: //SDL_JoyAxisEvent
|
||||
break;
|
||||
case SDL_JOYBALLMOTION: //SDL_JoyBallEvent
|
||||
break;
|
||||
case SDL_JOYHATMOTION: //SDL_JoyHatEvent
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
case SDL_JOYBUTTONUP: //SDL_JoyButtonEvent
|
||||
break;
|
||||
case SDL_VIDEORESIZE: //SDL_ResizeEvent
|
||||
{
|
||||
width = event->resize.w;
|
||||
height = event->resize.h;
|
||||
|
||||
SDL_FreeSurface(screen);
|
||||
screen = CreateScreen(width, height, bpp, videoflags);
|
||||
ASSERT(screen);
|
||||
Ctrl::SetFramebufferSize(Size(width, height));
|
||||
}
|
||||
break;
|
||||
case SDL_VIDEOEXPOSE: //SDL_ExposeEvent
|
||||
break;
|
||||
case SDL_QUIT: //SDL_QuitEvent
|
||||
break;
|
||||
case SDL_USEREVENT: //SDL_UserEvent
|
||||
HandleUserEvent(event);
|
||||
break;
|
||||
case SDL_SYSWMEVENT: //SDL_SysWMEvent
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
} // End switch
|
||||
}
|
||||
|
||||
void HandleUserEvent(SDL_Event* event)
|
||||
{
|
||||
/*
|
||||
switch (event->user.code) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,16 @@
|
|||
NAMESPACE_UPP
|
||||
|
||||
extern bool fbEndSession;
|
||||
void HandleUserEvents(SDL_Event* event);
|
||||
extern SDL_Surface * screen;
|
||||
extern int videoflags;
|
||||
extern int height;
|
||||
extern int width;
|
||||
extern int bpp;
|
||||
|
||||
SDL_Surface *CreateScreen(int w, int h, int bpp, int flags);
|
||||
dword fbKEYtoK(dword chr);
|
||||
void HandleSDLEvent(SDL_Event* event);
|
||||
void HandleUserEvent(SDL_Event* event);
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -2,27 +2,15 @@
|
|||
|
||||
NAMESPACE_UPP
|
||||
|
||||
dword fbKEYtoK(dword chr);
|
||||
#define LLOG(x) //LOG(x)
|
||||
|
||||
SDL_Surface * screen = NULL;
|
||||
bool fbEndSession = false;
|
||||
SDL_Surface * screen = NULL;
|
||||
int videoflags = 0;
|
||||
int height = 0;
|
||||
int width = 0;
|
||||
int bpp = 0;
|
||||
|
||||
SDL_Surface *CreateScreen(int w, int h, int bpp, int flags)
|
||||
{
|
||||
SDL_Surface * screen = SDL_SetVideoMode(w, h, bpp, flags);
|
||||
if(!screen)
|
||||
{
|
||||
Cout() << Format("Couldn't set display mode: %s\n", SDL_GetError());
|
||||
return NULL;
|
||||
}
|
||||
Cout() << Format("Screen is in %s mode\n", (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed");
|
||||
return screen;
|
||||
}
|
||||
|
||||
bool FBEndSession()
|
||||
{
|
||||
return fbEndSession;
|
||||
|
|
@ -40,108 +28,9 @@ bool FBProcessEvent(bool *quit)
|
|||
{
|
||||
SDL_Event event;
|
||||
if(SDL_PollEvent(&event)) {
|
||||
switch(event.type) {
|
||||
case SDL_ACTIVEEVENT: //SDL_ActiveEvent
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP: //SDL_KeyboardEvent
|
||||
{
|
||||
String msgdump;
|
||||
switch(event.type)
|
||||
{
|
||||
case SDL_KEYDOWN: msgdump << "SDL_KEYDOWN"; break;
|
||||
case SDL_KEYUP: msgdump << "SDL_KEYUP"; break;
|
||||
}
|
||||
// msgdump << " wParam = 0x" << FormatIntHex(wParam, 8)
|
||||
// << ", lParam = 0x" << FormatIntHex(lParam, 8);
|
||||
msgdump << (int)event.key.keysym.sym;
|
||||
RLOG(msgdump);
|
||||
|
||||
bool b = false;
|
||||
dword keycode = 0;
|
||||
if(event.type == SDL_KEYDOWN) {
|
||||
keycode = fbKEYtoK((dword)event.key.keysym.sym);
|
||||
if(keycode != K_SPACE) //dont send space on keydown
|
||||
b = Ctrl::DoKeyFB(keycode, 1);
|
||||
|
||||
//send respective keyup things as char events as well
|
||||
keycode = (dword)event.key.keysym.unicode;
|
||||
if((keycode != 127 && keycode > 32 && keycode < 255)
|
||||
|| (keycode == 32 && fbKEYtoK(SDLK_SPACE) == K_SPACE))
|
||||
b = Ctrl::DoKeyFB(keycode, 1);
|
||||
|
||||
}
|
||||
else
|
||||
if(event.type == SDL_KEYUP)
|
||||
{
|
||||
keycode = fbKEYtoK((dword)event.key.keysym.sym) | K_KEYUP;
|
||||
b = Ctrl::DoKeyFB(keycode, 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEMOTION: //SDL_MouseMotionEvent
|
||||
Ctrl::DoMouseFB(Ctrl::MOUSEMOVE, Point(event.motion.x, event.motion.y));
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN: //SDL_MouseButtonEvent, FIXME DoubleClick
|
||||
{
|
||||
Point p(event.button.x, event.button.y);
|
||||
switch(event.button.button)
|
||||
{
|
||||
case SDL_BUTTON_LEFT: Ctrl::DoMouseFB(Ctrl::LEFTDOWN, p); break;
|
||||
case SDL_BUTTON_RIGHT: Ctrl::DoMouseFB(Ctrl::RIGHTDOWN, p); break;
|
||||
case SDL_BUTTON_MIDDLE: Ctrl::DoMouseFB(Ctrl::MIDDLEDOWN, p); break;
|
||||
case SDL_BUTTON_WHEELUP: Ctrl::DoMouseFB(Ctrl::MOUSEWHEEL, p, +120); break;
|
||||
case SDL_BUTTON_WHEELDOWN: Ctrl::DoMouseFB(Ctrl::MOUSEWHEEL, p, -120); break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
{
|
||||
Point p(event.button.x, event.button.y);
|
||||
switch(event.button.button)
|
||||
{
|
||||
case SDL_BUTTON_LEFT: Ctrl::DoMouseFB(Ctrl::LEFTUP, p); break;
|
||||
case SDL_BUTTON_RIGHT: Ctrl::DoMouseFB(Ctrl::RIGHTUP, p); break;
|
||||
case SDL_BUTTON_MIDDLE: Ctrl::DoMouseFB(Ctrl::MIDDLEUP, p); break;
|
||||
case SDL_BUTTON_WHEELUP: Ctrl::DoMouseFB(Ctrl::MOUSEWHEEL, p, +120); break;
|
||||
case SDL_BUTTON_WHEELDOWN: Ctrl::DoMouseFB(Ctrl::MOUSEWHEEL, p, -120); break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_JOYAXISMOTION: //SDL_JoyAxisEvent
|
||||
break;
|
||||
case SDL_JOYBALLMOTION: //SDL_JoyBallEvent
|
||||
break;
|
||||
case SDL_JOYHATMOTION: //SDL_JoyHatEvent
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
case SDL_JOYBUTTONUP: //SDL_JoyButtonEvent
|
||||
break;
|
||||
case SDL_VIDEORESIZE: //SDL_ResizeEvent
|
||||
{
|
||||
width = event.resize.w;
|
||||
height = event.resize.h;
|
||||
|
||||
SDL_FreeSurface(screen);
|
||||
screen = CreateScreen(width, height, bpp, videoflags);
|
||||
ASSERT(screen);
|
||||
Ctrl::SetFramebufferSize(Size(width, height));
|
||||
}
|
||||
break;
|
||||
case SDL_VIDEOEXPOSE: //SDL_ExposeEvent
|
||||
break;
|
||||
case SDL_QUIT: //SDL_QuitEvent
|
||||
if(quit) *quit = true;
|
||||
break;
|
||||
case SDL_USEREVENT: //SDL_UserEvent
|
||||
HandleUserEvents(&event);
|
||||
break;
|
||||
case SDL_SYSWMEVENT: //SDL_SysWMEvent
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
} // End switch
|
||||
if(event.type == SDL_QUIT && quit)
|
||||
*quit = true;
|
||||
HandleSDLEvent(&event);
|
||||
return true;
|
||||
} // End while
|
||||
return false;
|
||||
|
|
@ -162,7 +51,7 @@ void FBUpdate(const Rect& inv)
|
|||
memcpy(screen->pixels, ~framebuffer, framebuffer.GetLength() * sizeof(RGBA));
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
ASSERT(Size(screen->w,screen->h) == framebuffer.GetSize());
|
||||
|
||||
Size ssz = inv.GetSize();
|
||||
|
|
@ -183,8 +72,6 @@ void FBUpdate(const Rect& inv)
|
|||
|
||||
void FBFlush()
|
||||
{
|
||||
// ::UpdateWindow(fbHWND);
|
||||
// GdiFlush();
|
||||
}
|
||||
|
||||
void FBInit()
|
||||
|
|
@ -199,7 +86,7 @@ void FBInit()
|
|||
return;
|
||||
}
|
||||
|
||||
SDL_EnableUNICODE(1);
|
||||
SDL_EnableUNICODE(1); //for unicode keycode availability
|
||||
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL/2);
|
||||
|
||||
const SDL_VideoInfo* vi = SDL_GetVideoInfo();
|
||||
|
|
@ -207,8 +94,6 @@ void FBInit()
|
|||
|
||||
width = vi->current_w;
|
||||
height = vi->current_h;
|
||||
//width = 600;
|
||||
//height = 400;
|
||||
bpp = vi->vfmt->BitsPerPixel;
|
||||
ASSERT(bpp == 32);
|
||||
|
||||
|
|
@ -218,12 +103,11 @@ void FBInit()
|
|||
screen = CreateScreen(width, height, bpp, videoflags);
|
||||
ASSERT(screen);
|
||||
Ctrl::SetFramebufferSize(Size(width, height));
|
||||
|
||||
// Csizeinit();
|
||||
}
|
||||
|
||||
void FBDeInit()
|
||||
{
|
||||
Ctrl::ExitFB();
|
||||
SDL_FreeSurface(screen);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue