Draws a button in a picture window, it can have various styles and receives certain events.
For documentation, read the comments throughout the code.
; draws a button in a picture window, it can receive various events, and it can have different styles.
;
; /button [-abBcCdefgGhHiIk<N>KloOprRsSuU] [+b<N>] <@window rgb x y width height font fontsize fontrgb text/icon>
;
; -a reverse text.
; -b bevel text.
; -B bold text.
; -c center text.
; -C interpret rgb and fontrgb as control codes rather than rgb values.
; -d uses dbu instead of pixels (doubles the sizes you specify)
; -e emboss text.
; -f fill button with background colour.
; -g add gamma to colours.
; -G remove gamma from colours.
; -h interpret rgb and fontrgb as hexidecimal numbers rather than rgb values.
; -H interpret rgb and fontrgb as octal numbers rather than rgb values.
; -i invert colours.
; -I draws an icon instead of text.
; -k<N> uses an existing id instead of creating a new one.
; -K randomize colours.
; -l aligns text to the left.
; -o overline text.
; -O double overline text.
; -p uses pixels instead of dbu (halves the sizes you specify)
; -r aligns text to the right.
; -R rotate colours.
; -s strikethrough text.
; -S double strikethrough text.
; -u underline text.
; -U double underline text.
;
; +b<N> <N> can be 1-11 and it specifies a border for the button, try them out to see which you prefer (+b11 is my personal favourite).
; +b<N> can only be used if a -switch was used, the -l switch was created especially for this.
;
; $button([window],<id>)
;
; returns info about the specified window and id, if no window is specified, the active window is used.
alias button {
if !$isid {
if $left($1,1) == - { var %switch = $1 }
if $left($2,2) == +b {
var %border
.echo -q $regsub($right($2,-1),/\D/g,,%border)
}
if !%border {
if %switch { tokenize 32 $2- }
}
elseif %border { tokenize 32 $3- }
var %window = $1, %rgb = $2, %x = $3, %y = $4, %w = $5, %h = $6, %font = $7, %fontsize = $8, %fontrgb = $9, %text = $10-, %fontx, %fonty
colour -r 0
colour -r 1
var %id = $calc($hget(button [ $+ [ %window ] ],0).item +1)
if I !isincs %switch {
var %i = $len(%text)
while $iif(B isincs %switch,$width($left(%text,%i),%font,%fontsize,1),$width($left(%text,%i),%font,%fontsize)) > %w {
%text = $left(%text,%i)
dec %i
}
}
if d isincs %switch {
inc %x %x
inc %y %y
inc %w %w
inc %h %h
%switch = $removecs(%switch,d)
}
elseif p isincs %switch {
%x = $calc(%x /2)
%y = $calc(%y /2)
%w = $calc(%w /2)
%h = $calc(%h /2)
%switch = $removecs(%switch,p)
}
if k isincs %switch {
var %id = $mid(%switch,$calc($pos(%switch,k) +1))
.echo -q $regsub(%id,/\D/g,,%id)
if $window(%window) {
if $hget(button [ $+ [ %window ] ],%id) {
tokenize 32 $hget(button [ $+ [ %window ] ],%id)
if $left($2,2) == +b { tokenize 32 $3- }
elseif $left($1,1) == - { tokenize 32 $2- }
drawrect -fr %window $getdot(%window,1,1) 1 $calc($2 -2) $calc($3 -2) $calc($4 +4) $calc($5 +4)
}
}
}
if I isincs %switch { var %file = %text }
if C isincs %switch {
%rgb = $colour($remove(%rgb,$chr(3)))
%fontrgb = $colour($remove(%fontrgb,$chr(3)))
}
elseif h isincs %switch {
%rgb = $base($remove(%rgb,$chr(35)),16,10)
%fontrgb = $base($remove(%fontrgb,$chr(35)),16,10)
}
elseif H isincs %switch {
%rgb = $base($remove(%rgb,$chr(35)),8,10)
%fontrgb = $base($remove(%fontrgb,$chr(35)),8,10)
}
if i isincs %switch {
%rgb = $calc(16777215 - %rgb)
%fontrgb = $calc(16777215 - %fontrgb)
}
if l isincs %switch { %fontx = $calc(%x +3) }
elseif r isincs %switch { %fontx = $calc((%x + %w) - $iif(B isincs %switch,$width(%text,%font,%fontsize,1),$width(%text,%font,%fontsize)) -3) }
elseif c isincs %switch { %fontx = $calc(%x + (%w /2) - ($iif(B isincs %switch,$width(%text,%font,%fontsize,1),$width(%text,%font,%fontsize)) /2)) }
if !%fontx { %fontx = $calc(%x +3) }
%fontx = $int(%fontx)
%fonty = $int($calc(%y + (%h /2) - ($height(%text,%font,%fontsize) /2)))
if $window(%window) && $window(%window).type != picture {
echo -ac Info * /button: ' $+ %window $+ ' is not a picture window.
return
}
if !%text {
echo -ac Info * /button: insufficient parameters.
return
}
if %rgb !isnum 0-16777215 {
echo -ac Info * /button: ' $+ %rgb $+ ' is an invalid colour.
return
}
if %file && !$isfile(%file) {
echo -ac Info * /button: ' $+ %file $+ ' doesn't exist.
return
}
if %file { %file = $shortfn(%file) }
if !$window(%window) { window -p %window }
if K isincs %switch {
%rgb = $r(0,16777215)
%fontrgb = $r(0,16777215)
}
if g isincs %switch {
var %r = $gettok($rgb(%rgb),1,44), %g = $gettok($rgb(%rgb),2,44), %b = $gettok($rgb(%rgb),3,44)
var %fr = $gettok($rgb(%fontrgb),1,44), %fg = $gettok($rgb(%fontrgb),2,44), %fb = $gettok($rgb(%fontrgb),3,44)
inc %r $r(0,$calc(255 - %r))
inc %g $r(0,$calc(255 - %g))
inc %b $r(0,$calc(255 - %b))
inc %fr $r(0,$calc(255 - %fr))
inc %fg $r(0,$calc(255 - %fg))
inc %fb $r(0,$calc(255 - %fb))
%rgb = $rgb(%r,%g,%b)
%fontrgb = $rgb(%fr,%fg,%fb)
}
elseif G isincs %switch {
var %r = $gettok($rgb(%rgb),1,44), %g = $gettok($rgb(%rgb),2,44), %b = $gettok($rgb(%rgb),3,44)
var %fr = $gettok($rgb(%fontrgb),1,44), %fg = $gettok($rgb(%fontrgb),2,44), %fb = $gettok($rgb(%fontrgb),3,44)
dec %r $r(0,%r)
dec %g $r(0,%g)
dec %b $r(0,%b)
dec %fr $r(0,%fr)
dec %fg $r(0,%fg)
dec %fb $r(0,%fb)
%rgb = $rgb(%r,%g,%b)
%fontrgb = $rgb(%fr,%fg,%fb)
}
if R isincs %switch {
tokenize 32 %rgb %fontrgb
%fontrgb = $1
%rgb = $2
}
hadd -m button [ $+ [ %window ] ] %id %switch $iif(%border,+b $+ %border) %rgb %x %y %w %h %font %fontsize %fontrgb %fontx %fonty $iif(%file,%file,%text)
drawrect - $+ $iif(f isincs %switch,f) $+ r %window %rgb 1 %x %y %w %h
if !%file {
if a isincs %switch {
var %i = 1, %retext
while $mid(%text,%i,1) {
%retext = $ifmatch $+ %retext
inc %i
}
%text = %retext
}
if b isincs %switch { drawtext - $+ $iif(B isincs %switch,o) $+ r %window $rgb(shadow) %font %fontsize $calc(%fontx +1) $calc(%fonty +1) %text }
drawtext - $+ $iif(B isincs %switch,o) $+ r %window %fontrgb %font %fontsize %fontx %fonty %text
if e isincs %switch { drawtext - $+ $iif(B isincs %switch,o) $+ r %window $rgb(shadow) %font %fontsize $calc(%fontx -1) $calc(%fonty -1) %text }
if o isincs %switch { drawline -r %window %fontrgb 1 %fontx %fonty $calc(%fontx + $iif(B isincs %switch,$width(%text,%font,%fontsize,1),$width(%text,%font,%fontsize))) %fonty }
elseif O isincs %switch {
drawline -r %window %fontrgb 1 %fontx %fonty $calc(%fontx + $iif(B isincs %switch,$width(%text,%font,%fontsize,1),$width(%text,%font,%fontsize))) %fonty
drawline -r %window %fontrgb 1 %fontx $calc(%fonty -2) $calc(%fontx + $iif(B isincs %switch,$width(%text,%font,%fontsize,1),$width(%text,%font,%fontsize))) $calc(%fonty -2)
}
if s isincs %switch { drawline -r %window %fontrgb 1 %fontx $calc(%fonty + ($height(%text,%font,%fontsize) /2)) $calc(%fontx + $iif(B isincs %switch,$width(%text,%font,%fontsize,1),$width(%text,%font,%fontsize))) $calc(%fonty + ($height(%text,%font,%fontsize) /2)) }
elseif S isincs %switch {
drawline -r %window %fontrgb 1 %fontx $calc(%fonty + ($height(%text,%font,%fontsize) /3)) $calc(%fontx + $iif(B isincs %switch,$width(%text,%font,%fontsize,1),$width(%text,%font,%fontsize))) $calc(%fonty + ($height(%text,%font,%fontsize) /3))
drawline -r %window %fontrgb 1 %fontx $calc(%fonty + ($height(%text,%font,%fontsize) /2)) $calc(%fontx + $iif(B isincs %switch,$width(%text,%font,%fontsize,1),$width(%text,%font,%fontsize))) $calc(%fonty + ($height(%text,%font,%fontsize) /2))
}
if u isincs %switch { drawline -r %window %fontrgb 1 %fontx $calc(%fonty + $height(%text,%font,%fontsize)) $calc(%fontx + $iif(B isincs %switch,$width(%text,%font,%fontsize,1),$width(%text,%font,%fontsize))) $calc(%fonty + $height(%text,%font,%fontsize)) }
elseif U isincs %switch {
drawline -r %window %fontrgb 1 %fontx $calc(%fonty + $height(%text,%font,%fontsize)) $calc(%fontx + $iif(B isincs %switch,$width(%text,%font,%fontsize,1),$width(%text,%font,%fontsize))) $calc(%fonty + $height(%text,%font,%fontsize))
drawline -r %window %fontrgb 1 %fontx $calc(%fonty + $height(%text,%font,%fontsize) +2) $calc(%fontx + $iif(B isincs %switch,$width(%text,%font,%fontsize,1),$width(%text,%font,%fontsize))) $calc(%fonty + $height(%text,%font,%fontsize) +2)
}
}
elseif %file { drawpic -ms %window %x %y %w %h %file }
if %border == 1 { drawrect -r %window $rgb(frame) 1 %x %y %w %h }
elseif %border == 2 { drawrect -r %window $rgb(shadow) 1 %x %y %w %h }
elseif %border == 3 { drawrect -r %window $rgb(hilight) 1 %x %y %w %h }
elseif %border == 4 { drawrect -r %window $rgb(3dlight) 1 %x %y %w %h }
elseif %border == 5 {
drawline -r %window $rgb(hilight) 1 %x %y $calc(%x + %w) %y %x %y %x $calc(%y + %h)
drawline -r %window $rgb(shadow) 2 $calc(%x + %w) %y $calc(%x + %w) $calc(%y + %h) %x $calc(%y + %h) $calc(%x + %w) $calc(%y + %h)
}
elseif %border == 6 {
drawline -r %window $rgb(shadow) 1 %x %y $calc(%x + %w) %y %x %y %x $calc(%y + %h)
drawline -r %window $rgb(shadow) 2 $calc(%x + %w) %y $calc(%x + %w) $calc(%y + %h) %x $calc(%y + %h) $calc(%x + %w) $calc(%y + %h)
}
elseif %border == 7 {
drawline -r %window $rgb(3dlight) 1 %x %y $calc(%x + %w) %y %x %y %x $calc(%y + %h)
drawline -r %window $rgb(shadow) 2 $calc(%x + %w) %y $calc(%x + %w) $calc(%y + %h) %x $calc(%y + %h) $calc(%x + %w) $calc(%y + %h)
}
elseif %border == 8 {
drawline -r %window $rgb(shadow) 2 %x %y $calc(%x + %w) %y %x %y %x $calc(%y + %h)
drawline -r %window $rgb(hilight) 1 $calc(%x + %w) %y $calc(%x + %w) $calc(%y + %h) %x $calc(%y + %h) $calc(%x + %w) $calc(%y + %h)
}
elseif %border == 9 {
drawline -r %window $rgb(shadow) 2 %x %y $calc(%x + %w) %y %x %y %x $calc(%y + %h)
drawline -r %window $rgb(shadow) 1 $calc(%x + %w) %y $calc(%x + %w) $calc(%y + %h) %x $calc(%y + %h) $calc(%x + %w) $calc(%y + %h)
}
elseif %border == 10 {
drawline -r %window $rgb(shadow) 2 %x %y $calc(%x + %w) %y %x %y %x $calc(%y + %h)
drawline -r %window $rgb(3dlight) 1 $calc(%x + %w) %y $calc(%x + %w) $calc(%y + %h) %x $calc(%y + %h) $calc(%x + %w) $calc(%y + %h)
}
elseif %border == 11 {
drawline -r %window $rgb(0,0,0) 1 %x %y $calc(%x + %w) %y %x %y %x $calc(%y + %h)
drawline -r %window $rgb(0,0,0) 1 $calc(%x + %w) %y $calc(%x + %w) $calc(%y + %h) %x $calc(%y + %h) $calc(%x + %w) $calc(%y + %h)
drawline -r %window $rgb(190,190,200) 1 $calc(%x +1) $calc(%y +1) $calc((%x +1) + (%w -2)) $calc(%y +1) $calc(%x +1) $calc(%y +1) $calc(%x +1) $calc($calc(%y +1) + (%h -2))
drawline -r %window $rgb(148,148,148) 1 $calc((%x +1) + (%w -2)) $calc(%y +1) $calc((%x +1) + (%w -2)) $calc((%y +1) + (%h -2)) $calc(%x +1) $calc((%y +1) + (%h -2)) $calc((%x +1) + (%w -2)) $calc((%y +1) + (%h -2))
}
}
elseif $isid {
if !$2 { tokenize 32 $active $1 }
return $iif($left($gettok($hget(button [ $+ [ $1 ] ],$2),2,32),2) == +b,$gettok($hget(button [ $+ [ $1 ] ],$2),1-2,32) $1 $gettok($hget(button [ $+ [ $1 ] ],$2),3-,32),$iif($left($gettok($hget(button [ $+ [ $1 ] ],$2),1,32),1) == -,$gettok($hget(button [ $+ [ $1 ] ],$2),1,32) $1 $gettok($hget(button [ $+ [ $1 ] ],$2),3-,32),$1 $hget(button [ $+ [ $1 ] ],$2)))
}
}
; this event just cleans up hash tables when the window is closed.
on *:close:@:{
if $hget(button [ $+ [ $target ] ]) { .hfree $ifmatch }
}
; this catches the events.
menu @* {
sclick:{
if $hget(button [ $+ [ $active ] ]) {
var %i = 1
while $hget(button [ $+ [ $active ] ],%i).item {
tokenize 32 $hget(button [ $+ [ $active ] ],%i).data
if $left($2,2) != +b {
if $left($1,1) == - {
var %switch = $1
tokenize 32 $2-
}
}
elseif $left($2,2) == +b {
var %switch = $1, %border = $2
tokenize 32 $3-
}
if $inrect($mouse.x,$mouse.y,$2,$3,$4,$5) {
if $mouse.key & 2 { .signal button_ctrlsclick $hget(button [ $+ [ $active ] ],%i).item %switch %border $active $1- }
elseif $mouse.key & 4 { .signal button_shiftsclick $hget(button [ $+ [ $active ] ],%i).item %switch %border $active $1- }
else { .signal button_sclick $hget(button [ $+ [ $active ] ],%i).item %switch %border $active $1- }
}
inc %i
}
}
}
uclick:{
if $hget(button [ $+ [ $active ] ]) {
var %i = 1
while $hget(button [ $+ [ $active ] ],%i).item {
tokenize 32 $hget(button [ $+ [ $active ] ],%i).data
if $left($2,2) != +b {
if $left($1,1) == - {
var %switch = $1
tokenize 32 $2-
}
}
elseif $left($2,2) == +b {
var %switch = $1, %border = $2
tokenize 32 $3-
}
if $inrect($mouse.x,$mouse.y,$2,$3,$4,$5) {
if $mouse.key & 2 { .signal button_ctrluclick $hget(button [ $+ [ $active ] ],%i).item %switch %border $active $1- }
elseif $mouse.key & 4 { .signal button_shiftuclick $hget(button [ $+ [ $active ] ],%i).item %switch %border $active $1- }
else { .signal button_uclick $hget(button [ $+ [ $active ] ],%i).item %switch %border $active $1- }
}
inc %i
}
}
}
rclick:{
if $hget(button [ $+ [ $active ] ]) {
var %i = 1
while $hget(button [ $+ [ $active ] ],%i).item {
tokenize 32 $hget(button [ $+ [ $active ] ],%i).data
if $left($2,2) != +b {
if $left($1,1) == - {
var %switch = $1
tokenize 32 $2-
}
}
elseif $left($2,2) == +b {
var %switch = $1, %border = $2
tokenize 32 $3-
}
if $inrect($mouse.x,$mouse.y,$2,$3,$4,$5) {
if $mouse.key & 2 { .signal button_ctrlrclick $hget(button [ $+ [ $active ] ],%i).item %switch %border $active $1- }
elseif $mouse.key & 4 { .signal button_shiftrclick $hget(button [ $+ [ $active ] ],%i).item %switch %border $active $1- }
else { .signal button_rclick $hget(button [ $+ [ $active ] ],%i).item %switch %border $active $1- }
}
inc %i
}
}
}
dclick:{
if $hget(button [ $+ [ $active ] ]) {
var %i = 1
while $hget(button [ $+ [ $active ] ],%i).item {
tokenize 32 $hget(button [ $+ [ $active ] ],%i).data
if $left($2,2) != +b {
if $left($1,1) == - {
var %switch = $1
tokenize 32 $2-
}
}
elseif $left($2,2) == +b {
var %switch = $1, %border = $2
tokenize 32 $3-
}
if $inrect($mouse.x,$mouse.y,$2,$3,$4,$5) {
if $mouse.key & 2 { .signal button_ctrldclick $hget(button [ $+ [ $active ] ],%i).item %switch %border $active $1- }
elseif $mouse.key & 4 { .signal button_shiftdclick $hget(button [ $+ [ $active ] ],%i).item %switch %border $active $1- }
else { .signal button_dclick $hget(button [ $+ [ $active ] ],%i).item %switch %border $active $1- }
}
inc %i
}
}
}
mouse:{
if $hget(button [ $+ [ $active ] ]) {
var %i = 1
while $hget(button [ $+ [ $active ] ],%i).item {
tokenize 32 $hget(button [ $+ [ $active ] ],%i).data
if $left($2,2) != +b {
if $left($1,1) == - {
var %switch = $1
tokenize 32 $2-
}
}
elseif $left($2,2) == +b {
var %switch = $1, %border = $2
tokenize 32 $3-
}
if $inrect($mouse.x,$mouse.y,$2,$3,$4,$5) {
if $mouse.key & 2 { .signal button_ctrlmouse $hget(button [ $+ [ $active ] ],%i).item %switch %border $active $1- }
elseif $mouse.key & 4 { .signal button_shiftmouse $hget(button [ $+ [ $active ] ],%i).item %switch %border $active $1- }
else { .signal button_mouse $hget(button [ $+ [ $active ] ],%i).item %switch %border $active $1- }
}
inc %i
}
}
}
}
; these are the events.
; if you aren't too sure about how to use signals, type /help signals.
;
; the following events can be used:
;
; button_sclick - left clicked the button.
; button_ctrlsclick - left clicked the button with ctrl held down.
; button_shiftsclick - left clicked the button with shift held down.
;
; button_uclick - unclicked the button.
; button_ctrluclick - unclicked the button with ctrl held down.
; button_shiftuclick - unclicked the button with shift held down.
;
; button_dclick - double clicked the button.
; button_ctrldclick - double clicked the button with ctrl held down.
; button_shiftdclick - double clicked the button with shift held down.
;
; button_rclick - right clicked the button.
; button_ctrlrclick - right clicked the button with ctrl held down.
; button_shiftrclick - right clicked the button with shift held down.
;
; button_mouse - moved the mouse over the button.
; button_ctrlmouse - moved the mouse over the button with ctrl held down.
; button_shiftmouse - moved the mouse over the button with shift held down.
on *:signal:button_sclick:{ .echo -q button sclick: $1- }
on *:signal:button_ctrlsclick:{ .echo -q button ctrl+sclick: $1- }
on *:signal:button_shiftsclick:{ .echo -q button shift+sclick: $1- }
on *:signal:button_uclick:{ .echo -q button uclick: $1- }
on *:signal:button_ctrluclick:{ .echo -q button ctrl+uclick: $1- }
on *:signal:button_shiftuclick:{ .echo -q button shift+uclick: $1- }
on *:signal:button_dclick:{ .echo -q button dclick: $1- }
on *:signal:button_ctrldclick:{ .echo -q button ctrl+dclick: $1- }
on *:signal:button_shiftdclick:{ .echo -q button shift+dclick: $1- }
on *:signal:button_rclick:{ .echo -q button rclick: $1- }
on *:signal:button_ctrlrclick:{ .echo -q button ctrl+rclick: $1- }
on *:signal:button_shiftrclick:{ .echo -q button shift+rclick: $1- }
on *:signal:button_mouse:{ .echo -q button mouse: $1- }
on *:signal:button_ctrlmouse:{ .echo -q button ctrl+mouse: $1- }
on *:signal:button_shiftmouse:{ .echo -q button shift+mouse: $1- }
; example script
;
; //button -bcfB +b5 @mp3 $rgb(209,209,209) 50 50 15 15 webdings 15 0 4
;
; on *:signal:button_sclick:{
; if $1 $4 == 1 @mp3 { splay $shortfn($$sfile(c:\*.mp3,choose a song,play)) }
; }
;
; nothing special, just an example.
; note
;
; you cannot use events in this file unless you remove the ones already in the file.
; contact
;
; irc: /server irc.undernet.org -j #mirc.net
; email: tidy_trax@mirc.net
; msn: mat_tye@hotmail.com