-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui_interface.c
More file actions
73 lines (53 loc) · 1.98 KB
/
gui_interface.c
File metadata and controls
73 lines (53 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdlib.h>
#include <gtk/gtk.h>
#include "gui_interface.h"
/*
* gui_interface.c
* Copyright (C) 2015 Barajas D. Paul <Paul.Barajas@linux.com>
*
*/
Common vara={ .count = 0 };
Common *var=&vara;
void increase(gtk_struct *widgets, gpointer label){
var->count++;
sprintf(var->buf, "%d", var->count);
gtk_label_set_text(GTK_LABEL(label), var->buf);
}
void decrease(gtk_struct *widgets, gpointer label)
{
var->count--;
sprintf(var->buf, "%d", var->count);
gtk_label_set_text(GTK_LABEL(label), var->buf);
}
void GUI_start(){
gtk_struct *widgets;
widgets=(gtk_struct *)malloc(sizeof(gtk_struct));
if (widgets == NULL){
exit(1);
}
widgets->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(widgets->window), "Center");
gtk_window_set_default_size(GTK_WINDOW(widgets->window), 1024, 720);
gtk_window_set_position(GTK_WINDOW(widgets->window), GTK_WIN_POS_CENTER);
gtk_widget_show(widgets->window);
g_signal_connect_swapped(G_OBJECT(widgets->window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
widgets->frame = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(widgets->window), widgets->frame);
widgets->plus = gtk_button_new_with_label("+");
gtk_widget_set_size_request(widgets->plus, 80, 35);
gtk_fixed_put(GTK_FIXED(widgets->frame), widgets->plus, 50, 20);
widgets->minus = gtk_button_new_with_label("-");
gtk_widget_set_size_request(widgets->minus, 80, 35);
gtk_fixed_put(GTK_FIXED(widgets->frame), widgets->minus, 50, 80);
widgets->label = gtk_label_new("0");
gtk_fixed_put(GTK_FIXED(widgets->frame), widgets->label, 110, 58);
gtk_widget_show_all(widgets->window);
g_signal_connect(widgets->window, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
g_signal_connect(widgets->plus, "clicked",
G_CALLBACK(increase), widgets->label);
g_signal_connect(widgets->minus, "clicked",
G_CALLBACK(decrease), widgets->label);
gtk_main();
}