Example #1
0
/* draws an inline image at rect (x,y,width,height)
 *  maxwidth is maximum width the image can take in
 *  zoom is whether the image is currently zoomed in
 *  position is the y position along the image the player has scrolled */
static void draw_message_image(UTOX_NATIVE_IMAGE *image, int x, int y, uint32_t width, uint32_t height, uint32_t maxwidth, _Bool zoom, double position)
{
    if(!zoom && width > maxwidth) {
        image_set_scale(image, (double)maxwidth / width);

        draw_image(image, x, y, maxwidth, height * maxwidth / width, 0, 0);

        image_set_scale(image, 1.0);
    } else {
        if(width > maxwidth) {
            draw_image(image, x, y, maxwidth, height, (int)((double)(width - maxwidth) * position), 0);
        } else {
            draw_image(image, x, y, width, height, 0, 0);
        }
    }
}
Example #2
0
File: ui.c Project: Matsu616/uTox
void draw_avatar_image(NATIVE_IMAGE *image, int x, int y, uint32_t width, uint32_t height, uint32_t targetwidth,
                       uint32_t targetheight)
{
    /* get smallest of width or height */
    const double scale = (width > height) ? (double)targetheight / height : (double)targetwidth / width;

    image_set_scale(image, scale);
    image_set_filter(image, FILTER_BILINEAR);

    /* set position to show the middle of the image in the center  */
    const int xpos = (int)((double)width * scale / 2 - (double)targetwidth / 2);
    const int ypos = (int)((double)height * scale / 2 - (double)targetheight / 2);

    draw_image(image, x, y, targetwidth, targetheight, xpos, ypos);

    image_set_scale(image, 1.0);
    image_set_filter(image, FILTER_NEAREST);
}