Crossfire Client, Branch  R11627
Data Structures | Defines | Functions | Variables
info.c File Reference

This covers drawing text to the info window. More...

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

Go to the source code of this file.

Data Structures

struct  Info_Pane

Defines

#define NUM_TEXT_VIEWS   2
 EndOf GTK V2 Font Style Definitions.

Functions

static void add_to_textbuf (int pane, char *message, int type, int subtype, int bold, int italic, int font, 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.
void draw_color_info (int colr, const char *buf)
 Display information in color.
void draw_info (const char *str, int color)
 Add text to the informational message windows.
int get_info_width (void)
 This is used by the common help system to determine when to wrap.
void info_get_styles (void)
 Loads up values from the style file.
void info_init (GtkWidget *window_root)
 Initialize the information panels in the client.
void menu_clear (void)
 Clears all the message panels.
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.
void set_autorepeat (const char *s)
 A stub function that does nothing.
void set_scroll (const char *s)
 A stub function that does nothing.
void set_text_tag_from_style (GtkTextTag *tag, GtkStyle *style, GtkStyle *base_style)
 Sets attributes in the text tag from a style.

Variables

const char *const colorname [NUM_COLORS]
static int has_style = 0
struct Info_Pane info_pane [NUM_TEXT_VIEWS]
static int max_subtype = 0
const char *const rcsid_gtk2_info_c = "$Id: info.c 11116 2008-12-30 06:57:53Z mwedel $"
const char *const usercolorname [NUM_COLORS]

GTK V2 Font Style Definitions.

Font style support definitions for the info window.

Font style defines are indices into the font_style_names[] array. The actual fonts that they are bound to are set up in the style file.

#define FONT_NORMAL   0
#define FONT_ARCANE   1
#define FONT_STRANGE   2
#define FONT_FIXED   3
#define FONT_HAND   4
#define NUM_FONTS   5
static char * font_style_names [NUM_FONTS]
 A mapping of font numbers to style based on the rcfile content.

Detailed Description

This covers drawing text to the info window.

Definition in file info.c.


Define Documentation

#define FONT_ARCANE   1

Definition at line 52 of file info.c.

Referenced by message_callback().

#define FONT_FIXED   3

Definition at line 54 of file info.c.

Referenced by message_callback().

#define FONT_HAND   4

Definition at line 55 of file info.c.

Referenced by message_callback().

#define FONT_NORMAL   0

Definition at line 51 of file info.c.

Referenced by message_callback().

#define FONT_STRANGE   2

Definition at line 53 of file info.c.

Referenced by message_callback().

#define NUM_FONTS   5

Definition at line 56 of file info.c.

Referenced by info_get_styles().

#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. FIXME: Create defines for each panel and replace panel numbers with the defines describing the panel.

Definition at line 79 of file info.c.

Referenced by info_get_styles(), info_init(), and menu_clear().


Function Documentation

static void add_to_textbuf ( int  pane,
char *  message,
int  type,
int  subtype,
int  bold,
int  italic,
int  font,
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 display 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 number to use - this is resolved to actual font style based on the users theme file.
colorstring version of the color
underlineIf true, should underline the text.

Definition at line 481 of file info.c.

References Info_Pane::adjustment, Info_Pane::color_tags, Info_Pane::default_tag, info_pane, LOG(), LOG_ERROR, max_subtype, MSG_TYPE_LAST, Info_Pane::msg_type_tags, NUM_COLORS, and usercolorname.

Referenced by message_callback().

Here is the call graph for this function:

Here is the caller graph for this function:

void draw_color_info ( int  colr,
const char *  buf 
)

Display information in color.

This function simply calls draw_info() with the parameter order swapped, and it provides no unique features. Since it is called from common, it is likely a legacy function that should probably be considered deprecated. Important: This function calls draw_info(), so if a color other than black is specified, the text is routed to both the primary and secondary (critical) message panes.

Parameters:
colrThe color to use when displaying text.
bufThe text to display.

Definition at line 742 of file info.c.

References draw_info().

Here is the call graph for this function:

void draw_info ( const char *  str,
int  color 
)

Add text to the informational message windows.

Colored text implies some level of importance, and results in the messge being auto-routed to the critical message panel. Note that with the textbufs, it seems you need to manually set it to the bottom of the screen - otherwise, the scrollbar just stays at the top. However, this does not seem ideal if you are trying to scroll back while new stuff comes in. Question: Is there a good reason for draw_info() and draw_color_info() to write directly to the message panel when add_to_textbuf() does this? Does it really make sense to use color to determine if a message is critical?.

Parameters:
strPointer to displayable text.
colorColor of the text.

Definition at line 662 of file info.c.

References Info_Pane::adjustment, info_pane, NDI_BLACK, and NDI_WHITE.

int get_info_width ( void  )

This is used by the common help system to determine when to wrap.

Should be able to get width of window, and divide by character width - however, still not perfect if we are using a variable width font. Actually, gtk can do word wrapping for us, so maybe the real fix is to have it to the word wrapping and just run a sufficiently large value. FIXME: should be better than hardcoded value.

Returns:
The width of the info window in characters.

Definition at line 795 of file info.c.

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 165 of file info.c.

References Info_Pane::bold_tag, Info_Pane::color_tags, Info_Pane::default_tag, font_style_names, Info_Pane::font_tags, has_init, has_style, info_pane, Info_Pane::italic_tag, LOG(), LOG_INFO, MAX_BUF, max_subtype, MSG_TYPE_LAST, msg_type_names, Info_Pane::msg_type_tags, NUM_COLORS, NUM_FONTS, NUM_TEXT_VIEWS, set_text_tag_from_style(), Msg_Type_Names::subtype, Msg_Type_Names::type, Info_Pane::underline_tag, and usercolorname.

Referenced by info_init(), and load_theme().

Here is the call graph for this function:

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_rootParent (root) window of the application.

Definition at line 413 of file info.c.

References Info_Pane::adjustment, FALSE, info_get_styles(), info_pane, MAX_BUF, message_callback(), MSG_TYPE_LAST, NUM_TEXT_VIEWS, Info_Pane::scrolled_window, setTextManager(), Info_Pane::textbuffer, Info_Pane::textmark, and Info_Pane::textview.

Referenced by main().

Here is the call graph for this function:

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 750 of file info.c.

References info_pane, and NUM_TEXT_VIEWS.

static void message_callback ( int  orig_color,
int  type,
int  subtype,
char *  message 
) [static]

A callback to accept messages along with meta information color and type.

Unlike the GTK V1 client, we don't do anything tricky like popups with different message types. However, we will choose different fonts, etc, based on this information - for this reason, we just use one callback, and change those minor things based on the callback. The message is parsed to handle embedded style codes.

Parameters:
orig_colorA suggested text color that may change based on message type/subtype.
typeThe message type. See the MSG_TYPE definitions in newclient.h
subtypeMessage subtype. See MSG_TYPE_..._... values in newclient.h
messageThe message text.

< Which pane the incoming message should go to.

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

Definition at line 573 of file info.c.

References add_to_textbuf(), FALSE, font, FONT_ARCANE, FONT_FIXED, FONT_HAND, FONT_NORMAL, FONT_STRANGE, has_style, LOG(), LOG_ERROR, LOG_INFO, NUM_COLORS, TRUE, and usercolorname.

Referenced by info_init().

Here is the call graph for this function:

Here is the caller graph for this function:

void set_autorepeat ( const char *  s)

A stub function that does nothing.

These are callbacks used by the common code, but they are not implemented in GTK, either because it makes no sense (set_scroll for example), or because it may not be technically possible to do so if we limit ourselves to proper GTK2 code (Eg, don't mess with the internals of X or platform specific issues)

Parameters:
s

Definition at line 780 of file info.c.

void set_scroll ( const char *  s)

A stub function that does nothing.

These are callbacks used by the common code, but they are not implemented in GTK, either because it makes no sense (set_scroll for example), or because it may not be technically possible to do so if we limit ourselves to proper GTK2 code (Eg, don't mess with the internals of X or platform specific issues)

Parameters:
s

Definition at line 767 of file info.c.

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

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 to get values from
base_stylebase style for the widget to compare against

Definition at line 133 of file info.c.

References FALSE.

Referenced by info_get_styles().

Here is the caller graph for this function:


Variable Documentation

const char* const colorname[NUM_COLORS]

Definition at line 60 of file main.c.

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 61 of file info.c.

Referenced by info_get_styles().

int has_style = 0 [static]

Definition at line 114 of file info.c.

Referenced by info_get_styles(), and message_callback().

int max_subtype = 0 [static]

Definition at line 114 of file info.c.

Referenced by add_to_textbuf(), and info_get_styles().

const char* const rcsid_gtk2_info_c = "$Id: info.c 11116 2008-12-30 06:57:53Z mwedel $"

Definition at line 1 of file info.c.

const char* const usercolorname[NUM_COLORS]

Definition at line 80 of file main.c.

Referenced by add_to_textbuf(), info_get_styles(), and message_callback().