X-Git-Url: https://hackdaworld.org/gitweb/?p=lectures%2Fdfb-slides.git;a=blobdiff_plain;f=render.c;fp=render.c;h=883693a4047d40d726bff71cd352dc315bb08dce;hp=0000000000000000000000000000000000000000;hb=56d4b0f73d20f1104a304573aac565db10446262;hpb=dd74245a5f1d1e5b9449cd5e41f56d5929ddf462 diff --git a/render.c b/render.c new file mode 100644 index 0000000..883693a --- /dev/null +++ b/render.c @@ -0,0 +1,230 @@ +/* DirectFB presentation app + * + * Copyright (C) 2001 convergence integrated media + * Authors: Sven Neumann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +#include +#include + +#include + +#include + +#include "apptypes.h" + +#include "action.h" +#include "context.h" +#include "header.h" +#include "image.h" +#include "listitem.h" +#include "render.h" +#include "resources.h" +#include "slides.h" +#include "slide.h" +#include "text.h" +#include "video.h" + + +static void render_bullet (Context *context, + gint *offx, + gint offy); + +void +render_bg (Context *context) +{ + guchar *color; + + color = context_get_bgcolor (context); + context->surface->SetColor (context->surface, + color[0], color[1], color[2], color[3]); + context->surface->FillRectangle (context->surface, + 0, 0, context->w, context->h); +} + +void +render_bgimage (Context *context) +{ + gchar *image; + + image = context_get_bgimage (context); + if (image) + { + IDirectFBSurface *src; + gint w, h; + + src = resources_get_surface (image); + if (!src) + return; + + src->GetSize (src, &w, &h); + + if (w == context->w && h == context->h) + { + context->surface->Blit (context->surface, src, NULL, 0, 0); + } + else + { + DFBRectangle rect = { 0, 0, context->w, context->h }; + + context->surface->StretchBlit (context->surface, + src, NULL, &rect); + } + + resources_release_surface (image); + } +} + +void +render_image (Context *context, + Image *image) +{ + Item *item; + IDirectFBSurface *src; + DFBRectangle rect; + DFBSurfacePixelFormat format; + gint w, h, ratio; + + if (IS_VIDEO (image)) + { + Video *video; + + video = (Video *) image; + video->dest_surface = context->surface; + + return; + } + + src = resources_get_surface (ITEM (image)->value); + + if (!src) + return; + + src->GetSize (src, &w, &h); + src->GetPixelFormat (src, &format); + + if (format == DSPF_ARGB) + context->surface->SetBlittingFlags (context->surface, + DSBLIT_BLEND_ALPHACHANNEL); + + ratio = (w * 1024) / h; + item = (Item *) image; + + rect.w = item->flags & WIDTH ? + item->width : (item->flags & HEIGHT ? (item->height * ratio) / 1024 : w); + rect.h = item->flags & HEIGHT ? + item->height : (item->flags & WIDTH ? (item->width * 1024) / ratio : h); + + rect.x = item->flags & XOFFSET ? item->x : 0; + rect.y = item->flags & YOFFSET ? item->y : 0; + + if (format == DSPF_ARGB) + context->surface->SetBlittingFlags (context->surface, + DSBLIT_BLEND_ALPHACHANNEL); + + if (w == rect.w || h == rect.h) + context->surface->Blit (context->surface, src, NULL, rect.x, rect.y); + else + context->surface->StretchBlit (context->surface, src, NULL, &rect); + + context->surface->SetBlittingFlags (context->surface, DSBLIT_NOFX); + + resources_release_surface (ITEM (image)->value); +} + +void +render_text (Context *context, + Text *text, + gint *offy) +{ + guchar *color; + gchar *face; + gint size; + gint offx; + IDirectFBFont *font; + + context_push (context, (Item *) text); + + color = context_get_fgcolor (context); + context->surface->SetColor (context->surface, + color[0], color[1], color[2], color[3]); + + face = context_get_face (context); + size = context_get_size (context); + + g_return_if_fail (face != NULL); + g_return_if_fail (size > 0); + + offx = 10; + + if (IS_HEADER (text)) + size = (size * 64) / 52; + else if (IS_LISTITEM (text)) + size = (size * 48) / 64; + else + offx+=40; + + font = resources_get_font (face, size); + + if (IS_LISTITEM (text)) + { + gint asc; + + font->GetAscender (font, &asc); + render_bullet (context, &offx, *offy + asc); + } + + context->surface->SetFont (context->surface, font); + context->surface->DrawString (context->surface, + ITEM (text)->value, -1, + offx, *offy, DSTF_TOPLEFT); + + *offy += (size * 64) / 48; + + context_pop (context, (Item *) text); +} + +static void +render_bullet (Context *context, + gint *offx, + gint offy) +{ + IDirectFBSurface *src; + gchar *image; + gint w, h; + + image = context_get_bullet (context); + if (image) + { + src = resources_get_surface (image); + if (!src) + return; + + src->GetSize (src, &w, &h); + + context->surface->SetBlittingFlags (context->surface, + DSBLIT_BLEND_ALPHACHANNEL); + context->surface->Blit (context->surface, + src, NULL, *offx + 20, offy - h); + context->surface->SetBlittingFlags (context->surface, DSBLIT_NOFX); + + resources_release_surface (image); + + *offx += w + 24; + } +}