046e670260e287c9999905929b08a3401cb7bd6c
[terminatorX.git] / src / tX_pbutton.cc
1 /*
2     terminatorX - realtime audio scratching software
3     Copyright (C) 1999-2020  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 const char* tx_icons[ALL_ICONS];
35
36 int tx_icon_size=20;
37
38 static const char tx_css[] = "#close:hover { background-color: #FF5555; color: #FFFFFF; }";
39
40 void tx_icons_init(int size) {
41         tx_icon_size=size;
42
43         tx_icons[AUDIOENGINE] = "audio-speakers-symbolic";
44         tx_icons[POWER] = "system-shutdown-symbolic";
45         tx_icons[GRAB] = "input-mouse-symbolic";
46
47         tx_icons[SEQUENCER] = "emblem-music-symbolic";
48
49         tx_icons[PLAY] = "media-playback-start-symbolic";
50         tx_icons[STOP] = "media-playback-stop-symbolic";
51         tx_icons[RECORD] = "media-record-symbolic";
52         tx_icons[MIN_AUDIO] = "audio-x-generic-symbolic";
53         tx_icons[MIN_CONTROL] = "multimedia-volume-control-symbolic";
54
55         tx_icons[MINIMIZE] = "window-minimize-symbolic";
56         tx_icons[MAXIMIZE] = "view-more-symbolic";
57         tx_icons[FX_UP] = "go-up-symbolic";
58         tx_icons[FX_DOWN] = "go-down-symbolic";
59         tx_icons[FX_CLOSE] = "window-close-symbolic";
60         tx_icons[ADD_ITEM] = "list-add-symbolic";
61         tx_icons[ADD_DRYWET] = "list-add-symbolic";
62         tx_icons[REMOVE_DRYWET] = "list-remove-symbolic";
63
64         GtkCssProvider *provider = gtk_css_provider_new();
65         gtk_css_provider_load_from_data(provider, tx_css, -1, NULL);
66         gtk_style_context_add_provider_for_screen (gdk_screen_get_default (), GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
67 }
68
69 GtkWidget *tx_pixmap_widget(tX_icon id)
70 {
71         return gtk_image_new_from_icon_name (tx_icons[id], GTK_ICON_SIZE_SMALL_TOOLBAR);
72 }
73
74 GtkWidget *tx_xpm_label_box(tX_icon id, const gchar *label_text, GtkWidget **labelwidget)
75 {
76         GtkWidget *box1;
77         GtkWidget *label;
78         GtkWidget *pixmapwid;
79
80         switch (globals.button_type) {
81                 case BUTTON_TYPE_TEXT:
82                         label = gtk_label_new(label_text);
83                         gtk_widget_show(label);
84                         if (labelwidget!=NULL) *labelwidget=label;
85                         return label;
86                         break;
87                 case BUTTON_TYPE_ICON:
88                         pixmapwid=tx_pixmap_widget(id);
89                         gtk_widget_show(pixmapwid);
90                         return pixmapwid;
91                         break;
92                 default:
93                         box1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
94                         gtk_container_set_border_width (GTK_CONTAINER (box1), 2);
95                         pixmapwid=tx_pixmap_widget(id);
96                         gtk_box_pack_start (GTK_BOX (box1), pixmapwid, FALSE, FALSE, 0);
97                         gtk_widget_show(pixmapwid);
98                         label = gtk_label_new (label_text);
99                         gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
100                         gtk_widget_show(label);
101                         if (labelwidget!=NULL)  *labelwidget=label;
102                         return box1;
103         }
104 }
105
106 extern GtkWidget *tx_xpm_button_new(tX_icon id, const char *label, int toggle, GtkWidget **labelwidget)
107 {
108         GtkWidget *box;
109         GtkWidget *button;
110
111         if (toggle) button=gtk_toggle_button_new();
112         else button=gtk_button_new();
113
114         box=tx_xpm_label_box(id, label, labelwidget);
115         gtk_widget_show(box);
116         gtk_container_add (GTK_CONTAINER (button), box);
117
118         return(button);
119 }
120
121 GtkWidget* create_top_button(int icon_id) {
122         GtkWidget* button = gtk_button_new_from_icon_name(tx_icons[icon_id], GTK_ICON_SIZE_SMALL_TOOLBAR);
123         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
124         gtk_widget_set_margin_end(button, 0);
125         gtk_container_set_border_width(GTK_CONTAINER(button),0);
126         return button;
127 }