diff options
Diffstat (limited to 'engines/sci/gfx/operations.cpp')
-rw-r--r-- | engines/sci/gfx/operations.cpp | 725 |
1 files changed, 342 insertions, 383 deletions
diff --git a/engines/sci/gfx/operations.cpp b/engines/sci/gfx/operations.cpp index 44d58f4a75..13e4cd6008 100644 --- a/engines/sci/gfx/operations.cpp +++ b/engines/sci/gfx/operations.cpp @@ -33,7 +33,7 @@ #define PRECISE_PRIORITY_MAP /* Duplicate all operations on the local priority map as appropriate */ #undef GFXW_DEBUG_DIRTY /* Enable to debug stuff relevant for dirty rects - ** in widget management */ +** in widget management */ #ifdef GFXW_DEBUG_DIRTY # define DDIRTY fprintf(stderr, "%s:%5d| ", __FILE__, __LINE__); fprintf @@ -43,15 +43,15 @@ /* Default color maps */ #define DEFAULT_COLORS_NR 16 -gfx_pixmap_color_t default_colors[DEFAULT_COLORS_NR] = - {{GFX_COLOR_SYSTEM, 0x00, 0x00, 0x00}, {GFX_COLOR_SYSTEM, 0x00, 0x00, 0xaa}, - {GFX_COLOR_SYSTEM, 0x00, 0xaa, 0x00}, {GFX_COLOR_SYSTEM, 0x00, 0xaa, 0xaa}, - {GFX_COLOR_SYSTEM, 0xaa, 0x00, 0x00}, {GFX_COLOR_SYSTEM, 0xaa, 0x00, 0xaa}, - {GFX_COLOR_SYSTEM, 0xaa, 0x55, 0x00}, {GFX_COLOR_SYSTEM, 0xaa, 0xaa, 0xaa}, - {GFX_COLOR_SYSTEM, 0x55, 0x55, 0x55}, {GFX_COLOR_SYSTEM, 0x55, 0x55, 0xff}, - {GFX_COLOR_SYSTEM, 0x55, 0xff, 0x55}, {GFX_COLOR_SYSTEM, 0x55, 0xff, 0xff}, - {GFX_COLOR_SYSTEM, 0xff, 0x55, 0x55}, {GFX_COLOR_SYSTEM, 0xff, 0x55, 0xff}, - {GFX_COLOR_SYSTEM, 0xff, 0xff, 0x55}, {GFX_COLOR_SYSTEM, 0xff, 0xff, 0xff}}; /* "Normal" EGA */ +gfx_pixmap_color_t default_colors[DEFAULT_COLORS_NR] = {{GFX_COLOR_SYSTEM, 0x00, 0x00, 0x00}, {GFX_COLOR_SYSTEM, 0x00, 0x00, 0xaa}, + {GFX_COLOR_SYSTEM, 0x00, 0xaa, 0x00}, {GFX_COLOR_SYSTEM, 0x00, 0xaa, 0xaa}, + {GFX_COLOR_SYSTEM, 0xaa, 0x00, 0x00}, {GFX_COLOR_SYSTEM, 0xaa, 0x00, 0xaa}, + {GFX_COLOR_SYSTEM, 0xaa, 0x55, 0x00}, {GFX_COLOR_SYSTEM, 0xaa, 0xaa, 0xaa}, + {GFX_COLOR_SYSTEM, 0x55, 0x55, 0x55}, {GFX_COLOR_SYSTEM, 0x55, 0x55, 0xff}, + {GFX_COLOR_SYSTEM, 0x55, 0xff, 0x55}, {GFX_COLOR_SYSTEM, 0x55, 0xff, 0xff}, + {GFX_COLOR_SYSTEM, 0xff, 0x55, 0x55}, {GFX_COLOR_SYSTEM, 0xff, 0x55, 0xff}, + {GFX_COLOR_SYSTEM, 0xff, 0xff, 0x55}, {GFX_COLOR_SYSTEM, 0xff, 0xff, 0xff} +}; /* "Normal" EGA */ #define POINTER_VISIBLE_BUT_CLIPPED 2 @@ -78,8 +78,7 @@ if (!state->driver) { \ /* Internal operations */ static void -_gfxop_scale_rect(rect_t *rect, gfx_mode_t *mode) -{ +_gfxop_scale_rect(rect_t *rect, gfx_mode_t *mode) { int xfact = mode->xfact; int yfact = mode->yfact; @@ -90,8 +89,7 @@ _gfxop_scale_rect(rect_t *rect, gfx_mode_t *mode) } static void -_gfxop_scale_point(point_t *point, gfx_mode_t *mode) -{ +_gfxop_scale_point(point_t *point, gfx_mode_t *mode) { int xfact = mode->xfact; int yfact = mode->yfact; @@ -100,8 +98,7 @@ _gfxop_scale_point(point_t *point, gfx_mode_t *mode) } static void -_gfxop_alloc_colors(gfx_state_t *state, gfx_pixmap_color_t *colors, int colors_nr) -{ +_gfxop_alloc_colors(gfx_state_t *state, gfx_pixmap_color_t *colors, int colors_nr) { int i; if (!PALETTE_MODE) @@ -114,8 +111,7 @@ _gfxop_alloc_colors(gfx_state_t *state, gfx_pixmap_color_t *colors, int colors_n #if 0 // Unreferenced - removed static void -_gfxop_free_colors(gfx_state_t *state, gfx_pixmap_color_t *colors, int colors_nr) -{ +_gfxop_free_colors(gfx_state_t *state, gfx_pixmap_color_t *colors, int colors_nr) { int i; if (!PALETTE_MODE) @@ -130,8 +126,8 @@ int _gfxop_clip(rect_t *rect, rect_t clipzone) /* Returns 1 if nothing is left */ { #if 0 - printf ("Clipping (%d, %d) size (%d, %d) by (%d,%d)(%d,%d)\n", rect->x, rect->y, rect->xl, rect->yl, - clipzone.x, clipzone.y, clipzone.xl, clipzone.yl); + printf("Clipping (%d, %d) size (%d, %d) by (%d,%d)(%d,%d)\n", rect->x, rect->y, rect->xl, rect->yl, + clipzone.x, clipzone.y, clipzone.xl, clipzone.yl); #endif if (rect->x < clipzone.x) { @@ -156,15 +152,15 @@ int _gfxop_clip(rect_t *rect, rect_t clipzone) rect->yl = 0; #if 0 - printf (" => (%d, %d) size (%d, %d)\n", rect->x, rect->y, rect->xl, rect->yl); + printf(" => (%d, %d) size (%d, %d)\n", rect->x, rect->y, rect->xl, rect->yl); #endif return (rect->xl <= 0 || rect->yl <= 0); } static int _gfxop_grab_pixmap(gfx_state_t *state, gfx_pixmap_t **pxmp, int x, int y, - int xl, int yl, int priority, rect_t *zone) - /* Returns 1 if the resulting data size was zero, GFX_OK or an error code otherwise */ + int xl, int yl, int priority, rect_t *zone) +/* Returns 1 if the resulting data size was zero, GFX_OK or an error code otherwise */ { int xfact = state->driver->mode->xfact; int yfact = state->driver->mode->yfact; @@ -173,8 +169,8 @@ _gfxop_grab_pixmap(gfx_state_t *state, gfx_pixmap_t **pxmp, int x, int y, *zone = gfx_rect(x, y, xl, yl); if (_gfxop_clip(zone, gfx_rect(0, 0, - 320 * state->driver->mode->xfact, - 200 * state->driver->mode->yfact))) + 320 * state->driver->mode->xfact, + 200 * state->driver->mode->yfact))) return GFX_ERROR; if (!*pxmp) @@ -191,7 +187,7 @@ _gfxop_grab_pixmap(gfx_state_t *state, gfx_pixmap_t **pxmp, int x, int y, gfx_pixmap_alloc_data(*pxmp, state->driver->mode); } return state->driver->grab_pixmap(state->driver, *zone, *pxmp, - priority? GFX_MASK_PRIORITY : GFX_MASK_VISUAL); + priority ? GFX_MASK_PRIORITY : GFX_MASK_VISUAL); } @@ -241,12 +237,11 @@ DRAW_LOOP(map->index_data[offset] < color) /* Draw only lower priority */ #undef DRAW_LOOP static int -_gfxop_install_pixmap(gfx_driver_t *driver, gfx_pixmap_t *pxm) -{ +_gfxop_install_pixmap(gfx_driver_t *driver, gfx_pixmap_t *pxm) { int error; if (driver->capabilities & GFX_CAPABILITY_PIXMAP_REGISTRY - && !(pxm->flags & GFX_PIXMAP_FLAG_INSTALLED)) { + && !(pxm->flags & GFX_PIXMAP_FLAG_INSTALLED)) { error = driver->register_pixmap(driver, pxm); if (error) { @@ -257,21 +252,21 @@ _gfxop_install_pixmap(gfx_driver_t *driver, gfx_pixmap_t *pxm) } if (driver->mode->palette && - (!(pxm->flags & GFX_PIXMAP_FLAG_PALETTE_SET))) { + (!(pxm->flags & GFX_PIXMAP_FLAG_PALETTE_SET))) { int i; int error; for (i = 0; i < pxm->colors_nr; i++) { if ((error = driver->set_palette(driver, pxm->colors[i].global_index, - pxm->colors[i].r, - pxm->colors[i].g, - pxm->colors[i].b))) { + pxm->colors[i].r, + pxm->colors[i].g, + pxm->colors[i].b))) { GFXWARN("driver->set_palette(%d, %02x/%02x/%02x) failed!\n", - pxm->colors[i].global_index, - pxm->colors[i].r, - pxm->colors[i].g, - pxm->colors[i].b); + pxm->colors[i].global_index, + pxm->colors[i].r, + pxm->colors[i].g, + pxm->colors[i].b); if (error == GFX_FATAL) return GFX_FATAL; @@ -285,15 +280,14 @@ _gfxop_install_pixmap(gfx_driver_t *driver, gfx_pixmap_t *pxm) static int _gfxop_draw_pixmap(gfx_driver_t *driver, gfx_pixmap_t *pxm, int priority, int control, - rect_t src, rect_t dest, rect_t clip, int static_buf, gfx_pixmap_t *control_map, - gfx_pixmap_t *priority_map) -{ + rect_t src, rect_t dest, rect_t clip, int static_buf, gfx_pixmap_t *control_map, + gfx_pixmap_t *priority_map) { int error; rect_t clipped_dest = gfx_rect(dest.x, dest.y, dest.xl, dest.yl); if (control >= 0 || priority >= 0) { point_t original_pos = gfx_point(dest.x / driver->mode->xfact, - dest.y / driver->mode->yfact); + dest.y / driver->mode->yfact); if (control >= 0) _gfxop_draw_control(control_map, pxm, control, original_pos); @@ -304,7 +298,7 @@ _gfxop_draw_pixmap(gfx_driver_t *driver, gfx_pixmap_t *pxm, int priority, int co #endif } - + if (_gfxop_clip(&clipped_dest, clip)) return GFX_OK; @@ -323,7 +317,7 @@ _gfxop_draw_pixmap(gfx_driver_t *driver, gfx_pixmap_t *pxm, int priority, int co clipped_dest.yl / driver->mode->yfact); error = driver->draw_pixmap(driver, pxm, priority, src, clipped_dest, - static_buf? GFX_BUFFER_STATIC : GFX_BUFFER_BACK); + static_buf ? GFX_BUFFER_STATIC : GFX_BUFFER_BACK); if (error) { GFXERROR("driver->draw_pixmap() returned error!\n"); @@ -333,11 +327,10 @@ _gfxop_draw_pixmap(gfx_driver_t *driver, gfx_pixmap_t *pxm, int priority, int co } static int -_gfxop_remove_pointer(gfx_state_t *state) -{ +_gfxop_remove_pointer(gfx_state_t *state) { if (state->mouse_pointer_visible - && !state->mouse_pointer_in_hw - && state->mouse_pointer_bg) { + && !state->mouse_pointer_in_hw + && state->mouse_pointer_bg) { int retval; if (state->mouse_pointer_visible == POINTER_VISIBLE_BUT_CLIPPED) { @@ -350,9 +343,9 @@ _gfxop_remove_pointer(gfx_state_t *state) state->mouse_pointer_visible = 0; retval = state->driver->draw_pixmap(state->driver, state->mouse_pointer_bg, GFX_NO_PRIORITY, - gfx_rect(0, 0, state->mouse_pointer_bg->xl, state->mouse_pointer_bg->yl), - state->pointer_bg_zone, - GFX_BUFFER_BACK); + gfx_rect(0, 0, state->mouse_pointer_bg->xl, state->mouse_pointer_bg->yl), + state->pointer_bg_zone, + GFX_BUFFER_BACK); state->pointer_pos.x = state->driver->pointer_x / state->driver->mode->xfact; state->pointer_pos.y = state->driver->pointer_y / state->driver->mode->yfact; @@ -367,8 +360,7 @@ _gfxop_remove_pointer(gfx_state_t *state) } static int /* returns 1 if there are no pointer bounds, 0 otherwise */ -_gfxop_get_pointer_bounds(gfx_state_t *state, rect_t *rect) -{ +_gfxop_get_pointer_bounds(gfx_state_t *state, rect_t *rect) { gfx_pixmap_t *ppxm = state->mouse_pointer; if (!ppxm) @@ -380,15 +372,14 @@ _gfxop_get_pointer_bounds(gfx_state_t *state, rect_t *rect) rect->yl = ppxm->yl; return (_gfxop_clip(rect, gfx_rect(0, 0, 320 * state->driver->mode->xfact, - 200 * state->driver->mode->yfact))); + 200 * state->driver->mode->yfact))); } static int _gfxop_buffer_propagate_box(gfx_state_t *state, rect_t box, gfx_buffer_t buffer); static int -_gfxop_draw_pointer(gfx_state_t *state) -{ +_gfxop_draw_pointer(gfx_state_t *state) { if (state->mouse_pointer_visible || !state->mouse_pointer || state->mouse_pointer_in_hw) return GFX_OK; else { @@ -408,8 +399,8 @@ _gfxop_draw_pointer(gfx_state_t *state) * we should reuse the buffer instead of malloc/free for better performance */ retval = _gfxop_grab_pixmap(state, &(state->mouse_pointer_bg), x, y, - ppxm->xl, ppxm->yl, 0, - &(state->pointer_bg_zone)); + ppxm->xl, ppxm->yl, 0, + &(state->pointer_bg_zone)); if (retval == GFX_ERROR) { state->pointer_bg_zone = gfx_rect(0, 0, 320, 200); @@ -421,10 +412,10 @@ _gfxop_draw_pointer(gfx_state_t *state) return retval; error = _gfxop_draw_pixmap(state->driver, ppxm, -1, -1, - gfx_rect(0, 0, ppxm->xl, ppxm->yl), - gfx_rect(x, y, ppxm->xl, ppxm->yl), - gfx_rect(0, 0, xfact * 320 , yfact * 200), - 0, state->control_map, state->priority_map); + gfx_rect(0, 0, ppxm->xl, ppxm->yl), + gfx_rect(x, y, ppxm->xl, ppxm->yl), + gfx_rect(0, 0, xfact * 320 , yfact * 200), + 0, state->control_map, state->priority_map); if (error) return error; @@ -435,8 +426,7 @@ _gfxop_draw_pointer(gfx_state_t *state) } gfx_pixmap_t * -_gfxr_get_cel(gfx_state_t *state, int nr, int *loop, int *cel, int palette) -{ +_gfxr_get_cel(gfx_state_t *state, int nr, int *loop, int *cel, int palette) { gfxr_view_t *view = gfxr_get_view(state->resstate, nr, loop, cel, palette); gfxr_loop_t *indexed_loop; @@ -444,17 +434,17 @@ _gfxr_get_cel(gfx_state_t *state, int nr, int *loop, int *cel, int palette) return NULL; if (*loop >= view->loops_nr - || *loop < 0) { + || *loop < 0) { GFXWARN("Attempt to get cel from loop %d/%d inside view %d\n", *loop, - view->loops_nr, nr); + view->loops_nr, nr); return NULL; } indexed_loop = view->loops + *loop; if (*cel >= indexed_loop->cels_nr - || *cel < 0) { + || *cel < 0) { GFXWARN("Attempt to get cel %d/%d from view %d/%d\n", *cel, indexed_loop->cels_nr, - nr, *loop); + nr, *loop); return NULL; } @@ -464,14 +454,13 @@ _gfxr_get_cel(gfx_state_t *state, int nr, int *loop, int *cel, int palette) /*** Dirty rectangle operations ***/ static inline int -_gfxop_update_box(gfx_state_t *state, rect_t box) -{ +_gfxop_update_box(gfx_state_t *state, rect_t box) { int retval; _gfxop_scale_rect(&box, state->driver->mode); if ((retval = _gfxop_buffer_propagate_box(state, box, GFX_BUFFER_FRONT))) { GFXERROR("Error occured while propagating box (%d,%d,%d,%d) to front buffer\n", - box.x, box.y, box.xl, box.yl); + box.x, box.y, box.xl, box.yl); return retval; } return GFX_OK; @@ -479,8 +468,7 @@ _gfxop_update_box(gfx_state_t *state, rect_t box) static struct _dirty_rect * -_rect_create(rect_t box) -{ + _rect_create(rect_t box) { struct _dirty_rect *rect; rect = (struct _dirty_rect*)sci_malloc(sizeof(struct _dirty_rect)); @@ -492,8 +480,7 @@ _rect_create(rect_t box) gfx_dirty_rect_t * -gfxdr_add_dirty(gfx_dirty_rect_t *base, rect_t box, int strategy) -{ +gfxdr_add_dirty(gfx_dirty_rect_t *base, rect_t box, int strategy) { if (box.xl < 0) { box.x += box.xl; box.xl = - box.xl; @@ -505,7 +492,7 @@ gfxdr_add_dirty(gfx_dirty_rect_t *base, rect_t box, int strategy) } #ifdef GFXOP_DEBUG_DIRTY fprintf(stderr, "Adding new dirty (%d %d %d %d)\n", - GFX_PRINT_RECT(box)); + GFX_PRINT_RECT(box)); #endif if (_gfxop_clip(&box, gfx_rect(0, 0, 320, 200))) return base; @@ -533,7 +520,8 @@ gfxdr_add_dirty(gfx_dirty_rect_t *base, rect_t box, int strategy) } *rectp = _rect_create(box); - } break; + } + break; default: GFXERROR("Attempt to use invalid dirty frame mode %d!\nPlease refer to gfx_options.h.", strategy); @@ -544,8 +532,7 @@ gfxdr_add_dirty(gfx_dirty_rect_t *base, rect_t box, int strategy) } static void -_gfxop_add_dirty(gfx_state_t *state, rect_t box) -{ +_gfxop_add_dirty(gfx_state_t *state, rect_t box) { if (state->disable_dirty) return; @@ -554,7 +541,7 @@ _gfxop_add_dirty(gfx_state_t *state, rect_t box) static inline void _gfxop_add_dirty_x(gfx_state_t *state, rect_t box) - /* Extends the box size by one before adding (used for lines) */ +/* Extends the box size by one before adding (used for lines) */ { if (box.xl < 0) box.xl--; @@ -570,8 +557,7 @@ _gfxop_add_dirty_x(gfx_state_t *state, rect_t box) } static int -_gfxop_clear_dirty_rec(gfx_state_t *state, struct _dirty_rect *rect) -{ +_gfxop_clear_dirty_rec(gfx_state_t *state, struct _dirty_rect *rect) { int retval; if (!rect) @@ -579,7 +565,7 @@ _gfxop_clear_dirty_rec(gfx_state_t *state, struct _dirty_rect *rect) #ifdef GFXOP_DEBUG_DIRTY fprintf(stderr, "\tClearing dirty (%d %d %d %d)\n", - GFX_PRINT_RECT(rect->rect)); + GFX_PRINT_RECT(rect->rect)); #endif if (!state->fullscreen_override) retval = _gfxop_update_box(state, rect->rect); @@ -596,8 +582,7 @@ _gfxop_clear_dirty_rec(gfx_state_t *state, struct _dirty_rect *rect) /*** Exported operations ***/ static void -init_aux_pixmap(gfx_pixmap_t **pixmap) -{ +init_aux_pixmap(gfx_pixmap_t **pixmap) { *pixmap = gfx_pixmap_alloc_index_data(gfx_new_pixmap(320, 200, GFX_RESID_NONE, 0, 0)); (*pixmap)->flags |= GFX_PIXMAP_FLAG_EXTERNAL_PALETTE; (*pixmap)->colors_nr = DEFAULT_COLORS_NR; @@ -605,23 +590,22 @@ init_aux_pixmap(gfx_pixmap_t **pixmap) } static int -_gfxop_init_common(gfx_state_t *state, gfx_options_t *options, void *misc_payload) -{ +_gfxop_init_common(gfx_state_t *state, gfx_options_t *options, void *misc_payload) { state->options = options; if (!((state->resstate = gfxr_new_resource_manager(state->version, - state->options, - state->driver, - misc_payload)))) { + state->options, + state->driver, + misc_payload)))) { GFXERROR("Failed to initialize resource manager!\n"); return GFX_FATAL; } if ((state->static_palette = - gfxr_interpreter_get_static_palette(state->resstate, - state->version, - &(state->static_palette_entries), - misc_payload))) + gfxr_interpreter_get_static_palette(state->resstate, + state->version, + &(state->static_palette_entries), + misc_payload))) _gfxop_alloc_colors(state, state->static_palette, state->static_palette_entries); state->visible_map = GFX_MASK_VISUAL; @@ -655,8 +639,7 @@ _gfxop_init_common(gfx_state_t *state, gfx_options_t *options, void *misc_payloa } int -gfxop_init_default(gfx_state_t *state, gfx_options_t *options, void *misc_info) -{ +gfxop_init_default(gfx_state_t *state, gfx_options_t *options, void *misc_info) { BASIC_CHECKS(GFX_FATAL); if (state->driver->init(state->driver)) return GFX_FATAL; @@ -667,9 +650,8 @@ gfxop_init_default(gfx_state_t *state, gfx_options_t *options, void *misc_info) int gfxop_init(gfx_state_t *state, int xfact, int yfact, gfx_color_mode_t bpp, - gfx_options_t *options, void *misc_info) -{ - int color_depth = bpp? bpp : 1; + gfx_options_t *options, void *misc_info) { + int color_depth = bpp ? bpp : 1; int initialized = 0; BASIC_CHECKS(GFX_FATAL); @@ -689,8 +671,7 @@ gfxop_init(gfx_state_t *state, int xfact, int yfact, gfx_color_mode_t bpp, int -gfxop_set_parameter(gfx_state_t *state, char *attribute, char *value) -{ +gfxop_set_parameter(gfx_state_t *state, char *attribute, char *value) { BASIC_CHECKS(GFX_FATAL); return state->driver->set_parameter(state->driver, attribute, value); @@ -698,8 +679,7 @@ gfxop_set_parameter(gfx_state_t *state, char *attribute, char *value) int -gfxop_exit(gfx_state_t *state) -{ +gfxop_exit(gfx_state_t *state) { BASIC_CHECKS(GFX_ERROR); gfxr_free_resource_manager(state->driver, state->resstate); @@ -729,15 +709,13 @@ gfxop_exit(gfx_state_t *state) int -gfxop_have_mouse(gfx_state_t *state) -{ +gfxop_have_mouse(gfx_state_t *state) { return state->driver->capabilities & GFX_CAPABILITY_MOUSE_SUPPORT; } static int -_gfxop_scan_one_bitmask(gfx_pixmap_t *pixmap, rect_t zone) -{ +_gfxop_scan_one_bitmask(gfx_pixmap_t *pixmap, rect_t zone) { int retval = 0; int pixmap_xscale = pixmap->index_xl / 320; int pixmap_yscale = pixmap->index_yl / 200; @@ -762,15 +740,14 @@ _gfxop_scan_one_bitmask(gfx_pixmap_t *pixmap, rect_t zone) } int -gfxop_scan_bitmask(gfx_state_t *state, rect_t area, gfx_map_mask_t map) -{ - gfxr_pic_t *pic = (state->pic_unscaled)? state->pic_unscaled : state->pic; +gfxop_scan_bitmask(gfx_state_t *state, rect_t area, gfx_map_mask_t map) { + gfxr_pic_t *pic = (state->pic_unscaled) ? state->pic_unscaled : state->pic; int retval = 0; _gfxop_clip(&area, gfx_rect(0, 10, 320, 200)); if (area.xl <= 0 - || area.yl <= 0) + || area.yl <= 0) return 0; if (map & GFX_MASK_VISUAL) @@ -791,8 +768,7 @@ gfxop_scan_bitmask(gfx_state_t *state, rect_t area, gfx_map_mask_t map) #define MAX_Y 199 int -gfxop_set_clip_zone(gfx_state_t *state, rect_t zone) -{ +gfxop_set_clip_zone(gfx_state_t *state, rect_t zone) { int xfact, yfact; BASIC_CHECKS(GFX_ERROR); @@ -829,13 +805,12 @@ gfxop_set_clip_zone(gfx_state_t *state, rect_t zone) int gfxop_set_color(gfx_state_t *state, gfx_color_t *color, int r, int g, int b, int a, - int priority, int control) -{ + int priority, int control) { gfx_pixmap_color_t pixmap_color = {0}; int error_code; int mask = ((r >= 0 && g >= 0 && b >= 0) ? GFX_MASK_VISUAL : 0) - | ((priority >= 0)? GFX_MASK_PRIORITY : 0) - | ((control >= 0)? GFX_MASK_CONTROL : 0); + | ((priority >= 0) ? GFX_MASK_PRIORITY : 0) + | ((control >= 0) ? GFX_MASK_CONTROL : 0); BASIC_CHECKS(GFX_FATAL); @@ -865,7 +840,7 @@ gfxop_set_color(gfx_state_t *state, gfx_color_t *color, int r, int g, int b, int return error_code; } else if ((error_code = state->driver->set_palette(state->driver, pixmap_color.global_index, (byte) r, (byte) g, (byte) b))) { GFXWARN("Graphics driver failed to set color index %d to (%02x/%02x/%02x)\n", - pixmap_color.global_index, r, g, b); + pixmap_color.global_index, r, g, b); return error_code; } } @@ -876,8 +851,7 @@ gfxop_set_color(gfx_state_t *state, gfx_color_t *color, int r, int g, int b, int } int -gfxop_set_system_color(gfx_state_t *state, gfx_color_t *color) -{ +gfxop_set_system_color(gfx_state_t *state, gfx_color_t *color) { gfx_palette_color_t *palette_colors; BASIC_CHECKS(GFX_FATAL); @@ -885,7 +859,7 @@ gfxop_set_system_color(gfx_state_t *state, gfx_color_t *color) return GFX_OK; if (color->visual.global_index < 0 - || color->visual.global_index >= state->driver->mode->palette->max_colors_nr) { + || color->visual.global_index >= state->driver->mode->palette->max_colors_nr) { GFXERROR("Attempt to set invalid color index %02x as system color\n", color->visual.global_index); return GFX_ERROR; } @@ -897,8 +871,7 @@ gfxop_set_system_color(gfx_state_t *state, gfx_color_t *color) } int -gfxop_free_color(gfx_state_t *state, gfx_color_t *color) -{ +gfxop_free_color(gfx_state_t *state, gfx_color_t *color) { gfx_palette_color_t *palette_color = {0}; gfx_pixmap_color_t pixmap_color = {0}; int error_code; @@ -908,7 +881,7 @@ gfxop_free_color(gfx_state_t *state, gfx_color_t *color) return GFX_OK; if (color->visual.global_index < 0 - || color->visual.global_index >= state->driver->mode->palette->max_colors_nr) { + || color->visual.global_index >= state->driver->mode->palette->max_colors_nr) { GFXERROR("Attempt to free invalid color index %02x\n", color->visual.global_index); return GFX_ERROR; } @@ -933,8 +906,7 @@ gfxop_free_color(gfx_state_t *state, gfx_color_t *color) static int -line_check_bar(int *start, int *length, int clipstart, int cliplength) -{ +line_check_bar(int *start, int *length, int clipstart, int cliplength) { int overlength; if (*start < clipstart) { @@ -951,8 +923,7 @@ line_check_bar(int *start, int *length, int clipstart, int cliplength) } static void -clip_line_partial(float *start, float *end, float delta_val, float pos_val, float start_val, float end_val) -{ +clip_line_partial(float *start, float *end, float delta_val, float pos_val, float start_val, float end_val) { float my_start = (start_val - pos_val) * delta_val; float my_end = (end_val - pos_val) * delta_val; @@ -978,41 +949,40 @@ line_clip(rect_t *line, rect_t clip, int xfact, int yfact) } else - if (!line->yl) {/* hbar */ - if (line->y < clip.y || line->y >= (clip.y + clip.yl)) - return 1; + if (!line->yl) {/* hbar */ + if (line->y < clip.y || line->y >= (clip.y + clip.yl)) + return 1; - return line_check_bar(&(line->x), &(line->xl), clip.x, clip.xl); + return line_check_bar(&(line->x), &(line->xl), clip.x, clip.xl); - } else { /* "normal" line */ - float start = 0.0, end = 1.0; - float xv = (float) line->xl; - float yv = (float) line->yl; + } else { /* "normal" line */ + float start = 0.0, end = 1.0; + float xv = (float) line->xl; + float yv = (float) line->yl; - if (line->xl < 0) - clip_line_partial(&start, &end, (float) (1.0 / xv), (float) line->x, (float) (clip.x + clip.xl), (float) clip.x); - else - clip_line_partial(&start, &end, (float) (1.0 / xv), (float) line->x, (float) clip.x, (float) (clip.x + clip.xl)); + if (line->xl < 0) + clip_line_partial(&start, &end, (float)(1.0 / xv), (float) line->x, (float)(clip.x + clip.xl), (float) clip.x); + else + clip_line_partial(&start, &end, (float)(1.0 / xv), (float) line->x, (float) clip.x, (float)(clip.x + clip.xl)); - if (line->yl < 0) - clip_line_partial(&start, &end, (float) (1.0 / yv), (float) line->y, (float) (clip.y + clip.yl), (float) clip.y); - else - clip_line_partial(&start, &end, (float) (1.0 / yv), (float) line->y, (float) clip.y, (float) (clip.y + clip.yl)); + if (line->yl < 0) + clip_line_partial(&start, &end, (float)(1.0 / yv), (float) line->y, (float)(clip.y + clip.yl), (float) clip.y); + else + clip_line_partial(&start, &end, (float)(1.0 / yv), (float) line->y, (float) clip.y, (float)(clip.y + clip.yl)); - line->x += (int) (xv * start); - line->y += (int) (yv * start); + line->x += (int)(xv * start); + line->y += (int)(yv * start); - line->xl = (int) (xv * (end-start)); - line->yl = (int) (yv * (end-start)); + line->xl = (int)(xv * (end - start)); + line->yl = (int)(yv * (end - start)); - return (start > 1.0 || end < 0.0); - } + return (start > 1.0 || end < 0.0); + } return 0; } static int -point_clip(point_t *start, point_t *end, rect_t clip, int xfact, int yfact) -{ +point_clip(point_t *start, point_t *end, rect_t clip, int xfact, int yfact) { rect_t line = gfx_rect(start->x, start->y, end->x - start->x, end->y - start->y); int retval = line_clip(&line, clip, xfact, yfact); @@ -1028,8 +998,7 @@ point_clip(point_t *start, point_t *end, rect_t clip, int xfact, int yfact) static void -draw_line_to_control_map(gfx_state_t *state, point_t start, point_t end, gfx_color_t color) -{ +draw_line_to_control_map(gfx_state_t *state, point_t start, point_t end, gfx_color_t color) { if (color.mask & GFX_MASK_CONTROL) if (!point_clip(&start, &end, state->clip_zone_unscaled, 0, 0)) gfx_draw_line_pixmap_i(state->control_map, start, end, color.control); @@ -1037,13 +1006,13 @@ draw_line_to_control_map(gfx_state_t *state, point_t start, point_t end, gfx_col static int simulate_stippled_line_draw(gfx_driver_t *driver, int skipone, point_t start, point_t end, gfx_color_t color, gfx_line_mode_t line_mode) - /* Draws a stippled line if this isn't supported by the driver (skipone is ignored ATM) */ +/* Draws a stippled line if this isn't supported by the driver (skipone is ignored ATM) */ { int xl = end.x - start.x; int yl = end.y - start.y; - int stepwidth = (xl)? driver->mode->xfact : driver->mode->yfact; - int dbl_stepwidth = 2*stepwidth; - int linelength = (line_mode == GFX_LINE_MODE_FINE)? stepwidth - 1 : 0; + int stepwidth = (xl) ? driver->mode->xfact : driver->mode->yfact; + int dbl_stepwidth = 2 * stepwidth; + int linelength = (line_mode == GFX_LINE_MODE_FINE) ? stepwidth - 1 : 0; int *posvar; int length; int delta; @@ -1052,12 +1021,12 @@ simulate_stippled_line_draw(gfx_driver_t *driver, int skipone, point_t start, po if (!xl) { /* xl = 0, so we move along yl */ posvar = &start.y; length = yl; - delta = (yl < 0)? -dbl_stepwidth : dbl_stepwidth; + delta = (yl < 0) ? -dbl_stepwidth : dbl_stepwidth; } else { - assert (!yl); /* We don't do diagonals; that's not needed ATM. */ + assert(!yl); /* We don't do diagonals; that's not needed ATM. */ posvar = &start.x; length = xl; - delta = (xl < 0)? -dbl_stepwidth : dbl_stepwidth; + delta = (xl < 0) ? -dbl_stepwidth : dbl_stepwidth; } length_left = length; @@ -1081,9 +1050,9 @@ simulate_stippled_line_draw(gfx_driver_t *driver, int skipone, point_t start, po point_t nextpos = gfx_point(start.x + xl, start.y + yl); if ((retval = driver->draw_line(driver, start, nextpos, - color, line_mode, GFX_LINE_STYLE_NORMAL))) { + color, line_mode, GFX_LINE_STYLE_NORMAL))) { GFXERROR("Failed to draw partial stippled line (%d,%d) -- (%d,%d)\n", - GFX_PRINT_POINT(start), GFX_PRINT_POINT(nextpos)); + GFX_PRINT_POINT(start), GFX_PRINT_POINT(nextpos)); return retval; } *posvar += delta; @@ -1106,7 +1075,7 @@ simulate_stippled_line_draw(gfx_driver_t *driver, int skipone, point_t start, po if ((retval = driver->draw_line(driver, start, nextpos, color, line_mode, GFX_LINE_STYLE_NORMAL))) { GFXERROR("Failed to draw partial stippled line (%d,%d) -- (%d,%d)\n", - GFX_PRINT_POINT(start), GFX_PRINT_POINT(nextpos)); + GFX_PRINT_POINT(start), GFX_PRINT_POINT(nextpos)); return retval; } } @@ -1117,8 +1086,7 @@ simulate_stippled_line_draw(gfx_driver_t *driver, int skipone, point_t start, po static int _gfxop_draw_line_clipped(gfx_state_t *state, point_t start, point_t end, gfx_color_t color, gfx_line_mode_t line_mode, - gfx_line_style_t line_style) -{ + gfx_line_style_t line_style) { int retval; int skipone = (start.x ^ end.y) & 1; /* Used for simulated line stippling */ @@ -1133,17 +1101,17 @@ _gfxop_draw_line_clipped(gfx_state_t *state, point_t start, point_t end, gfx_col } if (start.x < state->clip_zone.x - || start.y < state->clip_zone.y - || end.x >= (state->clip_zone.x + state->clip_zone.xl) - || end.y >= (state->clip_zone.y + state->clip_zone.yl)) + || start.y < state->clip_zone.y + || end.x >= (state->clip_zone.x + state->clip_zone.xl) + || end.y >= (state->clip_zone.y + state->clip_zone.yl)) if (point_clip(&start, &end, state->clip_zone, state->driver->mode->xfact - 1, - state->driver->mode->yfact - 1)) + state->driver->mode->yfact - 1)) return GFX_OK; /* Clipped off */ if (line_style == GFX_LINE_STYLE_STIPPLED) { if (start.x != end.x && start.y != end.y) { GFXWARN("Attempt to draw stippled line which is neither an hbar nor a vbar: (%d,%d) -- (%d,%d)\n", - GFX_PRINT_POINT(start), GFX_PRINT_POINT(end)); + GFX_PRINT_POINT(start), GFX_PRINT_POINT(end)); return GFX_ERROR; } if (!(state->driver->capabilities & GFX_CAPABILITY_STIPPLED_LINES)) @@ -1151,12 +1119,12 @@ _gfxop_draw_line_clipped(gfx_state_t *state, point_t start, point_t end, gfx_col } if (line_mode == GFX_LINE_MODE_FINE - && !(state->driver->capabilities & GFX_CAPABILITY_FINE_LINES)) + && !(state->driver->capabilities & GFX_CAPABILITY_FINE_LINES)) line_mode = GFX_LINE_MODE_FAST; if ((retval = state->driver->draw_line(state->driver, start, end, color, line_mode, line_style))) { GFXERROR("Failed to draw line (%d,%d) -- (%d,%d)\n", - GFX_PRINT_POINT(start), GFX_PRINT_POINT(end)); + GFX_PRINT_POINT(start), GFX_PRINT_POINT(end)); return retval; } return GFX_OK; @@ -1164,9 +1132,8 @@ _gfxop_draw_line_clipped(gfx_state_t *state, point_t start, point_t end, gfx_col int gfxop_draw_line(gfx_state_t *state, point_t start, point_t end, - gfx_color_t color, gfx_line_mode_t line_mode, - gfx_line_style_t line_style) -{ + gfx_color_t color, gfx_line_mode_t line_mode, + gfx_line_style_t line_style) { int xfact, yfact; BASIC_CHECKS(GFX_FATAL); @@ -1193,8 +1160,7 @@ gfxop_draw_line(gfx_state_t *state, point_t start, point_t end, int gfxop_draw_rectangle(gfx_state_t *state, rect_t rect, gfx_color_t color, gfx_line_mode_t line_mode, - gfx_line_style_t line_style) -{ + gfx_line_style_t line_style) { int retval = 0; int xfact, yfact; int xunit, yunit; @@ -1209,7 +1175,7 @@ gfxop_draw_rectangle(gfx_state_t *state, rect_t rect, gfx_color_t color, gfx_lin yfact = state->driver->mode->yfact; if (line_mode == GFX_LINE_MODE_FINE - && state->driver->capabilities & GFX_CAPABILITY_FINE_LINES) { + && state->driver->capabilities & GFX_CAPABILITY_FINE_LINES) { xunit = yunit = 1; xl = 1 + (rect.xl - 1) * xfact; yl = 1 + (rect.yl - 1) * yfact; @@ -1240,10 +1206,10 @@ gfxop_draw_rectangle(gfx_state_t *state, rect_t rect, gfx_color_t color, gfx_lin _gfxop_add_dirty_x(state, \ gfx_rect(pt1##_u.x, pt1##_u.y, pt2##_u.x - pt1##_u.x, pt2##_u.y - pt1##_u.y)) - PARTIAL_LINE (upper_left, upper_right); - PARTIAL_LINE (upper_right, lower_right); - PARTIAL_LINE (lower_right, lower_left); - PARTIAL_LINE (lower_left, upper_left); + PARTIAL_LINE(upper_left, upper_right); + PARTIAL_LINE(upper_right, lower_right); + PARTIAL_LINE(lower_right, lower_left); + PARTIAL_LINE(lower_left, upper_left); #undef PARTIAL_LINE if (retval) { @@ -1259,8 +1225,7 @@ gfxop_draw_rectangle(gfx_state_t *state, rect_t rect, gfx_color_t color, gfx_lin int gfxop_draw_box(gfx_state_t *state, rect_t box, gfx_color_t color1, gfx_color_t color2, - gfx_box_shade_t shade_type) -{ + gfx_box_shade_t shade_type) { gfx_driver_t *drv = state->driver; int reverse = 0; /* switch color1 and color2 */ float mod_offset = 0.0, mod_breadth = 1.0; /* 0.0 to 1.0: Color adjustment */ @@ -1305,18 +1270,20 @@ gfxop_draw_box(gfx_state_t *state, rect_t box, gfx_color_t color1, gfx_color_t c driver_shade_type = GFX_SHADE_FLAT; break; - case GFX_BOX_SHADE_LEFT: reverse = 1; + case GFX_BOX_SHADE_LEFT: + reverse = 1; case GFX_BOX_SHADE_RIGHT: driver_shade_type = GFX_SHADE_HORIZONTALLY; - mod_offset = (float) (((new_box.x - box.x) * 1.0) / (box.xl * 1.0)); - mod_breadth = (float) ((new_box.xl * 1.0) / (box.xl * 1.0)); + mod_offset = (float)(((new_box.x - box.x) * 1.0) / (box.xl * 1.0)); + mod_breadth = (float)((new_box.xl * 1.0) / (box.xl * 1.0)); break; - case GFX_BOX_SHADE_UP: reverse = 1; + case GFX_BOX_SHADE_UP: + reverse = 1; case GFX_BOX_SHADE_DOWN: driver_shade_type = GFX_SHADE_VERTICALLY; - mod_offset = (float) (((new_box.y - box.y) * 1.0) / (box.yl * 1.0)); - mod_breadth = (float) ((new_box.yl * 1.0) / (box.yl * 1.0)); + mod_offset = (float)(((new_box.y - box.y) * 1.0) / (box.yl * 1.0)); + mod_breadth = (float)((new_box.yl * 1.0) / (box.yl * 1.0)); break; default: @@ -1326,7 +1293,7 @@ gfxop_draw_box(gfx_state_t *state, rect_t box, gfx_color_t color1, gfx_color_t c if (reverse) - mod_offset = (float) (1.0 - (mod_offset + mod_breadth)); + mod_offset = (float)(1.0 - (mod_offset + mod_breadth)); /* Reverse offset if we have to interpret colors inversely */ if (shade_type == GFX_BOX_SHADE_FLAT) @@ -1363,16 +1330,14 @@ gfxop_draw_box(gfx_state_t *state, rect_t box, gfx_color_t color1, gfx_color_t c int -gfxop_fill_box(gfx_state_t *state, rect_t box, gfx_color_t color) -{ +gfxop_fill_box(gfx_state_t *state, rect_t box, gfx_color_t color) { return gfxop_draw_box(state, box, color, color, GFX_BOX_SHADE_FLAT); } static int -_gfxop_buffer_propagate_box(gfx_state_t *state, rect_t box, gfx_buffer_t buffer) -{ +_gfxop_buffer_propagate_box(gfx_state_t *state, rect_t box, gfx_buffer_t buffer) { int error; if (_gfxop_clip(&box, gfx_rect(0, 0, 320 * state->driver->mode->xfact, 200 * state->driver->mode->yfact))) @@ -1380,7 +1345,7 @@ _gfxop_buffer_propagate_box(gfx_state_t *state, rect_t box, gfx_buffer_t buffer) if ((error = state->driver->update(state->driver, box, gfx_point(box.x, box.y), buffer))) { GFXERROR("Error occured while updating region (%d,%d,%d,%d) in buffer %d\n", - box.x, box.y, box.xl, box.yl, buffer); + box.x, box.y, box.xl, box.yl, buffer); return error; } return GFX_OK; @@ -1388,15 +1353,14 @@ _gfxop_buffer_propagate_box(gfx_state_t *state, rect_t box, gfx_buffer_t buffer) extern int sci0_palette; int -gfxop_clear_box(gfx_state_t *state, rect_t box) -{ +gfxop_clear_box(gfx_state_t *state, rect_t box) { BASIC_CHECKS(GFX_FATAL); REMOVE_POINTER; _gfxop_add_dirty(state, box); DDIRTY(stderr, "[] clearing box %d %d %d %d\n", GFX_PRINT_RECT(box)); if (box.x == 29 - && box.y == 77 - && (sci0_palette == 1)) { + && box.y == 77 + && (sci0_palette == 1)) { BREAKPOINT(); } @@ -1412,8 +1376,7 @@ gfxop_clear_box(gfx_state_t *state, rect_t box) } int -gfxop_set_visible_map(gfx_state_t *state, gfx_map_mask_t visible_map) -{ +gfxop_set_visible_map(gfx_state_t *state, gfx_map_mask_t visible_map) { switch (visible_map) { case GFX_MASK_VISUAL: @@ -1443,8 +1406,7 @@ gfxop_set_visible_map(gfx_state_t *state, gfx_map_mask_t visible_map) } int -gfxop_update(gfx_state_t *state) -{ +gfxop_update(gfx_state_t *state) { int retval; BASIC_CHECKS(GFX_FATAL); @@ -1458,7 +1420,7 @@ gfxop_update(gfx_state_t *state) /* We've been asked to re-draw the active full-screen image, essentially. */ rect_t rect = gfx_rect(0, 0, 320, 200); gfx_xlate_pixmap(state->fullscreen_override, state->driver->mode, GFX_XLATE_FILTER_NONE); - gfxop_draw_pixmap(state, state->fullscreen_override, rect, gfx_point(0,0)); + gfxop_draw_pixmap(state, state->fullscreen_override, rect, gfx_point(0, 0)); retval |= _gfxop_update_box(state, rect); } @@ -1477,8 +1439,7 @@ gfxop_update(gfx_state_t *state) int -gfxop_update_box(gfx_state_t *state, rect_t box) -{ +gfxop_update_box(gfx_state_t *state, rect_t box) { BASIC_CHECKS(GFX_FATAL); DRAW_POINTER; @@ -1491,8 +1452,7 @@ gfxop_update_box(gfx_state_t *state, rect_t box) } int -gfxop_enable_dirty_frames(gfx_state_t *state) -{ +gfxop_enable_dirty_frames(gfx_state_t *state) { BASIC_CHECKS(GFX_ERROR); state->disable_dirty = 0; @@ -1500,8 +1460,7 @@ gfxop_enable_dirty_frames(gfx_state_t *state) } int -gfxop_disable_dirty_frames(gfx_state_t *state) -{ +gfxop_disable_dirty_frames(gfx_state_t *state) { BASIC_CHECKS(GFX_ERROR); state->disable_dirty = 1; @@ -1522,17 +1481,16 @@ gfxop_disable_dirty_frames(gfx_state_t *state) #define GFXOP_FULL_POINTER_REFRESH if (_gfxop_full_pointer_refresh(state)) { GFXERROR("Failed to do full pointer refresh!\n"); return GFX_ERROR; } static int -_gfxop_full_pointer_refresh(gfx_state_t *state) -{ +_gfxop_full_pointer_refresh(gfx_state_t *state) { rect_t pointer_bounds; rect_t old_pointer_bounds = {0, 0, 0, 0}; int new_x = state->driver->pointer_x; int new_y = state->driver->pointer_y; if (new_x != state->old_pointer_draw_pos.x - || new_y != state->old_pointer_draw_pos.y) { + || new_y != state->old_pointer_draw_pos.y) { point_t pp_new = gfx_point(new_x / state->driver->mode->xfact, - new_y / state->driver->mode->yfact); + new_y / state->driver->mode->yfact); if (!_gfxop_get_pointer_bounds(state, &pointer_bounds)) { memcpy(&old_pointer_bounds, &(state->pointer_bg_zone), sizeof(rect_t)); @@ -1551,8 +1509,7 @@ _gfxop_full_pointer_refresh(gfx_state_t *state) } int -gfxop_usleep(gfx_state_t *state, long usecs) -{ +gfxop_usleep(gfx_state_t *state, long usecs) { long time, utime; long wakeup_time, wakeup_utime; long add_seconds; @@ -1582,8 +1539,7 @@ gfxop_usleep(gfx_state_t *state, long usecs) int -_gfxop_set_pointer(gfx_state_t *state, gfx_pixmap_t *pxm) -{ +_gfxop_set_pointer(gfx_state_t *state, gfx_pixmap_t *pxm) { rect_t old_pointer_bounds = {0}; rect_t pointer_bounds = {0}; int retval = -1; @@ -1600,16 +1556,16 @@ _gfxop_set_pointer(gfx_state_t *state, gfx_pixmap_t *pxm) draw_old = state->driver->capabilities & GFX_CAPABILITY_COLOR_MOUSE_POINTER; if (!draw_old - && state->mouse_pointer - && (state->driver->capabilities & GFX_CAPABILITY_POINTER_PIXMAP_REGISTRY)) - if ((retval = state->driver->unregister_pixmap(state->driver, state->mouse_pointer))){ + && state->mouse_pointer + && (state->driver->capabilities & GFX_CAPABILITY_POINTER_PIXMAP_REGISTRY)) + if ((retval = state->driver->unregister_pixmap(state->driver, state->mouse_pointer))) { GFXERROR("Pointer un-registration failed!\n"); return retval; } if (pxm == NULL - || (state->driver->capabilities & GFX_CAPABILITY_COLOR_MOUSE_POINTER) - || pxm->colors_nr <= 2) { + || (state->driver->capabilities & GFX_CAPABILITY_COLOR_MOUSE_POINTER) + || pxm->colors_nr <= 2) { if (state->driver->capabilities & GFX_CAPABILITY_POINTER_PIXMAP_REGISTRY) { if ((pxm) && (retval = state->driver->register_pixmap(state->driver, pxm))) { GFXERROR("Pixmap-registering a new mouse pointer failed!\n"); @@ -1659,8 +1615,7 @@ _gfxop_set_pointer(gfx_state_t *state, gfx_pixmap_t *pxm) int -gfxop_set_pointer_cursor(gfx_state_t *state, int nr) -{ +gfxop_set_pointer_cursor(gfx_state_t *state, int nr) { gfx_pixmap_t *new_pointer = NULL; BASIC_CHECKS(GFX_FATAL); @@ -1680,8 +1635,7 @@ gfxop_set_pointer_cursor(gfx_state_t *state, int nr) int -gfxop_set_pointer_view(gfx_state_t *state, int nr, int loop, int cel, point_t *hotspot) -{ +gfxop_set_pointer_view(gfx_state_t *state, int nr, int loop, int cel, point_t *hotspot) { int real_loop = loop; int real_cel = cel; gfx_pixmap_t *new_pointer = NULL; @@ -1689,10 +1643,9 @@ gfxop_set_pointer_view(gfx_state_t *state, int nr, int loop, int cel, point_t * BASIC_CHECKS(GFX_FATAL); new_pointer = _gfxr_get_cel(state, nr, &real_loop, &real_cel, - 0); /* FIXME: For now, don't palettize pointers */ + 0); /* FIXME: For now, don't palettize pointers */ - if (hotspot) - { + if (hotspot) { new_pointer->xoffset = hotspot->x; new_pointer->yoffset = hotspot->y; } @@ -1700,25 +1653,22 @@ gfxop_set_pointer_view(gfx_state_t *state, int nr, int loop, int cel, point_t * if (!new_pointer) { GFXWARN("Attempt to set invalid pointer #%d\n", nr); return GFX_ERROR; - } else - { + } else { if (real_loop != loop || real_cel != cel) { GFXDEBUG("Changed loop/cel from %d/%d to %d/%d in view %d\n", - loop, cel, real_loop, real_cel, nr); + loop, cel, real_loop, real_cel, nr); } return _gfxop_set_pointer(state, new_pointer); } } int -gfxop_set_pointer_position(gfx_state_t *state, point_t pos) -{ +gfxop_set_pointer_position(gfx_state_t *state, point_t pos) { BASIC_CHECKS(GFX_ERROR); state->pointer_pos = pos; - if (pos.x > 320 || pos.y > 200) - { + if (pos.x > 320 || pos.y > 200) { GFXWARN("Attempt to place pointer at invalid coordinates (%d, %d)\n", pos.x, pos.y); return 0; /* Not fatal */ } @@ -1743,7 +1693,7 @@ struct scancode_row { static int _gfxop_scancode(int ch) - /* Calculates a PC keyboard scancode from a character */ +/* Calculates a PC keyboard scancode from a character */ { int row; int c = toupper((char)ch); @@ -1764,13 +1714,12 @@ _gfxop_scancode(int ch) return ch; /* not found */ } -/* static */ int -_gfxop_shiftify(int c) -{ +/* static */ +int +_gfxop_shiftify(int c) { char shifted_numbers[] = ")!@#$%^&*("; - - if (c < 256) - { + + if (c < 256) { c = toupper((char)c); if (c >= 'A' && c <= 'Z') @@ -1778,64 +1727,96 @@ _gfxop_shiftify(int c) if (c >= '0' && c <= '9') return shifted_numbers[c-'0']; - + switch (c) { - case SCI_K_TAB: return SCI_K_SHIFT_TAB; - case ']': return '}'; - case '[': return '{'; - case '`': return '~'; - case '-': return '_'; - case '=': return '+'; - case ';': return ':'; - case '\'': return '"'; - case '\\': return '|'; - case ',': return '<'; - case '.': return '>'; - case '/': return '?'; - default: return c; /* No match */ + case SCI_K_TAB: + return SCI_K_SHIFT_TAB; + case ']': + return '}'; + case '[': + return '{'; + case '`': + return '~'; + case '-': + return '_'; + case '=': + return '+'; + case ';': + return ':'; + case '\'': + return '"'; + case '\\': + return '|'; + case ',': + return '<'; + case '.': + return '>'; + case '/': + return '?'; + default: + return c; /* No match */ } } - switch (c) - { - case SCI_K_F1 : return SCI_K_SHIFT_F1; - case SCI_K_F2 : return SCI_K_SHIFT_F2; - case SCI_K_F3 : return SCI_K_SHIFT_F3; - case SCI_K_F4 : return SCI_K_SHIFT_F4; - case SCI_K_F5 : return SCI_K_SHIFT_F5; - case SCI_K_F6 : return SCI_K_SHIFT_F6; - case SCI_K_F7 : return SCI_K_SHIFT_F7; - case SCI_K_F8 : return SCI_K_SHIFT_F8; - case SCI_K_F9 : return SCI_K_SHIFT_F9; - case SCI_K_F10 : return SCI_K_SHIFT_F10; + switch (c) { + case SCI_K_F1 : + return SCI_K_SHIFT_F1; + case SCI_K_F2 : + return SCI_K_SHIFT_F2; + case SCI_K_F3 : + return SCI_K_SHIFT_F3; + case SCI_K_F4 : + return SCI_K_SHIFT_F4; + case SCI_K_F5 : + return SCI_K_SHIFT_F5; + case SCI_K_F6 : + return SCI_K_SHIFT_F6; + case SCI_K_F7 : + return SCI_K_SHIFT_F7; + case SCI_K_F8 : + return SCI_K_SHIFT_F8; + case SCI_K_F9 : + return SCI_K_SHIFT_F9; + case SCI_K_F10 : + return SCI_K_SHIFT_F10; } return c; } static int -_gfxop_numlockify(int c) -{ +_gfxop_numlockify(int c) { switch (c) { - case SCI_K_DELETE: return '.'; - case SCI_K_INSERT: return '0'; - case SCI_K_END: return '1'; - case SCI_K_DOWN: return '2'; - case SCI_K_PGDOWN: return '3'; - case SCI_K_LEFT: return '4'; - case SCI_K_CENTER: return '5'; - case SCI_K_RIGHT: return '6'; - case SCI_K_HOME: return '7'; - case SCI_K_UP: return '8'; - case SCI_K_PGUP: return '9'; - default: return c; /* Unchanged */ + case SCI_K_DELETE: + return '.'; + case SCI_K_INSERT: + return '0'; + case SCI_K_END: + return '1'; + case SCI_K_DOWN: + return '2'; + case SCI_K_PGDOWN: + return '3'; + case SCI_K_LEFT: + return '4'; + case SCI_K_CENTER: + return '5'; + case SCI_K_RIGHT: + return '6'; + case SCI_K_HOME: + return '7'; + case SCI_K_UP: + return '8'; + case SCI_K_PGUP: + return '9'; + default: + return c; /* Unchanged */ } } sci_event_t -gfxop_get_event(gfx_state_t *state, unsigned int mask) -{ +gfxop_get_event(gfx_state_t *state, unsigned int mask) { sci_event_t error_event = { SCI_EVT_ERROR, 0, 0 }; sci_event_t event; event.data = 0; @@ -1858,21 +1839,20 @@ gfxop_get_event(gfx_state_t *state, unsigned int mask) } else { event.type = 0; - if (!(mask & SCI_EVT_NONBLOCK)) - { + if (!(mask & SCI_EVT_NONBLOCK)) { do { if (event.type) { *seekerp = (gfx_input_event_t*)sci_malloc(sizeof(gfx_input_event_t)); (*seekerp)->next = NULL; - - event.data = (char) (event.data); + + event.data = (char)(event.data); /* Clip illegal bits */ - + (*seekerp)->event = event; seekerp = &((*seekerp)->next); } event = state->driver->get_event(state->driver); - + } while (event.type && !(event.type & mask)); } } @@ -1883,7 +1863,7 @@ gfxop_get_event(gfx_state_t *state, unsigned int mask) } if (event.type == SCI_EVT_KEYBOARD - && !(state->driver->capabilities & GFX_CAPABILITY_KEYTRANSLATE)) { + && !(state->driver->capabilities & GFX_CAPABILITY_KEYTRANSLATE)) { /* Do we still have to translate the key? */ event.character = event.data; @@ -1894,10 +1874,10 @@ gfxop_get_event(gfx_state_t *state, unsigned int mask) /* Shift if appropriate */ else if (((event.buckybits & (SCI_EVM_RSHIFT | SCI_EVM_LSHIFT)) - && !(event.buckybits & SCI_EVM_CAPSLOCK)) - || - (!(event.buckybits & (SCI_EVM_RSHIFT | SCI_EVM_LSHIFT)) - && (event.buckybits & SCI_EVM_CAPSLOCK))) + && !(event.buckybits & SCI_EVM_CAPSLOCK)) + || + (!(event.buckybits & (SCI_EVM_RSHIFT | SCI_EVM_LSHIFT)) + && (event.buckybits & SCI_EVM_CAPSLOCK))) event.character = _gfxop_shiftify(event.character); /* Numlockify if appropriate */ @@ -1914,8 +1894,7 @@ gfxop_get_event(gfx_state_t *state, unsigned int mask) /*******************/ int -gfxop_lookup_view_get_loops(gfx_state_t *state, int nr) -{ +gfxop_lookup_view_get_loops(gfx_state_t *state, int nr) { int loop = 0, cel = 0; gfxr_view_t *view = NULL; @@ -1933,8 +1912,7 @@ gfxop_lookup_view_get_loops(gfx_state_t *state, int nr) int -gfxop_lookup_view_get_cels(gfx_state_t *state, int nr, int loop) -{ +gfxop_lookup_view_get_cels(gfx_state_t *state, int nr, int loop) { int real_loop = loop, cel = 0; gfxr_view_t *view = NULL; @@ -1954,9 +1932,8 @@ gfxop_lookup_view_get_cels(gfx_state_t *state, int nr, int loop) int -gfxop_check_cel(gfx_state_t *state, int nr, int *loop, int *cel) -{ - BASIC_CHECKS(GFX_ERROR); +gfxop_check_cel(gfx_state_t *state, int nr, int *loop, int *cel) { + BASIC_CHECKS(GFX_ERROR); if (!gfxr_get_view(state->resstate, nr, loop, cel, 0)) { GFXWARN("Attempt to verify loop/cel values for invalid view %d\n", nr); @@ -1967,11 +1944,10 @@ gfxop_check_cel(gfx_state_t *state, int nr, int *loop, int *cel) } int -gfxop_overflow_cel(gfx_state_t *state, int nr, int *loop, int *cel) -{ +gfxop_overflow_cel(gfx_state_t *state, int nr, int *loop, int *cel) { int loop_v = *loop; int cel_v = *cel; - BASIC_CHECKS(GFX_ERROR); + BASIC_CHECKS(GFX_ERROR); if (!gfxr_get_view(state->resstate, nr, &loop_v, &cel_v, 0)) { GFXWARN("Attempt to verify loop/cel values for invalid view %d\n", nr); @@ -1982,7 +1958,7 @@ gfxop_overflow_cel(gfx_state_t *state, int nr, int *loop, int *cel) *loop = 0; if (loop_v != *loop - || cel_v != *cel) + || cel_v != *cel) *cel = 0; return GFX_OK; @@ -1991,8 +1967,7 @@ gfxop_overflow_cel(gfx_state_t *state, int nr, int *loop, int *cel) int gfxop_get_cel_parameters(gfx_state_t *state, int nr, int loop, int cel, - int *width, int *height, point_t *offset) -{ + int *width, int *height, point_t *offset) { gfxr_view_t *view = NULL; gfx_pixmap_t *pxm = NULL; BASIC_CHECKS(GFX_ERROR); @@ -2014,11 +1989,10 @@ gfxop_get_cel_parameters(gfx_state_t *state, int nr, int loop, int cel, static int _gfxop_draw_cel_buffer(gfx_state_t *state, int nr, int loop, int cel, - point_t pos, gfx_color_t color, int static_buf, - int palette) -{ - int priority = (color.mask & GFX_MASK_PRIORITY)? color.priority : -1; - int control = (color.mask & GFX_MASK_CONTROL)? color.control : -1; + point_t pos, gfx_color_t color, int static_buf, + int palette) { + int priority = (color.mask & GFX_MASK_PRIORITY) ? color.priority : -1; + int control = (color.mask & GFX_MASK_CONTROL) ? color.control : -1; gfxr_view_t *view = NULL; gfx_pixmap_t *pxm = NULL; int old_x, old_y; @@ -2040,35 +2014,33 @@ _gfxop_draw_cel_buffer(gfx_state_t *state, int nr, int loop, int cel, _gfxop_add_dirty(state, gfx_rect(old_x, old_y, pxm->index_xl, pxm->index_yl)); return _gfxop_draw_pixmap(state->driver, pxm, priority, control, - gfx_rect(0, 0, pxm->xl, pxm->yl), - gfx_rect(pos.x, pos.y, pxm->xl, pxm->yl), - state->clip_zone, - static_buf , state->control_map, - static_buf - ? state->static_priority_map - : state->priority_map); + gfx_rect(0, 0, pxm->xl, pxm->yl), + gfx_rect(pos.x, pos.y, pxm->xl, pxm->yl), + state->clip_zone, + static_buf , state->control_map, + static_buf + ? state->static_priority_map + : state->priority_map); } int gfxop_draw_cel(gfx_state_t *state, int nr, int loop, int cel, point_t pos, - gfx_color_t color, int palette) -{ + gfx_color_t color, int palette) { return _gfxop_draw_cel_buffer(state, nr, loop, cel, pos, color, 0, palette); } int gfxop_draw_cel_static(gfx_state_t *state, int nr, int loop, int cel, point_t pos, - gfx_color_t color, int palette) -{ + gfx_color_t color, int palette) { int retval; rect_t oldclip = state->clip_zone; state->clip_zone = gfx_rect_fullscreen; _gfxop_scale_rect(&(state->clip_zone), state->driver->mode); retval = gfxop_draw_cel_static_clipped(state, nr, loop, cel, pos, color, - palette); + palette); /* Except that the area it's clipped against is... unusual ;-) */ state->clip_zone = oldclip; @@ -2078,8 +2050,7 @@ gfxop_draw_cel_static(gfx_state_t *state, int nr, int loop, int cel, point_t pos int gfxop_draw_cel_static_clipped(gfx_state_t *state, int nr, int loop, int cel, - point_t pos, gfx_color_t color, int palette) -{ + point_t pos, gfx_color_t color, int palette) { return _gfxop_draw_cel_buffer(state, nr, loop, cel, pos, color, 1, palette); } @@ -2089,10 +2060,9 @@ gfxop_draw_cel_static_clipped(gfx_state_t *state, int nr, int loop, int cel, /******************/ static int -_gfxop_set_pic(gfx_state_t *state) -{ +_gfxop_set_pic(gfx_state_t *state) { gfx_copy_pixmap_box_i(state->control_map, state->pic->control_map, gfx_rect(0, 0, 320, 200)); - gfx_copy_pixmap_box_i(state->priority_map, state->pic_unscaled->priority_map, gfx_rect(0, 0, 320, 200)); + gfx_copy_pixmap_box_i(state->priority_map, state->pic_unscaled->priority_map, gfx_rect(0, 0, 320, 200)); gfx_copy_pixmap_box_i(state->static_priority_map, state->pic_unscaled->priority_map, gfx_rect(0, 0, 320, 200)); _gfxop_install_pixmap(state->driver, state->pic->visual_map); @@ -2104,15 +2074,13 @@ _gfxop_set_pic(gfx_state_t *state) void * -gfxop_get_pic_metainfo(gfx_state_t *state) -{ - return (state->pic)? state->pic->internal : NULL; +gfxop_get_pic_metainfo(gfx_state_t *state) { + return (state->pic) ? state->pic->internal : NULL; } int -gfxop_new_pic(gfx_state_t *state, int nr, int flags, int default_palette) -{ +gfxop_new_pic(gfx_state_t *state, int nr, int flags, int default_palette) { BASIC_CHECKS(GFX_FATAL); gfxr_tag_resources(state->resstate); @@ -2147,8 +2115,7 @@ gfxop_new_pic(gfx_state_t *state, int nr, int flags, int default_palette) int -gfxop_add_to_pic(gfx_state_t *state, int nr, int flags, int default_palette) -{ +gfxop_add_to_pic(gfx_state_t *state, int nr, int flags, int default_palette) { BASIC_CHECKS(GFX_FATAL); if (!state->pic) { @@ -2157,14 +2124,14 @@ gfxop_add_to_pic(gfx_state_t *state, int nr, int flags, int default_palette) } if (!(state->pic = gfxr_add_to_pic(state->resstate, state->pic_nr, nr, - GFX_MASK_VISUAL, flags, state->palette_nr, default_palette, 1))) { + GFX_MASK_VISUAL, flags, state->palette_nr, default_palette, 1))) { GFXERROR("Could not add pic #%d to pic #%d!\n", state->pic_nr, nr); return GFX_ERROR; } state->pic_unscaled = gfxr_add_to_pic(state->resstate, state->pic_nr, nr, - GFX_MASK_VISUAL, flags, - state->palette_nr, - default_palette, 1); + GFX_MASK_VISUAL, flags, + state->palette_nr, + default_palette, 1); return _gfxop_set_pic(state); } @@ -2176,8 +2143,7 @@ gfxop_add_to_pic(gfx_state_t *state, int nr, int flags, int default_palette) int -gfxop_get_font_height(gfx_state_t *state, int font_nr) -{ +gfxop_get_font_height(gfx_state_t *state, int font_nr) { gfx_bitmap_font_t *font; BASIC_CHECKS(GFX_FATAL); @@ -2190,9 +2156,8 @@ gfxop_get_font_height(gfx_state_t *state, int font_nr) int gfxop_get_text_params(gfx_state_t *state, int font_nr, const char *text, - int maxwidth, int *width, int *height, int text_flags, - int *lines_nr, int *lineheight, int *lastline_width) -{ + int maxwidth, int *width, int *height, int text_flags, + int *lines_nr, int *lineheight, int *lastline_width) { text_fragment_t *textsplits; gfx_bitmap_font_t *font; @@ -2207,10 +2172,10 @@ gfxop_get_text_params(gfx_state_t *state, int font_nr, const char *text, } textsplits = gfxr_font_calculate_size(font, maxwidth, text, width, - height, lines_nr, - lineheight, lastline_width, - (state->options->workarounds & GFX_WORKAROUND_WHITESPACE_COUNT) - | text_flags); + height, lines_nr, + lineheight, lastline_width, + (state->options->workarounds & GFX_WORKAROUND_WHITESPACE_COUNT) + | text_flags); if (!textsplits) { @@ -2241,14 +2206,13 @@ gfxop_get_text_params(gfx_state_t *state, int font_nr, const char *text, gfx_text_handle_t * gfxop_new_text(gfx_state_t *state, int font_nr, char *text, int maxwidth, - gfx_alignment_t halign, gfx_alignment_t valign, - gfx_color_t color1, gfx_color_t color2, gfx_color_t bg_color, - int flags) -{ + gfx_alignment_t halign, gfx_alignment_t valign, + gfx_color_t color1, gfx_color_t color2, gfx_color_t bg_color, + int flags) { gfx_text_handle_t *handle = {0}; gfx_bitmap_font_t *font = {0}; int i; - gfx_pixmap_color_t pxm_col1, pxm_col2, pxm_colbg= {0}; + gfx_pixmap_color_t pxm_col1, pxm_col2, pxm_colbg = {0}; BASIC_CHECKS(NULL); COL_XLATE(pxm_col1, color1); @@ -2271,12 +2235,12 @@ gfxop_new_text(gfx_state_t *state, int font_nr, char *text, int maxwidth, handle->line_height = font->line_height; handle->lines = - gfxr_font_calculate_size(font, maxwidth, handle->text, &(handle->width), &(handle->height), - &(handle->lines_nr), - NULL, NULL, - ((state->options->workarounds & GFX_WORKAROUND_WHITESPACE_COUNT)? - GFXR_FONT_FLAG_COUNT_WHITESPACE : 0) - | flags); + gfxr_font_calculate_size(font, maxwidth, handle->text, &(handle->width), &(handle->height), + &(handle->lines_nr), + NULL, NULL, + ((state->options->workarounds & GFX_WORKAROUND_WHITESPACE_COUNT) ? + GFXR_FONT_FLAG_COUNT_WHITESPACE : 0) + | flags); if (!handle->lines) { free(handle->text); @@ -2297,9 +2261,9 @@ gfxop_new_text(gfx_state_t *state, int font_nr, char *text, int maxwidth, int chars_nr = handle->lines[i].length; handle->text_pixmaps[i] = gfxr_draw_font(font, handle->lines[i].offset, chars_nr, - (color1.mask & GFX_MASK_VISUAL)? &pxm_col1 : NULL, - (color2.mask & GFX_MASK_VISUAL)? &pxm_col2 : NULL, - (bg_color.mask & GFX_MASK_VISUAL)? &pxm_colbg : NULL); + (color1.mask & GFX_MASK_VISUAL) ? &pxm_col1 : NULL, + (color2.mask & GFX_MASK_VISUAL) ? &pxm_col2 : NULL, + (bg_color.mask & GFX_MASK_VISUAL) ? &pxm_colbg : NULL); if (!handle->text_pixmaps[i]) { int j; @@ -2317,16 +2281,15 @@ gfxop_new_text(gfx_state_t *state, int font_nr, char *text, int maxwidth, handle->font = font; - handle->priority = (color1.mask & GFX_MASK_PRIORITY)? color1.priority : -1; - handle->control = (color1.mask & GFX_MASK_CONTROL)? color1.control : -1; + handle->priority = (color1.mask & GFX_MASK_PRIORITY) ? color1.priority : -1; + handle->control = (color1.mask & GFX_MASK_CONTROL) ? color1.control : -1; return handle; } int -gfxop_free_text(gfx_state_t *state, gfx_text_handle_t *handle) -{ +gfxop_free_text(gfx_state_t *state, gfx_text_handle_t *handle) { int j; BASIC_CHECKS(GFX_ERROR); @@ -2345,8 +2308,7 @@ gfxop_free_text(gfx_state_t *state, gfx_text_handle_t *handle) int -gfxop_draw_text(gfx_state_t *state, gfx_text_handle_t *handle, rect_t zone) -{ +gfxop_draw_text(gfx_state_t *state, gfx_text_handle_t *handle, rect_t zone) { int line_height; rect_t pos; int i; @@ -2426,8 +2388,8 @@ gfxop_draw_text(gfx_state_t *state, gfx_text_handle_t *handle, rect_t zone) _gfxop_add_dirty(state, pos); _gfxop_draw_pixmap(state->driver, pxm, handle->priority, handle->control, - gfx_rect(0, 0, pxm->xl, pxm->yl), pos, state->clip_zone, 0, - state->control_map, state->priority_map); + gfx_rect(0, 0, pxm->xl, pxm->yl), pos, state->clip_zone, 0, + state->control_map, state->priority_map); pos.y += line_height; } @@ -2437,8 +2399,7 @@ gfxop_draw_text(gfx_state_t *state, gfx_text_handle_t *handle, rect_t zone) gfx_pixmap_t * -gfxop_grab_pixmap(gfx_state_t *state, rect_t area) -{ +gfxop_grab_pixmap(gfx_state_t *state, rect_t area) { gfx_pixmap_t *pixmap = NULL; rect_t resultzone; /* Ignored for this application */ BASIC_CHECKS(NULL); @@ -2457,8 +2418,7 @@ gfxop_grab_pixmap(gfx_state_t *state, rect_t area) } int -gfxop_draw_pixmap(gfx_state_t *state, gfx_pixmap_t *pxm, rect_t zone, point_t pos) -{ +gfxop_draw_pixmap(gfx_state_t *state, gfx_pixmap_t *pxm, rect_t zone, point_t pos) { rect_t target; BASIC_CHECKS(GFX_ERROR); @@ -2482,13 +2442,12 @@ gfxop_draw_pixmap(gfx_state_t *state, gfx_pixmap_t *pxm, rect_t zone, point_t po _gfxop_scale_rect(&target, state->driver->mode); return _gfxop_draw_pixmap(state->driver, pxm, -1, -1, zone, target, - gfx_rect(0, 0, 320*state->driver->mode->xfact, - 200*state->driver->mode->yfact), 0, NULL, NULL); + gfx_rect(0, 0, 320*state->driver->mode->xfact, + 200*state->driver->mode->yfact), 0, NULL, NULL); } int -gfxop_free_pixmap(gfx_state_t *state, gfx_pixmap_t *pxm) -{ +gfxop_free_pixmap(gfx_state_t *state, gfx_pixmap_t *pxm) { BASIC_CHECKS(GFX_ERROR); gfx_free_pixmap(state->driver, pxm); return GFX_OK; |