OpenQNX :: The QNX Community Portal

Oct 07, 2008 - 11:30 AM
Google
  Web openqnx.com   
     Create an account Home · Submit News · QNX Forums · QNX Download · Search   
_
Main Menu
Who's Online
There are 54 unlogged users and 0 registered users online.

You can log-in or register for a user account here.

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
copperleaf
Post subject: PtRegion with Alpha Channel  PostPosted: Feb 18, 2008 - 02:06 PM
New Member


Joined: Jan 13, 2005
Posts: 9
Location: Richmond, VA
I want to create a region in a small app that covers the entire screen but shows whatever is behind at 50% opacity. I'm able to go full screen, but when I try and do a fill with PgARGB(128, 0, 0, 0) it is still 100% opaque. Here is the code I'm playing with:
Code:

     if((p = getenv("PHIG")))
        input_group = atoi(p);
 
     PhQueryRids(0, 0, input_group, Ph_INPUTGROUP_REGION, 0, 0, 0, &rid, 1);
     PhRegionQuery(rid, &region, &rect, NULL, 0);
     PhWindowQueryVisible(Ph_QUERY_INPUT_GROUP | Ph_QUERY_EXACT, 0, region.input_group, &rect);
     PhRectToArea(&rect, &area);

     raw_cb.event_f = clickCB;
     raw_cb.event_mask = input_events;
     raw_cb.data = 0;

    PgSetColorModel(Pg_CM_ARGB);

    PtSetArg( &args[n++], Pt_ARG_AREA, &area, 0 );
    PtSetArg( &args[n++], Pt_ARG_REGION_SENSE, -1, input_events);
    PtSetArg( &args[n++], Pt_ARG_REGION_OPAQUE, -1, Ph_EV_PTR_ALL | Ph_EV_EXPOSE | Ph_EV_DRAW);
    PtSetArg( &args[n++], Pt_ARG_FILL_COLOR, PgARGB(128,0,0,0), 0 );
    PtSetArg( &args[n++], Pt_ARG_REGION_FIELDS, -1, Ph_REGION_ORIGIN
            | Ph_REGION_RECT | Ph_REGION_EV_SENSE | Ph_REGION_EV_OPAQUE
            | Ph_REGION_PARENT | Ph_REGION_FLAGS );
    PtSetArg( &args[n++], Pt_ARG_REGION_FLAGS, -1, Ph_FORCE_FRONT );
    PtSetArg( &args[n++], Pt_ARG_REGION_PARENT, 0, 0 );
     PtSetArg(&args[n++], Pt_ARG_REGION_INPUT_GROUP, region.input_group, 0);
     PtSetArg(&args[n++], Pt_ARG_REGION_INFRONT, Ph_DEV_RID, 0);
    PtSetParentWidget( NULL );               
    frame = PtCreateWidget( PtRegion, NULL, n, args );
 


I've event tried painting the region with PgTRANSPARENT and drawing a label with 50% fill, but has the same result.

Is there any way to do this?

TIA,
Bill
 
 View user's profile Send private message  
Reply with quote Back to top
ysinitsky
Post subject: RE: PtRegion with Alpha Channel  PostPosted: Apr 07, 2008 - 06:28 PM
Senior Member


Joined: Dec 14, 2005
Posts: 131

“I want to create a region in a small app that covers the entire screen but shows whatever is behind at 50% opacity”

Hello Copperleaf,
There is an interesting example in description of PhRegionOpen().
It looks like after a small modification (please see below) it provides the required functionality.
Thanks,
Yuriy
--------
#include <stdio.h>
#include <Ph.h>

PhRid_t open_region( void )
{
PhRegion_t region;
PhRect_t rect;
PhRid_t rid;

memset(&region, 0, sizeof(region));
/* Wish to have pointer motion
* events enqueued to us.
*/
region.events_sense = Ph_EV_PTR_MOTION |
Ph_EV_BUT_RELEASE;

/* Wish to be opaque to all pointer-type
* events.
*/
region.events_opaque = Ph_EV_PTR_ALL | Ph_EV_DRAW |
Ph_EV_EXPOSE;
/* Origin at (0,0) relative to root */
region.origin.x = region.origin.y = 0;
region.parent = Ph_ROOT_RID;



if (PhWindowQueryVisible(Ph_QUERY_INPUT_GROUP | Ph_QUERY_EXACT, 0, region.input_group, &rect)== 0 )
{
printf( "Upper left: (%d,%d) Lower right: (%d,%d)\n",
rect.ul.x, rect.ul.y,
rect.lr.x, rect.lr.y );

}else
{
perror( "PhWindowQueryVisible" );
return 1;

}
rect.ul.x = rect.ul.y = 0;
rect.lr.x = rect.lr.x ;
rect.lr.y = rect.lr.y;

rid = PhRegionOpen( Ph_REGION_PARENT |
Ph_REGION_EV_SENSE |
Ph_REGION_EV_OPAQUE |
Ph_REGION_ORIGIN |
Ph_REGION_RECT,
&region, &rect, NULL );

/* If open was successful, make the region semitransparent region */
if( rid != -1 ) {

PgSetRegion( rid );
PgSetFillColor( Pg_RED );
PgSetFillTransPat( Pg_PAT_HALF );
PgDrawRect( &rect, Pg_DRAW_FILL );

PgFlush();
}
return( rid );
}

void draw_at_cursor( PhPoint_t *pos )
{
PhRect_t rect;
static int count = 0;

rect.ul.x = pos->x - 10;
rect.ul.y = pos->y - 10;
rect.lr.x = pos->x + 10;
rect.lr.y = pos->y + 10;
switch( ++ count % 3 ) {
case 0:
PgSetFillColor( Pg_RED );
break;
case 1:
PgSetFillColor( Pg_GREEN );
break;
default:
PgSetFillColor( Pg_BLUE );
}
PgDrawRect( &rect, Pg_DRAW_FILL );
PgFlush();
}

int main( int argc, char *argv[] )
{
PhEvent_t *event;
int go = 1;

if( NULL == PhAttach( NULL, NULL ) ) {
fprintf( stderr, "Couldn't attach a "
"Photon channel.\n" );
exit( EXIT_FAILURE );
}

if( -1 == open_region() ) {
fprintf( stderr, "Couldn't open region.\n" );
exit( EXIT_FAILURE );
}
event = (PhEvent_t *)malloc( sizeof( PhEvent_t )
+ 1000 );
if( event == NULL ) {
fprintf( stderr,
"Couldn't allocate event buffer.\n" );
exit( EXIT_FAILURE );
}
while( go ) {
if( PhEventNext( event, sizeof( PhEvent_t )
+ 1000 ) == Ph_EVENT_MSG ) {
if( (event->type & Ph_EV_PTR_MOTION) != 0 )
draw_at_cursor(
(PhPoint_t *)PhGetRects( event ) );
else
go = 0;
} else
fprintf( stderr, "Error.\n" );
}

return 0;
}
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group
Credits
All logos and trademarks in this site are property of their respective owners. The comments are property of their posters.
Powered by OpenQNX: The QNX Community Portal Site
QNX and the QNX logo are registered trademarks of QNX Software Systems.