From: sasha Date: Sun, 5 Aug 2007 06:19:01 +0000 (+0000) Subject: started implementing proper image resizing functionality with align and stuff X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=b310c7588f04ac9c1767439c99110b11a7ce5321;p=dana%2Furxvt.git started implementing proper image resizing functionality with align and stuff --- diff --git a/src/rxvt.h b/src/rxvt.h index a6b43b63..9723e2bb 100644 --- a/src/rxvt.h +++ b/src/rxvt.h @@ -178,7 +178,9 @@ struct bgPixmap_t { # ifdef XPM_BACKGROUND # ifdef HAVE_AFTERIMAGE - ASImage *original_asim; + ASImage *original_asim; + + ASImage *resize_asim (rxvt_term *target, ASImage *background, XRectangle &dst_rect); # endif #define bgPmap_defaultScale 100 diff --git a/src/xpm.C b/src/xpm.C index 37a1da80..dc895bdb 100644 --- a/src/xpm.C +++ b/src/xpm.C @@ -125,6 +125,40 @@ check_set_align_value (int geom_flags, int flag, int &align, int new_value) return false; } +static inline int +make_align_position (int align, int window_size, int image_size) +{ + int diff = window_size - image_size; + int smaller = MIN (image_size,window_size); + + if (align >= 0 && align <= 50) + return diff * align / 100; + else if (align > 50 && align <= 100) + return window_size - image_size + diff * align / 100; + else if (align > 100 && align <= 200 ) + return ((align - 100) * smaller / 100) + window_size - smaller; + else if (align > -100 && align < 0) + return ((align + 100) * smaller / 100) - image_size; + return 0; +} + +static inline void +make_clip_rectangle (int pos, int size, int target_size, short &clip_pos, unsigned short &clip_size) +{ + if (pos < 0) + { + clip_pos = 0; + clip_size = MIN (target_size, size + pos); + } + else + { + clip_pos = pos; + clip_size = size; + if (pos < target_size && (int)clip_size > target_size - pos) + clip_pos = target_size - pos; + } +} + bool bgPixmap_t::handle_geometry (const char *geom) { @@ -318,6 +352,28 @@ bgPixmap_t::handle_geometry (const char *geom) return (changed > 0); } +#ifdef HAVE_AFTERIMAGE +ASImage * +bgPixmap_t::resize_asim (rxvt_term *target, ASImage *background, XRectangle &dst_rect) +{ + if (original_asim == NULL || target == NULL) + return NULL; + + int target_width = (int)target->szHint.width; + int target_height = (int)target->szHint.height; + int w = h_scale * target_width / 100; + int h = v_scale * target_height / 100; + int x = make_align_position (h_align, target_width, w); + int y = make_align_position (v_align, target_height, h); + + make_clip_rectangle (x, w, target_width, dst_rect.x, dst_rect.width); + make_clip_rectangle (y, h, target_height, dst_rect.y, dst_rect.height); + + /* TODO : actuall scaling code :) */ + +} +#endif + void rxvt_term::resize_pixmap () {