Fix behaviour of the expanders in the about dialog.
[terminatorX.git] / src / tX_pbutton.cc
1 /*
2     terminatorX - realtime audio scratching software
3     Copyright (C) 1999-2016  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, see <http://www.gnu.org/licenses/>.
17  
18     File: tX_pbutton.cc
19  
20     Description: This implements the pixmaped buttons - based on
21                  gtk+ tutorial.
22
23 */
24
25 #include <gtk/gtk.h>
26 #include <gdk-pixbuf/gdk-pixbuf.h>
27 #include <stdio.h>
28 #include "tX_mastergui.h"
29 #include "tX_pbutton.h"
30 #include "tX_global.h"
31
32 #include "icons/tX_icons_resources.c"
33
34 char tx_icons[ALL_ICONS][256];
35 int tx_icon_size=20;
36
37 #define icon_init(id, name) { snprintf(tx_icons[id], 256, "/org/terminatorX/tX_pbutton/%s.svg", name); }
38
39 void tx_icons_init(int size) 
40 {
41         tx_icon_size=size;
42
43         GError *error = NULL;
44         g_resource_new_from_data(g_bytes_new_static(tX_icons_resource_data.data, sizeof(tX_icons_resource_data.data)), &error);
45         if (error) {
46           tX_error("failed accessing tX_icons resources: %s", error->message);
47         }
48
49         icon_init(AUDIOENGINE, "audioengine");
50         icon_init(POWER, "power");
51         icon_init(GRAB, "grab");
52         icon_init(SEQUENCER, "sequencer");
53         icon_init(PLAY, "play");
54         icon_init(STOP, "stop");
55         icon_init(RECORD, "record");
56         icon_init(MIN_AUDIO, "samples");
57         icon_init(MIN_CONTROL, "control");
58         icon_init(MINIMIZE, "minimize");
59         icon_init(MAXIMIZE, "maximize");
60         icon_init(FX_UP, "fx_up");
61         icon_init(FX_DOWN, "fx_down");
62         icon_init(FX_CLOSE, "fx_close");
63         icon_init(MINIMIZE_PANEL, "minimize_panel");
64 }
65
66 GtkWidget *tx_pixmap_widget(tX_icon id)
67 {
68         GError *error = NULL;
69         GtkWidget *widget=gtk_image_new();
70         GdkPixbuf *pixbuf=gdk_pixbuf_new_from_resource_at_scale(tx_icons[id], tx_icon_size, tx_icon_size, TRUE, &error);
71         if (error) {
72                 tX_error("failed rendering icon to pixbuf: %s", error->message);
73         } else {
74                 gtk_image_set_from_pixbuf(GTK_IMAGE(widget), pixbuf);
75         }
76
77   return widget;
78 }
79
80 GtkWidget *tx_xpm_label_box(tX_icon id, const gchar *label_text, GtkWidget **labelwidget)
81 {
82         GtkWidget *box1;
83         GtkWidget *label;
84         GtkWidget *pixmapwid;
85         
86         switch (globals.button_type) {
87                 case BUTTON_TYPE_TEXT:
88                         label = gtk_label_new(label_text);
89                         gtk_widget_show(label);
90                         if (labelwidget!=NULL) *labelwidget=label;
91                         return label;
92                         break;
93                 case BUTTON_TYPE_ICON:
94                         pixmapwid=tx_pixmap_widget(id);
95                         gtk_widget_show(pixmapwid);
96                         return pixmapwid;
97                         break;
98                 default:
99                         box1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
100                         gtk_container_set_border_width (GTK_CONTAINER (box1), 2);
101                         pixmapwid=tx_pixmap_widget(id);
102                         gtk_box_pack_start (GTK_BOX (box1), pixmapwid, FALSE, FALSE, 0);
103                         gtk_widget_show(pixmapwid);
104                         label = gtk_label_new (label_text);
105                         gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
106                         gtk_widget_show(label); 
107                         if (labelwidget!=NULL)  *labelwidget=label;
108                         return box1;
109         }    
110 }
111
112 extern GtkWidget *tx_xpm_button_new(tX_icon id, const char *label, int toggle, GtkWidget **labelwidget)
113 {
114         GtkWidget *box;
115         GtkWidget *button;
116         
117         if (toggle) button=gtk_toggle_button_new();
118         else button=gtk_button_new();
119         
120         box=tx_xpm_label_box(id, label, labelwidget);
121         gtk_widget_show(box);
122         gtk_container_add (GTK_CONTAINER (button), box);                
123         
124         return(button);
125 }