Computer Science Canada

buttons and clicks

Author:  air_force91 [ Sat Jan 10, 2004 1:27 pm ]
Post subject:  buttons and clicks

ive made buttons and stuff...but i don't know how to make a code for the user to click anywhere inside the buttons and be taken to specific pages...here's my code:

code:
setscreen ("graphics:800;350")

colourback (3)
cls


%2nd page

var size : int
var text1 : string
size := 15
var text := "The PAGE!!!"

var afontID : array 1 .. size of int

for i : size div 2 .. size
    afontID (i) := Font.New ("Tahoma:" + intstr (i))

end for


procedure Text3D (text : string)

    for t : 1 .. length (text)

        for i : size div 2 .. size
            Font.Draw (text (t), t * size, 315, afontID (i), 20 + floor
                (i / size * 10))

        end for
    end for

end Text3D

Text3D (text)

%%Import computer picture

var comppic : int := Pic.FileNew ("comp3.bmp")
Pic.Draw (comppic, 50 div 2, 20 div 2, 0)


%%%%%%%%%%%%%%%%%%%%%%buttons

%3rd button

Draw.FillBox (550, 40, 667, 90, 5)

var bfontID : int := Font.New ("Arial:12:bold")
Font.Draw ("Exit", 590, 60, bfontID, black)

%2nd button

Draw.FillBox (550, 140, 667, 190, 5)

var cfontID : int := Font.New ("Arial:12:bold")
Font.Draw ("Start", 562, 160, cfontID, black)

%1st button

Draw.FillBox (550, 240, 667, 290, 5)

var dfontID : int := Font.New ("Arial:12:bold")
Font.Draw ("Music", 562, 260, dfontID, black)

%%%mouse detect--*click*

var ch : string (1)
var x, y, btnnum, btnupdown : int
x := 562
y := 260
loop
    if hasch then
        getch (ch)


    end if
    if Mouse.ButtonMoved ("down") then
        Mouse.ButtonWait ("down", x, y, btnnum, btnupdown)
Text.Locate (21, 100)

        cls


    end if
end loop


if u have any suggestions so i can improve the look of my page or the buttons...pls tell me....thanx for ur help... Smile

Author:  santabruzer [ Sat Jan 10, 2004 1:37 pm ]
Post subject: 

use "mousewhere".. it'll return you where the mouse is.. and if the button is pressed.. so that
code:
var x, y, button : int
mousewhere (x, y, button)


Then you can make an if statement, that

code:
if button = 1 then
*code here*
end if


It's pretty straight forward.. but if you get confused, look in help! Smile

Author:  CITC [ Sat Jan 10, 2004 1:38 pm ]
Post subject: 

you need to use the Mouse.Where command and make if statements

code:

var x,y,btn : int
Mouse.Where (x,y,btn)
if x > ## and x < ## and y > ## and y < ## and btn = 1 then
%do whatever you want here
end if


or you can do the cheap way out and do:
code:

if whatdotcolour (x,y) = ## then

Author:  CITC [ Sat Jan 10, 2004 1:39 pm ]
Post subject: 

lol 1 minute before me Razz

Author:  santabruzer [ Sat Jan 10, 2004 1:39 pm ]
Post subject: 

ha ha.. the second time it happened to me.. and it doesn't matter which Mouse Where you use.. they are both identical...

Author:  air_force91 [ Sat Jan 10, 2004 1:41 pm ]
Post subject: 

do u know how to make a picture appear as the background of the execution window? coz my page seems too simple...

Author:  santabruzer [ Sat Jan 10, 2004 1:50 pm ]
Post subject: 

i would think
Quote:
picUnderMerge This draws the picture, but only where the background color was displayed underneath it. The effect of this is to make the picture appear to be displayed behind the background.

Author:  air_force91 [ Sun Jan 11, 2004 11:18 am ]
Post subject:  this is what ive donw

ive inserted ur code but it still doesn't work...

code:
setscreen ("graphics:800;350")

colourback (red)
cls

var fontID : int := Font.New ("Franklin Gothic Medium:16:bold")
Font.Draw ("Welcome To", 300, 300, fontID, blue)
Font.Draw ("...", 350, 270, fontID, yellow)
%3D effect for "The Ultimate MB!!"

var size : int
var text1 : string
size := 40
var text := "The Ultimate MB!!"

var afontID : array 1 .. size of int

for i : size div 2 .. size
    afontID (i) := Font.New ("Tahoma:" + intstr (i))

end for


procedure Text3D (text : string)

    for t : 1 .. length (text)

        for i : size div 2 .. size
            Font.Draw (text (t), t * size, 170, afontID (i), 20 + floor
                (i / size * 10))

        end for
    end for

end Text3D

Text3D (text)

%ball animation

%Import computer picture

var comppic : int := Pic.FileNew ("comp2.bmp")
Pic.Draw (comppic, 20 div 2, 20 div 2, picMerge)

%"enter any key"

var bfontID : int := Font.New ("Arial:10:bold")
Font.Draw ("Press any key to continue...", 597, 25, bfontID, blue)

loop
    exit when hasch
end loop
cls


can u tell me y the click's not working? i can't figure it out...thanx.

Author:  santabruzer [ Sun Jan 11, 2004 11:23 am ]
Post subject: 

here.. try this:
code:
setscreen ("graphics:800;350")

colourback (red)
cls

var fontID : int := Font.New ("Franklin Gothic Medium:16:bold")
Font.Draw ("Welcome To", 300, 300, fontID, blue)
Font.Draw ("...", 350, 270, fontID, yellow)
%3D effect for "The Ultimate MB!!"

var size : int
var text1 : string
size := 40
var text := "The Ultimate MB!!"

var afontID : array 1 .. size of int

for i : size div 2 .. size
    afontID (i) := Font.New ("Tahoma:" + intstr (i))

end for


procedure Text3D (text : string)

    for t : 1 .. length (text)

        for i : size div 2 .. size
            Font.Draw (text (t), t * size, 170, afontID (i), 20 + floor
                (i / size * 10))

        end for
    end for

end Text3D

%Import computer picture

var comppic : int := Pic.FileNew ("comp2.bmp")
Pic.Draw (comppic, 20 div 2, 20 div 2, picMerge)

Text3D (text)

%ball animation


%"enter any key"

var bfontID : int := Font.New ("Arial:10:bold")
Font.Draw ("Press any key to continue...", 597, 25, bfontID, blue)

loop
    exit when hasch
end loop
cls

Author:  air_force91 [ Sun Jan 11, 2004 12:16 pm ]
Post subject: 

oppsss sorry...im getting soo stressed out from all the exams and stuff...im sorry...i copied the wrong page of code...now this is the page where i inserted the mouseclick function...and it doesn't work....

code:
setscreen ("graphics:800;350")

colourback (3)
cls


%2nd page

var size : int
var text1 : string
size := 15
var text := "The Ultimate MB!!"

var afontID : array 1 .. size of int

for i : size div 2 .. size
    afontID (i) := Font.New ("Tahoma:" + intstr (i))

end for


procedure Text3D (text : string)

    for t : 1 .. length (text)

        for i : size div 2 .. size
            Font.Draw (text (t), t * size, 315, afontID (i), 20 + floor
                (i / size * 10))

        end for
    end for

end Text3D

Text3D (text)

%%Import computer picture

var comppic : int := Pic.FileNew ("comp3.bmp")
Pic.Draw (comppic, 50 div 2, 20 div 2, 0)


%%%%%%%%%%%%%%%%%%%%%%buttons

%3rd button

Draw.FillBox (550, 40, 667, 90, 5)

var bfontID : int := Font.New ("Arial:12:bold")
Font.Draw ("Exit", 590, 60, bfontID, black)

%2nd button

Draw.FillBox (550, 140, 667, 190, 5)

var cfontID : int := Font.New ("Arial:12:bold")
Font.Draw ("Start Game", 562, 160, cfontID, black)

%1st button

Draw.FillBox (550, 240, 667, 290, 5)

var dfontID : int := Font.New ("Arial:12:bold")
Font.Draw ("Instructions", 562, 260, dfontID, black)

%%%mouse detect--*click*
 
var x,y,btn : int
Mouse.Where (x,y,btn)

if x >= 550 and x <= 667 and y >= 240 and y <= 290 and btn = 1 then
cls
end if

Author:  air_force91 [ Sun Jan 11, 2004 12:18 pm ]
Post subject: 

and u know the "picUnderMerge"...well I can't view my pic when i use the command...i want my picture to be set as the background of the screen but using this...i can;t see the pic at all...

Author:  santabruzer [ Sun Jan 11, 2004 12:20 pm ]
Post subject: 

here.. post the pic.. and the Turing File..

Author:  air_force91 [ Sun Jan 11, 2004 12:32 pm ]
Post subject: 

[img]www.extendinc.com/ computer.jpg[/img]

that's the image i want as the background...and attached is the main page...thanx sooooo much...

Author:  santabruzer [ Sun Jan 11, 2004 2:59 pm ]
Post subject: 

Here it is (the pic is attached):
code:
setscreen ("graphics:800;350,nocursor")

colourback (red)
cls

var fontID : int := Font.New ("Franklin Gothic Medium:16:bold")
Font.Draw ("Welcome To", 300, 300, fontID, blue)
Font.Draw ("...", 350, 270, fontID, yellow)

%3D effect for "The Ultimate MB!!"

var size : int := 40
var text1 : string
var text := "The Ultimate MB!!"
var ch : string (1)

var afontID : array 1 .. size of int

for i : size div 2 .. size
    afontID (i) := Font.New ("Tahoma:" + intstr (i))
end for


procedure Text3D (text : string)
    for t : 1 .. length (text)
        for i : size div 2 .. size
            Font.Draw (text (t), t * size, 170, afontID (i), 20 + floor
                (i / size * 10))
        end for
    end for
end Text3D

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% You have to insert the picture before the text, so that                   %
%  the text will overlap the picture                                        %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%Import computer picture
var comppic : int := Pic.FileNew ("computerback.jpg")
Pic.Draw (comppic, maxx div 2 - (Pic.Width (comppic) div 2), maxy div 2 - Pic.Height (comppic) div 2, picMerge)

%ball animation
Text3D (text)


%"enter any key"
var bfontID : int := Font.New ("Arial:10:bold")
Font.Draw ("Press any key to continue...", 597, 25, bfontID, blue)
getch (ch)

Author:  CITC [ Sun Jan 11, 2004 6:12 pm ]
Post subject: 

just from looking quickly at the code (I didn't download the files either)

you have no loop around your mousewhere bit. Therefore there is only a split-second when if you click the mouse it'll do anything.

code:
%%%mouse detect--*click*
loop 
var x,y,btn : int
Mouse.Where (x,y,btn)

if x >= 550 and x <= 667 and y >= 240 and y <= 290 and btn = 1 then
cls
end if
end loop

Author:  santabruzer [ Sun Jan 11, 2004 7:09 pm ]
Post subject: 

just don't forget the getch command in that loop, or you'll wind with clicking the button, and the keyboard not responding..


: