From: yu.dongliang <18588496441@163.com> Date: Sat, 15 Apr 2023 06:55:50 +0000 (+0800) Subject: glade X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=dc61d4714747239ef441dd26cd792bee2f0f89b5;p=simplay.git glade --- diff --git a/main.c b/main.c index 7fb7d73..c06b6ad 100644 --- a/main.c +++ b/main.c @@ -1,79 +1,199 @@ -#include"simp.h" +#include +#include -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; } + diff --git a/simp.glade b/simp.glade new file mode 100644 index 0000000..588fde0 --- /dev/null +++ b/simp.glade @@ -0,0 +1,185 @@ + + + + + + True + False + 国际象棋 + False + 640 + 544 + + + + + + True + True + vertical + 27 + True + + + True + False + + + True + False + + + True + False + 文件(_F) + True + + + True + False + + + gtk-add + True + False + True + True + + + + + gtk-quit + True + False + True + True + + + + + + + + + True + False + 编辑(_E) + True + + + True + False + + + 上一步(B) + True + False + True + True + + + + + + + + + True + False + 视图(_V) + True + + + + + True + False + 帮助(_H) + True + + + True + False + + + gtk-about + True + False + True + True + + + + + + + + + False + True + 0 + + + + + gtk-media-record + True + True + True + True + + + False + True + 1 + + + + + gtk-media-pause + True + True + True + True + + + False + True + 2 + + + + + gtk-media-stop + True + True + True + True + + + False + True + 3 + + + + + False + True + + + + + True + True + False + + + True + True + + + + + + diff --git a/test.c b/test.c new file mode 100644 index 0000000..7fb7d73 --- /dev/null +++ b/test.c @@ -0,0 +1,79 @@ +#include"simp.h" + +void usage() +{ + printf("./simp input output\n"); +} + +int main(int argc, char* argv[]) +{ + if (argc < 3) { + usage(); + return -1; + } + + avdevice_register_all(); + + simp_filter_t* f = NULL; + simp_avio_t* in = NULL; + simp_avio_t* out = NULL; + simp_avio_t* alsa = NULL; + + if (simp_avio_open(&in, "ffmpeg_input", argv[1], NULL) < 0) { + scf_loge("\n"); + return -1; + } + + if (simp_avio_open(&out, "ffmpeg_output", NULL, argv[2]) < 0) { + scf_loge("\n"); + return -1; + } + + if (simp_avio_open(&alsa, "ffmpeg_alsa", NULL, "hw:0") < 0) { + scf_loge("\n"); + return -1; + } + + if (simp_filter_open(&f) < 0) { + scf_loge("\n"); + return -1; + } + + simp_filter_add_input (f, in); + simp_filter_add_output(f, out); + simp_filter_add_output(f, alsa); + + f->speed.num = 1; + f->speed.den = 1; + + if (simp_filter_run(f) < 0) { + scf_loge("\n"); + return -1; + } + + if (simp_avio_run(alsa) < 0) { + scf_loge("\n"); + return -1; + } + + if (simp_avio_run(out) < 0) { + scf_loge("\n"); + return -1; + } + + if (simp_avio_run(in) < 0) { + scf_loge("\n"); + return -1; + } + + int c; + + while ('q' != (c = getchar())) { + sleep(1); + } + + simp_filter_close(f, 1); + + printf("main quit ok\n"); + return 0; +}