[GB.SDL2]
* NEW: Image class. * NEW: Can load images now, thanks to SDL_image. * NEW: Image drawing, with optional opacity and rotation. git-svn-id: svn://localhost/gambas/trunk@6771 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
7f06ab1316
commit
a8e23e8c23
@ -9,6 +9,7 @@ gb_sdl2_la_CXXFLAGS = $(AM_CXXFLAGS) -DDATA_DIR=\"$(DESTDIR)$(gbdatadir)/$(COMPO
|
||||
gb_sdl2_la_CPPFLAGS = @SDL2_INC@
|
||||
|
||||
gb_sdl2_la_SOURCES = \
|
||||
c_image.h c_image.c \
|
||||
c_window.h c_window.c \
|
||||
c_draw.h c_draw.c \
|
||||
main.h main.c
|
||||
|
@ -24,6 +24,7 @@
|
||||
#define __C_DRAW_C
|
||||
|
||||
#include "c_window.h"
|
||||
#include "c_image.h"
|
||||
#include "c_draw.h"
|
||||
|
||||
#define DRAW_STACK_MAX 8
|
||||
@ -275,6 +276,44 @@ BEGIN_METHOD(Draw_FillRects, GB_OBJECT rects; GB_INTEGER col)
|
||||
|
||||
END_METHOD
|
||||
|
||||
BEGIN_METHOD(Draw_Image, GB_OBJECT image; GB_INTEGER x; GB_INTEGER y; GB_INTEGER w; GB_INTEGER h; GB_OBJECT src; GB_FLOAT opacity; GB_FLOAT angle)
|
||||
|
||||
CIMAGE *image;
|
||||
SDL_Texture *texture;
|
||||
GEOM_RECT *src;
|
||||
SDL_Rect *rect;
|
||||
SDL_Rect dest;
|
||||
|
||||
CHECK_DEVICE();
|
||||
|
||||
image = VARG(image);
|
||||
if (GB.CheckObject(image))
|
||||
return;
|
||||
|
||||
texture = IMAGE_get_texture(image, (CWINDOW *)THIS->device);
|
||||
|
||||
dest.x = VARG(x);
|
||||
dest.y = VARG(y);
|
||||
dest.w = VARGOPT(w, image->img.width);
|
||||
dest.h = VARGOPT(h, image->img.height);
|
||||
|
||||
src = VARGOPT(src, NULL);
|
||||
if (src)
|
||||
rect = (SDL_Rect *)&src->x;
|
||||
else
|
||||
rect = NULL;
|
||||
|
||||
if (MISSING(opacity) && MISSING(angle))
|
||||
SDL_RenderCopy(RENDERER, texture, rect, &dest);
|
||||
else
|
||||
{
|
||||
SDL_SetTextureAlphaMod(texture, 255 - VARGOPT(opacity, 1.0) * 255);
|
||||
SDL_RenderCopyEx(RENDERER, texture, rect, &dest, VARGOPT(angle, 0.0), NULL, SDL_FLIP_NONE);
|
||||
SDL_SetTextureAlphaMod(texture, 255);
|
||||
}
|
||||
|
||||
END_METHOD
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
@ -296,6 +335,8 @@ GB_DESC DrawDesc[] =
|
||||
GB_STATIC_METHOD("Point", NULL, Draw_Point, "(X)i(Y)i(Color)i"),
|
||||
GB_STATIC_METHOD("Points", NULL, Draw_Points, "(Points)Integer[];(Color)i"),
|
||||
|
||||
GB_STATIC_METHOD("Image", NULL, Draw_Image, "(Image)Image;(X)i(Y)i[(Width)i(Height)i(Source)Rect;(Opacity)f(Angle)f"),
|
||||
|
||||
GB_STATIC_PROPERTY("Background", "i", Draw_Background),
|
||||
|
||||
GB_END_DECLARE
|
||||
|
@ -42,6 +42,7 @@ DECLARE_EVENT(EVENT_LostFocus);
|
||||
DECLARE_EVENT(EVENT_Draw);
|
||||
|
||||
CWINDOW *WINDOW_list = NULL;
|
||||
static int _id = 0;
|
||||
|
||||
static void update_geometry(void *_object)
|
||||
{
|
||||
@ -221,6 +222,9 @@ void WINDOW_update(void)
|
||||
|
||||
BEGIN_METHOD(Window_new, GB_BOOLEAN opengl)
|
||||
|
||||
_id++;
|
||||
THIS->id = _id;
|
||||
|
||||
THIS->opengl = VARGOPT(opengl, FALSE);
|
||||
THIS->fullscreen = FALSE;
|
||||
THIS->width = 640;
|
||||
|
@ -32,6 +32,7 @@ typedef
|
||||
LIST list;
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
int id;
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
#include "gambas.h"
|
||||
#include "main.h"
|
||||
#include "c_image.h"
|
||||
#include "c_draw.h"
|
||||
#include "c_window.h"
|
||||
|
||||
@ -34,8 +35,10 @@
|
||||
|
||||
GB_INTERFACE GB EXPORT;
|
||||
IMAGE_INTERFACE IMAGE EXPORT;
|
||||
GEOM_INTERFACE GEOM EXPORT;
|
||||
|
||||
GB_CLASS CLASS_Window;
|
||||
GB_CLASS CLASS_Image;
|
||||
|
||||
static void event_loop()
|
||||
{
|
||||
@ -57,6 +60,7 @@ static void event_loop()
|
||||
static void my_main(int *argc, char **argv)
|
||||
{
|
||||
CLASS_Window = GB.FindClass("Window");
|
||||
CLASS_Image = GB.FindClass("Image");
|
||||
}
|
||||
|
||||
static int my_loop()
|
||||
@ -77,6 +81,7 @@ static void my_wait(int duration)
|
||||
|
||||
GB_DESC *GB_CLASSES[] EXPORT =
|
||||
{
|
||||
ImageDesc,
|
||||
DrawDesc,
|
||||
WindowDesc,
|
||||
NULL
|
||||
@ -84,7 +89,10 @@ GB_DESC *GB_CLASSES[] EXPORT =
|
||||
|
||||
int EXPORT GB_INIT(void)
|
||||
{
|
||||
GB.GetInterface("gb.image", IMAGE_INTERFACE_VERSION, &IMAGE);
|
||||
GB.Component.Load("gb.geom");
|
||||
GB.GetInterface("gb.geom", GEOM_INTERFACE_VERSION, &GEOM);
|
||||
GB.Component.Load("gb.image");
|
||||
GB.GetInterface("gb.image", IMAGE_INTERFACE_VERSION, &IMAGE);
|
||||
IMAGE.SetDefaultFormat(GB_IMAGE_BGRA);
|
||||
|
||||
GB.Hook(GB_HOOK_MAIN, (void *)my_main);
|
||||
@ -100,12 +108,15 @@ int EXPORT GB_INIT(void)
|
||||
fprintf(stderr, "gb.sdl2: error: unable to initialize the library: %s\n", SDL_GetError());
|
||||
abort();
|
||||
}
|
||||
|
||||
IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void EXPORT GB_EXIT()
|
||||
{
|
||||
IMG_Quit();
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
|
@ -27,15 +27,20 @@
|
||||
#include "gambas.h"
|
||||
#include "gb_common.h"
|
||||
#include "gb_list.h"
|
||||
#include "gb.geom.h"
|
||||
#include "gb.image.h"
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_image.h"
|
||||
#include "SDL_opengl.h"
|
||||
|
||||
#ifndef __MAIN_C
|
||||
extern GB_INTERFACE GB;
|
||||
extern IMAGE_INTERFACE IMAGE;
|
||||
extern GEOM_INTERFACE GEOM;
|
||||
|
||||
extern GB_CLASS CLASS_Window;
|
||||
extern GB_CLASS CLASS_Image;
|
||||
#endif
|
||||
|
||||
#define RAISE_ERROR(_msg) GB.Error(_msg ": &1", SDL_GetError());
|
||||
|
Loading…
x
Reference in New Issue
Block a user