Commit 6557ebfb authored by Benoît Minisini's avatar Benoît Minisini

[GB.SDL2]

* NEW: Start rewriting the SDL component with SDL 2.


git-svn-id: svn://localhost/gambas/trunk@6769 867c0c6c-44f3-4631-809d-bfa615b0a4ec
parent 95637f98
......@@ -13,6 +13,7 @@ SUBDIRS = \
@pcre_dir@ \
@sdl_dir@ \
@sdlsound_dir@ \
@sdl2_dir@ \
@libxml_dir@ \
@xml_dir@ \
@v4l_dir@ \
......
......@@ -24,6 +24,7 @@ GB_CONFIG_SUBDIRS(mime, gb.mime)
GB_CONFIG_SUBDIRS(pcre, gb.pcre)
GB_CONFIG_SUBDIRS(sdl, gb.sdl)
GB_CONFIG_SUBDIRS(sdlsound, gb.sdl.sound)
GB_CONFIG_SUBDIRS(sdl2, gb.sdl2)
GB_CONFIG_SUBDIRS(libxml, gb.libxml)
GB_CONFIG_SUBDIRS(xml, gb.xml)
GB_CONFIG_SUBDIRS(v4l, gb.v4l)
......
Codes/ideas/contributions (in alphabetic order):
Fabien Bodard <gambasfr@wanadoo.fr>
Daniel Campos FernànDez <danielcampos@netcourrier.com>
Laurent Carlier <lordheavy@users.sourceforge.net>
Benoît Minisini <gambas@users.sourceforge.net>
../COPYING
\ No newline at end of file
../INSTALL
\ No newline at end of file
ACLOCAL_AMFLAGS = -I m4 --install
SUBDIRS = @SDL2_DIR@
EXTRA_DIST = reconf spec gambas.h gb*.h
../acinclude.m4
\ No newline at end of file
../component.am
\ No newline at end of file
dnl ---- configure.ac for gb.sdl
m4_include([../version.m4])
AC_INIT(gambas3-gb-sdl2, GB_VERSION, GB_MAIL, [], GB_URL)
AC_CONFIG_MACRO_DIR([m4])
GB_INIT(gb.sdl2)
AC_PROG_LIBTOOL
GB_COMPONENT_SEARCH(
sdl2, SDL2, gb.sdl2, [src],
sdl2 ">= 2.0.2" SDL2_ttf ">= 2.0.12"
)
AC_OUTPUT( \
Makefile \
src/Makefile \
)
GB_PRINT_MESSAGES
../depcomp
\ No newline at end of file
../main/share/gambas.h
\ No newline at end of file
../main/lib/image/gb.image.h
\ No newline at end of file
../main/share/gb_common.h
\ No newline at end of file
../main/share/gb_list.h
\ No newline at end of file
../main/share/gb_list_temp.h
\ No newline at end of file
../m4
\ No newline at end of file
../missing
\ No newline at end of file
../reconf
\ No newline at end of file
COMPONENT = gb.sdl2
include $(top_srcdir)/component.am
gblib_LTLIBRARIES = gb.sdl2.la
gb_sdl2_la_LIBADD = @SDL2_LIB@
gb_sdl2_la_LDFLAGS = -module @LD_FLAGS@ @SDL2_LDFLAGS@
gb_sdl2_la_CXXFLAGS = $(AM_CXXFLAGS) -DDATA_DIR=\"$(DESTDIR)$(gbdatadir)/$(COMPONENT)\"
gb_sdl2_la_CPPFLAGS = @SDL2_INC@
gb_sdl2_la_SOURCES = \
c_window.h c_window.c \
main.h main.c
/***************************************************************************
c_window.c
(c) 2014 Benoît Minisini <gambas@users.sourceforge.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
***************************************************************************/
#define __C_WINDOW_C
#include "c_window.h"
#define THIS ((CWINDOW *)_object)
#define WINDOW THIS->window
DECLARE_EVENT(EVENT_Open);
DECLARE_EVENT(EVENT_Close);
DECLARE_EVENT(EVENT_Show);
DECLARE_EVENT(EVENT_Hide);
DECLARE_EVENT(EVENT_Move);
DECLARE_EVENT(EVENT_Resize);
DECLARE_EVENT(EVENT_Enter);
DECLARE_EVENT(EVENT_Leave);
DECLARE_EVENT(EVENT_GotFocus);
DECLARE_EVENT(EVENT_LostFocus);
CWINDOW *WINDOW_list = NULL;
static void close_window(void *_object)
{
if (!THIS->opened)
return;
if (GB.Raise(THIS, EVENT_Close, 0))
return;
LIST_remove(&WINDOW_list, THIS, &THIS->list);
SDL_HideWindow(WINDOW);
THIS->opened = FALSE;
GB.Unref(POINTER(&_object));
}
void WINDOW_handle_event(SDL_WindowEvent *event)
{
SDL_Window *window;
CWINDOW *_object;
window = SDL_GetWindowFromID(event->windowID);
_object = SDL_GetWindowData(window, "gambas-object");
if (!THIS)
return;
switch(event->event)
{
case SDL_WINDOWEVENT_SHOWN:
GB.Raise(THIS, EVENT_Show, 0);
break;
case SDL_WINDOWEVENT_HIDDEN:
GB.Raise(THIS, EVENT_Hide, 0);
break;
/*case SDL_WINDOWEVENT_EXPOSED:*/
case SDL_WINDOWEVENT_MOVED:
GB.Raise(THIS, EVENT_Move, 0);
break;
case SDL_WINDOWEVENT_RESIZED:
GB.Raise(THIS, EVENT_Resize, 0);
break;
/*case SDL_WINDOWEVENT_MINIMIZED:
SDL_Log("Window %d minimized", event->window.windowID);
break;
case SDL_WINDOWEVENT_MAXIMIZED:
SDL_Log("Window %d maximized", event->window.windowID);
break;
case SDL_WINDOWEVENT_RESTORED:
SDL_Log("Window %d restored", event->window.windowID);
break;*/
case SDL_WINDOWEVENT_ENTER:
GB.Raise(THIS, EVENT_Enter, 0);
break;
case SDL_WINDOWEVENT_LEAVE:
GB.Raise(THIS, EVENT_Leave, 0);
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
GB.Raise(THIS, EVENT_GotFocus, 0);
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
GB.Raise(THIS, EVENT_LostFocus, 0);
break;
case SDL_WINDOWEVENT_CLOSE:
close_window(THIS);
break;
}
}
//-------------------------------------------------------------------------
BEGIN_METHOD(Window_new, GB_BOOLEAN opengl)
THIS->opengl = VARGOPT(opengl, FALSE);
if (SDL_CreateWindowAndRenderer(0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_HIDDEN, &THIS->window, &THIS->renderer))
{
RAISE_ERROR("Unable to create window");
return;
}
SDL_SetWindowData(THIS->window, "gambas-object", THIS);
END_METHOD
BEGIN_METHOD_VOID(Window_free)
SDL_DestroyRenderer(THIS->renderer);
SDL_DestroyWindow(WINDOW);
END_METHOD
BEGIN_METHOD_VOID(Window_Show)
if (!THIS->opened)
{
if (GB.Raise(THIS, EVENT_Open, 0))
return;
THIS->opened = TRUE;
GB.Ref(THIS);
LIST_insert(&WINDOW_list, THIS, &THIS->list);
}
SDL_ShowWindow(WINDOW);
END_METHOD
BEGIN_METHOD_VOID(Window_Hide)
SDL_HideWindow(WINDOW);
END_METHOD
BEGIN_METHOD_VOID(Window_Close)
close_window(THIS);
END_METHOD
BEGIN_PROPERTY(Window_Visible)
if (READ_PROPERTY)
GB.ReturnBoolean(SDL_GetWindowFlags(WINDOW) & SDL_WINDOW_SHOWN);
else
{
if (VPROP(GB_BOOLEAN))
SDL_ShowWindow(WINDOW);
else
SDL_HideWindow(WINDOW);
}
END_PROPERTY
void set_geometry(void *_object, int x, int y, int w, int h)
{
if (x > 0 && y > 0)
SDL_SetWindowPosition(WINDOW, x, y);
if (w >= 0 && h >= 0)
{
SDL_SetWindowFullscreen(WINDOW, (w > 0 && h > 0) ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP);
SDL_SetWindowSize(WINDOW, w, h);
}
}
BEGIN_METHOD(Window_Move, GB_INTEGER x; GB_INTEGER y; GB_INTEGER width; GB_INTEGER height)
set_geometry(THIS, VARG(x), VARG(y), VARGOPT(width, -1), VARGOPT(height, -1));
END_METHOD
BEGIN_METHOD(Window_Resize, GB_INTEGER width; GB_INTEGER height)
set_geometry(THIS, -1, -1, VARG(width), VARG(height));
END_METHOD
//-------------------------------------------------------------------------
GB_DESC WindowDesc[] =
{
GB_DECLARE("Window", sizeof(CWINDOW)),
GB_METHOD("_new", NULL, Window_new, "[(OpenGL)b]"),
GB_METHOD("_free", NULL, Window_free, NULL),
GB_METHOD("Show", NULL, Window_Show, NULL),
GB_METHOD("Hide", NULL, Window_Hide, NULL),
GB_METHOD("Close", NULL, Window_Close, NULL),
GB_METHOD("Move", NULL, Window_Move, "(X)i(Y)i[(Width)i(Height)i]"),
GB_METHOD("Resize", NULL, Window_Resize, "(Width)i(Height)i"),
GB_PROPERTY("Visible", "b", Window_Visible),
GB_EVENT("Open", NULL, NULL, &EVENT_Open),
GB_EVENT("Close", NULL, NULL, &EVENT_Close),
GB_EVENT("Show", NULL, NULL, &EVENT_Show),
GB_EVENT("Hide", NULL, NULL, &EVENT_Hide),
GB_EVENT("Move", NULL, NULL, &EVENT_Move),
GB_EVENT("Resize", NULL, NULL, &EVENT_Resize),
GB_EVENT("Enter", NULL, NULL, &EVENT_Enter),
GB_EVENT("Leave", NULL, NULL, &EVENT_Leave),
GB_EVENT("GotFocus", NULL, NULL, &EVENT_GotFocus),
GB_EVENT("LostFocus", NULL, NULL, &EVENT_LostFocus),
/* GB_METHOD("_new", NULL, CWINDOW_new, "[(OpenGL)b]"),
GB_METHOD("_free", NULL, CWINDOW_free, NULL),
GB_METHOD("Show", NULL, CWINDOW_show, NULL),
GB_METHOD("Close", NULL, CWINDOW_close, NULL),
GB_METHOD("Clear", NULL, CWINDOW_clear, NULL),
GB_METHOD("Fill", NULL, CWINDOW_fill, "(Color)i"),
GB_METHOD("Refresh", NULL, CWINDOW_refresh, NULL),
GB_METHOD("Update", NULL, CWINDOW_refresh, NULL),
GB_PROPERTY("Caption", "s", CWINDOW_text),
// GB_PROPERTY("Cursor", "Cursor;", CWINDOW_cursor),
GB_PROPERTY("Framerate", "f", CWINDOW_framerate),
GB_PROPERTY("FullScreen", "b", CWINDOW_fullscreen),
GB_PROPERTY("Height", "i", CWINDOW_height),
GB_PROPERTY("Mouse", "i", CWINDOW_mouse),
GB_PROPERTY("Text", "s", CWINDOW_text),
GB_PROPERTY("Title", "s", CWINDOW_text),
GB_PROPERTY("Tracking", "b", CWINDOW_tracking),
GB_PROPERTY("Resizable", "b", CWINDOW_resizable),
GB_PROPERTY("Width", "i", CWINDOW_width),
GB_PROPERTY_READ("Handle", "i", CWINDOW_id),
GB_PROPERTY_READ("Id", "i", CWINDOW_id),
GB_PROPERTY_READ("Shown", "b", CWINDOW_shown),
GB_PROPERTY("Grabbed", "b", Window_Grabbed),
GB_METHOD("Screenshot", "Image", Window_Screenshot, "[(X)i(Y)i(Width)i(Height)i]"),
GB_EVENT("Close", "b", NULL, &EVENT_Close),
GB_EVENT("Resize", NULL, NULL, &EVENT_Resize),
GB_EVENT("Activate", NULL, NULL, &EVENT_Activate),
GB_EVENT("Deactivate", NULL, NULL, &EVENT_Deactivate),
GB_EVENT("Enter", NULL, NULL, &EVENT_Enter),
GB_EVENT("JoyAxisMove", NULL, NULL, &EVENT_JoyAxisMotion),
GB_EVENT("JoyBallMove", NULL, NULL, &EVENT_JoyBallMotion),
GB_EVENT("JoyButtonPress", NULL, NULL, &EVENT_JoyButtonPressed),
GB_EVENT("JoyButtonRelease", NULL, NULL, &EVENT_JoyButtonReleased),
GB_EVENT("JoyHatMove", NULL, NULL, &EVENT_JoyHatMotion),
GB_EVENT("Leave", NULL, NULL, &EVENT_Leave),
GB_EVENT("Draw", "b", NULL, &EVENT_Refresh),
GB_EVENT("KeyPress", NULL, NULL, &EVENT_KeyPressed),
GB_EVENT("KeyRelease", NULL, NULL, &EVENT_KeyReleased),
GB_EVENT("MouseMove", NULL, NULL, &EVENT_MouseMove),
GB_EVENT("MouseDown", NULL, NULL, &EVENT_MouseDown),
GB_EVENT("MouseUp", NULL, NULL, &EVENT_MouseUp),
GB_EVENT("Open", NULL, NULL, &EVENT_Open),*/
GB_END_DECLARE
};
/***************************************************************************
c_window.h
(c) 2014 Benoît Minisini <gambas@users.sourceforge.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
***************************************************************************/
#ifndef __C_WINDOW_H
#define __C_WINDOW_H
#include "main.h"
typedef
struct CWINDOW {
GB_BASE ob;
LIST list;
SDL_Window *window;
SDL_Renderer *renderer;
bool opengl;
bool opened;
}
CWINDOW;
#ifndef __C_WINDOW_C
extern GB_DESC WindowDesc[];
extern CWINDOW *WINDOW_list;
void WINDOW_handle_event(SDL_WindowEvent *event);
#endif
#endif /* __C_WINDOW_H */
[Component]
Key=gb.sdl2
Implements=EventLoop,OpenGLViewer
Requires=gb.image,gb.image.io
State=1
/***************************************************************************
main.c
(c) 2014 Benoît Minisini <gambas@users.sourceforge.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
***************************************************************************/
#define __MAIN_C
#include "gambas.h"
#include "main.h"
#include "c_window.h"
#include "gb_list_temp.h"
GB_INTERFACE GB EXPORT;
IMAGE_INTERFACE IMAGE EXPORT;
static void event_loop()
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
break;
case SDL_WINDOWEVENT:
WINDOW_handle_event(&event.window);
break;
}
}
}
static void my_main(int *argc, char **argv)
{
}
static int my_loop()
{
while (WINDOW_list != NULL)
event_loop();
return 1;
}
static void my_wait(int duration)
{
event_loop();
}
GB_DESC *GB_CLASSES[] EXPORT =
{
WindowDesc,
NULL
};
int EXPORT GB_INIT(void)
{
GB.GetInterface("gb.image", IMAGE_INTERFACE_VERSION, &IMAGE);
IMAGE.SetDefaultFormat(GB_IMAGE_BGRA);
GB.Hook(GB_HOOK_MAIN, (void *)my_main);
GB.Hook(GB_HOOK_LOOP, (void *)my_loop);
GB.Hook(GB_HOOK_WAIT, (void *)my_wait);
/*CLASS_Window = GB.FindClass("Window");
CLASS_Image = GB.FindClass("Image");
CLASS_Font = GB.FindClass("Font");*/
if (SDL_Init(SDL_INIT_EVERYTHING))
{
fprintf(stderr, "gb.sdl2: error: unable to initialize the library: %s\n", SDL_GetError());
abort();
}
return -1;
}
void EXPORT GB_EXIT()
{
SDL_Quit();
}
void EXPORT GB_SIGNAL(int signal, void *param)
{
//static bool wasFullscreen = false;
//if (!SDLcore::GetWindow())
// return;
if ((signal == GB_SIGNAL_DEBUG_BREAK) || (signal == GB_SIGNAL_DEBUG_CONTINUE))
{
/*if (SDLcore::GetWindow()->IsFullScreen())
{
wasFullscreen = true;
SDLcore::GetWindow()->SetFullScreen(false);
}*/
}
if (signal == GB_SIGNAL_DEBUG_CONTINUE)
{
/*if (wasFullscreen)
SDLcore::GetWindow()->SetFullScreen(true);*/
}
}
/***************************************************************************
main.h
(c) 2014 Benoît Minisini <gambas@users.sourceforge.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
***************************************************************************/
#ifndef __MAIN_H
#define __MAIN_H
#include "gambas.h"
#include "gb_common.h"
#include "gb_list.h"
#include "gb.image.h"
#include "SDL.h"
#ifndef __MAIN_C
extern GB_INTERFACE GB;
extern IMAGE_INTERFACE IMAGE;
#endif
#define RAISE_ERROR(_msg) GB.Error(_msg ": &1", SDL_GetError());
#endif /* __MAIN_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment