1 /*
2  * File:         bottombar.c
3  *
4  * Description:  funcs for creating the bottom bar
5  *
6  * This source code is part of kludge3d, and is released under the
7  * GNU General Public License.
8  *
9  *
10  */
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <stdarg.h>
16 #include <gtk/gtk.h>
17 
18 
19 #include "bottombar.h"
20 
21 #ifdef MEMWATCH
22 #include "memwatch.h"
23 #endif
24 
25 
26 /* DEFINES ****************************************************************/
27 
28 #define MAX_STRING_LENGTH 256
29 
30 
31 /* FILE-SCOPE VARS ********************************************************/
32 
33 GtkWidget *bb_coords = NULL;
34 GtkStatusbar * statusbar;
35 guint waitTime = 0;
36 
37 
38 /* PROTOTYPES *************************************************************/
39 
40 gboolean bb_pop_message( gpointer data ) ;
41 
42 
43 /* FUNCS ******************************************************************/
44 
bb_pop_message(gpointer data)45 gboolean bb_pop_message( gpointer data ) {
46 
47 	gtk_statusbar_pop( statusbar,
48 						gtk_statusbar_get_context_id( statusbar, "default" ) );
49 	waitTime -= (guint)(data);
50 	return FALSE; /* important */
51 }
52 
53 
bb_push_message(float durationf,char * message)54 void bb_push_message( float durationf, char * message ) {
55 	guint messageId;
56 	guint duration;
57 
58 	duration = (guint)(durationf * 1000.);
59 	waitTime += duration;
60 
61 	messageId =
62 	gtk_statusbar_push( statusbar,
63 						gtk_statusbar_get_context_id( statusbar, "default" ),
64 						message );
65 	gtk_timeout_add( waitTime,
66 					 bb_pop_message, (gpointer)duration );
67 }
68 
69 
bb_push_message_f(float duration,char * msgfmt,...)70 void bb_push_message_f( float duration, char *msgfmt, ... ) {
71 	char message[ MAX_STRING_LENGTH ];
72 	va_list ap;
73 
74 	va_start( ap, msgfmt );
75 	vsnprintf( message, MAX_STRING_LENGTH - 1, msgfmt, ap );
76 /*	vsprintf ( message, msgfmt, ap );*/
77 	va_end( ap );
78 
79 	bb_push_message( duration, message );
80 }
81 
82 
create_bottombar(void)83 GtkWidget *create_bottombar( void ) {
84 	GtkWidget *frame;
85 
86 	statusbar = (GtkStatusbar*)gtk_statusbar_new();
87 	gtk_widget_show( GTK_WIDGET( statusbar ) );
88 
89 	/* NOTE - status bars are actually just glorified hboxes.  This means
90 	we can add widgets to them, just like any other hbox.  (I don't know why
91 	the gtk people went to the trouble.  It would be easier and more
92 	flexible to have a label-style status bar rather than a complete
93 	hbox-enclosed-label-style status bar.) */
94 
95 	frame = gtk_frame_new( NULL );
96 	gtk_frame_set_shadow_type( GTK_FRAME( frame ), GTK_SHADOW_IN );
97 	bb_coords = gtk_label_new(NULL);
98 	gtk_label_set_justify( GTK_LABEL( bb_coords ), GTK_JUSTIFY_LEFT );
99 	gtk_label_set_text(GTK_LABEL( bb_coords ), "[0, 0, 0]");
100 	gtk_container_add( GTK_CONTAINER( frame ), bb_coords );
101 	gtk_box_pack_start(GTK_BOX( statusbar ), frame, TRUE, TRUE, 0);
102 
103 	/* relocate coord label to beginning of status bar */
104 	gtk_box_reorder_child( GTK_BOX( statusbar ), frame, 0 );
105 
106 	gtk_widget_show( bb_coords );
107 	gtk_widget_show( frame );
108 
109 	bb_push_message( 2.5, "Welcome to kludge3d" );
110 
111 	return GTK_WIDGET( statusbar );
112 }
113 
114 
115 
bb_update_coords(gchar * coords)116 void bb_update_coords( gchar *coords) {
117 
118     gtk_label_set_text(GTK_LABEL( bb_coords ), coords);
119 
120 }
121