gfxgfxFreeBASIC Games Directory Forumgfxgfx
gfx gfx
gfx
Welcome, Guest. Please login or register. May 21, 2013, 12:27:07 PM

Login with username, password and session length
11.5.2013 - Added a webpage for the latest FBGD competition.

13.3.2013 - Members registrations temporary disabled. For all membership requests, please email me: lachie13@yahoo.com

30.11.2012 - The ninth issue of BASIC Gaming is out! Read it here: http://games.freebasic.net/forum/index.php?topic=560.0

22.11.2012 - Be sure to check our currently running annual FBGD game making competition. This year's theme is SEASONS OF THE YEAR, 300 $ first place prize, and the competition runs till 18th of February. Link: http://games.freebasic.net/forum/index.php?topic=559.0
gfx
gfx
*
gfxgfx
gfxgfx gfxgfx
gfxgfx Home Help Search Login Register   gfxgfx
gfx gfx
gfx
Pages: [1] 2 3 4
Print
Author Topic: new help with makeing a button for the mouse  (Read 8285 times)
the_laughing_man
Recruit
**
Posts: 46


View Profile Email
« on: May 22, 2008, 05:08:36 PM »

this is one thing i would like to know how to make a button for my shell i am working on .
in freebasic
Logged
hexdude!
Global Moderator
Novice
*****
Gender: Male
Posts: 66


283467208 Malatestas_Ghost@hotmail.co.uk hhexadecimaldude jabrazavi
View Profile Email
« Reply #1 on: May 22, 2008, 05:26:29 PM »

A button is normally a rectangular area. If you already know how to use GETMOUSE, then you use that to find the x and y co-ordinates of the mouse, and which buttons are down. If the user is clicking the left button, then check to see if the mouse is inside the button (This is done by seeing if mouse_x > button_left and mouse_x < button_right, and mouse_y > button_top and mouse_y < button_bottom). If all these things are true, then the user clicked the button.

If you don't know how to use GETMOUSE, then a quick guide for our purposes is:

GETMOUSE mouse_x,mouse_y,,mouse_buttons

Now mouse_x and mouse_y will contain the x and y co-ordinates of the mouse, and mouse_buttons will tell us which buttons are down. To find out if the left button is down, do an:

IF mouse_buttons AND 1 THEN

Anything after the THEN will only be executed if the left button was down.

For a more complete discussion of GETMOUSE, you could look at the wiki page, which is at http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgGetmouse
« Last Edit: May 22, 2008, 05:31:11 PM by hexdude! » Logged
the_laughing_man
Recruit
**
Posts: 46


View Profile Email
« Reply #2 on: May 22, 2008, 05:48:12 PM »

like if i want a button at the the right side of my sreen how would I do this ?
Logged
the_laughing_man
Recruit
**
Posts: 46


View Profile Email
« Reply #3 on: May 22, 2008, 05:49:32 PM »

i see ok but how do i make a bmp file in to a button on the screen ? i know how to call the mouse 
Logged
phycowelder
Novice
***
Posts: 72


View Profile Email
« Reply #4 on: May 22, 2008, 06:25:26 PM »

get(0,0)-(99,99),@button_pic(0)        'sets button 100x100 to memory
put (100,100), @button_pic(0), pset  'puts button at location 100,100
get mouse x,y,s,b
if b=1 then
  if x>100 and x<199 and y>100 and y<199 then   'checks to see if you are in the button zone
    {button code}
  end if
end if

for looks though you will have to make a shading mask or another button picture for the animation
so it looks like a button being pushed!
Logged
the_laughing_man
Recruit
**
Posts: 46


View Profile Email
« Reply #5 on: May 22, 2008, 06:51:50 PM »

let me show you what i got now
if you click it will quit
now i want to make a box if i click it will quit the program.

-----------------------------------------
#include "fbgfx.bi"
Dim x As Integer, y As Integer, buttons As Integer
                       

Do
    ' get mouse x, y and button state
    GetMouse x, y , , buttons                     

    If buttons = 1 Then
        ' on left mouse click, center mouse
        SetMouse 400, 300end
 
 
  End If

    ' do loop until esc is pressed
Loop Until MultiKey(fb.SC_ESCAPE)
Logged
BadMrBox
Forum Sage
*****
Gender: Male
Posts: 371



View Profile WWW
« Reply #6 on: May 22, 2008, 06:58:56 PM »

Remove that END after SetMouse.
Logged

the_laughing_man
Recruit
**
Posts: 46


View Profile Email
« Reply #7 on: May 22, 2008, 08:38:55 PM »

ok and what dose that do if i do ?
Logged
the_laughing_man
Recruit
**
Posts: 46


View Profile Email
« Reply #8 on: May 22, 2008, 09:02:59 PM »

but how do you make a button ?
like do i make a pic bmp like a box and put it in a say if 300x300
then if i click there it will quit ?
Logged
the_laughing_man
Recruit
**
Posts: 46


View Profile Email
« Reply #9 on: May 22, 2008, 09:03:30 PM »

ok guys
i have a good lay out all i need like a bit of help
Logged
BadMrBox
Forum Sage
*****
Gender: Male
Posts: 371



View Profile WWW
« Reply #10 on: May 22, 2008, 11:13:14 PM »

Okey, I wrote this up for you.
It should be fairly easy to follow. Just create a bmp of your choice, put it in the same directory as your basfile and change buttonsizex/buttonsizey to the image size.
'FB 0.18b
screenres 640,480,32,2

dim button as any ptr
dim as integer mousex,mousey,mousebuttons,buttonposx,buttonposy, imgwidth, imgheight
dim as integer buttonsizex,buttonsizey,exittheloop

    Const True = 1
    const false = not true
       
        buttonsizex = 100
        buttonsizey = 30
        buttonposx = 50
        buttonposy = 50

button = imagecreate(buttonsizex,buttonsizey)
bload "button.bmp",button

screenset 1,0

do
    cls
   
    locate 1,1:? "Press the button"
    put (buttonposx,buttonposy),button
    GetMouse mousex, mousey , , mousebuttons 


    if mousebuttons=1 then
        if mousex>buttonposx and mousex<buttonposx+buttonsizex then
            if mousey>buttonposy and mousey<buttonposy+buttonsizey then
            exittheloop = True
            endif
        endif
    endif
   
    screencopy
   
loop until exittheloop = True
Logged

the_laughing_man
Recruit
**
Posts: 46


View Profile Email
« Reply #11 on: May 22, 2008, 11:23:57 PM »

 Cheesy thx dude that was a big help Smiley
you need any thing let me know the_laughing_man@live.ca
Logged
BadMrBox
Forum Sage
*****
Gender: Male
Posts: 371



View Profile WWW
« Reply #12 on: May 22, 2008, 11:56:18 PM »

Good to hear Smiley
Logged

Leonheart
Guest
« Reply #13 on: May 23, 2008, 12:22:30 AM »

Nice BadMrBox. <Yah, Im late>

I sometimes peek to themes resource files, their pack some button bitmap for corner-upper-left/right, corner-downside-left/right, and for around skin. And, their pack it skin into four state (if not going wrong); focus, no focus, disabled, pushed. Keep that state to variable to show their condition, maybe that's can be help.
And, you can keep bitmap part into variable too when load (so you don't have to include bitmap files everytime).

Maybe that's from me. Have a nice button! Cheesy
Logged
the_laughing_man
Recruit
**
Posts: 46


View Profile Email
« Reply #14 on: May 23, 2008, 09:24:46 AM »

now you guys are going to kick me but this is that last thing i need help with now how
do i make 2 buttons ...?
Logged
Pages: [1] 2 3 4
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
Cerberus design by Bloc
Valid XHTML 1.0! Valid CSS!
gfx
gfxgfx gfxgfx