Games-Axmud
view release on metacpan or search on metacpan
lib/Games/Axmud/Obj/TextView.pm view on Meta::CPAN
$colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $colourScheme);
$self->ivPoke('colourScheme', $colourSchemeObj->name);
$self->ivPoke('textColour', $colourSchemeObj->textColour);
$self->ivPoke('underlayColour', $colourSchemeObj->underlayColour);
$self->ivPoke('backgroundColour', $colourSchemeObj->backgroundColour);
$self->ivPoke('font', $colourSchemeObj->font);
$self->ivPoke('fontSize', $colourSchemeObj->fontSize);
# Apply the maximum number of lines, if specified; otherwise keep using the default value
if (defined $maxLines) {
$self->ivPoke('maxLines', $maxLines);
}
# Apply the default newline behaviour, if specified, otherwise keep using the default value
if (
defined $newLineDefault
&& (
$newLineDefault eq 'before'
|| $newLineDefault eq 'after'
|| $newLineDefault eq 'nl'
|| $newLineDefault eq 'echo'
)
) {
$self->ivPoke('newLineDefault', $newLineDefault);
}
# If $oldBuffer wasn't specified, create a new Gtk3::TextBuffer
if (! $oldBuffer) {
$self->ivPoke('buffer', Gtk3::TextBuffer->new());
# Create colour/style tags for the new textbuffer
$self->createColourTags();
$self->createStyleTags();
} else {
$self->ivPoke('buffer', $oldBuffer);
}
# Create the Gtk3::TextView(s)
my ($scroll, $scroll2, $vPaned, $textView, $textView2);
$textView = $self->createTextViewWidget($self->buffer, $colourSchemeObj);
if ($self->splitScreenMode eq 'single') {
# Pack the textview into a container widget
$scroll = $self->setupScroller($textView);
} else {
$textView2 = $self->createTextViewWidget($self->buffer, $colourSchemeObj);
# Pack the textviews into a container widget
($vPaned, $scroll, $scroll2) = $self->setupVPaned($textView, $textView2);
}
# Set the textview's CSS style
$axmud::CLIENT->desktopObj->setTextViewObjStyle(
$self->number,
$axmud::CLIENT->returnRGBColour($self->textColour),
$axmud::CLIENT->returnRGBColour($self->backgroundColour),
$self->font,
$self->fontSize,
$textView,
$textView2,
);
# Update IVs
$self->ivPoke('textView', $textView);
$self->ivPoke('textView2', $textView2);
$self->ivPoke('vPaned', $vPaned);
$self->ivPoke('scroll', $scroll);
$self->ivPoke('scroll2', $scroll2);
$self->ivPoke('sizeUpdateFlag', TRUE);
# Create a mark at the end of the buffer, with right gravity, so that whenever text is
# inserted, we can scroll to that mark (and the mark stays at the end)
# Also create a mark at the beginning of the buffer, with left gravity, for scrolling to the
# top
my $startMark
= $self->buffer->create_mark('start_mark', $self->buffer->get_start_iter(), TRUE);
my $endMark
= $self->buffer->create_mark('end_mark', $self->buffer->get_end_iter(), FALSE);
# ($self->insertNewLine creates a 'line_N' mark after every newline character, but not at
# the beginning of the Gtk3::TextBuffer)
$self->buffer->create_mark('line_0', $self->buffer->get_start_iter(), TRUE);
# Create a search mark which moves whenever $self->searchBuffer is called, and is initially
# at the beginning of the buffer
my $searchMark
= $self->buffer->create_mark('search_mark', $self->buffer->get_start_iter(), TRUE);
# Update IVs again
$self->ivPoke('startMark', $startMark);
$self->ivPoke('endMark', $endMark);
$self->ivPoke('searchMark', $searchMark);
# Gtk3::TextTags might not exist for any RGB tags that have just been copied to
# $self->textColour and/or $self->underlayColour, and $self->interpretTags won't have the
# opportunity to create them, so create them right away
$self->updateRGBTags();
if ($self->splitScreenMode eq 'single') {
return $scroll;
} else {
return $vPaned;
}
}
sub objDestroy {
# Called by GA::Table::Pane->objDestroy, ->removeSessionTab and ->removeTab
#
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $check) = @_;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->objUpdate', @_);
}
# Update the GA::Obj::Desktop registry
$axmud::CLIENT->desktopObj->del_textView($self);
return 1;
}
sub objUpdate {
# Called by GA::Table::Pane->applyColourScheme or ->updateColourScheme (must not be called
# directly)
# Also called by $self->setMonochromeMode and ->resetMonochromeMode when a monochrome colour
# scheme is applied/removed
#
# Applies a colour scheme to this object's Gtk3::TextView(s)
#
# Expected arguments
# (none besides $self)
#
# Optional arguments
# $colourScheme
# - The new colour scheme to use (matches a key in GA::Client->colourSchemeHash).
# 'undef' when called by $self->applyMonochrome, in which the colours already
# stored in $self->textColour, ->underlayColour and ->backgroundColour are used
#
# Return values
# 'undef' on improper arguments or if the specified colour scheme doesn't exist
# 1 otherwise
my ($self, $colourScheme, $check) = @_;
# Local variables
my (
$colourSchemeObj, $backgroundColour, $textColour,
@list,
);
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->objUpdate', @_);
}
# Get the colour scheme object (the calling function has already checked it exists)
if ($colourScheme) {
$colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $colourScheme);
if (! $colourSchemeObj) {
return undef;
} else {
# Make sure the colour scheme's colour/font values are acceptable, to avoid getting
# nasty Gtk errors
$colourSchemeObj->repair();
# Update IVs. When the colour scheme is updated, the scheme's colours aren't applied
# in monochrome mode with modified colours (because some code, usually a task,
# specifically requested those colours)
$self->ivPoke('colourScheme', $colourSchemeObj->name);
if (! $self->monochromeFlag) {
$self->ivPoke('textColour', $colourSchemeObj->textColour);
$self->ivPoke('underlayColour', $colourSchemeObj->underlayColour);
$self->ivPoke('backgroundColour', $colourSchemeObj->backgroundColour);
} elsif (! $self->monochromeModFlag) {
$backgroundColour = $colourSchemeObj->backgroundColour;
if ($axmud::CLIENT->ivExists('constMonochromeHash', $backgroundColour)) {
# Choose a text colour to match the background colour in the standard way,
# ignoring the text colour specified by the colour scheme
$textColour = $axmud::CLIENT->ivShow(
'constMonochromeHash',
$backgroundColour,
);
} else {
# Non-standard background colour tag, in which case use the colour specified
# by the colour scheme itself, rather than choosing a matching colour
# (It's up to the person who edits the colour scheme to choose a suitable
# colour)
$textColour = $colourSchemeObj->textColour;
}
# In monochrome mode, the underlay colour is always the same as the background
$self->ivPoke('textColour', $textColour);
$self->ivPoke('underlayColour', undef);
$self->ivPoke('backgroundColour', $backgroundColour);
}
# The fonts are applied in all situations
$self->ivPoke('font', $colourSchemeObj->font);
$self->ivPoke('fontSize', $colourSchemeObj->fontSize);
}
}
# Update the textview's CSS style
$axmud::CLIENT->desktopObj->setTextViewObjStyle(
$self->number,
$self->textColour,
$self->backgroundColour,
$self->font,
$self->fontSize,
$self->textView,
$self->textView2, # May be 'undef'
);
# Gtk3::TextTags might not exist for any RGB tags that have just been copied to
# $self->textColour and/or $self->underlayColour, and $self->interpretTags won't have the
# opportunity to create them, so create them right away
$self->updateRGBTags();
# Create any new Gtk3::TextTags that don't already exist, using a phoney call to
# $self->interpretTags
# NB Default values for these IVs are 'undef', so we have to check for that
if ($self->textColour) {
push (@list, $self->textColour);
}
if ($self->underlayColour) {
push (@list, $self->underlayColour);
}
if ($self->backgroundColour) {
push (@list, $self->backgroundColour);
}
if (@list) {
$self->interpretTags($self->newLineDefault, @list);
}
# Operation complete
return 1;
}
# ->signal_connects
sub setMotionNotifyEvent {
# Called by $self->createTextViewWidget
# Set up a ->signal_connect to watch out for the motion over clickable links
#
# Expected arguments
# $textView - The Gtk3::TextView that generated the signal (later stored in either
# $self->textView or $self->textView2)
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $textView, $check) = @_;
# Check for improper arguments
if (! defined $textView || defined $check) {
lib/Games/Axmud/Obj/TextView.pm view on Meta::CPAN
}
if (defined $text && $text ne '') {
if ($taskFlag) {
# Write the message in the System task window, but remove an 'empty' argument if one
# was specified for the 'main' window
foreach my $item (@args) {
if ($item ne 'empty') {
push (@modArgs, $item);
}
}
$self->session->systemTask->showSystemText($text, @modArgs);
}
if ($consoleFlag) {
# Send the message to the GA::Session, for display (now or later) in the Session
# Console window
$self->session->add_systemMsg('system', $text);
}
# Write to logs and convert text-to-speech, if required
# Only a complete line (ending in a newline character) is written to logs and/or
# converted to text-to-speech; until then, a partial system message is stored in a
# buffer
if (! $self->systemTextBuffer) {
$self->ivPoke('systemTextBuffer', $text);
} else {
$self->ivPoke('systemTextBuffer', $self->systemTextBuffer . $text);
}
}
if (($beforeFlag || $afterFlag) && $self->systemTextBuffer) {
# Write to logs
$axmud::CLIENT->writeLog(
$self->session,
TRUE, # Not world-specific logs
$self->systemTextBuffer,
$beforeFlag,
$afterFlag,
'main', 'system', # Write to these files
);
# Convert text-to-speech, if required (but don't try to convert an 'undef' or text
# containing no readable characters)
if (
$axmud::CLIENT->systemAllowTTSFlag
&& $axmud::CLIENT->ttsSystemFlag
&& defined $self->systemTextBuffer
&& $self->systemTextBuffer =~ m/\w/
# Also, temporarily don't convert system messages if the GA::Session flag is set
&& ! $self->session->ttsTempDisableFlag
) {
# Make sure the received text is visible in the textview(s)...
$axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showSystemText');
# ...before converting text to speech
if (
$axmud::CLIENT->ttsVerboseFlag
&& defined $self->session->ttsLastType
&& $self->session->ttsLastType ne 'system'
) {
# Last TTS conversion was something other than a system message
$axmud::CLIENT->tts(
'System message: ' . $self->systemTextBuffer,
'system',
'system',
$self->session,
);
} else {
# (Don't read out 'system message' again and again and again!
$axmud::CLIENT->tts(
$self->systemTextBuffer,
'system',
'system',
$self->session,
);
}
}
# Fire any hooks that are using the system hook events
$self->session->checkHooks('system_text', $self->systemTextBuffer);
$self->session->checkHooks('system_all', $self->systemTextBuffer);
$self->ivUndef('systemTextBuffer');
}
# This type of system message always requires a return value of 1
return 1;
}
sub showError {
# Called by Games::Axmud->writeError
# Inserts a system error message into the Gtk3::TextBuffer and/or updates the System task's
# window
#
# Expected arguments
# (none besides $self)
#
# Optional arguments
# $text - The system text to write. If undefined, the text <<undef>> is written
# $func - The function that produced the error (e.g.
# 'Games::Axmud::Client->helloWorld'). If 'undef', the function is not
# displayed
#
# Return values
# 'undef'
my ($self, $text, $func, $check) = @_;
# Local variables
my (
lib/Games/Axmud/Obj/TextView.pm view on Meta::CPAN
if ($self->scrollLockType eq 'top') {
$self->scrollToTop();
} else {
$self->scrollToBottom();
}
}
}
if (defined $msg && $msg ne '') {
if ($taskFlag) {
# Write the message in the System task window
$self->session->systemTask->showError($msg);
}
if ($consoleFlag) {
# Send the message to the GA::Session, for display (now or later) in the Session
# Console window
$self->session->add_systemMsg('error', $msg);
}
# Write to logs
$axmud::CLIENT->writeLog(
$self->session,
TRUE, # Not world-specific logs
$msg,
$beforeFlag,
TRUE, # Use final newline character
'main', 'errors', 'error', # Write to these files
);
# Fire any hooks that are using the system hook events
$self->session->checkHooks('system_error', $msg);
$self->session->checkHooks('system_all', $msg);
$self->session->checkHooks('system_all_error', $msg);
}
# Play a sound effect (if allowed, and if this textview object hasn't played the same
# sound effect recently)
if (! $self->soundCheckTime || $self->soundCheckTime < $axmud::CLIENT->clientTime) {
$axmud::CLIENT->playSound('error');
# Don't play it again for a few seconds
$self->ivPoke('soundCheckTime', ($axmud::CLIENT->clientTime + $self->soundDelayTime));
}
# Convert text-to-speech, if required (but don't try to convert an 'undef' or text
# containing no readable characters)
if (
$axmud::CLIENT->systemAllowTTSFlag
&& $axmud::CLIENT->ttsSystemErrorFlag
&& defined $text
&& $text =~ m/\w/
# Also, temporarily don't convert system messages if the GA::Session flag is set
&& ! $self->session->ttsTempDisableFlag
) {
# Make sure the received text is visible in the textview(s)...
$axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showError');
# ...before converting text to speech
if (
$axmud::CLIENT->ttsVerboseFlag
&& defined $self->session->ttsLastType
&& $self->session->ttsLastType ne 'error'
) {
# Last TTS conversion was something other than a system error (etc) message
$axmud::CLIENT->tts('System error: ' . $text, 'error', 'error', $self->session);
} else {
# (Don't read out 'system error' again and again and again!
$axmud::CLIENT->tts($text, 'error', 'error', $self->session);
}
}
# This type of system message always requires a return value of 'undef'
return undef;
}
sub showWarning {
# Called by Games::Axmud->writeWarning
# Inserts a system warning message into the Gtk3::TextBuffer and/or updates the System
# task's window
#
# Expected arguments
# (none besides $self)
#
# Optional arguments
# $text - The system text to write. If undefined, the text <<undef>> is written
# $func - The function that produced the warning (e.g.
# 'Games::Axmud::Client->helloWorld'). If 'undef', the function is not
# displayed
#
# Return values
# 'undef'
my ($self, $text, $func, $check) = @_;
# Local variables
my (
$colourSchemeObj, $monochromeFlag, $textColour, $msg, $systemTask, $hereFlag, $taskFlag,
$consoleFlag, $iter, $beforeFlag,
);
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->showWarning', @_);
}
# If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
$self->removeCursor();
# If the buffer is due to be cleared before inserting any text, then clear it
if ($self->clearAfterInsertFlag) {
# The TRUE argument means 'don't remove/move the cursor'
$self->clearBuffer(undef, TRUE);
lib/Games/Axmud/Obj/TextView.pm view on Meta::CPAN
if ($self->scrollLockType eq 'top') {
$self->scrollToTop();
} else {
$self->scrollToBottom();
}
}
}
if (defined $msg && $msg ne '') {
if ($taskFlag) {
# Write the message in the System task window
$self->session->systemTask->showWarning($msg);
}
if ($consoleFlag) {
# Send the message to the GA::Session, for display (now or later) in the Session
# Console window
$self->session->add_systemMsg('warning', $msg);
}
# Write to logs
$axmud::CLIENT->writeLog(
$self->session,
TRUE, # Not world-specific logs
$msg,
$beforeFlag,
TRUE, # Use final newline character
'main', 'errors', 'warning', # Write to these files
);
# Fire any hooks that are using the system hook events
$self->session->checkHooks('system_warning', $msg);
$self->session->checkHooks('system_all', $msg);
$self->session->checkHooks('system_all_error', $msg);
}
# Play a sound effect (if allowed, and if this textview object hasn't played the same
# sound effect recently)
if (! $self->soundCheckTime || $self->soundCheckTime < $axmud::CLIENT->clientTime) {
$axmud::CLIENT->playSound('error');
# Don't play it again for a few seconds
$self->ivPoke('soundCheckTime', ($axmud::CLIENT->clientTime + $self->soundDelayTime));
}
# Convert text-to-speech, if required (but don't try to convert an 'undef' or text
# containing no readable characters)
if (
$axmud::CLIENT->systemAllowTTSFlag
&& $axmud::CLIENT->ttsSystemErrorFlag
&& defined $text
&& $text =~ m/\w/
# Also, temporarily don't convert system messages if the GA::Session flag is set
&& ! $self->session->ttsTempDisableFlag
) {
# Make sure the received text is visible in the textview(s)...
$axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showWarning');
# ...before converting text to speech
if (
$axmud::CLIENT->ttsVerboseFlag
&& defined $self->session->ttsLastType
&& $self->session->ttsLastType ne 'error'
) {
# Last TTS conversion was something other than a system error (etc) message
$axmud::CLIENT->tts('System warning: ' . $text, 'error', 'error', $self->session);
} else {
# (Don't read out 'system warning' again and again and again!
$axmud::CLIENT->tts($text, 'error', 'error', $self->session);
}
}
# This type of system message always requires a return value of 'undef'
return undef;
}
sub showDebug {
# Called by Games::Axmud->writeDebug or ->wd
# Inserts a system debug message into the Gtk3::TextBuffer and/or updates the System task's
# window
#
# Expected arguments
# (none besides $self)
#
# Optional arguments
# $text - The system text to write. If undefined, the text <<undef>> is written
# $func - The function that produced the debug message (e.g.
# 'Games::Axmud::Client->helloWorld'). If 'undef', the function is not
# displayed
#
# Return values
# 'undef'
my ($self, $text, $func, $check) = @_;
# Local variables
my (
$colourSchemeObj, $monochromeFlag, $textColour, $msg, $systemTask, $hereFlag, $taskFlag,
$consoleFlag, $iter, $beforeFlag,
);
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->showDebug', @_);
}
# If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
$self->removeCursor();
# If the buffer is due to be cleared before inserting any text, then clear it
if ($self->clearAfterInsertFlag) {
# The TRUE argument means 'don't remove/move the cursor'
$self->clearBuffer(undef, TRUE);
lib/Games/Axmud/Obj/TextView.pm view on Meta::CPAN
if ($self->scrollLockType eq 'top') {
$self->scrollToTop();
} else {
$self->scrollToBottom();
}
}
}
if (defined $msg && $msg ne '') {
if ($taskFlag) {
# Write the message in the System task window
$self->session->systemTask->showDebug($msg);
}
if ($consoleFlag) {
# Send the message to the GA::Session, for display (now or later) in the Session
# Console window
$self->session->add_systemMsg('debug', $msg);
}
# Write to logs
$axmud::CLIENT->writeLog(
$self->session,
TRUE, # Not world-specific logs
$msg,
$beforeFlag,
TRUE, # Use final newline character
'main', 'errors', 'debug', # Write to these files
);
# Fire any hooks that are using the system hook events
$self->session->checkHooks('system_debug', $msg);
$self->session->checkHooks('system_all', $msg);
$self->session->checkHooks('system_all_error', $msg);
}
# Play a sound effect (if allowed, and if this textview object hasn't played the same
# sound effect recently)
if (! $self->soundCheckTime || $self->soundCheckTime < $axmud::CLIENT->clientTime) {
$axmud::CLIENT->playSound('error');
# Don't play it again for a few seconds
$self->ivPoke('soundCheckTime', ($axmud::CLIENT->clientTime + $self->soundDelayTime));
}
# Convert text-to-speech, if required (but don't try to convert an 'undef' or text
# containing no readable characters)
if (
$axmud::CLIENT->systemAllowTTSFlag
&& $axmud::CLIENT->ttsSystemErrorFlag
&& defined $text
&& $text =~ m/\w/
# Also, temporarily don't convert system messages if the GA::Session flag is set
&& ! $self->session->ttsTempDisableFlag
) {
# Make sure the received text is visible in the textview(s)...
$axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showDebug');
# ...before converting text to speech
if (
$axmud::CLIENT->ttsVerboseFlag
&& defined $self->session->ttsLastType
&& $self->session->ttsLastType ne 'error'
) {
# Last TTS conversion was something other than a system error (etc) message
$axmud::CLIENT->tts('System debug: ' . $text, 'error', 'error', $self->session);
} else {
# (Don't read out 'system debug' again and again and again!
$axmud::CLIENT->tts($text, 'error', 'error', $self->session);
}
}
# This type of system message always requires a return value of 'undef'
return undef;
}
sub showImproper {
# Called by Games::Axmud->writeImproper
# Inserts a system 'improper arguments' message into the Gtk3::TextBuffer and/or updates the
# System task's window
#
# Expected arguments
# $func - The function that produced the message (e.g.
# 'Games::Axmud::Client->helloWorld')
#
# Optional arguments
# @args - A list of arguments passed by the function that called the
# ->writeImproper() function. If no arguments were passed, an empty list
#
# Return values
# 'undef'
my ($self, $func, @args) = @_;
# Local variables
my (
$colourSchemeObj, $monochromeFlag, $textColour, $msg, $systemTask, $hereFlag, $taskFlag,
$consoleFlag, $iter, $beforeFlag,
);
# Check for improper arguments
if (! defined $func) {
# This function mustn't call itself, so write something to the terminal
print "ERROR: Recursive improper arguments call from $func\n";
return undef;
}
# Import the colour scheme in use
$colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $self->colourScheme);
# Choose which colour tags to use (in monochrome mode, text/underlay colours are ignored,
# but in this case we don't any apply overrides specified by the colour scheme)
if ($self->monochromeFlag || ($colourSchemeObj && $colourSchemeObj->overrideAllFlag)) {
$monochromeFlag = TRUE;
lib/Games/Axmud/Obj/TextView.pm view on Meta::CPAN
$self->scrollToTop();
} else {
$self->scrollToBottom();
}
}
}
if (defined $msg && $msg ne '') {
if ($taskFlag) {
# Write the message in the System task window
$self->session->systemTask->showImproper($msg);
}
if ($consoleFlag) {
# Send the message to the GA::Session, for display (now or later) in the Session
# Console window
$self->session->add_systemMsg('improper', $msg);
}
# Write to logs
$axmud::CLIENT->writeLog(
$self->session,
TRUE, # Not world-specific logs
$msg,
$beforeFlag,
TRUE, # Use final newline character
'main', 'errors', 'improper', # Write to these files
);
# Fire any hooks that are using the system hook events
$self->session->checkHooks('system_improper', $msg);
$self->session->checkHooks('system_all', $msg);
$self->session->checkHooks('system_all_error', $msg);
}
# Play a sound effect (if allowed, and if this textview object hasn't played the same
# sound effect recently)
if (! $self->soundCheckTime || $self->soundCheckTime < $axmud::CLIENT->clientTime) {
$axmud::CLIENT->playSound('error');
# Don't play it again for a few seconds
$self->ivPoke('soundCheckTime', ($axmud::CLIENT->clientTime + $self->soundDelayTime));
}
# # v1.2.208 Improper args messages are incomprehensible, when converted to speech; so this
# # is now disabled
# # Convert text-to-speech, if required (but don't try to convert an 'undef' or text
# # containing no readable characters)
# if (
# $axmud::CLIENT->systemAllowTTSFlag
# && $axmud::CLIENT->ttsSystemFlag
# && defined $msg
# && $msg =~ m/\w/
# # Also, temporarily don't convert system messages if the GA::Session flag is set
# && ! $self->session->ttsTempDisableFlag
# ) {
# # Make sure the received text is visible in the textview(s)...
# $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showImproper');
#
# # ...before converting text to speech
# $axmud::CLIENT->tts(
# 'System error: improper arguments in function: ' . $func,
# 'error',
# 'error',
# $self->session,
# );
# }
# This type of system message always requires a return value of 'undef'
return undef;
}
sub showImage {
# Can be called by anything
# Inserts an image pixbuf into the textview at the current insertion point
#
# Expected arguments
# $pixbuf - The Gtk3::Gdk::Pixbuf or Gtk3::Gdk::PixbufAnimation of the image to
# display
#
# Optional arguments
# $linkObj - For clickable images, the corresponding GA::Obj::Link object. Can be a an
# incomplete link object created by GA::Session's MXP functions (for
# example), or a completed link object stored in this textview object's
# ->linkObjHash; otherwise 'undef'
# $padWidth, $padHeight
# - Optional padding around the image, in pixels (not the width/height of the
# image itself; that is only specified by the pixbuf)
# @args - Optional list of arguments, in any order:
# - 'empty' (empties the buffer before writing $text)
# - 'before' (prepends a newline character to $text)
# - 'after' or 'nl' (appends a newline character to $text)
# - 'echo' (does not prepend/append a newline character, overrides
# 'before', 'after' and 'nl' if they are specified)
#
# - NB The default behaviour is set by $self->defaultNewLine, which is set to
# 'before', 'after', 'nl' or 'echo'. This default behaviour is only
# applied if none of 'before', 'after', 'nl' and 'echo' are specified
# - NB If @args contains Axmud colour/style tags (as they might in a call to
# $self->insertText), they are ignored
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $pixbuf, $linkObj, $padWidth, $padHeight, @args) = @_;
# Local variables
my (
$animFlag, $emptyFlag, $beforeFlag, $afterFlag, $mark, $iter, $image, $packWidget,
$ebox, $anchor, $lineNum, $posn, $newMark, $newIter, $tempInsertFlag,
);
# Check for improper arguments
if (! defined $pixbuf) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->showImage', @_);
lib/Games/Axmud/Obj/TextView.pm view on Meta::CPAN
# doesn't have a ->hint set
$hint = $linkObj->hint;
if (! $self->winObj->winWidget->is_active() || ! $hint) {
return undef;
} else {
$self->textView->set_tooltip_text($hint);
if ($self->textView2) {
$self->textView2->set_tooltip_text($hint);
}
return 1;
}
}
sub showSessionTooltips {
# Called by $self->checkMousePosn (but only if this is the session's default textview, and
# if the mouse is hovering over a line containing text received from the world)
# Shows the tooltips window to display information about the display buffer objects
# (GA::Buffer::Display) corresponding to this line
#
# Expected arguments
# $lineNum - The line number of the Gtk3::TextBuffer line above which the mouse is
# hovering
#
# Return values
# 'undef' on improper arguments or if the tooltip can't be shown
# 1 otherwise
my ($self, $lineNum, $check) = @_;
# Local variables
my $tooltip;
# Check for improper arguments
if (! defined $lineNum || defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->showSessionTooltips', @_);
}
# Don't show tooltips if the parent window isn't active
if (! $self->winObj->winWidget->is_active()) {
return undef;
}
if (defined $self->lastTooltipLine && $self->lastTooltipLine != $lineNum) {
# The mouse has moved over a new line. Make the tooltip window 'follow' it by
# briefly resetting the tooltip
$self->textView->set_tooltip_text('');
if ($self->textView2) {
$self->textView2->set_tooltip_text('');
}
$axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->checkMousePosn');
}
# Show the window
$tooltip = $self->ivShow('tooltipHash', $lineNum);
$self->textView->set_tooltip_text($tooltip);
if ($self->textView2) {
$self->textView2->set_tooltip_text($tooltip);
}
$self->ivPoke('lastTooltipLine', $lineNum);
return 1;
}
sub hideTooltips {
# Called by $self->checkMousePosn and various ->signal_connects in this textview object
#
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments or if the tooltip can't be hidden
# 1 otherwise
my ($self, $check) = @_;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->hideTooltips', @_);
}
# Hide the tooltips window
$self->textView->set_tooltip_text('');
if ($self->textView2) {
$self->textView2->set_tooltip_text('');
}
# Update IVs
$self->ivUndef('lastTooltipLine');
return 1;
}
sub useDisplayBufferNum {
# Called by GA::Session->processLineSegment (only)
# The calling function is informing us that this textview object is its default textview
# object, that it's about to call ->insertText, and that we should make a note of the
# session's current display buffer line number, so we can display our tooltips correctly
#
# Expected arguments
# $sessionLineNum - The session's display buffer line number (matching
# GA::Session->displayBufferCount)
#
# Return values
# 'undef' on improper arguments
lib/Games/Axmud/Obj/TextView.pm view on Meta::CPAN
return $axmud::CLIENT->writeImproper($self->_objClass . '->setSplitScreenMode', @_);
}
if ($mode eq $self->splitScreenMode) {
# No changes required
return undef;
} elsif ($mode eq 'single') {
return $self->enableSingleScreen();
} elsif ($mode eq 'split') {
return $self->enableSplitScreen();
} elsif ($mode eq 'hidden') {
return $self->enableHiddenSplitScreen();
}
}
sub enableSingleScreen {
# Called by $self->setSplitScreenMode (or directly by any code)
# Sets $self->splitScreenMode to 'single'
# If $self->splitScreenMode was 'split' or 'hidden', replaces the existing Gtk3::VPaned,
# containing two textviews, with a Gtk3::Frame containing a single textview, and returns
# the frame. The calling function should pack the frame into the space previously occupied
# by the vpaned
#
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments or if $self->splitScreenMode is already 'single'
# Otherwise, returns the Gtk3::Frame
my ($self, $check) = @_;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->enableSingleScreen');
}
if ($self->splitScreenMode eq 'single') {
# Nothing needs to be re-packed
return undef
} else {
# Set the new mode
$self->ivPoke('splitScreenMode', 'single');
# Create the new Gtk3::TextView, using the same Gtk3::TextBuffer as the original one
my $textView = $self->createTextViewWidget($self->buffer);
# Set the textview's CSS style
$axmud::CLIENT->desktopObj->setTextViewObjStyle(
$self->number,
$self->textColour,
$self->backgroundColour,
$self->font,
$self->fontSize,
$textView,
);
# Pack the textview into a container widget
my $scroll = $self->setupScroller($textView);
# Update IVs again
$self->ivPoke('textView', $textView);
$self->ivUndef('textView2');
$self->ivUndef('vPaned');
$self->ivPoke('scroll', $scroll);
$self->ivUndef('scroll2');
# In case split screen mode has just been turned off, check that the textview's size
# hasn't change (as soon as possible)
$self->ivPoke('sizeUpdateFlag', TRUE);
# Operation complete
return $scroll;
}
}
sub enableSplitScreen {
# Called by $self->setSplitScreenMode (or directly by any code)
# Sets $self->splitScreenMode to 'split'
# If $self->splitScreenMode was 'single', replaces the existing Gtk3::Frame, containing a
# single textview, with a Gtk3::VPaned, containing two textviews, and returns the vpaned.
# The calling function should pack the vpaned into the space previously occupied by the
# frame
# If $self->splitScreenMode was 'hidden', moves the divider so that the hidden textview
# becomes visible (if the user manually moved the divider, this function moves the
# divider to its default position for this mode)
#
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments or if $self->splitScreenMode is currently 'split' or
# 'hidden'
# Otherwise, returns the Gtk3::VPaned
my ($self, $check) = @_;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->enableSplitScreen');
}
if ($self->splitScreenMode eq 'split') {
# Nothing needs to be re-packed
return undef
} else {
if ($self->splitScreenMode eq 'hidden') {
# Set the new mode
$self->ivPoke('splitScreenMode', 'split');
# Move the divider and rescroll textviews to the bottom (for tidiest visual effect)
$self->setDividerPosn($self->vPaned);
$axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->enableSplitScreen');
$self->scrollToLock();
# Nothing needs to be re-packed
return undef
} else {
# Set the new mode
$self->ivPoke('splitScreenMode', 'split');
# Create the new Gtk3::TextView, using the same Gtk3::TextBuffer as the original one
my $textView2 = $self->createTextViewWidget($self->buffer);
# Update the textviews' CSS style
$axmud::CLIENT->desktopObj->setTextViewObjStyle(
$self->number,
$self->textColour,
$self->backgroundColour,
$self->font,
$self->fontSize,
$self->textView,
$textView2,
);
# Pack the textviews into a container widget
my ($vPaned, $scroll, $scroll2) = $self->setupVPaned($self->textView, $textView2);
# Update IVs again
$self->ivPoke('textView2', $textView2);
$self->ivPoke('vPaned', $vPaned);
$self->ivPoke('scroll', $scroll);
$self->ivPoke('scroll2', $scroll2);
# Operation complete
return $vPaned;
}
}
}
sub enableHiddenSplitScreen {
# Called by $self->setSplitScreenMode (or directly by any code)
# Sets $self->splitScreenMode to 'hidden'
# If $self->splitScreenMode was 'single', replaces the existing Gtk3::Frame, containing a
# single textview, with a Gtk3::VPaned, containing two textviews, and returns the vpaned.
# The calling function should pack the vpaned into the space previously occupied by the
# frame
# If $self->splitScreenMode was 'split', moves the divider so that the second textview
# becomes hidden
#
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments or if $self->splitScreenMode is currently 'split' or
# 'hidden'
# Otherwise, returns the Gtk3::VPaned
my ($self, $check) = @_;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->enableHiddenSplitScreen');
}
if ($self->splitScreenMode eq 'hidden') {
# Nothing needs to be re-packed
return undef
} else {
if ($self->splitScreenMode eq 'split') {
# Set the new mode
$self->ivPoke('splitScreenMode', 'hidden');
# Move the divider and rescroll textviews to the bottom (for tidiest visual effect)
$self->setDividerPosn($self->vPaned);
$axmud::CLIENT->desktopObj->updateWidgets(
$self->_objClass . '->enableHiddenSplitScreen',
);
$self->scrollToLock();
# In case split screen mode has just been turned off, check that the textview's size
# hasn't change (as soon as possible)
$self->ivPoke('sizeUpdateFlag', TRUE);
# Nothing needs to be re-packed
return undef
} else {
# Set the new mode
$self->ivPoke('splitScreenMode', 'hidden');
# Create the new Gtk3::TextView, using the same Gtk3::TextBuffer as the original one
my $textView2 = $self->createTextViewWidget($self->buffer);
# Update the textviews' CSS style
$axmud::CLIENT->desktopObj->setTextViewObjStyle(
$self->number,
$self->textColour,
$self->backgroundColour,
$self->font,
$self->fontSize,
$self->textView,
$textView2,
);
# Pack the textviews into a container widget
my ($vPaned, $scroll, $scroll2) = $self->setupVPaned($self->textView, $textView2);
# Update IVs again
$self->ivPoke('textView2', $textView2);
$self->ivPoke('vPaned', $vPaned);
$self->ivPoke('scroll', $scroll);
$self->ivPoke('scroll2', $scroll2);
# Operation complete
return $vPaned;
}
}
}
sub checkMousePosn {
# Called by ->signal_connects in $self->setMotionNotifyEvent
# When the mouse moves over a clickable link in a Gtk3::TextView, we should change the mouse
# cursor. When the mouse moves away from a clickable link, we should restore the mouse
# cursor
#
# NB This function isn't used for clickable images. ->signal_connects for that are found in
# $self->showImage
#
# Expected arguments
# $textView - The Gtk3::TextView over which the mouse is moving
# $event - The Gtk3::Gdk::Event
#
# Return values
# 'undef' on improper arguments
# 1 on success
my ($self, $textView, $event, $check) = @_;
# Local variables
my (
$xPos, $yPos, $iter, $lineNum, $posn, $hoverFlag, $listRef, $window, $listRef2,
$linkObj, $tooltipsFlag, $tooltip,
);
# Check for improper arguments
if (! defined $textView || ! defined $event || defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->checkMousePosn', @_);
}
# Get the mouse's position over the textview's buffer
($xPos, $yPos) = $textView->window_to_buffer_coords('widget', $event->x, $event->y);
# Get the buffer iter corresponding to that position
$iter = $textView->get_iter_at_location($xPos, $yPos);
( run in 0.499 second using v1.01-cache-2.11-cpan-f56aa216473 )