Toolbar Digital Clock

By pball on Dec 27, 2011

Screenshots

Firstly I'd like to give a shout out to xdesoto since his clock script gave me the idea to do this.
Secondly this script is completely different than his in all but the fact they are both digital styled clocks.

This clock appears in the toolbar and has 12/24 hour modes which can easily be toggled by clicking on the clock. To start type /clock or /clock 12 to start in 12 hour mode. The clock will start with mirc if you leave it on before closing mirc.

This script doesn't use pictures for the display unlike xdesoto's and my older one I posted in the comments of his snippet. This draws all of the characters from scratch using an alias that was simpler than I thought it'd be, lol.

Type /clockcolors to bring up the color picker. You can either type in numbers into the rgb edit boxes or use the slider. The clock will update in near real time, you'll have to wait up to a second lol. Non valid entries in the rgb edit boxes will be replaced with 0, including if you try to delete all the numbers, if you wish to change the whole number just select it and edit it.

There is an option to display the color selections in the color dialog selector. This is turned off by default since it's quite CPU intensive as it has to created picture files and load them every time the value changes.

Right clicking on the clock also shows the option to switch between 12/24 hours times and to open the color dialog.

Guess what? Yet another update.
Just trying to condense the script a bit, removed a lot of duplicate code and I'll be doing more when I can.

1-5-12
whoops used an online timer so any time you get disconnected the clock stops until you restart/toggle it, switched to offline timer which fixes that

1-6-12
updated it to sync itself with the computer time. since the timer runs every second from the time it's started which means it's up to just under a second off the computers time. Now every minute it syncs itself to the computers time.

10-21-14
Added $qt() to file paths in script to fix errors if the script's path has spaces in it.

/*
[Addon]
Script=Toolbar Clock
Version=2.8
Author=pball
Desc=Shows a digital clock in the toolbar
For=Mirc
Date=

[script]
*/
alias clock {
  set %startclock clock $1
  if (!$isfile($qt($scriptdirclock.txt))) popupfile
  if (!%clockcolors) set %clockcolors 0 255 0 11 74 19 0 0 0 0
  if (!$toolbar(clocksep)) toolbar -is clocksep
  if (!$window(@clock)) window -nBj2kpw0 +f @clock 0 0 117 23
  if (!$toolbar(clock)) toolbar -auxo clock "" @clock 0 0 $iif($1 == 12,111,82) 17
  clear @clock
  set -l %time $asctime($iif($1 == 12,hhcnncsstt,HHcnncss))
  set -l %num 1
  while ($mid(%time,%num,1) != $null) {
    if ($mid(%time,1,1) != 0) || (%num != 1) || ($1 != 12) numbers $mid(%time,%num,1) $gettok(0 12 24 29 41 53 58 70 $iif($1 == 12,87 99),%num,32)
    else numbers null 0
    inc %num
  }
  toolbar -pu clock @clock 0 0 $iif($1 == 12,111,82) 17
  toolbar -l clock "/clockchange"
  toolbar -o clock $qt($scriptdirclock.txt)
  .timerclock -mo $iif($asctime(ss) == 00,$asctime(HH:nn) 1 0,1 1000) clock $iif($1 == 12,$v1)
}

on *:start: if (%startclock) { .timerclock -o 1 1 %startclock | unset %startclock }

alias clockchange { clock $iif($timer(clock).com == clock 12,,12) }

alias clockoff {
  unset %startclock
  .timerclock off
  toolbar -d clocksep
  toolbar -d clock
  window -c @clock
}

alias -l popupfile {
  write -c $qt($scriptdirclock.txt) Switch to $($iif($timer(clock).com == clock 12,24,12),0) Hour Time: clock $($iif($timer(clock).com == clock 12,,12),0)
  write $qt($scriptdirclock.txt) $(Change Colors: if (!$dialog(clockcolors)) dialog -ma clockcolors clockcolors,0)
}

alias -l numbers {
  if ($2 == 0) drawdot -r @clock $rgb( [ $replace($gettok(%clockcolors,7-9,32),$chr(32),$chr(44)) ] ) 75 50 10
  if ($1 == c) {
    set -l %num 1
    while (%num <= 4) {
      drawline -r @clock $c2 1 $calc($2 + $gettok(1 5 11 13,%num,32)) $gettok(3 5 11 13,%num,32) $calc($2 + 4) $gettok(3 5 11 13,%num,32)
      inc %num
    }
    drawline -r @clock $c1 3 $calc($2 + 2) 4 $calc($2 + 2) 4
    drawline -r @clock $c1 3 $calc($2 + 2) 12 $calc($2 + 2) 12
    return
  }
  drawline -r @clock $iif($1 isin ap02356789,$c1,$c2) 1 $calc($2 + 2) 1 $calc($2 + 10) 1
  drawline -r @clock $iif($1 isin ap02356789,$c1,$c2) 1 $calc($2 + 3) 2 $calc($2 + 9) 2
  drawline -r @clock $iif($1 isin apm045689,$c1,$c2) 1 $calc($2 + 1) 2 $calc($2 + 1) 7
  drawline -r @clock $iif($1 isin apm045689,$c1,$c2) 1 $calc($2 + 2) 3 $calc($2 + 2) 8
  drawline -r @clock $iif($1 isin apm0268,$c1,$c2) 1 $calc($2 + 1) 10 $calc($2 + 1) 15
  drawline -r @clock $iif($1 isin apm0268,$c1,$c2) 1 $calc($2 + 2) 9 $calc($2 + 2) 14
  drawline -r @clock $iif($1 isin 023568,$c1,$c2) 1 $calc($2 + 2) 15 $calc($2 + 10) 15
  drawline -r @clock $iif($1 isin 023568,$c1,$c2) 1 $calc($2 + 3) 14 $calc($2 + 9) 14
  drawline -r @clock $iif($1 isin apm01234789,$c1,$c2) 1 $calc($2 + 10) 2 $calc($2 + 10) 7
  drawline -r @clock $iif($1 isin apm01234789,$c1,$c2) 1 $calc($2 + 9) 3 $calc($2 + 9) 8
  drawline -r @clock $iif($1 isin am013456789,$c1,$c2) 1 $calc($2 + 10) 10 $calc($2 + 10) 15
  drawline -r @clock $iif($1 isin am013456789,$c1,$c2) 1 $calc($2 + 9) 9 $calc($2 + 9) 14
  drawline -r @clock $iif($1 isin ap2345689,$c1,$c2) 3 $calc($2 + 4) 8 $calc($2 + 7) 8
  if ($1 == m) {
    set -l %num 1
    while (%num <= 6) {
      drawline -r @clock $c1 1 $calc($2 + $gettok(2 3 4 5 7 8,%num,32)) $gettok(1 2 3 4 2 1,%num,32) $calc($2 + $gettok(4 5 8 7 9 10,%num,32)) $gettok(1 2 3 4 2 1,%num,32)
      inc %num
    }
  }
}

alias c1 { return $rgb( [ $replace($gettok(%clockcolors,1-3,32),$chr(32),$chr(44)) ] ) }

alias c2 { return $rgb( [ $replace($gettok(%clockcolors,4-6,32),$chr(32),$chr(44)) ] ) }

dialog clockcolors {
  title "Clock Colors"
  size -1 -1 400 230
  option pixels
  text "Main", 3, 5 5 55 17
  icon 105, 5 25 40 40
  text "Red", 5, 70 5 34 17
  text "Green", 6, 70 25 34 17
  text "Blue", 7, 70 45 34 17
  edit "", 100, 105 5 35 20, limit 3
  edit "", 200, 105 25 35 20, limit 3
  edit "", 300, 105 45 35 20, limit 3  
  scroll "", 101, 140 5 256 16, horizontal range 1 256
  scroll "", 201, 140 25 256 16, horizontal range 1 256
  scroll "", 301, 140 45 256 16, horizontal range 1 256
  text "Secondary", 12, 5 75 55 17
  icon 405, 5 95 40 40
  text "Red", 14, 70 75 34 17
  text "Green", 15, 70 95 34 17
  text "Blue", 16, 70 115 34 17
  edit "", 400, 105 75 35 20, limit 3  
  edit "", 500, 105 95 35 20, limit 3
  edit "", 600, 105 115 35 20, limit 3
  scroll "", 401, 140 75 256 16, horizontal range 1 256
  scroll "", 501, 140 95 256 16, horizontal range 1 256
  scroll "", 601, 140 115 256 16, horizontal range 1 256
  text "Background", 23, 5 140 55 17
  icon 705, 5 160 40 40
  text "Red", 25, 70 140 34 17
  text "Green", 26, 70 160 34 17
  text "Blue", 27, 70 180 34 17
  edit "", 700, 105 140 35 20, limit 3
  edit "", 800, 105 160 35 20, limit 3
  edit "", 900, 105 180 35 20, limit 3
  scroll "", 701, 140 140 256 16, horizontal range 1 256
  scroll "", 801, 140 160 256 16, horizontal range 1 256
  scroll "", 901, 140 180 256 16, horizontal range 1 256
  check "Check for color samples to update (Warning CPU intensive)", 1, 5 205 360 17
}

alias clockcolors { if (!$dialog(clockcolors)) dialog -ma clockcolors clockcolors }

on *:dialog:clockcolors:*:*: {
  if ($devent == close) {
    set %clockcolors $did(100) $did(200) $did(300) $did(400) $did(500) $did(600) $did(700) $did(800) $did(900) $did(1).state
    .remove $qt($scriptdirclock1.bmp)
    .remove $qt($scriptdirclock2.bmp)
    .remove $qt($scriptdirclock3.bmp)
  }
  elseif ($devent == init) {
    if (!%clockcolors) set %clockcolors 0 255 0 11 74 19 0 0 0 0
    set -l %num 1
    while (%num <= 9) {
      did -a $dname %num $+ 00 $gettok(%clockcolors,%num,32)
      did -c $dname %num $+ 01 $gettok(%clockcolors,%num,32)
      inc %num
    }
    if ($gettok(%clockcolors,10,32)) did -c $dname 1 
    refreshcolors
  }
  elseif ($devent == scroll) {
    did -ra $dname $calc($did - 1) $calc($did($did).sel - 1)
    refreshcolors
  }
  elseif ($devent == edit) {
    if ($did($did) isnum 0-255) did -c $dname $calc($did + 1) $did($did)
    else did -ra $dname $did 0
    refreshcolors
  }
  elseif ($devent == sclick) {
    if ($did == 1) { did - $+ $iif($did(1).state,v,h) $dname 105,405,705 | if ($did(1).state == 1) refreshcolors }
  }
}

alias -l refreshcolors { set %clockcolors $did(100) $did(200) $did(300) $did(400) $did(500) $did(600) $did(700) $did(800) $did(900) | if ($did(1).state == 1) clockcolor }

alias -l clockcolor {
  set -l %num 1
  while (%num <= 3) {
    window -nBfj2kpw0 +f @color $+ %num 0 0 40 40
    drawdot -r @color $+ %num $rgb($gettok(%clockcolors,$calc(1 + (( %num -1)*3) ),32),$gettok(%clockcolors,$calc(2 + (( %num -1)*3) ),32),$gettok(%clockcolors,$calc(3 + (( %num -1)*3) ),32)) 120 20 20
    drawsave @color $+ %num $qt($scriptdirclock $+ %num $+ .bmp)
    window -c @color $+ %num
    did -g clockcolors $calc(1 + (( %num -1)*3) ) $+ 05 $qt($scriptdirclock $+ %num $+ .bmp)
    inc %num
  }
}

Comments

Sign in to comment.
DashRipr0ck   -  Jul 12, 2017

I FREAKIN' LOVE THIS SCRIPT!
THANK YOU

 Respond  
pball   -  Dec 29, 2011

I figure I could do a blinking colon. I just played around a bit and I'll probably be better off rewriting the parts that position stuff to make them more dynamic. So I'll be doing more updates when I get less lazy lol

 Respond  
IllogicTC   -  Dec 29, 2011

Eye-candy suggestion: For the mode where it just shows hours and minutes, have the colon separating them alternate between lit and unlit states, like a watch does.

As for one-upping with the scrollbars, I just did that because I figured it would be a bit easier for the average user to pick up and use. Slide it, and see the result immediately, rather than having to type numbers in to fine-tweak lol. Good knowledge on the did -c :D +1 for that.

 Respond  
Abcdefmonkey   -  Dec 28, 2011

Military time = 24 hour clock. Just click the toolbar for the 24-hour clock.

 Respond  
LordBotTeam   -  Dec 28, 2011

It can be great if you add some stuff so it can Be Military Time.

 Respond  
pball   -  Dec 28, 2011

I think I might start making the display more customizable. Being able to choose whether to show seconds or not, showing the date in different formats. Though I don't think I'll do day/month with letters, just numbers, since making nice looking letters would be a pain, lol.

 Respond  
TheImrac   -  Dec 27, 2011

This is nice, Great stuff!

 Respond  
Abcdefmonkey   -  Dec 27, 2011

Agreed.

 Respond  
pball   -  Dec 27, 2011

You forgot the best part of not using images, being able to dynamically choose colors

 Respond  
Abcdefmonkey   -  Dec 27, 2011

I actually like the RGB sliders posted by IllogicTC. +1 like.

As far as the initial post, I liked it as well. You posted this in another thread, but this one doesn't include image files, which helps with loading and all. +1 9/10 from me. Kudos.

 Respond  
Spoof   -  Dec 27, 2011
  • cause ... typo'd "case" sorry
 Respond  
Spoof   -  Dec 27, 2011

would be nicer if the user could custom set the location in the toolbar in cause they are running a lag bar.
But its O.K. for plain mirc's.

 Respond  
pball   -  Dec 27, 2011

Well I was just going to have a dialog with editboxes for rgb colors, but since you had to step it up I'll be doing scroll bars and the editboxes. So you can either just type in the number you like or scroll around for something.

You can use /did -c tablename id value to move scroll bars, it's not really documented but i knew one of the things for selecting stuff had to work with scroll bars.

 Respond  
IllogicTC   -  Dec 27, 2011

Very nicely done. Doing the numbers in-script rather than having to grab more files makes this much more user-friendly, very grab-n-go.

As for the colors, here's my take. It's nowhere near perfect, I'm still tinkering with it. Also I can figure out how to give a scrollbar a value when initializing a dialog... so it's bugged in a way. But works? I dunno.

alias clock {
  if (%clock.colors == $null) set %clock.colors 0 255 0
  set %startclock clock $1
  if (!$toolbar(clocksep)) toolbar -is clocksep
  if (!$window(@clock)) window -nBj2kpw0 +f @clock 0 0 117 23
  if (!$toolbar(clock)) toolbar -aux clock "" @clock 0 0 $iif($1 == 12,111,82) 17
  clear @clock
  set -l %time $asctime($iif($1 == 12,hhcnncsstt,HHcnncss))
  set -l %num 1
  while ($mid(%time,%num,1) != $null) {
    if ($mid(%time,1,1) != 0) || (%num != 1) || ($1 != 12) numbers $mid(%time,%num,1) $gettok(0 12 24 29 41 53 58 70 $iif($1 == 12,87 99),%num,32)
    inc %num
  }
  toolbar -pu clock @clock 0 0 $iif($1 == 12,111,82) 17
  toolbar -l clock "/clockchange"
  .timerclock -m 0 1000 clock $iif($1 == 12,$v1)
}
alias clockchange { clock $iif($timer(clock).com == clock 12,,12) }
alias clockoff {
  unset %startclock
  .timerclock off
  toolbar -d clocksep
  toolbar -d clock
  window -c @clock
}

on *:start: if (%startclock) { .timerclock 1 1 %startclock | unset %startclock }

alias numbers {
  var %a = $1, %b = $2
  tokenize 32 %clock.colors
  if (%i == c) {
    drawline -r @clock 1264139 1 $calc(%b + 1) 3 $calc(%b + 4) 3
    drawline -r @clock 1264139 1 $calc(%b + 1) 5 $calc(%b + 4) 5
    drawline -r @clock 1264139 1 $calc(%b + 1) 11 $calc(%b + 4) 11
    drawline -r @clock 1264139 1 $calc(%b + 1) 13 $calc(%b + 4) 13
    drawline -r @clock $rgb($1,$2,$3) 3 $calc(%b + 2) 4 $calc(%b + 2) 4
    drawline -r @clock $rgb($1,$2,$3) 3 $calc(%b + 2) 12 $calc(%b + 2) 12
    return
  }
  drawline -r @clock $iif(%a isin ap02356789,$rgb($1,$2,$3),1264139) 1 $calc(%b + 2) 1 $calc(%b + 10) 1
  drawline -r @clock $iif(%a isin ap02356789,$rgb($1,$2,$3),1264139) 1 $calc(%b + 3) 2 $calc(%b + 9) 2
  drawline -r @clock $iif(%a isin apm045689,$rgb($1,$2,$3),1264139) 1 $calc(%b + 1) 2 $calc(%b + 1) 7
  drawline -r @clock $iif(%a isin apm045689,$rgb($1,$2,$3),1264139) 1 $calc(%b + 2) 3 $calc(%b + 2) 8
  drawline -r @clock $iif(%a isin apm0268,$rgb($1,$2,$3),1264139) 1 $calc(%b + 1) 10 $calc(%b + 1) 15
  drawline -r @clock $iif(%a isin apm0268,$rgb($1,$2,$3),1264139) 1 $calc(%b + 2) 9 $calc(%b + 2) 14
  drawline -r @clock $iif(%a isin 023568,$rgb($1,$2,$3),1264139) 1 $calc(%b + 2) 15 $calc(%b + 10) 15
  drawline -r @clock $iif(%a isin 023568,$rgb($1,$2,$3),1264139) 1 $calc(%b + 3) 14 $calc(%b + 9) 14
  drawline -r @clock $iif(%a isin apm01234789,$rgb($1,$2,$3),1264139) 1 $calc(%b + 10) 2 $calc(%b + 10) 7
  drawline -r @clock $iif(%a isin apm01234789,$rgb($1,$2,$3),1264139) 1 $calc(%b + 9) 3 $calc(%b + 9) 8
  drawline -r @clock $iif(%a isin am013456789,$rgb($1,$2,$3),1264139) 1 $calc(%b + 10) 10 $calc(%b + 10) 15
  drawline -r @clock $iif(%a isin am013456789,$rgb($1,$2,$3),1264139) 1 $calc(%b + 9) 9 $calc(%b + 9) 14
  drawline -r @clock $iif(%a isin ap2345689,$rgb($1,$2,$3),1264139) 3 $calc(%b + 4) 8 $calc(%b + 7) 8
  if (%a == m) {
    tokenize 32 %clock.colors
    drawline -r @clock $rgb($1,$2,$3) 1 $calc(%b + 2) 1 $calc(%b + 4) 1
    drawline -r @clock $rgb($1,$2,$3) 1 $calc(%b + 3) 2 $calc(%b + 5) 2
    drawline -r @clock $rgb($1,$2,$3) 1 $calc(%b + 4) 3 $calc(%b + 8) 3
    drawline -r @clock $rgb($1,$2,$3) 1 $calc(%b + 5) 4 $calc(%b + 7) 4
    drawline -r @clock $rgb($1,$2,$3) 1 $calc(%b + 7) 2 $calc(%b + 9) 2
    drawline -r @clock $rgb($1,$2,$3) 1 $calc(%b + 8) 1 $calc(%b + 10) 1
  }
}

alias clockcolor { dialog -m clock_colors clock_colors }
dialog clock_colors {
  title "Clock Colors"
  size -1 -1 96 41
  option dbu
  scroll "", 1, 2 4 92 8, range 1 32 horizontal bottom
  scroll "", 2, 2 17 92 8, range 1 32 horizontal bottom
  scroll "", 3, 2 30 92 8, range 1 32 horizontal bottom
}

on *:dialog:clock_colors:*:*: {
  if ($devent == scroll) set %clock.colors $calc(($did($dname,1).sel * 8) - 1) $calc(($did($dname,2).sel * 8) - 1) $calc(($did($dname,3).sel * 8) - 1)
}

Use /clockcolors to open the color selection script. The three bars adjust the RGB values of the lit "LEDs," as you move them. There are 32 intensities for each colours channel.

Like I said, my work on custom colors needs (quite a bit) of work. You can either stem off of what I have so far here, or well use your imagination! Having customization is a love of mine, and I would like to see this script have more options in the future. ^_^

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.