Advertisement
SReject

xPallette

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