Advertisement
RLocke

Simple Sobriety Tracker

May 15th, 2018
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     Version:
  3.     0.46 Update the Desktop Widget without making it show on top of anything else.
  4.     0.45 Added more user editable values at the top of the file
  5.     0.44 Show "it's a new day" for either the start of a new week, or someones first day.
  6.     0.43 added dynamic width calculation. I think that can be done via the gui itself, but it's less fun that way.
  7.     0.42 removed the taskbar button, now it has to be closed from the notification tray.
  8.     0.41 made the window transparent, dynamically resizes a bit, tracks weeks, removed borders/title bar.
  9. */
  10.  
  11.     start_date = 20180505 ; Date in a YYYYYMMDD format.
  12.     menu_X := 435 ;x cordinate for where the menu loads
  13.     menu_Y := 20 ; y coord
  14.  
  15.     gosub load_gui ; end user editable variables
  16.     gosub update_gui
  17.     SetTimer, update_gui, 900000 ; update every 10 minutes
  18. return
  19.  
  20. load_gui:
  21.     Gui, Color, Black
  22.     Gui +Owner ; hide taskbar button, it must be closed from the notification tray.
  23.  
  24.     Gui, Font, s10, Trebuchet MS
  25.     Gui, Add, Text, x2 y2  h200 w200 vDays cwhite ;cf4f3f5,
  26.  
  27.     Gui, Show, x%menu_X% y%menu_Y% h80 w125,
  28.  
  29.     Gui +LastFound  ; Make the GUI window the last found window for use by the line below.
  30.     WinSet, Transparent, 150, A
  31.  
  32.     ;Gui, Color, EEAA99 ;this and the line below allows full transparency
  33.     ;WinSet, TransColor, EEAA99
  34.  
  35.     WinSet, Style, ^0xC00000, A ; Hide the title bar and borders
  36.     OnMessage(0x201, "WM_LBUTTONDOWN") ; allow the menu to be dragged by the font. Ouch.
  37. return
  38.  
  39. WM_LBUTTONDOWN()
  40. {
  41.     PostMessage, 0xA1, 2
  42. }
  43.  
  44. uiMove:
  45.     PostMessage, 0xA1, 2,,, A
  46. Return
  47.  
  48. GuiClose:
  49.     ExitApp
  50. return
  51.  
  52. update_gui:
  53.     FormatTime, m_days, YYYYMMDD, yyyyMMdd
  54.     EnvSub, m_days, %start_date%, days
  55.  
  56.     ;m_days := 725 ; testing purposes
  57.  
  58.     m_totaldays := m_days
  59.     m_includetotal := ( m_days >= 7 )
  60.  
  61.     m_string := ""
  62.     if ( m_days >= 365 )
  63.         m_string := m_string . "Years sober: " Floor( m_days / 365 ) . "`n"
  64.  
  65.     while m_days >= 365
  66.         m_days -= 365
  67.  
  68.     if ( m_days >= 30 ) ; average days in a month is a smidge over 30
  69.         m_string := m_string . "Months Sober: " Floor( m_days / 30 ) . "`n"
  70.  
  71.     while m_days >= 30
  72.         m_days -= 30
  73.  
  74.     if ( m_days >= 7 )
  75.         m_string := m_string . "Weeks Sober: " Floor( m_days / 7 ) . "`n"
  76.  
  77.     while m_days >= 7
  78.         m_days -= 7
  79.  
  80.     if ( m_Days > 0 )
  81.         m_string := m_string . "Days Sober: " m_days . "`n"
  82.     else
  83.         m_string := m_string . "It's a new day!`n"
  84.  
  85.     if ( m_includetotal )
  86.         m_string := m_string . "`nTotal days sober: " m_totaldays
  87.  
  88.     GuiControl, Text, Days, %m_string%
  89.  
  90.     StringReplace, m_string, m_string, `n, `n, UseErrorLevel
  91.     height := ( ErrorLevel *= 24 ) ; 25 pixels for every 2 lines
  92.     ;width := ( m_totaldays >= 1000 ? 137 : 127 ) ; just add 10 pixels for the thousandths collumn, I don't care all that much about tens of thousands.
  93.     width := ( StrLen( m_totaldays ) >= 4 ? 127 + ( ( StrLen( m_totaldays ) - 3 ) * 8 ) : 127 ) ; I lied.
  94.  
  95.     Gui, Show, x%menu_X% y%menu_Y% h%height% w%width% NA,
  96. return
  97.  
  98. IsWhole(Number)
  99. {
  100.     return !Mod(Number, Floor(number))
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement