… | |
… | |
123 | } |
123 | } |
124 | } |
124 | } |
125 | return false; |
125 | return false; |
126 | } |
126 | } |
127 | |
127 | |
|
|
128 | static inline int |
|
|
129 | make_align_position (int align, int window_size, int image_size) |
|
|
130 | { |
|
|
131 | int diff = window_size - image_size; |
|
|
132 | int smaller = MIN (image_size,window_size); |
|
|
133 | |
|
|
134 | if (align >= 0 && align <= 50) |
|
|
135 | return diff * align / 100; |
|
|
136 | else if (align > 50 && align <= 100) |
|
|
137 | return window_size - image_size + diff * align / 100; |
|
|
138 | else if (align > 100 && align <= 200 ) |
|
|
139 | return ((align - 100) * smaller / 100) + window_size - smaller; |
|
|
140 | else if (align > -100 && align < 0) |
|
|
141 | return ((align + 100) * smaller / 100) - image_size; |
|
|
142 | return 0; |
|
|
143 | } |
|
|
144 | |
|
|
145 | static inline void |
|
|
146 | make_clip_rectangle (int pos, int size, int target_size, int &clip_pos, int &clip_size) |
|
|
147 | { |
|
|
148 | if (size <= 0) |
|
|
149 | { /* special case - tiling */ |
|
|
150 | clip_pos = pos; |
|
|
151 | clip_size = target_size; |
|
|
152 | } |
|
|
153 | else if (pos < 0) |
|
|
154 | { |
|
|
155 | clip_pos = 0; |
|
|
156 | clip_size = MIN (target_size, size + pos); |
|
|
157 | } |
|
|
158 | else |
|
|
159 | { |
|
|
160 | clip_pos = pos; |
|
|
161 | clip_size = size; |
|
|
162 | if (pos < target_size && (int)clip_size > target_size - pos) |
|
|
163 | clip_pos = target_size - pos; |
|
|
164 | } |
|
|
165 | } |
|
|
166 | |
128 | bool |
167 | bool |
129 | bgPixmap_t::handle_geometry (const char *geom) |
168 | bgPixmap_t::handle_geometry (const char *geom) |
130 | { |
169 | { |
131 | int geom_flags = 0, changed = 0; |
170 | int geom_flags = 0, changed = 0; |
132 | int x = 0, y = 0; |
171 | int x = 0, y = 0; |
… | |
… | |
315 | } |
354 | } |
316 | //fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
355 | //fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
317 | // flags, h_scale, v_scale, h_align, v_align); |
356 | // flags, h_scale, v_scale, h_align, v_align); |
318 | return (changed > 0); |
357 | return (changed > 0); |
319 | } |
358 | } |
|
|
359 | |
|
|
360 | #ifdef HAVE_AFTERIMAGE |
|
|
361 | bool |
|
|
362 | bgPixmap_t::render_asim (rxvt_term *target, ASImage *background, ARGB32 background_tint) |
|
|
363 | { |
|
|
364 | if (target == NULL) |
|
|
365 | return false; |
|
|
366 | |
|
|
367 | int target_width = (int)target->szHint.width; |
|
|
368 | int target_height = (int)target->szHint.height; |
|
|
369 | int new_pmap_width = target_width, new_pmap_height = target_height; |
|
|
370 | ASImage *result = NULL; |
|
|
371 | |
|
|
372 | int x = 0; |
|
|
373 | int y = 0; |
|
|
374 | int w = h_scale * target_width / 100; |
|
|
375 | int h = v_scale * target_height / 100; |
|
|
376 | |
|
|
377 | if (original_asim) |
|
|
378 | { |
|
|
379 | x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); |
|
|
380 | y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); |
|
|
381 | } |
|
|
382 | |
|
|
383 | int dst_x, dst_y; |
|
|
384 | int clip_width, clip_height; |
|
|
385 | |
|
|
386 | make_clip_rectangle (x, w, target_width, dst_x, clip_width); |
|
|
387 | make_clip_rectangle (y, h, target_height, dst_y, clip_height); |
|
|
388 | |
|
|
389 | /* TODO : actuall scaling code :) */ |
|
|
390 | if (dst_x >= target_width || dst_y >= target_height |
|
|
391 | || clip_width <= 0 || clip_height <= 0 || original_asim == NULL) |
|
|
392 | { |
|
|
393 | result = background; |
|
|
394 | dst_x = dst_y = 0; |
|
|
395 | if (background) |
|
|
396 | { |
|
|
397 | new_pmap_width = clip_width = background->width; |
|
|
398 | new_pmap_height = clip_height = background->height; |
|
|
399 | } |
|
|
400 | else |
|
|
401 | new_pmap_width = new_pmap_height = 0; |
|
|
402 | } |
|
|
403 | else |
|
|
404 | { |
|
|
405 | result = original_asim; |
|
|
406 | if ((w > 0 && w != original_asim->width) |
|
|
407 | || (h > 0 && h != original_asim->height)) |
|
|
408 | { |
|
|
409 | result = scale_asimage (target->asv, original_asim, |
|
|
410 | w > 0 ? w : original_asim->width, |
|
|
411 | h > 0 ? h : original_asim->height, |
|
|
412 | background ? ASA_ASImage : ASA_XImage, |
|
|
413 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
414 | } |
|
|
415 | if (background == NULL) |
|
|
416 | {/* if tiling - pixmap has to be sized exactly as the image */ |
|
|
417 | if (h_scale == 0) |
|
|
418 | new_pmap_width = result->width; |
|
|
419 | if (v_scale == 0) |
|
|
420 | new_pmap_height = result->height; |
|
|
421 | } |
|
|
422 | else |
|
|
423 | {/* if blending background and image - pixmap has to be sized same as target window */ |
|
|
424 | ASImageLayer *layers = create_image_layers (2); |
|
|
425 | ASImage *merged_im = NULL; |
|
|
426 | |
|
|
427 | layers[0].im = background; |
|
|
428 | layers[0].clip_width = target_width; |
|
|
429 | layers[0].clip_height = target_height; |
|
|
430 | layers[0].tint = background_tint; |
|
|
431 | layers[1].im = result; |
|
|
432 | if (w <= 0) |
|
|
433 | {/* tile horizontally */ |
|
|
434 | layers[1].dst_x = dst_x - (int)result->width; |
|
|
435 | layers[1].clip_width = result->width; |
|
|
436 | } |
|
|
437 | else |
|
|
438 | {/* clip horizontally */ |
|
|
439 | layers[1].dst_x = dst_x; |
|
|
440 | layers[1].clip_width = clip_width; |
|
|
441 | } |
|
|
442 | if (h <= 0) |
|
|
443 | { |
|
|
444 | layers[1].dst_y = dst_y - (int)result->height; |
|
|
445 | layers[1].clip_height = result->height; |
|
|
446 | } |
|
|
447 | else |
|
|
448 | { |
|
|
449 | layers[1].dst_y = dst_y; |
|
|
450 | layers[1].clip_height = clip_height; |
|
|
451 | } |
|
|
452 | if (target->rs[Rs_blendtype]) |
|
|
453 | { |
|
|
454 | layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); |
|
|
455 | if (layers[1].merge_scanlines == NULL) |
|
|
456 | layers[1].merge_scanlines = alphablend_scanlines; |
|
|
457 | } |
|
|
458 | ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, |
|
|
459 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
|
|
460 | if (tmp) |
|
|
461 | { |
|
|
462 | if (result != original_asim) |
|
|
463 | destroy_asimage (&result); |
|
|
464 | result = tmp; |
|
|
465 | dst_x = dst_y = 0; |
|
|
466 | clip_width = target_width; |
|
|
467 | clip_height = target_height; |
|
|
468 | } |
|
|
469 | free (layers); |
|
|
470 | } |
|
|
471 | } |
|
|
472 | |
|
|
473 | if (pixmap) |
|
|
474 | { |
|
|
475 | if (result == NULL |
|
|
476 | || pmap_width != new_pmap_width |
|
|
477 | || pmap_height != new_pmap_height |
|
|
478 | || pmap_depth != target->depth) |
|
|
479 | { |
|
|
480 | XFreePixmap (target->dpy, pixmap); |
|
|
481 | pixmap = None; |
|
|
482 | } |
|
|
483 | } |
|
|
484 | |
|
|
485 | if (result) |
|
|
486 | { |
|
|
487 | XGCValues gcv; |
|
|
488 | GC gc; |
|
|
489 | |
|
|
490 | /* create Pixmap */ |
|
|
491 | if (pixmap == None) |
|
|
492 | { |
|
|
493 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
|
|
494 | pmap_width = new_pmap_width; |
|
|
495 | pmap_height = new_pmap_height; |
|
|
496 | pmap_depth = target->depth; |
|
|
497 | } |
|
|
498 | /* fill with background color ( if result's not completely overlapping it)*/ |
|
|
499 | gcv.foreground = target->pix_colors[Color_bg]; |
|
|
500 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
|
|
501 | |
|
|
502 | if (dst_x > 0 || dst_y > 0 |
|
|
503 | || dst_x + clip_width < new_pmap_width |
|
|
504 | || dst_y + clip_height < new_pmap_height) |
|
|
505 | { |
|
|
506 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
|
|
507 | } |
|
|
508 | /* put result on pixmap */ |
|
|
509 | asimage2drawable (target->asv, pixmap, result, gc, 0, 0, dst_x, dst_y, clip_width, clip_height, True); |
|
|
510 | |
|
|
511 | /* set target's background to pixmap */ |
|
|
512 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
|
|
513 | |
|
|
514 | XFreeGC (target->dpy, gc); |
|
|
515 | } |
|
|
516 | else |
|
|
517 | { |
|
|
518 | /* set target background to a pixel */ |
|
|
519 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
|
|
520 | } |
|
|
521 | |
|
|
522 | return true; |
|
|
523 | } |
|
|
524 | #endif |
320 | |
525 | |
321 | void |
526 | void |
322 | rxvt_term::resize_pixmap () |
527 | rxvt_term::resize_pixmap () |
323 | { |
528 | { |
324 | XGCValues gcvalue; |
529 | XGCValues gcvalue; |