Graphical Window Sprites

version 1 by Erik Temple

  • Home page
  • Beginning
  • Previous
  • Next



  • Part 3 - Drawing Rules

    The sprite-background drawing rules are a rulebook.

    A sprite-background drawing rule (this is the sprite-background scaled-centered display rule):
        unless glulx graphics is supported, rule fails;
        determine the scaling and offset factors;
        blank window to graphics background color;
        draw the background;
        draw active sprites.

    A sprite-background drawing rule (this is the sprite-background centered display rule):
        unless glulx graphics is supported, rule fails;
        determine the offset factor;
        blank window to graphics background color;
        draw the background;
        draw active sprites.
        
    To draw the/-- background:
        (- DrawBackground(); -)
        
    To draw the/-- sprite (ID - a figure-name) at coordinates (off_x - a number) and (off_y - a number) with dimensions (image_x - a number) and (image_y - a number):
        (- DrawSprite({ID}, {off_x}, {off_y}, {image_x}, {image_y}); -)


    Include (-

    [ FindImageWidth img result img_width;
        result = glk_image_get_info(img, gg_arguments, gg_arguments+WORDSIZE);
    img_width = gg_arguments-->0;
        return img_width;
    ];

    [ FindImageHeight img result img_height;
        result = glk_image_get_info(img, gg_arguments, gg_arguments+WORDSIZE);
    img_height = gg_arguments-->1;
        return img_height;
    ];

    [ DrawBackground cur_pic;
        if (FollowRulebook( (+glulx picture selection rules+) ) ) { cur_pic = (+ internally selected picture +); }
        if (cur_pic == 0) rtrue;
        if (+ grid-background +) rtrue;
        if (gg_picwin) {
        
            glk_image_draw_scaled(gg_picwin, cur_pic, (+ window x-offset +), (+ window y-offset +), (+ background-width +), (+ background-height +));
        }
    ];

    [DrawSprite ID off_x off_y image_x image_y ;
        if (gg_picwin) {
            glk_image_draw_scaled(gg_picwin, ID, off_x, off_y, image_x, image_y);
        }
    ];

    -)