Merge r14152 from theora-exp.
[xiph/unicode.git] / postfish / readout.c
blob9260cb928cab3e3e42a526140d139e1e9d8b256b
1 /*
3 * postfish
4 *
5 * Copyright (C) 2002-2005 Monty
7 * Postfish is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
12 * Postfish is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Postfish; see the file COPYING. If not, write to the
19 * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <stdlib.h>
25 #include "readout.h"
27 static GtkDrawingAreaClass *parent_class = NULL;
29 static void draw(GtkWidget *widget){
30 Readout *r=READOUT(widget);
32 int width=widget->allocation.width;
33 int height=widget->allocation.height;
34 int px,py;
35 GdkGC *gc=widget->style->bg_gc[0];
36 GdkGC *text_gc=widget->style->text_gc[0];
37 GdkGC *light_gc=widget->style->light_gc[0];
38 GdkGC *dark_gc=widget->style->dark_gc[0];
40 /* blank pane */
42 gdk_draw_rectangle(r->backing,gc,1,
43 0,0,width,height);
45 /* draw layout */
46 pango_layout_get_pixel_size(r->layout,&px,&py);
48 gdk_draw_layout (r->backing,text_gc,
49 width-2-px-(py/4),(height-py)/2,
50 r->layout);
52 /* draw frame */
53 gdk_draw_rectangle(r->backing,dark_gc,0,
54 0,0,width-2,height-2);
56 gdk_draw_line(r->backing,light_gc,1,1,width-3,1);
57 gdk_draw_line(r->backing,light_gc,1,1,1,height-3);
59 gdk_draw_line(r->backing,light_gc,width-1,0,width-1,height-1);
60 gdk_draw_line(r->backing,light_gc,0,height-1,width-1,height-1);
64 static void draw_and_expose(GtkWidget *widget){
65 Readout *r=READOUT(widget);
66 if(!GDK_IS_DRAWABLE(r->backing))return;
67 draw(widget);
68 if(!GTK_WIDGET_DRAWABLE(widget))return;
69 if(!GDK_IS_DRAWABLE(widget->window))return;
70 gdk_draw_drawable(widget->window,
71 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
72 r->backing,
73 0, 0,
74 0, 0,
75 widget->allocation.width,
76 widget->allocation.height);
79 static gboolean expose( GtkWidget *widget, GdkEventExpose *event ){
80 Readout *r=READOUT(widget);
81 gdk_draw_drawable(widget->window,
82 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
83 r->backing,
84 event->area.x, event->area.y,
85 event->area.x, event->area.y,
86 event->area.width, event->area.height);
88 return FALSE;
91 static void size_request (GtkWidget *widget,GtkRequisition *requisition){
92 int x,y;
93 Readout *r=READOUT(widget);
95 pango_layout_get_pixel_size(r->layout,&x,&y);
97 requisition->width = x+4+y/2;
98 requisition->height = y+6;
102 static gboolean configure(GtkWidget *widget, GdkEventConfigure *event){
103 Readout *r=READOUT(widget);
105 if (r->backing)
106 g_object_unref(r->backing);
108 r->backing = gdk_pixmap_new(widget->window,
109 widget->allocation.width,
110 widget->allocation.height,
111 -1);
112 draw_and_expose(widget);
114 return TRUE;
117 static void readout_class_init (ReadoutClass *class){
118 GtkWidgetClass *widget_class = (GtkWidgetClass*) class;
119 parent_class = g_type_class_peek_parent (class);
121 widget_class->expose_event = expose;
122 widget_class->configure_event = configure;
123 widget_class->size_request = size_request;
126 static void readout_init (Readout *r){
130 GType readout_get_type (void){
131 static GType m_type = 0;
132 if (!m_type){
133 static const GTypeInfo m_info={
134 sizeof (ReadoutClass),
135 NULL, /* base_init */
136 NULL, /* base_finalize */
137 (GClassInitFunc) readout_class_init,
138 NULL, /* class_finalize */
139 NULL, /* class_data */
140 sizeof (Readout),
142 (GInstanceInitFunc) readout_init,
146 m_type = g_type_register_static (GTK_TYPE_DRAWING_AREA, "Readout", &m_info, 0);
149 return m_type;
152 GtkWidget* readout_new (char *markup){
153 GtkWidget *ret= GTK_WIDGET (g_object_new (readout_get_type (), NULL));
154 Readout *r=READOUT(ret);
156 r->layout=gtk_widget_create_pango_layout(ret,markup);
158 return ret;
161 void readout_set(Readout *r,char *label){
162 pango_layout_set_text(r->layout,label,-1);
163 draw_and_expose(GTK_WIDGET(r));
166 const gchar *readout_get(Readout *r){
167 return pango_layout_get_text(r->layout);