Liberty BASIC Community Forum
« 'buttons' whit extra events try »

Welcome Guest. Please Login or Register.
Jan 23rd, 2018, 7:24pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: 'buttons' whit extra events try  (Read 159 times)
bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 936
xx 'buttons' whit extra events try
« Thread started on: Dec 18th, 2017, 04:49am »

i m trying to build buttons whit extra events
you can make a array of buttons this way

error :
button x clicked = blue

it shoot be :
when hovered button = blue
when cklicked button = red
else button = green

this can be useful :
these buttons can be moved while running code
Code:
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , muisx , muisy , leftbutton
winx = WindowWidth
winy = WindowHeight
dim r( 10 , 3 ) , r$( 10 )
nomainwin
open "rect event example" for graphics as #m
  #m "trapclose [quit]"
  #m "when mouseMove [move]"
  #m "when leftButtunDown [leftdown]"
  #m "when leftButtunUp [leftup]"
  for i = 0 to 10
    call r i , i*50 , 0 , i*50+40 , 50
  next i
  timer 100 , [timer]
wait
[quit]
  close #m
end
sub swap byref a , byref b
  h = a
  a = b
  b = h
end sub
sub r no , x1 , y1 , x2 , y2
  if x1 > x2 then call swap x1 , x2
  if y1 > y2 then call swap y1 , y2
  r(no,0)=x1
  r(no,1)=y1
  r(no,2)=x2
  r(no,3)=y2
end sub
function rno()
  no = -1
  for i = 0 to 10
    if muisx > r(i,0) and muisx < r(i,2) then
      if muisy > r(i,1) and muisy < r(i,3) then
        no = i
      end if
    end if
  next i
  rno = no
end function
[timer]
  scan
  #m "fill black"
  for i = 0 to 10
    r$( i ) = "green"
  next i
  hover = rno()
  if hover <> -1 then
    if leftbutton then
      r$( hover ) = "red"
    else
      r$( hover ) = "blue"
    end if
  end if
  for i = 0 to 10
    call show i
  next i
wait
sub show no
  #m "goto ";r(no,0);" ";r(no,1)
  #m "down"
  #m "color ";r$(no)
  #m "backcolor ";r$(no)
  #m "boxfilled ";r(no,2);" ";r(no,3)
  #m "up"
end sub
[move]
  muisx = MouseX
  muisy = MouseY
wait
[leftdown]
  leftbutton = 1
wait
[leftup]
  leftbutton = 0
wait


 
User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1732
xx Re: 'buttons' whit extra events try
« Reply #1 on: Dec 18th, 2017, 08:27am »

some typoos
Code:
'  #m "when leftButtunDown [leftdown]"  'wrong
  #m "when leftButtonDown [leftdown]"
'  #m "when leftButtunUp [leftup]" 'wrong
  #m "when leftButtonUp [leftup]" 
User IP Logged

damned Dog in the Manger
bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 936
xx Re: 'buttons' whit extra events try
« Reply #2 on: Dec 19th, 2017, 03:00am »

@ tsh73 :
thank for spotting that

update :
more events

i dont know [ jet ] when this might be useful

i got this idea while learning lazarus

Code:
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , muisx , muisy , leftbutton , rightbutton
winx = WindowWidth
winy = WindowHeight
dim r( 10 , 3 ) , r$( 10 )
nomainwin
open "rect event example" for graphics as #m
  #m "trapclose [quit]"
  #m "when mouseMove [move]"
  #m "when leftButtonDown [leftdown]"
  #m "when leftButtonUp [leftup]"
  #m "when rightButtonDown [rightdown]"
  #m "when rightButtonUp [rightup]"
  for i = 0 to 10
    call r i , i*50 , 0 , i*50+40 , 50
  next i
  timer 100 , [timer]
wait
[quit]
  close #m
end
sub swap byref a , byref b
  h = a
  a = b
  b = h
end sub
sub r no , x1 , y1 , x2 , y2
  if x1 > x2 then call swap x1 , x2
  if y1 > y2 then call swap y1 , y2
  r(no,0)=x1
  r(no,1)=y1
  r(no,2)=x2
  r(no,3)=y2
end sub
function rno()
  no = -1
  for i = 0 to 10
    if muisx > r(i,0) and muisx < r(i,2) then
      if muisy > r(i,1) and muisy < r(i,3) then
        no = i
      end if
    end if
  next i
  rno = no
end function
[timer]
  scan
  #m "fill black"
  for i = 0 to 10
    r$( i ) = "lightgray"
  next i
  hover = rno()
  if hover <> -1 then
    if rightbutton then
      if leftbutton then
        r$( hover ) = "red"
      else
        r$( hover ) = "blue"
      end if
    else
      if leftbutton then
        r$( hover ) = "green"
      else
        r$( hover ) = "yellow"
      end if
    end if
  end if
  for i = 0 to 10
    call show i
  next i
wait
sub show no
  #m "goto ";r(no,0);" ";r(no,1)
  #m "down"
  #m "color ";r$(no)
  #m "backcolor ";r$(no)
  #m "boxfilled ";r(no,2);" ";r(no,3)
  #m "up"
end sub
[move]
  muisx = MouseX
  muisy = MouseY
wait
[leftdown]
  leftbutton = 1
wait
[leftup]
  leftbutton = 0
wait
[rightdown]
  rightbutton = 1
wait
[rightup]
  rightbutton = 0
wait
 
« Last Edit: Dec 19th, 2017, 03:01am by bluatigro » User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
G. Rahman
Guru
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1147
xx Re: 'buttons' whit extra events try
« Reply #3 on: Dec 19th, 2017, 6:31pm »


and I moved the Code:
  #m "fill black" 

to the opening of the window.


Gordon
User IP Logged

Gordon Rahman

http://www.libertybasic.nl
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls