Crossfire Client, Trunk  R20507
Data Structures | Macros | Functions | Variables
info.c File Reference

Text-drawing functions for the message window. More...

#include "client.h"
#include <gtk/gtk.h>
#include "image.h"
#include "main.h"
#include "gtk2proto.h"
#include "msgtypes.h"
Include dependency graph for info.c:

Go to the source code of this file.

Data Structures

struct  boolean_widget_t
 A container that holds the pointer and state of a checkbox control. More...
 
struct  buffer_control_t
 A container for all of the buffer control parameters like output count and time. More...
 
struct  buffer_parameter_t
 A container for a single buffer control parameter like output count or time. More...
 
struct  info_buffer_t
 A buffer record that supports suppression of duplicate messages. More...
 
struct  message_control_t
 A container for all of the checkboxes associated with a single message type. More...
 
struct  msgctrl_data_t
 Descriptive message type names with pane routing and buffer enable. More...
 

Macros

#define NUM_TEXT_VIEWS   2
 EndOf GTK V2 Font Style Definitions. More...
 

Functions

void add_marked_text_to_pane (Info_Pane *pane, const char *message, int type, int subtype, int orig_color)
 This just does the work of taking text (which may have markup) and putting it into the target pane. More...
 
void add_style_to_textbuffer (Info_Pane *pane, GtkStyle *base_style)
 This is like add_tags_to_textbuffer above, but styles can be changed during the run of the client. More...
 
void add_tags_to_textbuffer (Info_Pane *pane, GtkTextBuffer *textbuf)
 Adds the various tags to the next buffer. More...
 
static void add_to_textbuf (Info_Pane *pane, const char *message, int type, int subtype, int bold, int italic, int font, const char *color, int underline)
 Adds some data to the text buffer of the specified information panel using the appropriate tags to provide the desired formatting. More...
 
void default_msgctrl_configuration (void)
 Setup the state of the message control dialog so the configuration matches the default settings built in to the client. More...
 
void draw_ext_info (int orig_color, int type, int subtype, const char *message)
 A message processor that accepts messages along with meta information color and type. More...
 
void info_buffer_flush (const int id)
 Handles message buffer flushes, and, as needed, displays the text. More...
 
void info_buffer_init (void)
 Output count/sync message buffer initialization to set all buffers empty. More...
 
void info_buffer_tick (void)
 Output count/sync buffer maintainer adds buffer time and output messages. More...
 
void info_get_styles (void)
 Loads up values from the style file. More...
 
void info_init (GtkWidget *window_root)
 Initialize the information panels in the client. More...
 
void load_msgctrl_configuration (void)
 Setup the state of the message control dialog so the configuration matches a previously saved configuration. More...
 
void menu_clear (void)
 Clears all the message panels. More...
 
void msgctrl_init (GtkWidget *window_root)
 Initialize the message control panel by populating it with descriptions of each message type along with checkboxes that are used to configure the routing and duplicate suppression system. More...
 
void on_msgctrl_activate (GtkMenuItem *menuitem, gpointer user_data)
 Shows the message control dialog when the menu item is activated. More...
 
void on_msgctrl_button_apply_clicked (GtkButton *button, gpointer user_data)
 When the message control dialog apply button is pressed, the currently displayed settings are applied. More...
 
void on_msgctrl_button_close_clicked (GtkButton *button, gpointer user_data)
 When the message control dialog close button is pressed, the currently displayed settings are applied and the dialog is dismissed. More...
 
void on_msgctrl_button_defaults_clicked (GtkButton *button, gpointer user_data)
 When the message control dialog defaults button is pressed, the default settings built into the client are restored and applied. More...
 
void on_msgctrl_button_load_clicked (GtkButton *button, gpointer user_data)
 When the message control dialog load button is pressed, the settings last saved are restored and applied. More...
 
void on_msgctrl_button_save_clicked (GtkButton *button, gpointer user_data)
 When the message control dialog save button is pressed, the currently shown settings are applied for immediate use and they are saved to disk so the settings persist across client sessions. More...
 
void read_msgctrl_configuration (void)
 Reads the state of the message control dialog and applies the settings to the msgctrl_widgets[] state variables that control the message routing and duplicate suppression system. More...
 
void save_msgctrl_configuration (void)
 Applies the current state of the checkboxes to the msgctrl_widgets state variables and saves the settings to disk so the configuration persists across client sessions. More...
 
void set_text_tag_from_style (GtkTextTag *tag, GtkStyle *style, GtkStyle *base_style)
 EndOf GTK V2 Message Control System. More...
 
void update_msgctrl_configuration (void)
 Update the state of the message control dialog so the configuration matches the currently selected settings. More...
 

Variables

const char *const colorname [NUM_COLORS]
 
static const char * font_style_names [NUM_FONTS]
 A mapping of font numbers to style based on the rcfile content. More...
 
static int has_style =0
 
Info_Pane info_pane [NUM_TEXT_VIEWS]
 
static int max_subtype =0
 
static const char *const usercolorname [NUM_COLORS]
 Color names set by the user in the gtkrc file. More...
 

GTK V2 Message Control System.

Supports a client-side implementation of what used to be provided by the server output-count and output-sync commands.

These defines presently control the way the system works. The hardcoded values here are temporary and shall give way to client commands and/or a GUI method of configuring the system. Turn off the output count/sync by setting MESSAGE_COUNT_MAX to 1. It should be safe to experiment with most values as long as none of them are set less than 1, and as long as the two buffer sizes are set to reasonable values (buffer sizes include the terminating null character).

#define MESSAGE_BUFFER_COUNT   10
 The maximum number of messages to concurrently monitor for duplicate occurances. More...
 
#define MESSAGE_BUFFER_SIZE   56
 The maximum allowable size of messages that are checked for duplicate reduction. More...
 
#define COUNT_BUFFER_SIZE   16
 The maximum size of the tag that indicates the number of times a message occured while buffered. More...
 
#define MESSAGE_COUNT_MAX   16
 The maximum number of times a buffered message may repeat before it is sent to a client panel for for display. More...
 
#define MESSAGE_AGE_MAX   16
 The maximum time in client ticks, that a message resides in a buffer before it is sent to a client panel for display. More...
 
GtkWidget * msgctrl_window
 The message control dialog where routing and buffer configuration is set up. More...
 
GtkWidget * msgctrl_table
 The message control table where routing and buffer configuration is set up. More...
 
struct info_buffer_t info_buffer [MESSAGE_BUFFER_COUNT]
 Several buffers that support suppression of duplicates even even when the duplicates are alternate with other messages. More...
 
struct buffer_control_t buffer_control
 
message_control_t msgctrl_widgets [MSG_TYPE_LAST-1]
 All of the checkbox widgets for the entire message control dialog. More...
 
struct msgctrl_data_t msgctrl_defaults [MSG_TYPE_LAST-1]
 A data structure to track how to handle each message type in with respect to panel routing and output count. More...
 
static void message_callback (int orig_color, int type, int subtype, char *message)
 A callback to accept messages along with meta information color and type. More...
 

Detailed Description

Text-drawing functions for the message window.

Definition in file info.c.

Macro Definition Documentation

#define COUNT_BUFFER_SIZE   16

The maximum size of the tag that indicates the number of times a message occured while buffered.

Example: "4 times "

Definition at line 130 of file info.c.

Referenced by draw_ext_info().

#define MESSAGE_AGE_MAX   16

The maximum time in client ticks, that a message resides in a buffer before it is sent to a client panel for display.

8 ticks is roughly 1 second.

Definition at line 148 of file info.c.

#define MESSAGE_BUFFER_COUNT   10

The maximum number of messages to concurrently monitor for duplicate occurances.

Definition at line 116 of file info.c.

Referenced by draw_ext_info(), and message_callback().

#define MESSAGE_BUFFER_SIZE   56

The maximum allowable size of messages that are checked for duplicate reduction.

Definition at line 123 of file info.c.

Referenced by draw_ext_info().

#define MESSAGE_COUNT_MAX   16

The maximum number of times a buffered message may repeat before it is sent to a client panel for for display.

Definition at line 139 of file info.c.

#define NUM_TEXT_VIEWS   2

EndOf GTK V2 Font Style Definitions.

The number of supported message panes (normal + critical). This define is meant to support anything that iterates over all the information panels. It does nothing to help remove or document hardcoded panel numbers throughout the code.

Todo:
Create defines for each panel and replace panel numbers with the defines describing the panel. This integer declaration is to that account.c knows how many are being used here, and can add appropriately.

Definition at line 68 of file info.c.

Referenced by draw_ext_info(), message_callback(), and save_msgctrl_configuration().

Function Documentation

void add_marked_text_to_pane ( Info_Pane pane,
const char *  message,
int  type,
int  subtype,
int  orig_color 
)

This just does the work of taking text (which may have markup) and putting it into the target pane.

This is a lower level than the draw_ext_info() below, as it does not do message routing. This is called from draw_ext_info() below, as well as account.c to update news/motd/rules.

Parameters
panePointer to the pane info to draw info.
messageMessage that is parsed and displayed.
typeType of the message - for default coloring information.
subtypeSubtype of message - used for default coloring information.
orig_colorLegacy color hint not based on type that is used when a theme does not define a style for the message.
Note
Note both type and subtype are the values passed to draw_ext_info().

< Only if we get a [color] tag should we care, otherwise, the type/subtype should dictate color (unless no style set!)

Definition at line 819 of file info.c.

References add_to_textbuf(), CONFIG_TIMESTAMP, draw_ext_info(), FONT_ARCANE, FONT_FIXED, FONT_HAND, FONT_NORMAL, FONT_STRANGE, LOG(), LOG_ERROR, LOG_INFO, usercolorname, and want_config.

Referenced by add_to_textbuf(), draw_ext_info(), on_combobox_starting_map_changed(), and update_login_info().

Here is the call graph for this function:

Here is the caller graph for this function:

void add_style_to_textbuffer ( Info_Pane pane,
GtkStyle *  base_style 
)

This is like add_tags_to_textbuffer above, but styles can be changed during the run of the client.

So this has to be separate to note it it might be a reload.

Parameters
paneMessage panel number to update.
base_styleBase style if retrieved - may be null.

Definition at line 426 of file info.c.

Referenced by init_choose_char_window(), init_create_account_window(), init_create_character_window(), and init_login_window().

Here is the caller graph for this function:

void add_tags_to_textbuffer ( Info_Pane pane,
GtkTextBuffer *  textbuf 
)

Adds the various tags to the next buffer.

If textbuf is non-null, then it also sets the text buffer for that pane to textbuf. This is called right now by info_get_styles() below and from within the account code.

Parameters
paneMessage panel number to add buffer to.
textbufText buffer to apply tags to. It is allowed to be null if info_pane[pane].textbuffer has already been set.

Definition at line 372 of file info.c.

Referenced by init_choose_char_window(), init_create_account_window(), init_create_character_window(), init_login_window(), and set_text_tag_from_style().

Here is the caller graph for this function:

static void add_to_textbuf ( Info_Pane pane,
const char *  message,
int  type,
int  subtype,
int  bold,
int  italic,
int  font,
const char *  color,
int  underline 
)
static

Adds some data to the text buffer of the specified information panel using the appropriate tags to provide the desired formatting.

Note that the style within the users theme determines how a particular type/subtype is drawn.

Parameters
paneThe client message panel to write a message to.
messageA pointer to some text to show in a client message window.
typeThe message type - see the MSG_TYPE values in newclient.h.
subtypeMessage subtype - see MSG_TYPE_*_* values in newclient.h.
boldIf true, should be in bold text.
italicIf true, should be in italic text
fontWhich font to use - resolved to an actual font style based on the user's theme file.
colorString name of the color.
underlineIf true, draw underlined text.

Definition at line 710 of file info.c.

References add_marked_text_to_pane(), Info_Pane::adjustment, Info_Pane::bold_tag, Info_Pane::color_tags, Info_Pane::default_tag, Info_Pane::font_tags, Info_Pane::italic_tag, LOG(), LOG_ERROR, max_subtype, MSG_TYPE_CLIENT, Info_Pane::msg_type_tags, NUM_COLORS, Info_Pane::textbuffer, Info_Pane::textmark, Info_Pane::textview, Info_Pane::underline_tag, and usercolorname.

Referenced by add_marked_text_to_pane().

Here is the call graph for this function:

Here is the caller graph for this function:

void default_msgctrl_configuration ( void  )

Setup the state of the message control dialog so the configuration matches the default settings built in to the client.

Iterate through each message type. For each, copy the built-in client default to the Message Control dialog state variables. All supported defaults are copied, not just the ones supported by the layout.

Definition at line 1760 of file info.c.

void draw_ext_info ( int  orig_color,
int  type,
int  subtype,
const char *  message 
)

A message processor that accepts messages along with meta information color and type.

The message type and subtype are analyzed to select font and other text attributes. All gtk-v2 client messages pass through this processor before being output. Before addition of the output buffering feature, this was the message callback function. It is a separate function so that it can be called both by the callback, and but buffer maintenance functions.

Client-sourced messages generally should be passed directly to this handler instead of to the callback. This will save some overhead as the callback implements a system that coalesces duplicate messages - a feature that is not really applicable to most messages that do not come from the server.

Parameters
orig_colorSuggested text color that type/subtype can over-ride.
typeMessage type. See MSG_TYPE definitions in newclient.h.
subtypeMessage subtype. See MSG_TYPE_*_* values in newclient.h.
messageThe message text to display.

< When 0, the type is valid and may be used to pick the panel routing, otherwise the message can only go to the main message pane.

Definition at line 932 of file info.c.

References add_marked_text_to_pane(), info_buffer_t::age, info_buffer_t::count, buffer_control_t::count, COUNT_BUFFER_SIZE, info_buffer, info_buffer_flush(), info_buffer_init(), LOG(), LOG_ERROR, info_buffer_t::message, MESSAGE_BUFFER_COUNT, MESSAGE_BUFFER_SIZE, msgctrl_widgets, NUM_TEXT_VIEWS, info_buffer_t::orig_color, info_buffer_t::subtype, info_buffer_t::type, and want_config.

Referenced by add_marked_text_to_pane(), bind_key(), client_negotiate(), command_foodbeep(), command_show(), command_take(), complete_command(), configure_keys(), draw_prompt(), DrawInfoCmd(), focusoutfunc(), get_image_info(), handle_local_command(), handle_query(), init_common_cache_data(), keybinding_get_data(), list_item_action(), message_callback(), new_menu_pickup(), parse_key(), parse_key_release(), print_inventory(), save_defaults(), save_keys(), save_msgctrl_configuration(), save_winpos(), script_init(), script_kill(), script_list(), script_process_cmd(), script_tell(), set_command_window(), SetupCmd(), show_keys(), toggle_keybind_scope(), unbind_key(), and unbind_usage().

Here is the call graph for this function:

Here is the caller graph for this function:

void info_get_styles ( void  )

Loads up values from the style file.

Note that the actual name of the style file is set elsewhere.

This function is designed so that it should be possible to call it multiple times - it will release old style data and load up new values. In this way, a user should be able to change styles on the fly and have things work.

Definition at line 516 of file info.c.

Referenced by load_theme().

Here is the caller graph for this function:

void info_init ( GtkWidget *  window_root)

Initialize the information panels in the client.

These panels are the client areas where text is drawn.

Parameters
window_rootPointer to the parent (root) application window.

Definition at line 649 of file info.c.

Referenced by init_ui().

Here is the caller graph for this function:

void load_msgctrl_configuration ( void  )

Setup the state of the message control dialog so the configuration matches a previously saved configuration.

Definition at line 1579 of file info.c.

Referenced by save_msgctrl_configuration().

Here is the caller graph for this function:

void menu_clear ( void  )

Clears all the message panels.

It is not clear why someone would use it, but is called from the common area, and so is supported here.

Definition at line 1312 of file info.c.

References dialog_xml, and msgctrl_window.

Referenced by do_clearinfo(), and message_callback().

Here is the caller graph for this function:

void msgctrl_init ( GtkWidget *  window_root)

Initialize the message control panel by populating it with descriptions of each message type along with checkboxes that are used to configure the routing and duplicate suppression system.

If previously saved settings are found on disk, they are loaded and applied, otherwise the built in client defaults are loaded and applied. This initialization must occur after the info_init() function runs.

Parameters
window_rootThe client main window
Todo:
Panes that are unsupported in the current layout should always have their routing disabled, and should disallow user interaction with the control but this logic is not yet implemented.

Definition at line 1331 of file info.c.

Referenced by init_ui().

Here is the caller graph for this function:

void on_msgctrl_activate ( GtkMenuItem *  menuitem,
gpointer  user_data 
)

Shows the message control dialog when the menu item is activated.

The settings shown on the dialog when it is activated are the settings currently in use.

Parameters
menuitem
user_data

Definition at line 1896 of file info.c.

Referenced by init_menu_items().

Here is the caller graph for this function:

void on_msgctrl_button_apply_clicked ( GtkButton *  button,
gpointer  user_data 
)

When the message control dialog apply button is pressed, the currently displayed settings are applied.

The dialog is not dismissed, but remains open for further adjustments to be made.

Parameters
button
user_data

Definition at line 1866 of file info.c.

void on_msgctrl_button_close_clicked ( GtkButton *  button,
gpointer  user_data 
)

When the message control dialog close button is pressed, the currently displayed settings are applied and the dialog is dismissed.

Parameters
button
user_data

Definition at line 1880 of file info.c.

void on_msgctrl_button_defaults_clicked ( GtkButton *  button,
gpointer  user_data 
)

When the message control dialog defaults button is pressed, the default settings built into the client are restored and applied.

Parameters
button
user_data

Definition at line 1851 of file info.c.

References read_msgctrl_configuration().

Here is the call graph for this function:

void on_msgctrl_button_load_clicked ( GtkButton *  button,
gpointer  user_data 
)

When the message control dialog load button is pressed, the settings last saved are restored and applied.

It may be used to "undo" both applied and unapplied setting changes.

Parameters
button
user_data

Definition at line 1837 of file info.c.

References read_msgctrl_configuration().

Here is the call graph for this function:

void on_msgctrl_button_save_clicked ( GtkButton *  button,
gpointer  user_data 
)

When the message control dialog save button is pressed, the currently shown settings are applied for immediate use and they are saved to disk so the settings persist across client sessions.

Saved settings automatically load and apply when the client is started.

Parameters
button
user_data

Definition at line 1821 of file info.c.

void read_msgctrl_configuration ( void  )

Reads the state of the message control dialog and applies the settings to the msgctrl_widgets[] state variables that control the message routing and duplicate suppression system.

Definition at line 1782 of file info.c.

Referenced by on_msgctrl_button_defaults_clicked(), and on_msgctrl_button_load_clicked().

Here is the caller graph for this function:

void save_msgctrl_configuration ( void  )

Applies the current state of the checkboxes to the msgctrl_widgets state variables and saves the settings to disk so the configuration persists across client sessions.

Definition at line 1511 of file info.c.

References buffer_control, config_dir, buffer_control_t::count, draw_ext_info(), load_msgctrl_configuration(), LOG(), LOG_DEBUG, MAX_BUF, MSG_TYPE_CLIENT, MSG_TYPE_CLIENT_CONFIG, MSG_TYPE_CLIENT_ERROR, msgctrl_widgets, NDI_BLUE, NDI_RED, NUM_TEXT_VIEWS, buffer_parameter_t::state, and buffer_control_t::timer.

Here is the call graph for this function:

void set_text_tag_from_style ( GtkTextTag *  tag,
GtkStyle *  style,
GtkStyle *  base_style 
)

EndOf GTK V2 Message Control System.

Sets attributes in the text tag from a style. Best I can gather, there is no way to take all of the attributes from a style and apply them directly to a text tag, hence this function to do the work. GtkTextTags also know what attributes are set and which are not set - thus, you can apply multiple tags to the same text, and get all of the effects. For styles, that isn't the case - a style contains all of the information. So this function also compares the loaded style from the base style, and only sets the attributes that are different.

Parameters
tagText tag to set values on.
styleStyle name to get values from.
base_styleBase style for the widget to compare against.

Definition at line 334 of file info.c.

References add_tags_to_textbuffer(), Info_Pane::color_tags, Info_Pane::font_tags, max_subtype, MSG_TYPE_LAST, Info_Pane::msg_type_tags, NUM_COLORS, NUM_FONTS, and Info_Pane::textbuffer.

Here is the call graph for this function:

void update_msgctrl_configuration ( void  )

Update the state of the message control dialog so the configuration matches the currently selected settings.

Do not call this before msgctrl_widgets[] is initialized. It also really only makes sense to call it if changes have been made to msgctrl_widgets[].

Definition at line 1481 of file info.c.

Variable Documentation

struct buffer_control_t buffer_control
Initial value:
= {
{ NULL, 0, MESSAGE_COUNT_MAX },
{ NULL, 0, MESSAGE_AGE_MAX }
}
#define MESSAGE_AGE_MAX
The maximum time in client ticks, that a message resides in a buffer before it is sent to a client pa...
Definition: info.c:148
#define MESSAGE_COUNT_MAX
The maximum number of times a buffered message may repeat before it is sent to a client panel for for...
Definition: info.c:139

Referenced by save_msgctrl_configuration().

const char* const colorname[NUM_COLORS]
const char* font_style_names[NUM_FONTS]
static
Initial value:
= {
"info_font_normal",
"info_font_arcane",
"info_font_strange",
"info_font_fixed",
"info_font_hand"
}

A mapping of font numbers to style based on the rcfile content.

Definition at line 47 of file info.c.

int has_style =0
static

Definition at line 90 of file info.c.

struct info_buffer_t info_buffer[MESSAGE_BUFFER_COUNT]

Several buffers that support suppression of duplicates even even when the duplicates are alternate with other messages.

Referenced by draw_ext_info(), and message_callback().

Definition at line 72 of file info.c.

int max_subtype =0
static

Definition at line 90 of file info.c.

Referenced by add_to_textbuf(), and set_text_tag_from_style().

struct msgctrl_data_t msgctrl_defaults[MSG_TYPE_LAST-1]
Initial value:
=
{
{ "Books", FALSE, { TRUE, FALSE } },
{ "Cards", FALSE, { TRUE, FALSE } },
{ "Paper", FALSE, { TRUE, FALSE } },
{ "Signs & Magic Mouths", FALSE, { TRUE, FALSE } },
{ "Monuments", FALSE, { TRUE, FALSE } },
{ "Dialogs (Altar/NPC/Magic Ear)" , FALSE, { TRUE, FALSE } },
{ "Message of the day", FALSE, { TRUE, FALSE } },
{ "Administrative", FALSE, { TRUE, FALSE } },
{ "Shops", TRUE, { TRUE, FALSE } },
{ "Command responses", FALSE, { TRUE, FALSE } },
{ "Changes to attributes", TRUE, { TRUE, TRUE } },
{ "Skill-related messages", TRUE, { TRUE, FALSE } },
{ "Apply results", TRUE, { TRUE, FALSE } },
{ "Attack results", TRUE, { TRUE, FALSE } },
{ "Player communication", FALSE, { TRUE, TRUE } },
{ "Spell results", TRUE, { TRUE, FALSE } },
{ "Item information", TRUE, { TRUE, FALSE } },
{ "Miscellaneous", TRUE, { TRUE, FALSE } },
{ "Victim notification", FALSE, { TRUE, TRUE } },
{ "Client-generated messages", FALSE, { TRUE, FALSE } }
}

A data structure to track how to handle each message type in with respect to panel routing and output count.

GtkWidget* msgctrl_table

The message control table where routing and buffer configuration is set up.

Definition at line 112 of file info.c.

message_control_t msgctrl_widgets[MSG_TYPE_LAST-1]

All of the checkbox widgets for the entire message control dialog.

Definition at line 249 of file info.c.

Referenced by draw_ext_info(), and save_msgctrl_configuration().

GtkWidget* msgctrl_window

The message control dialog where routing and buffer configuration is set up.

Definition at line 108 of file info.c.

Referenced by menu_clear().

const char *const usercolorname
static
Initial value:
= {
"black",
"white",
"darkblue",
"red",
"orange",
"lightblue",
"darkorange",
"green",
"darkgreen",
"grey",
"brown",
"yellow",
"tan"
}

Color names set by the user in the gtkrc file.

Definition at line 28 of file info.c.

Referenced by add_marked_text_to_pane(), and add_to_textbuf().