diff options
author | Nao Pross <naopross@thearcway.org> | 2017-02-14 11:48:19 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2017-02-14 11:48:19 +0100 |
commit | 0bb03c0a1d96c23689cc420238a37b9fd15b739c (patch) | |
tree | f2c137723355541788327ae4da6dfc789e78936c /sw/linux/src/ui.c | |
parent | hw: created z80acpu in sch library (diff) | |
download | z80uPC-0bb03c0a1d96c23689cc420238a37b9fd15b739c.tar.gz z80uPC-0bb03c0a1d96c23689cc420238a37b9fd15b739c.zip |
sw: copied flash tool source from gameboymod
Diffstat (limited to 'sw/linux/src/ui.c')
-rw-r--r-- | sw/linux/src/ui.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/sw/linux/src/ui.c b/sw/linux/src/ui.c new file mode 100644 index 0000000..b33aa04 --- /dev/null +++ b/sw/linux/src/ui.c @@ -0,0 +1,90 @@ +#include "ui.h" + +static bool ui_connected, ui_fileset; +static GtkTextBuffer *ui_logbuf; +static GtkBuilder *ui_builder; + +void ui_init(int *argc, char **argv[]) +{ + GtkWindow *window; + GtkTextView *logview; + GtkFileChooserButton *filechoosebtn; + GtkButton *connectbtn, *flashbtn; + + /* set ui global variables */ + ui_connected = ui_fileset = false; + + /* start gtk */ + gtk_init(argc, argv); + + /* load glade gtk ui */ + ui_builder = gtk_builder_new(); + gtk_builder_add_from_file(ui_builder, "gbprog.ui", NULL); + + /* connect logger buffer (extern variable) */ + ui_logbuf = gtk_text_buffer_new(NULL); + logview = GTK_TEXT_VIEW(gtk_builder_get_object(ui_builder, "logview")); + + gtk_text_view_set_buffer(logview, ui_logbuf); + + /* connect objects to function calls */ + // window + window = GTK_WINDOW(gtk_builder_get_object(ui_builder, "window")); + g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL); + + // connectbtn + connectbtn = GTK_BUTTON(gtk_builder_get_object(ui_builder, "flashbtn")); + g_signal_connect(connectbtn, "clicked", + G_CALLBACK(ui_connect_clicked), NULL); + + // flashbtn + flashbtn = GTK_BUTTON(gtk_builder_get_object(ui_builder, "flashbtn")); + g_signal_connect(flashbtn, "clicked", G_CALLBACK(ui_flash_clicked), NULL); + + // file chooser + filechoosebtn = GTK_FILE_CHOOSER_BUTTON( + gtk_builder_get_object(ui_builder, "filechoosebtn")); + g_signal_connect(filechoosebtn, "file-set", G_CALLBACK(ui_file_set), NULL); + + /* start gtk window */ + gtk_main(); +} + +void ui_log(const char *msg, char type) +{ + GtkTextIter end; + gchar typech[4] = "[ ] "; + + switch (type) { + case 'm': typech[1] = '@'; break; // message + case 'w': typech[1] = '#'; break; // warning + case 'e': typech[1] = '!'; break; // error + } + + gtk_text_buffer_get_end_iter(ui_logbuf, &end); + gtk_text_buffer_insert(ui_logbuf, &end, typech, 4); + gtk_text_buffer_get_end_iter(ui_logbuf, &end); + gtk_text_buffer_insert(ui_logbuf, &end, (const gchar *) msg, strlen(msg)); +} + +void ui_file_set(GtkFileChooserButton *btn, gpointer user_data) +{ + GtkEntry *filepath = + GTK_ENTRY(gtk_builder_get_object(ui_builder, "filepath")); + + gtk_entry_set_text(filepath, + gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(btn))); + + ui_log("File set\n", 'm'); + ui_fileset = true; +} + +void ui_connect_clicked(void) +{ + +} + +void ui_flash_clicked(void) +{ + +} |