size Function

private pure function size(self)

The size of the text: character height (window units).

Type Bound

HUDText

Arguments

Type IntentOptional Attributes Name
class(HUDText), intent(in) :: self

Return Value real(kind=wp)


Source Code

    function new_hud_text(text, position, alignment, size, color, font) result(h)
        character(len=*), intent(in) :: text            !! the text
        real(wp), intent(in), optional :: position(2)   !! [x, y] (0 to 1 across the window, y up)
        real(wp), intent(in), optional :: size          !! character height (window units)
        real(wp), intent(in), optional :: color(:)      !! [r, g, b] or [r, g, b, a] (0 to 1)
        integer, intent(in), optional :: alignment      !! an ALIGN_* constant
        character(len=*), intent(in), optional :: font  !! font file
        type(HUDText) :: h
        h%text_ = text
        if (present(position)) h%position_ = position
        if (present(alignment)) h%alignment_ = alignment
        if (present(size)) h%size_ = size
        if (present(color)) call h%set_color(color)
        if (present(font)) h%font_ = font
    end function new_hud_text

    !> Set the text (up to 256 characters, or twice the first text's length; see the module documentation).
    subroutine set_text(self, text)
        class(HUDText), intent(inout) :: self
        character(len=*), intent(in) :: text    !! the text
        self%text_ = text
        self%revision_ = self%revision_ + 1
    end subroutine set_text

    !> The text (as shown: '' while hidden).
    function text(self) result(t)
        class(HUDText), intent(in) :: self
        character(len=:), allocatable :: t
        t = ''
        if (allocated(self%text_) .and. self%shown) t = self%text_
    end function text

    !> Set where the text is.
    subroutine set_position(self, position)
        class(HUDText), intent(inout) :: self
        real(wp), intent(in) :: position(2)     !! [x, y] (0 to 1 across the window, y up)
        self%position_ = position
        self%revision_ = self%revision_ + 1
    end subroutine set_position

    !> Where the text is: [x, y] (0 to 1 across the window, y up).
    pure function position(self) result(p)
        class(HUDText), intent(in) :: self
        real(wp) :: p(2)
        p = self%position_
    end function position

    !> Set which point of the text is at its position.
    subroutine set_alignment(self, alignment)
        class(HUDText), intent(inout) :: self
        integer, intent(in) :: alignment        !! an ALIGN_* constant
        self%alignment_ = alignment
        self%revision_ = self%revision_ + 1
    end subroutine set_alignment

    !> Which point of the text is at its position (an ALIGN_* constant).
    pure integer function alignment(self)
        class(HUDText), intent(in) :: self
        alignment = self%alignment_
    end function alignment

    !> Set the size of the text.
    subroutine set_size(self, size)
        class(HUDText), intent(inout) :: self
        real(wp), intent(in) :: size            !! character height (window units)
        self%size_ = size
        self%revision_ = self%revision_ + 1
    end subroutine set_size

    !> The size of the text: character height (window units).
    pure real(wp) function size(self)
        class(HUDText), intent(in) :: self
        size = self%size_
    end function size