SDL:
- Refactoring; - Fixed mouse bug; - Added middle mouse button support. git-svn-id: svn://kolibrios.org@9785 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
2f58880d77
commit
1d446821e9
@ -33,7 +33,7 @@ static char rcsid =
|
|||||||
#include "SDL_error.h"
|
#include "SDL_error.h"
|
||||||
#include "SDL_timer.h"
|
#include "SDL_timer.h"
|
||||||
#include "SDL_timer_c.h"
|
#include "SDL_timer_c.h"
|
||||||
#include "kos32sys.h"
|
#include <sys/ksys.h>
|
||||||
|
|
||||||
#if _POSIX_THREAD_SYSCALL_SOFT
|
#if _POSIX_THREAD_SYSCALL_SOFT
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
@ -43,52 +43,24 @@ static char rcsid =
|
|||||||
#define USE_ITIMER
|
#define USE_ITIMER
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* The first ticks value of the application */
|
|
||||||
//static struct timeval start;
|
|
||||||
//static unsigned startlo,starthi;
|
|
||||||
//static unsigned clockrate;
|
|
||||||
static unsigned starttime;
|
static unsigned starttime;
|
||||||
|
|
||||||
void SDL_StartTicks(void)
|
void SDL_StartTicks(void)
|
||||||
{
|
{
|
||||||
// gettimeofday(&start, NULL);
|
starttime = _ksys_get_tick_count();
|
||||||
// __asm__ ("int $0x40" : "=a"(clockrate) : "a"(18),"b"(5));
|
|
||||||
// __asm__ ("rdtsc" : "=a"(startlo),"=d"(starthi));
|
|
||||||
__asm__ ("int $0x40" : "=a"(starttime) : "a"(26),"b"(9));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Uint32 SDL_GetTicks (void)
|
Uint32 SDL_GetTicks (void)
|
||||||
{
|
{
|
||||||
/* struct timeval now;
|
unsigned curtime = _ksys_get_tick_count();
|
||||||
Uint32 ticks;
|
|
||||||
gettimeofday(&now, NULL);
|
|
||||||
ticks=(now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000;
|
|
||||||
return(ticks);*/
|
|
||||||
/*int res;
|
|
||||||
__asm__ ("rdtsc\n\t"
|
|
||||||
"sub (_startlo),%%eax\n\t"
|
|
||||||
"sbb (_starthi),%%edx\n\t"
|
|
||||||
"push %%eax\n\t"
|
|
||||||
"mov %%edx,%%eax\n\t"
|
|
||||||
"mov $1000,%%ecx\n\t"
|
|
||||||
"mul %%ecx\n\t"
|
|
||||||
"xchg (%%esp),%%eax\n\t"
|
|
||||||
"mul %%ecx\n\t"
|
|
||||||
"add %%edx,(%%esp)\n\t"
|
|
||||||
"pop %%edx\n\t"
|
|
||||||
"divl (_clockrate)\n\t" : "=a"(res));
|
|
||||||
return res;*/
|
|
||||||
unsigned curtime;
|
|
||||||
__asm__ ("int $0x40" : "=a"(curtime) : "a"(26),"b"(9));
|
|
||||||
return (curtime-starttime)*10;
|
return (curtime-starttime)*10;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDL_Delay(unsigned ms){
|
void SDL_Delay(unsigned ms){
|
||||||
unsigned start = SDL_GetTicks();
|
unsigned start = SDL_GetTicks();
|
||||||
do{
|
do{
|
||||||
delay(1);
|
_ksys_delay(1);
|
||||||
}while (SDL_GetTicks()-start < ms);
|
}while (SDL_GetTicks()-start < ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#include <menuet/os.h>
|
#include <stdint.h>
|
||||||
#include <kos32sys.h>
|
|
||||||
#include <sys/ksys.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <sys/ksys.h>
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
#include "SDL_sysevents.h"
|
#include "SDL_sysevents.h"
|
||||||
#include "SDL_sysvideo.h"
|
#include "SDL_sysvideo.h"
|
||||||
@ -11,70 +11,38 @@
|
|||||||
|
|
||||||
extern void kos_SDL_RepaintWnd(void);
|
extern void kos_SDL_RepaintWnd(void);
|
||||||
|
|
||||||
void MenuetOS_InitOSKeymap(_THIS)
|
void kos_InitOSKeymap(_THIS)
|
||||||
{
|
{
|
||||||
__asm__("int $0x40"::"a"(66),"b"(1),"c"(1));
|
_ksys_set_key_input_mode(KSYS_KEY_INPUT_MODE_SCANC);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LSHIFT 1
|
|
||||||
#define RSHIFT 2
|
|
||||||
#define LCTRL 4
|
|
||||||
#define RCTRL 8
|
|
||||||
#define LALT 0x10
|
|
||||||
#define RALT 0x20
|
|
||||||
#define CAPS 0x40
|
|
||||||
#define NUML 0x80
|
|
||||||
#define SCRL 0x100
|
|
||||||
|
|
||||||
#define SHIFT (LSHIFT+RSHIFT)
|
#define SHIFT (LSHIFT+RSHIFT)
|
||||||
#define CTRL (LCTRL+RCTRL)
|
#define CTRL (LCTRL+RCTRL)
|
||||||
#define ALT (LALT+RALT)
|
#define ALT (LALT+RALT)
|
||||||
|
|
||||||
static SDLMod GetModState(void)
|
static SDLMod GetModState(void)
|
||||||
{
|
{
|
||||||
unsigned controlstate;
|
unsigned controlstate = _ksys_get_control_key_state();
|
||||||
__asm__("int $0x40":"=a"(controlstate):"a"(66),"b"(3));
|
|
||||||
SDLMod res = 0;
|
SDLMod res = 0;
|
||||||
if (controlstate & LSHIFT)
|
if (controlstate & KSYS_CONTROL_LSHIFT)
|
||||||
res |= KMOD_LSHIFT;
|
res |= KMOD_LSHIFT;
|
||||||
if (controlstate & RSHIFT)
|
if (controlstate & KSYS_CONTROL_RSHIFT)
|
||||||
res |= KMOD_RSHIFT;
|
res |= KMOD_RSHIFT;
|
||||||
if (controlstate & LCTRL)
|
if (controlstate & KSYS_CONTROL_LCTRL)
|
||||||
res |= KMOD_LCTRL;
|
res |= KMOD_LCTRL;
|
||||||
if (controlstate & RCTRL)
|
if (controlstate & KSYS_CONTROL_RCTRL)
|
||||||
res |= KMOD_RCTRL;
|
res |= KMOD_RCTRL;
|
||||||
if (controlstate & LALT)
|
if (controlstate & KSYS_CONTROL_LALT)
|
||||||
res |= KMOD_LALT;
|
res |= KMOD_LALT;
|
||||||
if (controlstate & RALT)
|
if (controlstate & KSYS_CONTROL_RALT)
|
||||||
res |= KMOD_RALT;
|
res |= KMOD_RALT;
|
||||||
if (controlstate & CAPS)
|
if (controlstate & KSYS_CONTROL_CAPS)
|
||||||
res |= KMOD_CAPS;
|
res |= KMOD_CAPS;
|
||||||
if (controlstate & NUML)
|
if (controlstate & KSYS_CONTROL_NUM_LOCK)
|
||||||
res |= KMOD_NUM;
|
res |= KMOD_NUM;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*static __u8 scan2ascii(__u8 n,SDLMod mod)
|
|
||||||
{
|
|
||||||
__u8 layout[128];
|
|
||||||
int layouttype;
|
|
||||||
int bControlLayout = 0;
|
|
||||||
if (mod & KMOD_ALT)
|
|
||||||
layouttype = 3;
|
|
||||||
else if (mod & KMOD_SHIFT)
|
|
||||||
layouttype = 2;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (mod & KMOD_CTRL)
|
|
||||||
bControlLayout = 1;
|
|
||||||
layouttype = 1;
|
|
||||||
}
|
|
||||||
__asm__("int $0x40" :: "a"(26),"b"(2),"c"(layouttype),"d"(layout));
|
|
||||||
__u8 res = layout[n];
|
|
||||||
if (bControlLayout)
|
|
||||||
res -= 0x60;
|
|
||||||
return res;
|
|
||||||
}*/
|
|
||||||
static SDLKey sdlkeys[0x80] =
|
static SDLKey sdlkeys[0x80] =
|
||||||
{
|
{
|
||||||
// 0x0*
|
// 0x0*
|
||||||
@ -102,6 +70,7 @@ static SDLKey sdlkeys[0x80] =
|
|||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0
|
0, 0, 0, 0, 0, 0, 0, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
static SDLKey sdlkeys_shift[0x80] =
|
static SDLKey sdlkeys_shift[0x80] =
|
||||||
{
|
{
|
||||||
// 0x0*
|
// 0x0*
|
||||||
@ -129,6 +98,7 @@ static SDLKey sdlkeys_shift[0x80] =
|
|||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0
|
0, 0, 0, 0, 0, 0, 0, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
static SDLKey sdlkeys_e0[0x80] =
|
static SDLKey sdlkeys_e0[0x80] =
|
||||||
{
|
{
|
||||||
// 0x0*
|
// 0x0*
|
||||||
@ -157,36 +127,49 @@ static SDLKey sdlkeys_e0[0x80] =
|
|||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void KolibriOS_CheckMouseMode(_THIS);
|
extern void kos_CheckMouseMode(_THIS);
|
||||||
void MenuetOS_PumpEvents(_THIS)
|
|
||||||
|
void kos_PumpEvents(_THIS)
|
||||||
{
|
{
|
||||||
int i;
|
uint32_t kos_event;
|
||||||
|
ksys_pos_t mouse_pos;
|
||||||
|
ksys_pos_t center_pos;
|
||||||
SDL_keysym key;
|
SDL_keysym key;
|
||||||
static int ext_code = 0;
|
static int ext_code = 0;
|
||||||
static __u8 old_mode=0;
|
static uint8_t old_mode = 0;
|
||||||
for (;;) {
|
// static uint32_t old_mouse_but = 0;
|
||||||
i=__menuet__check_for_event();
|
static uint32_t mouse_but = 0;
|
||||||
switch(i)
|
|
||||||
{
|
while (1) {
|
||||||
case 0:
|
kos_event = _ksys_check_event();
|
||||||
|
switch (kos_event) {
|
||||||
|
case KSYS_EVENT_NONE:
|
||||||
return;
|
return;
|
||||||
case 1:
|
case KSYS_EVENT_REDRAW:
|
||||||
kos_SDL_RepaintWnd();
|
kos_SDL_RepaintWnd();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case KSYS_EVENT_KEY:
|
||||||
key.scancode = __menuet__getkey();
|
key.scancode = _ksys_get_key().code;
|
||||||
if (key.scancode == 0xE0 || key.scancode == 0xE1)
|
if (key.scancode == 0xE0 || key.scancode == 0xE1) {
|
||||||
{ext_code=key.scancode;break;}
|
ext_code = key.scancode;
|
||||||
if (ext_code == 0xE1 && (key.scancode & 0x7F) == 0x1D) break;
|
break;
|
||||||
if (ext_code == 0xE1 && key.scancode == 0xC5) {ext_code=0;break;}
|
}
|
||||||
|
if (ext_code == 0xE1 && (key.scancode & 0x7F) == 0x1D) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ext_code == 0xE1 && key.scancode == 0xC5) {
|
||||||
|
ext_code=0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
key.mod = GetModState();
|
key.mod = GetModState();
|
||||||
|
|
||||||
if (ext_code == 0xE1) key.mod &= ~KMOD_CTRL;
|
if (ext_code == 0xE1) key.mod &= ~KMOD_CTRL;
|
||||||
if (!(key.scancode & 0x80))
|
if (!(key.scancode & 0x80))
|
||||||
old_mode = key.mod;
|
old_mode = key.mod;
|
||||||
SDL_SetModState(key.mod);
|
SDL_SetModState(key.mod);
|
||||||
int code = (key.scancode & 0x80) ? SDL_RELEASED : SDL_PRESSED;
|
int code = (key.scancode & 0x80) ? SDL_RELEASED : SDL_PRESSED;
|
||||||
key.scancode &= 0x7F;
|
key.scancode &= 0x7F;
|
||||||
// key.sym = scan2ascii(key.scancode,key.mod);
|
|
||||||
if (ext_code == 0xE1 && key.scancode == 0x45)
|
if (ext_code == 0xE1 && key.scancode == 0x45)
|
||||||
key.sym = SDLK_PAUSE;
|
key.sym = SDLK_PAUSE;
|
||||||
else if (ext_code == 0xE0)
|
else if (ext_code == 0xE0)
|
||||||
@ -195,54 +178,52 @@ void MenuetOS_PumpEvents(_THIS)
|
|||||||
key.sym = sdlkeys_shift[key.scancode];
|
key.sym = sdlkeys_shift[key.scancode];
|
||||||
else
|
else
|
||||||
key.sym = sdlkeys[key.scancode];
|
key.sym = sdlkeys[key.scancode];
|
||||||
|
|
||||||
key.unicode=key.sym;
|
key.unicode=key.sym;
|
||||||
ext_code = 0;
|
ext_code = 0;
|
||||||
if (!key.sym) break;
|
if (!key.sym) break;
|
||||||
|
|
||||||
SDL_PrivateKeyboard(code, &key);
|
SDL_PrivateKeyboard(code, &key);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case KSYS_EVENT_BUTTON:
|
||||||
if (_ksys_get_button()==1) {
|
if (_ksys_get_button() == 1) exit(0);
|
||||||
SDL_CloseAudio();
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 6: {
|
case KSYS_EVENT_MOUSE: {
|
||||||
int __tmp,mx,my;
|
mouse_pos = _ksys_get_mouse_pos(KSYS_MOUSE_WINDOW_POS);
|
||||||
static int oldmousestate = 0;
|
if (mouse_pos.x >= 0 && mouse_pos.x < this->hidden->win_size_x &&
|
||||||
__asm__("int $0x40":"=a"(__tmp):"a"(37),"b"(1));
|
mouse_pos.y >= 0 && mouse_pos.y < this->hidden->win_size_y ||
|
||||||
mx=(__tmp>>16);
|
this->input_grab != SDL_GRAB_OFF) {
|
||||||
my=(__tmp&0xffff);
|
|
||||||
if(mx>=0 && mx<this->hidden->win_size_x &&
|
if (this->input_grab != SDL_GRAB_OFF) {
|
||||||
my>=0 && my<this->hidden->win_size_y || this->input_grab != SDL_GRAB_OFF)
|
center_pos.x = mouse_pos.x-this->hidden->win_size_x/2;
|
||||||
{
|
center_pos.y = mouse_pos.y-this->hidden->win_size_y/2;
|
||||||
if (this->input_grab != SDL_GRAB_OFF)
|
if (center_pos.x || center_pos.y) {
|
||||||
{
|
SDL_PrivateMouseMotion(0, 1, center_pos.x, center_pos.y);
|
||||||
int dx=mx-this->hidden->win_size_x/2;
|
|
||||||
int dy=my-this->hidden->win_size_y/2;
|
|
||||||
if (dx||dy)
|
|
||||||
{
|
|
||||||
SDL_PrivateMouseMotion(0,1,dx,dy);
|
|
||||||
kos_CheckMouseMode(this);
|
kos_CheckMouseMode(this);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
SDL_PrivateMouseMotion(0, 0, mouse_pos.x, mouse_pos.y);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
SDL_PrivateMouseMotion(0,0,mx,my);
|
mouse_but = _ksys_get_mouse_buttons();
|
||||||
__asm__("int $0x40":"=a"(__tmp):"a"(37),"b"(2));
|
if (mouse_but & KSYS_MOUSE_LBUTTON_PRESSED) {
|
||||||
if ((__tmp^oldmousestate)&1) {
|
|
||||||
if(__tmp&1)
|
|
||||||
{
|
|
||||||
SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0);
|
SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0);
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0);
|
SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0);
|
||||||
} }
|
}
|
||||||
if ((__tmp^oldmousestate)&2) {
|
if (mouse_but & KSYS_MOUSE_RBUTTON_PRESSED) {
|
||||||
if(__tmp&2)
|
|
||||||
{
|
|
||||||
SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_RIGHT, 0, 0);
|
SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_RIGHT, 0, 0);
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0);
|
SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0);
|
||||||
} }
|
}
|
||||||
oldmousestate = __tmp;
|
if (mouse_but & KSYS_MOUSE_MBUTTON_PRESSED) {
|
||||||
|
SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_MIDDLE, 0, 0);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,8 +219,9 @@ void kos_CheckMouseMode(_THIS)
|
|||||||
if (this->input_grab == SDL_GRAB_OFF)
|
if (this->input_grab == SDL_GRAB_OFF)
|
||||||
return;
|
return;
|
||||||
ksys_thread_t thread_info;
|
ksys_thread_t thread_info;
|
||||||
int res = _ksys_thread_info(&thread_info, -1);
|
int top = _ksys_thread_info(&thread_info, -1);
|
||||||
if (res == thread_info.window_pos_info) {
|
|
||||||
|
if (top == thread_info.pos_in_window_stack) {
|
||||||
int x = thread_info.winx_start + thread_info.clientx + this->hidden->win_size_x/2;
|
int x = thread_info.winx_start + thread_info.clientx + this->hidden->win_size_x/2;
|
||||||
int y = thread_info.winy_start + thread_info.clienty + this->hidden->win_size_y/2;
|
int y = thread_info.winy_start + thread_info.clienty + this->hidden->win_size_y/2;
|
||||||
_ksys_set_mouse_pos(x, y);
|
_ksys_set_mouse_pos(x, y);
|
||||||
@ -268,8 +269,8 @@ static SDL_VideoDevice *kos_CreateDevice(int indx)
|
|||||||
dev->IconifyWindow = NULL;
|
dev->IconifyWindow = NULL;
|
||||||
dev->GrabInput = NULL;
|
dev->GrabInput = NULL;
|
||||||
dev->GetWMInfo = NULL;
|
dev->GetWMInfo = NULL;
|
||||||
dev->InitOSKeymap = MenuetOS_InitOSKeymap;
|
dev->InitOSKeymap = kos_InitOSKeymap;
|
||||||
dev->PumpEvents = MenuetOS_PumpEvents;
|
dev->PumpEvents = kos_PumpEvents;
|
||||||
dev->free = kos_DeleteDevice;
|
dev->free = kos_DeleteDevice;
|
||||||
dev->CreateWMCursor = kos_CreateWMCursor;
|
dev->CreateWMCursor = kos_CreateWMCursor;
|
||||||
dev->FreeWMCursor = kos_FreeWMCursor;
|
dev->FreeWMCursor = kos_FreeWMCursor;
|
||||||
|
@ -14,7 +14,7 @@ struct SDL_PrivateVideoData {
|
|||||||
unsigned char** __lines;
|
unsigned char** __lines;
|
||||||
};
|
};
|
||||||
|
|
||||||
void MenuetOS_InitOSKeymap(_THIS);
|
void kos_InitOSKeymap(_THIS);
|
||||||
void MenuetOS_PumpEvents(_THIS);
|
void kos_PumpEvents(_THIS);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user