TJ
New Member
Posts: 7
|
Post by TJ on Dec 18, 2019 21:23:57 GMT -5
Instead of using a back ground color , can a picture bmp be used My sample program looks like this and has a gray back ground,I am trying to replace it with a picture
UpperLeftX = 125 UpperLeftY = 140 WindowWidth = 500 WindowHeight = 320
nomainwin BackgroundColor$ = "darkblue" ForegroundColor$ = "Brown" TextboxColor$ = "Red"
button #main.Stop, "Stop", [Stop], UL, 94, 76, 72, 50 button #main.Backward, "Back", [Backward], UL, 94, 141, 72, 50 button #main.Forward, "Forward", [Forward], UL, 94, 6, 72, 50 button #main.Left, "Left", [Left], UL, 6, 76, 72, 50 button #main.Right, "Right", [Right], UL, 182, 76, 72, 50 button #main.Up, "Up", [Up], UL, 334, 6, 96, 25 button #main.Down, "Down", [Down], UL, 334, 101, 96, 25 button #main.Launch, "Launch", [Launch], UL, 334, 55, 96, 25 button #main.Menu, "Exit", [Exit], UL, 350, 215, 62, 30 ' L/R U/D W H textbox #main.selectedField1, 14, 216, 32, 25 textbox #main.selectedField2, 54, 216, 32, 25 textbox #main.selectedField3, 94, 216, 32, 25 textbox #main.selectedField4, 134, 216, 32, 25 textbox #main.selectedField5, 174, 216, 32, 25 textbox #main.selectedField6, 214, 216, 32, 25 textbox #main.selectedField7, 254, 216, 32, 25 textbox #main.selectedField8, 294, 216, 32, 25
open "Remote Screen 1" for graphics as #main print #main, "fill lightgray; flush" 'playwave"Sound Files/star.wav"
[main.inputLoop] 'wait here for input event input aVar$ goto [main.inputLoop]
[Stop] print #1.selectedField1,"On" 'R1 / On '<---------------------------------- R1 & R2 & R3 / Off Stop Button pin=2 'pin relay is attached to #ard "set "+str$(pin)+" 1" '- print #1.selectedField2,"On" 'R1 / On '<---------------------------------- R1 & R2 & R3 / Off Stop Button pin=3 'pin relay is attached to #ard "set "+str$(pin)+" 1" '- print #1.selectedField3,"On" 'R1 / On '<---------------------------------- R1 & R2 & R3 / Off Stop Button pin=4 'pin relay is attached to #ard "set "+str$(pin)+" 1"
print #1.selectedField1," " 'R1 / Clear Field
print #1.selectedField2," " 'R2 / Clear Field
print #1.selectedField3," " 'R3 / Clear Field
gosub [allstop] goto [main.inputLoop]
[allstop] 'Perform action for the button named 'Stop'
playwave"Sound Files/type.wav"
print #main.selectedField1,"" print #main.selectedField2,"" print #main.selectedField3,"" print #main.selectedField4,"" print #main.selectedField5,"" print #main.selectedField6,"" print #main.selectedField7,"" print #main.selectedField8,""
return
[Backward] 'Perform action for the button named 'Backward'
playwave"Sound Files/laser.wav" gosub [allstop]
print #1.selectedField1,"On" 'R1 / On '<---------------------------------- R1 & R2 & R3 / ON BackWard Button pin=2 'pin relay is attached to #ard "set "+str$(pin)+" 0" '- print #1.selectedField2,"On" 'R1 / On '<---------------------------------- R1 & R2 & R3 / ON BackWard Button pin=3 'pin relay is attached to #ard "set "+str$(pin)+" 0" '- print #1.selectedField3,"On" 'R1 / On '<---------------------------------- R1 & R2 & R3 / ON BackWard Button pin=4 'pin relay is attached to #ard "set "+str$(pin)+" 0" print #main.selectedField3,"R3" print #main.selectedField2,"R2" print #main.selectedField1,"R1"
goto [main.inputLoop]
[Forward] 'Perform action for the button named 'Forward'
playwave"Sound Files/laser.wav" gosub [allstop] print #main.selectedField3,"R3" goto [main.inputLoop]
[Left]'Perform action for the button named 'Left'
playwave"laser.wav" gosub [allstop] print #main.selectedField4,"R4"
goto [main.inputLoop]
[Right]'Perform action for the button named 'Right'
playwave"Sound Files/laser.wav" gosub [allstop] print #main.selectedField5,"R5"
goto [main.inputLoop]
[Up] 'Perform action for the button named 'Up'
playwave"Sound Files/laser.wav" gosub [allstop] print #main.selectedField6,"R6"
goto [main.inputLoop]
[Down] 'Perform action for the button named 'Down'
playwave"Sound Files/laser.wav" gosub [allstop] print #main.selectedField7,"R7"
goto [main.inputLoop]
[Launch] 'Perform action for the button named 'Launch'
playwave"Sound Files/toy-15.wav" gosub [allstop] print #main.selectedField8,"R8"
goto [main.inputLoop] [Exit] Close #main
EDITED by tsh73 - inserted CODEDE tags. And re-inserted Left Right in square brackets.
|
|
|
Post by sarossell on Dec 18, 2019 22:55:46 GMT -5
It's pretty easy really. Just before you open your graphics window, insert the loadbmp command. Then, right after the open command line, add the drawbmp command. Be sure to comment out your original fill command line. I would also suggest you add a trapclose so your program closes cleanly if the user clicks on the X instead of the Exit button. loadbmp "image", "C:\Programming\pic.bmp" open "Remote Screen 1" for graphics as #main print #main, "drawbmp image 10 10" 'print #main, "fill lightgray; flush" #main, "trapclose [Exit]" Lastly, add the unloadbmp command when you exit. [Exit] Close #main unloadbmp("image") 'wait end And adding an End command wouldn't hurt.
In the future, be sure to use the code block to display your source code. Your "Left" and "Right" button branch labels caused the text to left and right justify the code.
Crazy stuff, huh? :@)
|
|
|
Post by Rod on Dec 19, 2019 3:19:23 GMT -5
I would tweak it just a little to #main “down ; drawbmp image 0 0 ; flush”
|
|
|
Post by sarossell on Dec 19, 2019 3:33:43 GMT -5
Ah, right. Good point. Otherwise the picture won't "stick". Good catch, Rod!
|
|
|
Post by tsh73 on Dec 20, 2019 3:21:25 GMT -5
There is a thing that prevents graphic window from having scrollbars and resizable border
open "Remote Screen 1" for graphics_nsb_nf as #main
Also, if you do some magic (use sprite engine) you can automatically scale picture UP (not down, sorry)
'before open loadbmp "image", "C:\some\path\to\picture.bmp" 'open open "Remote Screen 1" for graphics_nsb_nf as #main 'after open #main "down" #main "home; posxy cx cy" 'gets center of window to calc size of client area #main "background image" #main "drawsprites" 'draws image as a background, scaling up if needed #main "getbmp KeepIt 0 0 "; cx*2;" ";cy*2 #main "drawbmp KeepIt 0 0; flush";
|
|
|
Post by sarossell on Dec 20, 2019 10:11:27 GMT -5
tsh73: Pretty slick. I've never used sprites before. And I completely forgot about the _nsb_nf option. TJ: You will have to remove the other image line I suggested earlier though... print #main, "drawbmp image 10 10" ...or the image will overlap. Fun stuff!
|
|
|
Post by sarossell on Dec 20, 2019 13:56:50 GMT -5
I've got a question: Is it possible to create a graphics window without a title bar? If not, can this same interface be built in a window that can?
|
|
|
Post by Rod on Dec 20, 2019 14:27:44 GMT -5
You can use a pop up window which gives you the entire screen. But you have to handle all of the user input. There is no X so you have to give the user a way out. The window can also be a floating transparent gadget, like a floating round clock for instance. We don’t need to live by Windows design rules.
|
|
|
Post by Rod on Dec 20, 2019 14:45:01 GMT -5
For popup look at meteor.bas that ships with Liberty for transparent look at this. All things are possible. Alyce and Janet are quite a hot combination, they taught me nearly everything I know about Liberty BASIC... well ok everything.
nomainwin WindowWidth = 120 WindowHeight = 144
'set window stylebits to layered and stay on top WS.EX.LAYERED = 524288 style=WS.EX.LAYERED or _WS_EX_TOPMOST stylebits #1, 0, 0, style, 0
'set graphicbox stylebits to no border stylebits #1.gb, 0, _WS_BORDER, 0, 0 graphicbox #1.gb, 0,0,120,144
'open popup window open "Clock" for window_popup as #1
'get the window handle hMain = HWND(#1)
'set the window to use red as transparent mask calldll #user32, "SetLayeredWindowAttributes",_ hMain As long,_ 'window handle 255 As long,_ '255 = Red color key (rgb color value) bAlpha As long,_ '0 = Completely transparent (0-255) 1 As long,_ '1 = use color key for transparency / 2 = use bAlpha ret As long 'nonzero=success if ret=0 then [quit]
'move window with api call calldll #user32, "MoveWindow",_ hMain as ulong, _ 'window handle 100 as long,_ 'x location of window 200 as long,_ 'y location of window 120 as long,_ 'desired width of window 144 as long,_ 'desired height of window 1 as boolean,_ 'repaint flag,0=false,1=true ret as long 'nonzero=success if ret=0 then [quit]
' start event tracking #1 "trapclose [quit]" #1.gb "when leftButtonUp [quit]" #1.gb, "when leftButtonMove [movewindow]"
'draw clock face print #1.gb, "down ; fill red ; home ; backcolor darkgray ; circlefilled 48 ;color white ; circle 49" for angle = 0 to 330 step 30 print #1.gb, "up ; home ; north ; turn "; angle print #1.gb, "go 40 ; down ; go 5" next angle print #1.gb, "flush"
timer 1000, [display] wait
[display] ' call this only when seconds has changed time$ = time$() hours = val(time$) if hours > 12 then hours = hours - 12 minutes = val(mid$(time$, 4, 2)) seconds = val(right$(time$, 2))
' delete the last drawn segment, if there is one if segId > 2 then print #1.gb, "delsegment "; segId - 1
' center the turtle print #1.gb, "up ; home ; down ; north"
' erase each hand if its position has changed if oldHours <> hours then print #1.gb, "size 2 ; color darkgray ; turn "; oldHours * 30 + int(oldMinutes/2) ; " ; go 19 ; home ; color black ; north" : oldHours = hours if oldMinutes <> minutes then print #1.gb, "size 2 ; color darkgray ; turn "; oldMinutes * 6 ; " ; go 38 ; home ; color black ; north" : oldMinutes = minutes if oldSeconds <> seconds then print #1.gb, "size 1 ; color darkgray ; turn "; oldSeconds * 6 ; " ; go 38 ; home ; color black ; north" : oldSeconds = seconds
' redraw all three hands, second hand first print #1.gb, "size 1 ; turn "; seconds * 6 ; " ; go 38" print #1.gb, "size 2 ; home ; north ; turn "; hours * 30 + int(minutes/2); " ; go 19" print #1.gb, "home ; north ; turn "; minutes * 6 ; " ; go 38"
' flush to end segment, then get the next segment id # print #1.gb, "flush" print #1.gb, "segment" input #1.gb, segId wait
[movewindow] CallDLL #user32, "ReleaseCapture",r As void CallDLL #user32, "SendMessageA",hMain As ULong,_WM_NCLBUTTONDOWN As ULong,_HTCAPTION As Long,0 As Long,r As Long wait
[quit] timer 0 close #1 end
|
|
|
Post by Rod on Dec 20, 2019 14:46:54 GMT -5
There are bugs in this clock code, holidays challenge!
|
|
|
Post by sarossell on Dec 21, 2019 0:59:17 GMT -5
Over my head! I'ma have to stare at this for a bit. };@\
|
|
mark
New Member
Posts: 24
|
Post by mark on Jun 12, 2020 3:47:35 GMT -5
I would tweak it just a little to #main “down ; drawbmp image 0 0 ; flush” I was playing around with this code and can't seem to get it to work. I think this tweak would solve the problem but I keep getting an error. Where do I place it or does it replace another line?
|
|
|
Post by Rod on Jun 12, 2020 7:18:55 GMT -5
Can you see the foot of the ide? The error will be explained there. Tell us what the error is and showcus the line of code that is highlighted when it stops.
|
|
mark
New Member
Posts: 24
|
Post by mark on Jun 12, 2020 8:38:54 GMT -5
UpperLeftX = 125 UpperLeftY = 140 WindowWidth = 500 WindowHeight = 320
nomainwin BackgroundColor$ = "darkblue" ForegroundColor$ = "Brown" TextboxColor$ = "Red"
button #main.Stop, "Stop", [Stop], UL, 94, 76, 72, 50 button #main.Backward, "Back", [Backward], UL, 94, 141, 72, 50 button #main.Forward, "Forward", [Forward], UL, 94, 6, 72, 50 button #main.Left, "Left", [Left], UL, 6, 76, 72, 50 button #main.Right, "Right", [Right], UL, 182, 76, 72, 50 button #main.Up, "Up", [Up], UL, 334, 6, 96, 25 button #main.Down, "Down", [Down], UL, 334, 101, 96, 25 button #main.Launch, "Launch", [Launch], UL, 334, 55, 96, 25 button #main.Menu, "Exit", [Exit], UL, 350, 215, 62, 30 ' L/R U/D W H textbox #main.selectedField1, 14, 216, 32, 25 textbox #main.selectedField2, 54, 216, 32, 25 textbox #main.selectedField3, 94, 216, 32, 25 textbox #main.selectedField4, 134, 216, 32, 25 textbox #main.selectedField5, 174, 216, 32, 25 textbox #main.selectedField6, 214, 216, 32, 25 textbox #main.selectedField7, 254, 216, 32, 25 textbox #main.selectedField8, 294, 216, 32, 25
loadbmp "image", "pics\pic.bmp" open "Remote Screen 1" for graphics as #main print #main, "drawbmp image 10 10" 'print #main, "fill lightgray; flush" #main, "trapclose [Exit]"
open "Remote Screen 1" for graphics as #main print #main, "fill lightgray; flush" 'playwave"Sound Files/star.wav"
[main.inputLoop] 'wait here for input event input aVar$ goto [main.inputLoop]
[Stop] print #1.selectedField1,"On" 'R1 / On '<---------------------------------- R1 & R2 & R3 / Off Stop Button pin=2 'pin relay is attached to #ard "set "+str$(pin)+" 1" '- print #1.selectedField2,"On" 'R1 / On '<---------------------------------- R1 & R2 & R3 / Off Stop Button pin=3 'pin relay is attached to #ard "set "+str$(pin)+" 1" '- print #1.selectedField3,"On" 'R1 / On '<---------------------------------- R1 & R2 & R3 / Off Stop Button pin=4 'pin relay is attached to #ard "set "+str$(pin)+" 1"
print #1.selectedField1," " 'R1 / Clear Field
print #1.selectedField2," " 'R2 / Clear Field
print #1.selectedField3," " 'R3 / Clear Field
gosub [allstop] goto [main.inputLoop]
[allstop] 'Perform action for the button named 'Stop'
playwave"Sound Files/type.wav"
print #main.selectedField1,"" print #main.selectedField2,"" print #main.selectedField3,"" print #main.selectedField4,"" print #main.selectedField5,"" print #main.selectedField6,"" print #main.selectedField7,"" print #main.selectedField8,""
return
[Backward] 'Perform action for the button named 'Backward'
playwave"Sound Files/laser.wav" gosub [allstop]
print #1.selectedField1,"On" 'R1 / On '<---------------------------------- R1 & R2 & R3 / ON BackWard Button pin=2 'pin relay is attached to #ard "set "+str$(pin)+" 0" '- print #1.selectedField2,"On" 'R1 / On '<---------------------------------- R1 & R2 & R3 / ON BackWard Button pin=3 'pin relay is attached to #ard "set "+str$(pin)+" 0" '- print #1.selectedField3,"On" 'R1 / On '<---------------------------------- R1 & R2 & R3 / ON BackWard Button pin=4 'pin relay is attached to #ard "set "+str$(pin)+" 0" print #main.selectedField3,"R3" print #main.selectedField2,"R2" print #main.selectedField1,"R1"
goto [main.inputLoop]
[Forward] 'Perform action for the button named 'Forward'
playwave"Sound Files/laser.wav" gosub [allstop] print #main.selectedField3,"R3" goto [main.inputLoop]
[Left]'Perform action for the button named 'Left'
playwave"laser.wav" gosub [allstop] print #main.selectedField4,"R4"
goto [main.inputLoop]
[Right]'Perform action for the button named 'Right'
playwave"Sound Files/laser.wav" gosub [allstop] print #main.selectedField5,"R5"
goto [main.inputLoop]
[Up] 'Perform action for the button named 'Up'
playwave"Sound Files/laser.wav" gosub [allstop] print #main.selectedField6,"R6"
goto [main.inputLoop]
[Down] 'Perform action for the button named 'Down'
playwave"Sound Files/laser.wav" gosub [allstop] print #main.selectedField7,"R7"
goto [main.inputLoop]
[Launch] 'Perform action for the button named 'Launch'
playwave"Sound Files/toy-15.wav" gosub [allstop] print #main.selectedField8,"R8"
goto [main.inputLoop] [Exit] Close #main unloadbmp("image") 'wait end
Runtime Error: index: 320057 is outside of collection bounds (Se error log for more info)
I can't find the error log.
I tried reloading the code just in case I was doing something wrong before I replied and now I actually get a different error than I did the first time. I don't know what I'm doing wrong. It would be cool to have an example of a bmp in the background to learn from which is what I was trying to get.
The first error was a syntax error with (halted)
#main, “down ; drawbmp image 0 0 ; flush”
|
|
cundo
Full Member
Muchas Gracias!!
Posts: 146
|
Post by cundo on Jun 12, 2020 10:27:07 GMT -5
A bitmap error perhaps? wrong bit depth? Open the bmp file with paint and save it. Can't remember exactly which color depth is the best one tho. Make a backup of that file first.
|
|