Games-Axmud

 view release on metacpan or  search on metacpan

lib/Games/Axmud/Obj/TextView.pm  view on Meta::CPAN

        }

        # Import IVs (for convenience)
        %colourTagHash = $axmud::CLIENT->colourTagHash;
        %boldColourTagHash = $axmud::CLIENT->boldColourTagHash;
        %xTermColourTagHash = $axmud::CLIENT->xTermColourHash;

        # Standard (normal) colour tags
        foreach my $tag (keys %colourTagHash) {

            # Text colours have tags in the format 'green' for normal colours and 'GREEN' for bold
            #   colours
            $self->buffer->create_tag(
                $tag,
                'foreground'    => $colourTagHash{$tag},
            );

            # Underlay colours have tags in the format 'ul_green' for normal colours and 'UL_GREEN'
            #   for bold colours
            $self->buffer->create_tag(
                'ul_' . $tag,
                'background'    => $colourTagHash{$tag},
            );
        }

        # Standard (bold) colour tags
        foreach my $tag (keys %boldColourTagHash) {

            $self->buffer->create_tag(
                $tag,
                'foreground'    => $boldColourTagHash{$tag},
            );

            $self->buffer->create_tag(
                'UL_' . $tag,
                'background'    => $boldColourTagHash{$tag},
            );
        }

        # XTerm colour tags
        foreach my $tag (keys %xTermColourTagHash) {

            # Text colours, e.g. 'x255'
            $self->buffer->create_tag(
                $tag,
                'foreground'    => $xTermColourTagHash{$tag},
            );

            # Underlay colours, e.g. 'ux255'
            $self->buffer->create_tag(
                'u' . $tag,
                'background'    => $xTermColourTagHash{$tag},
            );
        }

        # (NB RGB colour tags, e.g. '#ABCDEF', are created by $self->interpretTags when required)

        return 1;
    }

    sub updateStandardTag {

        # Called by GA::Cmd::SetColour->do
        # Updates the Gtk3::TextTag for a specified Axmud standard text colour tag, when the colour
        #   is modified
        # If the Gtk3::TextTag doesn't exist (for some reason), creates it
        #
        # Expected arguments
        #   $tag    - An Axmud standard text or underlay colour tag, e.g. 'red', 'BLUE', 'ul_red',
        #               'UL_BLUE')
        #
        # Return values
        #   'undef' on improper arguments or if $tag isn't an Axmud standard colour tag
        #   1 otherwise

        my ($self, $tag, $check) = @_;

        # Local variables
        my ($type, $underlayFlag, $boldType, $tagTable, $textTag, $rgb);

        # Check for improper arguments
        if (! defined $tag || defined $check) {

             return $axmud::CLIENT->writeImproper($self->_objClass . '->updateStandardTag', @_);
        }

        # Check $tag is an Axmud standard colour tag
        ($type, $underlayFlag) = $axmud::CLIENT->checkColourTags($tag);
        $boldType = $axmud::CLIENT->checkBoldTags($tag);

        if (! $type || $type ne 'standard') {

            return undef;
        }

        # Get Gtk3 objects
        $tagTable = $self->buffer->get_tag_table();
        $textTag = $tagTable->lookup($tag);
        if (! $textTag) {

            # Add a new Gtk3::TextTag
            if (! $boldType) {

                if (! $underlayFlag) {

                    $self->buffer->create_tag(
                        $tag,
                        'foreground'    => $axmud::CLIENT->ivShow('colourTagHash', $tag),
                    );

                } else {

                    $self->buffer->create_tag(
                        $tag,
                        'background'    => $axmud::CLIENT->returnRGBColour($tag),
                    );
                }

            } else {

                if ($boldType eq 'text') {

                    $self->buffer->create_tag(
                        $tag,
                        'foreground'    => $axmud::CLIENT->ivShow('boldColourTagHash', $tag),
                    );

                } else {

                    $self->buffer->create_tag(
                        $tag,
                        'background'    => $axmud::CLIENT->returnRGBColour($tag),
                    );
                }
            }

        } else {

            # Modify an existing Gtk3::TextTag
            if (! $boldType) {

                if (! $underlayFlag) {

                    $textTag->set_property(
                        'foreground'    => $axmud::CLIENT->ivShow('colourTagHash', $tag),
                    );

                } else {

                    $textTag->set_property(
                        'background'    => $axmud::CLIENT->returnRGBColour($tag),
                    );
                }

            } else {

                if ($boldType eq 'text') {

                    $textTag->set_property(
                        'foreground'    => $axmud::CLIENT->ivShow('boldColourTagHash', $tag),
                    );

                } else {

                    $textTag->set_property(
                        'background'    => $axmud::CLIENT->returnRGBColour($tag),
                    );
                }
            }
        }

        return 1;
    }

    sub updateXTermTags {

        # Called by GA::Cmd::SetXTerm->do
        # Updates all Gtk3::TextTags for xterm colour tags, usually after the xterm colour cube is
        #   switched
        # If the Gtk3::TextTag doesn't exist (for some reason), creates it
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

        my ($self, $check) = @_;

        # Local variables
        my (
            $tagTable,
            %tagHash,
        );

        # Check for improper arguments
        if (defined $check) {

             return $axmud::CLIENT->writeImproper($self->_objClass . '->updateXTermTags', @_);
        }

        # Import the IV
        %tagHash = $axmud::CLIENT->xTermColourHash;
        # Get Gtk3::TextTagTable
        $tagTable = $self->buffer->get_tag_table();

        # Update (or create) each xterm colour tag in turn
        foreach my $tag (keys %tagHash) {

            my ($textTag, $underlayTag);

            # Text colours, e.g. 'x255'
            $textTag = $tagTable->lookup($tag);
            if (! $textTag) {

                $self->buffer->create_tag(
                    $tag,
                    'foreground'    => $tagHash{$tag},
                );

            } else {

                $textTag->set_property(
                    'foreground'    => $tagHash{$tag},
                );
            }

            # Underlay colours, e.g. 'ux255'
            $underlayTag = $tagTable->lookup('u' . $tag);
            if (! $underlayTag) {

                $self->buffer->create_tag(
                    'u' . $tag,
                    'background'    => $tagHash{$tag},
                );

            } else {

                $underlayTag->set_property(
                    'background'    => $tagHash{$tag},
                );
            }
        }

        return 1;
    }

    sub updateRGBTags {

        # Called by $self->objEnable and ->objUpdate (only)
        # When a colour scheme is applied to this textview, $self->textColour and/or
        #   ->underlayColour might be set
        # Gtk3::TextTags are usually created only as needed by $self->interpretTags, but that
        #   function won't have a chance to create Gtk3::TextTags if $self->textColour and/or
        #   ->underlayColour are now set to RGB colour tags like '#ABCDEF and 'u#ABCDEF'
        # Check which (if any) Gtk3::TextTags must be created, and create them
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

        my ($self, $check) = @_;

        # Local variables
        my ($textColour, $underlayColour, $type, $ulFlag);

        # Check for improper arguments
        if (defined $check) {

            return $axmud::CLIENT->writeImproper($self->_objClass . '->updateRGBTags', @_);
        }

        if ($self->textColour) {

            $textColour = $self->textColour;

            ($type, $ulFlag) = $axmud::CLIENT->checkColourTags($textColour, 'rgb');
            if (defined $type && ! $self->buffer->get_tag_table->lookup($textColour)) {

                if (! $ulFlag) {

                    $self->buffer->create_tag(
                        $textColour,                                    # e.g. '#FFFFFF'
                        'foreground' => $textColour,                    # e.g. '#FFFFFF'
                    );

                } else {

                    # This should never be executed, but it's better to be safe than sorry
                    $self->buffer->create_tag(
                        $textColour,                                    # e.g. 'u#FFFFFF'
                        'background' => substr($textColour, 1),         # e.g. '#FFFFFF'
                    );
                }
            }
        }

        if ($self->underlayColour) {

            $underlayColour = $self->underlayColour;

            ($type, $ulFlag) = $axmud::CLIENT->checkColourTags($underlayColour, 'rgb');
            if (defined $type && ! $self->buffer->get_tag_table->lookup($underlayColour)) {

                if ($ulFlag) {

                    $self->buffer->create_tag(
                        $underlayColour,                                # e.g. 'u#FFFFFF'
                        'background' => substr($underlayColour, 1),     # e.g. '#FFFFFF'
                    );

                } else {

                    # This should never be executed, but it's better to be safe than sorry
                    $self->buffer->create_tag(
                        $underlayColour,                                # e.g. '#FFFFFF'
                        'foreground' => $underlayColour,                # e.g. '#FFFFFF'
                    );

                }
            }
        }

        return 1;
    }

    sub updateLinkTag {

        # Called by GA::Session->detectPueblo
        # When Pueblo is enabled, links are displayed in cyan and with no underline (normally, they
        #   are displayed with no particular colour, but with an underline)
        # This function modifies the Gtk3::TextTag's properties to display links in the correct way
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Return values
        #   'undef' on improper arguments or if the 'link' tag is not updated
        #   1 if the 'link' tag is updated

        my ($self, $check) = @_;

        # Local variables
        my $linkTag;

        if (! $self->buffer || $self->session->puebloMode ne 'client_agree') {

            return undef;
        }

        $linkTag = $self->buffer->get_tag_table->lookup('link');
        if (! $linkTag) {

            return undef;
        }

        $linkTag->set_property(
            'foreground',
            $axmud::CLIENT->returnRGBColour($axmud::CLIENT->constPuebloLinkColour),
        );
        $linkTag->set_property('foreground-set', TRUE);
        $linkTag->set_property('underline', 'none');

        return 1;
    }

    sub createStyleTags {

        # Called by $self->objEnable
        # Defines the style tags used by this Gtk3::TextView to change the text style
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

        my ($self, $check) = @_;

        # Local variables
        my $background;

        # Check for improper arguments
        if (defined $check) {

            return $axmud::CLIENT->writeImproper($self->_objClass . '->createStyleTags', @_);

lib/Games/Axmud/Obj/TextView.pm  view on Meta::CPAN


                    } elsif ($linkObj->type eq 'mail') {

                        $window->set_cursor($axmud::CLIENT->constMailCursor);

                    } elsif (
                        $linkObj->type eq 'telnet'
                        || $linkObj->type eq 'ssh'
                        || $linkObj->type eq 'ssl'
                    ) {
                        $window->set_cursor($axmud::CLIENT->constTelnetCursor);

                    } elsif ($linkObj->type eq 'image') {

                        $axmud::CLIENT->writeDebug(
                            'Mouse above image link; examine code please',
                            $self->_objClass . '->checkMousePosn',
                        );

                    } elsif ($linkObj->type eq 'other') {

                        $window->set_cursor($axmud::CLIENT->constNormalCursor);
                    }

                    # If it's an MXP link with a hint, show the hint in the tooltip window
                    if ($linkObj->hint) {

                        # Unhide the tooltips window and display $linkObj's ->hint
                        $self->showLinkTooltips($linkObj);
                        $tooltipsFlag = TRUE;

                    } else {

                        # Hide the tooltips window
                        $self->hideTooltips();
                    }
                }
            }
        }

        # If there's no link tooltip visible, consider showing the session tooltip instead
        if ($axmud::CLIENT->mainWinTooltipFlag && ! $tooltipsFlag && ! $self->currentLinkObj) {

            # Only lines created by the GA::Session, and displayed in its default textview object,
            #   cause key-value pairs to be added to this hash
            # NB The Gtk3::Textbuffer renumbers its line every time we delete one from the
            #   beginning of the buffer, so here we must add $self->nextDeleteLine
            if ($self->ivExists('tooltipHash', ($lineNum + $self->nextDeleteLine))) {

                $self->showSessionTooltips($lineNum + $self->nextDeleteLine);

            } elsif ($self->lastTooltipLine) {

                $self->hideTooltips();
            }
        }

        return 1;
    }

    sub updateVisibleSize {

        # Called by Games::Axmud::Obj::Desktop->updateWidgets (only) for any textview object whose
        #   ->sizeUpdateFlag is set
        # Updates IVs and informs the GA::Session
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

        my ($self, $check) = @_;

        # Local variables
        my ($charWidth, $charHeight, $hashRef, $textViewWidth, $textViewHeight);

        # Check for improper arguments
        if (defined $check) {

            return $axmud::CLIENT->writeImproper($self->_objClass . '->updateVisibleSize', @_);
        }

        # Do nothing while split screen mode is on
        if ($self->splitScreenMode ne 'split') {

            # Get the width/height of a character in the Gtk3::TextView
            ($charWidth, $charHeight) = $self->getCharSize();
            # Get a Gtk3::Gdk::Rectangle
            $hashRef = $self->textView->get_visible_rect();
            # Get the size of the textview
            $textViewWidth = int($$hashRef{width} / $charWidth);
            $textViewHeight = int($$hashRef{height} / $charHeight);

            if (
                ! defined $self->textWidthChars
                || $textViewWidth != $self->textWidthChars
                || $textViewHeight != $self->textHeightChars
            ) {
                # The size has changed. Update IVs...
                $self->ivPoke('textWidthChars', $textViewWidth);
                $self->ivPoke('textHeightChars', $textViewHeight);
                # ...and inform the parent GA::Session
                $self->session->textViewSizeUpdate($self);
            }
        }

        $self->ivPoke('sizeUpdateFlag', FALSE);

        return 1;
    }

    sub getCharSize {

        # Called by $self->updateVisibleSize
        # Gets the size (in pixels) of a single character in the Gtk3::TextView
        #
        # Expected arguments
        #   (none besides $self)
        #



( run in 3.791 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )