-#include"simp.h"
+#include <gtk/gtk.h>
+#include <assert.h>
-void usage()
+void chess_file_new(GtkMenuButton* self, gpointer user_data)
{
- printf("./simp input output\n");
+ printf("%s(),%d\n", __func__, __LINE__);
+
+ GtkBuilder *builder;
+ GtkNotebook *code_notebook;
+ GtkWidget *code_page;
+
+ builder = GTK_BUILDER(user_data);
}
-int main(int argc, char* argv[])
+void chess_file_open(GtkMenuButton* self, gpointer user_data)
{
- if (argc < 3) {
- usage();
- return -1;
- }
+ printf("%s(),%d\n", __func__, __LINE__);
- avdevice_register_all();
+ GtkBuilder *builder;
+ GtkWindow *window;
+ GtkWidget *dialog;
- simp_filter_t* f = NULL;
- simp_avio_t* in = NULL;
- simp_avio_t* out = NULL;
- simp_avio_t* alsa = NULL;
+ builder = GTK_BUILDER(user_data);
+ window = GTK_WINDOW(gtk_builder_get_object(builder, "main_window"));
- if (simp_avio_open(&in, "ffmpeg_input", argv[1], NULL) < 0) {
- scf_loge("\n");
- return -1;
- }
+ GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
- if (simp_avio_open(&out, "ffmpeg_output", NULL, argv[2]) < 0) {
- scf_loge("\n");
- return -1;
- }
+ dialog = gtk_file_chooser_dialog_new ("Open File",
+ window,
+ action,
+ "_Cancel",
+ GTK_RESPONSE_CANCEL,
+ "_Open",
+ GTK_RESPONSE_ACCEPT,
+ NULL);
- if (simp_avio_open(&alsa, "ffmpeg_alsa", NULL, "hw:0") < 0) {
- scf_loge("\n");
- return -1;
- }
+ gtk_widget_show(dialog);
- if (simp_filter_open(&f) < 0) {
- scf_loge("\n");
- return -1;
- }
+ g_signal_connect(dialog, "response", G_CALLBACK(on_open_response), NULL);
+}
- simp_filter_add_input (f, in);
- simp_filter_add_output(f, out);
- simp_filter_add_output(f, alsa);
+void chess_file_save(GtkMenuButton* self, gpointer user_data)
+{
+ printf("%s(),%d\n", __func__, __LINE__);
+}
- f->speed.num = 1;
- f->speed.den = 1;
+void chess_file_save_as(GtkMenuButton* self, gpointer user_data)
+{
+ printf("%s(),%d\n", __func__, __LINE__);
- if (simp_filter_run(f) < 0) {
- scf_loge("\n");
- return -1;
- }
+ GtkBuilder *builder;
+ GtkWindow *window;
+ GtkWidget *dialog;
- if (simp_avio_run(alsa) < 0) {
- scf_loge("\n");
- return -1;
- }
+ builder = GTK_BUILDER(user_data);
+ window = GTK_WINDOW(gtk_builder_get_object(builder, "main_window"));
+
+ GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
+
+ dialog = gtk_file_chooser_dialog_new ("Save File",
+ window,
+ action,
+ "_Cancel",
+ GTK_RESPONSE_CANCEL,
+ "_Save",
+ GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ gtk_widget_show(dialog);
+
+ g_signal_connect(dialog, "response", G_CALLBACK(on_save_response), NULL);
+}
+
+void chess_edit_reset(GtkMenuButton* self, gpointer user_data)
+{
+ printf("%s(),%d\n", __func__, __LINE__);
+
+ gtk_gl_area_queue_render(GTK_GL_AREA(gl_area));
+}
+
+static void resize (GtkGLArea* self, gint width, gint height, gpointer user_data)
+{
+ printf("%s(),%d\n", __func__, __LINE__);
+
+ GdkGLContext *context;
+
+ gtk_gl_area_make_current (self);
- if (simp_avio_run(out) < 0) {
- scf_loge("\n");
- return -1;
+ if (gtk_gl_area_get_error (self) != NULL) {
+ printf("%s(),%d, error:\n", __func__, __LINE__);
+ return;
}
- if (simp_avio_run(in) < 0) {
- scf_loge("\n");
- return -1;
+ context = gtk_gl_area_get_context (self);
+
+ if (gdk_gl_context_get_use_es (context)) {
+ printf("%s(),%d, gles\n", __func__, __LINE__);
+ } else {
+ printf("%s(),%d, gl\n", __func__, __LINE__);
}
+}
+
+static void unrealize(GtkWidget *widget)
+{
+ printf("%s(),%d\n", __func__, __LINE__);
+}
+
+static gboolean render(GtkGLArea *area, GdkGLContext *context)
+{
+ if (gtk_gl_area_get_error (area) != NULL)
+ return FALSE;
- int c;
+ glViewport(0, 0, 512, 512);
- while ('q' != (c = getchar())) {
- sleep(1);
+ glClearColor (1.0, 0.0, 0.0, 1.0);
+ glClear (GL_COLOR_BUFFER_BIT);
+
+// chess_gl_draw(gl);
+
+ glFlush ();
+
+ return TRUE;
+}
+
+static gboolean button_release_event (GtkWidget* self, GdkEventButton* event, gpointer user_data)
+{
+ gtk_gl_area_queue_render(GTK_GL_AREA(gl_area));
+ return TRUE;
+}
+
+
+int main(int argc, char *argv[])
+{
+ printf("%s(),%d\n", __func__, __LINE__);
+
+ GtkBuilder *builder;
+ GObject *window;
+
+ GObject *menu_file_quit;
+ GObject *menu_file_new;
+ GObject *menu_file_open;
+ GObject *menu_file_save;
+ GObject *menu_file_save_as;
+ GObject *menu_edit_back;
+ GObject *menu_edit_next;
+ GObject *menu_edit_mode;
+ GObject *menu_edit_reset;
+ GError *error = NULL;
+
+ gtk_init (&argc, &argv);
+#if 1
+ builder = gtk_builder_new ();
+ if (gtk_builder_add_from_file (builder, "chess.glade", &error) == 0)
+ {
+ g_printerr ("Error loading file: %s\n", error->message);
+ g_clear_error (&error);
+ return 1;
}
+#endif
+ window = gtk_builder_get_object (builder, "main_window");
+ g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
+
+#if 1
+ menu_file_quit = gtk_builder_get_object (builder, "menu_file_quit");
+ menu_file_new = gtk_builder_get_object (builder, "menu_file_new");
+ menu_file_open = gtk_builder_get_object (builder, "menu_file_open");
+ menu_file_save = gtk_builder_get_object (builder, "menu_file_save");
+ menu_file_save_as = gtk_builder_get_object (builder, "menu_file_save_as");
+
+ menu_edit_back = gtk_builder_get_object (builder, "menu_edit_back");
+ menu_edit_next = gtk_builder_get_object (builder, "menu_edit_next");
+ menu_edit_reset = gtk_builder_get_object (builder, "menu_edit_reset");
- simp_filter_close(f, 1);
+ g_signal_connect(menu_file_quit, "activate", G_CALLBACK(gtk_main_quit), NULL);
+ g_signal_connect(menu_file_new, "activate", G_CALLBACK(chess_file_new), builder);
+ g_signal_connect(menu_file_open, "activate", G_CALLBACK(chess_file_open), builder);
+ g_signal_connect(menu_file_save, "activate", G_CALLBACK(chess_file_save), builder);
+ g_signal_connect(menu_file_save_as, "activate", G_CALLBACK(chess_file_save_as), builder);
- printf("main quit ok\n");
+ g_signal_connect(menu_edit_back, "activate", G_CALLBACK(chess_edit_back), builder);
+ g_signal_connect(menu_edit_next, "activate", G_CALLBACK(chess_edit_next), builder);
+ g_signal_connect(menu_edit_reset, "activate", G_CALLBACK(chess_edit_reset), builder);
+ g_signal_connect(menu_edit_mode, "activate", G_CALLBACK(chess_edit_mode), builder);
+
+#endif
+ gl_area = GTK_WIDGET(gtk_builder_get_object(builder, "gl_area"));
+
+ g_signal_connect (gl_area, "resize", G_CALLBACK (resize), NULL);
+ g_signal_connect (gl_area, "unrealize", G_CALLBACK (unrealize), NULL);
+ g_signal_connect (gl_area, "render", G_CALLBACK (render), NULL);
+
+ g_signal_connect (window, "button-release-event", G_CALLBACK (button_release_event), NULL);
+
+ gtk_widget_show_all(GTK_WIDGET(window));
+
+ gtk_main ();
return 0;
}
+
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
+<interface>
+ <requires lib="gtk+" version="3.20"/>
+ <object class="GtkWindow" id="main_window">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="title" translatable="yes">国际象棋</property>
+ <property name="resizable">False</property>
+ <property name="default_width">640</property>
+ <property name="default_height">544</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <object class="GtkPaned" id="menu_workspace">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="orientation">vertical</property>
+ <property name="position">27</property>
+ <property name="position_set">True</property>
+ <child>
+ <object class="GtkBox" id="menu_box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkMenuBar" id="menu_bar">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkMenuItem" id="menu_file">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">文件(_F)</property>
+ <property name="use_underline">True</property>
+ <child type="submenu">
+ <object class="GtkMenu">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkImageMenuItem" id="menu_file_add">
+ <property name="label">gtk-add</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="menu_file_quit">
+ <property name="label">gtk-quit</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuItem" id="menu_edit">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">编辑(_E)</property>
+ <property name="use_underline">True</property>
+ <child type="submenu">
+ <object class="GtkMenu">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkImageMenuItem" id="menu_edit_play">
+ <property name="label">上一步(B)</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuItem" id="menu_view">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">视图(_V)</property>
+ <property name="use_underline">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuItem" id="menu_help">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">帮助(_H)</property>
+ <property name="use_underline">True</property>
+ <child type="submenu">
+ <object class="GtkMenu">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkImageMenuItem" id="menu_help_about">
+ <property name="label">gtk-about</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button_record">
+ <property name="label">gtk-media-record</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button_pause">
+ <property name="label">gtk-media-pause</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button_stop">
+ <property name="label">gtk-media-stop</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="resize">False</property>
+ <property name="shrink">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGLArea" id="gl_area">
+ <property name="visible">True</property>
+ <property name="app_paintable">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ <packing>
+ <property name="resize">True</property>
+ <property name="shrink">True</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>