Page 1 of 2

Info bar to add to your apps (2 versions)

Posted: Wed Mar 11, 2015 12:05 pm
by Dav
This code is something you can add to your programs. It will show a top bar of info, like a clock in the middle and a picture battery level at top right. The example is set to draw it every minute, but you can change that. Just call the drawinfobar gosub routine to show it.

There are Two versions now - the second one uses transparent buttons so it can display over graphics. The original ones uses a black bar at top display.

- Dav

Version #1 - Black bar at top of screen

Code: Select all

'infobar shows device, clock, battery
'by Dav

graphics
graphics clear .5,0,0

sw=screen_width()
sh=screen_height()

gosub drawinfobar


do

'update infobar every minute
if time()>60 then
  gosub drawinfobar
  time reset
end if

'check for screen resize
if sw<>screen_width() then
  sw=screen_width()
  sh=screen_height()
  gosub drawinfobar
end if

until 0

end



drawinfobar:
fill color 0,0,0
fill rect 0,0 to sw,35
draw color 1,1,1
sv$=" "&system_version()
draw text device_type$()&sv$ at 10,7
ampm$="AM" ! hr=current_hour()
min$=str$(current_minute())
if len(min$)=1 then min$="0"&min$
if hr>11 then ampm$="PM"
if hr>12 then hr=hr-12
if hr=0 then hr=12
tm$=str$(hr)&":"&min$&" "&ampm$
draw text tm$ at ((sw/2)-text_width(tm$)/2),6
bat$=str$(battery_level())&"%"
draw text bat$ at sw-text_width(bat$)-80,7
draw rect sw-70,10 to sw-20,24
f=battery_level()/2
fill color 1,1,1
fill rect sw-70,10 to sw-70+f,24
fill rect sw-20, 14 to sw-17, 19

return
Version #2 - Transparent version - save over graphic displays

Code: Select all


'infobar-trans, shows device, clock, battery
'transparent button version, no black bar.
'safe for over graphic screens 
'by Dav

graphics

sw=screen_width()
sh=screen_height()

draw alpha .4
'draw something pretty.
for y=0 to screen_height() step 4
   draw color rnd(255)/255,rnd(255)/255,rnd(255)/255
   draw line 0,y to screen_width(),y
next y
draw alpha 1

gosub drawinfobar


do

'update infobar every minute
if time()>60 then
  gosub drawinfobar
  time reset
end if
'check for screen resize
if sw<>screen_width() then
  sw=screen_width()
  sh=screen_height()
  gosub drawinfobar
end if

until 0

end


'==========
drawinfobar:
'==========
set buttons custom
fill alpha 0
draw color 1,1,1
'=== show device info
sv$=device_type$()&" "&system_version()
button "dev" text sv$ at 10,7
'===show time
bat$=str$(battery_level())&"%"
button "bat" text bat$ at sw-text_width(bat$)-90,1
ampm$="AM" ! hr=current_hour()
min$=str$(current_minute())
if len(min$)=1 then min$="0"&min$
if hr>11 then ampm$="PM"
if hr>12 then hr=hr-12
if hr=0 then hr=12
tm$=str$(hr)&":"&min$&" "&ampm$
tx=((sw/2)-text_width(tm$)/2)
button "time" text tm$ at tx,1
'=== draw battery graphic
fill alpha 1
fill color 0,0,0
fill rect sw-70,10 to sw-20,24
draw rect sw-70,10 to sw-20,24
f=battery_level()/2
fill color 1,1,1
fill rect sw-70,10 to sw-70+f,24
fill rect sw-20, 14 to sw-17, 19
return

Re: Info bar to add to your apps

Posted: Wed Mar 11, 2015 12:30 pm
by Mr. Kibernetik
Great!
If this toolbar will include Pause and Stop buttons (probably optional), then it could completely replace main toolbar...

When rotating screen it does not resize, so probably it should contain screen size function inside.

Re: Info bar to add to your apps

Posted: Wed Mar 11, 2015 6:06 pm
by Dav
Thanks. I added a screen check/resize in the do/until. Should update when user turns device.

- Dav

Re: Info bar to add to your apps

Posted: Wed Mar 11, 2015 6:11 pm
by Mr. Kibernetik
Dav wrote:- Dav
I just checked your QBasic compiler on your website. It is a great work :!:

Re: Info bar to add to your apps

Posted: Wed Mar 11, 2015 7:00 pm
by Dav
Thank you very much! It was fun to make and a learning experience. It is really just an interpreter made in QB, and the compiled programs it makes are interpreters with code attached to it. When run, the compiled programs open the basic code attached, and executes that code. The code itself is encrypted so it can remain private. I didn't continue the project because I had reached the memory limit of QB.

Thanks for checking out my website! I'm working on an update to it, planning to add smart basic programs to it, changing the name to simply my Basic programming site, instead of only Qbasic. I think many QB programers should know about smart basic!

- Dav

Re: Info bar to add to your apps

Posted: Wed Mar 11, 2015 7:40 pm
by Mr. Kibernetik
Dav wrote:Thank you very much! It was fun to make and a learning experience. It is really just an interpreter made in QB, and the compiled programs it makes are interpreters with code attached to it. When run, the compiled programs open the basic code attached, and executes that code. The code itself is encrypted so it can remain private. I didn't continue the project because I had reached the memory limit of QB.

Thanks for checking out my website! I'm working on an update to it, planning to add smart basic programs to it, changing the name to simply my Basic programming site, instead of only Qbasic. I think many QB programers should know about smart basic!

- Dav
This is very interesting! Thank you very much for explanation! 8-)

Re: Info bar to add to your apps

Posted: Thu Mar 19, 2015 3:35 am
by milby
Very cool. I had added a simple time to the top of one of my programs and decided to switch over to this code. I wanted a smaller font (to match Apple's bar) and turned the code into a library.

Code: Select all

'infobar library shows device, clock, battery
'  by Dav
'  converted to library by milby
'
'add {infobar-lib} to beginning of program
'  (assumes that the file is named infobar-lib.txt)
'put "infobar" call into the event loop

'initialize variables
infobar.sw = screen_width()
infobar.sh = screen_height()
infobar.min = current_minute()-1 'force a draw on the first call

def infobar
  if sw <> screen_width() or min <> current_minute() then
    sw = screen_width()
    sh = screen_height()
    min = current_minute()
  else
    'neither time nor orientation changed, skipping redraw
    return
  end if
  draw font size 12
  draw size 1
  fill color 0,0,0
  fill rect 0,0 to sw,22
  draw color 1,1,1
  sv$=" "&system_version()
  draw text device_type$()&sv$ at 10,5
  ampm$="AM" ! hr=current_hour()
  min$=str$(current_minute())
  if len(min$)=1 then min$="0"&min$
  if hr>12 then
    hr=hr-12 ! ampm$="PM"
  end if
  tm$=str$(hr)&":"&min$&" "&ampm$
  draw text tm$ at ((sw/2)-text_width(tm$)/2),5
  bat$=str$(battery_level())&"%"
  draw text bat$ at sw-text_width(bat$)-48,5
  draw rect sw-40,6 to sw-20,14
  f=20*battery_level()/100
  fill color 1,1,1
  fill rect sw-40,6 to sw-40+f,14
  fill rect sw-20,9 to sw-18, 12
end def 'infobar

Re: Info bar to add to your apps

Posted: Fri Mar 20, 2015 1:25 pm
by Dav
Nice, milby! You made it easier to use.

- Dav

Re: Info bar to add to your apps

Posted: Sat Jun 06, 2015 4:01 am
by rbytes
I haven't yet tried using your toolbar script in the library format. I liked very much what you had done with it. It seemed redundant to see two toolbars, so I added SET TOOLBAR OFF to the code to hide the standard toolbar. But then there was no stop button, so I shifted the battery gauge to the left a bit and added one where I think the user would expect it. I hope to use your toolbar in many of my future scripts. Thanks!

Code: Select all

'infobar shows device, clock, battery
'by Dav

GRAPHICS
GRAPHICS CLEAR .5,0,0
SET TOOLBAR OFF
sw=SCREEN_WIDTH()
sh=SCREEN_HEIGHT()
GOSUB drawinfobar

DO
IF BUTTON_PRESSED(n$) THEN    'New
END
ENDIF
'update infobar every minute
IF TIME()>60 THEN
  GOSUB drawinfobar
  TIME RESET
END IF

'check for screen resize
IF sw<>SCREEN_WIDTH() THEN
  sw=SCREEN_WIDTH()
  sh=SCREEN_HEIGHT()
  GOSUB drawinfobar
END IF

UNTIL 0

END

drawinfobar:
FILL COLOR 0,0,0
FILL RECT 0,0 TO sw,35
DRAW COLOR 1,1,1
sv$=" "&SYSTEM_VERSION()
DRAW TEXT DEVICE_TYPE$()&sv$ AT 10,7
ampm$="AM" ! hr=CURRENT_HOUR()
MIN$=STR$(CURRENT_MINUTE())
IF LEN(MIN$)=1 THEN MIN$="0"&MIN$
IF hr>12 THEN
  hr=hr-12 ! ampm$="PM"
END IF
tm$=STR$(hr)&":"&MIN$&" "&ampm$
DRAW TEXT tm$ AT ((sw/2)-TEXT_WIDTH(tm$)/2),6
bat$=STR$(BATTERY_LEVEL())&"%"
DRAW TEXT bat$ AT sw-80 - TEXT_WIDTH(bat$)-80,7
DRAW RECT sw-150,10 TO sw-100,24
f=BATTERY_LEVEL()/2
FILL COLOR 1,1,1
FILL RECT sw-150,10 TO sw-150+f,24
FILL RECT sw-100, 14 TO sw-97, 19
T$ = "X" ! n$ = "X"
BUTTON N$ TEXT T$ AT sw-50,8 SIZE 30,18   'New


RETURN
'Last edited by Dav ON Wed Mar 11, 2015 12:04 pm, edited 1 TIME in total.
'Visit My Basic programming website

Re: Info bar to add to your apps

Posted: Mon Jun 08, 2015 11:49 am
by Dav
Thanks, ricardobytes. Glad it is useful to others. I found your digital clock program useful - it looks nice.

- Dav