Post by tsh73 on Dec 15, 2019 21:16:56 GMT
If ordinary BUTTON is not enough but BMPBUTTON is too much (or you do not like how it behaves then clicked )
one could draw buttons oneself, in a graphicbox
More code to write, sure
but things could be done:
* colored buttons
* buttons aligned to center of screen (try resizing that window)
* buttons what change color on click (try clicking last button a few times)
one could draw buttons oneself, in a graphicbox
More code to write, sure
but things could be done:
* colored buttons
* buttons aligned to center of screen (try resizing that window)
* buttons what change color on click (try clicking last button a few times)
'drawn button in a graphic box
'tsh73, March 2016
nomainwin
WindowWidth = 550
WindowHeight = 410
UpperLeftX=1 'int((DisplayWidth-WindowWidth)/2)
UpperLeftY=1 'int((DisplayHeight-WindowHeight)/2)
'two normal buttons, une linked to upper left corner (normal?) second to upper right
button #main.button1, "Button1", [button1Click], UL, 10, 10, 100, 25
button #main.button2, "Button2", [button2Click], UR, 10+100/2, 10-2, 100, 25
'but we cannot make it stay center
'drawn buttons in a grraphicbox
'make grraphicboxes
btnWid1=100
btnHht1=25
graphicbox #main.grBtn1, 10, 45, btnWid1, btnHht1
graphicbox #main.grBtn2, (WindowWidth-btnWid1)/2, 45, btnWid1, btnHht1 'this one would stay center then form is resized
graphicbox #main.grBtn3, WindowWidth-btnWid1-10, 45, btnWid1, btnHht1
'bonus: colored buttons
btnWid2=60
btnHht2=35
graphicbox #main.grBtnRed, 10, 80, btnWid2, btnHht2
graphicbox #main.grBtnGreen, (WindowWidth-btnWid2)/2, 80, btnWid2, btnHht2
graphicbox #main.grBtnBlue, WindowWidth-btnWid2-10, 80, btnWid2, btnHht2
texteditor #main.log 10, 120, WindowWidth - 25, WindowHeight - 180
open "button which stays in the center - do resize by mouse" for window as #main
#main.log "!autoresize";
'make drawn buttons
call makeButton "#main.grBtn1", "grBtn1", btnWid1, btnHht1
#main.grBtn1 "when leftButtonDown showButtonDown" 'same for all drawn buttons
#main.grBtn1 "when leftButtonUp [grBtn1Click]"
call makeButton "#main.grBtn2", "grBtn2", btnWid1, btnHht1
#main.grBtn2 "when leftButtonDown showButtonDown" 'same for all drawn buttons
#main.grBtn2 "when leftButtonUp [grBtn2Click]"
call makeButton "#main.grBtn3", "grBtn3", btnWid1, btnHht1
#main.grBtn3 "when leftButtonDown showButtonDown" 'same for all drawn buttons
#main.grBtn3 "when leftButtonUp [grBtn3Click]"
call makeColorButton "#main.grBtnRed", "Red", btnWid2, btnHht2, "white", "255 128 128", "128 64 64"
#main.grBtnRed "when leftButtonDown showButtonDown" 'same for all drawn buttons
#main.grBtnRed "when leftButtonUp [grBtnRedClick]"
call makeColorButton "#main.grBtnGreen", "Green", btnWid2, btnHht2, "white", "128 255 128", "64 128 64"
#main.grBtnGreen "when leftButtonDown showButtonDown" 'same for all drawn buttons
#main.grBtnGreen "when leftButtonUp [grBtnGreenClick]"
call makeColorButton "#main.grBtnBlue", "Blue", btnWid2, btnHht2, "white", "128 128 255", "64 64 128"
#main.grBtnBlue "when leftButtonDown showButtonDown" 'same for all drawn buttons
#main.grBtnBlue "when leftButtonUp [grBtnBlueClick]"
print #main, "trapclose [quit.main]"
#main "resizehandler [resizeHandler]"
wait
[quit.main]
Close #main
END
[button1Click]
#main.log "Button1 clicked"
wait
[button2Click]
#main.log "Button2 clicked"
wait
[grBtn1Click]
call showButtonUp "#main.grBtn1"
#main.log "grBtn1 clicked"
wait
[grBtn2Click]
call showButtonUp "#main.grBtn2"
#main.log "grBtn2 clicked"
wait
[grBtn3Click]
call showButtonUp "#main.grBtn3"
#main.log "grBtn3 clicked"
wait
[grBtnRedClick]
call showButtonUp "#main.grBtnRed"
#main.log "Red button clicked"
wait
[grBtnGreenClick]
call showButtonUp "#main.grBtnGreen"
#main.log "Green button clicked"
wait
[grBtnBlueClick]
call showButtonUp "#main.grBtnBlue"
#main.log "Last button clicked"
' change color of the same #main.grBtnBlue
btnColr=(btnColr+1) mod 3
select case btnColr
case 1
call makeColorButton "#main.grBtnBlue", "Red", btnWid2, btnHht2, "white", "255 128 128", "128 64 64"
case 2
call makeColorButton "#main.grBtnBlue", "Green", btnWid2, btnHht2, "white", "128 255 128", "64 128 64"
case 0
call makeColorButton "#main.grBtnBlue", "Blue", btnWid2, btnHht2, "white", "128 128 255", "64 64 128"
end select
wait
[resizeHandler]
'changed are WindowWidth , WindowHeight
#main "refresh"
wait
sub makeButton handle$, ttl$, btnWid, btnHht
call makeColorButton handle$, ttl$, btnWid, btnHht, "white", "lightgray", "darkgray"
end sub
sub makeColorButton handle$, ttl$, btnWid, btnHht, light$, mid$, dark$
'make two named segments, <handle>Down and <handle>Up. Leave 'Up' one.
#handle$ "down; backcolor ";mid$
#handle$ "font ms_sans_serif 8"
'segment <handle>Down
#handle$ "fill ";mid$;"; size 2"
#handle$ "color ";dark$;"; size 2; place 0 0; box ";btnWid-2;" ";btnHht-2 '128
#handle$ "line 1 1 1 ";btnHht-2
#handle$ "color black; place ";(btnWid-len(ttl$)*5)/2;" ";btnHht/2+5+1 'X is by trial an error, +1 is "pressed"
#handle$ "\";ttl$
#handle$ "flush ";mid$(handle$,2);"Down"
'segment <handle>Up
#handle$ "fill ";mid$
#handle$ "color ";dark$;"; size 2; place 1 1; box ";btnWid-2;" ";btnHht-2 '128
#handle$ "color white; line 1 1 ";btnWid-2;" 1" '255
#handle$ "line 1 1 1 ";btnHht-2
#handle$ "color black; backcolor ";mid$;"; place ";(btnWid-len(ttl$)*5)/2;" ";btnHht/2+5 'X is by trial an error?
#handle$ "\";ttl$
#handle$ "flush ";mid$(handle$,2);"Up"
end sub
sub showButtonDown handle$, dummyX, dummyY
#handle$ "redraw ";mid$(handle$,2);"Down"
end sub
sub showButtonUp handle$', dummyX, dummyY
#handle$ "redraw ";mid$(handle$,2);"Up"
end sub