All pastes #503632 Raw Edit

Sticky

public text v1 · immutable
·published 2007-05-22 23:13 UTC
rendered paste body
;;;;;;;;;;;;;;;;;;;;;;;;;;
; /sticky by poiuy_qwert ;
;;;;;;;;;;;;;;;;;;;;;;;;;;
; irc.gamesurge.net #script #eval
;;;;;;;;;;;;;;;;;;;;;;;;;;
; NOTE 1: THIS VERSION IS NOT BACKWARDS COMPATABLE
; NOTE 2: THERE IS NO ERROR CHECKING
;;;;;;;;;;;;;;;;;;;;;;;;;;
; Updates:
;  - Can now specify width and height of the sticky
;  - Multiple lines supported
;  - Sticky resizing
;  - Lots of little changes
;;;;;;;;;;;;;;;;;;;;;;;;;;
; Usage:
;  /sticky <Name> <X Y W H> <BackgroundColor> <BoarderColor> <TextColor> <Font> <FontSize> [<Title> [Text]]
;    Create a new sticky:
;      -Name is the name of the sticky
;      -X Y W H is the x/y co-ordinates and width/height of the sticky (use -1 for X and Y to center the sticky on screen)
;      -BackgroundColor is the background color of the sticky
;      -BoarderColor is the boarder color of the sticky
;      -TextColor is the color of the text in the sticky
;      -Font is the font used in the sticky
;      -FontSize is the size of the font in the sticky
;      -Title is the stickies title text. To have a title with more than one word wrap it in quotes
;      -Text is the default text for the sticky
;  /stickies
;    List the current stickies (like /socklist)
;  $stickies(N)
;    Return the Nth stickies name, if N is 0 return how many stickies there are
;  /sticky.title <Name> <Text>
;    Set the stickies title
;      -Name is the name of the sticky
;      -Text is the title text to use (No quotes are required for this)
;  /sticky.size <Name> <X Y W H>
;    Resize/reposition a sticky
;      -Name is the name of the sticky
;      -X Y W H is the position and size of the sticky (use -1 for the values to use the current value)
;  /sticky.ontop <Name>
;    Toggle on top for a sticky
;      -Name is the name of the sticky
;  $sticky.ontop(Name)
;    Return if a sticky is ontop or not
;      -Name is the name of the sticky
;  /sticky.aline <Name> <Text>
;    Add a line of text to the sticky
;      -Name is the name of the sticky
;      -Text is the text of the line
;  /sticky.dline <Name> <N>
;    Delete the Nth line in the sticky
;      -Name is the name of the sticky
;      -N is the line number
;  /sticky.iline <Name> <N> <Text>
;    Insert a line of text in the Nth position
;      -Name is the name of the sticky
;      -N is the line number
;      -Text is the text of the line
;  /sticky.rline <Name> <N> <Text>
;    Replace the Nth line of text
;      -Name is the name of the sticky
;      -N is the line number
;      -Text is the text of the line
;  $sticky.line(Name,N)
;    Return the Nth line of text
;      -Name is the name of the sticky
;      -N is the line number
;  $sticky.fline(Name,Wildtext,N[,X])
;    Return Nth position of the line that matches the wildcard
;      -Name is the name of the sticky
;      -Wildtext is the text to match on the line
;      -N is the Nth line that matches Wildtext
;      -X can be anything, if its set it means Wildtext is a regular expression
;  /sticky.close <Name>
;    Close a sticky
;      -Name is the name of the sticky (can use wildcards)
;;;;;;;;;;;;;;;;;;;;;;;;;;
; Example:
;  Run the '/teststicky' command to test stickies
;;;;;;;;;;;;;;;;;;;;;;;;;;

alias teststicky {
  sticky sticky 100 100 300 500 $rgb(50,50,255) $rgb(0,0,130) $rgb(0,0,130) Tahoma 12 "Testing title with spaces" This is a test for my /sticky snippet that is supposed to imitate the stickies that a MAC has.
  sticky.aline sticky In the top right there is a X for closing the sticky, and a box beside it to toggle on-top off or on (filled is on-top).
  sticky.aline sticky The stickies are also resizable, click and drag in the bottem right corner to do it!
  sticky.aline sticky Stickies has commands like /aline, /rline, /iline, /dline, $!line, and $!fline, just with /sticky.* before them.
  sticky.iline sticky 4
}

alias sticky {
  var %h sticky. $+ $1,%w = @ $+ %h,%a 33,%c
  window -Bpdow0 $+ $iif($2-3 == -1 -1,C) +dL %w $2-5
  window -lh @sticky.lines. $+ $1
  hadd -m %h bgcolor $6
  hadd %h bordercolor $7
  hadd %h textcolor $8
  hadd %h font $9
  hadd %h fontsize $10
  while (%a < 127) var %c = %c $+ $chr(%a),%a = %a + 1
  hadd %h textheight $height(%c,$9,$10)
  if ($11) {
    var %p $pos($11-,",2)
    if ("* iswm $11) && (%p) var %t = $noqt($left($11-,%p)),%r = $right($11-,- $+ %p)
    else var %t $11,%r $12-
    hadd %h title %t
    if (%r) aline @sticky.lines. $+ $1 %r
  }
  sticky.draw $1
}

alias stickies {
  if ($isid) && ($1 isnum) return $iif($1 == 0,$window(@sticky.lines.*,0),$gettok($window(@sticky.lines.*,$1),3-,46))
  else {
    if ($window(@sticky.lines.*,0)) {
      echo $color(info) * Open stickies:
      var %a 1
      while ($window(@sticky.lines.*,%a)) {
        var %n $gettok($v1,3-,46),%a = %a + 1
        echo $color(info2) %n $qt($hget(sticky. $+ %n,title))
      }
    }
    else echo $color(info) * No open stickies
  }
}

alias sticky.title {
  hadd sticky. $+ $1 title $2-
  sticky.draw $1
}

alias sticky.size {
  window @sticky. $+ $1-
  sticky.draw $1
}

alias sticky.ontop {
  var %o $window(@sticky. $+ $1).ontop
  if ($isid) return %o
  else {
    window $iif(%o,-u,-o) @sticky. $+ $1
    sticky.draw $1
  }
}

alias sticky.aline {
  aline @sticky.lines. $+ $1 $iif(!$2,$chr(160),$2-)
  sticky.draw $1
}

alias sticky.dline {
  dline @sticky.lines. $+ $1-2
  sticky.draw $1
}

alias sticky.iline {
  iline @sticky.lines. $+ $1-2 $iif(!$3,$chr(160),$3-)
  sticky.draw $1
}

alias sticky.rline {
  rline @sticky.lines. $+ $1-2 $iif(!$3,$chr(160),$3-)
  sticky.draw $1
}

alias sticky.line return $line(@sticky.lines. $+ $1,$2)

alias sticky.fline return $fline(@sticky.lines. $+ $1,$2,$3,$iif($4,2))

alias sticky.close {
  window -c @sticky. $+ $1
  window -c @sticky.lines. $+ $1
  hfree -w sticky. $+ $1
}

alias -l sticky.draw {
  var %h sticky. $+ $1,%w = @ $+ %h,%ww $window(%w).w,%wh $window(%w).h,%s $calc($hget(%h,textheight) +6),%t = $hget(%h,title)
  drawrect -rnf %w $hget(%h,bgcolor) 1 0 0 %ww %wh
  drawrect -rn %w $hget(%h,bordercolor) 1 0 0 %ww %wh
  drawrect -rn $+ $iif($window(%w).ontop,f) %w $hget(%h,bordercolor) 1 $calc(%ww -19) 0 10 10
  drawline -rn %w $hget(%h,bordercolor) 1 $calc(%ww -10) 0 $calc(%ww -1) 9 $calc(%ww -10) 9 $calc(%ww -1) 0
  drawline -rn %w $hget(%h,bordercolor) 1 0 %s $window(%w).w %s
  drawline -rn %w $hget(%h,bordercolor) 1 $calc(%ww -11) %wh $calc(%ww -1) $calc(%wh -10)
  if (%t) {
    if ($width(%t,$hget(%h,font),$hget(%h,fontsize)) > $calc(%ww -25)) %t = $wrap(%t,$hget(%h,font),$hget(%h,fontsize),$calc(%ww - $width(...,$hget(%h,font),$hget(%h,fontsize))-25),0,1) $+ ...
    drawtext -rn %w $hget(%h,textcolor) $hget(%h,font) $hget(%h,fontsize) 3 3 %t
  }
  var %a 1,%y = %s + 3
  while (%y < $window(%w).h) && (%a <= $line(@sticky.lines. $+ $1,0)) {
    var %b 1,%t = $line(@sticky.lines. $+ $1,%a)
    while (%y < $window(%w).h) && (%b <= $wrap(%t,$hget(%h,font),$hget(%h,fontsize),$calc(%ww -6),1,0)) {
      if ($wrap(%t,$hget(%h,font),$hget(%h,fontsize),$calc(%ww -6),1,%b)) drawtext -rn %w $hget(%h,textcolor) $hget(%h,font) $hget(%h,fontsize) 3 %y $v1
      var %y = $calc($hget(%h,textheight) +4+%y),%b = %b + 1
    }
    inc %a
  }
  drawdot %w
}

menu @sticky.* {
  sclick:sticky.sdrag $active
  mouse:sticky.mdrag $active
  drop:unset %sticky.*
  leave:if (%sticky.x) && (%sticky.y) sticky.mdrag $active
}

alias -l sticky.sdrag {
  var %w $window($1).w,%h $window($1).h
  if ($inrect($mouse.x,$mouse.y,$calc(%w -10),0,10,10)) sticky.close $gettok($1,2-,46)
  elseif ($inrect($mouse.x,$mouse.y,$calc(%w -19),0,9,10)) {
    window $iif($window($1).ontop,-u,-o) $1
    sticky.draw $gettok($1,2-,46)
  }
  else {
    if ($inrect($mouse.x,$mouse.y,$calc(%w -10),$calc(%h -10),10,10)) {
      set %sticky.size 1
      set %sticky.x $calc(%w - $mouse.x)
      set %sticky.y $calc(%h - $mouse.y)
    }
    else {
      set %sticky.x $mouse.x
      set %sticky.y $mouse.y
    }
  }
}

alias -l sticky.mdrag {
  if (%sticky.x) && (%sticky.y) {
    if ($mouse.key !& 1) unset %sticky.*
    elseif (%sticky.size) {
      var %w $iif($calc($mouse.x +%sticky.x) > 50,$v1,50),%h $iif($calc($mouse.y +%sticky.y) > 50,$v1,50)
      if (%w != $window($1).w) && (%h != $window($1).h) {
        window $1 -1 -1 %w %h
        sticky.draw $gettok($1,2-,46)
      }
    }
    else window $1 $calc($window($1).x + $mouse.x -%sticky.x) $calc($window($1).y + $mouse.y -%sticky.y)
  }
}

on *:CLOSE:@:if (@sticky.* iswm $target) sticky.close $gettok($1,2-,46)