Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
a27med
Posts: 6
Registered: ‎03-12-2012
My Device: Non
Accepted Solution

Background Image for Drawing Application

Hello All,

 

I am currently trying to figure out the following: how to add a background image to my drawing application. I have a drawing application that is built over the Gesture sample application.

 

What is currently done is the following:

 

case GESTURE_SWIPE: {
            gesture_swipe_t* tap = (gesture_swipe_t*)gesture;

            int bg[] = { SCREEN_BLIT_DESTINATION_X, swipe->coords.x,
			SCREEN_BLIT_DESTINATION_Y, swipe->coords.y,
			SCREEN_BLIT_DESTINATION_WIDTH, 10,
			SCREEN_BLIT_DESTINATION_HEIGHT, 10,    SCREEN_BLIT_COLOR, 0xffffff00, SCREEN_BLIT_END };
            screen_fill(screen_ctx, screen_buf[0], bg);	               
            screen_post_window(screen_win, screen_buf[0], 1, rect, 0);

            fprintf(stderr,"Tap x:%d y:%d",swipe->coords.x,swipe->coords.y);
            break;
        }

 

Whenever a gesture is recognized, I simply "draw" a box in that area. Since the gesture is a swipe, numerous boxes are then created after each other, therefore, creating a line.

 

My question is, since I'm basing this over the Gesture sample application, where only one screen is used (I am intending to leave it as one screen), why doesn't my "drawing" appear over the background image already in place? 

 

The Gesture sample app used this function to load the image:

 

int
load_image(screen_window_t screen_win, const char *path)
{
    img_decode_callouts_t callouts;
    img_lib_t ilib = NULL;
    img_t img;
    int rc;

    rc = img_lib_attach(&ilib);
    if (rc != IMG_ERR_OK) {
        return -1;
    }

    memset(&img, 0, sizeof(img));
    img.flags |= IMG_FORMAT;
    img.format = IMG_FMT_PKLE_XRGB8888;

    memset(&callouts, 0, sizeof(callouts));
    callouts.setup_f = decode_setup;
    callouts.abort_f = decode_abort;
    callouts.data = (uintptr_t)screen_win;

    rc = img_load_file(ilib, path, &callouts, &img);
    img_lib_detach(ilib);

    return rc == IMG_ERR_OK ? 0 : -1;
}

 

Where decode_setup and decode_abort are:

 

static int decode_setup(uintptr_t data, img_t *img, unsigned flags)
{
    screen_window_t screen_win = (screen_window_t)data;
    screen_buffer_t screen_buf;
    int size[2];

    size[0] = img->w;
    size[1] = img->h;
    screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);
    screen_create_window_buffers(screen_win, 1);

    screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf);
    screen_get_buffer_property_pv(screen_buf, SCREEN_PROPERTY_POINTER, (void **)&img->access.direct.data);
    screen_get_buffer_property_iv(screen_buf, SCREEN_PROPERTY_STRIDE, (int *)&img->access.direct.stride);

    img->flags |= IMG_DIRECT;
    return IMG_ERR_OK;
}

static void decode_abort(uintptr_t data, img_t *img)
{
    screen_window_t screen_win = (screen_window_t)data;
    screen_destroy_window_buffers(screen_win);
}

 

Using my function above (from Case Gesture_Swipe), shouldn't the "boxes" appear over the background image since it is replacing the buffer taken by the image loading? All I am seeing is the image and the x and y locations as messages form the debugging process.

 

Previously, which used to work, is other than loading the image, I would create a WHITE screen fill in the main (as a whiteboard for instance). This used to work. However, with the image fiasca I am not seeing anything. May someone help me with what I am doing?

 

Thanks,

A27med

New Contributor
a27med
Posts: 6
Registered: ‎03-12-2012
My Device: Non

Re: Background Image for Drawing Application

Apparently, all I did was fill the screen with a WHITE background then load the image during the main. This solved the problem for me :smileyhappy:

Developer
fracobx19
Posts: 35
Registered: ‎11-17-2013
My Device: Blackberry Simulator 10.2

Re: Background Image for Drawing Application

Hi!

 

Basically I would like to do the same that you, but I'm beginnig so, I would like you (or somebody else) to tell me what is that Gesture sample app you say your app is based on. Because I can't find it.

 

That would be really helpful. Thanks!