Commit 8d3b79b0 authored by Kiste's avatar Kiste
Browse files

SDL2 port

parent 839af8a1
......@@ -23,8 +23,8 @@
INSTALL ?= install
SDL_CFLAGS ?= `sdl-config --cflags`
SDL_LIBS ?= `sdl-config --libs` -lSDL_ttf
SDL_CFLAGS ?= `sdl2-config --cflags`
SDL_LIBS ?= `sdl2-config --libs` -lSDL2_ttf
ALSA_LIBS ?= -lasound
JACK_LIBS ?= -ljack
......
......@@ -133,8 +133,6 @@
#define LOCK(sf) if (SDL_MUSTLOCK(sf)) SDL_LockSurface(sf)
#define UNLOCK(sf) if (SDL_MUSTLOCK(sf)) SDL_UnlockSurface(sf)
#define UPDATE(sf, rect) SDL_UpdateRect(sf, (rect)->x, (rect)->y, \
(rect)->w, (rect)->h)
/* List of directories to use as search path for fonts. */
......@@ -168,7 +166,7 @@ static unsigned short *spinner_angle, spinner_size;
static int width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT,
meter_scale = DEFAULT_METER_SCALE;
static Uint32 video_flags = SDL_RESIZABLE;
static Uint32 video_flags = SDL_WINDOW_RESIZABLE;
static float scale = DEFAULT_SCALE;
static iconv_t utf;
static pthread_t ph;
......@@ -426,7 +424,7 @@ static int do_draw_text(SDL_Surface *sf, const struct rect *rect,
if (iconv(utf, NULL, NULL, &out, &fill) == -1)
abort();
in = strdupa(buf);
in = strdup(buf);
len = strlen(in);
(void)iconv(utf, &in, &len, &out, &fill);
......@@ -1402,7 +1400,7 @@ static void draw_library(SDL_Surface *surface, const struct rect *rect,
* Return: true if the selector needs to be redrawn, otherwise false
*/
static bool handle_key(SDLKey key, SDLMod mod)
static bool handle_key(SDL_Keycode key, SDL_Keymod mod)
{
struct selector *sel = &selector;
......@@ -1549,7 +1547,7 @@ static SDL_Surface* set_size(int w, int h, struct rect *r)
{
SDL_Surface *surface;
surface = SDL_SetVideoMode(w, h, 32, video_flags);
surface = SDL_CreateRGBSurface(0, w, h, 32, 0, 0, 0, 0);
if (surface == NULL) {
fprintf(stderr, "%s\n", SDL_GetError());
return NULL;
......@@ -1566,7 +1564,7 @@ static void push_event(int t)
{
SDL_Event e;
if (!SDL_PeepEvents(&e, 1, SDL_PEEKEVENT, SDL_EVENTMASK(t))) {
if (!SDL_PeepEvents(&e, 1, SDL_PEEKEVENT, t, t)) {
e.type = t;
if (SDL_PushEvent(&e) == -1)
abort();
......@@ -1608,9 +1606,31 @@ static int interface_main(void)
SDL_Event event;
SDL_TimerID timer;
SDL_Surface *surface;
SDL_Renderer *renderer;
SDL_Texture *texture;
SDL_Window *window;
struct rect rworkspace, rplayers, rlibrary, rstatus, rtmp;
window = SDL_CreateWindow(banner, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, video_flags);
if (window == NULL) {
fprintf(stderr, "%s\n", SDL_GetError());
return -1;
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer == NULL) {
fprintf(stderr, "%s\n", SDL_GetError());
return -1;
}
SDL_RenderSetLogicalSize(renderer, width, height);
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height);
if (texture == NULL) {
fprintf(stderr, "%s\n", SDL_GetError());
return -1;
}
surface = set_size(width, height, &rworkspace);
if (!surface)
return -1;
......@@ -1640,15 +1660,24 @@ static int interface_main(void)
return -1;
break;
case SDL_VIDEORESIZE:
surface = set_size(event.resize.w, event.resize.h, &rworkspace);
if (!surface)
return -1;
library_update = true;
decks_update = true;
status_update = true;
case SDL_WINDOWEVENT:
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
SDL_FreeSurface(surface);
SDL_DestroyTexture(texture);
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, event.window.data1, event.window.data2);
if (texture == NULL) {
fprintf(stderr, "%s\n", SDL_GetError());
return -1;
}
SDL_RenderSetLogicalSize(renderer, event.window.data1, event.window.data2);
surface = set_size(event.window.data1, event.window.data2, &rworkspace);
if (!surface)
return -1;
library_update = true;
decks_update = true;
status_update = true;
}
break;
case EVENT_TICKER:
......@@ -1715,18 +1744,13 @@ static int interface_main(void)
UNLOCK(surface);
if (library_update) {
UPDATE(surface, &rlibrary);
if (library_update || status_update || decks_update) {
SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
library_update = false;
}
if (status_update) {
UPDATE(surface, &rstatus);
status_update = false;
}
if (decks_update) {
UPDATE(surface, &rplayers);
decks_update = false;
}
......@@ -1736,6 +1760,10 @@ static int interface_main(void)
rig_unlock();
SDL_RemoveTimer(timer);
SDL_FreeSurface(surface);
SDL_DestroyTexture(texture);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
return 0;
}
......@@ -1841,7 +1869,7 @@ int interface_start(struct library *lib, const char *geo, bool decor)
}
if (!decor)
video_flags |= SDL_NOFRAME;
video_flags |= SDL_WINDOW_BORDERLESS;
for (n = 0; n < ndeck; n++) {
if (timecoder_monitor_init(&deck[n].timecoder, zoom(SCOPE_SIZE)) == -1)
......@@ -1862,8 +1890,6 @@ int interface_start(struct library *lib, const char *geo, bool decor)
fprintf(stderr, "%s\n", SDL_GetError());
return -1;
}
SDL_WM_SetCaption(banner, NULL);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
/* Initialise the fonts */
......
......@@ -8,6 +8,9 @@
SDL_Surface *surface;
TTF_Font *font;
SDL_Renderer *renderer;
SDL_Texture *texture;
SDL_Window *window;
void draw(void)
{
......@@ -28,7 +31,10 @@ void draw(void)
SDL_BlitSurface(rendered, &source, surface, &dest);
SDL_FreeSurface(rendered);
SDL_UpdateRect(surface, 0, 0, source.w, source.h);
SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
}
int main(int argc, char *argv[])
......@@ -53,7 +59,12 @@ int main(int argc, char *argv[])
#endif
TTF_SetFontKerning(font, 1);
surface = SDL_SetVideoMode(400, 200, 32, 0);
if (SDL_CreateWindowAndRenderer(400, 200, 0, &window, &renderer))
abort();
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 400, 200);
if (texture == NULL)
abort();
surface = SDL_CreateRGBSurface(0, 400, 200, 32, 0, 0, 0, 0);
if (surface == NULL)
abort();
......@@ -72,6 +83,10 @@ int main(int argc, char *argv[])
}
done:
SDL_FreeSurface(surface);
SDL_DestroyTexture(texture);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
TTF_CloseFont(font);
TTF_Quit();
SDL_Quit();
......
Supports Markdown
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