X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=libchimara%2Fmouse.c;h=2c7d7b23812e67de6d83e62fd0659d0334bb930f;hb=0c5e51127206d26290a8e1e1349ab37d847d1d84;hp=f6c23b229e3b595114e26fa3b21c9991c1f46c06;hpb=632ef9d57c270608e01b1afdba772da0da7993ca;p=projects%2Fchimara%2Fchimara.git diff --git a/libchimara/mouse.c b/libchimara/mouse.c index f6c23b2..2c7d7b2 100644 --- a/libchimara/mouse.c +++ b/libchimara/mouse.c @@ -1,22 +1,34 @@ #include "mouse.h" #include "magic.h" +/** + * glk_request_mouse_event: + * @win: Window on which to request a mouse input event. + * + * Requests mouse input on the window @win. + */ void glk_request_mouse_event(winid_t win) { VALID_WINDOW(win, return); g_return_if_fail(win != NULL); - g_return_if_fail(win->type == wintype_TextBuffer || win->type == wintype_TextGrid); + g_return_if_fail(win->type == wintype_TextGrid || win->type == wintype_Graphics); g_signal_handler_unblock(win->widget, win->button_press_event_handler); } +/** + * glk_cancel_mouse_event: + * @win: Window with a mouse input event pending. + * + * Cancels the pending mouse input request on @win. + */ void glk_cancel_mouse_event(winid_t win) { VALID_WINDOW(win, return); g_return_if_fail(win != NULL); - g_return_if_fail(win->type == wintype_TextBuffer || win->type == wintype_TextGrid); + g_return_if_fail(win->type == wintype_TextGrid || win->type == wintype_Graphics); g_signal_handler_block(win->widget, win->button_press_event_handler); } @@ -27,8 +39,19 @@ on_window_button_press(GtkWidget *widget, GdkEventButton *event, winid_t win) ChimaraGlk *glk = CHIMARA_GLK(gtk_widget_get_ancestor(win->widget, CHIMARA_TYPE_GLK)); g_assert(glk); - /* TODO: calculate coordinates in proper metric */ - event_throw(glk, evtype_MouseInput, win, event->x, event->y); + switch(win->type) + { + case wintype_TextGrid: + event_throw(glk, evtype_MouseInput, win, event->x/win->unit_width, event->y/win->unit_height); + break; + case wintype_Graphics: + event_throw(glk, evtype_MouseInput, win, event->x, event->y); + break; + default: + ILLEGAL_PARAM("Unknown window type: %u", win->type); + } + + g_signal_handler_block(win->widget, win->button_press_event_handler); return TRUE; }