2007-10-12 04:17:00 -04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-05-02 16:05:29 -04:00
|
|
|
#include "config.h"
|
2007-10-12 04:17:00 -04:00
|
|
|
#endif
|
2007-05-02 16:05:29 -04:00
|
|
|
|
|
|
|
#include "clutter-stage-sdl.h"
|
|
|
|
#include "clutter-sdl.h"
|
|
|
|
|
|
|
|
#include "../clutter-main.h"
|
|
|
|
#include "../clutter-feature.h"
|
|
|
|
#include "../clutter-color.h"
|
|
|
|
#include "../clutter-util.h"
|
|
|
|
#include "../clutter-event.h"
|
|
|
|
#include "../clutter-enum-types.h"
|
|
|
|
#include "../clutter-private.h"
|
|
|
|
#include "../clutter-debug.h"
|
2007-05-22 05:31:40 -04:00
|
|
|
#include "../clutter-units.h"
|
2008-04-25 08:17:01 -04:00
|
|
|
#include "../clutter-stage-window.h"
|
2007-05-02 16:05:29 -04:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
#include "cogl/cogl.h"
|
2007-05-02 16:05:29 -04:00
|
|
|
|
2008-04-25 08:17:01 -04:00
|
|
|
static void clutter_stage_window_iface_init (ClutterStageWindowIface *iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (ClutterStageSDL,
|
|
|
|
clutter_stage_sdl,
|
2009-10-05 10:51:28 -04:00
|
|
|
G_TYPE_OBJECT,
|
2008-04-25 08:17:01 -04:00
|
|
|
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_STAGE_WINDOW,
|
|
|
|
clutter_stage_window_iface_init));
|
2007-05-02 16:05:29 -04:00
|
|
|
|
2009-10-05 10:51:28 -04:00
|
|
|
static ClutterActor *
|
|
|
|
clutter_stage_sdl_get_wrapper (ClutterStageWindow *stage_window)
|
2007-05-02 16:05:29 -04:00
|
|
|
{
|
2009-10-05 10:51:28 -04:00
|
|
|
return CLUTTER_ACTOR (CLUTTER_STAGE_SDL (stage_window)->wrapper);
|
2007-05-02 16:05:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-10-05 10:51:28 -04:00
|
|
|
clutter_stage_sdl_show (ClutterStageWindow *stage_window,
|
|
|
|
gboolean do_raise G_GNUC_UNUSED)
|
2007-05-02 16:05:29 -04:00
|
|
|
{
|
2009-10-05 10:51:28 -04:00
|
|
|
clutter_actor_map (clutter_stage_sdl_get_wrapper (stage_window));
|
2007-05-02 16:05:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-10-05 10:51:28 -04:00
|
|
|
clutter_stage_sdl_hide (ClutterStageWindow *stage_window)
|
2007-05-02 16:05:29 -04:00
|
|
|
{
|
2009-10-05 10:51:28 -04:00
|
|
|
clutter_actor_unmap (clutter_stage_sdl_get_wrapper (stage_window));
|
2007-05-02 16:05:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-10-05 10:51:28 -04:00
|
|
|
clutter_stage_sdl_unrealize (ClutterStageWindow *stage_window)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_stage_sdl_realize (ClutterStageWindow *stage_window)
|
2007-05-02 16:05:29 -04:00
|
|
|
{
|
2009-10-05 10:51:28 -04:00
|
|
|
ClutterStageSDL *stage_sdl = CLUTTER_STAGE_SDL (stage_window);
|
2009-07-31 13:34:51 -04:00
|
|
|
gboolean is_fullscreen = FALSE;
|
|
|
|
gint flags = SDL_OPENGL;
|
2007-05-02 16:05:29 -04:00
|
|
|
|
|
|
|
CLUTTER_NOTE (BACKEND, "Realizing main stage");
|
|
|
|
|
2008-04-25 08:17:01 -04:00
|
|
|
g_object_get (stage_sdl->wrapper,
|
2009-06-09 08:48:03 -04:00
|
|
|
"fullscreen-set", &is_fullscreen,
|
2008-04-25 08:17:01 -04:00
|
|
|
NULL);
|
2007-05-02 16:05:29 -04:00
|
|
|
|
2009-07-31 13:34:51 -04:00
|
|
|
if (is_fullscreen)
|
|
|
|
flags |= SDL_FULLSCREEN;
|
2007-05-02 16:05:29 -04:00
|
|
|
|
2009-07-31 13:34:51 -04:00
|
|
|
SDL_GL_SetAttribute (SDL_GL_ACCUM_RED_SIZE, 0);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
|
2008-04-25 08:17:01 -04:00
|
|
|
|
2009-07-31 13:34:51 -04:00
|
|
|
if (SDL_SetVideoMode (stage_sdl->win_width,
|
|
|
|
stage_sdl->win_height,
|
|
|
|
0, flags) == NULL)
|
2007-05-02 16:05:29 -04:00
|
|
|
{
|
2009-07-31 13:34:51 -04:00
|
|
|
CLUTTER_NOTE (BACKEND, "SDL appears not to handle this mode - %s",
|
|
|
|
SDL_GetError ());
|
2008-04-25 08:17:01 -04:00
|
|
|
|
2009-10-05 10:51:28 -04:00
|
|
|
return FALSE;
|
2007-05-02 16:05:29 -04:00
|
|
|
}
|
2009-10-05 10:51:28 -04:00
|
|
|
|
|
|
|
return TRUE;
|
2007-05-02 16:05:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-10-05 10:51:28 -04:00
|
|
|
clutter_stage_sdl_get_geometry (ClutterStageWindow *stage_window,
|
|
|
|
ClutterGeometry *geometry)
|
2007-05-02 16:05:29 -04:00
|
|
|
{
|
2009-10-05 10:51:28 -04:00
|
|
|
ClutterStageSDL *stage_sdl = CLUTTER_STAGE_SDL (stage_window);
|
|
|
|
gboolean is_fullscreen = FALSE;
|
2008-06-11 06:12:44 -04:00
|
|
|
|
2009-10-05 10:51:28 -04:00
|
|
|
is_fullscreen = clutter_stage_get_fullscreen (stage_sdl->wrapper);
|
2007-05-02 16:05:29 -04:00
|
|
|
|
2009-10-05 10:51:28 -04:00
|
|
|
if (is_fullscreen)
|
|
|
|
{
|
|
|
|
const SDL_VideoInfo *v_info;
|
2008-06-11 06:12:44 -04:00
|
|
|
|
2009-10-05 10:51:28 -04:00
|
|
|
v_info = SDL_GetVideoInfo ();
|
2008-06-11 06:12:44 -04:00
|
|
|
|
2009-10-05 10:51:28 -04:00
|
|
|
geometry->width = v_info->current_w;
|
|
|
|
geometry->height = v_info->current_h;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
geometry->width = stage_sdl->win_width;
|
|
|
|
geometry->height = stage_sdl->win_height;
|
|
|
|
}
|
2008-06-11 06:12:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-10-05 10:51:28 -04:00
|
|
|
clutter_stage_sdl_resize (ClutterStageWindow *stage_window,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
2007-05-02 16:05:29 -04:00
|
|
|
{
|
2009-10-05 10:51:28 -04:00
|
|
|
ClutterStageSDL *stage_sdl = CLUTTER_STAGE_SDL (stage_window);
|
2007-05-02 16:05:29 -04:00
|
|
|
|
2009-10-05 10:51:28 -04:00
|
|
|
if (width != stage_sdl->win_width ||
|
|
|
|
height != stage_sdl->win_height)
|
2007-05-02 16:05:29 -04:00
|
|
|
{
|
2009-10-05 10:51:28 -04:00
|
|
|
if (SDL_SetVideoMode (width, height, 0, SDL_OPENGL) == NULL)
|
2007-05-02 16:05:29 -04:00
|
|
|
{
|
|
|
|
/* Failed */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-05 10:51:28 -04:00
|
|
|
stage_sdl->win_width = width;
|
|
|
|
stage_sdl->win_height = height;
|
2007-05-02 16:05:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-04-25 08:17:01 -04:00
|
|
|
clutter_stage_sdl_set_fullscreen (ClutterStageWindow *stage_window,
|
|
|
|
gboolean fullscreen)
|
2007-05-02 16:05:29 -04:00
|
|
|
{
|
2008-04-25 08:17:01 -04:00
|
|
|
ClutterStageSDL *stage_sdl = CLUTTER_STAGE_SDL (stage_window);
|
2007-05-02 16:05:29 -04:00
|
|
|
int flags = SDL_OPENGL;
|
|
|
|
|
2008-04-25 08:17:01 -04:00
|
|
|
if (fullscreen)
|
|
|
|
flags |= SDL_FULLSCREEN;
|
2007-05-02 16:05:29 -04:00
|
|
|
|
2008-06-11 06:12:44 -04:00
|
|
|
SDL_SetVideoMode (stage_sdl->win_width,
|
|
|
|
stage_sdl->win_height,
|
|
|
|
0, flags);
|
2007-05-02 16:05:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-04-25 08:17:01 -04:00
|
|
|
clutter_stage_sdl_set_cursor_visible (ClutterStageWindow *stage_window,
|
|
|
|
gboolean show_cursor)
|
2007-05-02 16:05:29 -04:00
|
|
|
{
|
2008-04-25 08:17:01 -04:00
|
|
|
SDL_ShowCursor (show_cursor);
|
2007-05-02 16:05:29 -04:00
|
|
|
}
|
|
|
|
|
2007-06-19 05:10:37 -04:00
|
|
|
static void
|
2008-04-25 08:17:01 -04:00
|
|
|
clutter_stage_sdl_set_title (ClutterStageWindow *stage_window,
|
|
|
|
const gchar *title)
|
2007-06-19 05:10:37 -04:00
|
|
|
{
|
|
|
|
SDL_WM_SetCaption (title, NULL);
|
|
|
|
}
|
|
|
|
|
2007-05-02 16:05:29 -04:00
|
|
|
static void
|
|
|
|
clutter_stage_sdl_dispose (GObject *gobject)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (clutter_stage_sdl_parent_class)->dispose (gobject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_sdl_class_init (ClutterStageSDLClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->dispose = clutter_stage_sdl_dispose;
|
2008-04-25 08:17:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_window_iface_init (ClutterStageWindowIface *iface)
|
|
|
|
{
|
|
|
|
iface->set_fullscreen = clutter_stage_sdl_set_fullscreen;
|
|
|
|
iface->set_cursor_visible = clutter_stage_sdl_set_cursor_visible;
|
|
|
|
iface->set_title = clutter_stage_sdl_set_title;
|
2009-10-05 10:51:28 -04:00
|
|
|
iface->show = clutter_stage_sdl_show;
|
|
|
|
iface->hide = clutter_stage_sdl_hide;
|
|
|
|
iface->realize = clutter_stage_sdl_realize;
|
|
|
|
iface->unrealize = clutter_stage_sdl_unrealize;
|
|
|
|
iface->resize = clutter_stage_sdl_resize;
|
|
|
|
iface->get_geometry = clutter_stage_sdl_get_geometry;
|
|
|
|
iface->get_wrapper = clutter_stage_sdl_get_wrapper;
|
2007-05-02 16:05:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_sdl_init (ClutterStageSDL *stage)
|
|
|
|
{
|
|
|
|
stage->win_width = 640;
|
|
|
|
stage->win_height = 480;
|
|
|
|
}
|
|
|
|
|