e5a0dc1d8fe8999654bafdde80f6a66350535f4b
[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 <stdio.h>
28 #include "tX_mastergui.h"
29 #include "tX_global.h"
30
31 #include "gui_icons/tx_audioengine.xpm"
32 #include "gui_icons/tx_power.xpm"
33 #include "gui_icons/tx_grab.xpm"
34 #include "gui_icons/tx_sequencer.xpm"
35 #include "gui_icons/tx_play.xpm"
36 #include "gui_icons/tx_stop.xpm"
37 #include "gui_icons/tx_record.xpm"
38 #include "gui_icons/tx_wave.xpm"
39 #include "gui_icons/tx_reload.xpm"
40 #include "gui_icons/tx_minimize.xpm"
41 #include "gui_icons/tX_fx_up.xpm"
42 #include "gui_icons/tX_fx_down.xpm"
43 #include "gui_icons/tX_fx_close.xpm"
44 #include "gui_icons/tX_minimize_panel.xpm"
45 #include "gui_icons/tX_min_control.xpm"
46
47 gchar ** tx_icons[]={ tx_audioengine_xpm, tx_power_xpm, tx_grab_xpm, 
48                       tx_sequencer_xpm, tx_play_xpm, tx_stop_xpm, tx_record_xpm, 
49                       tx_wave_xpm, tx_reload_xpm, tx_minimize_xpm,
50                       tX_fx_up_xpm, tX_fx_down_xpm, tX_fx_close_xpm, tX_minimize_panel_xpm, tX_min_control_xpm };
51
52 GtkWidget *tx_pixmap_widget(int icon_id)
53 {
54         GdkPixbuf *pixbuf=gdk_pixbuf_new_from_xpm_data((const char **) tx_icons[icon_id]);
55     GtkWidget *widget=gtk_image_new();
56         gtk_image_set_from_pixbuf(GTK_IMAGE(widget), pixbuf);
57
58     return widget;
59 }
60
61 GtkWidget *tx_xpm_label_box(int icon_id, gchar *label_text, GtkWidget **labelwidget=(GtkWidget **) NULL)
62 {
63     GtkWidget *box1;
64     GtkWidget *label;
65     GtkWidget *pixmapwid;
66         
67         switch (globals.button_type) {
68                 case BUTTON_TYPE_TEXT:
69                         label = gtk_label_new(label_text);
70                         gtk_widget_show(label);
71                         if (labelwidget!=NULL) *labelwidget=label;
72                         return label;
73                         break;
74                 case BUTTON_TYPE_ICON:
75                         pixmapwid=tx_pixmap_widget(icon_id);
76                         gtk_widget_show(pixmapwid);
77                         return pixmapwid;
78                         break;
79                 default:
80                         box1 = gtk_hbox_new (FALSE, 2);
81                         pixmapwid=tx_pixmap_widget(icon_id);
82                         gtk_box_pack_start (GTK_BOX (box1), pixmapwid, FALSE, FALSE, 0);
83                         gtk_widget_show(pixmapwid);
84                         label = gtk_label_new (label_text);
85                         gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
86                         gtk_widget_show(label); 
87                         if (labelwidget!=NULL)  *labelwidget=label;
88                         return box1;
89         }    
90 }
91
92 //GtkWidget *tx_xpm_button_new(int icon_id, char *label, int toggle)
93 extern GtkWidget *tx_xpm_button_new(int icon_id, char *label, int toggle, GtkWidget **labelwidget=(GtkWidget **) NULL)
94 {
95         GtkWidget *box;
96         GtkWidget *button;
97         
98         if (toggle) button=gtk_toggle_button_new();
99         else button=gtk_button_new();
100         
101         box=tx_xpm_label_box(icon_id, label, labelwidget);
102         gtk_widget_show(box);
103     gtk_container_set_border_width (GTK_CONTAINER (button), 0);
104         gtk_container_add (GTK_CONTAINER (button), box);                
105         
106         return(button);
107 }