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
Contributor
Jkanold
Posts: 15
Registered: ‎03-03-2012
My Device: Playbook

screen_blit

I am having problems with Blits. The below code works if pasted into the Gesture sample. But doeas not seem to work if pasted into HelloWorldDisplay. I don't get why. I have played with negative numbers and such. That leads me to a rookie question. Can I print to the screen without initiating Open GL? 

 

Also the scaling described below does not work. The blit only works if the destination size matches the source size.

 

if I change 

SCREEN_BLIT_DESTINATION_WIDTH, 100,

to

SCREEN_BLIT_DESTINATION_WIDTH, 150,

The blit does nothing???

 

The documentation says that scaling is possible...

SCREEN_BLIT_DESTINATION_WIDTHThe following element contains the width of the rectangle into the destination buffer that defines the area that will be copied into. The width is in pixels. The width does not have to match the source width. If the destination width is larger, the source rectangle will be stretched. If the destination width is smaller than the source width, the image will be compressed.

 

int hg[] = {
SCREEN_BLIT_SOURCE_WIDTH,100,
SCREEN_BLIT_SOURCE_HEIGHT,100,
SCREEN_BLIT_DESTINATION_X, 500,
SCREEN_BLIT_DESTINATION_Y, 300,
SCREEN_BLIT_SOURCE_X, 0,
SCREEN_BLIT_SOURCE_Y, 800,
SCREEN_BLIT_DESTINATION_WIDTH, 100,
SCREEN_BLIT_DESTINATION_HEIGHT, 100,
SCREEN_BLIT_END
};
screen_blit(screen_ctx, screen_buf, screen_buf, hg);

Developer
mmd12
Posts: 117
Registered: ‎03-13-2012
My Device: Playbook, Dev Alpha C, Q10, Z10

Re: screen_blit

I can't really address your questions, but I'm curious what you're trying to achieve.

 

Specifically with,

 

SCREEN_BLIT_SOURCE_X, 0,
SCREEN_BLIT_SOURCE_Y, 800

 

If your soucre is a 100 x 100 pixmap. why are you specifying a start of y = 800?

 

and

 

screen_blit(screen_ctx, screen_buf, screen_buf, hg);

 

You seem to be bliting to and from the same buffer (screen_buf).  I'm pretty sure that's not what you want.

Contributor
Jkanold
Posts: 15
Registered: ‎03-03-2012
My Device: Playbook

Re: screen_blit

I have loaded a large image. The view port is a smaller part of the image (1024 x 600) I then move a rectangle which is off the screen, onto the screen.

Developer
mmd12
Posts: 117
Registered: ‎03-13-2012
My Device: Playbook, Dev Alpha C, Q10, Z10

Re: screen_blit

OK.

 

Have you tried not using screen_buf as both the source and destination buffer in your screen_blit call?

Contributor
Jkanold
Posts: 15
Registered: ‎03-03-2012
My Device: Playbook

Re: screen_blit

thought I might share some poorly written code which may help others with blits..

It is a simple demo to drag a square from the screen around.

 


#include <assert.h>
#include <bps/navigator.h>
#include <bps/screen.h>
#include <bps/bps.h>
#include <bps/event.h>
#include <bps/soundplayer.h>
#include <bps/orientation.h>
#include <math.h>
#include <screen/screen.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "gestures/tap.h"
#include <time.h>

int size[2] = { 100, 100 };
int rect[4] = { 0, 0 };
int drawscreen = 0;
int shutdown;
int stride = 0;
screen_context_t screen_ctx;
screen_window_t screen_win;
screen_buffer_t screen_buf[2];
screen_buffer_t screen_pbuf;


static void mode1(bps_event_t *event) {
int screen_val, buttons,ii,x,y,s,c,r,cs1,cs2;
int x1,y1,h1,w1,c2;
float ix,iy,h,w;
int pair[2];
static bool mouse_pressed = false;
screen_event_t screen_event = screen_event_get_event(event);
screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE,
&screen_val);
screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_SOURCE_POSITION,
pair);
int hg1[] = {
SCREEN_BLIT_SOURCE_X, 0,
SCREEN_BLIT_SOURCE_Y, 0,
SCREEN_BLIT_SOURCE_WIDTH,1020,
SCREEN_BLIT_SOURCE_HEIGHT,580,
SCREEN_BLIT_DESTINATION_X,0,
SCREEN_BLIT_DESTINATION_Y, 0,
SCREEN_BLIT_DESTINATION_WIDTH, 1020,
SCREEN_BLIT_DESTINATION_HEIGHT, 580,
SCREEN_BLIT_END
};
screen_blit(screen_ctx, screen_buf[1], screen_buf[0], hg1);

//There is a difference between touch screen events and mouse events
if (screen_val == SCREEN_EVENT_MTOUCH_TOUCH) {
//This is touch screen event.
screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE,&screen_val);
screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_SOURCE_POSITION,pair);
x=(float) pair[0];
y=(float) pair[1];
x1=(float) pair[0];
y1=(float) pair[1];
w=100;
h=100;


while (screen_val != SCREEN_EVENT_MTOUCH_RELEASE) {
ii = bps_get_event(&event, 0);
screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE,&screen_val);
screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_SOURCE_POSITION,pair);

int hg[] = {
SCREEN_BLIT_SOURCE_X, x1,
SCREEN_BLIT_SOURCE_Y, y1,
SCREEN_BLIT_SOURCE_WIDTH,w1,
SCREEN_BLIT_SOURCE_HEIGHT,h1,
SCREEN_BLIT_DESTINATION_X,x1,
SCREEN_BLIT_DESTINATION_Y, y1,
SCREEN_BLIT_DESTINATION_WIDTH, w1,
SCREEN_BLIT_DESTINATION_HEIGHT, h1,
SCREEN_BLIT_END
};
screen_blit(screen_ctx, screen_buf[0], screen_buf[1], hg);
x1=(float) pair[0];
y1=(float) pair[1];
w1=w;
h1=h;
if(x1<0){w1=x1+w;x1=0;}
if(y1<0){h1=y1+h;y1=0;}
if(x1+w>1022){w1=1022-x1;}
if(y1+h>598){h1=598-y1;}
int hg2[] = {
SCREEN_BLIT_SOURCE_X, x,
SCREEN_BLIT_SOURCE_Y, y,
SCREEN_BLIT_SOURCE_WIDTH,w1,
SCREEN_BLIT_SOURCE_HEIGHT,h1,
SCREEN_BLIT_DESTINATION_X,x1,
SCREEN_BLIT_DESTINATION_Y, y1,
SCREEN_BLIT_DESTINATION_WIDTH, w1,
SCREEN_BLIT_DESTINATION_HEIGHT, h1,
SCREEN_BLIT_END
};
screen_blit(screen_ctx, screen_buf[0], screen_buf[1], hg2);

screen_post_window(screen_win, screen_buf[0], 1, rect, 0);

}


}
}


static void handleNavigatorEvent(bps_event_t *event) {
int rc,angle;
bps_event_t *activation_event = NULL;

switch (bps_event_get_code(event)) {
case NAVIGATOR_ORIENTATION_CHECK:
//Signal navigator that we intend to resize
navigator_orientation_check_response(event, true);
break;
case NAVIGATOR_ORIENTATION:
angle = navigator_event_get_orientation_angle(event);
//Let bbutil rotate current screen surface to this angle
navigator_done_orientation(event);
break;
case NAVIGATOR_SWIPE_DOWN:
break;
case NAVIGATOR_EXIT:
shutdown = true;
break;
case NAVIGATOR_WINDOW_INACTIVE:
//Wait for NAVIGATOR_WINDOW_ACTIVE event
for (;:smileywink: {
rc = bps_get_event(&activation_event, -1);
assert(rc == BPS_SUCCESS);
if (bps_event_get_code(activation_event)
== NAVIGATOR_WINDOW_ACTIVE) {
break;
}
}
break;
}
}
static void handle_events() {
int screen_domain = screen_get_domain();
int navigator_domain = navigator_get_domain();
// int sensor_domain = sensor_get_domain();

int rc;

//Request and process available BPS events
for(;:smileywink: {
bps_event_t *event = NULL;
rc = bps_get_event(&event, 0);
assert(rc == BPS_SUCCESS);

if (event) {
int domain = bps_event_get_domain(event);

if (domain == screen_domain) {
mode1(event);
} else if (domain == navigator_domain) {
handleNavigatorEvent(event);
// } else if (domain == sensor_domain) {
// handleSensorEvent(event);
}
} else {
//No more events in the queue
break;
}
}
}

void render(){
srandom(time(NULL));
int x,y,w,h,c,any;
for (any = 0; any < 4224; any++){
x=random()% 1000;
y=random()% 1000;
h=random()% 100+4;
w=random()% 100+4;
c=random() % 0xffffffff;
int bar[] = {
SCREEN_BLIT_COLOR, 0xff000000,
SCREEN_BLIT_DESTINATION_X, x,
SCREEN_BLIT_DESTINATION_WIDTH, w+2,
SCREEN_BLIT_DESTINATION_Y,y,
SCREEN_BLIT_DESTINATION_HEIGHT, h+2,
SCREEN_BLIT_END };

screen_fill(screen_ctx, screen_buf[0], bar);
int bar2[] = {
// SCREEN_BLIT_COLOR, 0xffffffff,
SCREEN_BLIT_COLOR, c,
SCREEN_BLIT_DESTINATION_X, x+1,
SCREEN_BLIT_DESTINATION_WIDTH, w,
SCREEN_BLIT_DESTINATION_Y,y+1,
SCREEN_BLIT_DESTINATION_HEIGHT, h,
SCREEN_BLIT_END };
screen_fill(screen_ctx, screen_buf[0], bar2);
screen_post_window(screen_win, screen_buf[0], 1, rect, 0);
}
}
int main(int argc, char **argv)
{
int i, j, any, pos = 0;
screen_create_context(&screen_ctx, SCREEN_APPLICATION_CONTEXT);
bps_initialize();
navigator_rotation_lock(true);
screen_create_window(&screen_win, screen_ctx);
int usage = SCREEN_USAGE_NATIVE;
screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage);
screen_create_window_buffers(screen_win, 2);
screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, rect+2);
if (BPS_SUCCESS != screen_request_events(screen_ctx)) {
fprintf(stderr, "screen_request_events failed\n");
screen_destroy_context(screen_ctx);
return 0;
}

if (BPS_SUCCESS != navigator_request_events(0)) {
fprintf(stderr, "navigator_request_events failed\n");
screen_destroy_context(screen_ctx);
return 0;
}
screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)screen_buf);
int bg[] = { SCREEN_BLIT_COLOR, 0xffffff00, SCREEN_BLIT_END };
screen_fill(screen_ctx, screen_buf[0], bg);
render();
while (1) {
handle_events();
}

return EXIT_SUCCESS;
}