Beispiel #1
0
/* //////////////////////////////////////////////////////////////////////////////////////
 * implementation
 */
gb_device_ref_t gb_device_init(gb_window_ref_t window)
{
    // check
    tb_assert_and_check_return_val(window, tb_null);

    // the window mode
    tb_size_t mode = gb_window_mode(window);
    tb_assert_and_check_return_val(mode, tb_null);

    // done
    gb_device_ref_t device = tb_null;
    switch (mode)
    {
#ifdef GB_CONFIG_PACKAGE_HAVE_OPENGL
    case GB_WINDOW_MODE_GL:
        device = gb_device_init_gl(window);
        break;
#endif
    case GB_WINDOW_MODE_BITMAP:
#if defined(GB_CONFIG_PACKAGE_HAVE_SKIA)
        device = gb_device_init_skia(gb_window_bitmap(window));
#elif defined(GB_CONFIG_DEVICE_HAVE_BITMAP)
        device = gb_device_init_bitmap(gb_window_bitmap(window));
#else
        // trace
        tb_trace_e("no bitmap device!");
#endif
        break;
    default:
        // trace
        tb_trace_e("unknown window mode: %lu", mode);
        break;
    }

    // init
    tb_bool_t ok = tb_false;
    do
    {
        // check
        gb_device_impl_t* impl = (gb_device_impl_t*)device;
        tb_assert_and_check_break(impl);

        // init pixfmt
        impl->pixfmt    = (tb_uint16_t)gb_window_pixfmt(window); 

        // init width and height
        impl->width     = (tb_uint16_t)gb_window_width(window); 
        impl->height    = (tb_uint16_t)gb_window_height(window); 

        // ok
        ok = tb_true;

    } while (0);

    // failed?
    if (!ok)
    {
        // exit it
        if (device) gb_device_exit(device);
        device = tb_null;
    }

    // ok?
    return device;
}
Beispiel #2
0
static tb_void_t gb_window_sdl_fullscreen(gb_window_ref_t window, tb_bool_t fullscreen)
{
    // check
    gb_window_sdl_impl_t* impl = (gb_window_sdl_impl_t*)window;
    tb_assert_and_check_return(impl);

    // the pixmap
    gb_pixmap_ref_t pixmap = gb_pixmap(impl->base.pixfmt, 0xff);
    tb_assert_and_check_return(pixmap);

    // fullscreen?
    tb_size_t changed = tb_false;
    if (fullscreen && !(impl->base.flag & GB_WINDOW_FLAG_FULLSCREEN)) 
    {
        // exit surface
        if (impl->surface) SDL_FreeSurface(impl->surface);

        // init mode
        tb_size_t mode = SDL_DOUBLEBUF | SDL_FULLSCREEN;

        // TODO
        // the screen width and height
        tb_uint16_t screen_width  = 0;//tb_screen_width();
        tb_uint16_t screen_height = 0;//tb_screen_height();
        tb_assert(screen_width && screen_height && screen_width <= GB_WIDTH_MAXN && screen_height <= GB_HEIGHT_MAXN);

        // init surface
        impl->surface = SDL_SetVideoMode(screen_width, screen_height, pixmap->bpp, mode | SDL_HWSURFACE);
        if (!impl->surface) impl->surface = SDL_SetVideoMode(screen_width, screen_height, pixmap->bpp, mode | SDL_SWSURFACE);
        tb_assert(impl->surface && impl->surface->pixels);

        // update flag
        impl->base.flag |= GB_WINDOW_FLAG_FULLSCREEN;

        // save the normal width and height
        impl->normal_width      = (tb_uint16_t)gb_window_width(window);
        impl->normal_height     = (tb_uint16_t)gb_window_height(window);

        // update the window width and height
        impl->base.width        = screen_width;
        impl->base.height       = screen_height;

        // changed
        changed = tb_true;
    }
    else if (impl->base.flag & GB_WINDOW_FLAG_FULLSCREEN)
    {
        // exit surface
        if (impl->surface) SDL_FreeSurface(impl->surface);

        // init mode
        tb_size_t mode = SDL_DOUBLEBUF;
        if (impl->base.flag & GB_WINDOW_FLAG_HIHE_TITLEBAR) mode |= SDL_NOFRAME;
        if (impl->base.flag & GB_WINDOW_FLAG_NOT_REISZE) mode &= ~SDL_RESIZABLE;
        else mode |= SDL_RESIZABLE;

        // init surface
        impl->surface = SDL_SetVideoMode(impl->normal_width, impl->normal_height, pixmap->bpp, mode | SDL_HWSURFACE);
        if (!impl->surface) impl->surface = SDL_SetVideoMode(impl->normal_width, impl->normal_height, pixmap->bpp, mode | SDL_SWSURFACE);
        tb_assert(impl->surface && impl->surface->pixels);

        // update flag
        impl->base.flag &= ~GB_WINDOW_FLAG_FULLSCREEN;

        // update the window width and height
        impl->base.width        = impl->normal_width;
        impl->base.height       = impl->normal_height;

        // changed
        changed = tb_true;
    }

    // ok?
    if (changed)
    {
        // exit canvas first
        if (impl->canvas) gb_canvas_exit(impl->canvas);

        // exit bitmap first
        if (impl->base.bitmap) tb_free(impl->base.bitmap);

        // init bitmap
        impl->base.bitmap = gb_bitmap_init(impl->surface->pixels, impl->base.pixfmt, impl->base.width, impl->base.height, impl->surface->pitch, tb_false);
        tb_assert(impl->base.bitmap);

        // init canvas
        impl->canvas = gb_canvas_init_from_window(window);
        tb_assert(impl->canvas);

        // done resize
        if (impl->base.info.resize) impl->base.info.resize((gb_window_ref_t)impl, impl->canvas, impl->base.info.priv);
    }
}