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,
|
|
|
|
CLUTTER_TYPE_ACTOR,
|
|
|
|
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_STAGE_WINDOW,
|
|
|
|
clutter_stage_window_iface_init));
|
2007-05-02 16:05:29 -04:00
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_sdl_show (ClutterActor *actor)
|
|
|
|
{
|
2007-11-26 07:07:25 -05:00
|
|
|
CLUTTER_ACTOR_SET_FLAGS (actor, CLUTTER_ACTOR_MAPPED);
|
|
|
|
|
|
|
|
CLUTTER_ACTOR_CLASS (clutter_stage_sdl_parent_class)->show (actor);
|
2007-05-02 16:05:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_sdl_hide (ClutterActor *actor)
|
|
|
|
{
|
|
|
|
/* No way to easily unmap SDL window ? */
|
2007-11-26 07:07:25 -05:00
|
|
|
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_MAPPED);
|
|
|
|
|
|
|
|
CLUTTER_ACTOR_CLASS (clutter_stage_sdl_parent_class)->hide (actor);
|
2007-05-02 16:05:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_sdl_unrealize (ClutterActor *actor)
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_sdl_realize (ClutterActor *actor)
|
|
|
|
{
|
|
|
|
ClutterStageSDL *stage_sdl = CLUTTER_STAGE_SDL (actor);
|
|
|
|
gboolean is_offscreen, is_fullscreen;
|
|
|
|
|
|
|
|
CLUTTER_NOTE (BACKEND, "Realizing main stage");
|
|
|
|
|
2008-04-25 08:17:01 -04:00
|
|
|
is_offscreen = is_fullscreen = FALSE;
|
|
|
|
g_object_get (stage_sdl->wrapper,
|
|
|
|
"offscreen", &is_offscreen,
|
|
|
|
"fullscreen", &is_fullscreen,
|
|
|
|
NULL);
|
2007-05-02 16:05:29 -04:00
|
|
|
|
|
|
|
if (G_LIKELY (!is_offscreen))
|
|
|
|
{
|
|
|
|
gint flags = SDL_OPENGL;
|
|
|
|
|
2008-04-25 08:17:01 -04:00
|
|
|
if (is_fullscreen)
|
|
|
|
flags |= SDL_FULLSCREEN;
|
2007-05-02 16:05:29 -04:00
|
|
|
|
2008-04-25 08:17:01 -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);
|
2007-05-02 16:05:29 -04:00
|
|
|
|
2008-04-25 08:17:01 -04:00
|
|
|
if (SDL_SetVideoMode (stage_sdl->win_width,
|
|
|
|
stage_sdl->win_height,
|
|
|
|
0, flags) == NULL)
|
2007-05-02 16:05:29 -04:00
|
|
|
{
|
|
|
|
CLUTTER_NOTE (BACKEND, "SDL appears not to handle this mode - %s",
|
|
|
|
SDL_GetError());
|
2008-04-25 08:17:01 -04:00
|
|
|
|
|
|
|
CLUTTER_ACTOR_UNSET_FLAGS (stage_sdl, CLUTTER_ACTOR_REALIZED);
|
|
|
|
CLUTTER_ACTOR_UNSET_FLAGS (stage_sdl->wrapper,
|
|
|
|
CLUTTER_ACTOR_REALIZED);
|
2007-05-02 16:05:29 -04:00
|
|
|
return;
|
|
|
|
}
|
2008-04-25 08:17:01 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
CLUTTER_ACTOR_SET_FLAGS (stage_sdl, CLUTTER_ACTOR_REALIZED);
|
|
|
|
CLUTTER_ACTOR_SET_FLAGS (stage_sdl->wrapper, CLUTTER_ACTOR_REALIZED);
|
|
|
|
clutter_stage_ensure_current (stage_sdl->wrapper);
|
|
|
|
}
|
2007-05-02 16:05:29 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* FIXME */
|
|
|
|
g_warning("SDL Backend does not yet support offscreen rendering\n");
|
2008-04-25 08:17:01 -04:00
|
|
|
|
2007-05-02 16:05:29 -04:00
|
|
|
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-25 08:17:01 -04:00
|
|
|
CLUTTER_NOTE (BACKEND, "SDL stage realized");
|
|
|
|
CLUTTER_SET_PRIVATE_FLAGS (stage_sdl->wrapper, CLUTTER_ACTOR_SYNC_MATRICES);
|
2007-05-02 16:05:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-06-13 19:24:59 -04:00
|
|
|
clutter_stage_sdl_query_coords (ClutterActor *self,
|
2007-05-02 16:05:29 -04:00
|
|
|
ClutterActorBox *box)
|
|
|
|
{
|
|
|
|
ClutterStageSDL *stage_sdl = CLUTTER_STAGE_SDL (self);
|
|
|
|
|
|
|
|
box->x1 = box->y1 = 0;
|
2007-05-22 05:31:40 -04:00
|
|
|
box->x2 = box->x1 + CLUTTER_UNITS_FROM_INT (stage_sdl->win_width);
|
|
|
|
box->y2 = box->y1 + CLUTTER_UNITS_FROM_INT (stage_sdl->win_height);
|
2007-05-02 16:05:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_sdl_request_coords (ClutterActor *self,
|
|
|
|
ClutterActorBox *box)
|
|
|
|
{
|
|
|
|
ClutterStageSDL *stage_sdl = CLUTTER_STAGE_SDL (self);
|
|
|
|
gint new_width, new_height;
|
|
|
|
|
|
|
|
/* FIXME: some how have X configure_notfiys call this ? */
|
2007-05-22 05:31:40 -04:00
|
|
|
new_width = ABS (CLUTTER_UNITS_TO_INT (box->x2 - box->x1));
|
|
|
|
new_height = ABS (CLUTTER_UNITS_TO_INT (box->y2 - box->y1));
|
2007-05-02 16:05:29 -04:00
|
|
|
|
|
|
|
if (new_width != stage_sdl->win_width ||
|
|
|
|
new_height != stage_sdl->win_height)
|
|
|
|
{
|
|
|
|
if (SDL_SetVideoMode(new_width,
|
|
|
|
new_height,
|
|
|
|
0, SDL_OPENGL) == NULL)
|
|
|
|
{
|
|
|
|
box->x2 = box->x1 + stage_sdl->win_width;
|
|
|
|
box->y2 = box->y1 + stage_sdl->win_height;
|
|
|
|
|
|
|
|
/* Failed */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
stage_sdl->win_width = new_width;
|
|
|
|
stage_sdl->win_height = new_height;
|
|
|
|
|
2008-04-25 08:17:01 -04:00
|
|
|
CLUTTER_SET_PRIVATE_FLAGS (self, CLUTTER_ACTOR_SYNC_MATRICES);
|
2007-05-02 16:05:29 -04:00
|
|
|
}
|
2008-04-25 08:17:01 -04:00
|
|
|
|
|
|
|
CLUTTER_ACTOR_CLASS (clutter_stage_sdl_parent_class)->request_coords (self,
|
|
|
|
box);
|
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
|
|
|
|
|
|
|
SDL_SetVideoMode(stage_sdl->win_width,
|
|
|
|
stage_sdl->win_height,
|
|
|
|
0, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-04-25 08:17:01 -04:00
|
|
|
static GdkPixbuf *
|
|
|
|
clutter_stage_sdl_draw_to_pixbuf (ClutterStageWindow *stage_window,
|
|
|
|
GdkPixbuf *dest,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
2007-05-02 16:05:29 -04:00
|
|
|
{
|
2008-04-25 08:17:01 -04:00
|
|
|
g_warning ("Stage of type `%s' do not support "
|
|
|
|
"ClutterStageWindow::draw_to_pixbuf",
|
|
|
|
G_OBJECT_TYPE_NAME (stage_window));
|
2007-06-19 10:10:25 -04:00
|
|
|
return NULL;
|
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)
|
|
|
|
{
|
|
|
|
ClutterStageSDL *stage_sdl = CLUTTER_STAGE_SDL (gobject);
|
|
|
|
|
|
|
|
clutter_actor_unrealize (CLUTTER_ACTOR (stage_sdl));
|
|
|
|
|
|
|
|
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);
|
|
|
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->dispose = clutter_stage_sdl_dispose;
|
|
|
|
|
|
|
|
actor_class->show = clutter_stage_sdl_show;
|
|
|
|
actor_class->hide = clutter_stage_sdl_hide;
|
|
|
|
actor_class->realize = clutter_stage_sdl_realize;
|
|
|
|
actor_class->unrealize = clutter_stage_sdl_unrealize;
|
|
|
|
actor_class->request_coords = clutter_stage_sdl_request_coords;
|
2007-06-13 19:24:59 -04:00
|
|
|
actor_class->query_coords = clutter_stage_sdl_query_coords;
|
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;
|
|
|
|
iface->draw_to_pixbuf = clutter_stage_sdl_draw_to_pixbuf;
|
2007-05-02 16:05:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_sdl_init (ClutterStageSDL *stage)
|
|
|
|
{
|
|
|
|
stage->win_width = 640;
|
|
|
|
stage->win_height = 480;
|
|
|
|
}
|
|
|
|
|