Add window borders and more keys
This commit is contained in:
parent
8f65d90228
commit
40fe8c42a1
@ -50,7 +50,14 @@ void TOARU_PumpEvents(_THIS) {
|
|||||||
switch (event->command_type) {
|
switch (event->command_type) {
|
||||||
case WE_RESIZED:
|
case WE_RESIZED:
|
||||||
fprintf(stderr, "[SDL] Window resized, need to update buffers!\n");
|
fprintf(stderr, "[SDL] Window resized, need to update buffers!\n");
|
||||||
SDL_PrivateResize(evt->width, evt->height);
|
SDL_PrivateResize(evt->width - this->hidden->x_w, evt->height - this->hidden->x_h);
|
||||||
|
break;
|
||||||
|
case WE_FOCUSCHG:
|
||||||
|
window = wins_get_window(evt->wid);
|
||||||
|
if (window) {
|
||||||
|
window->focused = evt->left;
|
||||||
|
}
|
||||||
|
SDL_PrivateAppActive(0, evt->left);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -89,32 +96,31 @@ void TOARU_PumpEvents(_THIS) {
|
|||||||
keysym.sym = SDLK_DOWN;
|
keysym.sym = SDLK_DOWN;
|
||||||
SDL_PrivateKeyboard(action, &keysym);
|
SDL_PrivateKeyboard(action, &keysym);
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case KEY_ESCAPE:
|
||||||
case 'b':
|
keysym.sym = SDLK_ESCAPE;
|
||||||
case 'c':
|
SDL_PrivateKeyboard(action, &keysym);
|
||||||
case 'd':
|
break;
|
||||||
case 'e':
|
case KEY_BACKSPACE:
|
||||||
case 'f':
|
keysym.sym = SDLK_BACKSPACE;
|
||||||
case 'g':
|
SDL_PrivateKeyboard(action, &keysym);
|
||||||
case 'h':
|
break;
|
||||||
case 'i':
|
case '\t':
|
||||||
case 'j':
|
keysym.sym = SDLK_TAB;
|
||||||
case 'k':
|
SDL_PrivateKeyboard(action, &keysym);
|
||||||
case 'l':
|
break;
|
||||||
case 'm':
|
case '0': case '1': case '2': case '3': case '4':
|
||||||
case 'n':
|
case '5': case '6': case '7': case '8': case '9':
|
||||||
case 'o':
|
case 'a': case 'b': case 'c': case 'd': case 'e':
|
||||||
case 'p':
|
case 'f': case 'g': case 'h': case 'i': case 'j':
|
||||||
case 'q':
|
case 'k': case 'l': case 'm': case 'n': case 'o':
|
||||||
case 'r':
|
case 'p': case 'q': case 'r': case 's': case 't':
|
||||||
case 's':
|
case 'u': case 'v': case 'w': case 'x': case 'y':
|
||||||
case 't':
|
|
||||||
case 'u':
|
|
||||||
case 'v':
|
|
||||||
case 'w':
|
|
||||||
case 'x':
|
|
||||||
case 'y':
|
|
||||||
case 'z':
|
case 'z':
|
||||||
|
case ':': case ';': case '<': case '=': case '>':
|
||||||
|
case '?': case '@': case '[': case ']': case '\\':
|
||||||
|
case '^': case '_': case '`': case '.': case '/':
|
||||||
|
case '*': case '-': case '+': case '#': case '"':
|
||||||
|
case '!': case '&': case '$': case '(': case '\'':
|
||||||
keysym.sym = (kbd->event.keycode - 'a' + SDLK_a);
|
keysym.sym = (kbd->event.keycode - 'a' + SDLK_a);
|
||||||
SDL_PrivateKeyboard(action, &keysym);
|
SDL_PrivateKeyboard(action, &keysym);
|
||||||
break;
|
break;
|
||||||
@ -129,8 +135,8 @@ void TOARU_PumpEvents(_THIS) {
|
|||||||
{
|
{
|
||||||
w_mouse_t * mouse = (w_mouse_t *)((uintptr_t)event + sizeof(wins_packet_t));
|
w_mouse_t * mouse = (w_mouse_t *)((uintptr_t)event + sizeof(wins_packet_t));
|
||||||
int i;
|
int i;
|
||||||
signed short x = mouse->new_x;
|
signed short x = mouse->new_x - this->hidden->o_w;
|
||||||
signed short y = mouse->new_y;
|
signed short y = mouse->new_y - this->hidden->o_h;
|
||||||
for (i = 0; i < 3; ++i) {
|
for (i = 0; i < 3; ++i) {
|
||||||
int was = mouse_state & (1 << i);
|
int was = mouse_state & (1 << i);
|
||||||
int is = mouse->buttons & (1 << i);
|
int is = mouse->buttons & (1 << i);
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
|
|
||||||
#include <toaru/window.h>
|
#include <toaru/window.h>
|
||||||
#include <toaru/graphics.h>
|
#include <toaru/graphics.h>
|
||||||
|
#include <toaru/decorations.h>
|
||||||
|
|
||||||
#define TOARUVID_DRIVER_NAME "toaru"
|
#define TOARUVID_DRIVER_NAME "toaru"
|
||||||
|
|
||||||
@ -64,6 +65,8 @@ static int TOARU_LockHWSurface(_THIS, SDL_Surface *surface);
|
|||||||
static void TOARU_UnlockHWSurface(_THIS, SDL_Surface *surface);
|
static void TOARU_UnlockHWSurface(_THIS, SDL_Surface *surface);
|
||||||
static void TOARU_FreeHWSurface(_THIS, SDL_Surface *surface);
|
static void TOARU_FreeHWSurface(_THIS, SDL_Surface *surface);
|
||||||
|
|
||||||
|
static void TOARU_SetCaption(_THIS, const char *title, const char *icon);
|
||||||
|
|
||||||
/* etc. */
|
/* etc. */
|
||||||
static void TOARU_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
|
static void TOARU_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
|
||||||
|
|
||||||
@ -124,6 +127,7 @@ static SDL_VideoDevice *TOARU_CreateDevice(int devindex)
|
|||||||
device->GetWMInfo = NULL;
|
device->GetWMInfo = NULL;
|
||||||
device->InitOSKeymap = TOARU_InitOSKeymap;
|
device->InitOSKeymap = TOARU_InitOSKeymap;
|
||||||
device->PumpEvents = TOARU_PumpEvents;
|
device->PumpEvents = TOARU_PumpEvents;
|
||||||
|
device->SetCaption = TOARU_SetCaption;
|
||||||
|
|
||||||
device->free = TOARU_DeleteDevice;
|
device->free = TOARU_DeleteDevice;
|
||||||
|
|
||||||
@ -144,6 +148,7 @@ int TOARU_VideoInit(_THIS, SDL_PixelFormat *vformat)
|
|||||||
vformat->BytesPerPixel = 4;
|
vformat->BytesPerPixel = 4;
|
||||||
|
|
||||||
setup_windowing();
|
setup_windowing();
|
||||||
|
init_decorations();
|
||||||
|
|
||||||
/* We're done! */
|
/* We're done! */
|
||||||
return(0);
|
return(0);
|
||||||
@ -160,17 +165,46 @@ SDL_Surface *TOARU_SetVideoMode(_THIS, SDL_Surface *current,
|
|||||||
if ( this->hidden->window) {
|
if ( this->hidden->window) {
|
||||||
fprintf(stderr, "waaat, already have a window! need to resize instead!\n");
|
fprintf(stderr, "waaat, already have a window! need to resize instead!\n");
|
||||||
|
|
||||||
resize_window_buffer_client(this->hidden->window, 0, 0, width, height);
|
resize_window_buffer_client(this->hidden->window, 0, 0, width + this->hidden->x_w, height + this->hidden->x_h);
|
||||||
reinit_graphics_window(this->hidden->ctx, this->hidden->window);
|
reinit_graphics_window(this->hidden->ctx, this->hidden->window);
|
||||||
|
|
||||||
|
if (this->hidden->bordered) {
|
||||||
|
this->hidden->buffer = realloc(this->hidden->buffer, sizeof(uint32_t) * width * height);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
if (flags & SDL_NOFRAME) {
|
||||||
|
fprintf(stderr, "Initializing without borders.\n");
|
||||||
|
this->hidden->bordered = 0;
|
||||||
|
this->hidden->x_h = 0;
|
||||||
|
this->hidden->x_w = 0;
|
||||||
|
this->hidden->o_h = 0;
|
||||||
|
this->hidden->o_w = 0;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Initializing with borders.\n");
|
||||||
|
this->hidden->bordered = 1;
|
||||||
|
this->hidden->x_h = decor_height();
|
||||||
|
this->hidden->x_w = decor_width();
|
||||||
|
this->hidden->o_h = decor_top_height;
|
||||||
|
this->hidden->o_w = decor_left_width;
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Initializing window %dx%d (%d bpp)\n", width, height, bpp);
|
fprintf(stderr, "Initializing window %dx%d (%d bpp)\n", width, height, bpp);
|
||||||
window_t * win = window_create(100, 100, width, height);
|
window_t * win = window_create(100, 100, width + this->hidden->x_w, height + this->hidden->x_h);
|
||||||
win_sane_events();
|
win_sane_events();
|
||||||
|
|
||||||
gfx_context_t * ctx = init_graphics_window_double_buffer(win);
|
gfx_context_t * ctx = init_graphics_window_double_buffer(win);
|
||||||
this->hidden->window = (void *)win;
|
this->hidden->window = (void *)win;
|
||||||
this->hidden->ctx = (void *)ctx;
|
this->hidden->ctx = (void *)ctx;
|
||||||
|
|
||||||
|
if (this->hidden->bordered) {
|
||||||
|
this->hidden->buffer = malloc(sizeof(uint32_t) * width * height);
|
||||||
|
} else {
|
||||||
|
this->hidden->buffer = ((gfx_context_t *)this->hidden->ctx)->backbuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fprintf(stderr, "Window output initialized...\n");
|
fprintf(stderr, "Window output initialized...\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +213,7 @@ SDL_Surface *TOARU_SetVideoMode(_THIS, SDL_Surface *current,
|
|||||||
this->hidden->w = current->w = width;
|
this->hidden->w = current->w = width;
|
||||||
this->hidden->h = current->h = height;
|
this->hidden->h = current->h = height;
|
||||||
current->pitch = current->w * (4);
|
current->pitch = current->w * (4);
|
||||||
current->pixels = ((gfx_context_t *)this->hidden->ctx)->backbuffer;
|
current->pixels = this->hidden->buffer;
|
||||||
|
|
||||||
/* We're done */
|
/* We're done */
|
||||||
return(current);
|
return(current);
|
||||||
@ -213,13 +247,28 @@ static void TOARU_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
|
|||||||
|
|
||||||
int y = 0;
|
int y = 0;
|
||||||
int x = 0;
|
int x = 0;
|
||||||
gfx_context_t * ctx = (gfx_context_t *)this->hidden->ctx;
|
if (this->hidden->bordered) {
|
||||||
for (y = 0; y < ctx->height; ++y) {
|
gfx_context_t * ctx = (gfx_context_t *)this->hidden->ctx;
|
||||||
for (x = 0; x < ctx->width; ++x) {
|
if (this->hidden->title) {
|
||||||
GFX(ctx, x, y) = GFX(ctx,x,y) | 0xFF000000;
|
render_decorations(this->hidden->window, this->hidden->ctx, this->hidden->title);
|
||||||
|
} else {
|
||||||
|
render_decorations(this->hidden->window, this->hidden->ctx, "[SDL App]");
|
||||||
}
|
}
|
||||||
|
flip(this->hidden->ctx);
|
||||||
|
for (y = 0; y < this->hidden->h; ++y) {
|
||||||
|
for (x = 0; x < this->hidden->w; ++x) {
|
||||||
|
GFX(ctx, x + this->hidden->o_w, y + this->hidden->o_h) = ((uint32_t *)this->hidden->buffer)[y * this->hidden->w + x] | 0xFF000000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
gfx_context_t * ctx = (gfx_context_t *)this->hidden->ctx;
|
||||||
|
for (y = 0; y < ctx->height; ++y) {
|
||||||
|
for (x = 0; x < ctx->width; ++x) {
|
||||||
|
GFX(ctx, x, y) = GFX(ctx,x,y) | 0xFF000000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
flip(this->hidden->ctx);
|
||||||
}
|
}
|
||||||
flip(this->hidden->ctx);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,3 +285,11 @@ void TOARU_VideoQuit(_THIS)
|
|||||||
{
|
{
|
||||||
teardown_windowing();
|
teardown_windowing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void TOARU_SetCaption(_THIS, const char *title, const char *icon) {
|
||||||
|
if (this->hidden->title) {
|
||||||
|
free(this->hidden->title);
|
||||||
|
}
|
||||||
|
this->hidden->title = strdup(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,10 @@ struct SDL_PrivateVideoData {
|
|||||||
void *buffer;
|
void *buffer;
|
||||||
void *window;
|
void *window;
|
||||||
void *ctx;
|
void *ctx;
|
||||||
SDL_Surface surface;
|
int bordered;
|
||||||
|
char * title;
|
||||||
|
int x_w, x_h;
|
||||||
|
int o_w, o_h;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _SDL_nullvideo_h */
|
#endif /* _SDL_nullvideo_h */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user