Fix SDL frontend input

svn path=/trunk/netsurf/; revision=6446
This commit is contained in:
Vincent Sanders 2009-02-11 20:55:50 +00:00
parent 7875677123
commit 5060882795
9 changed files with 114 additions and 11 deletions

View File

@ -34,6 +34,7 @@
#include "framebuffer/fb_plotters.h"
#include "framebuffer/fb_bitmap.h"
#include "framebuffer/fb_cursor.h"
#include "framebuffer/fb_frontend.h"
struct fb_cursor_s {
int x;
@ -125,6 +126,7 @@ static void fb_cursor_clear(framebuffer_t *fb)
uint8_t *pvid;
int yloop;
int height = fb->cursor->height;
bbox_t cursorbox;
if ((fb->height - fb->cursor->y) < height)
height = fb->height - fb->cursor->y ;
@ -152,15 +154,24 @@ static void fb_cursor_clear(framebuffer_t *fb)
pvid += fb->linelen;
}
/* callback to the os specific routine in case it needs to do something
* explicit to redraw
*/
cursorbox.x0 = fb->cursor->x;
cursorbox.y0 = fb->cursor->y;
cursorbox.x1 = fb->cursor->x + fb->cursor->width;
cursorbox.y1 = fb->cursor->y + fb->cursor->height;
fb_os_redraw(&cursorbox);
}
void
fb_cursor_move(framebuffer_t *fb, int x, int y)
fb_cursor_move_abs(framebuffer_t *fb, int x, int y)
{
fb_cursor_clear(fb);
fb->cursor->x += x;
fb->cursor->y += y;
fb->cursor->x = x;
fb->cursor->y = y;
if (fb->cursor->x < 0)
fb->cursor->x = 0;
if (fb->cursor->y < 0)
@ -172,14 +183,25 @@ fb_cursor_move(framebuffer_t *fb, int x, int y)
}
void
fb_cursor_move(framebuffer_t *fb, int x, int y)
{
fb_cursor_move_abs(fb, fb->cursor->x + x, fb->cursor->y + y);
}
void
fb_cursor_plot(framebuffer_t *fb)
{
bbox_t saved_plot_ctx;
bbox_t cursorbox;
/* if cursor is not currently plotted give up early */
if (fb->cursor->plotted)
return;
/* enlarge the clipping rectangle to the whole screen for plotting the
* cursor
*/
saved_plot_ctx = fb_plot_ctx;
fb_plot_ctx.x0 = 0;
@ -187,13 +209,26 @@ fb_cursor_plot(framebuffer_t *fb)
fb_plot_ctx.x1 = fb->width;
fb_plot_ctx.y1 = fb->height;
/* save under the cursor */
fb_cursor_save(fb);
/* plot the cursor image */
plot.bitmap(fb->cursor->x, fb->cursor->y,
fb->cursor->width, fb->cursor->height,
fb->cursor->bitmap, 0, NULL);
/* callback to the os specific routine in case it needs to do something
* explicit to redraw
*/
cursorbox.x0 = fb->cursor->x;
cursorbox.y0 = fb->cursor->y;
cursorbox.x1 = fb->cursor->x + fb->cursor->width;
cursorbox.y1 = fb->cursor->y + fb->cursor->height;
fb_os_redraw(&cursorbox);
fb->cursor->plotted = true;
/* restore clipping rectangle */
fb_plot_ctx = saved_plot_ctx;
}

View File

@ -21,6 +21,8 @@
void fb_cursor_move(struct framebuffer_s *fb, int x, int y);
void fb_cursor_move_abs(struct framebuffer_s *fb, int x, int y);
void fb_cursor_plot(struct framebuffer_s *fb);
fb_cursor_t *fb_cursor_init(struct framebuffer_s *fb);

View File

@ -23,6 +23,6 @@ extern framebuffer_t *fb_os_init(int argc, char** argv);
extern void fb_os_quit(framebuffer_t *fb);
extern void fb_os_input(struct gui_window *g);
extern void fb_os_option_override(void);
extern void fb_os_redraw(struct gui_window *g, struct bbox_s *box);
extern void fb_os_redraw(struct bbox_s *box);
#endif /* NETSURF_FB_FRONTEND_H */

View File

@ -134,6 +134,12 @@ fb_os_option_override(void)
option_max_fetchers = option_max_fetchers_per_host = 1;
}
/* called by generic code to inform os code of screen update */
void
fb_os_redraw(struct bbox_s *box)
{
}
/*
* Local Variables:
* c-basic-offset:8

View File

@ -64,13 +64,18 @@ framebuffer_t *fb_os_init(int argc, char** argv)
void fb_os_quit(framebuffer_t *fb)
{
free(fb->ptr);
}
void fb_os_input(struct gui_window *g)
{
}
/* called by generic code to inform os code of screen update */
void
fb_os_redraw(struct bbox_s *box)
{
}
/*
* Local Variables:
* c-basic-offset:8

View File

@ -672,6 +672,11 @@ fb_os_option_override(void)
{
}
/* called by generic code to inform os code of screen update */
void
fb_os_redraw(struct bbox_s *box)
{
}
/*
* Local Variables:

View File

@ -34,6 +34,7 @@
#include "framebuffer/fb_gui.h"
#include "framebuffer/fb_plotters.h"
#include "framebuffer/fb_frontend.h"
#include "framebuffer/fb_cursor.h"
#include "utils/log.h"
@ -74,6 +75,8 @@ framebuffer_t *fb_os_init(int argc, char** argv)
newfb->ptr = sdl_screen->pixels;
newfb->linelen = sdl_screen->pitch;
SDL_ShowCursor(SDL_DISABLE);
return newfb;
}
@ -89,10 +92,40 @@ void fb_os_input(struct gui_window *g)
switch (event.type) {
case SDL_KEYDOWN:
printf("The %s key was pressed!\n",
SDL_GetKeyName(event.key.keysym.sym));
switch (event.key.keysym.sym) {
case SDLK_j:
fb_window_scroll(g, 0, 100);
break;
case SDLK_k:
fb_window_scroll(g, 0, -100);
break;
case SDLK_q:
browser_window_destroy(g->bw);
break;
default:
printf("The %s key was pressed!\n",
SDL_GetKeyName(event.key.keysym.sym));
break;
}
break;
case SDL_MOUSEMOTION:
fb_cursor_move_abs(framebuffer,
event.motion.x,
event.motion.y);
break;
case SDL_MOUSEBUTTONDOWN:
fb_cursor_click(framebuffer, g, BROWSER_MOUSE_CLICK_1);
/* printf("Mouse button %d pressed at (%d,%d)\n",
event.button.button, event.button.x, event.button.y);*/
break;
case SDL_QUIT:
browser_window_destroy(g->bw);
}
@ -104,10 +137,13 @@ fb_os_option_override(void)
{
}
/* called by generic code to inform os code of screen update */
void
fb_os_redraw(struct gui_window *g, struct bbox_s *box)
fb_os_redraw(struct bbox_s *box)
{
SDL_UpdateRect(sdl_screen, box->x0, box->y0, box->x1, box->y1);
SDL_UpdateRect(sdl_screen,
box->x0, box->y0,
box->x1 - box->x0, box->y1 - box->y0);
}
/*

View File

@ -126,7 +126,7 @@ static void fb_redraw(struct gui_window *g)
g->redraw_box.x0, g->redraw_box.y0, g->redraw_box.x1, g->redraw_box.y1,
g->bw->scale, 0xFFFFFF);
fb_os_redraw(g, &g->redraw_box);
fb_os_redraw(&g->redraw_box);
g->redraw_required = false;
g->redraw_box.y0 = g->redraw_box.x0 = INT_MAX;

View File

@ -29,6 +29,7 @@
#include "framebuffer/fb_plotters.h"
#include "framebuffer/fb_bitmap.h"
#include "framebuffer/fb_font.h"
#include "framebuffer/fb_frontend.h"
/* Currently selected ploting routines. */
struct plotter_table plot;
@ -277,7 +278,6 @@ bool fb_plotters_bitmap_tile(int x, int y,
bool fb_plotters_move_block(int srcx, int srcy, int width, int height, int dstx, int dsty)
{
LOG(("from (%d,%d) w %d h %d to (%d,%d)",srcx,srcy,width,height,dstx,dsty));
uint8_t *srcptr = (framebuffer->ptr +
(srcy * framebuffer->linelen) +
(srcx));
@ -286,7 +286,21 @@ bool fb_plotters_move_block(int srcx, int srcy, int width, int height, int dstx,
(dsty * framebuffer->linelen) +
(dstx));
bbox_t redrawbox;
LOG(("from (%d,%d) w %d h %d to (%d,%d)",srcx,srcy,width,height,dstx,dsty));
memmove(dstptr, srcptr, (width * height * framebuffer->bpp) / 8);
/* callback to the os specific routine in case it needs to do something
* explicit to redraw
*/
redrawbox.x0 = dstx;
redrawbox.y0 = dsty;
redrawbox.x1 = dstx + width;
redrawbox.y1 = dsty + height;
fb_os_redraw(&redrawbox);
return true;
}