MODULE clip;

FROM tigr IMPORT TigrPtr,tigrWindow,tigrFree,tigrClosed, tigrClear, tigrUpdate, TPixelType,
                tigrLine, TK_ESCAPE, tigrKeyDown, tigrReadChar, tfont, tigrPrint,tigrFill,
                tigrCircle, tigrRect, tigrFillCircle,  tigrTime, tigrError, tigrClip, 
                tigrFillRect, tigrTextWidth, tigrTextHeight;
FROM helper IMPORT tigrRGB, tigrRGBA;
FROM InOut IMPORT Write, WriteLn;
FROM RealInOut IMPORT WriteShortReal;

CONST 
    w = 100;
    d = 50;
    message = "Half a thought is also a thought";

VAR 
    cx, cy : CARDINAL;
    c0, c1, c2, c3 : TPixelType;
    screen :  TigrPtr;
    tw, th : CARDINAL;

BEGIN 
    screen := tigrWindow(320, 240, "Clip", 0);

    c0 := tigrRGB(55, 55, 55);
    c1 := tigrRGB(255, 255, 255);
    c2 := tigrRGB(100, 200, 100);
    c3 := tigrRGBA(100, 100, 200, 150);

    WHILE (NOT (tigrClosed(screen) > 0)) OR (tigrKeyDown(screen, TK_ESCAPE) > 0) DO 
        tigrClear(screen, c0);

        cx := screen^.w / 2;
        cy := screen^.h / 2;

        tigrClip(screen, cx - d, cy - d, w, w);
        tigrFill(screen, cx - d, cy - d, w, w, c1);

        tigrRect(screen, cx - w, cy - w, w, w, c2);
        tigrFillRect(screen, cx - w, cy - w, w, w, c3);

        tigrCircle(screen, cx + d, cy - d, d, c2);
        tigrFillCircle(screen, cx + d, cy - d, d, c3);

        tw := tigrTextWidth(tfont, message);
        th := tigrTextHeight(tfont, message);
        tigrPrint(screen, tfont, cx - tw / 2, cy + d - th / 2, c2, message);

        tigrUpdate(screen);
    END;
    tigrFree(screen);
END clip.