Glimmr Drawing Commands

version 2/101030 by Erik Temple

  • Home page
  • Beginning
  • Previous
  • Next



  • Chapter - Text-painting with image-based fonts

    Section - Text-painting with a background color

    To paintimgtext of/-- (STR - indexed text) in (win - a g-window) at (X1 - a number) by/x (Y1 - a number) using font/-- (TYPF - a font) scaled at (SCF - a real number) with background (BKGD - a number) and margin of/-- (MARGIN - a number) pixel/pixels/px/--, center-aligned or right-aligned:
        unless STR is "":
            now g-LEN is the length of STR set in TYPF;
            now g-LEN is g-LEN real times SCF as an integer;
            if right-aligned:
                let X1 be X1 - g-LEN;
                let X1 be X1 - (g-LEN / 2);
            now current g-row is Y1;
            now current g-column is X1;
            [let vertical-size be font-height of TYPF real times SCF as an integer;]
            dimrectdraw (BKGD) in (WIN) at (current g-column - MARGIN) by (current g-row - MARGIN) with size (the length of STR set in TYPF real times SCF as an integer + MARGIN + MARGIN) by (font-height of TYPF real times SCF as an integer + MARGIN + MARGIN);
            repeat with N running from 1 to the number of characters in STR:
                now char_code is the character code of position N of STR;
                if there is a char of char_code in the font table of TYPF:
                    choose row with a char of char_code in the font table of TYPF;
                otherwise:
                    choose row with a char of 32 in the font table of TYPF;
                let the chosen glyph be glyph-ref entry;
                let the yoffset be yoffset entry real times SCF as an integer;
                now g-imgwidth is the image-width of chosen glyph;
                now g-imgheight is the image-height of chosen glyph;
                now g-imgwidth is g-imgwidth real times SCF as an integer;
                now g-imgheight is g-imgheight real times SCF as an integer;
                drscimage (chosen glyph) in (WIN) at (current g-column) by (current g-row + yoffset) with dimensions (g-imgwidth) by (g-imgheight);
                increase current g-column by the advance entry real times SCF as an integer;

    To paint/display an/-- image-based text of/-- (STR - indexed text) in (win - a g-window) at (X1 - a number) by/x (Y1 - a number) using font/-- (TYPF - a font) scaled at (SCF - a real number) with background (BKGD - a number) and margin of/-- (MARGIN - a number) pixel/pixels/px/--, center-aligned or right-aligned:
        #if utilizing Glimmr debugging;
        say "[>console][DC]Painting bitmap text string [quotation mark][STR][quotation mark] in [i][WIN][/i] with origin ([X1], [Y1])[if center-aligned], center-aligned[end if][if right-aligned], right-aligned[end if]. Font: [TYPF], scaled at [SCF], with background [BKGD] and margin of [MARGIN].[<]";
        #end if;
        if center-aligned:
            paintimgtext of (STR) in (WIN) at (X1) by (Y1) using (TYPF) scaled at (SCF) with background (BKGD) and margin (MARGIN), center-aligned;
        if right-aligned:
            paintimgtext of (STR) in (WIN) at (X1) by (Y1) using (TYPF) scaled at (SCF) with background (BKGD) and margin (MARGIN), right-aligned;
        paintimgtext of (STR) in (WIN) at (X1) by (Y1) using (TYPF) scaled at (SCF) with background (BKGD) and margin (MARGIN).

    To paint/display an/-- image-based text (hue - a number) of (str - indexed text) in (win - a g-window) at (coord1 - a list of numbers) using font/-- (typf - a font) scaled at (SCF - a real number) with background (BKGD - a number) and margin of/-- (MARGIN - a number) pixel/pixels/px/--, center-aligned or right-aligned:
        let x1 be entry 1 of coord1;
        let y1 be entry 2 of coord1;
        if center-aligned:
            paint image-based text of (STR) in (WIN) at (X1) by (Y1) using (TYPF) scaled at (SCF) with background (BKGD) and margin (MARGIN), center-aligned;
            rule succeeds;
        if right-aligned:
            paint image-based text of (STR) in (WIN) at (X1) by (Y1) using (TYPF) scaled at (SCF) with background (BKGD) and margin (MARGIN), right-aligned;
            rule succeeds;
        paint image-based text of (STR) in (WIN) at (X1) by (Y1) using (TYPF) scaled at (SCF) with background (BKGD) and margin (MARGIN).