Info bar to add to your apps (2 versions)
Posted: Wed Mar 11, 2015 12:05 pm
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
Version #2 - Transparent version - save over graphic displays
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$&" "&m$
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
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$&" "&m$
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