Add window borders and more keys

This commit is contained in:
Kevin Lange 2013-06-12 23:31:46 -07:00
parent 8f65d90228
commit 40fe8c42a1
3 changed files with 103 additions and 37 deletions

View File

@ -50,7 +50,14 @@ void TOARU_PumpEvents(_THIS) {
switch (event->command_type) {
case WE_RESIZED:
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;
@ -89,32 +96,31 @@ void TOARU_PumpEvents(_THIS) {
keysym.sym = SDLK_DOWN;
SDL_PrivateKeyboard(action, &keysym);
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case KEY_ESCAPE:
keysym.sym = SDLK_ESCAPE;
SDL_PrivateKeyboard(action, &keysym);
break;
case KEY_BACKSPACE:
keysym.sym = SDLK_BACKSPACE;
SDL_PrivateKeyboard(action, &keysym);
break;
case '\t':
keysym.sym = SDLK_TAB;
SDL_PrivateKeyboard(action, &keysym);
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case 'a': case 'b': case 'c': case 'd': case 'e':
case 'f': case 'g': case 'h': case 'i': case 'j':
case 'k': case 'l': case 'm': case 'n': case 'o':
case 'p': case 'q': case 'r': case 's': case 't':
case 'u': case 'v': case 'w': case 'x': case 'y':
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);
SDL_PrivateKeyboard(action, &keysym);
break;
@ -129,8 +135,8 @@ void TOARU_PumpEvents(_THIS) {
{
w_mouse_t * mouse = (w_mouse_t *)((uintptr_t)event + sizeof(wins_packet_t));
int i;
signed short x = mouse->new_x;
signed short y = mouse->new_y;
signed short x = mouse->new_x - this->hidden->o_w;
signed short y = mouse->new_y - this->hidden->o_h;
for (i = 0; i < 3; ++i) {
int was = mouse_state & (1 << i);
int is = mouse->buttons & (1 << i);

View File

@ -48,6 +48,7 @@
#include <toaru/window.h>
#include <toaru/graphics.h>
#include <toaru/decorations.h>
#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_FreeHWSurface(_THIS, SDL_Surface *surface);
static void TOARU_SetCaption(_THIS, const char *title, const char *icon);
/* etc. */
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->InitOSKeymap = TOARU_InitOSKeymap;
device->PumpEvents = TOARU_PumpEvents;
device->SetCaption = TOARU_SetCaption;
device->free = TOARU_DeleteDevice;
@ -144,6 +148,7 @@ int TOARU_VideoInit(_THIS, SDL_PixelFormat *vformat)
vformat->BytesPerPixel = 4;
setup_windowing();
init_decorations();
/* We're done! */
return(0);
@ -160,17 +165,46 @@ SDL_Surface *TOARU_SetVideoMode(_THIS, SDL_Surface *current,
if ( this->hidden->window) {
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);
if (this->hidden->bordered) {
this->hidden->buffer = realloc(this->hidden->buffer, sizeof(uint32_t) * width * height);
}
} 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);
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();
gfx_context_t * ctx = init_graphics_window_double_buffer(win);
this->hidden->window = (void *)win;
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");
}
@ -179,7 +213,7 @@ SDL_Surface *TOARU_SetVideoMode(_THIS, SDL_Surface *current,
this->hidden->w = current->w = width;
this->hidden->h = current->h = height;
current->pitch = current->w * (4);
current->pixels = ((gfx_context_t *)this->hidden->ctx)->backbuffer;
current->pixels = this->hidden->buffer;
/* We're done */
return(current);
@ -213,13 +247,28 @@ static void TOARU_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
int y = 0;
int x = 0;
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;
if (this->hidden->bordered) {
gfx_context_t * ctx = (gfx_context_t *)this->hidden->ctx;
if (this->hidden->title) {
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();
}
static void TOARU_SetCaption(_THIS, const char *title, const char *icon) {
if (this->hidden->title) {
free(this->hidden->title);
}
this->hidden->title = strdup(title);
}

View File

@ -37,7 +37,10 @@ struct SDL_PrivateVideoData {
void *buffer;
void *window;
void *ctx;
SDL_Surface surface;
int bordered;
char * title;
int x_w, x_h;
int o_w, o_h;
};
#endif /* _SDL_nullvideo_h */