A clock by jon (hellish) — File Browser

Aclockbyjonhellishv1.0 / Aclockbyjonhellishv1.0 / challenge_clock.mrc

challenge_clock.mrc — 17.85 KB — Download this file

alias clock {
  if ($window(@Clock)) {
    set_window_pos @Clock | settings analog_running 0 | unset %analog_clock.* | window -c @Clock
    return
  }
  reset_defaults
  window -pk +f @Clock $settings(analog_x) $settings(analog_y) $settings(analog_w) $settings(analog_h) @Clock
  draw_full_points @Clock | update_hands @Clock | drawdot @Clock
  settings analog_running 1
}

on *:CLOSE:@Clock:set_window_pos @Clock | unset %analog_clock.*
on *:LOAD:if ($version < 5.8) { echo -a * Requires mIRC 5.8 or above | unload -rs $script | return } | show_preferences
on *:START:if ($settings(analog_running)) clock

alias -l analog_controls_remove {
  drawline -n $1 $settings(analog_color_background) 1 $calc($2 - 8) $calc($3 - 15) $calc($2 - 8) $calc($3 - 8) $calc($2 - 15) $calc($3 - 8) $calc($2 - 8) $calc($3 - 15)
}
alias -l analog_controls_add {
  drawline -n $1 $settings(analog_color_controls) 1 $calc($2 - 8) $calc($3 - 15) $calc($2 - 8) $calc($3 - 8) $calc($2 - 15) $calc($3 - 8) $calc($2 - 8) $calc($3 - 15)
}
alias -l begin_moving {
  .timer 1 0 move_window $1 $window($1).x $window($1).y $mouse.dx $mouse.dy
}
alias -l begin_resizing {
  .timer 1 0 resize_window $1 $window($1).x $window($1).y $window($1).w $window($1).h $mouse.dx $mouse.dy
  drawrect -nf $1 $settings(analog_color_background) 1 0 0 $window($1).w $window($1).h
  draw_part_points $1
  analog_controls_add $1 $window($1).w $window($1).h
  drawdot $1
  %analog_clock.resizing = 1
}
alias -l change_color {
  var %a = $$dialog(choose_color,choose_color,-3)
  did -g $1 $2 clock_color $+ %a $+ .bmp
  did -o $1 $calc($2 + 10) 1 %a 
}
alias -l draw_full_points {
  var %a = 1,%x = $calc($window($1).w - 6) / 2),%y = $calc(($window($1).h - 6) / 2),%w = $calc(($window($1).w - 6 - 8) / 2 - $settings(analog_label_hours)),%h = $calc(($window($1).h - 6 - 8) / 2 - $settings(analog_label_hours))
  var %s = $settings(analog_show_minute_dots),%hr = $settings(analog_color_hour_dots),%mn = $settings(analog_color_minute_dots)
  var %win = $1,%lab = $settings(analog_label_hours)
  while (%a < 61) {
    if (($right(%a,1) == 0) || ($right(%a,1) == 5)) || (%s) drawdot -n %win $iif($right(%a,1) == 0 || $right(%a,1) == 5,%hr,%mn) 1 $min2coord(%a,%w,%h,%x,%y)
    if ($right(%a,1) == 0) || ($right(%a,1) == 5) {
      var %l = $calc(%a / 5)
      tokenize 32 $min2coord(%a,$calc(%w + 7),$calc(%h + 7),%x,%y)
      if (%lab) drawtext -n %win $settings(analog_color_labels) arial 12 $calc($1 - $width(%l,arial,12) / 2 + 1) $calc($2 - 5) %l
    }
    inc %a
  } 
}
alias -l draw_part_points {
  var %a = 6,%x = $calc(($window($1).w - 6) / 2),%y = $calc(($window($1).h - 6) / 2),%w = $calc(($window($1).w - 6 - 8) / 2 - $settings(analog_label_hours)),%h = $calc(($window($1).h - 6 - 8) / 2 - $settings(analog_label_hours))
  var %win = $1,%lab = $settings(analog_label_hours)
  while (%a < 62) {
    drawdot -n %win $settings(analog_color_hour_dots) 1 $min2coord($calc(%a - 1),%w,%h,%x,%y)
    var %l = $calc((%a - 1) / 5)
    tokenize 32 $min2coord($calc(%a - 1),$calc(%w + 7),$calc(%h + 7),%x,%y)
    if (%lab) drawtext -n %win $settings(analog_color_labels) arial 12 $calc($1 - $width(%l,arial,12) / 2 + 1) $calc($2 - 5) %l
    inc %a 5
  } 
}
alias -l move_window {
  if ($mouse.key !& 1) return
  var %x = $calc($2 + $mouse.dx - $4),%y = $calc($3 + $mouse.dy - $5)
  if (%x < $settings(analog_lock_actual)) %x = 0
  if (%y < $settings(analog_lock_actual)) %y = 0
  if (%x > $calc($window(-3).w - $window($1).w - $settings(analog_lock_actual))) %x = $calc($window(-3).w - $window($1).w)
  if (%y > $calc($window(-3).h - $window($1).h - $settings(analog_lock_actual))) %y = $calc($window(-3).h - $window($1).h)
  window $1 %x %y
  .timer 1 0 move_window $1-
}
alias -l reset_defaults {
  if ($settings(analog_color_background) == $null) settings analog_color_background 0
  if ($settings(analog_color_controls) == $null) settings analog_color_controls 1
  if ($settings(analog_color_hour_dots) == $null) settings analog_color_hour_dots 1
  if ($settings(analog_color_minute_dots) == $null) settings analog_color_minute_dots 15
  if ($settings(analog_color_hour_hand) == $null) settings analog_color_hour_hand 1
  if ($settings(analog_color_minute_hand) == $null) settings analog_color_minute_hand 1
  if ($settings(analog_color_second_hand) == $null) settings analog_color_second_hand 1
  if ($settings(analog_color_labels) == $null) settings analog_color_labels 1

  if ($settings(analog_show_hour) == $null) settings analog_show_hour 1
  if ($settings(analog_show_minute) == $null) settings analog_show_minute 1
  if ($settings(analog_show_second) == $null) settings analog_show_second 1
  if ($settings(analog_show_minute_dots) == $null) settings analog_show_minute_dots 1
  if ($settings(analog_label_hours) == $null) settings analog_label_hours 8

  if ($settings(analog_hour_perc) == $null) settings analog_hour_perc 60
  if ($settings(analog_minute_perc) == $null) settings analog_minute_perc 100
  if ($settings(analog_second_perc) == $null) settings analog_second_perc 100

  if ($settings(analog_lock) == $null) settings analog_lock 1
  if ($settings(analog_lock_visible) == $null) settings analog_lock_visible 10
  if ($settings(analog_lock_actual) == $null) settings analog_lock_actual 10
  if ($settings(analog_running) == $null) settings analog_running 0

  if ($settings(analog_x) == $null) settings analog_x -1
  if ($settings(analog_y) == $null) settings analog_y -1
  if ($settings(analog_w) == $null) settings analog_w 200
  if ($settings(analog_h) == $null) settings analog_h 200
}
alias -l resize_window {
  var %x = $2,%y = $3,%w = $calc($4 + $mouse.dx - $6),%h = $calc($5 + $mouse.dy - $7),%w2 = $window($1).w,%h2 = $window($1).h
  if ($mouse.key !& 1) return
  if ($mouse.key & 2) || ($mouse.key & 4) {
    if (%w > %h) %h = %w
    else %w = %h
  }
  if (%w < 60) %w = 60
  if (%h < 60) %h = 60
  if ($calc(%x + %w) > $window(-3).w) %w = $window(-3).w - %x
  if ($calc(%y + %h) > $window(-3).h) %h = $window(-3).h - %y
  window $1 %x %y %w %h
  drawrect -nf $1 $settings(analog_color_background) 1 0 0 %w2 %h2
  analog_controls_add $1 %w %h
  draw_part_points $1
  var %wh = %w $+ x $+ %h,%x2 = %w2 / 2,%y2 = %h2 / 2
  drawtext -n $1 1 arial 12 $calc(%x2 - $width(%wh,arial,12) / 2 - 2) $calc(%y2 - $height(%wh,arial,12) / 2 - 3) %wh
  .timer 1 0 resize_window $1-
  drawdot $1
}
alias -l settings {
  if ($isid) return $readini $scriptdir $+ clock_settings.ini clock $1
  else { 
    writeini $scriptdir $+ clock_settings.ini clock $1-
  }
}
alias -l set_window_pos {
  settings analog_x $window($1).x
  settings analog_y $window($1).y
  settings analog_w $window($1).w
  settings analog_h $window($1).h
}
alias -l show_preferences {
  if ($dialog(clock_preferences) == $null) {
    create_color_bmps
    dialog -m clock_preferences clock_preferences
  }
  else dialog -v clock_preferences
}
alias -l square_analog {
  var %a = $width_or_height($1),%x = $window($1).x,%y = $window($1).y,%w = $window($1).w,%h = $window($1).h
  if ($calc(%x + %a) > $window(-3).w) %x = $window(-3).w - %a
  if ($calc(%y + %a) > $window(-3).h) %y = $window(-3).h - %a
  window $1 %x %y %a %a
  drawrect -nf $1 $settings(analog_color_background) 1 0 0 %w %h
  analog_controls_add $1 %a %a
  draw_full_points $1
  update_hands_once $1
  drawdot $1
}
alias -l unload_clock {
  if ($?!="Would you like to clean up clock settings?") && ($exists( [ $scriptdir [ $+ [ clock_settings.ini ] ] ] )) .remove $scriptdir $+ clock_settings.ini
  if ($window(@Clock) != $null) clock
  .timerupdate_hands off
  echo -a * Unloaded clock
  .unload -rs $script
}
alias -l update_hands {
  if ($window($1) == $null) return
  if (%analog_clock.resizing == $null) { update_hands_once $1 | drawdot $1 }
  .timerupdate_hands 1 1 update_hands $1
}
alias -l update_hands_once {
  var %x = $calc(($window($1).w - 6) / 2),%y = $calc(($window($1).h - 6) / 2),%w = $calc(($window($1).w - 6 - 8) / 2 - $settings(analog_label_hours)),%h = $calc(($window($1).h - 6 - 8) / 2 - $settings(analog_label_hours))
  var %b = $settings(analog_color_background)
  var %hr = $asctime(h),%mn = $asctime(n),%sc = $asctime(s),%hr = $calc(%hr * 5 + %mn / 12 + %sc / 720),%mn = $calc(%mn + %sc / 60)
  var %hp = $settings(analog_hour_perc) / 100,%mp = $settings(analog_minute_perc) / 100,%sp = $settings(analog_second_perc) / 100
  if (%analog_clock.current_hour != $null) && ((%analog_clock.current_hour != %hr) || (%analog_clock.current_hour_perc != %hp)) drawline -n $1 %b 1 %x %y $min2coord(%analog_clock.current_hour,$calc(%w * %analog_clock.current_hour_perc),$calc(%h * %analog_clock.current_hour_perc),%x,%y)
  if (%analog_clock.current_minute != $null) && ((%analog_clock.current_minute != %mn) || (%analog_clock.current_minute_perc != %mp)) drawline -n $1 %b 1 %x %y $min2coord(%analog_clock.current_minute,$calc(%w * %analog_clock.current_minute_perc),$calc(%h * %analog_clock.current_minute_perc),%x,%y)
  if (%analog_clock.current_second != $null) && ((%analog_clock.current_second != %sc) || (%analog_clock.current_second_perc != %sp)) drawline -n $1 %b 1 %x %y $min2coord(%analog_clock.current_second,$calc(%w * %analog_clock.current_second_perc),$calc(%h * %analog_clock.current_second_perc),%x,%y)
  if ($settings(analog_show_hour)) && ((%analog_clock.current_hour != %hr) || (%analog_clock.current_hour_perc != %hp)) drawline -n $1 $settings(analog_color_hour_hand) 1 %x %y $min2coord(%hr,$calc(%w * %hp),$calc(%h * %hp),%x,%y)
  if ($settings(analog_show_minute)) && ((%analog_clock.current_minute != %mn) || (%analog_clock.current_minute_perc != %mp)) drawline -n $1 $settings(analog_color_minute_hand) 1 %x %y $min2coord(%mn,$calc(%w * %mp),$calc(%h * %mp),%x,%y)
  if ($settings(analog_show_second)) && ((%analog_clock.current_second != %sc) || (%analog_clock.current_second_perc != %sp)) drawline -n $1 $settings(analog_color_second_hand) 1 %x %y $min2coord(%sc,$calc(%w * %sp),$calc(%h * %sp),%x,%y)
  %analog_clock.current_hour = %hr
  %analog_clock.current_minute = %mn
  %analog_clock.current_second = %sc
  %analog_clock.current_hour_perc = %hp
  %analog_clock.current_minute_perc = %mp
  %analog_clock.current_second_perc = %sp
}

menu @Clock {
  sclick: {
    if ($inrect($mouse.x,$mouse.y,$calc($window($active).w - 16),$calc($window($active).h - 16),10,20)) begin_resizing $active
    else begin_moving @Clock
  }
  dclick:show_preferences
  uclick: {
    if (%analog_clock.resizing) {
      drawrect -nf $active $settings(analog_color_background) 1 0 0 $window($active).w $window($active).h
      draw_full_points $active
      update_hands_once $active
      unset %analog_clock.resizing
      drawdot $active
    }
  }
  mouse: {
    if (%clock.analog_controls == $null) {
      %clock.analog_controls = 1
      analog_controls_add $active $window($active).w $window($active).h
      drawdot $active
    }
  }
  leave: {
    if ($mouse.key !& 1) {
      unset %clock.analog_controls
      analog_controls_remove $mouse.win $window($mouse.win).w $window($mouse.win).h
      drawdot $mouse.win
    }
  }
  Preferences...:show_preferences
  $iif($window($active).w != $window($active).h, [ Size to $width_or_height($active) $+ x $+ [ $width_or_height($active) ] ] ):square_analog $active
  -
  Close clock:set_window_pos $active | settings analog_running 0 | unset %analog_clock.* | window -c $active
}

menu menubar {
  Clock
  .$iif($window(@Clock),Close,Launch) analog clock:clock
  .-
  .Preferences...:show_preferences
  .Unload:if ($?!="Are you sure you wish to unload?") unload_clock
}

;$min2coord(<minute>,<x radius>,<y radius>,<x center>,<y center>)
;Convert 0-59 to 0-354, offset the angle to position 0 at the top, convert to radians
alias -l min2coord {
  var %x = $calc(($1 * 6 - 90) * 0.01745)
  return $calc($cos(%x) * $2 + $4) $calc($sin(%x) * $3 + $5)
}
alias -l width_or_height return $iif($window($1).w > $window($1).h,$window($1).w,$window($1).h)

dialog clock_preferences {
  title "Clock preferences"
  size -1 -1 270 275

  icon 61,245 9 18 16,clock_color0.bmp
  icon 62,245 29 18 16,clock_color0.bmp
  icon 63,245 49 18 16,clock_color0.bmp
  icon 64,245 84 18 16,clock_color0.bmp
  icon 65,245 104 18 16,clock_color0.bmp
  icon 66,245 124 18 16,clock_color0.bmp
  icon 67,245 159 18 16,clock_color0.bmp
  icon 68,245 179 18 16,clock_color0.bmp

  check "Hour hand",1,5 10 120 14
  check "Minute hand",2,5 30 120 14
  check "Second hand",3,5 50 120 14

  edit "",11,140 7 30 21,right
  edit "",12,140 27 30 21,right
  edit "",13,140 47 30 21,right

  text "% of length",21,170 10 55 14
  text "% of length",22,170 30 55 14
  text "% of length",23,170 50 55 14

  text "Dots marking the hour",31,5 85 230 14
  check "Label dots marking the hour",32,5 105 230 14
  check "Show other dots",33,5 125 230 14

  text "Background",41,5 160 230 14
  text "Resize button",42,5 180 230 14

  check "Snap to edge at",51,5 215 100 14
  edit "",52,103 212 22 21,
  text "pixels",53,127 215 40 14

  edit "",71,225 9 28 22,hide
  edit "",72,225 29 28 22,hide
  edit "",73,225 49 28 22,hide
  edit "",74,225 84 28 22,hide
  edit "",75,225 104 28 22,hide
  edit "",76,225 159 28 22,hide
  edit "",77,225 179 28 22,hide
  edit "",78,225 199 28 22,hide

  button "Ok",101,30 243 75 22,ok 
  button "Cancel",102,110 243 75 22,cancel
  button "Apply",103,190 243 75 22
}
on *:dialog:clock_preferences:edit:*: {
  if ($did isnum 11-13) {
    if ($did($did).text > 100) did -o $dname $did 1 100
    if ($did($did).text < 0) did -o $dname $did 1 0
  }
}
on *:dialog:clock_preferences:init:*: {
  reset_defaults
  if ($settings(analog_show_hour)) did -c $dname 1
  if ($settings(analog_show_minute)) did -c $dname 2
  if ($settings(analog_show_second)) did -c $dname 3
  did -o $dname 11 1 $settings(analog_hour_perc)
  did -o $dname 12 1 $settings(analog_minute_perc)
  did -o $dname 13 1 $settings(analog_second_perc)
  did -g $dname 61 clock_color $+ $settings(analog_color_hour_hand) $+ .bmp
  did -a $dname 71 $settings(analog_color_hour_hand)
  did -g $dname 62 clock_color $+ $settings(analog_color_minute_hand) $+ .bmp
  did -a $dname 72 $settings(analog_color_minute_hand)
  did -g $dname 63 clock_color $+ $settings(analog_color_second_hand) $+ .bmp
  did -a $dname 73 $settings(analog_color_second_hand)
  did -g $dname 64 clock_color $+ $settings(analog_color_hour_dots) $+ .bmp
  did -a $dname 74 $settings(analog_color_hour_dots)
  if ($settings(analog_label_hours)) did -c $dname 32
  did -g $dname 65 clock_color $+ $settings(analog_color_labels) $+ .bmp
  did -a $dname 75 $settings(analog_color_labels)
  if ($settings(analog_show_minute_dots)) did -c $dname 33
  did -g $dname 66 clock_color $+ $settings(analog_color_minute_dots) $+ .bmp
  did -a $dname 76 $settings(analog_color_minute_dots)
  did -g $dname 67 clock_color $+ $settings(analog_color_background) $+ .bmp
  did -a $dname 77 $settings(analog_color_background)
  did -g $dname 68 clock_color $+ $settings(analog_color_controls) $+ .bmp
  did -a $dname 78 $settings(analog_color_controls)
  if ($settings(analog_lock)) did -c $dname 51
  did -o $dname 52 1 $settings(analog_lock_visible)
}
on *:dialog:clock_preferences:sclick:*: {
  if ($did isnum 1-3) && ($did(1).state == 0) && ($did(2).state == 0) && ($did(3).state == 0) did -c $dname $did
  if ($did isnum 61-68) .timer -m 1 1 change_color $dname $did
  if ($did == 101) || ($did == 103) {
    if ($did == 101) remove_color_bmps
    settings analog_show_hour $did(1).state
    settings analog_show_minute $did(2).state
    settings analog_show_second $did(3).state
    settings analog_hour_perc $did(11)
    settings analog_minute_perc $did(12)
    settings analog_second_perc $did(13)
    settings analog_label_hours $iif($did(32).state,8,0)
    settings analog_show_minute_dots $did(33).state
    settings analog_lock $did(51).state
    settings analog_lock_visible $did(52)
    if ($did(51).state) settings analog_lock_actual $did(52)
    else settings analog_lock_actual 0
    settings analog_color_hour_hand $did(71)
    settings analog_color_minute_hand $did(72)
    settings analog_color_second_hand $did(73)
    settings analog_color_hour_dots $did(74)
    settings analog_color_labels $did(75)
    settings analog_color_minute_dots $did(76)
    settings analog_color_background $did(77)
    settings analog_color_controls $did(78)
    if ($window(@Clock)) {
      drawrect -nf @Clock $settings(analog_color_background) 1 0 0 $window(@Clock).w $window(@Clock).h
      draw_full_points @Clock
      update_hands_once @Clock
      drawdot @Clock
    }
  }
  if ($did == 102) remove_color_bmps
}

dialog choose_color {
  title "Choose a color"
  size -1 -1 206 84

  icon 1,5 5 20 20,clock_color0.bmp
  icon 2,30 5 20 20,clock_color1.bmp
  icon 3,55 5 20 20,clock_color2.bmp
  icon 4,80 5 20 20,clock_color3.bmp
  icon 5,105 5 20 20,clock_color4.bmp
  icon 6,130 5 20 20,clock_color5.bmp
  icon 7,155 5 20 20,clock_color6.bmp
  icon 8,180 5 20 20,clock_color7.bmp
  icon 9,5 30 20 20,clock_color8.bmp
  icon 10,30 30 20 20,clock_color9.bmp
  icon 11,55 30 20 20,clock_color10.bmp
  icon 12,80 30 20 20,clock_color11.bmp
  icon 13,105 30 20 20,clock_color12.bmp
  icon 14,130 30 20 20,clock_color13.bmp
  icon 15,155 30 20 20,clock_color14.bmp
  icon 16,180 30 20 20,clock_color15.bmp

  button "",20,0 0 0 0,ok
  button "Cancel",21,43 56 120 24,cancel
  edit "",30,0 0 100 24,hide result
}
on *:dialog:choose_color:sclick:*: {
  if ($did isnum 1-16) { did -o $dname 30 1 $calc($did - 1) | dialog -k $dname }
}

alias create_color_bmps {
  var %a = 0
  while (%a < 16) {
    window -fph +d @clock_color $+ %a -1 -1 21 20
    drawrect -f @clock_color $+ %a %a 1 0 0 21 20
    drawsave @clock_color $+ %a clock_color $+ %a $+ .bmp
    window -c @clock_color $+ %a
    inc %a
  }
}
alias remove_color_bmps {
  var %a = 0
  while (%a < 16) {
    .remove clock_color $+ %a $+ .bmp
    inc %a
  }
}