color Function

private pure function color(self) result(c)

The color: [r, g, b, a] (0 to 1).

Type Bound

HUDText

Arguments

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

Return Value real(kind=wp), (4)


Called by

proc~~color~~CalledByGraph proc~color HUDText%color proc~create_hud create_hud proc~create_hud->proc~color proc~update_huds update_huds proc~update_huds->proc~color proc~update_huds->proc~create_hud proc~add_hud_text WindowProxy%add_hud_text proc~add_hud_text->proc~create_hud proc~create_huds create_huds proc~create_huds->proc~create_hud proc~frame WindowProxy%frame proc~frame->proc~update_huds proc~frame->proc~create_huds proc~resize WindowProxy%resize proc~resize->proc~frame proc~run WindowProxy%run proc~run->proc~frame

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

    !> [r, g, b] (alpha unchanged) or [r, g, b, a], 0 to 1.
    subroutine set_color(self, color)
        class(HUDText), intent(inout) :: self
        real(wp), intent(in) :: color(:)        !! [r, g, b] or [r, g, b, a] (0 to 1)
        integer :: n
        n = min(4, ubound(color, 1))
        self%color_(1:n) = color(1:n)
        self%revision_ = self%revision_ + 1
    end subroutine set_color

    !> The color: [r, g, b, a] (0 to 1).
    pure function color(self) result(c)
        class(HUDText), intent(in) :: self
        real(wp) :: c(4)
        c = self%color_
    end function color