From: Jordi Albornoz Date: Mon, 28 Oct 2002 01:24:21 +0000 (+0000) Subject: initial port to GNOME2. X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=ddd16ef7883b2e79a4d395b2622b0f5baeb2c7b8;p=gtetrinet initial port to GNOME2. --- diff --git a/ChangeLog b/ChangeLog index 049ea21..993fc24 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2002-10-28 Jordi Mallach + + * Finally, GNOME2! + + * configure.in: require GTK 2.0.0 and various GNOME2 libs. + * src/Makefile.am: new GNOME2 includes. + * src/client.c, src/client.h, src/commands.c, src/dialogs.c, + src/fields.c, src/fields.h, src/gtetrinet.c, src/misc.c, src/misc.h, + src/partyline.c, src/tetrinet.c, src/tetrinet.h: initial port to + GNOME2 by James Antill. + 2002-10-28 Jordi Mallach * src/config.c (config_loadconfig): patch from James Antill. Save diff --git a/configure.in b/configure.in index e29ad3f..5959377 100644 --- a/configure.in +++ b/configure.in @@ -7,11 +7,25 @@ AM_INIT_AUTOMAKE(gtetrinet, 0.4.4) AC_PROG_CC -AM_PATH_GTK(1.2.0,,exit 1) +AM_PATH_GTK_2_0(2.0.0,,exit 1) AM_GNU_GETTEXT_VERSION(0.11.5) ALL_LINGUAS="ca" -GNOME_INIT + +dnl ***************************************** +dnl pkg-config check time +dnl ***************************************** + +LIBGNOME_REQUIRED=2.0.0 +LIBGNOMEUI_REQUIRED=2.0.0 + +dnl ***************************************** +dnl libgnome, libgnomeui needed for all utils +dnl ***************************************** + +PKG_CHECK_MODULES(GTET, libgnome-2.0 >= $LIBGNOME_REQUIRED libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED) +AC_SUBST(GTET_CFLAGS) +AC_SUBST(GTET_LIBS) AM_PATH_ESD(0.2.5, AC_DEFINE(HAVE_ESD, 1, [Define this to enable EsounD support.])) diff --git a/src/Makefile.am b/src/Makefile.am index 28db9eb..7142cd7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,8 +1,11 @@ SUBDIRS = images localedir = $(datadir)/locale -INCLUDES = -DLOCALEDIR=\"$(localedir)\" $(GTK_CFLAGS) $(GNOME_INCLUDEDIR) -LDADD = $(GNOME_LIBDIR) $(GNOMEUI_LIBS) $(GTK_LIBS) + +GTET_DEBUG = -Wall -W -Wno-unused -g3 -O0 + +INCLUDES = -DLOCALEDIR=\"$(localedir)\" $(GTET_CFLAGS) $(GTET_DEBUG) +LDADD = $(GTET_LIBS) AM_CPPFLAGS = -DGTETRINET_DATA=\"$(pkgdatadir)\" gamesdir = $(prefix)/games diff --git a/src/client.c b/src/client.c index 5fc4049..e2bf9d1 100644 --- a/src/client.c +++ b/src/client.c @@ -172,7 +172,7 @@ void client_destroypipes (void) { } -void client_init (char *s, char *n) +void client_init (const char *s, const char *n) { int i; GTET_O_STRCPY(server, s); diff --git a/src/client.h b/src/client.h index 1dd8915..8504171 100644 --- a/src/client.h +++ b/src/client.h @@ -35,7 +35,7 @@ extern void client_initpipes (void); extern void client_destroypipes (void); /* functions for connecting and disconnecting */ -extern void client_init (char *server, char *nick); +extern void client_init (const char *server, const char *nick); extern void client_connectcancel (void); extern void client_destroy (void); diff --git a/src/commands.c b/src/commands.c index c42fac9..b6a2f5c 100644 --- a/src/commands.c +++ b/src/commands.c @@ -221,13 +221,19 @@ void about_command (GtkWidget *widget, gpointer data) { GtkWidget *about; - const char *authors[] = {N_("Ka-shu Wong "), NULL}; + const char *authors[] = {N_("Ka-shu Wong "), + N_("James Antill "), + NULL}; + const char *documentors[] = {N_("Ka-shu Wong "), + N_("Jordi Mallach "), + NULL}; about = gnome_about_new (APPNAME, APPVERSION, _("(C) 1999, 2000, 2001, 2002 Ka-shu Wong"), - authors, _("A Tetrinet client for GNOME.\n" "Homepage: http://gtetrinet.sourceforge.net/\n"), - NULL); + authors, + documentors, + NULL, NULL); gtk_widget_show (about); } diff --git a/src/dialogs.c b/src/dialogs.c index f38690c..5e424f7 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -631,8 +631,7 @@ void prefdialog_themelist () void prefdialog_apply (GnomePropertyBox *dialog, gint pagenum) { int i; - char *midi; - + if (pagenum == -1) { for (i = 0; i < K_NUM; i ++) { keys[i] = newkeys[i]; @@ -657,7 +656,7 @@ void prefdialog_apply (GnomePropertyBox *dialog, gint pagenum) } if (midichanged) { - midi = gtk_entry_get_text (GTK_ENTRY(gnome_entry_gtk_entry(GNOME_ENTRY(midientry)))); + const char *midi = gtk_entry_get_text (GTK_ENTRY(gnome_entry_gtk_entry(GNOME_ENTRY(midientry)))); GTET_O_STRCPY (midicmd, midi); } @@ -896,9 +895,9 @@ void prefdialog_new (void) themechanged = midichanged = FALSE; gtk_signal_connect (GTK_OBJECT(soundcheck), "toggled", - prefdialog_soundtoggle, NULL); + GTK_SIGNAL_FUNC(prefdialog_soundtoggle), NULL); gtk_signal_connect (GTK_OBJECT(midicheck), "toggled", - prefdialog_miditoggle, NULL); + GTK_SIGNAL_FUNC(prefdialog_miditoggle), NULL); gtk_signal_connect (GTK_OBJECT(gnome_entry_gtk_entry(GNOME_ENTRY(midientry))), "changed", GTK_SIGNAL_FUNC(prefdialog_midichanged), NULL); gtk_signal_connect (GTK_OBJECT(themelist), "select_row", diff --git a/src/fields.c b/src/fields.c index 5b38ae8..f5de3e1 100644 --- a/src/fields.c +++ b/src/fields.c @@ -23,7 +23,6 @@ #include #include -#include #include #include "config.h" @@ -58,15 +57,19 @@ static TETRISBLOCK displayblock; void fields_init (void) { - GdkBitmap *bmap; GtkWidget *mb; - if (gdk_imlib_load_file_to_pixmap (blocksfile, &blockpix, &bmap) == 0) { + GdkPixbuf *pb = NULL; + GError *err = NULL; + GdkBitmap *mask = NULL; + + if (!(pb = gdk_pixbuf_new_from_file(blocksfile, &err))) { mb = gnome_message_box_new (_("Error loading theme: cannot load graphics file\n" "Falling back to default"), GNOME_MESSAGE_BOX_ERROR, GNOME_STOCK_BUTTON_OK, NULL); gnome_dialog_run (GNOME_DIALOG(mb)); config_loadtheme (DEFAULTTHEME); - if (gdk_imlib_load_file_to_pixmap (blocksfile, &blockpix, &bmap) == 0) { + err = NULL; + if (!(pb = gdk_pixbuf_new_from_file(blocksfile, &err))) { /* shouldnt happen */ fprintf (stderr, _("Error loading default theme: Aborting...\n" "Check for installation errors\n")); @@ -74,11 +77,13 @@ void fields_init (void) } } /* we dont want the bitmap mask */ + gdk_pixbuf_render_pixmap_and_mask(pb, &blockpix, &mask, 1); + gdk_pixbuf_unref(pb); } void fields_cleanup (void) { - gdk_imlib_free_pixmap (blockpix); + gdk_pixmap_unref(blockpix); } /* a mess of functions here for creating the fields page */ @@ -270,9 +275,9 @@ GtkWidget *fields_page_contents (void) widget = gtk_label_new (_("Attacks and defenses:")); gtk_widget_show (widget); gtk_box_pack_start (GTK_BOX(box), widget, TRUE, TRUE, 0); - attdefwidget = gtk_text_new (NULL, NULL); + attdefwidget = gtk_text_view_new_with_buffer(gtk_text_buffer_new(tag_table)); gtk_widget_set_usize (attdefwidget, MAX(22*12, BLOCKSIZE*12), BLOCKSIZE*10); - gtk_text_set_word_wrap (GTK_TEXT(attdefwidget), TRUE); + gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(attdefwidget), GTK_WRAP_WORD); GTK_WIDGET_UNSET_FLAGS (attdefwidget, GTK_CAN_FOCUS); gtk_widget_show (attdefwidget); scroll = gtk_scrolled_window_new (NULL, NULL); @@ -290,7 +295,7 @@ GtkWidget *fields_page_contents (void) /* game messages */ table2 = gtk_table_new (1, 2, FALSE); - gmsgtext = gtk_text_new (NULL, NULL); + gmsgtext = gtk_text_view_new_with_buffer(gtk_text_buffer_new(tag_table)); gtk_widget_set_usize (gmsgtext, 0, 48); gtk_widget_show (gmsgtext); GTK_WIDGET_UNSET_FLAGS (gmsgtext, GTK_CAN_FOCUS); @@ -493,16 +498,13 @@ void fields_drawnextblock (TETRISBLOCK block) void fields_attdefmsg (char *text) { - textbox_addtext (GTK_TEXT(attdefwidget), text); - adjust_bottom (GTK_TEXT(attdefwidget)->vadj); + textbox_addtext (GTK_TEXT_VIEW(attdefwidget), text); + adjust_bottom (GTK_TEXT_VIEW(attdefwidget)->vadjustment); } void fields_attdefclear (void) { - gtk_text_freeze (GTK_TEXT(attdefwidget)); - gtk_text_backward_delete (GTK_TEXT(attdefwidget), - gtk_text_get_point (GTK_TEXT(attdefwidget))); - gtk_text_thaw (GTK_TEXT(attdefwidget)); + gtk_text_buffer_set_text(GTK_TEXT_VIEW(attdefwidget)->buffer, "", 0); } void fields_setlines (int l) @@ -538,16 +540,13 @@ void fields_setactivelevel (int l) void fields_gmsgadd (char *str) { - textbox_addtext (GTK_TEXT(gmsgtext), str); - adjust_bottom (GTK_TEXT(gmsgtext)->vadj); + textbox_addtext (GTK_TEXT_VIEW(gmsgtext), str); + adjust_bottom (GTK_TEXT_VIEW(gmsgtext)->vadjustment); } void fields_gmsgclear (void) { - gtk_text_freeze (GTK_TEXT(gmsgtext)); - gtk_text_backward_delete (GTK_TEXT(gmsgtext), - gtk_text_get_point (GTK_TEXT(gmsgtext))); - gtk_text_thaw (GTK_TEXT(gmsgtext)); + gtk_text_buffer_set_text(GTK_TEXT_VIEW(gmsgtext)->buffer, "", 0); } void fields_gmsginput (int i) @@ -590,7 +589,7 @@ void fields_gmsginputback (void) gtk_entry_set_position (GTK_ENTRY(gmsginput), strlen(buf)); } -char *fields_gmsginputtext (void) +const char *fields_gmsginputtext (void) { return gtk_entry_get_text (GTK_ENTRY(gmsginput)); } diff --git a/src/fields.h b/src/fields.h index 3d82814..b723059 100644 --- a/src/fields.h +++ b/src/fields.h @@ -21,4 +21,4 @@ extern void fields_gmsginputclear (void); extern void fields_gmsginputactivate (int i); extern void fields_gmsginputadd (char *c); extern void fields_gmsginputback (void); -extern char *fields_gmsginputtext (void); +extern const char *fields_gmsginputtext (void); diff --git a/src/gtetrinet.c b/src/gtetrinet.c index 1c42a46..f86af93 100644 --- a/src/gtetrinet.c +++ b/src/gtetrinet.c @@ -23,7 +23,6 @@ #include #include -#include #include #include #include @@ -136,8 +135,9 @@ int main (int argc, char *argv[]) srand (time(NULL)); gnome_init_with_popt_table (APPID, APPVERSION, argc, argv, options, 0 , NULL); - gdk_imlib_init (); + textbox_setup (); /* needs to be done before text boxes are created */ + /* load settings */ config_loadconfig (); @@ -217,7 +217,6 @@ int main (int argc, char *argv[]) gtk_widget_set_usize(winlistwidget, 480, 360); /* initialise some stuff */ - textbox_setup (); commands_checkstate (); /* check command line params */ @@ -255,10 +254,14 @@ int main (int argc, char *argv[]) GtkWidget *pixmapdata_label (char **d, char *str) { + GdkPixbuf *pb; GdkPixmap *pm; GdkBitmap *mask; - gdk_imlib_data_to_pixmap (d, &pm, &mask); + pb = gdk_pixbuf_new_from_xpm_data ((const char **)d); + + gdk_pixbuf_render_pixmap_and_mask(pb, &pm, &mask, 1); + gdk_pixbuf_unref(pb); return pixmap_label (pm, mask, str); } @@ -301,18 +304,19 @@ gint keypress (GtkWidget *widget, GdkEventKey *key) if (widget == app) { - /* Main window - check the notebook */ - game_area = (GTK_NOTEBOOK(notebook)->cur_page->child == pfields); + int cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)); + int pfields_page = gtk_notebook_page_num(GTK_NOTEBOOK(notebook), + pfields); + /* Main window - check the notebook */ + game_area = (cur_page == pfields_page); } else { /* Sub-window - find out which */ - GtkArg arg; + char *title = NULL; - arg.name = "title"; - gtk_object_getv( GTK_OBJECT(widget), 1, &arg ); - game_area = !strcmp( GTK_VALUE_STRING(arg), "Playing Fields" ); // FIXME - g_free( GTK_VALUE_STRING(arg) ); + title = gtk_object_get_data(GTK_OBJECT(widget), "title"); + game_area = title && !strcmp( title, "Playing Fields" ); } if (game_area) @@ -338,18 +342,19 @@ gint keyrelease (GtkWidget *widget, GdkEventKey *key) if (widget == app) { - /* Main window - check the notebook */ - game_area = (GTK_NOTEBOOK(notebook)->cur_page->child == pfields); + int cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)); + int pfields_page = gtk_notebook_page_num(GTK_NOTEBOOK(notebook), + pfields); + /* Main window - check the notebook */ + game_area = (cur_page == pfields_page); } else { /* Sub-window - find out which */ - GtkArg arg; + char *title = NULL; - arg.name = "title"; - gtk_object_getv( GTK_OBJECT(widget), 1, &arg ); - game_area = !strcmp( GTK_VALUE_STRING(arg), "Playing Fields" ); - g_free( GTK_VALUE_STRING(arg) ); + title = gtk_object_get_data(GTK_OBJECT(widget), "title"); + game_area = title && !strcmp( title, "Playing Fields" ); } if (game_area) diff --git a/src/misc.c b/src/misc.c index 9e62fbf..bbcddce 100644 --- a/src/misc.c +++ b/src/misc.c @@ -65,86 +65,116 @@ void fdreadline (int fd, char *buf) #define COLORNUM 26 -static GdkColor colors[] = +static struct gtet_text_tags { + GdkColor c; + GtkTextTag *t_c; +} gtet_text_tags[] = { - {0, 0, 0, 0}, /* ^A */ - {0, 0, 0, 0}, /* ^B */ - {0, 0x0000, 0xFFFF, 0xFFFF}, /* ^C cyan */ - {0, 0x0000, 0x0000, 0x0000}, /* ^D black */ - {0, 0x0000, 0x0000, 0xFFFF}, /* ^E bright blue */ - {0, 0x7FFF, 0x7FFF, 0x7FFF}, /* ^F grey */ - {0, 0, 0, 0}, /* ^G */ - {0, 0xFFFF, 0x0000, 0xFFFF}, /* ^H magenta */ - {0, 0, 0, 0}, /* ^I */ - {0, 0, 0, 0}, /* ^J */ - {0, 0x7FFF, 0x7FFF, 0x7FFF}, /* ^K grey */ - {0, 0x0000, 0x7FFF, 0x0000}, /* ^L dark green */ - {0, 0, 0, 0}, /* ^M */ - {0, 0x0000, 0xFFFF, 0x0000}, /* ^N bright green */ - {0, 0xBFFF, 0xBFFF, 0xBFFF}, /* ^O light grey */ - {0, 0x7FFF, 0x0000, 0x0000}, /* ^P dark red */ - {0, 0x0000, 0x0000, 0x7FFF}, /* ^Q dark blue */ - {0, 0x7FFF, 0x7FFF, 0x0000}, /* ^R brown */ - {0, 0x7FFF, 0x0000, 0x7FFF}, /* ^S purple */ - {0, 0xFFFF, 0x0000, 0x0000}, /* ^T bright red */ - {0, 0xBFFF, 0xBFFF, 0xBFFF}, /* ^U light grey */ - {0, 0, 0, 0}, /* ^V */ - {0, 0x0000, 0x7FFF, 0x7FFF}, /* ^W dark cyan */ - {0, 0xFFFF, 0xFFFF, 0xFFFF}, /* ^X white */ - {0, 0xFFFF, 0xFFFF, 0x0000}, /* ^Y yellow */ - {0, 0, 0, 0} /* ^Z */ + {{0, 0, 0, 0}, NULL}, /* ^A black */ + {{0, 0, 0, 0}, NULL}, /* ^B black */ + {{0, 0x0000, 0xFFFF, 0xFFFF}, NULL}, /* ^C cyan */ + {{0, 0x0000, 0x0000, 0x0000}, NULL}, /* ^D black */ + {{0, 0x0000, 0x0000, 0xFFFF}, NULL}, /* ^E bright blue */ + {{0, 0x7FFF, 0x7FFF, 0x7FFF}, NULL}, /* ^F grey */ + {{0, 0, 0, 0}, NULL}, /* ^G black */ + {{0, 0xFFFF, 0x0000, 0xFFFF}, NULL}, /* ^H magenta */ + {{0, 0, 0, 0}, NULL}, /* ^I black */ + {{0, 0, 0, 0}, NULL}, /* ^J black */ + {{0, 0x7FFF, 0x7FFF, 0x7FFF}, NULL}, /* ^K grey */ + {{0, 0x0000, 0x7FFF, 0x0000}, NULL}, /* ^L dark green */ + {{0, 0, 0, 0}, NULL}, /* ^M black */ + {{0, 0x0000, 0xFFFF, 0x0000}, NULL}, /* ^N bright green */ + {{0, 0xBFFF, 0xBFFF, 0xBFFF}, NULL}, /* ^O light grey */ + {{0, 0x7FFF, 0x0000, 0x0000}, NULL}, /* ^P dark red */ + {{0, 0x0000, 0x0000, 0x7FFF}, NULL}, /* ^Q dark blue */ + {{0, 0x7FFF, 0x7FFF, 0x0000}, NULL}, /* ^R brown */ + {{0, 0x7FFF, 0x0000, 0x7FFF}, NULL}, /* ^S purple */ + {{0, 0xFFFF, 0x0000, 0x0000}, NULL}, /* ^T bright red */ + {{0, 0xBFFF, 0xBFFF, 0xBFFF}, NULL}, /* ^U light grey */ + {{0, 0, 0, 0}, NULL}, /* ^V black */ + {{0, 0x0000, 0x7FFF, 0x7FFF}, NULL}, /* ^W dark cyan */ + {{0, 0xFFFF, 0xFFFF, 0xFFFF}, NULL}, /* ^X white */ + {{0, 0xFFFF, 0xFFFF, 0x0000}, NULL}, /* ^Y yellow */ + {{0, 0, 0, 0}, NULL} /* ^Z black */ }; -static GdkFont *fonts[4]; +static GtkTextTag *t_bold = NULL; +static GtkTextTag *t_italic = NULL; +static GtkTextTag *t_underline = NULL; + +GtkTextTagTable *tag_table = NULL; void textbox_setup (void) -{ +{ /* API is shafted, so we need to create a buffer, + * to use the nice API for adding tags to tag tables ... then we destroy the + * buffer and keep the table for use with new buffers */ int n; - GdkColormap *colormap = gdk_colormap_get_system (); + GtkTextBuffer *buffer = gtk_text_buffer_new(NULL); + for (n = 0; n < COLORNUM; n ++) - gdk_color_alloc (colormap, &colors[n]); - /* hard coded fonts ?!?!?!? */ - /* normal */ - fonts[0] = gdk_fontset_load("-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*,*--12-*"); - /* bold */ - fonts[1] = gdk_fontset_load("-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*,*--12-*"); - /* italic */ - fonts[2] = gdk_fontset_load("-adobe-helvetica-medium-o-normal--*-120-*-*-*-*-*-*,*--12-*"); - /* bold italic */ - fonts[3] = gdk_fontset_load("-adobe-helvetica-bold-o-normal--*-120-*-*-*-*-*-*,*--12-*"); + gtet_text_tags[n].t_c = gtk_text_buffer_create_tag (buffer, NULL, + "foreground-gdk", + >et_text_tags[n].c, + "background", + "white", + NULL); + + t_bold = gtk_text_buffer_create_tag (buffer, NULL, + "weight", PANGO_WEIGHT_BOLD, NULL); + t_italic = gtk_text_buffer_create_tag (buffer, NULL, + "style", PANGO_STYLE_ITALIC, NULL); + t_underline = gtk_text_buffer_create_tag (buffer, NULL, + "underline", PANGO_UNDERLINE_SINGLE, NULL); + + tag_table = gtk_text_buffer_get_tag_table(buffer); } -void textbox_addtext (GtkText *textbox, unsigned char *text) +void textbox_addtext (GtkTextView *textbox, unsigned char *text) { - GdkColor *color, *lastcolor; + GtkTextTag *color, *lastcolor; int attr; /* bits are used as flags: bold, italic */ - int i, bottom; - char last; - GtkAdjustment *textboxadj = GTK_TEXT(textbox)->vadj; - + int i; + /* int bottom; */ + char last = 0; + gboolean attr_bold = FALSE; + gboolean attr_italic = FALSE; + gboolean attr_underline = FALSE; + /* GtkAdjustment *textboxadj = GTK_TEXT_VIEW(textbox)->vadjustment; */ + GtkTextIter iter; + /* is the scroll bar at the bottom ?? */ - if ((textboxadj->value+10)>(textboxadj->upper-textboxadj->lower-textboxadj->page_size)) - bottom = TRUE; - else bottom = FALSE; + /* if ((textboxadj->value+10)>(textboxadj->upper-textboxadj->lower-textboxadj->page_size)) + bottom = TRUE; + else bottom = FALSE; */ + /* FIXME: this shouldn't be here ... GtkTextView craps itself if you adjust + * constantly ... + * plus this function is only used from one place that doesn't call + * adjust_bottom always anyway */ + + lastcolor = color = gtet_text_tags[0].t_c; + /* gtk_text_freeze (textbox); */ - lastcolor = color = >K_WIDGET(textbox)->style->black; - last = 0; attr = 0; - gtk_text_freeze (textbox); - - if (gtk_text_get_length (textbox)) /* not first line */ - gtk_text_insert (textbox, fonts[attr], color, NULL, "\n", 1); + gtk_text_buffer_get_end_iter(textbox->buffer, &iter); + + if (gtk_text_buffer_get_char_count (textbox->buffer)) /* not first line */ + gtk_text_buffer_insert (textbox->buffer, &iter, "\n", 1); for (i = 0; text[i]; i ++) { - if (text[i] == 0xFF) { /* reset */ - lastcolor = color = >K_WIDGET(textbox)->style->black; - last = 0; attr = 0; + if (text[i] == TETRI_TB_RESET) { + lastcolor = color = gtet_text_tags[0].t_c; + attr_bold = FALSE; + attr_italic = FALSE; + attr_underline = FALSE; } - else if (text[i] < 32) { + else if (text[i] <= TETRI_TB_END_OFFSET) { + g_assert(TETRI_TB_END_OFFSET < 32); /* ASCII space */ + g_assert(TETRI_TB_C_END_OFFSET <= TETRI_TB_END_OFFSET); + switch (text[i]) { - case TETRI_TB_BOLD: attr = attr ^ 0x01; break; /* bold */ - case TETRI_TB_ITALIC: attr = attr ^ 0x02; break; /* italics */ - case TETRI_TB_UNDERLINE: break; /* underline not available */ + case TETRI_TB_BOLD: attr_bold = !!attr_bold; break; + case TETRI_TB_ITALIC: attr_italic = !!attr_italic; break; + case TETRI_TB_UNDERLINE: attr_underline = !!attr_underline; break; default: /* it is a color... */ - if (text[i] > 0x1A) goto next; /* bounds checking */ + if (text[i] > TETRI_TB_C_END_OFFSET) break; if (text[i] == last) { /* restore previous color */ color = lastcolor; @@ -155,21 +185,63 @@ void textbox_addtext (GtkText *textbox, unsigned char *text) lastcolor = color; last = text[i]; /* get new color */ - color = &colors[text[i]-0x01]; + color = gtet_text_tags[text[i] - TETRI_TB_C_BEG_OFFSET].t_c; } } - else gtk_text_insert (textbox, fonts[attr], color, NULL, &text[i], 1); + else + { + char *out = g_utf8_normalize(&text[i], 1, G_NORMALIZE_ALL); + if (out) + { + if (0) + { /* do nothing */ ; } + else if (attr_bold && attr_italic && attr_underline) + gtk_text_buffer_insert_with_tags (textbox->buffer, &iter, out, -1, + t_bold, t_italic, t_underline, + color, NULL); + else if (attr_bold && attr_italic) + gtk_text_buffer_insert_with_tags (textbox->buffer, &iter, out, -1, + t_bold, t_italic, + color, NULL); + else if (attr_bold && attr_underline) + gtk_text_buffer_insert_with_tags (textbox->buffer, &iter, out, -1, + t_bold, t_underline, + color, NULL); + else if (attr_italic && attr_underline) + gtk_text_buffer_insert_with_tags (textbox->buffer, &iter, out, -1, + t_italic, t_underline, + color, NULL); + else if (attr_bold || attr_italic || attr_underline) + { + GtkTextTag *t_a = NULL; + + if (attr_bold) t_a = t_bold; + if (attr_italic) t_a = t_italic; + if (attr_underline) t_a = t_underline; + + gtk_text_buffer_insert_with_tags (textbox->buffer, &iter, out, -1, + t_a, color, NULL); + } + else + gtk_text_buffer_insert_with_tags (textbox->buffer, &iter, out, -1, + color, NULL); + + } + + g_free(out); + } + next: continue; } /* scroll to bottom */ - gtk_text_thaw (textbox); - if (bottom) adjust_bottom (textboxadj); + /* gtk_text_thaw (textbox); */ + /* if (bottom) adjust_bottom (textboxadj); */ } void adjust_bottom (GtkAdjustment *adj) -{ - gtk_adjustment_set_value (adj, adj->upper - adj->lower - adj->page_size); +{ /* FIXME: GtkTextView craps itself */ + gtk_adjustment_set_value (adj, adj->upper); } char *nocolor (char *str) diff --git a/src/misc.h b/src/misc.h index d929290..aae953a 100644 --- a/src/misc.h +++ b/src/misc.h @@ -1,11 +1,13 @@ #include +extern GtkTextTagTable *tag_table; + extern GtkWidget *leftlabel_new (char *str); extern void leftlabel_set (GtkWidget *align, char *str); extern int randomnum (int n); extern void fdreadline (int fd, char *buf); extern void textbox_setup (void); -extern void textbox_addtext (GtkText *textbox, unsigned char *text); +extern void textbox_addtext (GtkTextView *textbox, unsigned char *text); extern void adjust_bottom (GtkAdjustment *adj); extern char *nocolor (char *str); extern GtkWidget *pixmap_label (GdkPixmap *pm, GdkBitmap *mask, char *str); @@ -57,30 +59,36 @@ extern GtkWidget *pixmap_label (GdkPixmap *pm, GdkBitmap *mask, char *str); /* textbox codes ... */ #define TETRI_TB_RESET 0xFF -#define TETRI_TB_BOLD 0x2 -#define TETRI_TB_ITALIC 0x16 -#define TETRI_TB_UNDERLINE 0x1F +#define TETRI_TB_BOLD 2 +#define TETRI_TB_ITALIC 22 +#define TETRI_TB_UNDERLINE 31 + +#define TETRI_TB_C_BEG_OFFSET 1 /* in theory 1 and 2 are colors ... + * however 2 == bold */ /* colors... see colors[] in misc.c */ -#define TETRI_TB_C_CYAN 3 -#define TETRI_TB_C_BLACK 4 -#define TETRI_TB_C_BRIGHT_BLUE 5 -#define TETRI_TB_C_GREY 6 +#define TETRI_TB_C_CYAN 3 +#define TETRI_TB_C_BLACK 4 +#define TETRI_TB_C_BRIGHT_BLUE 5 +#define TETRI_TB_C_GREY 6 -#define TETRI_TB_C_MAGENTA 8 +#define TETRI_TB_C_MAGENTA 8 -/* #define TETRI_TB_C_GREY 11 -- dup */ -#define TETRI_TB_C_DARK_GREEN 12 +/* #define TETRI_TB_C_GREY 11 -- dup */ +#define TETRI_TB_C_DARK_GREEN 12 -#define TETRI_TB_C_BRIGHT_GREEN 14 -#define TETRI_TB_C_LIGHT_GREY 15 -#define TETRI_TB_C_DARK_RED 16 -#define TETRI_TB_C_DARK_BLUE 17 -#define TETRI_TB_C_BROWN 18 -#define TETRI_TB_C_PURPLE 19 -#define TETRI_TB_C_BRIGHT_RED 20 +#define TETRI_TB_C_BRIGHT_GREEN 14 +#define TETRI_TB_C_LIGHT_GREY 15 +#define TETRI_TB_C_DARK_RED 16 +#define TETRI_TB_C_DARK_BLUE 17 +#define TETRI_TB_C_BROWN 18 +#define TETRI_TB_C_PURPLE 19 +#define TETRI_TB_C_BRIGHT_RED 20 /* #define TETRI_TB_C_LIGHT_GREY 21 -- dup */ -#define TETRI_TB_C_DARK_CYAN 23 -#define TETRI_TB_C_WHITE 24 -#define TETRI_TB_C_YELLOW 25 +#define TETRI_TB_C_DARK_CYAN 23 +#define TETRI_TB_C_WHITE 24 +#define TETRI_TB_C_YELLOW 25 + +#define TETRI_TB_C_END_OFFSET 25 /* highest color value */ +#define TETRI_TB_END_OFFSET 31 /* highest value - must be less than 32 */ diff --git a/src/partyline.c b/src/partyline.c index ddc4930..58511b2 100644 --- a/src/partyline.c +++ b/src/partyline.c @@ -62,8 +62,8 @@ GtkWidget *partyline_page_new (void) leftbox = gtk_vbox_new (FALSE, 4); /* chat thingy */ /* textbox with scrollbars */ - textbox = gtk_text_new (NULL, NULL); - gtk_text_set_word_wrap (GTK_TEXT(textbox), TRUE); + textbox = gtk_text_view_new_with_buffer(gtk_text_buffer_new(tag_table)); + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW(textbox), GTK_WRAP_WORD); GTK_WIDGET_UNSET_FLAGS(textbox, GTK_CAN_FOCUS); gtk_signal_connect (GTK_OBJECT(textbox), "button_press_event", GTK_SIGNAL_FUNC(partyline_entryfocus), NULL); @@ -169,7 +169,8 @@ void partyline_status (char *status) void partyline_text (char *text) { - textbox_addtext (GTK_TEXT(textbox), text); + textbox_addtext (GTK_TEXT_VIEW(textbox), text); + adjust_bottom (GTK_TEXT_VIEW(textbox)->vadjustment); } void partyline_playerlist (int *numbers, char **names, char **teams, int n, char **specs, int sn) @@ -210,7 +211,7 @@ void partyline_switch_entryfocus (void) void textentry (GtkWidget *widget, gpointer data) { - char *text; + const char *text; text = gtk_entry_get_text (GTK_ENTRY(widget)); if (strlen(text) == 0) return; @@ -233,7 +234,7 @@ static gint entrykey (GtkWidget *widget, GdkEventKey *key) if (keyval == GDK_Up || keyval == GDK_Down) { if (plh_cur == plh_end) { - char *text; + const char *text; text = gtk_entry_get_text (GTK_ENTRY(widget)); GTET_O_STRCPY (plhistory[plh_end], text); } diff --git a/src/tetrinet.c b/src/tetrinet.c index 4f730cb..3350e7f 100644 --- a/src/tetrinet.c +++ b/src/tetrinet.c @@ -144,10 +144,10 @@ static void partylineupdate_team (char *name, char *team); static void partylineupdate_leave (char *name); static void playerlistupdate (void); static void fieldslabelupdate (void); -static void plinemsg (char *name, char *text); -static void plineact (char *name, char *text); -static void plinesmsg (char *name, char *text); -static void plinesact (char *name, char *text); +static void plinemsg (const char *name, const char *text); +static void plineact (const char *name, const char *text); +static void plinesmsg (const char *name, const char *text); +static void plinesact (const char *name, const char *text); static char translateblock (char c); static void clearallfields (void); static void checkmoderatorstatus (void); @@ -711,9 +711,10 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data) } } -void tetrinet_playerline (char *text) +void tetrinet_playerline (const char *text) { - char buf[1024], *p; + char buf[1024]; + const char *p; if (text[0] == '/') { p = text+1; @@ -742,7 +743,7 @@ void tetrinet_playerline (char *text) plinemsg (nick, text); } -void tetrinet_changeteam (char *newteam) +void tetrinet_changeteam (const char *newteam) { char buf[128]; @@ -924,12 +925,11 @@ void tetrinet_dospecial (int from, int to, int type) case S_ADDALL4: /* bad for everyone ... */ g_assert(!to); if (from == playernum) - g_snprintf (buf, sizeof(buf), "%c%c%s%c%c", + g_snprintf (buf, sizeof(buf), "%c%c%s%c", TETRI_TB_BOLD, TETRI_TB_C_BLACK, sbinfo[type].info, - TETRI_TB_C_BLACK, - TETRI_TB_BOLD); + TETRI_TB_RESET); else g_snprintf (buf, sizeof(buf), "%c%c%s%c%c", TETRI_TB_BOLD, @@ -945,19 +945,17 @@ void tetrinet_dospecial (int from, int to, int type) case S_BLOCKQUAKE: case S_BLOCKBOMB: /* badish stuff for someone */ if (to == playernum) - g_snprintf (buf, sizeof(buf), "%c%c%s%c%c", + g_snprintf (buf, sizeof(buf), "%c%c%s%c", TETRI_TB_BOLD, TETRI_TB_C_BRIGHT_RED, sbinfo[type].info, - TETRI_TB_C_BRIGHT_RED, - TETRI_TB_BOLD); + TETRI_TB_RESET); else if (from == playernum) - g_snprintf (buf, sizeof(buf), "%c%c%s%c%c", + g_snprintf (buf, sizeof(buf), "%c%c%s%c", TETRI_TB_BOLD, TETRI_TB_C_BLACK, sbinfo[type].info, - TETRI_TB_C_BLACK, - TETRI_TB_BOLD); + TETRI_TB_RESET); else g_snprintf (buf, sizeof(buf), "%c%c%s%c%c", TETRI_TB_BOLD, @@ -972,12 +970,11 @@ void tetrinet_dospecial (int from, int to, int type) case S_SWITCH: case S_GRAVITY: /* goodish stuff for someone */ if (to == playernum) - g_snprintf (buf, sizeof(buf), "%c%c%s%c%c", + g_snprintf (buf, sizeof(buf), "%c%c%s%c", TETRI_TB_BOLD, TETRI_TB_C_BRIGHT_GREEN, sbinfo[type].info, - TETRI_TB_C_BRIGHT_GREEN, - TETRI_TB_BOLD); + TETRI_TB_RESET); else g_snprintf (buf, sizeof(buf), "%c%c%s%c%c", TETRI_TB_BOLD, @@ -1498,7 +1495,8 @@ notfieldkey: switch (keyval) { case GDK_Return: { - char buf[256], *s; + char buf[256]; + const char *s; s = fields_gmsginputtext (); if (strlen(s) > 0) { if (strncmp("/me ", s, 4) == 0) { @@ -1850,7 +1848,7 @@ void checkmoderatorstatus (void) } } -void plinemsg (char *name, char *text) +void plinemsg (const char *name, const char *text) { char buf[1024]; g_snprintf (buf, sizeof(buf), "%c<%s%c%c>%c %s", @@ -1859,7 +1857,7 @@ void plinemsg (char *name, char *text) partyline_text (buf); } -void plinesmsg (char *name, char *text) +void plinesmsg (const char *name, const char *text) { char buf[1024]; g_snprintf (buf, sizeof(buf), "%c%c<%s%c%c%c>%c %s", @@ -1870,7 +1868,7 @@ void plinesmsg (char *name, char *text) partyline_text (buf); } -void plineact (char *name, char *text) +void plineact (const char *name, const char *text) { char buf[1024]; g_snprintf (buf, sizeof(buf), "%c* %c%s%c%c %s", @@ -1879,7 +1877,7 @@ void plineact (char *name, char *text) partyline_text (buf); } -void plinesact (char *name, char *text) +void plinesact (const char *name, const char *text) { char buf[1024]; g_snprintf (buf, sizeof(buf), "%c* %c%s%c%c %s", diff --git a/src/tetrinet.h b/src/tetrinet.h index ff7feb5..e93844f 100644 --- a/src/tetrinet.h +++ b/src/tetrinet.h @@ -15,8 +15,8 @@ extern char specialblocks[256]; extern int specialblocknum; extern void tetrinet_inmessage (enum inmsg_type msgtype, char *data); -extern void tetrinet_playerline (char *text); -extern void tetrinet_changeteam (char *newteam); +extern void tetrinet_playerline (const char *text); +extern void tetrinet_changeteam (const char *newteam); extern void tetrinet_updatefield (FIELD field); extern void tetrinet_sendfield (int reset); extern void tetrinet_resendfield (void);