예제 #1
0
파일: vehicle.c 프로젝트: Jalakas/libgarmin
int
vehicle_remove_attr(struct vehicle *this_, struct attr *attr)
{
	switch (attr->type) {
	case attr_callback:
		callback_list_remove(this_->cbl, attr->u.callback);
		break;
	default:
		return 0;
	}
	return 1;
}
예제 #2
0
/**************************************************************************
  SDL-client main loop.
**************************************************************************/
Uint16 gui_event_loop(void *pData,
                      void (*loop_action)(void *pData),
                      Uint16 (*key_down_handler)(SDL_keysym Key, void *pData),
                      Uint16 (*key_up_handler)(SDL_keysym Key, void *pData),
                      Uint16 (*mouse_button_down_handler)(SDL_MouseButtonEvent *pButtonEvent, void *pData),
                      Uint16 (*mouse_button_up_handler)(SDL_MouseButtonEvent *pButtonEvent, void *pData),
                      Uint16 (*mouse_motion_handler)(SDL_MouseMotionEvent *pMotionEvent, void *pData))
{
    Uint16 ID;
    static struct timeval tv;
    static fd_set civfdset;
    Uint32 t_current, t_last_unit_anim, t_last_map_scrolling;
    Uint32 real_timer_next_call;
    static int result, schot_nr = 0;
    static char schot[32];

    ID = ID_ERROR;
    t_last_map_scrolling = t_last_unit_anim = real_timer_next_call = SDL_GetTicks();
    while (ID == ID_ERROR) {
        /* ========================================= */
        /* net check with 10ms delay event loop */
        if ((net_socket >= 0) || (ggz_socket >= 0)) {
            FD_ZERO(&civfdset);

            if (net_socket >= 0) {
                FD_SET(net_socket, &civfdset);
            }
            if (ggz_socket >= 0) {
                FD_SET(ggz_socket, &civfdset);
            }

            tv.tv_sec = 0;
            tv.tv_usec = 10000;/* 10ms*/

            result = fc_select(MAX(net_socket, ggz_socket) + 1, &civfdset, NULL, NULL, &tv);
            if (result < 0) {
                if (errno != EINTR) {
                    break;
                } else {
                    continue;
                }
            } else {
                if (result > 0) {
                    if ((net_socket >= 0) && FD_ISSET(net_socket, &civfdset)) {
                        SDL_PushEvent(pNet_User_Event);
                    }
                    if ((ggz_socket >= 0) && FD_ISSET(ggz_socket, &civfdset)) {
                        SDL_PushEvent(pGGZ_User_Event);
                    }
                }
            }
        } else { /* if connection is not establish */
            SDL_Delay(10);
        }
        /* ========================================= */

        t_current = SDL_GetTicks();

        if (t_current > real_timer_next_call) {
            real_timer_next_call = t_current + (real_timer_callback() * 1000);
        }

        if ((t_current - t_last_unit_anim) > UNITS_TIMER_INTERVAL) {
            if (autoconnect) {
                widget_info_counter++;
                SDL_PushEvent(pAnim_User_Event);
            } else {
                SDL_PushEvent(pAnim_User_Event);
            }

            t_last_unit_anim = SDL_GetTicks();
        }

        if (is_map_scrolling) {
            if ((t_current - t_last_map_scrolling) > MAP_SCROLL_TIMER_INTERVAL) {
                SDL_PushEvent(pMap_Scroll_User_Event);
                t_last_map_scrolling = SDL_GetTicks();
            }
        } else {
            t_last_map_scrolling = SDL_GetTicks();
        }

        if (widget_info_counter > 0) {
            SDL_PushEvent(pInfo_User_Event);
            widget_info_counter = 0;
        }

        /* ========================================= */

        if (loop_action) {
            loop_action(pData);
        }

        /* ========================================= */

        while (SDL_PollEvent(&Main.event) == 1) {

            switch (Main.event.type) {

            case SDL_QUIT:
                return MAX_ID;
                break;

            case SDL_KEYUP:
                switch (Main.event.key.keysym.sym) {
                /* find if Shifts are released */
                case SDLK_RSHIFT:
                    RSHIFT = FALSE;
                    break;
                case SDLK_LSHIFT:
                    LSHIFT = FALSE;
                    break;
                case SDLK_LCTRL:
                    LCTRL = FALSE;
                    break;
                case SDLK_RCTRL:
                    RCTRL = FALSE;
                    break;
                case SDLK_LALT:
                    LALT = FALSE;
                    break;
                default:
                    if(key_up_handler) {
                        ID = key_up_handler(Main.event.key.keysym, pData);
                    }
                    break;
                }
                break;

            case SDL_KEYDOWN:
                switch(Main.event.key.keysym.sym) {
                case SDLK_PRINT:
                    fc_snprintf(schot, sizeof(schot), "fc_%05d.bmp", schot_nr++);
                    log_normal(_("Making screenshot %s"), schot);
                    SDL_SaveBMP(Main.screen, schot);
                    break;

                case SDLK_RSHIFT:
                    /* Right Shift is Pressed */
                    RSHIFT = TRUE;
                    break;

                case SDLK_LSHIFT:
                    /* Left Shift is Pressed */
                    LSHIFT = TRUE;
                    break;

                case SDLK_LCTRL:
                    /* Left CTRL is Pressed */
                    LCTRL = TRUE;
                    break;

                case SDLK_RCTRL:
                    /* Right CTRL is Pressed */
                    RCTRL = TRUE;
                    break;

                case SDLK_LALT:
                    /* Left ALT is Pressed */
                    LALT = TRUE;
                    break;

                default:
                    if(key_down_handler) {
                        ID = key_down_handler(Main.event.key.keysym, pData);
                    }
                    break;
                }
                break;

            case SDL_MOUSEBUTTONDOWN:
                if(mouse_button_down_handler) {
                    ID = mouse_button_down_handler(&Main.event.button, pData);
                }
                break;

            case SDL_MOUSEBUTTONUP:
                if(mouse_button_up_handler) {
                    ID = mouse_button_up_handler(&Main.event.button, pData);
                }
                break;

            case SDL_MOUSEMOTION:
                if(mouse_motion_handler) {
                    ID = mouse_motion_handler(&Main.event.motion, pData);
                }
                break;

            case SDL_USEREVENT:
                switch(Main.event.user.code) {
                case NET:
                    input_from_server(net_socket);
                    break;
                case GGZ:
                    input_from_ggz(ggz_socket);
                    break;
                case ANIM:
                    update_button_hold_state();
                    animate_mouse_cursor();
                    draw_mouse_cursor();
                    break;
                case SHOW_WIDGET_INFO_LABBEL:
                    draw_widget_info_label();
                    break;
                case TRY_AUTO_CONNECT:
                    if (try_to_autoconnect()) {
                        pInfo_User_Event->user.code = SHOW_WIDGET_INFO_LABBEL;
                        autoconnect = FALSE;
                    }
                    break;
                case FLUSH:
                    unqueue_flush();
                    break;
                case MAP_SCROLL:
                    scroll_mapview(scroll_dir);
                    break;
                case EXIT_FROM_EVENT_LOOP:
                    return MAX_ID;
                    break;
                default:
                    break;
                }
                break;

            }
        }

        if (ID == ID_ERROR) {
            if (callbacks && callback_list_size(callbacks) > 0) {
                struct callback *cb = callback_list_get(callbacks, 0);
                callback_list_remove(callbacks, cb);
                (cb->callback)(cb->data);
                free(cb);
            }
        }
    }

    return ID;
}
예제 #3
0
파일: navit.c 프로젝트: justinzane/navit
void
navit_remove_vehicle_cb(struct navit *this_, struct callback *cb)
{
	callback_list_remove(this_->vehicle_cbl, cb);
}