Hello,
I'm making a slideshow and would like to make use of a window to
output an title on top of the image. (on a 50% transparent background)
I'm somewhat new to DirectFB and the problem I'm facing is,
the window I've drawn on top of my primary layer has its own black
background.
How would I make this black background transparent?
Just to make the situation a little clearer, I'm not having any problems
drawing transparent objects onto the window surface. My problem is that,
there is a black background of my window object that I cant seem to get
transparent.
Any help would be appreciated
Daniel
(I've attached the source code)
#include <directfb.h>
#include <direct/util.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
/* macro for a safe call to DirectFB functions */
#define DFBCHECK(x...) \
{ \
err = x; \
if (err != DFB_OK) { \
fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ );
\
DirectFBErrorFatal( #x, err );
\
} \
}
static IDirectFB *dfb;
static IDirectFBSurface *primary;
static IDirectFBSurface *background;
static IDirectFBImageProvider *provider;
static IDirectFBFont *font;
static IDirectFBWindow *window;
static IDirectFBSurface *window_surface;
static IDirectFBDisplayLayer *layer;
static int xres;
static int yres;
static int fontheight;
char *inputFile[] = {"img1.jpg","img2.jpg",NULL};
static void init_resources(int argc, char *argv[])
{
DFBResult err;
DFBSurfaceDescription dsc;
DFBCHECK(DirectFBInit(&argc, &argv));
DFBCHECK(DirectFBCreate(&dfb));
dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer );
layer->SetCooperativeLevel( layer, DLSCL_ADMINISTRATIVE );
// layer->SetBackgroundColor( layer, 0, 130, 0, 0 );
// layer->SetOpacity(layer, 122);
layer->GetSurface(layer, &primary);
primary->SetDrawingFlags(primary, DSDRAW_BLEND);
DFBCHECK(primary->GetSize(primary, &xres, &yres));
// load font
{
DFBFontDescription desc;
desc.flags = DFDESC_HEIGHT;
desc.height = 24;
DFBCHECK(dfb->CreateFont(dfb, FONT, &desc, &font));
DFBCHECK(font->GetHeight(font, &fontheight));
DFBCHECK(primary->SetFont(primary, font));
}
// create offscreen buffer
dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT;
dsc.width = xres;
dsc.height = yres;
DFBCHECK(dfb->CreateSurface(dfb, &dsc, &background));
// create window
DFBWindowDescription desc;
desc.flags = ( DWDESC_POSX | DWDESC_POSY | DWDESC_WIDTH |
DWDESC_HEIGHT | DWDESC_CAPS );
desc.posx = 100;
desc.posy = 100;
desc.width = 250;
desc.height = 250;
desc.caps = DWCAPS_ALPHACHANNEL;
layer->CreateWindow(layer, &desc, &window);
window->GetSurface(window, &window_surface);
// window->SetOpacity(window, 122);
}
static void deinit_resources()
{
background->Release(background);
primary->Release(primary);
font->Release(font);
dfb->Release(dfb);
}
static void onscreen_text(char* img_path, int x, int y, int w, int h)
{
char buf[128];
primary->SetColor(primary, 125, 0, 0, 0xa0);
primary->FillRectangle(primary, x, y, w, fontheight+5);
sprintf(buf, "Now displaying: %s", img_path);
primary->SetColor(primary, 255, 255, 255, 0xFF);
primary->DrawString(primary, buf, -1, 10, 0, DSTF_LEFT | DSTF_TOP);
}
int main(int argc, char *argv[])
{
int i,j;
char img_path[128];
if (argc != 2)
{
printf("usage: %s <steps>\n", argv[0]);
return -1;
}
init_resources(argc, argv);
int total_boxes = atoi(argv[1]);
int one_row = sqrt(total_boxes);
DFBRectangle imgArea;
imgArea.x = 0;
imgArea.y = 0;
imgArea.w = 800 / one_row;
imgArea.h = 600 / one_row;
int position_x;
int position_y;
// main loop
while (1) {
for(j=0; NULL != inputFile[j]; j++) {
sprintf(img_path, "./%s", inputFile[j]); // set
filename as title
dfb->CreateImageProvider(dfb, img_path, &provider);
provider->RenderTo(provider, background, NULL);
provider->Release(provider);
for (i=0; i<total_boxes; ++i)
{
position_x = i % one_row;
position_y = (i-position_x) / one_row;
if (position_x != 0)
position_x *= imgArea.w;
if (position_y != 0)
position_y *= imgArea.h;
imgArea.x = position_x;
imgArea.y = position_y;
primary->Blit(primary, background, &imgArea,
position_x,
position_y);
if (i < one_row) // only update title and bg
when needed
onscreen_text(img_path, position_x,
position_y, imgArea.w,
imgArea.h);
primary->Flip(primary, NULL,
DSFLIP_WAITFORSYNC);
window->SetOpacity(window, 128);
window_surface->SetColor( window_surface, 255,
0, 0, 128);
window_surface->FillRectangle( window_surface,
0, 0, 100, 100 );
window_surface->Flip (window_surface, NULL, 0);
sleep(1);
}
sleep(1);
}
}
deinit_resources();
return 1;
}
_______________________________________________
directfb-dev mailing list
[email protected]
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-dev