GigBook v1.2 - Calendar/Journal for 2016-2033 (iPad/iPhone)

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

GigBook v1.2 - Calendar/Journal for 2016-2033 (iPad/iPhone)

Post by Dav »

This is an updated GigBook Event calendar/journal program. It's good up to year 2033. You can write notes for events for each day. Just press the day you want to write about. There's also a memo pad and phone# page to keep that info. You can navigate through the years by top arrows, or jumping via the years/month buttons. All data is saved in the GigBook-data folder in dir in the current directory.

There is some help info in the code. If you need more help or have a suggestion please post it. I moved the text editing page to a function, which can be easily lifted and used in your programs with a little changing.

I adapted ricardobytes method to make the app work on all iOS devices. Thanks, ricardobytes!

- Dav

New for v1.2: Added option to make entry highlighted red to mark as important.

Code: Select all

'================
'GigBook.txt v1.2
'================
'An event calendar/journal
'Works on ipad/iphone/ipod touch
'ONLY GOOD FOR YEARS BETWEEN 2016-2033
'Coded by Dav, OCT/2016
'
'NEW for v1.2: Added red highlight entry.
'
'HOW TO USE:
'^^^^^^^^^^
'This app lets you save important dates.
'You can also save memos and phone numbers.
'Use arrows to navigate the month to view.
'Or use Year & Month buttons to jump there.
'Press a number to add events on that day.
'An editing window will open to allow input.
'Press Done when you have finished editing.
'Pressing Clear will erase/delete the entry.
'Highlighted days mean an event is scheduled.
'To mark to entry as important and have it
'displayed red in the monthly view, just put
'an exclamation mark at top left in entry.
'To erase highlight press Clear when editing.
'Data saved in the /gigbook-data/ directory.
'Entry filenames saved like: 2016-10-12.txt

'CREDITS: I used ricardobytes method to make  
'the app compatible with both ipad & iphone.


option base 1
set orientation vertical
get screen size sw,sh

'detect device for screen settings
if lowstr$(device_type$())="ipad" then 
   rw=1!rh=1!vmod=0
else
   rw=sw/768!rh=sh/1024!vmod=50
end if

'========= for testing purposes ============
'call iphone("4") '<<<< force test iphone 4
'call iphone("5") '<<<< force test iphone 5
'call iphone("6") '<<<< force test iphone 6
'call iphone("6+")'<<<< force test iphone 6+
'===========================================

'make gigbook directory if doesn't exist
if file_exists("gigbook-data/") = 0 then 
   dir "gigbook-data" create
end if


'===
top:
'===

graphics
graphics clear .9,.9,.9

set buttons custom
set buttons font size 42*rw

gosub GetData

draw color 0,0,.8
fill color .9,.9,1

draw font size 56*rw
centertext(month$&" - "&str$(SelYear),30)

draw font size 37*rw
draw text "Sun  Mon  Tue  Wed  Thu  Fri  Sat" at 10*rw,100*rh

'draw a month view
y=150*rh!yc=sw/7!dim day$(days)!events=0
for t = 1 to days
    day$(t)=dayname$(xp)
    draw color 0,0,.8

    'see if event saved for this day
    'if so, make button special color.
    entry$=str$(SelYear)&"-"&str$(SelMonth)&"-"&str$(t)&".txt"
    if file_exists("gigbook-data/"&entry$) =1 then
       events=events+1
       fill color .89,.89,1
       'see if its marked important...
       f$="gigbook-data/"&entry$
       file f$ setpos 0 ! file f$ read m
       'if so, make entry red filled.
       if m=asc("!") then fill color 1,.89,.89
    else
       fill color 1,1,1
    end if

    'use special color if days todays date
    if current_year()=SelYear then
      if SelMonth=current_month() then
        if t=current_date() then 
         draw color 1,1,1
         fill color 0,0,1
        end if
      end if
    end if

    'draw days in the month
    button str$(t) text t at yc*(xp-1),y size yc,yc
    xp=xp+1
    if xp=8 then
      xp=1!y=y+yc
    end if

next t

'draw nav buttons
set buttons font size 65*rw
button "<" text chr$(9664) at 25*rw,20*rh size 75*rw,75*rh
button ">" text chr$(9654) at sw-(91*rw),20*rh size 75*rw,75*rh
set buttons font size 42*rw

'draw info at bottom
draw font size 32*rw
'show todays date
centertext("Today is "&today$,900)
'see if today has and entry
te$=str$(SelYear)&"-"&str$(current_month())&"-"&str$(current_date())&".txt"
if file_exists("gigbook-data/"&te$) =1 then
  centertext("An event is scheduled today",936)
else
  centertext("No events scheduled today",936)
end if

'draw buttons at bottom
draw font size 37*rw
button "year" text "Year" at 40*rw,830*rh size 135*rw,56*rh
button "month" text "Month" at 200*rw,830*rh size 145*rw,56*rh
button "memo" text "Memo" at 375*rw,830*rh size 145*rw,56*rh
button "phone" text "Phone#" at 550*rw,830*rh size 175*rw,56*rh


'wait for user to make a move
do

  for d=1 to days
    if button_pressed(str$(d)) then 
       gosub erasebuttons
       a$=day$(d)&" "&month$&" "
       a$=a$&str$(d)&", "&str$(SelYear)
       b$=str$(SelYear)&"-"&str$(SelMonth)
       b$=b$&"-"&str$(d)&".txt"
       EditText(a$,"gigbook-data/"&b$)
       goto Top
    end if
  next d
  
  if button_pressed("<") then
    if SelMonth=1 and SelYear=2016 then
       'dont do anything. hit wall.
    else
       gosub erasebuttons
       'subtract month
       SelMonth = SelMonth - 1
       if SelMonth=0 then
          SelMonth=12!SelYear=SelYear-1
       end if
       goto Top
    end if
  end if

  if button_pressed(">") then
    if SelMonth=12 and SelYear=MaxYear then 
       'dont do anything. hit wall.
    else
       gosub erasebuttons
       SelMonth = SelMonth +1
       if SelMonth=13 then
          SelMonth=1!SelYear=SelYear+1
       end if
       goto Top
    end if
  end if

  if button_pressed("year") then
     gosub ShowYears !  goto top
  end if

  if button_pressed("month") then
     gosub ShowMonths !  goto top
  end if

  if button_pressed("memo") then
     gosub erasebuttons
     a$="Memo: Save your notes & info"
     EditText(a$,"gigbook-data/memo.txt")
     goto top
  end if

  if button_pressed("phone") then
     gosub erasebuttons
     a$="Your Phone numbers & emails"
     EditText(a$,"gigbook-data/phone.txt")
     goto top
  end if

  slowdown

until 0

end



'=================================
' G O S U B S / F U N C T I O N S
'=================================

'=======
GetData: 'Gets & set Month & day data.
'======= 'xp is day of week the 1st on

MaxYear=2033 'data only up to this year.

'default selected year is current year
if SelYear=0 then SelYear=current_year()
'if out of date, go to last good year
if SelYear>MaxYear then SelYear=MaxYear

'default is current month
if SelMonth=0 then SelMonth=current_month()

'Data for years 2016-2033 is below.
'Contains number for each month - it's the
'day of week the 1st falls on.  The last 2
'numbers is how many days FEB has for
'that year, 28 or 29. (FEB has leap years).
'There's a math formula to figure this out,
'but I dont have it in my head.

if SelYear=2016 then i$="62361462573529"
if SelYear=2017 then i$="14472573614628"
if SelYear=2018 then i$="25513614725728"
if SelYear=2019 then i$="36624725136128"
if SelYear=2020 then i$="47146247351329"
if SelYear=2021 then i$="62257351462428"
if SelYear=2022 then i$="73361462573528"
if SelYear=2023 then i$="14472573614628"
if selYear=2024 then i$="25624725136129"
if SelYear=2025 then i$="47735136247228"
if SelYear=2026 then i$="51146247351328"
if SelYear=2027 then i$="62257351462428"
if SelYear=2028 then i$="73472573614629"
if SelYear=2029 then i$="25513614725728"
if SelYear=2030 then i$="36624725136128"
if SelYear=2031 then i$="47735136247228"
if SelYear=2032 then i$="51257351462429"
if SelYear=2033 then i$="73361462573528"

if SelMonth = 1 then 
  month$="January" ! days = 31
  xp = val(mid$(i$,1,1))
end if
if SelMonth = 2 then 
  month$="February"
  days = val(mid$(i$,13,2))
  xp = val(mid$(i$,2,1))
end if
if SelMonth = 3 then 
  month$="March" ! days = 31
  xp = val(mid$(i$,3,1))
end if
if SelMonth = 4 then 
  month$="April" ! days = 30
  xp = val(mid$(i$,4,1))
end if
if SelMonth = 5 then 
  month$="May" ! days = 31
  xp = val(mid$(i$,5,1))
end if
if SelMonth = 6 then 
  month$="June" ! days = 30
  xp = val(mid$(i$,6,1))
end if
if SelMonth = 7 then 
  month$="July" ! days = 31
  xp = val(mid$(i$,7,1))
end if
if SelMonth = 8 then 
  month$="August" ! days = 31
  xp = val(mid$(i$,8,1))
end if
if SelMonth = 9 then 
  month$="September" ! days = 30
  xp = val(mid$(i$,9,1))
end if
if SelMonth = 10 then 
  month$="October" ! days = 31
  xp = val(mid$(i$,10,1))
end if
if SelMonth = 11 then 
  month$="November" ! days = 30
  xp = val(mid$(i$,11,1))
end if
if SelMonth = 12 then 
  month$="December" ! days = 31
  xp = val(mid$(i$,12,1))
end if
return


'========
ShowYears:
'========

gosub erasebuttons

graphics clear .9,.9,.9
draw font size 56*rw
centertext("Select year:",30)
y=150*rh!yc=sw/6!xp=1
for t = 2016 to MaxYear
    'draw years
    button str$(t) text t at yc*(xp-1),y size yc,yc
    xp=xp+1
    if xp=7 then
      xp=1!y=y+yc
    end if
next t
do
  for d=2016 to MaxYear
    if button_pressed(str$(d)) then 
      SelYear=d
      goto yeardone
    end if
  next d
until 0

yeardone:
for t = 2016 to MaxYear
   button str$(t) delete
next t

return


'=========
ShowMonths:
'=========

gosub EraseButtons

dim m$(12)!m$(1)="January"!m$(2)="February"
m$(3)="March"!m$(4)="April"!m$(5)="May"
m$(6)="June"!m$(7)="July"!m$(8)="August"
m$(9)="September"!m$(10)="October"
m$(11)="November"!m$(12)="December"
graphics clear .9,.9,.9
draw font size 56*rw
centertext("Select month:",30)
y=150
for t = 1 to 12
   'draw month
   button str$(t) text m$(t) at 200*rw,y*rh size 400*rw,56*rh
   y=y+60
next t
do
  for d=1 to 12
    if button_pressed(str$(d)) then 
      SelMonth=d
      goto monthdone
    end if
  next d
until 0

monthdone:
for t = 1 to 12
   button str$(t) delete
next t

return


'===========
EraseButtons:
'===========

button "<" delete ! button ">" delete
for t = 1 to days
    button str$(t) delete
next t
button "year" delete
button "month" delete
button "memo" delete
button "phone" delete

return

'=================================

def iphone(dev$)
'settings for iphone/ipod devices
'iphone/ipod 4/5/6/6+

'default is iphone 6
.sw=375!.sh=667

if dev$="4" then
   .sw=320!.sh=480
end if
if dev$="5" then
   .sw=320!.sh=568
end if
if dev$="6" then
   .sw=375!.sh=667
end if
if dev$="6+" then
   .sw=414!.sh=736
end if

.rw=.sw/768!.rh=.sh/1024

end def

'=================================

def dayname$(num)
  if num = 1 then return "Sunday"
  if num = 2 then return "Monday"
  if num = 3 then return "Tuesday"
  if num = 4 then return "Wednesday"
  if num = 5 then return "Thursday"
  if num = 6 then return "Friday"
  if num = 7 then return "Saturday"
end def

'=================================

def today$
  'just a nice full display of todays date:
  'Wednesday, October 5th, 2016
  cd=current_day()
  if cd = 0 then cd$="Sunday "
  if cd = 1 then cd$="Monday "
  if cd = 2 then cd$="Tuesday "
  if cd = 3 then cd$="Wednesday "
  if cd = 4 then cd$="Thursday "
  if cd = 5 then cd$="Friday "
  if cd = 6 then cd$="Saturday "
  cm=current_month()
  if cm=1 then cm$="January "
  if cm=2 then cm$="February "
  if cm=3 then cm$="March "
  if cm=4 then cm$="April "
  if cm=5 then cm$="May "
  if cm=6 then cm$="June "
  if cm=7 then cm$="July "
  if cm=8 then cm$="August "
  if cm=9 then cm$="September "
  if cm=10 then cm$="October "
  if cm=11 then cm$="November "
  if cm=12 then cm$="December "
  c=current_date()!cdd$=str$(c)
  if c=1 or c=21 or c=31 then cdd$=cdd$&"st, "
  if c=2 or c=22 then cdd$=cdd$&"nd, "
  if c=3 or c=23 then cdd$=cdd$&"rd, "
  if c>3 and c<21 then cdd$=cdd$&"th, "
  if c>23 and c <31 then cdd$=cdd$&"th, "
  return cd$&cm$&cdd$&str$(.SelYear)
end def

'=================================

def centertext(a$,y)
  x=((.sw/2)-text_width(a$)/2)
  draw text a$ at x,y*.rh
end def

'=================================

def EditText(title$, f$)
'title$ is page title.
'f$ is text filename to use/edit.

'gosub EraseButtons

graphics clear .9,.9,.9

'draw paper
shadow on
draw color 0,0,1
draw line 45*.rw,120*.rh to 45*.rw,.sh
draw line 49*.rw,120*.rh to 49*.rw,.sh
for s= 1 to 21
   draw line 0,(130*.rh)+(41.3*s*.rh) to .sw,(130*.rh)+(41.3*s*.rh)
next s

'draw title bar
fill color 0,.5,1
fill rect 0,0 to .sw,110*.rh
draw color 1,1,1
centertext(title$,10)
shadow off

fill color .7,.7,.7
draw color 1,1,1
button "done" text "done" at .sw-(130*.rw),50*.rh size 125*.rw,56*.rh
draw color 1,1,1
fill color 1,.5,.5
button "clear" text "clear" at 500*.rw,50*.rh size 125*.rw,56*.rh

draw font size 26*.rw
draw text f$ at 25*.rw,65*.rh
draw font size 37*.rw

ReEdit:

'make an editor field
field "1" text "" at 60*.rw,122*.rh size .sw-(86*.rw),.sh-(381*.rh) ml
field "1" font size 36*.rw
field "1" back alpha 0

'load entry if filename exists
if file_exists(f$) then
   file f$ setpos 0 'top of file
   e$=""
   do
      file f$ readline lin$
      e$=e$&lin$&chr$(10)
   until file_end(f$)=1
   field "1" text e$
end if

do
   if button_pressed("clear") then 
      field "1" delete
      file f$ delete
      goto ReEdit
   end if
until button_pressed("done")

'grab text, if any, to txt$
txt$= field_text$("1")

file f$ delete
field "1" delete
button "done" delete
button "clear" delete

'only save data to file if txt$ not empty
if txt$<>"" then
  file f$ write 32 'make a file to use
  file f$ setpos 0 'go to beginning
  for u=1 to len(txt$)
    file f$ write asc(mid$(txt$,u,1))
  next u
end if

end def
Attachments
gigbook1.jpg
gigbook1.jpg (78.18 KiB) Viewed 6103 times
gigbook2.jpg
gigbook2.jpg (96.03 KiB) Viewed 6103 times
Last edited by Dav on Mon Oct 10, 2016 4:55 pm, edited 3 times in total.

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: GigBook v1.1 - Calendar/Journal for 2016-2033 (iPad/iPhone)

Post by rbytes »

What a treat for a long weekend! Thanks, Dav! :D
The only thing that gets me down is gravity...

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: GigBook v1.1 - Calendar/Journal for 2016-2033 (iPad/iPhone)

Post by rbytes »

These are great improvements. There was one little thing that bothered me - a flaw in iOS that makes the toolbar inactive if a program is launched in landscape mode and then set to portrait. I nearly always use your drawinfobar to create a much more informative and less bulky toolbar. See the iPad and iPhone 6 screengrabs. I added a charge indicator to the battery display. The button on the left side is for debug.

****** fixed a line of code that prevented the notebook paper from displaying! ***********

Normally the iPhone device info in the infobar would be correct, but I am calling your iPhone 6 function on my iPad for that screenshot.

Code: Select all

'================
'GigBook.txt v1.1
'================
'An event calendar/journal
'Works on ipad/iphone/ipod touch
'ONLY GOOD FOR YEARS BETWEEN 2016-2033
'Coded by Dav, OCT/2016
'
'Use arrows to navigate the month to view.
'Or use Year & Month buttons to jump there.
'Press a number to add events on that day.
'An editing window will open to allow input.
'Press Done when you have finished editing.
'Pressing Clear will erase/delete the entry.
'Highlighted days means an event is scheduled.
'To erase highlight press Clear when editing.
'Data saved in the /gigbook-data/ directory.
'Entry filenames saved like: 2016-10-12.txt

'CREDITS: I used ricardobytes method to make  
'the app compatible with both ipad & iphone.


OPTION BASE 1
SET ORIENTATION vertical
laun$=LAUNCHER$ ()
SET TOOLBAR OFF
GET SCREEN SIZE sw,sh

'detect device for screen settings
IF LOWSTR$(DEVICE_TYPE$())="ipad" THEN 
   rw=1!rh=1!vmod=0
ELSE
   rw=sw/768!rh=sh/1024!vmod=50
END IF

'========= for testing purposes ============
'call iphone("4") '<<<< force test iphone 4
'call iphone("5") '<<<< force test iphone 5
'call iphone("6") '<<<< force test iphone 6
'call iphone("6+")'<<<< force test iphone 6+
'===========================================
CALL iphone("6")

'make gigbook directory if doesn't exist
IF FILE_EXISTS("gigbook-data/") = 0 THEN 
   DIR "gigbook-data" CREATE
END IF


'===
TOP:
'===

GRAPHICS
GRAPHICS CLEAR .9,.9,.9

SET BUTTONS CUSTOM
SET BUTTONS FONT SIZE 42*rw

GOSUB GetData

DRAW COLOR 0,0,.8
FILL COLOR .9,.9,1

DRAW FONT SIZE 56*rw
centertext(month$&" - "&STR$(SelYear),30)

DRAW FONT SIZE 37*rw
DRAW TEXT "Sun  Mon  Tue  Wed  Thu  Fri  Sat" AT 10*rw,100*rh

'draw a month view
y=150*rh!yc=sw/7!DIM day$(days)!events=0
FOR t = 1 TO days
    day$(t)=dayname$(xp)
    DRAW COLOR 0,0,.8

    'see if event saved for this day
    'if so, make button special color.
    entry$=STR$(SelYear)&"-"&STR$(SelMonth)&"-"&STR$(t)&".txt"
    IF FILE_EXISTS("gigbook-data/"&entry$) =1 THEN
       events=events+1
       FILL COLOR .89,.89,1
    ELSE
       FILL COLOR 1,1,1
    END IF

    'use special color if days todays date
    IF CURRENT_YEAR()=SelYear THEN
      IF SelMonth=CURRENT_MONTH() THEN
        IF t=CURRENT_DATE() THEN 
         DRAW COLOR 1,1,1
         FILL COLOR 0,0,1
        END IF
      END IF
    END IF

    'draw days in the month
    BUTTON STR$(t) TEXT t AT yc*(xp-1),y SIZE yc,yc
    xp=xp+1
    IF xp=8 THEN
      xp=1!y=y+yc
    END IF

NEXT t

'draw nav buttons
SET BUTTONS FONT SIZE 65*rw
BUTTON "<" TEXT CHR$(9664) AT 25*rw,20*rh SIZE 75*rw,75*rh
BUTTON ">" TEXT CHR$(9654) AT sw-(91*rw),20*rh SIZE 75*rw,75*rh
SET BUTTONS FONT SIZE 42*rw

'draw info at bottom
DRAW FONT SIZE 32*rw
'show todays date
centertext("Today is "&today$,900)
'see if today has and entry
te$=STR$(SelYear)&"-"&STR$(CURRENT_MONTH())&"-"&STR$(CURRENT_DATE())&".txt"
IF FILE_EXISTS("gigbook-data/"&te$) =1 THEN
  centertext("An event is scheduled today",936)
ELSE
  centertext("No events scheduled today",936)
END IF

'draw buttons at bottom
DRAW FONT SIZE 37*rw
BUTTON "year" TEXT "Year" AT 40*rw,830*rh SIZE 135*rw,56*rh
BUTTON "month" TEXT "Month" AT 200*rw,830*rh SIZE 145*rw,56*rh
BUTTON "memo" TEXT "Memo" AT 375*rw,830*rh SIZE 145*rw,56*rh
BUTTON "phone" TEXT "Phone#" AT 550*rw,830*rh SIZE 175*rw,56*rh
GOSUB drawinfobar

'wait for user to make a move
DO
  ' check infobar buttons and update display info
  IF BUTTON_PRESSED("quit") THEN
    IF laun$="desktop" THEN RUN "/-Launch.sb"
    END
  ENDIF
  IF BUTTON_PRESSED("debug") THEN DEBUG PAUSE
  ' update infobar every 30 seconds
  IF TIME()-calc>30 THEN
    calc=TIME()
    GOSUB drawinfobar
  END IF
  FOR d=1 TO days
    IF BUTTON_PRESSED(STR$(d)) THEN 
       GOSUB erasebuttons
       a$=day$(d)&" "&month$&" "
       a$=a$&STR$(d)&", "&STR$(SelYear)
       b$=STR$(SelYear)&"-"&STR$(SelMonth)
       b$=b$&"-"&STR$(d)&".txt"
       EditText(a$,"gigbook-data/"&b$)
       GOTO TOP
    END IF
  NEXT d
  
  IF BUTTON_PRESSED("<") THEN
    IF SelMonth=1 AND SelYear=2016 THEN
       'dont do anything. hit wall.
    ELSE
       GOSUB erasebuttons
       'subtract month
       SelMonth = SelMonth - 1
       IF SelMonth=0 THEN
          SelMonth=12!SelYear=SelYear-1
       END IF
       GOTO TOP
    END IF
  END IF

  IF BUTTON_PRESSED(">") THEN
    IF SelMonth=12 AND SelYear=MaxYear THEN 
       'dont do anything. hit wall.
    ELSE
       GOSUB erasebuttons
       SelMonth = SelMonth +1
       IF SelMonth=13 THEN
          SelMonth=1!SelYear=SelYear+1
       END IF
       GOTO TOP
    END IF
  END IF

  IF BUTTON_PRESSED("year") THEN
     GOSUB ShowYears !  GOTO TOP
  END IF

  IF BUTTON_PRESSED("month") THEN
     GOSUB ShowMonths !  GOTO TOP
  END IF

  IF BUTTON_PRESSED("memo") THEN
     GOSUB erasebuttons
     a$="Memo: Save your notes & info"
     EditText(a$,"gigbook-data/memo.txt")
     GOTO TOP
  END IF

  IF BUTTON_PRESSED("phone") THEN
     GOSUB erasebuttons
     a$="Your Phone numbers & emails"
     EditText(a$,"gigbook-data/phone.txt")
     GOTO TOP
  END IF

  SLOWDOWN

UNTIL 0

END



'=================================
' G O S U B S / F U N C T I O N S
'=================================

'=======
GetData: 'Gets & set Month & day data.
'======= 'xp is day of week the 1st on

MaxYear=2033 'data only up to this year.

'default selected year is current year
IF SelYear=0 THEN SelYear=CURRENT_YEAR()
'if out of date, go to last good year
IF SelYear>MaxYear THEN SelYear=MaxYear

'default is current month
IF SelMonth=0 THEN SelMonth=CURRENT_MONTH()

'Data for years 2016-2030 is below.
'Contains number for each month - it's the
'day of week the 1st falls on.  The last 2
'numbers is how many days FEB has for
'that year, 28 or 29. (FEB has leap years).
'There's a math formula to figure this out,
'but I dont have it in my head.

IF SelYear=2016 THEN i$="62361462573529"
IF SelYear=2017 THEN i$="14472573614628"
IF SelYear=2018 THEN i$="25513614725728"
IF SelYear=2019 THEN i$="36624725136128"
IF SelYear=2020 THEN i$="47146247351329"
IF SelYear=2021 THEN i$="62257351462428"
IF SelYear=2022 THEN i$="73361462573528"
IF SelYear=2023 THEN i$="14472573614628"
IF selYear=2024 THEN i$="25624725136129"
IF SelYear=2025 THEN i$="47735136247228"
IF SelYear=2026 THEN i$="51146247351328"
IF SelYear=2027 THEN i$="62257351462428"
IF SelYear=2028 THEN i$="73472573614629"
IF SelYear=2029 THEN i$="25513614725728"
IF SelYear=2030 THEN i$="36624725136128"
IF SelYear=2031 THEN i$="47735136247228"
IF SelYear=2032 THEN i$="51257351462429"
IF SelYear=2033 THEN i$="73361462573528"

IF SelMonth = 1 THEN 
  month$="January" ! days = 31
  xp = VAL(MID$(i$,1,1))
END IF
IF SelMonth = 2 THEN 
  month$="February"
  days = VAL(MID$(i$,13,2))
  xp = VAL(MID$(i$,2,1))
END IF
IF SelMonth = 3 THEN 
  month$="March" ! days = 31
  xp = VAL(MID$(i$,3,1))
END IF
IF SelMonth = 4 THEN 
  month$="April" ! days = 30
  xp = VAL(MID$(i$,4,1))
END IF
IF SelMonth = 5 THEN 
  month$="May" ! days = 31
  xp = VAL(MID$(i$,5,1))
END IF
IF SelMonth = 6 THEN 
  month$="June" ! days = 30
  xp = VAL(MID$(i$,6,1))
END IF
IF SelMonth = 7 THEN 
  month$="July" ! days = 31
  xp = VAL(MID$(i$,7,1))
END IF
IF SelMonth = 8 THEN 
  month$="August" ! days = 31
  xp = VAL(MID$(i$,8,1))
END IF
IF SelMonth = 9 THEN 
  month$="September" ! days = 30
  xp = VAL(MID$(i$,9,1))
END IF
IF SelMonth = 10 THEN 
  month$="October" ! days = 31
  xp = VAL(MID$(i$,10,1))
END IF
IF SelMonth = 11 THEN 
  month$="November" ! days = 30
  xp = VAL(MID$(i$,11,1))
END IF
IF SelMonth = 12 THEN 
  month$="December" ! days = 31
  xp = VAL(MID$(i$,12,1))
END IF
RETURN


'========
ShowYears:
'========

GOSUB erasebuttons

GRAPHICS CLEAR .9,.9,.9
DRAW FONT SIZE 56*rw
centertext("Select year:",30)
y=150*rh!yc=sw/6!xp=1
FOR t = 2016 TO MaxYear
    'draw years
    BUTTON STR$(t) TEXT t AT yc*(xp-1),y SIZE yc,yc
    xp=xp+1
    IF xp=7 THEN
      xp=1!y=y+yc
    END IF
NEXT t
DO
  FOR d=2016 TO MaxYear
    IF BUTTON_PRESSED(STR$(d)) THEN 
      SelYear=d
      GOTO yeardone
    END IF
  NEXT d
UNTIL 0

yeardone:
FOR t = 2016 TO MaxYear
   BUTTON STR$(t) DELETE
NEXT t

RETURN


'=========
ShowMonths:
'=========

GOSUB EraseButtons

DIM m$(12)!m$(1)="January"!m$(2)="February"
m$(3)="March"!m$(4)="April"!m$(5)="May"
m$(6)="June"!m$(7)="July"!m$(8)="August"
m$(9)="September"!m$(10)="October"
m$(11)="November"!m$(12)="December"
GRAPHICS CLEAR .9,.9,.9
DRAW FONT SIZE 56*rw
centertext("Select month:",30)
y=150
FOR t = 1 TO 12
   'draw month
   BUTTON STR$(t) TEXT m$(t) AT 200*rw,y*rh SIZE 400*rw,56*rh
   y=y+60
NEXT t
DO
  FOR d=1 TO 12
    IF BUTTON_PRESSED(STR$(d)) THEN 
      SelMonth=d
      GOTO monthdone
    END IF
  NEXT d
UNTIL 0

monthdone:
FOR t = 1 TO 12
   BUTTON STR$(t) DELETE
NEXT t

RETURN


'===========
EraseButtons:
'===========

BUTTON "<" DELETE ! BUTTON ">" DELETE
FOR t = 1 TO days
    BUTTON STR$(t) DELETE
NEXT t
BUTTON "year" DELETE
BUTTON "month" DELETE
BUTTON "memo" DELETE
BUTTON "phone" DELETE

RETURN

'=================================

DEF iphone(dev$)
'settings for iphone/ipod devices
'iphone/ipod 4/5/6/6+

'default is iphone 6
.sw=375!.sh=667

IF dev$="4" THEN
   .sw=320!.sh=480
END IF
IF dev$="5" THEN
   .sw=320!.sh=568
END IF
IF dev$="6" THEN
   .sw=375!.sh=667
END IF
IF dev$="6+" THEN
   .sw=414!.sh=736
END IF

.rw=.sw/768!.rh=.sh/1024

END DEF

'=================================

DEF dayname$(num)
  IF num = 1 THEN RETURN "Sunday"
  IF num = 2 THEN RETURN "Monday"
  IF num = 3 THEN RETURN "Tuesday"
  IF num = 4 THEN RETURN "Wednesday"
  IF num = 5 THEN RETURN "Thursday"
  IF num = 6 THEN RETURN "Friday"
  IF num = 7 THEN RETURN "Saturday"
END DEF

'=================================

DEF today$
  'just a nice full display of todays date:
  'Wednesday, October 5th, 2016
  cd=CURRENT_DAY()
  IF cd = 0 THEN cd$="Sunday "
  IF cd = 1 THEN cd$="Monday "
  IF cd = 2 THEN cd$="Tuesday "
  IF cd = 3 THEN cd$="Wednesday "
  IF cd = 4 THEN cd$="Thursday "
  IF cd = 5 THEN cd$="Friday "
  IF cd = 6 THEN cd$="Saturday "
  cm=CURRENT_MONTH()
  IF cm=1 THEN cm$="January "
  IF cm=2 THEN cm$="February "
  IF cm=3 THEN cm$="March "
  IF cm=4 THEN cm$="April "
  IF cm=5 THEN cm$="May "
  IF cm=6 THEN cm$="June "
  IF cm=7 THEN cm$="July "
  IF cm=8 THEN cm$="August "
  IF cm=9 THEN cm$="September "
  IF cm=10 THEN cm$="October "
  IF cm=11 THEN cm$="November "
  IF cm=12 THEN cm$="December "
  c=CURRENT_DATE()!cdd$=STR$(c)
  IF c=1 OR c=21 OR c=31 THEN cdd$=cdd$&"st, "
  IF c=2 OR c=22 THEN cdd$=cdd$&"nd, "
  IF c=3 OR c=23 THEN cdd$=cdd$&"rd, "
  IF c>3 AND c<21 THEN cdd$=cdd$&"th, "
  IF c>23 AND c <31 THEN cdd$=cdd$&"th, "
  RETURN cd$&cm$&cdd$&STR$(.SelYear)
END DEF

'=================================

DEF centertext(a$,y)
  x=((.sw/2)-TEXT_WIDTH(a$)/2)
  DRAW TEXT a$ AT x,y*.rh
END DEF

'=================================

DEF EditText(title$, f$)
'title$ is page title.
'f$ is text filename to use/edit.

'gosub EraseButtons

GRAPHICS CLEAR .9,.9,.9

'draw paper
SHADOW ON
DRAW COLOR 0,0,1
DRAW LINE 45*.rw,120*.rh TO 45*.rw,.sh
DRAW LINE 49*.rw,120*.rh TO 49*.rw,.sh
FOR s= 1 TO 21
   DRAW LINE 0,(130*.rh)+(41.3*s*.rh) TO .sw,(130*.rh)+(41.3*s*.rh)
NEXT s

'draw title bar
FILL COLOR 0,.5,1
FILL RECT 0,0 TO .sw,110*.rh
DRAW COLOR 1,1,1
centertext(title$,10)
SHADOW OFF

FILL COLOR .7,.7,.7
DRAW COLOR 1,1,1
BUTTON "done" TEXT "done" AT .sw-(130*.rw),50*.rh SIZE 125*.rw,56*.rh
DRAW COLOR 1,1,1
FILL COLOR 1,.5,.5
BUTTON "clear" TEXT "clear" AT 500*.rw,50*.rh SIZE 125*.rw,56*.rh

DRAW FONT SIZE 26*.rw
DRAW TEXT f$ AT 25*.rw,65*.rh
DRAW FONT SIZE 37*.rw

ReEdit:

'make an editor field
FIELD "1" TEXT "" AT 60*.rw,122*.rh SIZE .sw-(86*.rw),.sh-(381*.rh) ML
FIELD "1" FONT SIZE 36*.rw
FIELD "1" BACK ALPHA 0

'load entry if filename exists
IF FILE_EXISTS(f$) THEN
   FILE f$ SETPOS 0 'top of file
   e$=""
   DO
      FILE f$ READLINE lin$
      e$=e$&lin$&CHR$(10)
   UNTIL FILE_END(f$)=1
   FIELD "1" TEXT e$
END IF

DO
   IF BUTTON_PRESSED("clear") THEN 
      FIELD "1" DELETE
      FILE f$ DELETE
      GOTO ReEdit
   END IF
UNTIL BUTTON_PRESSED("done")

'grab text, if any, to txt$
txt$= FIELD_TEXT$("1")

FILE f$ DELETE
FIELD "1" DELETE
BUTTON "done" DELETE
BUTTON "clear" DELETE

'only save data to file if txt$ not empty
IF txt$<>"" THEN
  FILE f$ WRITE 32 'make a file to use
  FILE f$ SETPOS 0 'go to beginning
  FOR u=1 TO LEN(txt$)
    FILE f$ WRITE ASC(MID$(txt$,u,1))
  NEXT u
END IF

END DEF

'g' 
'Create custom top toolbar
drawinfobar:                        ' by Dav
REFRESH OFF
FILL ALPHA 0
fsize=18
IF dev$="iPad" THEN
  ypos=-12
  baty1=11
  baty2=23
  SET BUTTONS FONT SIZE fsize
ELSE
  ypos=-6
  baty1=11
  baty2=21
  SET BUTTONS FONT SIZE fsize*rh*.9
ENDIF
fsize=18
pfactor=2.6         ' sets range of battery indicator
'SET BUTTONS FONT SIZE fsize*rw
'=== show device info
sv$=DEVICE_TYPE$()&" with iOS "&SYSTEM_VERSION()
'===show time
ampm$="AM" ! hr=CURRENT_HOUR()! IF hr=0 THEN hr=12
MIN$=STR$(CURRENT_MINUTE())
IF LEN(MIN$)=1 THEN MIN$="0"&MIN$
IF hr>12 THEN
  hr=hr-12 ! ampm$="PM"
ENDIF
IF hr=0 THEN hr=12
tme$=STR$(hr)&":"&MIN$&" "&ampm$
tx=((sw/2)-TEXT_WIDTH(tme$)/2)
'===show app name
app$="GigBook V1.3"
'===show battery condition
bat$=STR$(BATTERY_LEVEL())&"%"
lev=BATTERY_LEVEL()
tat=BATTERY_STATE ()
IF tat THEN tat$="~" ELSE tat$=""
/*
DRAW COLOR 1,1,1
BUTTON "sdebug" TEXT CHR$(8545) AT sw*.02,ypos+1
BUTTON "sdev" TEXT sv$ AT sw,ypos+1
BUTTON "stime" TEXT tme$ AT sw*.3,ypos+1
BUTTON "sapp" TEXT app$ AT sw*.44,ypos+1
BUTTON "sbat" TEXT bat$ AT sw*.68,ypos+1
BUTTON "stat" TEXT tat$ AT sw*.85,ypos+1
BUTTON "squit" TEXT "X" AT sw*.95,ypos+1
*/
DRAW COLOR 0,0,0
BUTTON "debug" TEXT CHR$(8545) AT sw*.02-1,ypos
BUTTON "dev" TEXT sv$ AT sw*.07-1,ypos
BUTTON "time" TEXT tme$ AT sw*.34-1,ypos
BUTTON "app" TEXT app$ AT sw*.48-1,ypos
BUTTON "bat" TEXT bat$ AT sw*.71-1,ypos
BUTTON "tat" TEXT tat$ AT sw*.87-1,ypos
BUTTON "quit" TEXT "X" AT sw*.95-1,ypos
'=== draw battery graphics
FILL ALPHA 1
DRAW ALPHA 1
DRAW SIZE 1
SHADOW OFFSET 0,0
lev=lev/pfactor
/*
FILL COLOR 0,0,0
DRAW COLOR 0,0,0
DRAW RECT sw*.75+1,(baty1+ypos)*rath+1 TO sw*.79+1,(baty2+ypos)*rath+1
'FILL RECT sw*.75+1,(baty1+ypos)*ratioh+1 TO sw*.75+1+lev*ratiow,(baty2+ypos)*ratioh+1
FILL RECT sw*.79+1,(baty1+3+ypos)*ratioh+1 TO sw*.79+4,(baty2-3+ypos)*ratioh+1
*/
FILL COLOR 0,0,0
DRAW COLOR 0,0,0
DRAW SIZE 1
DRAW RECT sw*.8,(baty1+ypos)*rh TO sw*.85,(baty2+ypos)*rh
FILL RECT sw*.8,(baty1+ypos)*rh TO sw*.8+lev*rw,(baty2+ypos)*rh
FILL RECT sw*.85,(baty1+3+ypos)*rh TO sw*.85+3,(baty2-3+ypos)*rh
tat=BATTERY_STATE ()
IF tat THEN tat$="ϟ" ELSE tat$=""         ' Show ~ if battery is charging
'BUTTON "stat" TEXT tat$
DRAW COLOR 1,1,1
BUTTON "tat" TEXT tat$
SHADOW OFFSET 3,3
REFRESH ON
RETURN
''
Attachments
Simulated iPhone 6 screen
Simulated iPhone 6 screen
IMG_5260.PNG (145.31 KiB) Viewed 6174 times
iPad Air screen
iPad Air screen
IMG_5259.PNG (230.04 KiB) Viewed 6174 times
Last edited by rbytes on Sun Oct 09, 2016 8:30 pm, edited 1 time in total.
The only thing that gets me down is gravity...

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: GigBook v1.1 - Calendar/Journal for 2016-2033 (iPad/iPhone)

Post by rbytes »

You will have to change or comment out a line of code that comes a few lines after the DO command. It runs my launcher if GigBook was started from the desktop. As an alternative you can just comment out the line near the start of the program that sets the laun$ variable. Then GigBook will never try to return to the launcher.
The only thing that gets me down is gravity...

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: GigBook v1.1 - Calendar/Journal for 2016-2033 (iPad/iPhone)

Post by Dav »

I should have not designed it so close to the top, so that the toolbar info can be better used. If there was a command to tell if toolbar is ON/OFF so layout can be adjusted that would be helpful In some cases (or is there one?). With toolbar on my screen size shrinks 48 pixels, I think.

I may alter the layout a bit and do another update. By the way, I left out using the vmod variable and didn't notice any problem on my iPod. Did leaving it out mess up layout some on your device?

Glad you like the app!

- Dav

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: GigBook v1.1 - Calendar/Journal for 2016-2033 (iPad/iPhone)

Post by rbytes »

No, eliminating vmod didn't cause any problems.

Are you thinking that some users will want the sB toolbar on, even though it won't respond if GigBook is launched with the device held horizontally? If so, you could provide a flag variable for them to set. Having used your infobar, I would not want or need this option. I like that infobar functions in all positions, gives more information and takes up less space.

If you want your code to automatically detect whether the sB toolbar is on, you just need to check which device is running, determine what its native screen height is in either landscape or portrait, and then see if the actual height is less than that. I wrote some quick code to do this for my iPad. It would need to be extended to detect the toolbar state on other devices.

BTW the sB toolbar is actually 44 points high. This code shows the actual screen dimensions, and tells whether the toolbar is on or off. No stop button needed. The program ends after 3 seconds. :lol:

Code: Select all

REM check if sB toolbar is on on ipad
'SET TOOLBAR OFF
GRAPHICS
GRAPHICS CLEAR
DRAW COLOR 0,0,0
GET ORIENTATION p
GET SCREEN SIZE x,y
sw=1024!sh=768
IF p=1 OR p= 3 THEN
  IF y<1024 THEN flag=1
ENDIF
IF P=2 OR p=4 THEN
  IF y<768 THEN flag=1
ENDIF
DRAW TEXT "Screen width is: "&x AT 100,100 
DRAW TEXT "Screen height is: "&y AT 100,150
IF flag THEN cond$="on." ELSE cond$="off."
DRAW TEXT "The sB toolbar is "&cond$ AT 100,200
PAUSE 3
END

The only thing that gets me down is gravity...

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: GigBook v1.1 - Calendar/Journal for 2016-2033 (iPad/iPhone)

Post by Dav »

Yes, something like that. That's good. If no toolbar then maybe move calendar down 22 pixels to look better. Then rh=sh/1024 would be ok, and rh=sh/980 when toolbar on. I was just thinking mostly though, probably not worth the trouble coding it in.

I like how you are using the infobar. When I have some more free time I'm going to try adding some more things to it. Maybe pull current temperature from a weather feed, parse it out, and stick the temp up there, perhaps a small image of it's cloudy or clear - I seem to recall seeing weather emoji to use when making my chr$() character map app. I've been wanting to make a weather app for a while.

- Dav

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: GigBook v1.1 - Calendar/Journal for 2016-2033 (iPad/iPhone)

Post by rbytes »

I look forward to that. A weather app is something I would use daily. There are lots of weather emoji.
The only thing that gets me down is gravity...

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: GigBook v1.2 - Calendar/Journal for 2016-2033 (iPad/iPhone)

Post by Dav »

I did a little update to this app. Added option to mark an entry as important, and have it highlighted red in the monthly view. All you have to do is put an ! in the top left of the entry data an it will be considered important and show up as red. Removing the exclamation mark will made it a normal entry again.

Code is updated, and also the screen caps to show what it looks like.

The only change in the code was when loading the month view entries. Here's that part only if you want to just patch up your previous version:

Code: Select all

    'see if event saved for this day
    'if so, make button special color.
    entry$=str$(SelYear)&"-"&str$(SelMonth)&"-"&str$(t)&".txt"
    if file_exists("gigbook-data/"&entry$) =1 then
       events=events+1
       fill color .89,.89,1
       'see if its marked important...
       f$="gigbook-data/"&entry$
       file f$ setpos 0 ! file f$ read m
       'if so, make entry red filled.
       if m=asc("!") then fill color 1,.89,.89
    else
       fill color 1,1,1
    end if
- Dav

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

GigBook v1.3 - Calendar/Journal for 2016-2033 (iPad/iPhone)

Post by GeorgeMcGinn »

Hi Dav,

I am having problems terminating this program when I run it. I have to close SmartBASIC and restart it again.

So I made a few changes, they are highlighted in YELLOW:

1. Added a QUIT button, placed it above the Phone#, and it is highlighted the same color as the Clear button in the draw pages
2. I also added code to highlight the MEMO and PHONE# buttons if it has data in the files. Right now it highlights as an orange color.

I figured that if someone creates a Memo or has Phone# data, then the button should be highlighted to show that there is data in those two files. It is more so important for Memo, as that data may become obsolete, and if some are like me where my short-term memory is crappy, then when the program starts, I can see I have data, and it may need to be updated.

When you go in and erase the entire memo, or remove all your entries in Phone#, the buttons revert back to white.

I am working on one more update, and that is a 7-day list of entries. I am creating another button that will collect all the events for "today" and the next 6 days, and that will be displayed. It is a this week preview, so if someone uses this program a lot, they might want to list out their schedule or work to do or upcoming events/deadlines occurring in the next 7 days.

I'll be finished with this update in – 7 days, yes.

BTW: this program seems to crash when certain characters are entered in the paper section. For example, if I decide to use the long dash, the program crashes. I haven't looked into why, as I suspect it is something that SmartBASIC might not allow or like in input text fields.

George.






Code: Select all

'================
'GigBook.txt v1.3
'================
'An event calendar/journal
'Works on ipad/iphone/ipod touch
'ONLY GOOD FOR YEARS BETWEEN 2016-2033
'Coded by Dav, OCT/2016
'
'NEW for v1.2: Added red highlight entry.
'
'NEW for v1.3: Added QUIT button.
'              Added orange highlight for
'              memo and phone# if data exists.
'v1.3 updated by George McGinn
'
'HOW TO USE:
'^^^^^^^^^^
'This app lets you save important dates.
'You can also save memos and phone numbers.
'Use arrows to navigate the month to view.
'Or use Year & Month buttons to jump there.
'Press a number to add events on that day.
'An editing window will open to allow input.
'Press Done when you have finished editing.
'Pressing Clear will erase/delete the entry.
'Highlighted days mean an event is scheduled.
'To mark to entry as important and have it
'displayed red in the monthly view, just put
'an exclamation mark at top left in entry.
'To erase highlight press Clear when editing.
'Data saved in the /gigbook-data/ directory.
'Entry filenames saved like: 2016-10-12.txt

'CREDITS: I used ricardobytes method to make  
'the app compatible with both ipad & iphone.


OPTION BASE 1
SET ORIENTATION vertical
GET SCREEN SIZE sw,sh

'detect device for screen settings
IF LOWSTR$(DEVICE_TYPE$())="ipad" THEN 
   rw=1!rh=1!vmod=0
ELSE
   rw=sw/768!rh=sh/1024!vmod=50
END IF

'========= for testing purposes ============
'call iphone("4") '<<<< force test iphone 4
'call iphone("5") '<<<< force test iphone 5
'call iphone("6") '<<<< force test iphone 6
'call iphone("6+")'<<<< force test iphone 6+
'===========================================

'make gigbook directory if doesn't exist
IF FILE_EXISTS("gigbook-data/") = 0 THEN 
   DIR "gigbook-data" CREATE
END IF


'===
TOP:
'===

GRAPHICS
GRAPHICS CLEAR .9,.9,.9

SET BUTTONS CUSTOM
SET BUTTONS FONT SIZE 42*rw

GOSUB GetData

DRAW COLOR 0,0,.8
FILL COLOR .9,.9,1

DRAW FONT SIZE 56*rw
centertext(month$&" - "&STR$(SelYear),30)

DRAW FONT SIZE 37*rw
DRAW TEXT "Sun  Mon  Tue  Wed  Thu  Fri  Sat" AT 10*rw,100*rh

'draw a month view
y=150*rh!yc=sw/7!DIM day$(days)!events=0
FOR t = 1 TO days
    day$(t)=dayname$(xp)
    DRAW COLOR 0,0,.8

    'see if event saved for this day
    'if so, make button special color.
    entry$=STR$(SelYear)&"-"&STR$(SelMonth)&"-"&STR$(t)&".txt"
    IF FILE_EXISTS("gigbook-data/"&entry$) =1 THEN
       events=events+1
       FILL COLOR .89,.89,1
       'see if its marked important...
       f$="gigbook-data/"&entry$
       FILE f$ SETPOS 0 ! FILE f$ READ m
       'if so, make entry red filled.
       IF m=ASC("!") THEN FILL COLOR 1,.89,.89
    ELSE
       FILL COLOR 1,1,1
    END IF

    'use special color if days todays date
    IF CURRENT_YEAR()=SelYear THEN
      IF SelMonth=CURRENT_MONTH() THEN
        IF t=CURRENT_DATE() THEN 
         DRAW COLOR 1,1,1
         FILL COLOR 0,0,1
        END IF
      END IF
    END IF

    'draw days in the month
    BUTTON STR$(t) TEXT t AT yc*(xp-1),y SIZE yc,yc
    xp=xp+1
    IF xp=8 THEN
      xp=1!y=y+yc
    END IF

NEXT t

'draw nav buttons
SET BUTTONS FONT SIZE 65*rw
BUTTON "<" TEXT CHR$(9664) AT 25*rw,20*rh SIZE 75*rw,75*rh
BUTTON ">" TEXT CHR$(9654) AT sw-(91*rw),20*rh SIZE 75*rw,75*rh
SET BUTTONS FONT SIZE 42*rw

'draw info at bottom
DRAW FONT SIZE 32*rw
'show todays date
centertext("Today is "&today$,900)
'see if today has and entry
te$=STR$(SelYear)&"-"&STR$(CURRENT_MONTH())&"-"&STR$(CURRENT_DATE())&".txt"
IF FILE_EXISTS("gigbook-data/"&te$) =1 THEN
  centertext("An event is scheduled today",936)
ELSE
  centertext("No events scheduled today",936)
END IF

'draw buttons at bottom
'y'

''
DRAW FONT SIZE 37*rw
BUTTON "year" TEXT "Year" AT 40*rw,830*rh SIZE 135*rw,56*rh
BUTTON "month" TEXT "Month" AT 200*rw,830*rh SIZE 145*rw,56*rh

'y'
FSZ=FILE_SIZE("gigbook-data/memo.txt")
IF FSZ>0 THEN FILL COLOR 1,.7,.4
''
BUTTON "memo" TEXT "Memo" AT 375*rw,830*rh SIZE 145*rw,56*rh
'y'
FILL COLOR 0,0,0
FSZ=FILE_SIZE("gigbook-data/phone.txt")
IF FSZ>0 THEN FILL COLOR 1,.7,.4
''
BUTTON "phone" TEXT "Phone#" AT 550*rw,830*rh SIZE 175*rw,56*rh
'y'
FILL COLOR 1,.5,.5
BUTTON "quit" TEXT "QUIT" AT 550*rw,760*rh SIZE 125*rw,56*rh
FILL COLOR 0,0,0
''

'wait for user to make a move
DO

  FOR d=1 TO days
    IF BUTTON_PRESSED(STR$(d)) THEN 
       GOSUB erasebuttons
       a$=day$(d)&" "&month$&" "
       a$=a$&STR$(d)&", "&STR$(SelYear)
       b$=STR$(SelYear)&"-"&STR$(SelMonth)
       b$=b$&"-"&STR$(d)&".txt"
       EditText(a$,"gigbook-data/"&b$)
       GOTO TOP
    END IF
  NEXT d
  
  IF BUTTON_PRESSED("<") THEN
    IF SelMonth=1 AND SelYear=2016 THEN
       'dont do anything. hit wall.
    ELSE
       GOSUB erasebuttons
       'subtract month
       SelMonth = SelMonth - 1
       IF SelMonth=0 THEN
          SelMonth=12!SelYear=SelYear-1
       END IF
       GOTO TOP
    END IF
  END IF

  IF BUTTON_PRESSED(">") THEN
    IF SelMonth=12 AND SelYear=MaxYear THEN 
       'dont do anything. hit wall.
    ELSE
       GOSUB erasebuttons
       SelMonth = SelMonth +1
       IF SelMonth=13 THEN
          SelMonth=1!SelYear=SelYear+1
       END IF
       GOTO TOP
    END IF
  END IF

  IF BUTTON_PRESSED("year") THEN
     GOSUB ShowYears !  GOTO TOP
  END IF

  IF BUTTON_PRESSED("month") THEN
     GOSUB ShowMonths !  GOTO TOP
  END IF

  IF BUTTON_PRESSED("memo") THEN
     GOSUB erasebuttons
     a$="Memo: Save your notes & info"
     EditText(a$,"gigbook-data/memo.txt")
     GOTO TOP
  END IF

  IF BUTTON_PRESSED("phone") THEN
     GOSUB erasebuttons
     a$="Your Phone numbers & emails"
     EditText(a$,"gigbook-data/phone.txt")
     GOTO TOP
  END IF
  
'y'
  IF BUTTON_PRESSED("quit") THEN
     STOP
  ENDIF   
''  

  SLOWDOWN

UNTIL 0

END



'=================================
' G O S U B S / F U N C T I O N S
'=================================

'=======
GetData: 'Gets & set Month & day data.
'======= 'xp is day of week the 1st on

MaxYear=2033 'data only up to this year.

'default selected year is current year
IF SelYear=0 THEN SelYear=CURRENT_YEAR()
'if out of date, go to last good year
IF SelYear>MaxYear THEN SelYear=MaxYear

'default is current month
IF SelMonth=0 THEN SelMonth=CURRENT_MONTH()

'Data for years 2016-2033 is below.
'Contains number for each month - it's the
'day of week the 1st falls on.  The last 2
'numbers is how many days FEB has for
'that year, 28 or 29. (FEB has leap years).
'There's a math formula to figure this out,
'but I dont have it in my head.

IF SelYear=2016 THEN i$="62361462573529"
IF SelYear=2017 THEN i$="14472573614628"
IF SelYear=2018 THEN i$="25513614725728"
IF SelYear=2019 THEN i$="36624725136128"
IF SelYear=2020 THEN i$="47146247351329"
IF SelYear=2021 THEN i$="62257351462428"
IF SelYear=2022 THEN i$="73361462573528"
IF SelYear=2023 THEN i$="14472573614628"
IF selYear=2024 THEN i$="25624725136129"
IF SelYear=2025 THEN i$="47735136247228"
IF SelYear=2026 THEN i$="51146247351328"
IF SelYear=2027 THEN i$="62257351462428"
IF SelYear=2028 THEN i$="73472573614629"
IF SelYear=2029 THEN i$="25513614725728"
IF SelYear=2030 THEN i$="36624725136128"
IF SelYear=2031 THEN i$="47735136247228"
IF SelYear=2032 THEN i$="51257351462429"
IF SelYear=2033 THEN i$="73361462573528"

IF SelMonth = 1 THEN 
  month$="January" ! days = 31
  xp = VAL(MID$(i$,1,1))
END IF
IF SelMonth = 2 THEN 
  month$="February"
  days = VAL(MID$(i$,13,2))
  xp = VAL(MID$(i$,2,1))
END IF
IF SelMonth = 3 THEN 
  month$="March" ! days = 31
  xp = VAL(MID$(i$,3,1))
END IF
IF SelMonth = 4 THEN 
  month$="April" ! days = 30
  xp = VAL(MID$(i$,4,1))
END IF
IF SelMonth = 5 THEN 
  month$="May" ! days = 31
  xp = VAL(MID$(i$,5,1))
END IF
IF SelMonth = 6 THEN 
  month$="June" ! days = 30
  xp = VAL(MID$(i$,6,1))
END IF
IF SelMonth = 7 THEN 
  month$="July" ! days = 31
  xp = VAL(MID$(i$,7,1))
END IF
IF SelMonth = 8 THEN 
  month$="August" ! days = 31
  xp = VAL(MID$(i$,8,1))
END IF
IF SelMonth = 9 THEN 
  month$="September" ! days = 30
  xp = VAL(MID$(i$,9,1))
END IF
IF SelMonth = 10 THEN 
  month$="October" ! days = 31
  xp = VAL(MID$(i$,10,1))
END IF
IF SelMonth = 11 THEN 
  month$="November" ! days = 30
  xp = VAL(MID$(i$,11,1))
END IF
IF SelMonth = 12 THEN 
  month$="December" ! days = 31
  xp = VAL(MID$(i$,12,1))
END IF
RETURN


'========
ShowYears:
'========

GOSUB erasebuttons

GRAPHICS CLEAR .9,.9,.9
DRAW FONT SIZE 56*rw
centertext("Select year:",30)
y=150*rh!yc=sw/6!xp=1
FOR t = 2016 TO MaxYear
    'draw years
    BUTTON STR$(t) TEXT t AT yc*(xp-1),y SIZE yc,yc
    xp=xp+1
    IF xp=7 THEN
      xp=1!y=y+yc
    END IF
NEXT t
DO
  FOR d=2016 TO MaxYear
    IF BUTTON_PRESSED(STR$(d)) THEN 
      SelYear=d
      GOTO yeardone
    END IF
  NEXT d
UNTIL 0

yeardone:
FOR t = 2016 TO MaxYear
   BUTTON STR$(t) DELETE
NEXT t

RETURN


'=========
ShowMonths:
'=========

GOSUB EraseButtons

DIM m$(12)!m$(1)="January"!m$(2)="February"
m$(3)="March"!m$(4)="April"!m$(5)="May"
m$(6)="June"!m$(7)="July"!m$(8)="August"
m$(9)="September"!m$(10)="October"
m$(11)="November"!m$(12)="December"
GRAPHICS CLEAR .9,.9,.9
DRAW FONT SIZE 56*rw
centertext("Select month:",30)
y=150
FOR t = 1 TO 12
   'draw month
   BUTTON STR$(t) TEXT m$(t) AT 200*rw,y*rh SIZE 400*rw,56*rh
   y=y+60
NEXT t
DO
  FOR d=1 TO 12
    IF BUTTON_PRESSED(STR$(d)) THEN 
      SelMonth=d
      GOTO monthdone
    END IF
  NEXT d
UNTIL 0

monthdone:
FOR t = 1 TO 12
   BUTTON STR$(t) DELETE
NEXT t

RETURN


'===========
EraseButtons:
'===========

BUTTON "<" DELETE ! BUTTON ">" DELETE
FOR t = 1 TO days
    BUTTON STR$(t) DELETE
NEXT t
BUTTON "year" DELETE
BUTTON "month" DELETE
BUTTON "memo" DELETE
BUTTON "phone" DELETE
'y'
BUTTON "quit" DELETE
''

RETURN

'=================================

DEF iphone(dev$)
'settings for iphone/ipod devices
'iphone/ipod 4/5/6/6+

'default is iphone 6
.sw=375!.sh=667

IF dev$="4" THEN
   .sw=320!.sh=480
END IF
IF dev$="5" THEN
   .sw=320!.sh=568
END IF
IF dev$="6" THEN
   .sw=375!.sh=667
END IF
IF dev$="6+" THEN
   .sw=414!.sh=736
END IF

.rw=.sw/768!.rh=.sh/1024

END DEF

'=================================

DEF dayname$(num)
  IF num = 1 THEN RETURN "Sunday"
  IF num = 2 THEN RETURN "Monday"
  IF num = 3 THEN RETURN "Tuesday"
  IF num = 4 THEN RETURN "Wednesday"
  IF num = 5 THEN RETURN "Thursday"
  IF num = 6 THEN RETURN "Friday"
  IF num = 7 THEN RETURN "Saturday"
END DEF

'=================================

DEF today$
  'just a nice full display of todays date:
  'Wednesday, October 5th, 2016
  cd=CURRENT_DAY()
  IF cd = 0 THEN cd$="Sunday "
  IF cd = 1 THEN cd$="Monday "
  IF cd = 2 THEN cd$="Tuesday "
  IF cd = 3 THEN cd$="Wednesday "
  IF cd = 4 THEN cd$="Thursday "
  IF cd = 5 THEN cd$="Friday "
  IF cd = 6 THEN cd$="Saturday "
  cm=CURRENT_MONTH()
  IF cm=1 THEN cm$="January "
  IF cm=2 THEN cm$="February "
  IF cm=3 THEN cm$="March "
  IF cm=4 THEN cm$="April "
  IF cm=5 THEN cm$="May "
  IF cm=6 THEN cm$="June "
  IF cm=7 THEN cm$="July "
  IF cm=8 THEN cm$="August "
  IF cm=9 THEN cm$="September "
  IF cm=10 THEN cm$="October "
  IF cm=11 THEN cm$="November "
  IF cm=12 THEN cm$="December "
  c=CURRENT_DATE()!cdd$=STR$(c)
  IF c=1 OR c=21 OR c=31 THEN cdd$=cdd$&"st, "
  IF c=2 OR c=22 THEN cdd$=cdd$&"nd, "
  IF c=3 OR c=23 THEN cdd$=cdd$&"rd, "
  IF c>3 AND c<21 THEN cdd$=cdd$&"th, "
  IF c>23 AND c <31 THEN cdd$=cdd$&"th, "
  RETURN cd$&cm$&cdd$&STR$(.SelYear)
END DEF

'=================================

DEF centertext(a$,y)
  x=((.sw/2)-TEXT_WIDTH(a$)/2)
  DRAW TEXT a$ AT x,y*.rh
END DEF

'=================================

DEF EditText(title$, f$)
'title$ is page title.
'f$ is text filename to use/edit.

'gosub EraseButtons

GRAPHICS CLEAR .9,.9,.9

'draw paper
SHADOW ON
DRAW COLOR 0,0,1
DRAW LINE 45*.rw,120*.rh TO 45*.rw,.sh
DRAW LINE 49*.rw,120*.rh TO 49*.rw,.sh
FOR s= 1 TO 21
   DRAW LINE 0,(130*.rh)+(41.3*s*.rh) TO .sw,(130*.rh)+(41.3*s*.rh)
NEXT s

'draw title bar
FILL COLOR 0,.5,1
FILL RECT 0,0 TO .sw,110*.rh
DRAW COLOR 1,1,1
centertext(title$,10)
SHADOW OFF

FILL COLOR .7,.7,.7
DRAW COLOR 1,1,1
BUTTON "done" TEXT "done" AT .sw-(130*.rw),50*.rh SIZE 125*.rw,56*.rh
DRAW COLOR 1,1,1
FILL COLOR 1,.5,.5
BUTTON "clear" TEXT "clear" AT 500*.rw,50*.rh SIZE 125*.rw,56*.rh

DRAW FONT SIZE 26*.rw
DRAW TEXT f$ AT 25*.rw,65*.rh
DRAW FONT SIZE 37*.rw

ReEdit:

'make an editor field
FIELD "1" TEXT "" AT 60*.rw,122*.rh SIZE .sw-(86*.rw),.sh-(381*.rh) ML
FIELD "1" FONT SIZE 36*.rw
FIELD "1" BACK ALPHA 0

'load entry if filename exists
IF FILE_EXISTS(f$) THEN
   FILE f$ SETPOS 0 'top of file
   e$=""
   DO
      FILE f$ READLINE lin$
      e$=e$&lin$&CHR$(10)
   UNTIL FILE_END(f$)=1
   FIELD "1" TEXT e$
END IF

DO
   IF BUTTON_PRESSED("clear") THEN 
      FIELD "1" DELETE
      FILE f$ DELETE
      GOTO ReEdit
   END IF
UNTIL BUTTON_PRESSED("done")

'grab text, if any, to txt$
txt$= FIELD_TEXT$("1")

FILE f$ DELETE
FIELD "1" DELETE
BUTTON "done" DELETE
BUTTON "clear" DELETE

'only save data to file if txt$ not empty
IF txt$<>"" THEN
  FILE f$ WRITE 32 'make a file to use
  FILE f$ SETPOS 0 'go to beginning
  FOR u=1 TO LEN(txt$)
    FILE f$ WRITE ASC(MID$(txt$,u,1))
  NEXT u
END IF

END DEF
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

Post Reply