Glimmr Canvas Editor

version 1/100805 by Erik Temple

  • Home page
  • Beginning
  • Previous
  • Next



  • Part - Paging and drawing the library-window

    The current-page is a number that varies. The current-page is 1.

    A dynamic-sprite has a number called the page-number. The page-number is 1.

    Minimum library-size is a number that varies. Minimum library-size is 50.

    Library-margin is a number that varies. Library-margin is 24.

    Row-coord is a number that varies. Col-coord is a number that varies. [Made global only because of built-in limits on the number of temporary variables in a phrase]

    Page-count is a number that varies. Page-capacity is a number that varies. Paged-rows is a number that varies. Paged-columns is a number that varies.
    [Page-count is the number of "pages" in the library window. It is determined by iteration in the page and scale routine and should only be used after that routine has been called.

    Page-capacity represents the number of items per page and will be derived from multipying paged-rows by paged-columns; these would be local variables except that the page and scale routine otherwise maxes out the allowable number of local variables within a single phrase.]

    The library-paging rules are a rulebook.

    A library-paging rule when the page-count is greater than 1 (this is the right arrow display rule):
        if page-count minus current-page is greater than 0:
            now the display status of page-right_button is g-active;
        otherwise:
            now the display status of page-right_button is g-inactive;
        continue the action;

    A library-paging rule when the page-count is greater than 1 (this is the left arrow display rule):
        if current-page is greater than 1:
            now the display status of page-left_button is g-active;
        otherwise:
            now the display status of page-left_button is g-inactive;
        continue the action;
        
    A library-paging rule when the page-count is less than 2 (this is the no arrows display rule):
        now the display status of page-left_button is g-inactive;
        now the display status of page-right_button is g-inactive;

    Nudge-direction is a kind of value. The nudge-directions are upward, leftward, rightward, and downward.
        
    Library-paging is an action applying to one value. Understand "page [nudge-direction]" as library-paging.

    Carry out library-paging:
        if the nudge-direction understood is:
            -- rightward: increase current-page by 1;
            -- leftward: decrease current-page by 1;
        follow the window-drawing rules for the library-window;
        follow the window-drawing rules for the paging-window;
        rule succeeds;

    To page and scale the/-- library-window sprites:
        if the library-window is g-present:
            now the canvas-width of the library-canvas is the width of the library-window;
            now the canvas-height of the library-canvas is the height of the library-window;
            let starting-row be library-margin;
            change paged-columns to (canvas-width of the library-canvas minus library-margin) / (minimum library-size + library-margin);
            change paged-rows to (canvas-height of the library-canvas minus starting-row) / (minimum library-size + library-margin);
            [say "Paged columns: [paged-columns]; paged rows: [paged-rows][line break]";]
            let standard-width be (canvas-width of the library-canvas minus library-margin) / paged-columns as a fixed point number;
            let standard-height be (canvas-height of the library-canvas minus starting-row) / paged-rows as a fixed point number;
            [say "[grid-x of the library-window]:[grid-x of the library-window minus library-margin]:[standard-width][line break]";
            say "[grid-y of the library-window]:[grid-y of the library-window minus starting-row]:[standard-height][line break]";]
            change standard-width to standard-width real minus library-margin;
            change standard-height to standard-height real minus library-margin;
            [say "The standard width is: [standard-width]; the standard height is [standard-height][line break]";]
            change page-capacity to paged-rows times paged-columns;
            let running-count be 1;
            change page-count to 1;
            let row-scan be 1;
            let column-scan be 1;
            change row-coord to library-margin;
            change col-coord to library-margin;
            repeat with current-element running through display-active dynamic-sprites:
                [say "Row # [row-scan]; Column # [column-scan][line break]Row: [row-coord]; Column: [col-coord][line break]";]
                if the associated canvas of current-element is the library-canvas:
                    let temp be the image-width of the image-ID of current-element;
                    change the sprite-x of the current-element to temp;
                    let temp be the image-height of the image-ID of current-element;
                    change the sprite-y of the current-element to temp;
                    let elem-x be the sprite-x of current-element as a fixed point number;
                    let elem-y be the sprite-y of current-element as a fixed point number;
                    if the standard-width real divided by elem-x is real greater than the standard-height real divided by elem-y:
                        change the x-scaling factor of current-element to the standard-height real divided by elem-y;
                        change the y-scaling factor of current-element to the standard-height real divided by elem-y;
                    otherwise:
                        change the x-scaling factor of current-element to the standard-width real divided by elem-x;
                        change the y-scaling factor of current-element to the standard-width real divided by elem-x;
                    if the x-scaling factor of current-element is greater than 1.0000, change the x-scaling factor of current-element to 1.0000;
                    if the y-scaling factor of current-element is greater than 1.0000, change the y-scaling factor of current-element to 1.0000;
                    change entry 1 of the origin of current-element to col-coord;
                    change entry 2 of the origin of current-element to row-coord;
                    [say "([origin of current-element]).";]
                    change the page-number of current-element to page-count;
                    increase running-count by 1;
                    increase column-scan by 1;
                    if column-scan is not greater than paged-columns:
                        increase col-coord by standard-width as an integer plus library-margin;
                    otherwise:
                        change column-scan to 1;
                        change col-coord to library-margin;
                        increase row-scan by 1;
                        increase row-coord by standard-height as an integer plus library-margin;
                    if running-count > page-capacity:
                        increase page-count by 1;
                        now row-scan is 1;
                        now column-scan is 1;
                        now row-coord is library-margin;
                        now col-coord is library-margin;
                        now running-count is 1;
                    [say "[element-name of current-element]: [sprite-x of current-element], [sprite-y of current-element] ([sprite-scaling factor of current-element])[line break]";]
                
    To draw the/-- library instances of/in (win - a g-window):
        [say "number of pages = [page-count]";]
        prune the link-table of win links;
        repeat with current-element running through display-active dynamic-sprites assigned to win:
            if current-element is assigned to win:
                [say "[element-name of current-element]: ";]
                if the page-number of the current-element is the current-page:
                    [Delete: let cur-image be image-ID of current-element;]
                    let elem-x be entry 1 of the origin of the current-element;
                    let elem-y be entry 2 of the origin of the current-element;
                    [say "([elem-x], [elem-y]).";]
                    let x-sprite be the sprite-x of current-element as a fixed point number;
                    let y-sprite be the sprite-y of the current-element as a fixed point number;
                    let dim-x be x-sprite real times the x-scaling factor of the current-element as an integer;
                    let dim-y be y-sprite real times the y-scaling factor of the current-element as an integer;
                    [say "drawing [element-name of current-element]: [dim-x], [dim-y] ([scaling factor of the current-element])[line break]";]
                    display sprite current-element in win at coordinates elem-x and elem-y with dimensions dim-x and dim-y;
                    if current-element is graphlinked:
                        set a graphlink in win identified as current-element from elem-x by elem-y to (elem-x + dim-x) by (elem-y + dim-y) as the linked replacement-command of current-element;
                        [say "Graphlinked as: [elem-x],[elem-y] - [elem-x + dim-x],[elem-y + dim-y][line break]";]