Glimmr Canvas-Based Drawing

version 2/101030 by Erik Temple

  • Home page
  • Beginning
  • Previous
  • Next



  • Section - Image-rendered string drawing rule

    An element display rule for an image-rendered string (called the stream):
        if the text-string of the stream is "" and the cursor of the stream is not 0:
            #if utilizing Glimmr debugging;
            say "[>console][CBD]Rendered image string [i][stream][/i] specifies no text and has not been rendered. To display only a cursor, now the cursor property of the image-rendered string is 0.[<]";
            #end if;
            exit;
        [let foreground-color be the tint of the stream;
        let background-color be the background tint of the stream;]
        let len be the length of the stream real times the calculated scaling factor of the stream as an integer;
        if the stream is right-aligned:
            now the win-x of the stream is the win-x of the stream - len;
        if the stream is center-aligned:
            now the win-x of the stream is the win-x of the stream - (len / 2);
        [let row be the win-y of the stream;]
        let column be the win-x of the stream;
        let cursor-weight be the cursor-width of the associated font of the stream real times the calculated scaling factor as an integer;
        if cursor-weight < 1, now cursor-weight is 1;
        let margin be background-margin of the associated font of the stream real times the calculated scaling factor as an integer;
        let vertical-size be font-height of the associated font of the stream real times the calculated scaling factor as an integer;
        unless background tint of the stream is g-PlaceNullCol or the text-string of the stream is "":
            dimrectdraw (color background tint of the stream) in (current window) at (win-x of the stream - margin) by (win-y of the stream - margin) with size (len + margin + margin) by (vertical-size + margin + margin);
        if the cursor of the stream is 0:
            dimrectdraw (color tint of the stream) in (current window) at (column) by (win-y of the stream) with size cursor-weight by vertical-size;
        if the text-string of the stream is "":
            #if utilizing Glimmr debugging;
            say "[>console][CBD]Rendered image-based string [i][stream][/i] specifies no text. Displaying cursor at position 0.[<]";
            #end if;
            exit;
        repeat with N running from 1 to the number of characters in the text-string of the stream:
            let V be the character code of position N of the text-string of the stream;
            if there is a char of V in the font table of the associated font of the stream:
                choose row with a char of V in the font table of the associated font of the stream;
            otherwise:
                choose row with a char of 32 in the font table of the associated font of the stream;
            let the chosen glyph be glyph-ref entry;
            let the yoffset be yoffset entry real times the calculated scaling factor of the stream as an integer;
            let xx be the image-width of chosen glyph;
            let yy be the image-height of chosen glyph;
            now xx is xx real times the calculated scaling factor of the stream as an integer;
            now yy is yy real times the calculated scaling factor of the stream as an integer;
            drscimage (chosen glyph) in (current window) at (column) by (win-y of the stream + yoffset) with dimensions (xx) by (yy);
            if the cursor of the stream is N:
                dimrectdraw (color tint of the stream) in (current window) at (column + xx) by (win-y of the stream) with size cursor-weight by vertical-size;
            [if the text-animation delay of the stream is greater than 0 and glulx timekeeping is supported:
                follow the text-painting animation rules for the stream;]
            increase column by the advance entry real times the calculated scaling factor of the stream as an integer;
        #if utilizing Glimmr debugging;
        say "[>console][CBD]Displaying rendered image string [i][stream][/i], foreground color [color tint of the stream], in [i][current window][/i] with upper left ([win-x of stream], [win-y]) and lower right ([column + margin], [win-y of the stream + vertical-size + margin])[unless background tint of the stream is g-PlaceNullCol]; background color [color background tint of the stream][end if][if stream is graphlinked]. [line break][CBD]Graphlink corresponding to [i][stream][/i] set from ([win-x of stream], [win-y of stream]) to ([column + margin], [win-y of the stream + vertical-size + margin]): [quotation mark][linked replacement-command of stream][quotation mark][end if].[<]";
        #end if;
        if the stream is graphlinked:
            set a graphlink in the current window identified as the stream from (win-x - margin) by (win-y - margin) to (column + margin) by (win-y of the stream + vertical-size + margin) as the linked replacement-command of the stream.