Monthly Planner View

new topic     » topic index » view thread      » older message » newer message

Since nobody seems to have already done this, I thought I'd add the
snippet for the archives.  This uses a slightly older version of
Win32Lib, so there may be some broken code with the most recent version.
 It also uses some routines from DateTime.e - Routines for handling Date
and Time - (c) 2001 CyrekSoft.  Use it or abuse it as you will.

Michael J. Sabal

---- Code follows ---

procedure draw_month(atom month, atom year)

  atom TOPLINE  -- constant defining the height of the header line
  sequence MONTHS  -- constant list of month names

  atom dow, dim    -- the day of week the month starts on & # days in
month
  atom curdow      -- current day of week used in drawing the days on
the cal.
  atom curweek     -- current week in drawing the days on the cal.
  sequence canvas  -- the drawable area

  TOPLINE=32
  MONTHS={"January","February","March","April",
                   "May","June","July",
                  
"August","September","October","November","December"}

  -- error trapping

  if currentMonth < 1 or currentMonth > 12 then
    return
  end if

  -- draw Grid

  setPenColor(LPlanner,Black)
  canvas = getClientRect(LPlanner)
 
drawLine(LPlanner,canvas[1],canvas[2]+TOPLINE,canvas[3],canvas[2]+TOPLINE)
  canvas[2] = canvas[2] + TOPLINE
  for ctr = 1 to 6 do
    drawLine(LPlanner,canvas[1]+floor(((canvas[3]-canvas[1])/7)*ctr),
             canvas[2],canvas[1]+floor(((canvas[3]-canvas[1])/7)*ctr),
             canvas[4])
  end for
  for ctr = 1 to 4 do
   
drawLine(LPlanner,canvas[1],canvas[2]+floor(((canvas[4]-canvas[2])/5)*ctr),
             canvas[3],canvas[2]+floor(((canvas[4]-canvas[2])/5)*ctr))
  end for

  -- draw Header

  setPenColor(LPlanner,Red)
 
drawRectangle(LPlanner,1,canvas[1],canvas[2]-TOPLINE,canvas[3],canvas[2])
  setTextColor(LPlanner,Yellow)
  setFont(LPlanner,"Times New Roman",16,Bold)
  wPuts({LPlanner,canvas[1]+3,canvas[2]-TOPLINE+3},MONTHS[month]&" "&
    sprintf("%4d",year))

  -- draw Days of month

  dim = daysInMonth(year,month)
  dow = dayOfWeek({year,month,1}) -- 1=Sun..7=Sat
  curweek = 1

  for ctr = 1 to dim do
    curdow = remainder((dow-1)+(ctr-1),7)+1  -- 1=Sun..7=Sat
    curweek = floor((ctr+dow-2)/7)+1
    if curdow = 1 then
      setTextColor(LPlanner,BrightRed)
    elsif curdow = 7 then
      setTextColor(LPlanner,BrightBlue)
    else
      setTextColor(LPlanner,Black)
    end if

   
wPuts({LPlanner,canvas[1]+floor(((canvas[3]-canvas[1])/7)*(curdow-1))+3,
          canvas[2]+floor(((canvas[4]-canvas[2])/5)*(curweek-1))+3},
          sprintf("%2d",ctr))
  end for

end procedure

global procedure onPaint_main(atom x1, atom y1, atom x2, atom y2)

  if currentView = MONTH_VIEW then
    draw_month(currentMonth, currentYear)
  end if


end procedure
onPaint[LPlanner] = routine_id("onPaint_main")

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu