Merged parts from Adam, overload detection start, new icons, more? -
[terminatorX.git] / src / tX_pbutton.cc
1 /*
2     terminatorX - realtime audio scratching software
3     Copyright (C) 1999-2004  Alexander K├Ânig
4  
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9  
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14  
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  
19     File: tX_pbutton.cc
20  
21     Description: This implements the pixmaped buttons - based on
22                  gtk+ tutorial.
23
24 */
25
26 #include <gtk/gtk.h>
27 #include <gdk-pixbuf/gdk-pixbuf.h>
28 #include <stdio.h>
29 #include "tX_mastergui.h"
30 #include "tX_pbutton.h"
31 #include "tX_global.h"
32
33 #include "gui_icons/icons.pixbuf"
34
35 const guint8* tx_icons[ALL_ICONS];
36 long tx_icon_sizes[ALL_ICONS];
37
38 #define icon_init(id, data) { tx_icons[id]=data; tx_icon_sizes[id]=sizeof(data); }
39
40 void tx_icons_init() 
41 {
42         icon_init(AUDIOENGINE, audioengine);
43         icon_init(POWER, power);
44         icon_init(GRAB, grab);
45         icon_init(SEQUENCER, sequencer);
46         icon_init(PLAY, play);
47         icon_init(STOP, stop);
48         icon_init(RECORD, record);
49         icon_init(MIN_AUDIO, wave);
50         icon_init(MIN_CONTROL, min_control);
51         icon_init(MINIMIZE, minimize);
52         icon_init(MAXIMIZE, maximize);
53         icon_init(FX_UP, fx_up);
54         icon_init(FX_DOWN, fx_down);
55         icon_init(FX_CLOSE, fx_close);
56         icon_init(MINIMIZE_PANEL, minimize_panel);
57 }
58
59 GtkWidget *tx_pixmap_widget(tX_icon id)
60 {
61         GError *error;
62         GdkPixbuf *pixbuf=gdk_pixbuf_new_from_inline(tx_icon_sizes[id], tx_icons[id], TRUE, &error);
63         GtkWidget *widget=gtk_image_new();
64         gtk_image_set_from_pixbuf(GTK_IMAGE(widget), pixbuf);
65
66     return widget;
67 }
68
69 GtkWidget *tx_xpm_label_box(tX_icon id, gchar *label_text, GtkWidget **labelwidget)
70 {
71         GtkWidget *box1;
72         GtkWidget *label;
73         GtkWidget *pixmapwid;
74         
75         switch (globals.button_type) {
76                 case BUTTON_TYPE_TEXT:
77                         label = gtk_label_new(label_text);
78                         gtk_widget_show(label);
79                         if (labelwidget!=NULL) *labelwidget=label;
80                         return label;
81                         break;
82                 case BUTTON_TYPE_ICON:
83                         pixmapwid=tx_pixmap_widget(id);
84                         gtk_widget_show(pixmapwid);
85                         return pixmapwid;
86                         break;
87                 default:
88                         box1 = gtk_hbox_new (FALSE, 5);
89                         gtk_container_set_border_width (GTK_CONTAINER (box1), 2);
90                         pixmapwid=tx_pixmap_widget(id);
91                         gtk_box_pack_start (GTK_BOX (box1), pixmapwid, FALSE, FALSE, 0);
92                         gtk_widget_show(pixmapwid);
93                         label = gtk_label_new (label_text);
94                         gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
95                         gtk_widget_show(label); 
96                         if (labelwidget!=NULL)  *labelwidget=label;
97                         return box1;
98         }    
99 }
100
101 extern GtkWidget *tx_xpm_button_new(tX_icon id, char *label, int toggle, GtkWidget **labelwidget)
102 {
103         GtkWidget *box;
104         GtkWidget *button;
105         
106         if (toggle) button=gtk_toggle_button_new();
107         else button=gtk_button_new();
108         
109         box=tx_xpm_label_box(id, label, labelwidget);
110         gtk_widget_show(box);
111         gtk_container_add (GTK_CONTAINER (button), box);                
112         
113         return(button);
114 }