Computer Science Canada

GUI, GUI GUI GOOOEEY!

Author:  Spartan_117 [ Wed Aug 10, 2005 9:55 am ]
Post subject:  GUI, GUI GUI GOOOEEY!

Im using a gooey (GUI) for my program (S_Engine if anyone wants to know) and the program scans an image basically. The problem is that the scanning part is in a loop. So when i Press "SCAN" it enter the loop and the GUI (CANCEL Button inparticular) becomes inactive. So i cant cancel the operation! Is there any way around this? or will i have to live with it?

Also, is it possible to remove the title bar? The bar that has the exit (X button) the maximize and minimize buttons. Is it possible to get rid of that bar?

Author:  MysticVegeta [ Wed Aug 10, 2005 10:01 am ]
Post subject: 

mind posting the code?

Author:  Spartan_117 [ Wed Aug 10, 2005 10:04 am ]
Post subject: 

Heres the Code:


code:
import GUI in "%oot/lib/GUI"
%import GUI in "%oot/S_Engine/GUI"
var scnBx := 1;
var xPix, yPix : int;
var scanX, scanY := 0;
var mainImage : string;
var imageNum := 1;
var sandImage : string;
var waterImage : string;
var maxNumImg : int;
var rwName := "rwImg";
var col : int;
var streamNum : int;
var picID : int;


var mainPic : int;
var canX, canY : int

var scanWin : int;
var alert : int;
var screen := Window.Open ("graphics:800,600;onscreenonly");
View.Set ("nobuttonbar");
GUI.SetBackgroundColour (29);

var font := Font.New ("courier:12")

%var quitButton : int := GUI.CreateButton (maxx - 45, maxy - 30, 0, "X", GUI.Quit)

var text : int; %text area where RGB and XY (co-ords) info is shown)
var textH, textW : int;
textW := 110;
textH := 85;

var x, y, button := 0;
var R, G, B : real;
var loRSand, loGSand, loBSand := 266;
var hiRSand, hiGSand, hiBSand := -1;
var loRWater, loGWater, loBWater := 266;
var hiRWater, hiGWater, hiBWater := -1;
var hiWaterCol, hiSandCol := -2;
var loWaterCol, loSandCol := 266;
var waterCols : array 1 .. 500000 of int
var sandCols : array 1 .. 50000 of int
var sandLength, waterLength : int;
var Red, Green, Blue : string;

var mainCanvas := 0; % main canvas where the picture will be drawn.
var mainCanW, mainCanH : int; %main canvases width and height
mainCanW := 4 * maxx div 5;
mainCanH := 4 * maxy div 5;

var sandLABEL : int % Labels
var waterLABEL : int; % Labels
var sandRGBCanvas : int % displays RGB range for Sand
var waterRGBCanvas : int % displays RGB range for Water

var converterLabel : int; %label for the converter pane
var cmLabel, pixLabel : int; %labels for each txtfield
var cmTxt, pixTxt : int; % cm and pixel txtFields

var mainMenu : int;
var quitButton : int;
var openButton : int;

var scan : int;
var cancel : int;
var redComp, greenComp, blueComp : int;

var countWhite := 0;



function checkSand (x, y : int) : boolean
    % var R, G, B : real;
    % RGB.GetColour (whatdotcolour (x, y), R, G, B);
    var returnVal := false;
    var col := whatdotcolour (x, y);

    % if ceil (R * 255) <= hiRSand and ceil (R * 255) >= loRSand and
    %         ceil (G * 255) <= hiGSand and ceil (G * 255) >= loGSand and
    %         ceil (B * 255) <= hiBSand and ceil (B * 255) >= loBSand then
    for i : 1 .. sandLength
        if col = sandCols (i) then
            returnVal := true
            exit
        end if
    end for
    result returnVal
end checkSand



function checkWater (x, y : int) : boolean
    % var R, G, B : real;
    % RGB.GetColour (whatdotcolour (x, y), R, G, B);
    var returnVal := false;
    var col := whatdotcolour (x, y);

    % if ceil (R * 255) <= hiRWater and ceil (G * 255) <= hiGWater
    %         and ceil (B * 255) <= hiBWater and ceil (R * 255) >= loRWater
    %         and ceil (G * 255) >= loGWater and ceil (B * 255) >= loBWater then
    for i : 1 .. waterLength
        if col = waterCols (i) then
            returnVal := true
            exit
        end if
    end for
    result returnVal
end checkWater

procedure DoNothing (mx, my : int)
end DoNothing

proc TextDoNothing (text : string)
end TextDoNothing

procedure cmEntered (text : string)
    GUI.SetSelection (cmTxt, 0, 0)
    GUI.SetActive (pixTxt)
    GUI.SetSelection (pixTxt, 1, 1)
end cmEntered


procedure pixEntered (text : string)
    GUI.SetSelection (pixTxt, 0, 0)
    GUI.SetActive (cmTxt)
    GUI.SetSelection (cmTxt, 1, 1)
end pixEntered


proc silent
end silent

proc Close
    Window.Close (Window.GetActive);
    Window.SetActive (screen);
end Close

function amountSand (x, y, dir : int) : int
    var sands := 0;
    for i : 1 .. 10
        if whatdotcolour (x, y + (dir * i)) = black then
            sands += 1;
        end if
    end for
    result sands
end amountSand

function amountWater (x, y, dir : int) : int
    var waters := 0;
    for i : 1 .. 10
        if whatdotcolour (x, y + (dir * i)) = blue then
            waters += 1;
        end if
    end for
    result waters
end amountWater



function amountOfSand (x, y, dir : int) : real
    scanX := x - scnBx;
    scanY := y;
    var amtSand := 0.0;
    loop
        if checkSand (scanX, scanY) then
            amtSand += 1;
        end if
        scanX += 1;
        if scanX > x + scnBx then
            scanX := x - scnBx;
            scanY := scanY + dir;
        end if
        if scanY > y + dir * (2 * scnBx) then
            exit
        end if
    end loop
    result amtSand
end amountOfSand

function amountOfWater (x, y, dir : int) : real
    scanX := x - scnBx;
    scanY := y;
    var amtWater := 0.0;
    loop
        if checkWater (scanX, scanY) then
            amtWater += 1;
        end if
        scanX += 1;
        if scanX > x + scnBx then
            scanX := x - scnBx;
            scanY := scanY + dir;
        end if
        if scanY > y + dir * (2 * scnBx) then
            exit
        end if
    end loop
    result amtWater
end amountOfWater


proc processImage
    if mainCanvas not= 0 then
        canX := ((maxx - 120) div 2) - (Pic.Width (mainPic) div 2) + scnBx
        canY := (maxy div 2) - (Pic.Height (mainPic) div 2)
        xPix := canX
        yPix := canY

        loop
            if amountOfWater (xPix, yPix, 1) >= (scnBx * scnBx * 4) / 2 then
                GUI.DrawFillBox (mainCanvas, xPix - canX - scnBx, yPix - canY,
                    xPix - canX + scnBx, yPix - canY + 2 * scnBx, blue);
            end if

            if amountOfSand (xPix, yPix, 1) >= (scnBx * scnBx * 4) / 2 then
                GUI.DrawFillBox (mainCanvas, xPix - canX - scnBx, yPix - canY,
                    xPix - canX + scnBx, yPix - canY + 2 * scnBx, black);
            end if

            xPix += 2 * scnBx;
            if xPix >= ((maxx - 120) div 2) - (Pic.Width (mainPic) div 2)
                    + GUI.GetWidth (mainCanvas) then
                xPix := canX;
                yPix += 2 * scnBx;
            end if

            if yPix > (maxy div 2) - (Pic.Height (mainPic) div 2)
                    + GUI.GetHeight (mainCanvas) then
                exit
            end if
        end loop

        xPix := canX - scnBx;
        yPix := canY;
        loop
            if amountSand (xPix, yPix, -1) >= 9 then
                if amountWater (xPix, yPix, 1) >= 9 then
                    Draw.Dot (xPix, yPix, white);
                end if
            end if

            if amountWater (xPix, yPix, -1) >= 9 then
                if amountWater (xPix, yPix, 1) = 0 then
                    Draw.Dot (xPix, yPix, yellow);
                end if
            end if


            xPix += 1;
            if xPix >= ((maxx - 120) div 2) - (Pic.Width (mainPic) div 2)
                    + GUI.GetWidth (mainCanvas) then
                xPix := canX - scnBx;
                yPix += 1;
            end if


            if yPix > (maxy div 2) - (Pic.Height (mainPic) div 2)
                    + GUI.GetHeight (mainCanvas) then
                exit
            end if
        end loop
    end if
end processImage



proc getFile
    var col : int
    var count := 1;
    var continue := true;
    scanX := 0;
    scanY := 0;

    loRSand := 1000;
    loGSand := 1000;
    loBSand := 1000;
    hiRSand := -213;
    hiGSand := -213;
    hiBSand := -213;

    loRWater := 1000;
    loGWater := 1000;
    loBWater := 1000;
    hiRWater := -213;
    hiGWater := -213;
    hiBWater := -213;

    scanWin := Window.Open ("graphics:400,100;onscreenonly");
    put "Enter Sample Image of Sand: (include extension[jpg or bmp only]):";
    % cancel := GUI.CreateButton (5, 5, 0, "Cancel",
    %     Close)
    get sandImage : *;
    picID := Pic.FileNew (sandImage);
    Window.Close (scanWin);
    % SCAN SAND ***************************************************************
    scanWin := Window.Open ("graphics:" + intstr (Pic.Width (picID)) + ","
        + intstr (Pic.Height (picID)) + ";onscreenonly");

    Pic.Draw (picID, 0, 0, picCopy);

    loop
        %RGB.GetColour (whatdotcolour (scanX, scanY), R, G, B)
        col := whatdotcolour (scanX, scanY);
        sandCols (count) := col;

        if count > 1 then
            for k : 1 .. count - 1
                if sandCols (count) = sandCols (k) then
                    continue := false
                end if
            end for
        end if
        if continue then
            count += 1;
        end if
        continue := true;

        scanX += 1;
        if scanX > maxx then
            scanX := 0;
            scanY += 1;
        end if
        if scanY > maxy then
            exit
        end if
    end loop
    continue := true;
    sandLength := count;
    scanX := 0;
    scanY := 0;
    Pic.Free (picID);
    % SCAN WATER **************************************************************
    Window.Close (scanWin);
    scanWin := Window.Open ("graphics:400,100;onscreenonly");
    put "Enter sample image of Water (include extension): ";
    get waterImage : *;
    var picID2 := Pic.FileNew (waterImage);
    put Pic.Height (picID2);
    Window.Close (scanWin);

    scanWin := Window.Open ("graphics:" + intstr (Pic.Width (picID2)) +
        "," + intstr (Pic.Height (picID2)) + ";onscreenonly");

    Pic.Draw (picID2, 0, 0, picCopy);
    count := 1;

    loop
        RGB.GetColour (whatdotcolour (scanX, scanY), R, G, B)
        col := whatdotcolour (scanX, scanY);
        waterCols (count) := col;


        if count > 1 then
            for k : 1 .. count - 1
                if waterCols (count) = waterCols (k) then
                    continue := false
                end if
            end for
        end if
        if continue then
            count += 1;
        end if
        continue := true;

        scanX += 1;
        if scanX > maxx         /*Pic.Width (picID2)*/ then
            scanX := 0;
            scanY += 1;
        end if
        if scanY > maxy         /*Pic.Height (picID2)*/ then
            exit
        end if
    end loop
    Window.Close (scanWin);
    scanWin := Window.Open ("graphics:400,100;onscreenonly");
    put "Enter main Image (include extension): ";
    get mainImage : *;
    mainPic := Pic.FileNew (mainImage);
    waterLength := count;
    Window.Close (scanWin);

    Window.SetActive (screen);

    mainCanvas := GUI.CreateCanvasFull (((maxx - 120) div 2) - (Pic.Width (mainPic) div 2),
        (maxy div 2) - (Pic.Height (mainPic) div 2), Pic.Width (mainPic), Pic.Height (mainPic),
        GUI.INDENT, DoNothing, DoNothing, DoNothing);


    GUI.PicScreenLoad (mainCanvas, mainImage, 0, 0, picCopy);

end getFile

% % SAND ************************************************************************
% sandLABEL := GUI.CreateLabelFull (maxx - 85, maxy - 230, "SAND", 0, 0,
%     GUI.LEFT, 0);         % LABEL FOR SAND
% sandRGBCanvas := GUI.CreateCanvasFull (maxx - 120, maxy - 300, textW, textH - 20, GUI.LINE,
%     DoNothing, DoNothing, DoNothing);         % SHOWS THE RGB VALUES OF SAND
%
% var sandWaterDiv := GUI.CreateLabelFull (maxx - 120, maxy - 320,
%     "___________________", 0, 0, GUI.LEFT, 0);         %divides space between water/sand
%
% % WATER ***********************************************************************
% waterLABEL := GUI.CreateLabelFull (maxx - 85, maxy - 340, "WATER", 0, 0,
%     GUI.LEFT, 0);         % LABEL FOR WATER
% waterRGBCanvas := GUI.CreateCanvasFull (maxx - 120, maxy - 410, textW, textH - 20, GUI.LINE,
%     DoNothing, DoNothing, DoNothing);         % SHOWS THE RGB VALUES FOR WATER

mainMenu := GUI.CreateMenu ("File");         % MAIN MENU..
openButton := GUI.CreateMenuItem ("Import Image", getFile);         % IMPORTS IMAGES
var divider := GUI.CreateMenuItem ("---", silent);         % DIVIDES
quitButton := GUI.CreateMenuItem ("Exit", GUI.Quit);         % EXIT PROGRAM

text := GUI.CreateCanvasFull (maxx - 120, maxy - 200, textW, textH, GUI.INDENT,
    DoNothing, DoNothing, DoNothing);         %text canvas with CurrX, CurrY, R, G, B

scan := GUI.CreateButton (maxx - 120, 25, maxx div 12, "SCAN", processImage);

converterLabel := GUI.CreateLabelFull (maxx - 105, maxy - 280, "CONVERSION", 0, 0,
    GUI.LEFT, 0);
var seperator := GUI.CreateLabelFull (maxx - 120, maxy - 285,
    "___________________", 0, 0, GUI.LEFT, 0);
cmLabel := GUI.CreateLabelFull (maxx - 110, maxy - 305, "CM", 0, 0,
    GUI.LEFT, 0);
pixLabel := GUI.CreateLabelFull (maxx - 45, maxy - 305, "Pixels", 0, 0,
    GUI.LEFT, 0);
cmTxt := GUI.CreateTextFieldFull (maxx - 120, maxy - 325, 45, "",
    cmEntered, GUI.INDENT, 0, 0)
pixTxt := GUI.CreateTextFieldFull (maxx - 55, maxy - 325, 45, "",
    pixEntered, GUI.INDENT, 0, 0)

%GUI.PicScreenLoad (mainCanvas, mainImage + intstr (imageNum) + ".bmp", 0, 0, picCopy);
%var picID := Pic.New (25, 25, 320 + 25, 240 + 25);
%var newPicID := Pic.Scale (picID, mainCanW, mainCanH);
%Pic.Draw (newPicID, 25, 25, picCopy);

loop
    Mouse.Where (x, y, button);
    RGB.GetColour (whatdotcolour (x, y), R, G, B);

    Red := realstr (R * 255, 3);
    Green := realstr (G * 255, 3);
    Blue := realstr (B * 255, 3);
    %if (button not= 0) then
    GUI.DrawFillBox (text, 0, 0, textW,
        textH, white);
    GUI.DrawText (text, "CurrX: " + intstr (x),
        5, textH - 15, font, black)
    GUI.DrawText (text, "CurrY: " + intstr (y),
        5, textH - 35, font, black)
    GUI.DrawText (text, "Col: " + intstr (whatdotcolour (x, y)),
        5, textH - 55, font, black)
    %end if

    exit when GUI.ProcessEvent
    View.Update ();
end loop
Window.Close (Window.GetActive);


THe Process Image Procedure is that loop i was talking about, Once this starts all Buttons become inactive and no way to cancel the process.

Author:  Spartan_117 [ Wed Aug 10, 2005 10:06 am ]
Post subject: 

Heres the Code for that loop:

code:
proc processImage
    if mainCanvas not= 0 then
        canX := ((maxx - 120) div 2) - (Pic.Width (mainPic) div 2) + scnBx
        canY := (maxy div 2) - (Pic.Height (mainPic) div 2)
        xPix := canX
        yPix := canY

        loop
            if amountOfWater (xPix, yPix, 1) >= (scnBx * scnBx * 4) / 2 then
                GUI.DrawFillBox (mainCanvas, xPix - canX - scnBx, yPix - canY,
                    xPix - canX + scnBx, yPix - canY + 2 * scnBx, blue);
            end if

            if amountOfSand (xPix, yPix, 1) >= (scnBx * scnBx * 4) / 2 then
                GUI.DrawFillBox (mainCanvas, xPix - canX - scnBx, yPix - canY,
                    xPix - canX + scnBx, yPix - canY + 2 * scnBx, black);
            end if

            xPix += 2 * scnBx;
            if xPix >= ((maxx - 120) div 2) - (Pic.Width (mainPic) div 2)
                    + GUI.GetWidth (mainCanvas) then
                xPix := canX;
                yPix += 2 * scnBx;
            end if

            if yPix > (maxy div 2) - (Pic.Height (mainPic) div 2)
                    + GUI.GetHeight (mainCanvas) then
                exit
            end if
        end loop

        xPix := canX - scnBx;
        yPix := canY;
        loop
            if amountSand (xPix, yPix, -1) >= 9 then
                if amountWater (xPix, yPix, 1) >= 9 then
                    Draw.Dot (xPix, yPix, white);
                end if
            end if

            if amountWater (xPix, yPix, -1) >= 9 then
                if amountWater (xPix, yPix, 1) = 0 then
                    Draw.Dot (xPix, yPix, yellow);
                end if
            end if


            xPix += 1;
            if xPix >= ((maxx - 120) div 2) - (Pic.Width (mainPic) div 2)
                    + GUI.GetWidth (mainCanvas) then
                xPix := canX - scnBx;
                yPix += 1;
            end if


            if yPix > (maxy div 2) - (Pic.Height (mainPic) div 2)
                    + GUI.GetHeight (mainCanvas) then
                exit
            end if
        end loop
    end if
end processImage

Once this procedure starts all Buttons become inactive and no way to cancel the process.

All the code is too long to post. Heres the file:

Author:  MysticVegeta [ Thu Aug 11, 2005 2:06 pm ]
Post subject: 

Sorry to bother you again but can you put the image in the same folder and zip it up, thanks,


: