Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/yabause/src/gtk/yuiresolution.c
2 views
1
/* Copyright 2006 Guillaume Duhamel
2
Copyright 2005-2006 Fabien Coulon
3
4
This file is part of Yabause.
5
6
Yabause is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
11
Yabause is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
15
16
You should have received a copy of the GNU General Public License
17
along with Yabause; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
*/
20
21
#include <gtk/gtksignal.h>
22
#include <gtk/gtktable.h>
23
#include <gtk/gtklabel.h>
24
#include <gtk/gtkentry.h>
25
#include <gtk/gtkcheckbutton.h>
26
#include <gtk/gtkhbox.h>
27
#include <gtk/gtkcombobox.h>
28
#include "yuiresolution.h"
29
30
static void yui_resolution_class_init (YuiResolutionClass *klass);
31
static void yui_resolution_init (YuiResolution *yie);
32
static void yui_resolution_width_changed (GtkWidget * w, YuiResolution * yr);
33
static void yui_resolution_height_changed (GtkWidget * w, YuiResolution * yr);
34
static void yui_resolution_options_changed (GtkWidget * w, YuiResolution * yr);
35
36
GType yui_resolution_get_type (void) {
37
static GType yie_type = 0;
38
39
if (!yie_type) {
40
static const GTypeInfo yie_info = {
41
sizeof (YuiResolutionClass),
42
NULL, /* base_init */
43
NULL, /* base_finalize */
44
(GClassInitFunc) yui_resolution_class_init,
45
NULL, /* class_finalize */
46
NULL, /* class_data */
47
sizeof (YuiResolution),
48
0,
49
(GInstanceInitFunc) yui_resolution_init,
50
NULL,
51
};
52
53
yie_type = g_type_register_static (GTK_TYPE_HBOX, "YuiResolution", &yie_info, 0);
54
}
55
56
return yie_type;
57
}
58
59
#define PROP_KEYFILE 1
60
#define PROP_GROUP 2
61
62
static void yui_resolution_set_property(GObject * object, guint property_id,
63
const GValue * value, GParamSpec * pspec) {
64
switch(property_id) {
65
case PROP_KEYFILE:
66
YUI_RESOLUTION(object)->keyfile = g_value_get_pointer(value);
67
break;
68
case PROP_GROUP:
69
YUI_RESOLUTION(object)->group = g_value_get_pointer(value);
70
break;
71
}
72
}
73
74
static void yui_resolution_get_property(GObject * object, guint property_id,
75
GValue * value, GParamSpec * pspec) {
76
}
77
78
static void yui_resolution_class_init (YuiResolutionClass *klass) {
79
GParamSpec * param;
80
81
G_OBJECT_CLASS(klass)->set_property = yui_resolution_set_property;
82
G_OBJECT_CLASS(klass)->get_property = yui_resolution_get_property;
83
84
param = g_param_spec_pointer("key-file", 0, 0, G_PARAM_READABLE | G_PARAM_WRITABLE);
85
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_KEYFILE, param);
86
87
param = g_param_spec_pointer("group", 0, 0, G_PARAM_READABLE | G_PARAM_WRITABLE);
88
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_GROUP, param);
89
}
90
91
static void yui_resolution_init(YuiResolution * yr) {
92
GtkWidget * label_w;
93
GtkWidget * label_h;
94
95
gtk_container_set_border_width (GTK_CONTAINER (yr), 10);
96
97
label_w = gtk_label_new ("Width");
98
gtk_box_pack_start(GTK_BOX(yr), label_w, TRUE, TRUE, 0);
99
100
yr->entry_w = gtk_entry_new ();
101
gtk_entry_set_width_chars(GTK_ENTRY(yr->entry_w), 8);
102
gtk_box_pack_start(GTK_BOX(yr), yr->entry_w, TRUE, TRUE, 0);
103
104
label_h = gtk_label_new ("Height");
105
gtk_box_pack_start(GTK_BOX(yr), label_h, TRUE, TRUE, 0);
106
107
yr->entry_h = gtk_entry_new ();
108
gtk_entry_set_width_chars(GTK_ENTRY(yr->entry_h), 8);
109
gtk_box_pack_start(GTK_BOX(yr), yr->entry_h, TRUE, TRUE, 0);
110
111
yr->options = gtk_combo_box_new_text();
112
gtk_combo_box_append_text(GTK_COMBO_BOX(yr->options), "Window");
113
gtk_combo_box_append_text(GTK_COMBO_BOX(yr->options), "Fullscreen");
114
gtk_combo_box_append_text(GTK_COMBO_BOX(yr->options), "Keep ratio");
115
gtk_box_pack_start(GTK_BOX(yr), yr->options, TRUE, TRUE, 0);
116
117
g_signal_connect(yr->entry_w, "changed", G_CALLBACK(yui_resolution_width_changed), yr);
118
g_signal_connect(yr->entry_h, "changed", G_CALLBACK(yui_resolution_height_changed), yr);
119
g_signal_connect(yr->options, "changed", G_CALLBACK(yui_resolution_options_changed), yr);
120
}
121
122
GtkWidget* yui_resolution_new(GKeyFile * keyfile, const gchar * group) {
123
GtkWidget * widget;
124
YuiResolution * yr;
125
gchar *widthText, *heightText;
126
127
widget = GTK_WIDGET(g_object_new(yui_resolution_get_type(), "key-file", keyfile, "group", group, NULL));
128
yr = YUI_RESOLUTION(widget);
129
130
widthText = g_key_file_get_value(yr->keyfile, yr->group, "Width", 0);
131
if ( !widthText ) widthText = "";
132
heightText = g_key_file_get_value(yr->keyfile, yr->group, "Height", 0);
133
if ( !heightText ) heightText = "";
134
gtk_entry_set_text(GTK_ENTRY(yr->entry_w), widthText );
135
gtk_entry_set_text(GTK_ENTRY(yr->entry_h), heightText );
136
if (g_key_file_get_integer(yr->keyfile, yr->group, "Fullscreen", 0) == 1)
137
gtk_combo_box_set_active(GTK_COMBO_BOX(yr->options), 1);
138
else if (g_key_file_get_integer(yr->keyfile, yr->group, "KeepRatio", 0) == 1)
139
gtk_combo_box_set_active(GTK_COMBO_BOX(yr->options), 2);
140
else
141
gtk_combo_box_set_active(GTK_COMBO_BOX(yr->options), 0);
142
143
return widget;
144
}
145
146
static void yui_resolution_width_changed(GtkWidget * w, YuiResolution * yr) {
147
g_key_file_set_value(yr->keyfile, yr->group, "Width", gtk_entry_get_text(GTK_ENTRY(w)));
148
}
149
150
static void yui_resolution_height_changed(GtkWidget * w, YuiResolution * yr) {
151
g_key_file_set_value(yr->keyfile, yr->group, "Height", gtk_entry_get_text(GTK_ENTRY(w)));
152
}
153
154
static void yui_resolution_options_changed(GtkWidget * w, YuiResolution * yr) {
155
gint active = gtk_combo_box_get_active(GTK_COMBO_BOX(yr->options));
156
switch(active) {
157
case 0:
158
g_key_file_set_integer(yr->keyfile, yr->group, "Fullscreen", 0);
159
g_key_file_set_integer(yr->keyfile, yr->group, "KeepRatio", 0);
160
break;
161
case 1:
162
g_key_file_set_integer(yr->keyfile, yr->group, "Fullscreen", 1);
163
g_key_file_set_integer(yr->keyfile, yr->group, "KeepRatio", 0);
164
break;
165
case 2:
166
g_key_file_set_integer(yr->keyfile, yr->group, "Fullscreen", 0);
167
g_key_file_set_integer(yr->keyfile, yr->group, "KeepRatio", 1);
168
break;
169
}
170
}
171
172