Autore: bull
Data: 28/02/2018
Linguaggio: mIRC Scripting
Descrizione: xpallette by SReject
  1. /*
  2. To do:
  3. - Better window positioning algro
  4. - insert color codes around selected text
  5. */
  6.  
  7. /*
  8. ---------------------------
  9. Customizable Settings
  10.  
  11. Edit these values to alter
  12. aspects of the pallette's
  13. display
  14. ---------------------------
  15. */
  16. ;; Hot key to display the pallette
  17. ;alias f2 xpallette
  18.  
  19. ;; Number of pixels of seperation between the window's border and cells within the pallette
  20. ;; default: 4
  21. alias -l windowmargin return 4
  22.  
  23. ;; The gap between color index 0-15, bold, italic, underline, reverse & clear buttons and the static pallette
  24. ;; default: 4
  25. alias -l pallettegap return 4
  26.  
  27. ;; If set to false, cells will not have a border
  28. ;; default: $true
  29. alias -l cellborder return $true
  30.  
  31. ;; The size of each cell, including border when applicable
  32. ;; default: 18
  33. alias -l cellsize return 18
  34.  
  35. ;; The spacing between each cell not including cell borders
  36. ;; default: 2
  37. alias -l cellspacing return 2
  38.  
  39. ;; The font to use when displaying color indexes within a cell
  40. ;; default: Arial
  41. alias -l cellfont return Arial
  42.  
  43. ;; The font size to use when displaying color indexes within a cell
  44. ;; default: 12
  45. alias -l cellfontsize return 12
  46.  
  47. ;; If true, the font used when displaying color indexes within a cell will be bold
  48. ;; default: $true
  49. alias -l cellfontbold return $true
  50.  
  51. /*
  52. ---------------------------
  53. Customizable Draw Settings end
  54. ---------------------------
  55. */
  56.  
  57. alias xpallette {
  58.   if (!$window(@xpallette)) {
  59.     xpallette.redraw
  60.   }
  61.   elseif (!$timer(xpallette)) {
  62.     .timerxpallette -m 1 50 xpallette.redraw
  63.   }
  64. }
  65. on *:LOAD:{
  66.   if ($window(@xpallette)) {
  67.     xpallette.redraw
  68.   }
  69. }
  70. on *:ACTIVE:*:{
  71.   if ($lactive == @xpallette) {
  72.     cleanup
  73.   }
  74. }
  75. on *:APPACTIVE:cleanup
  76. on *:UNLOAD:cleanup
  77. on *:KEYDOWN:@xpallette:*:{
  78.  
  79.  
  80.  
  81.   ;; todo: insert character into $lactive editbox
  82.  
  83.  
  84.  
  85.   cleanup
  86. }
  87. menu @xpallette {
  88.   mouse: .timerxpallette -m 1 10 xpallette.redraw
  89.   leave: .timerxpallette -m 1 10 xpallette.redraw
  90.   sclick: clicked
  91.   dclick: dclicked
  92. }
  93. alias xpallette.redraw {
  94.   var %i, %x, %y, %n, %c, %fx, %fy, %o
  95.   var %win        = @xpallette
  96.   var %win.parent = $iif($active === @xpallette, $lactive, $active)
  97.   var %win.width  = $calc(4 + ($windowmargin * 2) + (( $cellsize + $cellspacing ) * 11 + $cellsize) )
  98.   var %win.height = $calc(4 + ($windowmargin * 2) + ($cellsize * 2 + $cellspacing) + $pallettegap + ($cellsize * 7 + $cellspacing * 6) )
  99.   var %win.xpos   = $window(%win.parent).dx + 15
  100.   var %win.ypos   = $calc( ( $window(%win.parent).dy + $window(%win.parent).h) - %win.height - 40)
  101.   var %cell.pad   = $cellsize + $cellspacing
  102.   var %cell.inner = $iif($cellborder, $calc($cellsize -2), $cellsize)
  103.   if (!$window(%win) || $window(%win).bw !== %win.width || $window(%win).bh !== %win.height) {
  104.     close -@ %win
  105.     window -Bdk0opw0 +dL %win %win.xpos %win.ypos %win.width %win.height
  106.     drawsize %win %win.width %win.height
  107.   }
  108.   elseif (%win.xpos !== $window(%win).dx || %win.ypos !== $window(%win).dy) {
  109.     window %win %win.xpos %win.ypos
  110.   }
  111.   drawrect -fnr %win $rgb(240,240,240) 1 0 0 $window(%win).bw $window(%win).bh
  112.   drawline -nr %win $rgb(227,227,227) 1 0 0 %win.width 0
  113.   drawline -nr %win $rgb(227,227,227) 1 0 0 0 %win.height
  114.   drawline -nr %win $rgb(105,105,105) 1 $calc(%win.width -1) 0 $calc(%win.width -1) %win.height
  115.   drawline -nr %win $rgb(105,105,105) 1 0 $calc(%win.height -1) %win.width $calc(%win.height -1)
  116.   drawline -nr %win $rgb(255,255,255) 1 1 1 $calc(%win.width -1) 1
  117.   drawline -nr %win $rgb(255,255,255) 1 1 1 1 $calc(%win.height -1)
  118.   drawline -nr %win $rgb(160,160,160) 1 $calc(%win.width -2) 1 $calc(%win.width -2) $calc(%win.height -1)
  119.   drawline -nr %win $rgb(160,160,160) 1 1 $calc(%win.height -2) $calc(%win.width -2) $calc(%win.height -2)
  120.   %i = 0
  121.   while (%i < 5) {
  122.     %n = %i
  123.     %y = $floor($calc(%n / 3))
  124.     %x = $calc(2 + $windowmargin + (%cell.pad * 9) + ((%n - 3 * %y) * %cell.pad))
  125.     %y = $calc(2 + $windowmargin + %cell.pad * %y)
  126.     if (%i == 0) {
  127.       %n = $floor($calc( ( $cellsize - $width(B, $cellfont, $cellfontsize, 1) ) / 2))
  128.       %fx = %x + %n
  129.       %n = $floor($calc( ( $cellsize - $height(B, $cellfont, $cellfontsize) ) / 2 ))
  130.       %fy = %y + %n
  131.       drawtext -nor %win $color(88) $qt($cellfont) $cellfontsize %fx %fy B
  132.  
  133.     }
  134.     elseif (%i == 1) {
  135.       %n = $floor($calc( ( $cellsize - $width(I, $cellfont, $cellfontsize, 0) ) / 2 ))
  136.       %fx = %x + %n
  137.       %n = $floor($calc( ( $cellsize - $height(I, $cellfont, $cellfontsize) ) / 2 ))
  138.       %fy = %y + %n
  139.       drawtext -npr %win $color(88) $qt($cellfont) $cellfontsize %fx %fy I
  140.  
  141.     }
  142.     elseif (%i == 2) {
  143.       %n = $floor($calc( ( $cellsize - $width(O, $cellfont, $cellfontsize, 0) ) / 2 ))
  144.       %fx = %x + %n
  145.       %n = $floor($calc( ( $cellsize - $height(O, $cellfont, $cellfontsize) ) / 2 ))
  146.       %fy = %y + %n
  147.       drawtext -nr %win $color(88) $qt($cellfont) $cellfontsize %fx %fy O
  148.     }
  149.     elseif (%i == 3) {
  150.       %n = $floor($calc( ( $cellsize - $width(U, $cellfont, $cellfontsize, 0) ) / 2 ))
  151.       %fx = %x + %n
  152.       %n = $floor($calc( ( $cellsize - $height(U, $cellfont, $cellfontsize) ) / 2 ))
  153.       %fy = %y + %n
  154.       drawtext -npr %win $color(88) $qt($cellfont) $cellfontsize %fx %fy U
  155.     }
  156.     else {
  157.       %n = $floor($calc( ( $cellsize - $width(R, $cellfont, $cellfontsize, 0) ) / 2 ))
  158.       %fx = %x + %n
  159.       %n = $floor($calc( ( $cellsize - $height(R, $cellfont, $cellfontsize) ) / 2 ))
  160.       %fy = %y + %n
  161.       drawtext -nr %win $color(88) $qt($cellfont) $cellfontsize %fx %fy R
  162.       %n = $iif($cellborder, $calc($cellsize -2), $cellsize)
  163.       drawcopy -n %win $calc(%x +1) $calc(%y +1) %n %n %win $calc(%x + %n) $calc(%y + 1) $+(-, %n) %n
  164.     }
  165.     if ($inrect($mouse.x, $mouse.y, %x, %y, $cellsize, $cellsize)) {
  166.       drawrect -nr %win 0 1 %x %y $cellsize $cellsize
  167.     }
  168.     elseif ($cellborder) {
  169.       drawline -nr %win $rgb(255,255,255) 1 %x %y $calc(%x + $cellsize) %y
  170.       drawline -nr %win $rgb(255,255,255) 1 %x %y %x $calc(%y + $cellsize)
  171.       drawline -nr %win $rgb(160,160,160) 1 $calc(%x + $cellsize -1) %y $calc(%x + $cellsize -1) $calc(%y + $cellsize)
  172.       drawline -nr %win $rgb(160,160,160) 1 %x $calc(%y + $cellsize -1) $calc(%x + $cellsize) $calc(%y + $cellsize -1)  
  173.     }
  174.     inc %i
  175.   }
  176.   %i = 0
  177.   while (%i < 100) {
  178.     if (%i < 16) {
  179.       %n = %i
  180.       %y = $floor($calc(%n / 8))
  181.       %x = $calc(%n - %y * 8)
  182.       %x = $calc(2 + $windowmargin + %x * %cell.pad)
  183.       %y = $calc(2 + $windowmargin + %y * %cell.pad)
  184.     }
  185.     else {
  186.       %n = %i - 16
  187.       %y = $floor($calc(%n / 12))
  188.       %x = $calc(%n - %y * 12)
  189.       %x = $calc(2 + $windowmargin + %x * %cell.pad)
  190.       %y = $calc(2 + $windowmargin + ( $cellsize *2 + $cellspacing ) + $pallettegap + %y * %cell.pad)
  191.     }
  192.     if (%i == 99) {
  193.       %o = $floor($calc($cellsize /2))
  194.       drawrect -nfr %win $color(98) 1 %x %y $cellsize $cellsize
  195.       drawrect -nfr %win $color(96) 1 %x %y %o %o
  196.       drawrect -nfr %win $color(96) 1 $calc(%x + %o) $calc(%y + %o) $calc($cellsize - %o) $calc($cellsize - %o)
  197.     }
  198.     else {
  199.       drawrect -nfr %win $color(%i) 1 %x %y $cellsize $cellsize
  200.     }
  201.     if ($inrect($mouse.x, $mouse.y, %x, %y, $cellsize, $cellsize)) {
  202.       %c = $iif(0.179 < $lum(%i), 0, $rgb(255,255,255))
  203.       drawrect -nr %win %c 1 %x %y $cellsize $cellsize
  204.       %n = $floor($calc( ( $cellsize - $width($base(%i, 10, 10, 2), $cellfont, $cellfontsize, $iif($cellfontbold,1,0)) ) / 2 ))
  205.       %x = $iif(%n < 0, %x, $calc(%x + %n))
  206.       %n = $floor($calc( ( $cellsize - $height($base(%i, 10, 10, 2), $cellfont, $cellfontsize) ) / 2 ))
  207.       %y = $iif(%n < 0, %y, $calc(%y + %n))
  208.       drawtext $iif($cellfontbold, -nor, -nr) %win %c $qt($cellfont) $cellfontsize %x %y $base(%i, 10, 10, 2)
  209.     }
  210.     elseif ($cellborder) {
  211.       drawline -nr %win $rgb(160,160,160) 1 %x %y $calc(%x + $cellsize) %y
  212.       drawline -nr %win $rgb(160,160,160) 1 %x %y %x $calc(%y + $cellsize)
  213.       drawline -nr %win $rgb(255,255,255) 1 $calc(%x + $cellsize -1) %y $calc(%x + $cellsize -1) $calc(%y + $cellsize)
  214.       drawline -nr %win $rgb(255,255,255) 1 %x $calc(%y + $cellsize -1) $calc(%x + $cellsize) $calc(%y + $cellsize -1)  
  215.     }
  216.     inc %i
  217.   }
  218.   drawdot %win
  219. }
  220. alias -l Lum {
  221.   tokenize 44 $rgb($color($1))
  222.   return $calc(0.2126 * $brightness($1) + 0.7152 * $brightness($2) + 0.0722* $brightness($3))
  223. }
  224. alias -l brightness {
  225.   var %res = $1 / 255
  226.   return $iif(%res <= 0.03928, $calc(%res / 12.92), $calc((( %res + 0.055) / 1.055) ^ 2.4))
  227. }
  228. alias -l clicked {
  229.   if ($mouse.key !& 1 || $mouse.key & 16 || $mouse.key & 2 || $mouse.key & 8 || !$inrect($mouse.x, $mouse.y, $calc($windowmargin +3), $calc($windowmargin +3), $calc($window(@xpallette).bw - 2 - $windowmargin), $calc($window(@xpallette).bw - 2 - $windowmargin))) {
  230.     unset %xpallette.sclicked
  231.     return
  232.   }
  233.   unset %xpallette.sclicked
  234.   var %win = @xpallette
  235.   var %pad = $cellsize + $cellspacing
  236.   var %mx  = $calc($mouse.x - 2 - $windowmargin)
  237.   var %my  = $calc($mouse.y - 2 - $windowmargin)
  238.   var %yo
  239.   var %xo
  240.   var %cc
  241.   var %eb.txt = $editbox($lactive)
  242.   var %eb.swt = -
  243.   var %eb.tar = $lactive
  244.   var %eb.sst = $editbox($lactive).selstart
  245.   var %eb.end = $editbox($lactive).selend
  246.   var %eb.pre = $left(%eb.txt, $calc(%eb.sst -1))
  247.   var %eb.sel = $mid(%eb.txt, %eb.stl, $calc(%eb.sst - %eb.end))
  248.   var %eb.pst = $mid(%eb.txt, %eb.end $+ -)
  249.   if ($inrect(%mx, %my, $calc(%pad * 9), 0, $calc($cellsize * 3 + $cellspacing * 2), $calc($cellsize * 2 + $cellspacing))) {
  250.     %mx = $calc(%mx - %pad * 9)
  251.     %xo = $floor($calc(%mx / %pad))
  252.     %yo = $floor($calc(%my / %pad))
  253.     if ($inrect(%mx, %my, $calc(%xo * %pad), $calc(%yo * %pad), $cellsize, $cellsize)) {
  254.       %cc = $gettok($chr(2) $chr(29) $chr(15) $chr(31) $chr(22), $calc(%yo * 3 + %xo + 1), 32)
  255.     }
  256.   }
  257.   elseif ($inrect(%mx, %my, 0, 0, $calc($cellsize * 8 + $cellspacing * 7), $calc($cellsize * 2 + $cellspacing))) {
  258.     %xo = $floor($calc(%mx / %pad))
  259.     %yo = $floor($calc(%my / %pad))
  260.     if ($inrect(%mx, %my, $calc(%xo * %pad), $calc(%yo * %pad), $cellsize, $cellsize)) {
  261.       %cc = $calc(%yo * 8 + %xo)
  262.     }
  263.   }
  264.   elseif ($inrect(%mx, %my, 0, $calc($cellsize * 2 + $cellspacing + $pallettegap), $calc($cellsize * 12 + $cellspacing * 11),$calc($cellsize * 7 + $cellspacing * 6))) {
  265.     %my = $calc(%my - $cellsize * 2 - $cellspacing - $pallettegap)
  266.     %xo = $floor($calc(%mx / %pad))
  267.     %yo = $floor($calc(%my / %pad))
  268.     if ($inrect(%mx, %my, $calc(%xo * %pad), $calc(%yo * %pad), $cellsize, $cellsize)) {
  269.       %cc = $calc(%yo * 12 + %xo + 16)
  270.     }
  271.   }
  272.   if (%cc === $null) {
  273.     return
  274.   }
  275.   set -u1 %xpallette.sclicked $true
  276.   if ($lactive == status window) {
  277.     %eb.swt = -s
  278.     %eb.tar = $null
  279.   }
  280.   if (%cc == $chr(15)) {
  281.     if ($right(%eb.sel,1) == $chr(15) || $left(%eb.pst,1) == $chr(15)) {
  282.       return
  283.     }
  284.     %eb.txt = %eb.pre $+ %eb.sel $+ $chr(15) $+ %eb.pst
  285.   }
  286.   elseif (%cc !isnum) {
  287.     if (%eb.sst !== %eb.end) {
  288.       %eb.txt = %eb.pre $+ %cc $+ %eb.sel $+ %cc $+ %eb.pst
  289.       inc %eb.end
  290.     }
  291.     else {
  292.       %eb.txt = %eb.pre $+ %eb.sel $+ %cc $+ %eb.pst
  293.     }
  294.     inc %eb.sst
  295.     inc %eb.end
  296.   }
  297.   elseif (%eb.sst == %eb.end) {
  298.     if ($mouse.key & 4) {
  299.       %eb.txt = %eb.pre $+ $chr(3) $+ %cc $+ %eb.pst
  300.       inc %eb.sst 3
  301.     }
  302.     elseif ($regex(%eb.pre, \x03$)) {
  303.       %eb.txt = %eb.pre $+ %cc $+ %eb.pst
  304.       inc %eb.sst 2
  305.       inc %eb.end 2
  306.     }
  307.     elseif ($regex(%eb.pre, \x03\d\d?$)) {
  308.       %eb.txt = %eb.pre $+ , $+ %cc $+ %eb.pst
  309.       inc %eb.sst 3
  310.       inc %eb.sst 3
  311.     }
  312.     elseif ($regex(%eb.pre, \x03\d\d?\x2C$)) {
  313.       %eb.txt = %eb.pre $+ %cc $+ %eb.pst
  314.       inc %eb.sst 2
  315.       inc %eb.end 2
  316.     }
  317.     else {
  318.       %eb.txt = %eb.pre $+ $chr(3) $+ %cc $+ %eb.pst
  319.       inc %eb.sst 3
  320.       inc %eb.end 3
  321.     }
  322.   }
  323.  
  324.  
  325.  
  326.  
  327.   ;; todo : Handle inserting color codes around selected text
  328.  
  329.  
  330.  
  331.  
  332.  
  333.   editbox $+(%eb.swt, b, %eb.sst, e, %eb.end) %eb.tar %eb.txt
  334. }
  335. alias dclicked {
  336.   if ($mouse.key !& 1 || $mouse.key & 16 || $mouse.key & 2 || $mouse.key & 8) {
  337.     unset %xpallette.sclicked
  338.   }
  339.   elseif (%xpallette.sclicked) {
  340.     cleanup
  341.   } 
  342. }
  343. alias -l cleanup {
  344.   unset %xpallette.sclicked
  345.   unset %xpallette.refocus
  346.   .timerxpallette off
  347.   close -@ @xpallette
  348. }
  349.  
dPaste use Geshi

Torna al NoPaste