From e6c615a67ef73267fc8b7a600d531d8ccc67908f Mon Sep 17 00:00:00 2001 From: jaortega Date: Tue, 13 Mar 2001 00:10:13 +0000 Subject: first functional GUI --- mixgtk/Makefile.am | 4 +- mixgtk/mixgtk.c | 10 ++- mixgtk/mixgtk.glade | 116 +++++++++++++++++++------------ mixgtk/mixgtk_input.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++ mixgtk/mixgtk_input.h | 49 ++++++++++++++ mixgtk/mixgtk_mixal.c | 2 +- mixgtk/mixgtk_mixvm.c | 56 ++++++++++++++- 7 files changed, 375 insertions(+), 46 deletions(-) create mode 100644 mixgtk/mixgtk_input.c create mode 100644 mixgtk/mixgtk_input.h (limited to 'mixgtk') diff --git a/mixgtk/Makefile.am b/mixgtk/Makefile.am index ab7d069..7b1ed82 100644 --- a/mixgtk/Makefile.am +++ b/mixgtk/Makefile.am @@ -20,7 +20,9 @@ mixgtk_SOURCES = mixgtk.c mixgtk_gen_handlers.h mixgtk_gen_handlers.c \ mixgtk_widgets.h mixgtk_widgets.c \ mixgtk_device.h mixgtk_device.c \ mixgtk_mixvm.h mixgtk_mixvm.c \ - mixgtk_mixal.h mixgtk_mixal.c + mixgtk_mixal.h mixgtk_mixal.c \ + mixgtk_input.h mixgtk_input.c + diff --git a/mixgtk/mixgtk.c b/mixgtk/mixgtk.c index ac460ec..9dbae80 100644 --- a/mixgtk/mixgtk.c +++ b/mixgtk/mixgtk.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mixgtk.c : * Main function of the mix gtk front-end * ------------------------------------------------------------------ - * Last change: Time-stamp: "01/03/10 00:03:23 jose" + * Last change: Time-stamp: "01/03/13 00:12:37 jose" * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -29,6 +29,7 @@ #include "mixgtk_device.h" #include "mixgtk_mixvm.h" #include "mixgtk_mixal.h" +#include "mixgtk_input.h" int main(int argc, char *argv[]) @@ -73,6 +74,13 @@ main(int argc, char *argv[]) g_error ("Unable to initialise application (mixal widgets)\n"); return EXIT_FAILURE; } + + if (!mixgtk_input_init ()) + { + g_error ("Unable to initialise application (word input widgets)\n"); + return EXIT_FAILURE; + } + gtk_main(); diff --git a/mixgtk/mixgtk.glade b/mixgtk/mixgtk.glade index 154e708..247d08b 100644 --- a/mixgtk/mixgtk.glade +++ b/mixgtk/mixgtk.glade @@ -238,7 +238,7 @@ button_press_event on_register_click - Sun, 11 Mar 2001 11:42:43 GMT + Mon, 12 Mar 2001 23:09:49 GMT False True @@ -1061,7 +1061,7 @@ GtkDialog word_dialog False - Enter word + Enter value GTK_WINDOW_DIALOG GTK_WIN_POS_NONE True @@ -1113,6 +1113,11 @@ word_reset True True + + clicked + on_word_reset_clicked + Mon, 12 Mar 2001 22:40:33 GMT + GTK_RELIEF_NORMAL @@ -1122,6 +1127,11 @@ word_ok True True + + clicked + on_word_ok_clicked + Mon, 12 Mar 2001 22:40:45 GMT + GTK_RELIEF_NORMAL @@ -1133,8 +1143,8 @@ True clicked - gtk_widget_hide - Sun, 11 Mar 2001 11:56:42 GMT + on_word_cancel_clicked + Mon, 12 Mar 2001 23:18:49 GMT GTK_RELIEF_NORMAL @@ -1161,6 +1171,12 @@ 143 22 True + + key_press_event + on_word_dec_key_press + True + Mon, 12 Mar 2001 22:37:13 GMT + True True 0 @@ -1175,26 +1191,18 @@ 22 22 True + + key_press_event + on_word_byte_key_press + True + Mon, 12 Mar 2001 22:38:56 GMT + True True - 0 + 3 00 - - GtkEntry - entry35 - 160 - 64 - 22 - 22 - True - True - True - 0 - 01 - - GtkEntry word_b3 @@ -1203,9 +1211,15 @@ 22 22 True + + key_press_event + on_word_byte_key_press + True + Mon, 12 Mar 2001 22:39:26 GMT + True True - 0 + 3 00 @@ -1217,9 +1231,15 @@ 22 22 True + + key_press_event + on_word_byte_key_press + True + Mon, 12 Mar 2001 22:39:50 GMT + True True - 0 + 3 00 @@ -1231,10 +1251,16 @@ 22 22 True + + key_press_event + on_word_byte_key_press + True + Mon, 12 Mar 2001 22:40:09 GMT + True True - 0 - 63 + 3 + 00 @@ -1245,9 +1271,15 @@ 22 22 True + + key_press_event + on_word_byte_key_press + True + Mon, 12 Mar 2001 22:38:24 GMT + True True - 0 + 3 00 @@ -1261,24 +1293,8 @@ True True True - 0 - - - - - - GtkLabel - label60 - 16 - 34 - 67 - 20 - - GTK_JUSTIFY_CENTER - False - 0.5 - 0.5 - 0 - 0 + 1 + + @@ -1312,6 +1328,22 @@ 0 0 + + + GtkLabel + label60 + 16 + 34 + 67 + 20 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + diff --git a/mixgtk/mixgtk_input.c b/mixgtk/mixgtk_input.c new file mode 100644 index 0000000..95e22bb --- /dev/null +++ b/mixgtk/mixgtk_input.c @@ -0,0 +1,184 @@ +/* -*-c-*- -------------- mixgtk_input.c : + * Implementation of the functions declared in mixgtk_input.h + * ------------------------------------------------------------------ + * Last change: Time-stamp: "01/03/13 01:04:13 jose" + * ------------------------------------------------------------------ + * Copyright (C) 2001 Free Software Foundation, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include +#include "mixgtk_widgets.h" +#include "mixgtk_input.h" + +enum { + MSG_, SIGN_, B1_, B2_, B3_, B4_, B5_, DEC_, RESET_, OK_, SIZE_ +}; + +static const gchar *WGT_NAMES_[SIZE_] = { + "word_label", "word_sign", "word_b1", "word_b2", "word_b3", + "word_b4", "word_b5", "word_decimal", "word_reset", "word_ok" +}; + + +static GtkDialog *dialog_; +static GtkWidget *childs_[SIZE_]; +static input_callback_t callback_; +static gpointer data_; + +/* init */ +extern gboolean +mixgtk_input_init (void) +{ + gint k; + + dialog_ = GTK_DIALOG (mixgtk_widget_factory_get (MIXGTK_WIDGET_WORD_DIALOG)); + g_return_val_if_fail (dialog_ != NULL, FALSE); + for (k = 0; k < SIZE_; ++k) + { + childs_[k] = mixgtk_widget_factory_get_by_name (WGT_NAMES_[k]); + g_return_val_if_fail (childs_[k] != NULL, FALSE); + } + + return TRUE; +} + +static void +set_word_ (mix_word_t word) +{ + enum {SIZE = 50}; + static gchar BUFFER[SIZE] = {0}; + gint k; + gint val = mix_word_magnitude (word); + gboolean neg = mix_word_is_negative (word); + snprintf (BUFFER, SIZE, "%s%d", neg ? "-" : "", val); + gtk_entry_set_text (GTK_ENTRY (childs_[DEC_]), BUFFER); + gtk_entry_set_text (GTK_ENTRY (childs_[SIGN_]), neg ? "-" : "+"); + for (k = 1; k < 6; ++k) + { + mix_byte_t b = mix_word_get_byte (word, k); + snprintf (BUFFER, SIZE, "%02d", (int)b); + gtk_entry_set_text (GTK_ENTRY (childs_[SIGN_ + k]), BUFFER); + } +} + + +/* get a word */ +void +mixgtk_input_word (const gchar *message, mix_word_t def, + input_callback_t cb, gpointer data) +{ + gtk_label_set_text (GTK_LABEL (childs_[MSG_]), message); + set_word_ (def); + callback_ = cb; + data_ = data; + gtk_widget_show (childs_[B1_]); + gtk_widget_show (childs_[B2_]); + gtk_widget_show (childs_[B3_]); + gtk_widget_show (GTK_WIDGET (dialog_)); +} + +/* get a short */ +void +mixgtk_input_short (const gchar *message, mix_short_t def, + input_callback_t cb, gpointer data) +{ + gtk_label_set_text (GTK_LABEL (childs_[MSG_]), message); + set_word_ (mix_word_to_short_fast (def)); + callback_ = cb; + data_ = data; + gtk_widget_show (GTK_WIDGET (dialog_)); + gtk_widget_hide (childs_[B1_]); + gtk_widget_hide (childs_[B2_]); + gtk_widget_hide (childs_[B3_]); + /* gtk_widget_draw (GTK_WIDGET (dialog_));*/ +} + +#include + +/* dec and bytes input handler */ +void +on_word_dec_key_press (GtkWidget *dec, GdkEvent *event, gpointer *data) +{ + GdkEventKey *key = (GdkEventKey *)event; + if (key->string && strlen (key->string) > 0) + { + gchar *text = gtk_entry_get_text (GTK_ENTRY (childs_[DEC_])); + gint val = atoi (text); + set_word_ (mix_word_new (val)); + } + if (key->keyval == GDK_KP_Tab || key->keyval == GDK_Tab || + key->keyval == GDK_ISO_Left_Tab) + gtk_window_set_focus (GTK_WINDOW (dialog_), childs_[SIGN_]); +} + +void +on_word_byte_key_press (GtkWidget *widget, GdkEvent *event, gpointer *data) +{ + GdkEventKey *key = (GdkEventKey *)event; + if (key->string && strlen (key->string) > 0) + { + mix_byte_t bytes[5]; + gint k; + gchar *s; + mix_word_t w; + + for (k = 0; k < 5; ++k) + { + gchar *text = gtk_entry_get_text (GTK_ENTRY (childs_[B1_ + k])); + bytes[k] = mix_byte_new (atoi (text)); + } + w = mix_bytes_to_word (bytes, 5); + s = gtk_entry_get_text (GTK_ENTRY (childs_[SIGN_])); + if (s && s[0] == '-') mix_word_reverse_sign (w); + set_word_ (w); + } + if (key->keyval == GDK_KP_Tab || key->keyval == GDK_Tab || + key->keyval == GDK_ISO_Left_Tab) + { + gint k = 0; + while (widget != childs_[k]) ++k; + gtk_window_set_focus (GTK_WINDOW (dialog_), + childs_[(k + 1) & (SIZE_ - 1)]); + } +} + +void +on_word_ok_clicked (GtkWidget *widget, gpointer *data) +{ + const gchar *text = gtk_entry_get_text (GTK_ENTRY (childs_[DEC_])); + mix_word_t w = mix_word_new (atoi (text)); + callback_ (w, data_); + gtk_widget_hide (GTK_WIDGET (dialog_)); +} + +void +on_word_cancel_clicked (GtkWidget *widget, gpointer *data) +{ + gtk_widget_hide (GTK_WIDGET (dialog_)); +} + +void +on_word_reset_clicked (GtkWidget *w, gpointer *data) +{ + set_word_ (MIX_WORD_ZERO); +} + + + + + diff --git a/mixgtk/mixgtk_input.h b/mixgtk/mixgtk_input.h new file mode 100644 index 0000000..275894d --- /dev/null +++ b/mixgtk/mixgtk_input.h @@ -0,0 +1,49 @@ +/* -*-c-*- ---------------- mixgtk_input.h : + * Declaration of functions for user input + * ------------------------------------------------------------------ + * Last change: Time-stamp: <01/03/12 23:35:14 jose> + * ------------------------------------------------------------------ + * Copyright (C) 2001 Free Software Foundation, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + + +#ifndef MIXGTK_INPUT_H +#define MIXGTK_INPUT_H + +#include + +/* callback function type */ +typedef void (*input_callback_t)(mix_word_t result, gpointer data); + +/* init */ +extern gboolean +mixgtk_input_init (void); + +/* get a word */ +extern void +mixgtk_input_word (const gchar *message, mix_word_t def, + input_callback_t cb, gpointer data); + +/* get a short */ +extern void +mixgtk_input_short (const gchar *message, mix_short_t def, + input_callback_t cb, gpointer data ); + + +#endif /* MIXGTK_INPUT_H */ + diff --git a/mixgtk/mixgtk_mixal.c b/mixgtk/mixgtk_mixal.c index eeef239..b59688d 100644 --- a/mixgtk/mixgtk_mixal.c +++ b/mixgtk/mixgtk_mixal.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mixgtk_mixal.c : * Implementation of the functions declared in mixgtk_mixal.h * ------------------------------------------------------------------ - * Last change: Time-stamp: "01/03/11 02:45:28 jose" + * Last change: Time-stamp: "01/03/12 23:48:29 jose" * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * diff --git a/mixgtk/mixgtk_mixvm.c b/mixgtk/mixgtk_mixvm.c index 16fa410..1ef32a5 100644 --- a/mixgtk/mixgtk_mixvm.c +++ b/mixgtk/mixgtk_mixvm.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mixgtk_mixvm.c : * Implementation of the functions declared in mixgtk_mixvm.h * ------------------------------------------------------------------ - * Last change: Time-stamp: "01/03/09 22:20:59 jose" + * Last change: Time-stamp: "01/03/13 00:24:56 jose" * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -25,6 +25,7 @@ #include "mixgtk_widgets.h" #include "mixgtk_mixvm.h" #include "mixgtk_cmd_dispatcher.h" +#include "mixgtk_input.h" /* register widgets */ #define REGISTER_NO_ (MIXGTK_WIDGET_rI6 - MIXGTK_WIDGET_rA + 1) @@ -295,3 +296,56 @@ on_loc_arrow_clicked (GtkWidget *widget, gpointer data) mixgtk_mixvm_update_cells_to_address (address); } + +static void +register_AX_ (mix_word_t w, gpointer reg) +{ + gint k = GPOINTER_TO_INT (reg); + if (k == 0) + mix_vm_set_rA (vm_, w); + else + mix_vm_set_rX (vm_, w); + update_register_ (MIXGTK_WIDGET_rA + k); +} + +static void +register_j_ (mix_word_t w, gpointer data) +{ + if (mix_word_is_negative (w)) mix_word_reverse_sign (w); + mix_vm_set_rJ (vm_, mix_word_to_short_fast (w)); + update_register_ (MIXGTK_WIDGET_rJ); +} + +static void +register_i_ (mix_word_t w, gpointer reg) +{ + mix_vm_set_rI (vm_, GPOINTER_TO_INT (reg), mix_word_to_short_fast (w)); + update_register_ (MIXGTK_WIDGET_rI1 - 1 + GPOINTER_TO_INT (reg)); +} + +void +on_register_click (GtkWidget *w, GdkEvent *e, gpointer data) +{ + enum {SIZE = 20}; + static gchar BUFFER[SIZE]; + gint k; + + if (w == GTK_WIDGET (reg_entries_[0])) + mixgtk_input_word ("Register A", mix_vm_get_rA (vm_), + register_AX_, GINT_TO_POINTER (0)); + else if (w == GTK_WIDGET (reg_entries_[1])) + mixgtk_input_word ("Register X", mix_vm_get_rX (vm_), + register_AX_, GINT_TO_POINTER(1)); + else if (w == GTK_WIDGET (reg_entries_[2])) + mixgtk_input_short ("Register J", mix_vm_get_rJ (vm_), register_j_, NULL); + else for (k = 1; k < 7; ++k) + { + if (w == GTK_WIDGET (reg_entries_[2 + k])) + { + snprintf (BUFFER, SIZE, "Register I%d", k); + mixgtk_input_short (BUFFER, mix_vm_get_rI (vm_, k), + register_i_, GINT_TO_POINTER (k)); + break; + } + } +} -- cgit v1.2.3