From e8b94b38c4be1bf3ada57ade9eb3a96adb080775 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sun, 30 Jul 2006 13:17:49 +0200 Subject: [PATCH] rnd-20060730-1-src * improved down-scaling of images for better level and preview graphics --- ChangeLog | 3 +++ src/conftime.h | 2 +- src/events.c | 2 +- src/libgame/gadgets.c | 29 +++++++++++++--------- src/libgame/sdl.c | 57 +++++++++++++++++++++++++++++++++++++++++++ src/libgame/system.c | 23 +++++++++++++---- src/libgame/system.h | 12 ++++++++- 7 files changed, 109 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 54ede52f..e9752cd3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2006-07-30 + * improved down-scaling of images for better level and preview graphics + 2006-07-26 * improved level number selection in main menu and player selection in setup menu (input devices section) by using standard button gadgets diff --git a/src/conftime.h b/src/conftime.h index 5cb98cb1..fcaa9e27 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2006-07-27 11:23]" +#define COMPILE_DATE_STRING "[2006-07-30 12:51]" diff --git a/src/events.c b/src/events.c index d78ff4a9..10166129 100644 --- a/src/events.c +++ b/src/events.c @@ -419,7 +419,7 @@ void HandleButton(int mx, int my, int button, int button_nr) } /* do not use scroll wheel button events for anything other than gadgets */ - if (button_nr > 3) + if (IS_WHEEL_BUTTON(button_nr)) return; switch (game_status) diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index b01fe169..afe5c3a7 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -71,9 +71,11 @@ static struct GadgetInfo *getGadgetInfoFromMousePosition(int mx, int my, struct GadgetInfo *gi; /* first check for scrollbars in case of mouse scroll wheel button events */ - if (button == 4 || button == 5) + if (IS_WHEEL_BUTTON(button)) { - boolean check_horizontal = (GetKeyModState() & KMOD_Control); + /* real horizontal wheel or vertical wheel with modifier key pressed */ + boolean check_horizontal = (IS_WHEEL_BUTTON_HORIZONTAL(button) || + GetKeyModState() & KMOD_Shift); /* check for the first active scrollbar with matching mouse wheel area */ for (gi = gadget_list_first_entry; gi != NULL; gi = gi->next) @@ -1725,10 +1727,11 @@ boolean HandleGadgets(int mx, int my, int button) { int mpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? mx : my); int gpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? gi->x : gi->y); + int slider_start = gpos + gi->scrollbar.position; + int slider_end = gpos + gi->scrollbar.position + gi->scrollbar.size - 1; + boolean inside_slider = (mpos >= slider_start && mpos <= slider_end); - if (button > 3 || - mpos < gpos + gi->scrollbar.position || - mpos >= gpos + gi->scrollbar.position + gi->scrollbar.size) + if (IS_WHEEL_BUTTON(button) || !inside_slider) { /* click scrollbar one scrollbar length up/left or down/right */ @@ -1737,10 +1740,13 @@ boolean HandleGadgets(int mx, int my, int button) int item_steps = gs->items_visible - 1; int item_direction = (mpos < gpos + gi->scrollbar.position ? -1 : +1); - if (button > 3) + if (IS_WHEEL_BUTTON(button)) { - item_steps = 3; - item_direction = (button == 4 ? -1 : +1); + boolean scroll_single_step = (GetKeyModState() & KMOD_Alt); + + item_steps = (scroll_single_step ? 1 : DEFAULT_WHEEL_STEPS); + item_direction = (button == MB_WHEEL_UP || + button == MB_WHEEL_LEFT ? -1 : +1); } changed_position = FALSE; @@ -1815,10 +1821,11 @@ boolean HandleGadgets(int mx, int my, int button) { int mpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? mx : my); int gpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? gi->x : gi->y); + int slider_start = gpos + gi->scrollbar.position; + int slider_end = gpos + gi->scrollbar.position + gi->scrollbar.size - 1; + boolean inside_slider = (mpos >= slider_start && mpos <= slider_end); - if (button >= 1 && button <= 3 && - mpos >= gpos + gi->scrollbar.position && - mpos < gpos + gi->scrollbar.position + gi->scrollbar.size) + if (!IS_WHEEL_BUTTON(button) && inside_slider) { /* start dragging scrollbar */ gi->scrollbar.drag_position = diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index df3a0e34..406c0226 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -1046,12 +1046,69 @@ typedef struct Uint8 a; } tColorRGBA; +int zoomSurfaceRGBA_scaleDownBy2(SDL_Surface *src, SDL_Surface *dst) +{ + int x, y; + tColorRGBA *sp, *csp, *dp; + int sgap, dgap; + + /* pointer setup */ + sp = csp = (tColorRGBA *) src->pixels; + dp = (tColorRGBA *) dst->pixels; + sgap = src->pitch - src->w * 4; + dgap = dst->pitch - dst->w * 4; + + for (y = 0; y < dst->h; y++) + { + sp = csp; + + for (x = 0; x < dst->w; x++) + { + tColorRGBA *sp0 = sp; + tColorRGBA *sp1 = (tColorRGBA *) ((Uint8 *) sp + src->pitch); + tColorRGBA *sp00 = &sp0[0]; + tColorRGBA *sp01 = &sp0[1]; + tColorRGBA *sp10 = &sp1[0]; + tColorRGBA *sp11 = &sp1[1]; + tColorRGBA new; + + /* create new color pixel from all four source color pixels */ + new.r = (sp00->r + sp01->r + sp10->r + sp11->r) / 4; + new.g = (sp00->g + sp01->g + sp10->g + sp11->g) / 4; + new.b = (sp00->b + sp01->b + sp10->b + sp11->b) / 4; + new.a = (sp00->a + sp01->a + sp10->a + sp11->a) / 4; + + /* draw */ + *dp = new; + + /* advance source pointers */ + sp += 2; + + /* advance destination pointer */ + dp++; + } + + /* advance source pointer */ + csp = (tColorRGBA *) ((Uint8 *) csp + 2 * src->pitch); + + /* advance destination pointers */ + dp = (tColorRGBA *) ((Uint8 *) dp + dgap); + } + + return 0; +} + int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface *dst) { int x, y, sx, sy, *sax, *say, *csax, *csay, csx, csy; tColorRGBA *sp, *csp, *dp; int sgap, dgap; + /* use specialized zoom function when scaling down to exactly half size */ + if (src->w == 2 * dst->w && + src->h == 2 * dst->h) + return zoomSurfaceRGBA_scaleDownBy2(src, dst); + /* variable setup */ sx = (int) (65536.0 * (float) src->w / (float) dst->w); sy = (int) (65536.0 * (float) src->h / (float) dst->h); diff --git a/src/libgame/system.c b/src/libgame/system.c index b3ad0f28..4f8ef0fb 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -814,8 +814,8 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, boolean create_small_bitmaps) { Bitmap swap_bitmap; - Bitmap *new_bitmap, *tmp_bitmap_1, *tmp_bitmap_2, *tmp_bitmap_8; - int width_1, height_1, width_2, height_2, width_8, height_8; + Bitmap *new_bitmap, *tmp_bitmap_1, *tmp_bitmap_2, *tmp_bitmap_4,*tmp_bitmap_8; + int width_1, height_1, width_2, height_2, width_4, height_4, width_8,height_8; int new_width, new_height; /* calculate new image dimensions for normal sized image */ @@ -829,13 +829,15 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, tmp_bitmap_1 = old_bitmap; /* this is only needed to make compilers happy */ - tmp_bitmap_2 = tmp_bitmap_8 = NULL; + tmp_bitmap_2 = tmp_bitmap_4 = tmp_bitmap_8 = NULL; if (create_small_bitmaps) { /* calculate new image dimensions for small images */ width_2 = width_1 / 2; height_2 = height_1 / 2; + width_4 = width_1 / 4; + height_4 = height_1 / 4; width_8 = width_1 / 8; height_8 = height_1 / 8; @@ -845,9 +847,15 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, else tmp_bitmap_2 = old_bitmap; + /* get image with 1/4 of normal size (for use in the level editor) */ + if (zoom_factor != 4) + tmp_bitmap_4 = ZoomBitmap(tmp_bitmap_2, width_2 / 2, height_2 / 2); + else + tmp_bitmap_4 = old_bitmap; + /* get image with 1/8 of normal size (for use on the preview screen) */ if (zoom_factor != 8) - tmp_bitmap_8 = ZoomBitmap(tmp_bitmap_1, width_1 / 8, height_1 / 8); + tmp_bitmap_8 = ZoomBitmap(tmp_bitmap_4, width_4 / 2, height_4 / 2); else tmp_bitmap_8 = old_bitmap; } @@ -887,6 +895,8 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, BlitBitmap(tmp_bitmap_1, new_bitmap, 0, 0, width_1, height_1, 0, 0); BlitBitmap(tmp_bitmap_2, new_bitmap, 0, 0, width_1 / 2, height_1 / 2, 0, height_1); + BlitBitmap(tmp_bitmap_4, new_bitmap, 0, 0, width_1 / 4, height_1 / 4, + width_1 / 2, height_1); BlitBitmap(tmp_bitmap_8, new_bitmap, 0, 0, width_1 / 8, height_1 / 8, 3 * width_1 / 4, height_1); } @@ -907,11 +917,14 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, if (zoom_factor != 2) FreeBitmap(tmp_bitmap_2); + if (zoom_factor != 4) + FreeBitmap(tmp_bitmap_4); + if (zoom_factor != 8) FreeBitmap(tmp_bitmap_8); } - /* replace image with extended image (containing normal, 1/2 and 1/8 size) */ + /* replace image with extended image (containing 1/1, 1/2, 1/4, 1/8 size) */ #if defined(TARGET_SDL) swap_bitmap.surface = old_bitmap->surface; old_bitmap->surface = new_bitmap->surface; diff --git a/src/libgame/system.h b/src/libgame/system.h index f96d530f..c175d59f 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -90,7 +90,17 @@ #define MB_LEFTBUTTON 1 #define MB_MIDDLEBUTTON 2 #define MB_RIGHTBUTTON 3 - +#define MB_WHEEL_UP 4 +#define MB_WHEEL_DOWN 5 +#define MB_WHEEL_LEFT 6 +#define MB_WHEEL_RIGHT 7 +#define IS_WHEEL_BUTTON_VERTICAL(b) ((b) >= MB_WHEEL_UP && \ + (b) <= MB_WHEEL_DOWN) +#define IS_WHEEL_BUTTON_HORIZONTAL(b) ((b) >= MB_WHEEL_LEFT && \ + (b) <= MB_WHEEL_RIGHT) +#define IS_WHEEL_BUTTON(b) ((b) >= MB_WHEEL_UP && \ + (b) <= MB_WHEEL_DOWN) +#define DEFAULT_WHEEL_STEPS 3 /* values for move directions */ #define MV_BIT_LEFT 0 -- 2.34.1