Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/yabause/src/gtk/yuiscreenshot.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 "yuiscreenshot.h"
22
#include "gtkglwidget.h"
23
#include "yuiviewer.h"
24
#include "../core.h"
25
26
static void yui_screenshot_class_init (YuiScreenshotClass * klass);
27
static void yui_screenshot_init (YuiScreenshot * yfe);
28
static void yui_screenshot_update (YuiScreenshot * ys, gpointer data);
29
static gboolean yui_screenshot_draw(YuiScreenshot * ys);
30
31
GType yui_screenshot_get_type (void) {
32
static GType yfe_type = 0;
33
34
if (!yfe_type)
35
{
36
static const GTypeInfo yfe_info =
37
{
38
sizeof (YuiScreenshotClass),
39
NULL, /* base_init */
40
NULL, /* base_finalize */
41
(GClassInitFunc) yui_screenshot_class_init,
42
NULL, /* class_finalize */
43
NULL, /* class_data */
44
sizeof (YuiScreenshot),
45
0,
46
(GInstanceInitFunc) yui_screenshot_init,
47
NULL,
48
};
49
50
yfe_type = g_type_register_static(GTK_TYPE_WINDOW, "YuiScreenshot", &yfe_info, 0);
51
}
52
53
return yfe_type;
54
}
55
56
static void yui_screenshot_class_init (UNUSED YuiScreenshotClass * klass) {
57
}
58
59
static YuiWindow * yui;
60
61
static void yui_screenshot_init (YuiScreenshot * yv) {
62
GtkWidget * box;
63
GtkWidget * button_box;
64
GtkWidget * button;
65
66
gtk_window_set_title(GTK_WINDOW(yv), "Screenshot");
67
gtk_container_set_border_width(GTK_CONTAINER(yv), 4);
68
69
box = gtk_vbox_new(FALSE, 4);
70
gtk_container_add(GTK_CONTAINER(yv), box);
71
72
yv->image = yui_viewer_new();
73
gtk_box_pack_start(GTK_BOX(box), yv->image, FALSE, FALSE, 0);
74
gtk_widget_set_size_request(GTK_WIDGET(yv->image), 320, 224);
75
76
button_box = gtk_hbutton_box_new();
77
gtk_box_pack_start(GTK_BOX(box), button_box, FALSE, FALSE, 0);
78
79
button = gtk_button_new_from_stock(GTK_STOCK_REFRESH);
80
gtk_box_pack_start(GTK_BOX(button_box), button, FALSE, FALSE, 0);
81
g_signal_connect_swapped(button, "clicked", G_CALLBACK(yui_screenshot_update), yv);
82
83
button = gtk_button_new_from_stock(GTK_STOCK_SAVE);
84
gtk_box_pack_start(GTK_BOX(button_box), button, FALSE, FALSE, 0);
85
g_signal_connect_swapped(button, "clicked", G_CALLBACK(yui_viewer_save), yv->image);
86
87
button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
88
gtk_box_pack_start(GTK_BOX(button_box), button, FALSE, FALSE, 0);
89
g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_widget_destroy), yv);
90
}
91
92
GtkWidget * yui_screenshot_new(YuiWindow * y) {
93
GtkWidget * dialog;
94
YuiScreenshot * yv;
95
96
yui = y;
97
98
dialog = GTK_WIDGET(g_object_new(yui_screenshot_get_type(), NULL));
99
yv = YUI_SCREENSHOT(dialog);
100
101
gtk_widget_show_all(dialog);
102
103
yui_gl_dump_screen(YUI_GL(yui->area));
104
yui_screenshot_draw(yv);
105
106
return dialog;
107
}
108
109
static void yui_screenshot_update(YuiScreenshot * ys, UNUSED gpointer data) {
110
yui_gl_dump_screen(YUI_GL(yui->area));
111
yui_screenshot_draw(ys);
112
}
113
114
static gboolean yui_screenshot_draw(YuiScreenshot * ys) {
115
GdkPixbuf * pixbuf, * correct;
116
117
pixbuf = gdk_pixbuf_new_from_data((const guchar *) YUI_GL(yui->area)->pixels, GDK_COLORSPACE_RGB, FALSE, 8,
118
YUI_GL(yui->area)->pixels_width, YUI_GL(yui->area)->pixels_height, YUI_GL(yui->area)->pixels_rowstride, NULL, NULL);
119
correct = gdk_pixbuf_flip(pixbuf, FALSE);
120
121
yui_viewer_draw_pixbuf(YUI_VIEWER(ys->image), correct, YUI_GL(yui->area)->pixels_width, YUI_GL(yui->area)->pixels_height);
122
123
g_object_unref(pixbuf);
124
g_object_unref(correct);
125
126
return TRUE;
127
}
128
129