comparison src/aosd/aosd_ui.c.old @ 569:d401f87f89f7 trunk

[svn] - added Audacious OSD, yet-another-written-from-scratch plugin to display OSD, based on Ghosd library; currently untied from configure, to compile it you have to run make in its directory; will be added to configure after some testing
author giacomo
date Mon, 29 Jan 2007 06:40:04 -0800
parents
children
comparison
equal deleted inserted replaced
568:8c64b5abdcda 569:d401f87f89f7
1 /*
2 *
3 * Author: Giacomo Lozito <james@develia.org>, (C) 2005-2007
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21 #include "aosd_ui.h"
22 #include <glib.h>
23 #include <gdk/gdk.h>
24 #include <gtk/gtk.h>
25
26
27 gint
28 aosd_display_osd ( void )
29 {
30 GtkWidget *osd_win;
31 GtkWidget *osd_darea;
32 PangoLayout *osd_layout;
33 PangoFontDescription *osd_fontdesc;
34 GdkPixmap *osd_darea_pixmap, *osd_darea_bitmap;
35 GdkGC *osd_darea_gc;
36 GdkColor fg_color, bg_color, bitmap_color;
37 GdkColormap *bitmap_colormap;
38 gint max_width = 0, border_width = 1;
39 gint width = 0, height = 0;
40 gint off_x = 0, off_y = 0;
41 PangoAlignment osd_alignment = PANGO_ALIGN_CENTER;
42 gboolean translucent_bg = TRUE;
43
44 osd_win = gtk_window_new( GTK_WINDOW_POPUP );
45 gtk_widget_add_events( osd_win , GDK_ENTER_NOTIFY_MASK );
46 gtk_widget_realize( osd_win );
47
48 osd_darea = gtk_drawing_area_new();
49 gtk_container_add( GTK_CONTAINER(osd_win) , osd_darea );
50 gtk_widget_show( osd_darea );
51
52 osd_fontdesc = pango_font_description_from_string("Courier,Mono 28");
53
54 osd_layout = gtk_widget_create_pango_layout( osd_darea , "AUDACIOUS OSD 0.1 by Giacomo" );
55 pango_layout_set_ellipsize( osd_layout , PANGO_ELLIPSIZE_NONE );
56 pango_layout_set_justify( osd_layout , FALSE );
57 pango_layout_set_alignment( osd_layout , osd_alignment );
58 pango_layout_set_font_description( osd_layout , osd_fontdesc );
59
60 max_width = gdk_screen_get_width( gdk_screen_get_default() ) - 8;
61 pango_layout_set_width( osd_layout , PANGO_SCALE * max_width );
62 pango_layout_get_pixel_size( osd_layout , &width , &height );
63
64 off_x = border_width * 2;
65 off_y = border_width * 2;
66
67 if ( osd_alignment == PANGO_ALIGN_CENTER )
68 off_x -= max_width/2 - width/2;
69 else if ( osd_alignment == PANGO_ALIGN_RIGHT )
70 off_x -= max_width - width;
71
72 width += border_width * 4;
73 height += border_width * 4;
74
75 gtk_widget_set_size_request( osd_darea , width , height );
76 gtk_widget_realize( osd_darea );
77
78 osd_darea_pixmap = gdk_pixmap_new( GDK_DRAWABLE(osd_darea->window) , width , height , -1 );
79
80 osd_darea_gc = gdk_gc_new( GDK_DRAWABLE(osd_darea_pixmap) );
81 gdk_gc_copy( osd_darea_gc , osd_darea->style->fg_gc[GTK_STATE_NORMAL] );
82
83 gdk_color_parse( "Blue" , &fg_color ); /* TODO pass color as function param */
84 gdk_color_parse( "White" , &bg_color ); /* TODO pass color as function param */
85
86 gdk_gc_set_rgb_fg_color( osd_darea_gc , &bg_color );
87 gdk_draw_rectangle( GDK_DRAWABLE(osd_darea_pixmap) , osd_darea_gc , TRUE ,
88 0 , 0 , width , height );
89 gdk_gc_set_rgb_fg_color( osd_darea_gc , &fg_color );
90 gdk_draw_layout( GDK_DRAWABLE(osd_darea_pixmap) , osd_darea_gc , off_x , off_y , osd_layout );
91 g_object_unref( osd_darea_gc );
92
93 osd_darea_bitmap = gdk_pixmap_new( GDK_DRAWABLE(osd_darea->window) , width , height , 1 );
94 osd_darea_gc = gdk_gc_new( GDK_DRAWABLE(osd_darea_bitmap) );
95
96 /* gdk will complain if we don't pass a colormap to osd_darea_gc */
97 gdk_gc_set_colormap( osd_darea_gc , gdk_colormap_get_system() );
98
99 bitmap_color.pixel = 0;
100 gdk_gc_set_foreground( osd_darea_gc , &bitmap_color );
101
102 if ( translucent_bg == TRUE )
103 {
104 gint w = 2, h = 2;
105 GdkPixmap *stipple_bitmap;
106
107 stipple_bitmap = gdk_pixmap_new( NULL , w , h , 1 );
108 bitmap_color.pixel = 0; gdk_gc_set_foreground( osd_darea_gc , &bitmap_color );
109 gdk_draw_rectangle( GDK_DRAWABLE(stipple_bitmap) , osd_darea_gc , TRUE , 0 , 0 , w , h );
110 bitmap_color.pixel = 1; gdk_gc_set_foreground( osd_darea_gc , &bitmap_color );
111 gdk_draw_point( GDK_DRAWABLE(stipple_bitmap) , osd_darea_gc , 0 , 0 );
112 gdk_draw_point( GDK_DRAWABLE(stipple_bitmap) , osd_darea_gc , 1 , 1 );
113 bitmap_color.pixel = 0; gdk_gc_set_foreground( osd_darea_gc , &bitmap_color );
114 gdk_draw_rectangle( GDK_DRAWABLE(osd_darea_bitmap) , osd_darea_gc , TRUE ,
115 0 , 0 , width , height );
116 gdk_gc_set_stipple( osd_darea_gc , stipple_bitmap );
117 gdk_gc_set_fill( osd_darea_gc , GDK_STIPPLED );
118 bitmap_color.pixel = 1; gdk_gc_set_foreground( osd_darea_gc , &bitmap_color );
119 gdk_draw_rectangle( GDK_DRAWABLE(osd_darea_bitmap) , osd_darea_gc , TRUE ,
120 0 , 0 , width , height );
121 gdk_gc_set_fill( osd_darea_gc , GDK_SOLID );
122 }
123 else
124 gdk_draw_rectangle( GDK_DRAWABLE(osd_darea_bitmap) , osd_darea_gc , TRUE ,
125 0 , 0 , width , height );
126
127 bitmap_color.pixel = 1;
128 gdk_gc_set_foreground( osd_darea_gc , &bitmap_color );
129
130 gdk_draw_layout( GDK_DRAWABLE(osd_darea_bitmap) , osd_darea_gc ,
131 off_x , off_y , osd_layout );
132 gdk_draw_layout( GDK_DRAWABLE(osd_darea_bitmap) , osd_darea_gc ,
133 off_x + border_width , off_y , osd_layout );
134 gdk_draw_layout( GDK_DRAWABLE(osd_darea_bitmap) , osd_darea_gc ,
135 off_x + border_width , off_y + border_width , osd_layout );
136 gdk_draw_layout( GDK_DRAWABLE(osd_darea_bitmap) , osd_darea_gc ,
137 off_x , off_y + border_width , osd_layout );
138 gdk_draw_layout( GDK_DRAWABLE(osd_darea_bitmap) , osd_darea_gc ,
139 off_x - border_width , off_y + border_width , osd_layout );
140 gdk_draw_layout( GDK_DRAWABLE(osd_darea_bitmap) , osd_darea_gc ,
141 off_x - border_width , off_y , osd_layout );
142 gdk_draw_layout( GDK_DRAWABLE(osd_darea_bitmap) , osd_darea_gc ,
143 off_x - border_width , off_y - border_width , osd_layout );
144 gdk_draw_layout( GDK_DRAWABLE(osd_darea_bitmap) , osd_darea_gc ,
145 off_x , off_y - border_width , osd_layout );
146 gdk_draw_layout( GDK_DRAWABLE(osd_darea_bitmap) , osd_darea_gc ,
147 off_x + border_width , off_y - border_width , osd_layout );
148
149 g_object_unref( osd_darea_gc );
150
151 gdk_window_set_back_pixmap( GDK_WINDOW(osd_darea->window) , osd_darea_pixmap , FALSE );
152 gdk_window_shape_combine_mask( GDK_WINDOW(osd_win->window) , osd_darea_bitmap , 0 , 0 );
153
154 gtk_widget_show( osd_win );
155
156 pango_font_description_free( osd_fontdesc );
157 g_object_unref( osd_layout );
158 return 0;
159 }