📄 gui-dial.c
字号:
GTK_WIDGET_UNSET_FLAGS(w,GTK_CAN_FOCUS); gtk_widget_show(w); gtk_box_pack_start(GTK_BOX(butbox),w,1,1,0); gtk_signal_connect(GTK_OBJECT(w),"clicked", turn_callback,(gpointer)PMsgFormClosedChow); gtk_accel_group_add(scoring_accel,GDK_c,0,0,GTK_OBJECT(w),"clicked"); gtk_label_set_pattern(GTK_LABEL(GTK_BIN(w)->child),"_"); w = gtk_button_new_with_label("Pung"); GTK_WIDGET_UNSET_FLAGS(w,GTK_CAN_FOCUS); gtk_widget_show(w); gtk_box_pack_start(GTK_BOX(butbox),w,1,1,0); gtk_signal_connect(GTK_OBJECT(w),"clicked", turn_callback,(gpointer)PMsgFormClosedPung); gtk_accel_group_add(scoring_accel,GDK_p,0,0,GTK_OBJECT(w),"clicked"); gtk_label_set_pattern(GTK_LABEL(GTK_BIN(w)->child),"_"); scoring_special = w = gtk_button_new_with_label("Special Hand"); GTK_WIDGET_UNSET_FLAGS(w,GTK_CAN_FOCUS); gtk_widget_show(w); gtk_box_pack_start(GTK_BOX(butbox),w,1,1,0); gtk_signal_connect(GTK_OBJECT(w),"clicked", turn_callback,(gpointer)PMsgFormClosedSpecialSet); gtk_accel_group_add(scoring_accel,GDK_s,0,0,GTK_OBJECT(w),"clicked"); gtk_label_set_pattern(GTK_LABEL(GTK_BIN(w)->child),"_"); scoring_done = w = gtk_button_new_with_label("Finished"); GTK_WIDGET_UNSET_FLAGS(w,GTK_CAN_FOCUS); /* gtk_widget_show(w); */ /* uses same space as special hand */ gtk_box_pack_start(GTK_BOX(butbox),w,1,1,0); gtk_signal_connect(GTK_OBJECT(w),"clicked", turn_callback,(gpointer)PMsgShowTiles); gtk_accel_group_add(scoring_accel,GDK_f,0,0,GTK_OBJECT(w),"clicked"); gtk_label_set_pattern(GTK_LABEL(GTK_BIN(w)->child),"_"); gtk_signal_connect(GTK_OBJECT(scoring_dialog),"hide", add_or_remove_scoring_accels,(gpointer)0); gtk_signal_connect(GTK_OBJECT(scoring_dialog),"show", add_or_remove_scoring_accels,(gpointer)1);}void scoring_dialog_popup(void) { if ( the_game->player == our_seat ) { gtk_widget_show(scoring_special); gtk_widget_hide(scoring_done); } else { gtk_widget_hide(scoring_special); gtk_widget_show(scoring_done); } dialog_popup(scoring_dialog,DPCentredOnce);}/* close a widget, saving its position for next open */void close_saving_posn(GtkWidget *w) { gint x,y; gdk_window_get_deskrelative_origin(w->window,&x,&y); gtk_widget_set_uposition(w,x,y); gtk_widget_hide(w);}/* the textwindow for scoring information etc */void textwindow_init(void) { int i; GtkWidget *sbar, *obox, *box, *tmp, *lbl,*textw; textwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_signal_connect (GTK_OBJECT (textwindow), "delete_event", GTK_SIGNAL_FUNC (gtk_widget_hide), NULL); /* must allow shrinking */ gtk_window_set_policy(GTK_WINDOW(textwindow),TRUE,TRUE,FALSE); gtk_window_set_title(GTK_WINDOW(textwindow),"Scoring calculations"); /* reasonable size is depends on what fonts come up by... this seems to work */ /* we now set homogeneous tabs, which forces it pretty wide anyway */#ifdef WIN32 gtk_window_set_default_size(GTK_WINDOW(textwindow),000,400);#else gtk_window_set_default_size(GTK_WINDOW(textwindow),000,300);#endif obox = gtk_vbox_new(0,dialog_vert_spacing); gtk_container_set_border_width(GTK_CONTAINER(obox),dialog_border_width); gtk_widget_show(obox); gtk_container_add(GTK_CONTAINER(textwindow),obox); scoring_notebook = gtk_notebook_new(); GTK_WIDGET_UNSET_FLAGS(scoring_notebook,GTK_CAN_FOCUS); gtk_notebook_set_homogeneous_tabs(GTK_NOTEBOOK(scoring_notebook),1); gtk_widget_show(scoring_notebook); gtk_box_pack_start(GTK_BOX(obox),scoring_notebook,1,1,0); for (i=0;i<5;i++) { GtkStyle *s; textw = gtk_text_new(NULL,NULL); gtk_widget_show(textw); textpages[i] = textw; sbar = gtk_vscrollbar_new(GTK_TEXT (textw)->vadj); gtk_widget_show(sbar); box = gtk_hbox_new(0,0); gtk_widget_show(box); gtk_box_pack_start(GTK_BOX(box),sbar,0,0,0); gtk_box_pack_start(GTK_BOX(box),textw,1,1,0); lbl = gtk_label_new((i==4) ? "Settlement" : ""); gtk_widget_show(lbl); textlabels[i] = lbl; gtk_notebook_append_page(GTK_NOTEBOOK(scoring_notebook),box,lbl); gtk_widget_realize(textw); if ( fixed_font ) { s = gtk_style_copy(gtk_widget_get_style(textw)); s->font = fixed_font; gtk_widget_set_style(textw,s); } } tmp = gtk_button_new_with_label("Close"); gtk_signal_connect_object(GTK_OBJECT(tmp),"clicked", close_saving_posn,GTK_OBJECT(textwindow)); gtk_widget_show(tmp); gtk_box_pack_end(GTK_BOX(obox),tmp,0,0,0); gtk_widget_grab_focus(tmp);}/* the callback when user hits return in the message composition window */static void mentry_callback(GtkWidget *widget UNUSED,GtkWidget *mentry) { gchar *mentry_text; PMsgSendMessageMsg smm; mentry_text = gtk_entry_get_text(GTK_ENTRY(mentry)); smm.type = PMsgSendMessage; smm.addressee = 0; /* broadcast only at present ... */ smm.text = mentry_text; send_packet(&smm); gtk_entry_set_text(GTK_ENTRY(mentry),"");}/* the window for messages */void messagewindow_init(void) { GtkWidget *sbar, *obox, *box, *tmp, *mentry, *label; GtkStyle *s; if ( !info_windows_in_main ) { messagewindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_signal_connect (GTK_OBJECT (messagewindow), "delete_event", GTK_SIGNAL_FUNC (gtk_widget_hide), NULL); /* must allow shrinking */ gtk_window_set_policy(GTK_WINDOW(messagewindow),TRUE,TRUE,FALSE); gtk_window_set_title(GTK_WINDOW(messagewindow),"Messages"); /* reasonable size is ... */ gtk_window_set_default_size(GTK_WINDOW(messagewindow),400,300); } obox = gtk_vbox_new(0,info_windows_in_main ? 0 : dialog_vert_spacing); if ( !info_windows_in_main ) { gtk_container_set_border_width(GTK_CONTAINER(obox),dialog_border_width); } gtk_widget_show(obox); if ( info_windows_in_main ) { messagewindow = obox; gtk_box_pack_end(GTK_BOX(info_box),messagewindow,1,1,0); } else { gtk_container_add(GTK_CONTAINER(messagewindow),obox); } messagetext = gtk_text_new(NULL,NULL); if ( info_windows_in_main ) { gtk_widget_set_usize(messagetext,0,50); } gtk_widget_show(messagetext); sbar = gtk_vscrollbar_new(GTK_TEXT (messagetext)->vadj); gtk_widget_show(sbar); box = gtk_hbox_new(0,0); gtk_widget_show(box); gtk_box_pack_start(GTK_BOX(box),sbar,0,0,0); gtk_box_pack_start(GTK_BOX(box),messagetext,1,1,0); gtk_box_pack_start(GTK_BOX(obox),box,1,1,0); gtk_widget_realize(messagetext); if ( fixed_font ) { s = gtk_style_copy(gtk_widget_get_style(messagetext)); s->font = fixed_font; gtk_widget_set_style(messagetext,s); } GTK_WIDGET_UNSET_FLAGS(messagetext,GTK_CAN_FOCUS); /* entry widget shd focus */ label = gtk_label_new(info_windows_in_main ? "Chat:" : "Send message:"); GTK_WIDGET_UNSET_FLAGS(label,GTK_CAN_FOCUS); gtk_misc_set_alignment(GTK_MISC(label),0.0,0.5); gtk_widget_show(label); /* the thing for sending messages */ message_entry = mentry = gtk_entry_new(); gtk_widget_show(mentry); gtk_signal_connect(GTK_OBJECT(mentry),"activate", GTK_SIGNAL_FUNC(mentry_callback),mentry); if ( !info_windows_in_main ) { gtk_box_pack_start(GTK_BOX(obox),label,0,0,0); gtk_box_pack_start(GTK_BOX(obox),mentry,0,0,0); } else { GtkWidget *w = gtk_hbox_new(0,0); gtk_widget_show(w); gtk_box_pack_start(GTK_BOX(w),label,0,0,0); gtk_box_pack_start(GTK_BOX(w),mentry,0,0,0); mfocus = gtk_check_button_new_with_label("keep cursor here"); GTK_WIDGET_UNSET_FLAGS(mfocus,GTK_CAN_FOCUS); gtk_widget_show(mfocus); gtk_box_pack_start(GTK_BOX(w),mfocus,0,0,0); gtk_box_pack_start(GTK_BOX(obox),w,0,0,0); } if ( !info_windows_in_main ) { tmp = gtk_button_new_with_label("Close"); GTK_WIDGET_UNSET_FLAGS(tmp,GTK_CAN_FOCUS); /* entry widget shd focus */ gtk_signal_connect_object(GTK_OBJECT(tmp),"clicked", close_saving_posn,GTK_OBJECT(messagewindow)); gtk_widget_show(tmp); gtk_box_pack_end(GTK_BOX(obox),tmp,0,0,0); /* god knows how focus would work if this happened in the topwindow! */ gtk_widget_grab_focus(mentry); }}/* the window for showing warnings */void warningwindow_init(void) { GtkWidget *sbar, *obox, *box, *tmp, *label; GtkStyle *s; if ( warningwindow ) { gtk_widget_destroy(warningwindow); } warningwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_signal_connect (GTK_OBJECT (warningwindow), "delete_event", GTK_SIGNAL_FUNC (gtk_widget_hide), NULL); /* must allow shrinking */ gtk_window_set_policy(GTK_WINDOW(warningwindow),TRUE,TRUE,FALSE); gtk_window_set_title(GTK_WINDOW(warningwindow),"Warnings"); /* reasonable size is ... */ gtk_window_set_default_size(GTK_WINDOW(warningwindow),400,300); obox = gtk_vbox_new(0,dialog_vert_spacing); gtk_container_set_border_width(GTK_CONTAINER(obox),dialog_border_width); gtk_widget_show(obox); gtk_container_add(GTK_CONTAINER(warningwindow),obox); label = gtk_label_new( "Apart from when a player disconnects,\n" "warnings usually indicate a bug or other\n" "unexpected situation. If in doubt,\n" "please mail mahjong@stevens-bradfield.com\n" "with the warning text and a description\n" "of the situation in which it occurred."); GTK_WIDGET_UNSET_FLAGS(label,GTK_CAN_FOCUS); gtk_widget_show(label); gtk_box_pack_start(GTK_BOX(obox),label,0,0,0); warningtext = gtk_text_new(NULL,NULL); gtk_widget_show(warningtext); sbar = gtk_vscrollbar_new(GTK_TEXT (warningtext)->vadj); gtk_widget_show(sbar); box = gtk_hbox_new(0,0); gtk_widget_show(box); gtk_box_pack_start(GTK_BOX(box),sbar,0,0,0); gtk_box_pack_start(GTK_BOX(box),warningtext,1,1,0); gtk_box_pack_start(GTK_BOX(obox),box,1,1,0); gtk_widget_realize(warningtext); if ( fixed_font ) { s = gtk_style_copy(gtk_widget_get_style(warningtext)); s->font = fixed_font; gtk_widget_set_style(warningtext,s); } GTK_WIDGET_UNSET_FLAGS(warningtext,GTK_CAN_FOCUS); box = gtk_hbox_new(0,0); gtk_widget_show(box); gtk_box_pack_end(GTK_BOX(obox),box,0,0,0); tmp = gtk_button_new_with_label("Clear Warnings"); gtk_signal_connect_object(GTK_OBJECT(tmp),"clicked", warning_clear,NULL); gtk_widget_show(tmp); gtk_box_pack_start(GTK_BOX(box),tmp,1,1,0); tmp = gtk_button_new_with_label("Close"); GTK_WIDGET_UNSET_FLAGS(tmp,GTK_CAN_FOCUS); /* entry widget shd focus */ gtk_signal_connect_object(GTK_OBJECT(tmp),"clicked", close_saving_posn,GTK_OBJECT(warningwindow)); gtk_widget_show(tmp); gtk_box_pack_end(GTK_BOX(box),tmp,1,1,0); /* check for cached warnings */ log_msg_add(0,NULL);}static void warningraise(void) { showraise(warningwindow);}static int warning_numbers = 0;void warning_clear(void) { warning_numbers = 0; gtk_editable_delete_text(GTK_EDITABLE(warningtext),0,-1); gtk_widget_hide(warningentry); close_saving_posn(warningwindow);}/* a second argument of NULL just checks for stashed warnings to be transferred to the window */int log_msg_add(LogLevel l,char *warning) { static char buf[1024] = ""; if ( warning && l >= LogWarning) warning_numbers++; /* if the warning window is not currently available, cache the warning until it is */ if ( warningwindow == NULL ) { if ( warning ) { strncat(buf,warning,1023-strlen(buf)); } } else { if ( buf[0] ) { gtk_text_insert(GTK_TEXT(warningtext),NULL,NULL,NULL,buf,-1); buf[0] = 0; } if ( warning ) { gtk_text_insert(GTK_TEXT(warningtext),NULL,NULL,NULL,warning,-1); } if ( warning_numbers > 0 ) gtk_widget_show(warningentry); } /* tell warn to print the warning anyway */ return 0;}/* callback for saving as */static void save_callback(GtkWidget *w UNUSED, gpointer data UNUSED) { PMsgSaveStateMsg m; m.type = PMsgSaveState; m.filename = gtk_entry_get_text(GTK_ENTRY(save_text)); send_packet(&m); close_saving_posn(save_window);}/* window for Save As ... function */static void save_init(void) { GtkWidget *box, *bbox, *w1, *tmp; save_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_signal_connect (GTK_OBJECT (save_window), "delete_event", GTK_SIGNAL_FUNC (gtk_widget_hide), NULL); gtk_container_set_border_width(GTK_CONTAINER(save_window), dialog_border_width); bbox = gtk_vbox_new(0,0); gtk_widget_show(bbox); gtk_container_add(GTK_CONTAINER(save_window),bbox); w1 = gtk_label_new("Save as:"); gtk_widget_show(w1); gtk_box_pack_start(GTK_BOX(bbox),w1,0,0,0); box = gtk_hbox_new(0,0); gtk_widget_show(box); gtk_box_pack_start(GTK_BOX(bbox),box,0,0,0); save_text = gtk_entry_new(); gtk_widget_show(save_text); gtk_box_pack_start(GTK_BOX(box),save_text,0,0,0); w1 = gtk_label_new(".mjs"); gtk_widget_show(w1); gtk_box_pack_start(GTK_BOX(box),w1,0,0,0); box = gtk_hbox_new(0,0); gtk_widget_show(box); gtk_box_pack_start(GTK_BOX(bbox),box,0,0,0); tmp = gtk_button_new_with_label("Save"); gtk_signal_connect_object(GTK_OBJECT(tmp),"clicked", save_callback,0); gtk_widget_show(tmp); gtk_box_pack_start(GTK_BOX(box),tmp,1,1,0); tmp = gtk_button_new_with_label("Cancel");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -