/* ghosd -- OSD with fake transparency, cairo, and pango. * Copyright (C) 2006 Evan Martin <martine@danga.com> */ #include <stdio.h> #include <math.h> #include <cairo/cairo.h> #include <unistd.h> #include <ghosd/ghosd.h> #include "example-shared.h" #define MARGIN 10 #define RADIUS 20 #define WIDTH 185 #define HEIGHT 220 char displayText[200] = "default message"; static void render(Ghosd *ghosd, cairo_t *cr, void* data) { cairo_surface_t* image = data; const int width = cairo_image_surface_get_width(image); const int height = cairo_image_surface_get_height(image); cairo_set_source_rgba(cr, 0, 0, 0, 0.5); cairo_new_path(cr); example_round_rect(cr, 0, 0, width+(2*MARGIN), height+(2*MARGIN), RADIUS); cairo_fill(cr); cairo_save(cr); cairo_set_source_surface(cr, image, MARGIN, MARGIN); cairo_paint_with_alpha(cr, 0.9); cairo_restore(cr); cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size (cr, 90.0); // cairo_move_to (cr, 10.0, 135.0); // cairo_show_text (cr, "Hello"); cairo_move_to (cr, 70.0, 165.0); cairo_text_path (cr, displayText); cairo_set_source_rgb (cr, 1.5, 1.5, 1); cairo_fill_preserve (cr); cairo_set_source_rgb (cr, 0, 0, 0); cairo_set_line_width (cr, 2.56); cairo_stroke (cr); } int main(int argc, char* argv[]) { //g_type_init(); char *filename = NULL; GOptionEntry options[] = { { "image", 'i', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, (gpointer)&filename, "image to display", "PATH" }, { NULL } }; GOptionGroup *group = g_option_group_new("image", "Image Options", "image help", NULL, NULL); g_option_group_add_entries(group, options); example_options_parse(&argc, &argv, group, NULL); if (filename == NULL) { printf("must specify image with -i flag.\n" "try e.g. /usr/share/pixmaps/gnome-logo-large.png\n"); return 1; } if( argc == 2 ) { sprintf(displayText, argv[1]); } Ghosd *ghosd; cairo_surface_t* image = cairo_image_surface_create_from_png(filename); const int width = cairo_image_surface_get_width(image); const int height = cairo_image_surface_get_height(image); ghosd = ghosd_new(); ghosd_set_transparent(ghosd, opts.transparent); ghosd_set_position(ghosd, opts.x, opts.y, width+(2*MARGIN), height+(2*MARGIN)); ghosd_set_render(ghosd, render, image); ghosd_flash(ghosd, 1300, 6500); return 0; } /* vim: set ts=2 sw=2 et cino=(0 : */