Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/yabause/src/gtk/yuivdp1.c
2 views
1
/* Copyright 2006-2007 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 "yuiviewer.h"
22
#include "yuivdp1.h"
23
#include "../vdp1.h"
24
#include "../yabause.h"
25
#include "settings.h"
26
27
static void yui_vdp1_class_init (YuiVdp1Class * klass);
28
static void yui_vdp1_init (YuiVdp1 * yfe);
29
static void yui_vdp1_view_cursor_changed(GtkWidget * view, YuiVdp1 * vdp1);
30
static void yui_vdp1_clear(YuiVdp1 * vdp1);
31
static void yui_vdp1_draw(YuiVdp1 * vdp1);
32
33
GType yui_vdp1_get_type (void) {
34
static GType yfe_type = 0;
35
36
if (!yfe_type)
37
{
38
static const GTypeInfo yfe_info =
39
{
40
sizeof (YuiVdp1Class),
41
NULL, /* base_init */
42
NULL, /* base_finalize */
43
(GClassInitFunc) yui_vdp1_class_init,
44
NULL, /* class_finalize */
45
NULL, /* class_data */
46
sizeof (YuiVdp1),
47
0,
48
(GInstanceInitFunc) yui_vdp1_init,
49
NULL,
50
};
51
52
yfe_type = g_type_register_static(GTK_TYPE_WINDOW, "YuiVdp1", &yfe_info, 0);
53
}
54
55
return yfe_type;
56
}
57
58
static void yui_vdp1_class_init (UNUSED YuiVdp1Class * klass) {
59
}
60
61
static void yui_vdp1_init (YuiVdp1 * yv) {
62
GtkWidget * hbox, * vbox, * vbox2, * view;
63
64
gtk_window_set_title(GTK_WINDOW(yv), "VDP1");
65
66
vbox = gtk_vbox_new(FALSE, 0);
67
gtk_container_set_border_width(GTK_CONTAINER(vbox), 0);
68
gtk_container_add(GTK_CONTAINER(yv), vbox);
69
70
yv->toolbar = gtk_toolbar_new();
71
72
gtk_toolbar_set_style(GTK_TOOLBAR(yv->toolbar), GTK_TOOLBAR_ICONS);
73
74
gtk_box_pack_start(GTK_BOX(vbox), yv->toolbar, FALSE, FALSE, 0);
75
76
hbox = gtk_hpaned_new();
77
gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 4);
78
79
yv->store = gtk_list_store_new(2, G_TYPE_STRING, GDK_TYPE_PIXBUF);
80
view = gtk_tree_view_new_with_model(GTK_TREE_MODEL (yv->store));
81
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
82
{
83
GtkWidget * scroll;
84
GtkCellRenderer *renderer;
85
GtkCellRenderer *icon;
86
GtkTreeViewColumn *column;
87
88
scroll = gtk_scrolled_window_new(NULL, NULL);
89
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
90
91
renderer = gtk_cell_renderer_text_new();
92
column = gtk_tree_view_column_new_with_attributes("Command", renderer, "text", 0, NULL);
93
gtk_tree_view_append_column(GTK_TREE_VIEW (view), column);
94
95
icon = gtk_cell_renderer_pixbuf_new();
96
g_object_set(icon, "xalign", 0, NULL);
97
column = gtk_tree_view_column_new_with_attributes("Icon", icon, "pixbuf", 1, NULL);
98
gtk_tree_view_append_column(GTK_TREE_VIEW (view), column);
99
100
gtk_container_add(GTK_CONTAINER(scroll), view);
101
gtk_paned_pack1(GTK_PANED(hbox), scroll, FALSE, TRUE);
102
}
103
g_signal_connect(view, "cursor-changed", G_CALLBACK(yui_vdp1_view_cursor_changed), yv);
104
105
g_signal_connect(G_OBJECT(yv), "delete-event", GTK_SIGNAL_FUNC(yui_vdp1_destroy), NULL);
106
107
vbox2 = gtk_vpaned_new();
108
gtk_paned_pack2(GTK_PANED(hbox), vbox2, TRUE, TRUE);
109
{
110
GtkWidget * scroll = gtk_scrolled_window_new(NULL, NULL);
111
GtkWidget * text = gtk_text_view_new();
112
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
113
gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
114
gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text), FALSE);
115
yv->buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text));
116
gtk_container_add(GTK_CONTAINER(scroll), text);
117
gtk_paned_pack1(GTK_PANED(vbox2), scroll, FALSE, TRUE);
118
}
119
yv->image = yui_viewer_new();
120
{
121
GtkWidget * scroll = gtk_scrolled_window_new(NULL, NULL);
122
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
123
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), yv->image);
124
gtk_paned_pack2(GTK_PANED(vbox2), scroll, TRUE, TRUE);
125
}
126
127
yv->cursor = 0;
128
yv->texture = NULL;
129
130
gtk_window_set_default_size(GTK_WINDOW(yv), 500, 450);
131
132
gtk_paned_set_position(GTK_PANED(hbox), 250);
133
134
gtk_paned_set_position(GTK_PANED(vbox2), 200);
135
}
136
137
GtkWidget * yui_vdp1_new(YuiWindow * y) {
138
GtkWidget * dialog;
139
YuiVdp1 * yv;
140
141
dialog = GTK_WIDGET(g_object_new(yui_vdp1_get_type(), NULL));
142
yv = YUI_VDP1(dialog);
143
144
yv->yui = y;
145
146
if (!( yv->yui->state & YUI_IS_INIT )) {
147
yui_window_run(yv->yui);
148
yui_window_pause(yv->yui);
149
}
150
151
{
152
GtkToolItem * play_button, * pause_button;
153
154
play_button = gtk_tool_button_new_from_stock("run");
155
gtk_action_connect_proxy(gtk_action_group_get_action(yv->yui->action_group, "run"), GTK_WIDGET(play_button));
156
gtk_toolbar_insert(GTK_TOOLBAR(yv->toolbar), GTK_TOOL_ITEM(play_button), -1);
157
158
pause_button = gtk_tool_button_new_from_stock("pause");
159
gtk_action_connect_proxy(gtk_action_group_get_action(yv->yui->action_group, "pause"), GTK_WIDGET(pause_button));
160
gtk_toolbar_insert(GTK_TOOLBAR(yv->toolbar), GTK_TOOL_ITEM(pause_button), -1);
161
}
162
yv->paused_handler = g_signal_connect_swapped(yv->yui, "paused", G_CALLBACK(yui_vdp1_update), yv);
163
yv->running_handler = g_signal_connect_swapped(yv->yui, "running", G_CALLBACK(yui_vdp1_clear), yv);
164
165
if ((yv->yui->state & (YUI_IS_RUNNING | YUI_IS_INIT)) == YUI_IS_INIT)
166
yui_vdp1_update(yv);
167
168
gtk_widget_show_all(GTK_WIDGET(yv));
169
170
return dialog;
171
}
172
173
void yui_vdp1_fill(YuiVdp1 * vdp1) {
174
gint j;
175
gchar * string;
176
gchar nameTemp[1024];
177
GtkTreeIter iter;
178
179
yui_vdp1_clear(vdp1);
180
181
j = 0;
182
183
string = Vdp1DebugGetCommandNumberName(j);
184
while(string && (j < MAX_VDP1_COMMAND)) {
185
gtk_list_store_append(vdp1->store, &iter);
186
gtk_list_store_set(vdp1->store, &iter, 0, string, -1);
187
188
{
189
u32 * icontext;
190
int wtext, htext;
191
int rowstride;
192
GdkPixbuf * pixbuftext, * resized;
193
float ratio;
194
195
icontext = Vdp1DebugTexture(j, &wtext, &htext);
196
197
if ((icontext != NULL) && (wtext > 0) && (htext > 0)) {
198
rowstride = wtext * 4;
199
rowstride += (rowstride % 4)? (4 - (rowstride % 4)): 0;
200
pixbuftext = gdk_pixbuf_new_from_data((const guchar *) icontext, GDK_COLORSPACE_RGB, TRUE, 8,
201
wtext, htext, rowstride, yui_texture_free, NULL);
202
203
ratio = (float) 16 / htext;
204
if (htext > 16) {
205
resized = gdk_pixbuf_scale_simple(pixbuftext, wtext * ratio, 16, GDK_INTERP_BILINEAR);
206
} else {
207
resized = gdk_pixbuf_scale_simple(pixbuftext, wtext, htext, GDK_INTERP_BILINEAR);
208
}
209
210
gtk_list_store_set(vdp1->store, &iter, 1, resized, -1);
211
212
g_object_unref(pixbuftext);
213
g_object_unref(resized);
214
}
215
}
216
217
j++;
218
string = Vdp1DebugGetCommandNumberName(j);
219
}
220
221
Vdp1DebugCommand(vdp1->cursor, nameTemp);
222
gtk_text_buffer_set_text(vdp1->buffer, g_strstrip(nameTemp), -1);
223
vdp1->texture = Vdp1DebugTexture(vdp1->cursor, &vdp1->w, &vdp1->h);
224
yui_vdp1_draw(vdp1);
225
}
226
227
static void yui_vdp1_view_cursor_changed(GtkWidget * view, YuiVdp1 * vdp1) {
228
GtkTreePath * path;
229
gchar * strpath;
230
int i;
231
232
gtk_tree_view_get_cursor(GTK_TREE_VIEW(view), &path, NULL);
233
234
if (path) {
235
gchar nameTemp[1024];
236
237
yui_viewer_clear(YUI_VIEWER(vdp1->image));
238
239
strpath = gtk_tree_path_to_string(path);
240
241
sscanf(strpath, "%i", &i);
242
243
vdp1->cursor = i;
244
245
Vdp1DebugCommand(i, nameTemp);
246
gtk_text_buffer_set_text(vdp1->buffer, g_strstrip(nameTemp), -1);
247
vdp1->texture = Vdp1DebugTexture(i, &vdp1->w, &vdp1->h);
248
yui_vdp1_draw(vdp1);
249
250
g_free(strpath);
251
gtk_tree_path_free(path);
252
}
253
}
254
255
void yui_vdp1_update(YuiVdp1 * vdp1) {
256
gint i;
257
for(i = 0 ; i < MAX_VDP1_COMMAND ; i++ ) if ( !Vdp1DebugGetCommandNumberName(i)) break;
258
vdp1->cursor = 0;
259
yui_vdp1_fill(vdp1);
260
}
261
262
void yui_vdp1_destroy(YuiVdp1 * vdp1) {
263
g_signal_handler_disconnect(vdp1->yui, vdp1->running_handler);
264
g_signal_handler_disconnect(vdp1->yui, vdp1->paused_handler);
265
266
gtk_widget_destroy(GTK_WIDGET(vdp1));
267
}
268
269
static void yui_vdp1_clear(YuiVdp1 * vdp1) {
270
gtk_list_store_clear(vdp1->store);
271
gtk_text_buffer_set_text(vdp1->buffer, "", -1);
272
yui_viewer_clear(YUI_VIEWER(vdp1->image));
273
}
274
275
static void yui_vdp1_draw(YuiVdp1 * vdp1) {
276
GdkPixbuf * pixbuf;
277
int rowstride;
278
279
if ((vdp1->texture != NULL) && (vdp1->w > 0) && (vdp1->h > 0)) {
280
rowstride = vdp1->w * 4;
281
rowstride += (rowstride % 4)? (4 - (rowstride % 4)): 0;
282
pixbuf = gdk_pixbuf_new_from_data((const guchar *) vdp1->texture, GDK_COLORSPACE_RGB, TRUE, 8,
283
vdp1->w, vdp1->h, rowstride, yui_texture_free, NULL);
284
285
yui_viewer_draw_pixbuf(YUI_VIEWER(vdp1->image), pixbuf, vdp1->w, vdp1->h);
286
287
g_object_unref(pixbuf);
288
}
289
}
290
291