@@ -79,8 +79,8 @@ caca_t * caca_attach(cucul_t * qq) | |||||
kk->timer.last_usec = 0; | kk->timer.last_usec = 0; | ||||
kk->lastticks = 0; | kk->lastticks = 0; | ||||
kk->mouse_x = kk->qq->width / 2; | |||||
kk->mouse_y = kk->qq->height / 2; | |||||
kk->mouse.x = kk->qq->width / 2; | |||||
kk->mouse.y = kk->qq->height / 2; | |||||
kk->resize = 0; | kk->resize = 0; | ||||
kk->resize_event = 0; | kk->resize_event = 0; | ||||
@@ -86,8 +86,10 @@ struct caca_timer | |||||
/* Internal caca context */ | /* Internal caca context */ | ||||
struct caca_context | struct caca_context | ||||
{ | { | ||||
/* A link to our cucul canvas */ | |||||
cucul_t *qq; | cucul_t *qq; | ||||
/* Device-specific functions */ | |||||
struct drv | struct drv | ||||
{ | { | ||||
enum caca_driver driver; | enum caca_driver driver; | ||||
@@ -103,12 +105,17 @@ struct caca_context | |||||
unsigned int (* get_event) (caca_t *); | unsigned int (* get_event) (caca_t *); | ||||
} drv; | } drv; | ||||
//unsigned int width, height; | |||||
unsigned int mouse_x, mouse_y; | |||||
/* Mouse position */ | |||||
struct mouse | |||||
{ | |||||
unsigned int x, y; | |||||
} mouse; | |||||
/* Window resize handling */ | |||||
int resize; | int resize; | ||||
int resize_event; | int resize_event; | ||||
/* Framerate handling */ | |||||
unsigned int delay, rendertime; | unsigned int delay, rendertime; | ||||
struct caca_timer timer; | struct caca_timer timer; | ||||
int lastticks; | int lastticks; | ||||
@@ -331,9 +331,9 @@ static unsigned int gl_get_event(caca_t *kk) | |||||
event |= CACA_EVENT_MOUSE_PRESS | kk->drv.p->mouse_button; | event |= CACA_EVENT_MOUSE_PRESS | kk->drv.p->mouse_button; | ||||
kk->drv.p->mouse_clicked = 0; | kk->drv.p->mouse_clicked = 0; | ||||
} | } | ||||
kk->mouse_x = kk->drv.p->mouse_x; | |||||
kk->mouse_y = kk->drv.p->mouse_y; | |||||
event |= CACA_EVENT_MOUSE_MOTION | (kk->mouse_x << 12) | kk->mouse_y; | |||||
kk->mouse.x = kk->drv.p->mouse_x; | |||||
kk->mouse.y = kk->drv.p->mouse_y; | |||||
event |= CACA_EVENT_MOUSE_MOTION | (kk->mouse.x << 12) | kk->mouse.y; | |||||
kk->drv.p->mouse_changed = 0; | kk->drv.p->mouse_changed = 0; | ||||
} | } | ||||
@@ -360,14 +360,14 @@ static unsigned int ncurses_get_event(caca_t *kk) | |||||
break; | break; | ||||
} | } | ||||
if(kk->mouse_x == (unsigned int)mevent.x && | |||||
kk->mouse_y == (unsigned int)mevent.y) | |||||
if(kk->mouse.x == (unsigned int)mevent.x && | |||||
kk->mouse.y == (unsigned int)mevent.y) | |||||
return _pop_event(kk); | return _pop_event(kk); | ||||
kk->mouse_x = mevent.x; | |||||
kk->mouse_y = mevent.y; | |||||
kk->mouse.x = mevent.x; | |||||
kk->mouse.y = mevent.y; | |||||
return CACA_EVENT_MOUSE_MOTION | (kk->mouse_x << 12) | kk->mouse_y; | |||||
return CACA_EVENT_MOUSE_MOTION | (kk->mouse.x << 12) | kk->mouse.y; | |||||
} | } | ||||
event = CACA_EVENT_KEY_PRESS; | event = CACA_EVENT_KEY_PRESS; | ||||
@@ -287,13 +287,13 @@ static unsigned int slang_get_event(caca_t *kk) | |||||
_push_event(kk, CACA_EVENT_MOUSE_PRESS | button); | _push_event(kk, CACA_EVENT_MOUSE_PRESS | button); | ||||
_push_event(kk, CACA_EVENT_MOUSE_RELEASE | button); | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | button); | ||||
if(kk->mouse_x == x && kk->mouse_y == y) | |||||
if(kk->mouse.x == x && kk->mouse.y == y) | |||||
return _pop_event(kk); | return _pop_event(kk); | ||||
kk->mouse_x = x; | |||||
kk->mouse_y = y; | |||||
kk->mouse.x = x; | |||||
kk->mouse.y = y; | |||||
return CACA_EVENT_MOUSE_MOTION | (kk->mouse_x << 12) | kk->mouse_y; | |||||
return CACA_EVENT_MOUSE_MOTION | (kk->mouse.x << 12) | kk->mouse.y; | |||||
} | } | ||||
event = CACA_EVENT_KEY_PRESS; | event = CACA_EVENT_KEY_PRESS; | ||||
@@ -261,14 +261,15 @@ static unsigned int win32_get_event(caca_t *kk) | |||||
{ | { | ||||
COORD pos = rec.Event.MouseEvent.dwMousePosition; | COORD pos = rec.Event.MouseEvent.dwMousePosition; | ||||
if(kk->mouse_x == (unsigned int)pos.X && | |||||
kk->mouse_y == (unsigned int)pos.Y) | |||||
if(kk->mouse.x == (unsigned int)pos.X && | |||||
kk->mouse.y == (unsigned int)pos.Y) | |||||
continue; | continue; | ||||
kk->mouse_x = pos.X; | |||||
kk->mouse_y = pos.Y; | |||||
kk->mouse.x = pos.X; | |||||
kk->mouse.y = pos.Y; | |||||
return CACA_EVENT_MOUSE_MOTION | (kk->mouse_x << 12) | kk->mouse_y; | |||||
return CACA_EVENT_MOUSE_MOTION | |||||
| (kk->mouse.x << 12) | kk->mouse.y; | |||||
} | } | ||||
#if 0 | #if 0 | ||||
else if(rec.Event.MouseEvent.dwEventFlags == DOUBLE_CLICK) | else if(rec.Event.MouseEvent.dwEventFlags == DOUBLE_CLICK) | ||||
@@ -387,13 +387,13 @@ static unsigned int x11_get_event(caca_t *kk) | |||||
if(newy >= kk->qq->height) | if(newy >= kk->qq->height) | ||||
newy = kk->qq->height - 1; | newy = kk->qq->height - 1; | ||||
if(kk->mouse_x == newx && kk->mouse_y == newy) | |||||
if(kk->mouse.x == newx && kk->mouse.y == newy) | |||||
continue; | continue; | ||||
kk->mouse_x = newx; | |||||
kk->mouse_y = newy; | |||||
kk->mouse.x = newx; | |||||
kk->mouse.y = newy; | |||||
return CACA_EVENT_MOUSE_MOTION | (kk->mouse_x << 12) | kk->mouse_y; | |||||
return CACA_EVENT_MOUSE_MOTION | (kk->mouse.x << 12) | kk->mouse.y; | |||||
} | } | ||||
/* Check for mouse press and release events */ | /* Check for mouse press and release events */ | ||||
@@ -103,10 +103,10 @@ unsigned int caca_wait_event(caca_t *kk, unsigned int event_mask) | |||||
*/ | */ | ||||
unsigned int caca_get_mouse_x(caca_t *kk) | unsigned int caca_get_mouse_x(caca_t *kk) | ||||
{ | { | ||||
if(kk->mouse_x >= kk->qq->width) | |||||
kk->mouse_x = kk->qq->width - 1; | |||||
if(kk->mouse.x >= kk->qq->width) | |||||
kk->mouse.x = kk->qq->width - 1; | |||||
return kk->mouse_x; | |||||
return kk->mouse.x; | |||||
} | } | ||||
/** \brief Return the Y mouse coordinate. | /** \brief Return the Y mouse coordinate. | ||||
@@ -120,10 +120,10 @@ unsigned int caca_get_mouse_x(caca_t *kk) | |||||
*/ | */ | ||||
unsigned int caca_get_mouse_y(caca_t *kk) | unsigned int caca_get_mouse_y(caca_t *kk) | ||||
{ | { | ||||
if(kk->mouse_y >= kk->qq->height) | |||||
kk->mouse_y = kk->qq->height - 1; | |||||
if(kk->mouse.y >= kk->qq->height) | |||||
kk->mouse.y = kk->qq->height - 1; | |||||
return kk->mouse_y; | |||||
return kk->mouse.y; | |||||
} | } | ||||
/* | /* | ||||